mirror of
https://github.com/revanced/Apktool.git
synced 2024-12-04 18:12:54 +01:00
Add unit tests
- add APK file containing a simple app that tries to use coroutines every 2 seconds, and would fail with earlier versions of APKTool - add unit test for decoding the app
This commit is contained in:
parent
fa99bdd19d
commit
cfd50acd1d
@ -568,6 +568,7 @@ public class Androlib {
|
||||
buildLibrary(appDir, "lib");
|
||||
buildLibrary(appDir, "libs");
|
||||
buildLibrary(appDir, "kotlin");
|
||||
buildLibrary(appDir, "META-INF/services");
|
||||
}
|
||||
|
||||
public void buildLibrary(File appDir, String folder) throws AndrolibException {
|
||||
@ -756,6 +757,7 @@ public class Androlib {
|
||||
return ! stored.exists() || BrutIO.recursiveModifiedTime(working) > BrutIO .recursiveModifiedTime(stored);
|
||||
}
|
||||
|
||||
|
||||
private boolean isFile(File working) {
|
||||
return working.exists();
|
||||
}
|
||||
|
@ -0,0 +1,107 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||
* Copyright (C) 2018 Connor Tumbleson <connor.tumbleson@gmail.com>
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package brut.androlib.decode;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import brut.androlib.Androlib;
|
||||
import brut.androlib.AndrolibException;
|
||||
import brut.androlib.ApkDecoder;
|
||||
import brut.androlib.BaseTest;
|
||||
import brut.androlib.TestUtils;
|
||||
import brut.common.BrutException;
|
||||
import brut.directory.DirectoryException;
|
||||
import brut.directory.ExtFile;
|
||||
import brut.util.OS;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Adib Faramarzi <adibfara@gmail.com>
|
||||
*/
|
||||
public class DecodeKotlinCoroutinesTest extends BaseTest {
|
||||
private static String apk = "test-kotlin-coroutines.apk";
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
TestUtils.cleanFrameworkFile();
|
||||
sTmpDir = new ExtFile(OS.createTempDirectory());
|
||||
TestUtils.copyResourceDir(DecodeKotlinCoroutinesTest.class, "decode/kotlin-coroutines/", sTmpDir);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws BrutException {
|
||||
OS.rmdir(sTmpDir);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void kotlinCoroutinesDecodeTest() throws IOException, AndrolibException, DirectoryException {
|
||||
|
||||
// decode kotlin coroutines
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
|
||||
apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out"));
|
||||
apkDecoder.setForceDelete(true);
|
||||
apkDecoder.decode();
|
||||
File coroutinesExceptionHandler = new File(sTmpDir + File.separator + apk + ".out"+File.separator + "META-INF" + File.separator + "services", "kotlinx.coroutines.CoroutineExceptionHandler");
|
||||
File coroutinenMainDispatcherHandler = new File(sTmpDir + File.separator + apk + ".out"+File.separator + "META-INF" + File.separator + "services", "kotlinx.coroutines.internal.MainDispatcherFactory");
|
||||
|
||||
assert (coroutinesExceptionHandler.exists());
|
||||
assert (coroutinenMainDispatcherHandler.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kotlinCoroutinesEncodeAfterDecodeTest() throws IOException, BrutException {
|
||||
|
||||
// decode kotlin coroutines
|
||||
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + apk));
|
||||
apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out"));
|
||||
apkDecoder.setForceDelete(true);
|
||||
apkDecoder.decode();
|
||||
|
||||
// build kotlin coroutines
|
||||
ExtFile testApk = new ExtFile(sTmpDir, apk + ".out");
|
||||
new Androlib().build(testApk, null);
|
||||
String newApk = apk + ".out" + File.separator + "dist" + File.separator + apk;
|
||||
assertTrue(fileExists(newApk));
|
||||
|
||||
// decode kotlin coroutines again
|
||||
apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + newApk));
|
||||
apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out.two"));
|
||||
apkDecoder.setForceDelete(true);
|
||||
apkDecoder.decode();
|
||||
|
||||
Files.readAllBytes(Paths.get(sTmpDir + File.separator + apk + ".out.two" + File.separator + "AndroidManifest.xml"));
|
||||
File coroutinesExceptionHandler = new File(sTmpDir + File.separator + apk + ".out.two" + File.separator + "META-INF" + File.separator + "services", "kotlinx.coroutines.CoroutineExceptionHandler");
|
||||
File coroutinenMainDispatcherHandler = new File(sTmpDir + File.separator + apk + ".out.two" + File.separator + "META-INF" + File.separator + "services", "kotlinx.coroutines.internal.MainDispatcherFactory");
|
||||
|
||||
assert (coroutinesExceptionHandler.exists());
|
||||
assert (coroutinenMainDispatcherHandler.exists());
|
||||
}
|
||||
|
||||
private boolean fileExists(String filepath) {
|
||||
return Files.exists(Paths.get(sTmpDir.getAbsolutePath() + File.separator + filepath));
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user