Debian Codegraph @

brut.apktool/apktool-lib/src/test/java/brut/androlib/decode/ExternalEntityTest.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.Androlib;
20 import brut.androlib.ApkDecoder;
21 import brut.androlib.BaseTest;
22 import brut.androlib.TestUtils;
23 import brut.directory.ExtFile;
24 import brut.common.BrutException;
25 import brut.util.OS;
26 import org.junit.AfterClass;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
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.junit.Assert.assertEquals;
36
37 public class ExternalEntityTest extends BaseTest {
38
39 @BeforeClass
40 public static void beforeClass() throws Exception {
41 sTestOrigDir = new ExtFile(OS.createTempDirectory());
42 TestUtils.copyResourceDir(ExternalEntityTest.class, "decode/doctype/", sTestOrigDir);
43
44 LOGGER.info("Building doctype.apk...");
45 File testApk = new File(sTestOrigDir, "doctype.apk");
46 new Androlib().build(sTestOrigDir, testApk);
47
48 LOGGER.info("Decoding doctype.apk...");
49 ApkDecoder apkDecoder = new ApkDecoder(testApk);
50 apkDecoder.setOutDir(new File(sTestOrigDir + File.separator + "output"));
51 apkDecoder.decode();
52 }
53
54 @AfterClass
55 public static void afterClass() throws BrutException {
56 OS.rmdir(sTestOrigDir);
57 }
58
59 @Test
60 public void doctypeTest() throws IOException {
61
62 String expected = TestUtils.replaceNewlines("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
63 "<manifest android:versionCode=\"1\" android:versionName=\"1.0\" android:compileSdkVersion=\"23\" android:compileSdkVersionCodename=\"6.0-2438415\" " +
64 "hardwareAccelerated=\"true\" package=\"com.ibotpeaches.doctype\" platformBuildVersionCode=\"24\" platformBuildVersionName=\"6.0-2456767\" " +
65 "xmlns:android=\"http://schemas.android.com/apk/res/android\"> <supports-screens android:anyDensity=\"true\" android:smallScreens=\"true\" " +
66 "android:normalScreens=\"true\" android:largeScreens=\"true\" android:resizeable=\"true\" android:xlargeScreens=\"true\" /></manifest>");
67
68 byte[] encoded = Files.readAllBytes(Paths.get(sTestOrigDir + File.separator + "output" + File.separator + "AndroidManifest.xml"));
69 String obtained = TestUtils.replaceNewlines(new String(encoded));
70 assertEquals(expected, obtained);
71 }
72 }