Search in sources :

Example 1 with IntAttribute

use of org.haiku.pkg.model.IntAttribute in project haikudepotserver by haiku.

the class HpkgFileExtractorAttributeTest method testReadFile.

@Test
public void testReadFile() throws Exception {
    File hpkgFile = prepareTestFile(RESOURCE_TEST);
    try (HpkgFileExtractor hpkgFileExtractor = new HpkgFileExtractor(hpkgFile)) {
        AttributeContext tocContext = hpkgFileExtractor.getTocContext();
        List<Attribute> tocAttributes = toList(hpkgFileExtractor.getTocIterator());
        IntAttribute mTimeAttribute = (IntAttribute) tocAttributes.get(0).getChildAttributes().get(2);
        Assertions.assertThat(mTimeAttribute.getAttributeId()).isEqualTo(AttributeId.FILE_MTIME);
        Assertions.assertThat(mTimeAttribute.getAttributeType()).isEqualTo(AttributeType.INT);
        Assertions.assertThat(((Number) mTimeAttribute.getValue(tocContext)).longValue()).isEqualTo(1551679116L);
        AttributeContext packageAttributeContext = hpkgFileExtractor.getPackageAttributeContext();
        List<Attribute> packageAttributes = toList(hpkgFileExtractor.getPackageAttributesIterator());
        Attribute summaryAttribute = packageAttributes.get(1);
        Assertions.assertThat(summaryAttribute.getAttributeId()).isEqualTo(AttributeId.PACKAGE_SUMMARY);
        Assertions.assertThat(summaryAttribute.getAttributeType()).isEqualTo(AttributeType.STRING);
        Assertions.assertThat(summaryAttribute.getValue(packageAttributeContext)).isEqualTo("An application to display Haiku usage tips");
        // Pull out the actual binary to check.  The expected data results were obtained
        // from a Haiku host with the package installed.
        Attribute tipsterDirectoryEntry = findByDirectoryEntries(tocAttributes, tocContext, List.of("apps", "Tipster"));
        Attribute binaryData = tipsterDirectoryEntry.getChildAttribute(AttributeId.DATA);
        ByteSource binaryDataByteSource = (ByteSource) binaryData.getValue(tocContext);
        Assertions.assertThat(binaryDataByteSource.size()).isEqualTo(153840L);
        HashCode hashCode = binaryDataByteSource.hash(Hashing.md5());
        Assertions.assertThat(hashCode.toString().toLowerCase(Locale.ROOT)).isEqualTo("13b16cd7d035ddda09a744c49a8ebdf2");
        Optional<StringAttribute> iconAttributeOptional = tipsterDirectoryEntry.getChildAttributes(AttributeId.FILE_ATTRIBUTE).stream().map(a -> (StringAttribute) a).filter(a -> a.getValue(tocContext).equals("BEOS:ICON")).findFirst();
        Assertions.assertThat(iconAttributeOptional.isPresent()).isTrue();
        Attribute iconAttribute = iconAttributeOptional.get();
        Attribute iconBinaryData = iconAttribute.getChildAttribute(AttributeId.DATA);
        ByteSource iconDataByteSource = (ByteSource) iconBinaryData.getValue(tocContext);
        byte[] iconBytes = iconDataByteSource.read();
        assertIsHvif(iconBytes);
    }
}
Also used : StringAttribute(org.haiku.pkg.model.StringAttribute) HashCode(com.google.common.hash.HashCode) Assertions(org.fest.assertions.Assertions) Hashing(com.google.common.hash.Hashing) AttributeId(org.haiku.pkg.model.AttributeId) File(java.io.File) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) IntAttribute(org.haiku.pkg.model.IntAttribute) List(java.util.List) AttributeType(org.haiku.pkg.model.AttributeType) Locale(java.util.Locale) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) ByteSource(com.google.common.io.ByteSource) Attribute(org.haiku.pkg.model.Attribute) IntAttribute(org.haiku.pkg.model.IntAttribute) StringAttribute(org.haiku.pkg.model.StringAttribute) IntAttribute(org.haiku.pkg.model.IntAttribute) Attribute(org.haiku.pkg.model.Attribute) StringAttribute(org.haiku.pkg.model.StringAttribute) HashCode(com.google.common.hash.HashCode) ByteSource(com.google.common.io.ByteSource) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 2 with IntAttribute

use of org.haiku.pkg.model.IntAttribute in project haikudepotserver by haiku.

the class PkgFactoryTest method createTestPackageAttributes.

private Attribute createTestPackageAttributes() {
    StringInlineAttribute majorVersionA = new StringInlineAttribute(AttributeId.PACKAGE_VERSION_MAJOR, "6");
    majorVersionA.setChildAttributes(ImmutableList.of(new StringInlineAttribute(AttributeId.PACKAGE_VERSION_MINOR, "32"), new StringInlineAttribute(AttributeId.PACKAGE_VERSION_MICRO, "9"), new StringInlineAttribute(AttributeId.PACKAGE_VERSION_PRE_RELEASE, "beta"), new IntAttribute(AttributeId.PACKAGE_VERSION_REVISION, new BigInteger("8"))));
    StringInlineAttribute topA = new StringInlineAttribute(AttributeId.PACKAGE, "testpkg");
    topA.setChildAttributes(ImmutableList.of(new StringInlineAttribute(AttributeId.PACKAGE_NAME, "testpkg"), new StringInlineAttribute(AttributeId.PACKAGE_VENDOR, "Test Vendor"), new StringInlineAttribute(AttributeId.PACKAGE_SUMMARY, "This is a test package summary"), new StringInlineAttribute(AttributeId.PACKAGE_DESCRIPTION, "This is a test package description"), new StringInlineAttribute(AttributeId.PACKAGE_URL, "http://www.haiku-os.org"), // X86
    new IntAttribute(AttributeId.PACKAGE_ARCHITECTURE, new BigInteger("1")), majorVersionA, new StringInlineAttribute(AttributeId.PACKAGE_COPYRIGHT, "Some copyright A"), new StringInlineAttribute(AttributeId.PACKAGE_COPYRIGHT, "Some copyright B"), new StringInlineAttribute(AttributeId.PACKAGE_LICENSE, "Some license A"), new StringInlineAttribute(AttributeId.PACKAGE_LICENSE, "Some license B")));
    return topA;
}
Also used : IntAttribute(org.haiku.pkg.model.IntAttribute) BigInteger(java.math.BigInteger) StringInlineAttribute(org.haiku.pkg.model.StringInlineAttribute)

Aggregations

IntAttribute (org.haiku.pkg.model.IntAttribute)2 Preconditions (com.google.common.base.Preconditions)1 HashCode (com.google.common.hash.HashCode)1 Hashing (com.google.common.hash.Hashing)1 ByteSource (com.google.common.io.ByteSource)1 File (java.io.File)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 Optional (java.util.Optional)1 Assertions (org.fest.assertions.Assertions)1 Attribute (org.haiku.pkg.model.Attribute)1 AttributeId (org.haiku.pkg.model.AttributeId)1 AttributeType (org.haiku.pkg.model.AttributeType)1 StringAttribute (org.haiku.pkg.model.StringAttribute)1 StringInlineAttribute (org.haiku.pkg.model.StringInlineAttribute)1 Test (org.junit.jupiter.api.Test)1