-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pickup icons from the hpkg data - closes #110
- Loading branch information
Showing
17 changed files
with
484 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...epotserver-core-test/src/test/java/org/haiku/haikudepotserver/support/HpkgHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2021, Andrew Lindesay | ||
* Distributed under the terms of the MIT License. | ||
*/ | ||
package org.haiku.haikudepotserver.support; | ||
|
||
import com.google.common.collect.Iterables; | ||
import com.google.common.io.ByteSource; | ||
import com.google.common.io.Files; | ||
import com.google.common.io.Resources; | ||
import junit.framework.AssertionFailedError; | ||
import org.fest.assertions.Assertions; | ||
import org.haiku.pkg.AttributeContext; | ||
import org.haiku.pkg.HpkgFileExtractor; | ||
import org.haiku.pkg.model.Attribute; | ||
import org.haiku.pkg.model.AttributeId; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class HpkgHelperTest { | ||
|
||
private static final String RESOURCE_TEST = "tipster-1.1.1-1-x86_64.hpkg"; | ||
|
||
private static final int[] HVIF_MAGIC = { | ||
0x6e, 0x63, 0x69, 0x66 | ||
}; | ||
|
||
@Rule | ||
public TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
||
@Test | ||
public void testFindIconAttributesFromAppExecutableDirEntries() throws Exception { | ||
// GIVEN | ||
File file = prepareTestFile(RESOURCE_TEST); | ||
HpkgFileExtractor fileExtractor = new HpkgFileExtractor(file); | ||
AttributeContext tocContext = fileExtractor.getTocContext(); | ||
|
||
// WHEN | ||
List<Attribute> attributes = HpkgHelper.findIconAttributesFromExecutableDirEntries( | ||
tocContext, fileExtractor.getToc()); | ||
|
||
// THEN | ||
Assertions.assertThat(attributes).hasSize(1); | ||
Attribute iconA = Iterables.getOnlyElement(attributes); | ||
Attribute iconDataA = iconA.getChildAttribute(AttributeId.DATA); | ||
ByteSource byteSource = (ByteSource) iconDataA.getValue(tocContext); | ||
byte[] data = byteSource.read(); | ||
Assertions.assertThat(data).hasSize(544); | ||
assertIsHvif(data); | ||
} | ||
|
||
File prepareTestFile(String resource) throws IOException { | ||
byte[] payload = Resources.toByteArray(Resources.getResource(resource)); | ||
File temporaryFile = temporaryFolder.newFile(resource); | ||
Files.write(payload, temporaryFile); | ||
return temporaryFile; | ||
} | ||
|
||
private void assertIsHvif(byte[] payload) { | ||
Assertions.assertThat(payload.length).isGreaterThan(HVIF_MAGIC.length); | ||
for (int i = 0; i < HVIF_MAGIC.length; i++) { | ||
if ((0xff & payload[i]) != HVIF_MAGIC[i]) { | ||
throw new AssertionFailedError("mismatch on the magic in the data payload"); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+48.2 KB
haikudepotserver-core-test/src/test/resources/tipster-1.1.1-1-x86_64.hpkg
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.