Debian Codegraph @

brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/UnknownCompressionTest.java

raw
1 /*
2 * Copyright (C) 2010 Ryszard Wiśniewski <[email protected]>
3 * Copyright (C) 2010 Connor Tumbleson <[email protected]>
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package brut.androlib.aapt1;
18
19 import brut.androlib.*;
20 import brut.androlib.options.BuildOptions;
21 import brut.directory.ExtFile;
22 import brut.common.BrutException;
23 import brut.util.OS;
24 import org.junit.AfterClass;
25 import org.junit.BeforeClass;
26 import org.junit.Test;
27
28 import java.io.File;
29 import java.io.IOException;
30
31 import static org.junit.Assert.assertEquals;
32 import static org.junit.Assert.assertNotSame;
33
34 public class UnknownCompressionTest extends BaseTest {
35
36 @BeforeClass
37 public static void beforeClass() throws Exception {
38 TestUtils.cleanFrameworkFile();
39 sTmpDir = new ExtFile(OS.createTempDirectory());
40 TestUtils.copyResourceDir(UnknownCompressionTest.class, "aapt1/unknown_compression/", sTmpDir);
41
42 String apk = "deflated_unknowns.apk";
43 BuildOptions buildOptions = new BuildOptions();
44 buildOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath();
45
46 sTestOrigDir = new ExtFile(sTmpDir, apk);
47
48 // decode deflated_unknowns.apk
49 ApkDecoder apkDecoder = new ApkDecoder(sTestOrigDir);
50 apkDecoder.setOutDir(new File(sTestOrigDir.getAbsolutePath() + ".out"));
51 apkDecoder.decode();
52
53 // build deflated_unknowns
54 ExtFile clientApkFolder = new ExtFile(sTestOrigDir.getAbsolutePath() + ".out");
55 new Androlib(buildOptions).build(clientApkFolder, null);
56 sTestNewDir = new ExtFile(clientApkFolder, "dist" + File.separator + apk);
57 }
58
59 @AfterClass
60 public static void afterClass() throws BrutException {
61 OS.rmdir(sTmpDir);
62 }
63
64 @Test
65 public void pkmExtensionDeflatedTest() throws BrutException, IOException {
66 Integer control = sTestOrigDir.getDirectory().getCompressionLevel("assets/bin/Data/test.pkm");
67 Integer rebuilt = sTestNewDir.getDirectory().getCompressionLevel("assets/bin/Data/test.pkm");
68
69 // Check that control = rebuilt (both deflated)
70 // Add extra check for checking not equal to 0, just in case control gets broken
71 assertEquals(control, rebuilt);
72 assertNotSame(0, rebuilt);
73 }
74
75 @Test
76 public void doubleExtensionStoredTest() throws BrutException, IOException {
77 Integer control = sTestOrigDir.getDirectory().getCompressionLevel("assets/bin/Data/two.extension.file");
78 Integer rebuilt = sTestNewDir.getDirectory().getCompressionLevel("assets/bin/Data/two.extension.file");
79
80 // Check that control = rebuilt (both stored)
81 // Add extra check for checking = 0 to enforce check for stored just in case control breaks
82 assertEquals(control, rebuilt);
83 assertEquals(Integer.valueOf(0), rebuilt);
84 }
85
86 @Test
87 public void confirmJsonFileIsDeflatedTest() throws BrutException, IOException {
88 Integer control = sTestOrigDir.getDirectory().getCompressionLevel("test.json");
89 Integer rebuilt = sTestNewDir.getDirectory().getCompressionLevel("test.json");
90
91 assertEquals(control, rebuilt);
92 assertEquals(Integer.valueOf(8), rebuilt);
93 }
94
95 @Test
96 public void confirmPngFileIsCorrectlyDeflatedTest() throws BrutException, IOException {
97 Integer control = sTestOrigDir.getDirectory().getCompressionLevel("950x150.png");
98 Integer rebuilt = sTestNewDir.getDirectory().getCompressionLevel("950x150.png");
99
100 assertEquals(control, rebuilt);
101 assertEquals(Integer.valueOf(8), rebuilt);
102 }
103 }