Debian Codegraph @

brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt2/DebuggableFalseChangeToTrueTest.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.aapt2;
18
19 import brut.androlib.*;
20 import brut.androlib.options.BuildOptions;
21 import brut.common.BrutException;
22 import brut.directory.ExtFile;
23 import brut.util.OS;
24 import org.custommonkey.xmlunit.XMLUnit;
25 import org.junit.AfterClass;
26 import org.junit.BeforeClass;
27 import org.junit.Test;
28 import org.xml.sax.SAXException;
29
30 import java.io.File;
31 import java.io.IOException;
32 import java.nio.file.Files;
33 import java.nio.file.Paths;
34
35 import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
36 import static org.junit.Assert.assertTrue;
37
38 public class DebuggableFalseChangeToTrueTest extends BaseTest {
39
40 @BeforeClass
41 public static void beforeClass() throws Exception {
42 TestUtils.cleanFrameworkFile();
43 sTmpDir = new ExtFile(OS.createTempDirectory());
44 sTestOrigDir = new ExtFile(sTmpDir, "issue2328-debuggable-false-orig");
45 sTestNewDir = new ExtFile(sTmpDir, "issue2328-debuggable-flase-new");
46 LOGGER.info("Unpacking issue2328-debuggable-flase...");
47 TestUtils.copyResourceDir(DebuggableFalseChangeToTrueTest.class, "aapt2/issue2328/debuggable-false", sTestOrigDir);
48
49 LOGGER.info("Building issue2328-debuggable-flase.apk...");
50 BuildOptions buildOptions = new BuildOptions();
51 buildOptions.debugMode = true;
52 buildOptions.useAapt2 = true;
53 buildOptions.verbose = true;
54
55 File testApk = new File(sTmpDir, "issue2328-debuggable-flase.apk");
56 new Androlib(buildOptions).build(sTestOrigDir, testApk);
57
58 LOGGER.info("Decoding issue2328-debuggable-flase.apk...");
59 ApkDecoder apkDecoder = new ApkDecoder(testApk);
60 apkDecoder.setOutDir(sTestNewDir);
61 apkDecoder.decode();
62 }
63
64 @AfterClass
65 public static void afterClass() throws BrutException {
66 OS.rmdir(sTmpDir);
67 }
68
69 @Test
70 public void buildAndDecodeTest() {
71 assertTrue(sTestNewDir.isDirectory());
72 }
73
74 @Test
75 public void DebugIsTruePriorToBeingFalseTest() throws IOException, SAXException {
76 String apk = "issue2328-debuggable-flase-new";
77
78 String expected = TestUtils.replaceNewlines("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>" +
79 "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" android:compileSdkVersion=\"23\" " +
80 "android:compileSdkVersionCodename=\"6.0-2438415\" package=\"com.ibotpeaches.issue2328\" platformBuildVersionCode=\"23\" " +
81 "platformBuildVersionName=\"6.0-2438415\"> <application android:debuggable=\"true\"/></manifest>");
82
83 byte[] encoded = Files.readAllBytes(Paths.get(sTmpDir + File.separator + apk + File.separator + "AndroidManifest.xml"));
84 String obtained = TestUtils.replaceNewlines(new String(encoded));
85
86 XMLUnit.setIgnoreWhitespace(true);
87 XMLUnit.setIgnoreAttributeOrder(true);
88 XMLUnit.setCompareUnmatched(false);
89
90 assertXMLEqual(expected, obtained);
91 }
92 }