Debian Codegraph @

brut.apktool/apktool-lib/src/test/java/brut/androlib/decode/DecodeKotlinCoroutinesTest.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.*;
20 import brut.common.BrutException;
21 import brut.directory.DirectoryException;
22 import brut.directory.ExtFile;
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 import java.nio.file.Files;
31 import java.nio.file.Paths;
32
33 import static org.junit.Assert.assertTrue;
34
35 public class DecodeKotlinCoroutinesTest extends BaseTest {
36 private static final String apk = "test-kotlin-coroutines.apk";
37
38 @BeforeClass
39 public static void beforeClass() throws Exception {
40 TestUtils.cleanFrameworkFile();
41 sTmpDir = new ExtFile(OS.createTempDirectory());
42 TestUtils.copyResourceDir(DecodeKotlinCoroutinesTest.class, "decode/kotlin-coroutines/", sTmpDir);
43 }
44
45 @AfterClass
46 public static void afterClass() throws BrutException {
47 OS.rmdir(sTmpDir);
48 }
49
50
51 @Test
52 public void kotlinCoroutinesDecodeTest() throws IOException, AndrolibException, DirectoryException {
53
54 // decode kotlin coroutines
55 ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
56 apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out"));
57 apkDecoder.setForceDelete(true);
58 apkDecoder.decode();
59 File coroutinesExceptionHandler = new File(sTmpDir + File.separator + apk + ".out" + File.separator + "META-INF" + File.separator + "services", "kotlinx.coroutines.CoroutineExceptionHandler");
60 File coroutinenMainDispatcherHandler = new File(sTmpDir + File.separator + apk + ".out" + File.separator + "META-INF" + File.separator + "services", "kotlinx.coroutines.internal.MainDispatcherFactory");
61
62 assert (coroutinesExceptionHandler.exists());
63 assert (coroutinenMainDispatcherHandler.exists());
64 }
65
66 @Test
67 public void kotlinCoroutinesEncodeAfterDecodeTest() throws IOException, BrutException {
68
69 // decode kotlin coroutines
70 ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
71 apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out"));
72 apkDecoder.setForceDelete(true);
73 apkDecoder.decode();
74
75 // build kotlin coroutines
76 ExtFile testApk = new ExtFile(sTmpDir, apk + ".out");
77 new Androlib().build(testApk, null);
78 String newApk = apk + ".out" + File.separator + "dist" + File.separator + apk;
79 assertTrue(fileExists(newApk));
80
81 // decode kotlin coroutines again
82 apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + newApk));
83 apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out.two"));
84 apkDecoder.setForceDelete(true);
85 apkDecoder.decode();
86
87 Files.readAllBytes(Paths.get(sTmpDir + File.separator + apk + ".out.two" + File.separator + "AndroidManifest.xml"));
88 File coroutinesExceptionHandler = new File(sTmpDir + File.separator + apk + ".out.two" + File.separator + "META-INF" + File.separator + "services", "kotlinx.coroutines.CoroutineExceptionHandler");
89 File coroutinenMainDispatcherHandler = new File(sTmpDir + File.separator + apk + ".out.two" + File.separator + "META-INF" + File.separator + "services", "kotlinx.coroutines.internal.MainDispatcherFactory");
90
91 assert (coroutinesExceptionHandler.exists());
92 assert (coroutinenMainDispatcherHandler.exists());
93 }
94
95 private boolean fileExists(String filepath) {
96 return Files.exists(Paths.get(sTmpDir.getAbsolutePath() + File.separator + filepath));
97 }
98 }