Debian Codegraph @

brut.apktool/apktool-lib/src/test/java/brut/androlib/decode/AndResGuardTest.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.decode;
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 AndResGuardTest extends BaseTest {
32
33 @BeforeClass
34 public static void beforeClass() throws Exception {
35 TestUtils.cleanFrameworkFile();
36 sTmpDir = new ExtFile(OS.createTempDirectory());
37 TestUtils.copyResourceDir(AndResGuardTest.class, "decode/issue1170/", sTmpDir);
38 }
39
40 @AfterClass
41 public static void afterClass() throws BrutException {
42 OS.rmdir(sTmpDir);
43 }
44
45 @Test
46 public void checkifAndResDecodeRemapsRFolder() throws BrutException, IOException {
47 String apk = "issue1170.apk";
48
49 // decode issue1170.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(new File(sTmpDir + File.separator + apk + ".out"));
54 apkDecoder.decode();
55
56 File aPng = new File(sTestOrigDir,"res/mipmap-hdpi-v4/a.png");
57 assertTrue(aPng.isFile());
58 }
59
60 @Test
61 public void checkifAndResDecodeRemapsRFolderInRawMode() throws BrutException, IOException {
62 String apk = "issue1170.apk";
63 ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
64 sTestOrigDir = new ExtFile(sTmpDir + File.separator + apk + ".raw.out");
65
66 apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".raw.out"));
67 apkDecoder.setDecodeResources(ApkDecoder.DECODE_RESOURCES_NONE);
68 apkDecoder.decode();
69
70 File aPng = new File(sTestOrigDir,"r/a/a.png");
71 assertTrue(aPng.isFile());
72 }
73 }