use of org.haiku.pkg.model.StringAttribute 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);
}
}
Aggregations