Debian Codegraph @

brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/SkipAssetTest.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.ApkDecoder;
20 import brut.androlib.BaseTest;
21 import brut.androlib.TestUtils;
22 import brut.directory.ExtFile;
23 import brut.common.BrutException;
24 import brut.util.OS;
25 import java.io.File;
26 import java.io.IOException;
27
28 import org.junit.*;
29 import static org.junit.Assert.*;
30
31 public class SkipAssetTest extends BaseTest {
32
33 @BeforeClass
34 public static void beforeClass() throws Exception {
35 TestUtils.cleanFrameworkFile();
36 sTmpDir = new ExtFile(OS.createTempDirectory());
37 TestUtils.copyResourceDir(SkipAssetTest.class, "aapt1/issue1605/", sTmpDir);
38 }
39
40 @AfterClass
41 public static void afterClass() throws BrutException {
42 OS.rmdir(sTmpDir);
43 }
44
45 @Test
46 public void checkIfEnablingSkipAssetWorks() throws BrutException, IOException {
47 String apk = "issue1605.apk";
48
49 // decode issue1605.apk
50 ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
51 sTestOrigDir = new ExtFile(sTmpDir + File.separator + apk + ".out");
52
53 apkDecoder.setOutDir(sTestOrigDir);
54 apkDecoder.setDecodeAssets(ApkDecoder.DECODE_ASSETS_NONE);
55 apkDecoder.setForceDelete(true);
56 apkDecoder.decode();
57
58 checkFileDoesNotExist("assets" + File.separator + "kotlin.kotlin_builtins");
59 checkFileDoesNotExist("assets" + File.separator + "ranges" + File.separator + "ranges.kotlin_builtins");
60 }
61
62 @Test
63 public void checkControl() throws BrutException, IOException {
64 String apk = "issue1605.apk";
65
66 // decode issue1605.apk
67 ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
68 sTestOrigDir = new ExtFile(sTmpDir + File.separator + apk + ".out");
69
70 apkDecoder.setOutDir(sTestOrigDir);
71 apkDecoder.setDecodeAssets(ApkDecoder.DECODE_ASSETS_FULL);
72 apkDecoder.setForceDelete(true);
73 apkDecoder.decode();
74
75 checkFileDoesExist("assets" + File.separator + "kotlin.kotlin_builtins");
76 checkFileDoesExist("assets" + File.separator + "ranges" + File.separator + "ranges.kotlin_builtins");
77 }
78
79 private void checkFileDoesNotExist(String path) throws BrutException {
80 File f = new File(sTestOrigDir, path);
81
82 assertFalse(f.isFile());
83 }
84
85 private void checkFileDoesExist(String path) throws BrutException {
86 File f = new File(sTestOrigDir, path);
87
88 assertTrue(f.isFile());
89 }
90 }