diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndResGuardTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndResGuardTest.java index 95ec40fa..e4ffd699 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndResGuardTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndResGuardTest.java @@ -25,7 +25,7 @@ import java.io.IOException; import org.junit.*; import static org.junit.Assert.*; -public class AndResGuardTest { +public class AndResGuardTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -50,15 +50,7 @@ public class AndResGuardTest { apkDecoder.setOutDir(new File(sTmpDir + File.separator + apk + ".out")); apkDecoder.decode(); - checkFileExists("res/mipmap-hdpi-v4/a.png"); + File aPng = new File(sTestOrigDir,"res/mipmap-hdpi-v4/a.png"); + assertTrue(aPng.isFile()); } - - private void checkFileExists(String path) throws BrutException { - File f = new File(sTestOrigDir, path); - - assertTrue(f.isFile()); - } - - private static ExtFile sTmpDir; - private static ExtFile sTestOrigDir; } \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndroidOreoNotSparseTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndroidOreoNotSparseTest.java index 6f54061c..89e415d9 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndroidOreoNotSparseTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndroidOreoNotSparseTest.java @@ -24,14 +24,13 @@ import org.junit.BeforeClass; import org.junit.Test; import java.io.File; -import java.util.logging.Logger; import static org.junit.Assert.assertTrue; /** * @author Connor Tumbleson */ -public class AndroidOreoNotSparseTest { +public class AndroidOreoNotSparseTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { TestUtils.cleanFrameworkFile(); @@ -59,14 +58,8 @@ public class AndroidOreoNotSparseTest { } @Test - public void buildAndDecodeTest() throws BrutException { + public void buildAndDecodeTest() { assertTrue(sTestNewDir.isDirectory()); assertTrue(sTestOrigDir.isDirectory()); } - - private static ExtFile sTmpDir; - private static ExtFile sTestOrigDir; - private static ExtFile sTestNewDir; - - private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeJarTest.class.getName()); } \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndroidOreoSparseTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndroidOreoSparseTest.java index cdd7b788..409aa336 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndroidOreoSparseTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/AndroidOreoSparseTest.java @@ -24,14 +24,13 @@ import org.junit.BeforeClass; import org.junit.Test; import java.io.File; -import java.util.logging.Logger; import static org.junit.Assert.assertTrue; /** * @author Connor Tumbleson */ -public class AndroidOreoSparseTest { +public class AndroidOreoSparseTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { TestUtils.cleanFrameworkFile(); @@ -59,19 +58,13 @@ public class AndroidOreoSparseTest { } @Test - public void buildAndDecodeTest() throws BrutException { + public void buildAndDecodeTest() { assertTrue(sTestNewDir.isDirectory()); assertTrue(sTestOrigDir.isDirectory()); } @Test - public void ensureStringsOreoTest() throws BrutException { + public void ensureStringsOreoTest() { assertTrue((new File(sTestNewDir, "res/values-v26/strings.xml").isFile())); } - - private static ExtFile sTmpDir; - private static ExtFile sTestOrigDir; - private static ExtFile sTestNewDir; - - private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeJarTest.class.getName()); } \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/BaseTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/BaseTest.java new file mode 100644 index 00000000..990b170d --- /dev/null +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/BaseTest.java @@ -0,0 +1,137 @@ +/** + * Copyright (C) 2017 Ryszard Wiśniewski + * Copyright (C) 2017 Connor Tumbleson + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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; + +import brut.androlib.meta.MetaInfo; +import brut.common.BrutException; +import brut.directory.ExtFile; +import brut.directory.FileDirectory; +import org.custommonkey.xmlunit.DetailedDiff; +import org.custommonkey.xmlunit.Diff; +import org.custommonkey.xmlunit.ElementNameAndAttributeQualifier; +import org.custommonkey.xmlunit.ElementQualifier; +import org.xml.sax.SAXException; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.util.Map; +import java.util.Set; +import java.util.logging.Logger; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class BaseTest { + + void compareUnknownFiles() throws BrutException { + MetaInfo control = new Androlib().readMetaFile(sTestOrigDir); + MetaInfo test = new Androlib().readMetaFile(sTestNewDir); + assertNotNull(control.unknownFiles); + assertNotNull(test.unknownFiles); + + Map controlFiles = control.unknownFiles; + Map testFiles = test.unknownFiles; + assertTrue(controlFiles.size() == testFiles.size()); + + // Make sure that the compression methods are still the same + for (Map.Entry controlEntry : controlFiles.entrySet()) { + assertTrue(controlEntry.getValue().equals(testFiles.get(controlEntry.getKey()))); + } + } + + void compareBinaryFolder(String path, boolean res) throws BrutException, IOException { + Boolean exists = true; + + String prefixPath = ""; + if (res) { + prefixPath = File.separatorChar + "res" + File.separatorChar; + } + + String location = prefixPath + path; + + FileDirectory fileDirectory = new FileDirectory(sTestOrigDir, location); + + Set files = fileDirectory.getFiles(true); + for (String filename : files) { + + File control = new File((sTestOrigDir + location), filename); + File test = new File((sTestNewDir + location), filename); + + if (! test.isFile() || ! control.isFile()) { + exists = false; + } + } + + assertTrue(exists); + } + + void compareResFolder(String path) throws BrutException, IOException { + compareBinaryFolder(path, true); + } + + void compareLibsFolder(String path) throws BrutException, IOException { + compareBinaryFolder(File.separatorChar + path, false); + } + + void compareAssetsFolder(String path) throws BrutException, IOException { + compareBinaryFolder(File.separatorChar + "assets" + File.separatorChar + path, false); + } + + void compareValuesFiles(String path) throws BrutException { + compareXmlFiles("res/" + path, new ElementNameAndAttributeQualifier("name")); + } + + void compareXmlFiles(String path) throws BrutException { + compareXmlFiles(path, null); + } + + void checkFolderExists(String path) { + File f = new File(sTestNewDir, path); + + assertTrue(f.isDirectory()); + } + + boolean isTransparent(int pixel) { + return pixel >> 24 == 0x00; + } + + private void compareXmlFiles(String path, ElementQualifier qualifier) throws BrutException { + DetailedDiff diff; + try { + Reader control = new FileReader(new File(sTestOrigDir, path)); + Reader test = new FileReader(new File(sTestNewDir, path)); + + diff = new DetailedDiff(new Diff(control, test)); + } catch (SAXException | IOException ex) { + throw new BrutException(ex); + } + + if (qualifier != null) { + diff.overrideElementQualifier(qualifier); + } + + assertTrue(path + ": " + diff.getAllDifferences().toString(), diff.similar()); + } + + protected static ExtFile sTmpDir; + protected static ExtFile sTestOrigDir; + protected static ExtFile sTestNewDir; + + protected final static Logger LOGGER = Logger.getLogger(BaseTest.class.getName()); +} diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeJarTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeJarTest.java index 872e3c88..7485167e 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeJarTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeJarTest.java @@ -24,14 +24,13 @@ import org.junit.BeforeClass; import org.junit.Test; import java.io.File; -import java.util.logging.Logger; import static org.junit.Assert.assertTrue; /** * @author Connor Tumbleson */ -public class BuildAndDecodeJarTest { +public class BuildAndDecodeJarTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -61,10 +60,4 @@ public class BuildAndDecodeJarTest { public void buildAndDecodeTest() throws BrutException { assertTrue(sTestNewDir.isDirectory()); } - - private static ExtFile sTmpDir; - private static ExtFile sTestOrigDir; - private static ExtFile sTestNewDir; - - private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeJarTest.class.getName()); } \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java index 6e666609..2bef848d 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java @@ -16,33 +16,26 @@ */ package brut.androlib; -import brut.androlib.meta.MetaInfo; import brut.directory.ExtFile; import brut.common.BrutException; -import brut.directory.FileDirectory; import brut.util.OS; import java.awt.image.BufferedImage; import java.io.*; import java.util.Map; -import java.util.Set; -import java.util.logging.Logger; import brut.util.OSDetection; -import org.custommonkey.xmlunit.*; import org.junit.*; import static org.junit.Assert.*; import static org.junit.Assume.*; -import org.xml.sax.SAXException; - import javax.imageio.ImageIO; /** * @author Ryszard Wiśniewski */ -public class BuildAndDecodeTest { +public class BuildAndDecodeTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -500,10 +493,11 @@ public class BuildAndDecodeTest { @Test public void libsTest() throws BrutException, IOException { compareLibsFolder("libs"); + compareLibsFolder("lib"); } @Test - public void unknownFolderTest() throws BrutException, IOException { + public void unknownFolderTest() throws BrutException { compareUnknownFiles(); } @@ -529,104 +523,7 @@ public class BuildAndDecodeTest { } @Test - public void confirmKotlinFolderPersistsTest() throws BrutException, IOException { + public void confirmKotlinFolderPersistsTest() { checkFolderExists("/kotlin"); } - - @SuppressWarnings("unchecked") - private void compareUnknownFiles() throws BrutException, IOException { - MetaInfo control = new Androlib().readMetaFile(sTestOrigDir); - MetaInfo test = new Androlib().readMetaFile(sTestNewDir); - assertNotNull(control.unknownFiles); - assertNotNull(test.unknownFiles); - - Map control_files = control.unknownFiles; - Map test_files = test.unknownFiles; - assertTrue(control_files.size() == test_files.size()); - - // Make sure that the compression methods are still the same - for (Map.Entry controlEntry : control_files.entrySet()) { - assertTrue(controlEntry.getValue().equals(test_files.get(controlEntry.getKey()))); - } - } - - private void compareBinaryFolder(String path, boolean res) throws BrutException, IOException { - Boolean exists = true; - - String tmp = ""; - if (res) { - tmp = File.separatorChar + "res" + File.separatorChar; - } - - String location = tmp + path; - - FileDirectory fileDirectory = new FileDirectory(sTestOrigDir, location); - - Set files = fileDirectory.getFiles(true); - for (String filename : files) { - - File control = new File((sTestOrigDir + location), filename); - File test = new File((sTestNewDir + location), filename); - - if (! test.isFile() || ! control.isFile()) { - exists = false; - } - } - - assertTrue(exists); - } - - private void compareResFolder(String path) throws BrutException, IOException { - compareBinaryFolder(path, true); - } - - private void compareLibsFolder(String path) throws BrutException, IOException { - compareBinaryFolder(File.separatorChar + path, false); - } - - private void compareAssetsFolder(String path) throws BrutException, IOException { - compareBinaryFolder(File.separatorChar + "assets" + File.separatorChar + path, false); - } - - private void compareValuesFiles(String path) throws BrutException { - compareXmlFiles("res/" + path, new ElementNameAndAttributeQualifier("name")); - } - - private void compareXmlFiles(String path) throws BrutException { - compareXmlFiles(path, null); - } - - private void checkFolderExists(String path) throws BrutException { - File f = new File(sTestNewDir, path); - - assertTrue(f.isDirectory()); - } - - private boolean isTransparent(int pixel) { - return pixel >> 24 == 0x00; - } - - private void compareXmlFiles(String path, ElementQualifier qualifier) throws BrutException { - DetailedDiff diff; - try { - Reader control = new FileReader(new File(sTestOrigDir, path)); - Reader test = new FileReader(new File(sTestNewDir, path)); - - diff = new DetailedDiff(new Diff(control, test)); - } catch (SAXException | IOException ex) { - throw new BrutException(ex); - } - - if (qualifier != null) { - diff.overrideElementQualifier(qualifier); - } - - assertTrue(path + ": " + diff.getAllDifferences().toString(), diff.similar()); - } - - private static ExtFile sTmpDir; - private static ExtFile sTestOrigDir; - private static ExtFile sTestNewDir; - - private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeTest.class.getName()); } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/DebugTagRetainedTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/DebugTagRetainedTest.java index 4b0c183c..5fc1df83 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/DebugTagRetainedTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/DebugTagRetainedTest.java @@ -27,7 +27,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.logging.Logger; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -35,7 +34,7 @@ import static org.junit.Assert.assertTrue; /** * @author Connor Tumbleson */ -public class DebugTagRetainedTest { +public class DebugTagRetainedTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -65,12 +64,12 @@ public class DebugTagRetainedTest { } @Test - public void buildAndDecodeTest() throws BrutException { + public void buildAndDecodeTest() { assertTrue(sTestNewDir.isDirectory()); } @Test - public void DebugIsTruePriorToBeingFalseTest() throws BrutException, IOException { + public void DebugIsTruePriorToBeingFalseTest() throws IOException { String apk = "issue1235-new"; String expected = TestUtils.replaceNewlines("\n" + @@ -82,10 +81,4 @@ public class DebugTagRetainedTest { String obtained = TestUtils.replaceNewlines(new String(encoded)); assertEquals(expected, obtained); } - - private static ExtFile sTmpDir; - private static ExtFile sTestOrigDir; - private static ExtFile sTestNewDir; - - private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeJarTest.class.getName()); } \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/DecodeKotlinTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/DecodeKotlinTest.java index 443df480..4e71e9c8 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/DecodeKotlinTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/DecodeKotlinTest.java @@ -33,7 +33,7 @@ import static org.junit.Assert.assertTrue; /** * @author Connor Tumbleson */ -public class DecodeKotlinTest { +public class DecodeKotlinTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -57,7 +57,7 @@ public class DecodeKotlinTest { } @Test - public void kotlinFolderExistsTest() throws BrutException { + public void kotlinFolderExistsTest() { assertTrue(sTestNewDir.isDirectory()); File testKotlinFolder = new File(sTestNewDir, "kotlin"); @@ -65,14 +65,9 @@ public class DecodeKotlinTest { } @Test - public void kotlinDecodeTest() throws BrutException, IOException { + public void kotlinDecodeTest() throws IOException { File kotlinActivity = new File(sTestNewDir, "smali/org/example/kotlin/mixed/KotlinActivity.smali"); assertTrue(FileUtils.readFileToString(kotlinActivity).contains("KotlinActivity.kt")); } - - private static ExtFile sTmpDir; - private static ExtFile sTestNewDir; - - private final static Logger LOGGER = Logger.getLogger(DecodeKotlinTest.class.getName()); } \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/DefaultBaksmaliVariableTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/DefaultBaksmaliVariableTest.java index f5ee9f08..a31940e0 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/DefaultBaksmaliVariableTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/DefaultBaksmaliVariableTest.java @@ -27,11 +27,10 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.logging.Logger; import static org.junit.Assert.assertEquals; -public class DefaultBaksmaliVariableTest { +public class DefaultBaksmaliVariableTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -110,10 +109,4 @@ public class DefaultBaksmaliVariableTest { String obtained = TestUtils.replaceNewlines(new String(encoded)); assertEquals(expected, obtained); } - - private static ExtFile sTmpDir; - private static ExtFile sTestOrigDir; - private static ExtFile sTestNewDir; - - private final static Logger LOGGER = Logger.getLogger(DefaultBaksmaliVariableTest.class.getName()); } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/DoubleExtensionUnknownFileTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/DoubleExtensionUnknownFileTest.java index c4e8a955..f160b988 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/DoubleExtensionUnknownFileTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/DoubleExtensionUnknownFileTest.java @@ -33,7 +33,7 @@ import static org.junit.Assert.assertTrue; /** * @author Connor Tumbleson */ -public class DoubleExtensionUnknownFileTest { +public class DoubleExtensionUnknownFileTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -64,6 +64,4 @@ public class DoubleExtensionUnknownFileTest { } } } - - private static ExtFile sTmpDir; } \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/ExternalEntityTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/ExternalEntityTest.java index f21dcd42..a72f350f 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/ExternalEntityTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/ExternalEntityTest.java @@ -27,37 +27,36 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.logging.Logger; import static org.junit.Assert.assertEquals; /** * @author Connor Tumbleson */ -public class ExternalEntityTest { +public class ExternalEntityTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { - sOrigDir = new ExtFile(OS.createTempDirectory()); - TestUtils.copyResourceDir(ExternalEntityTest.class, "brut/apktool/doctype/", sOrigDir); + sTestOrigDir = new ExtFile(OS.createTempDirectory()); + TestUtils.copyResourceDir(ExternalEntityTest.class, "brut/apktool/doctype/", sTestOrigDir); LOGGER.info("Building doctype.apk..."); - File testApk = new File(sOrigDir, "doctype.apk"); - new Androlib().build(sOrigDir, testApk); + File testApk = new File(sTestOrigDir, "doctype.apk"); + new Androlib().build(sTestOrigDir, testApk); LOGGER.info("Decoding doctype.apk..."); ApkDecoder apkDecoder = new ApkDecoder(testApk); - apkDecoder.setOutDir(new File(sOrigDir + File.separator + "output")); + apkDecoder.setOutDir(new File(sTestOrigDir + File.separator + "output")); apkDecoder.decode(); } @AfterClass public static void afterClass() throws BrutException { - OS.rmdir(sOrigDir); + OS.rmdir(sTestOrigDir); } @Test - public void doctypeTest() throws BrutException, IOException { + public void doctypeTest() throws IOException { String expected = TestUtils.replaceNewlines("\n" + "\n" + ""); - byte[] encoded = Files.readAllBytes(Paths.get(sOrigDir + File.separator + "output" + File.separator + "AndroidManifest.xml")); + byte[] encoded = Files.readAllBytes(Paths.get(sTestOrigDir + File.separator + "output" + File.separator + "AndroidManifest.xml")); String obtained = TestUtils.replaceNewlines(new String(encoded)); assertEquals(expected, obtained); } - - private static ExtFile sOrigDir; - - private final static Logger LOGGER = Logger.getLogger(ExternalEntityTest.class.getName()); } \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/ForceManifestDecodeNoResourcesTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/ForceManifestDecodeNoResourcesTest.java index e1efc63a..ff890a53 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/ForceManifestDecodeNoResourcesTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/ForceManifestDecodeNoResourcesTest.java @@ -30,7 +30,7 @@ import java.util.Arrays; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -public class ForceManifestDecodeNoResourcesTest { +public class ForceManifestDecodeNoResourcesTest extends BaseTest { private byte[] xmlHeader = new byte[] { 0x3C, // < @@ -139,6 +139,4 @@ public class ForceManifestDecodeNoResourcesTest { apkDecoder.setOutDir(new File(output)); apkDecoder.decode(); } - - private static ExtFile sTmpDir; -} +} \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/InvalidSdkBoundingTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/InvalidSdkBoundingTest.java index 3f118f00..5fc16991 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/InvalidSdkBoundingTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/InvalidSdkBoundingTest.java @@ -17,8 +17,6 @@ package brut.androlib; import brut.androlib.res.AndrolibResources; -import brut.common.BrutException; -import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; @@ -26,10 +24,10 @@ import org.junit.*; import static org.junit.Assert.assertEquals; -public class InvalidSdkBoundingTest { +public class InvalidSdkBoundingTest extends BaseTest { @Test - public void checkIfInvalidValuesPass() throws BrutException, IOException { + public void checkIfInvalidValuesPass() { AndrolibResources androlibResources = new AndrolibResources(); Map sdkInfo = new LinkedHashMap<>(); @@ -42,7 +40,7 @@ public class InvalidSdkBoundingTest { } @Test - public void checkIfMissingMinPasses() throws BrutException, IOException { + public void checkIfMissingMinPasses() { AndrolibResources androlibResources = new AndrolibResources(); Map sdkInfo = new LinkedHashMap<>(); @@ -54,7 +52,7 @@ public class InvalidSdkBoundingTest { } @Test - public void checkIfMissingMaxPasses() throws BrutException, IOException { + public void checkIfMissingMaxPasses() { AndrolibResources androlibResources = new AndrolibResources(); Map sdkInfo = new LinkedHashMap<>(); @@ -66,7 +64,7 @@ public class InvalidSdkBoundingTest { } @Test - public void checkIfMissingBothPasses() throws BrutException, IOException { + public void checkIfMissingBothPasses() { AndrolibResources androlibResources = new AndrolibResources(); Map sdkInfo = new LinkedHashMap<>(); @@ -78,7 +76,7 @@ public class InvalidSdkBoundingTest { @Test - public void checkForShortHandSdkTag() throws BrutException, IOException { + public void checkForShortHandSdkTag() { AndrolibResources androlibResources = new AndrolibResources(); Map sdkInfo = new LinkedHashMap<>(); diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/LargeIntsInManifestTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/LargeIntsInManifestTest.java index 449d52f4..025f3a46 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/LargeIntsInManifestTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/LargeIntsInManifestTest.java @@ -19,16 +19,12 @@ package brut.androlib; import brut.directory.ExtFile; import brut.common.BrutException; import brut.util.OS; -import java.io.*; import java.io.File; import java.io.IOException; -import org.custommonkey.xmlunit.*; import org.junit.*; -import static org.junit.Assert.*; -import org.xml.sax.SAXException; -public class LargeIntsInManifestTest { +public class LargeIntsInManifestTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -67,30 +63,4 @@ public class LargeIntsInManifestTest { compareXmlFiles("AndroidManifest.xml"); } - - private void compareXmlFiles(String path) throws BrutException { - compareXmlFiles(path, null); - } - - private void compareXmlFiles(String path, ElementQualifier qualifier) throws BrutException { - DetailedDiff diff; - try { - Reader control = new FileReader(new File(sTestOrigDir, path)); - Reader test = new FileReader(new File(sTestNewDir, path)); - - diff = new DetailedDiff(new Diff(control, test)); - } catch (SAXException | IOException ex) { - throw new BrutException(ex); - } - - if (qualifier != null) { - diff.overrideElementQualifier(qualifier); - } - - assertTrue(path + ": " + diff.getAllDifferences().toString(), diff.similar()); - } - - private static ExtFile sTmpDir; - private static ExtFile sTestOrigDir; - private static ExtFile sTestNewDir; } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/MinifiedArscTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/MinifiedArscTest.java index c97ad97c..277a2c13 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/MinifiedArscTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/MinifiedArscTest.java @@ -33,7 +33,7 @@ import static org.junit.Assert.assertEquals; /** * @author Connor Tumbleson */ -public class MinifiedArscTest { +public class MinifiedArscTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -42,12 +42,12 @@ public class MinifiedArscTest { TestUtils.copyResourceDir(MinifiedArscTest.class, "brut/apktool/issue1157/", sTmpDir); String apk = "issue1157.apk"; - sDecodedDir = new ExtFile(sTmpDir, "issue1157"); + sTestNewDir = new ExtFile(sTmpDir, "issue1157"); // decode issue1157.apk ApkDecoder apkDecoder = new ApkDecoder(new ExtFile(sTmpDir, apk)); apkDecoder.setForceDelete(true); - apkDecoder.setOutDir(sDecodedDir); + apkDecoder.setOutDir(sTestNewDir); // this should not raise an exception: apkDecoder.decode(); @@ -66,11 +66,8 @@ public class MinifiedArscTest { " \n" + ""); - byte[] encoded = Files.readAllBytes(Paths.get(sDecodedDir + File.separator + "res" + File.separator + "xml" + File.separator + "custom.xml")); + byte[] encoded = Files.readAllBytes(Paths.get(sTestNewDir + File.separator + "res" + File.separator + "xml" + File.separator + "custom.xml")); String obtained = TestUtils.replaceNewlines(new String(encoded)); assertEquals(expected, obtained); } - - private static ExtFile sDecodedDir; - private static ExtFile sTmpDir; } \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/MissingVersionManifestTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/MissingVersionManifestTest.java index 81cde462..b6bda206 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/MissingVersionManifestTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/MissingVersionManifestTest.java @@ -26,14 +26,13 @@ import org.junit.Test; import java.io.File; import java.io.IOException; -import java.util.logging.Logger; import static org.junit.Assert.assertEquals; /** * @author Connor Tumbleson */ -public class MissingVersionManifestTest { +public class MissingVersionManifestTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -60,6 +59,4 @@ public class MissingVersionManifestTest { MetaInfo metaInfo = new Androlib().readMetaFile(decodedApk); assertEquals(null, metaInfo.versionInfo.versionName); } - - private static ExtFile sTmpDir; } \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/OutsideOfDirectoryEntryTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/OutsideOfDirectoryEntryTest.java index 6bbad9c1..d1b1b7aa 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/OutsideOfDirectoryEntryTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/OutsideOfDirectoryEntryTest.java @@ -24,7 +24,6 @@ import org.junit.BeforeClass; import org.junit.Test; import java.io.File; -import java.util.logging.Logger; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -32,7 +31,7 @@ import static org.junit.Assert.assertTrue; /** * @author Connor Tumbleson */ -public class OutsideOfDirectoryEntryTest { +public class OutsideOfDirectoryEntryTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -56,16 +55,10 @@ public class OutsideOfDirectoryEntryTest { } @Test - public void skippedDecodingOfInvalidFileTest() throws BrutException { + public void skippedDecodingOfInvalidFileTest() { assertTrue(sTestNewDir.isDirectory()); File testAssetFolder = new File(sTestNewDir, "assets"); assertFalse(testAssetFolder.isDirectory()); } - - - private static ExtFile sTmpDir; - private static ExtFile sTestNewDir; - - private final static Logger LOGGER = Logger.getLogger(OutsideOfDirectoryEntryTest.class.getName()); } \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/ParentDirectoryTraversalTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/ParentDirectoryTraversalTest.java index 2d94fae8..3b1a1a74 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/ParentDirectoryTraversalTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/ParentDirectoryTraversalTest.java @@ -26,7 +26,7 @@ import org.junit.Test; import java.io.File; import java.io.IOException; -public class ParentDirectoryTraversalTest { +public class ParentDirectoryTraversalTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -53,6 +53,4 @@ public class ParentDirectoryTraversalTest { // this should not raise an exception: apkDecoder.decode(); } - - private static ExtFile sTmpDir; } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/PositionalEnumerationTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/PositionalEnumerationTest.java index 6b6369a7..1ada2f56 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/PositionalEnumerationTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/PositionalEnumerationTest.java @@ -24,7 +24,7 @@ import static org.junit.Assert.assertEquals; /** * @author Connor Tumbleson */ -public class PositionalEnumerationTest { +public class PositionalEnumerationTest extends BaseTest { @Test public void noArgumentsTest() { diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/ProviderAttributeTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/ProviderAttributeTest.java index 35bd2da4..1991bef0 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/ProviderAttributeTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/ProviderAttributeTest.java @@ -31,7 +31,7 @@ import java.nio.file.Paths; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -public class ProviderAttributeTest { +public class ProviderAttributeTest extends BaseTest { @BeforeClass public static void beforeClass() throws BrutException { @@ -82,6 +82,4 @@ public class ProviderAttributeTest { private boolean fileExists(String filepath) { return Files.exists(Paths.get(sTmpDir.getAbsolutePath() + File.separator + filepath)); } - - private static ExtFile sTmpDir; } \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/ReferenceVersionCodeTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/ReferenceVersionCodeTest.java index 145df027..1cbe78f5 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/ReferenceVersionCodeTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/ReferenceVersionCodeTest.java @@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals; /** * @author Connor Tumbleson */ -public class ReferenceVersionCodeTest { +public class ReferenceVersionCodeTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -59,6 +59,4 @@ public class ReferenceVersionCodeTest { MetaInfo metaInfo = new Androlib().readMetaFile(decodedApk); assertEquals("v1.0.0", metaInfo.versionInfo.versionName); } - - private static ExtFile sTmpDir; } \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/SharedLibraryTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/SharedLibraryTest.java index 2400b9fe..d7b3a292 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/SharedLibraryTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/SharedLibraryTest.java @@ -30,7 +30,7 @@ import java.nio.file.Paths; import static org.junit.Assert.assertTrue; -public class SharedLibraryTest { +public class SharedLibraryTest extends BaseTest { @BeforeClass public static void beforeClass() throws BrutException { @@ -111,6 +111,4 @@ public class SharedLibraryTest { private boolean fileExists(String filepath) { return Files.exists(Paths.get(sTmpDir.getAbsolutePath() + File.separator + filepath)); } - - private static ExtFile sTmpDir; } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/SkipAssetTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/SkipAssetTest.java index e6c35f2f..ec8c4e5e 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/SkipAssetTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/SkipAssetTest.java @@ -25,7 +25,7 @@ import java.io.IOException; import org.junit.*; import static org.junit.Assert.*; -public class SkipAssetTest { +public class SkipAssetTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -84,7 +84,4 @@ public class SkipAssetTest { assertTrue(f.isFile()); } - - private static ExtFile sTmpDir; - private static ExtFile sTestOrigDir; } \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/TestUtils.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/TestUtils.java index ec0de2ef..14068eed 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/TestUtils.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/TestUtils.java @@ -72,18 +72,11 @@ public abstract class TestUtils { } return map; - } catch (IOException ex) { - throw new BrutException(ex); - } catch (XmlPullParserException ex) { + } catch (IOException | XmlPullParserException ex) { throw new BrutException(ex); } } - /* - * TODO: move to brut.util.Jar - it's not possible for now, because below - * implementation uses brut.dir. I think I should merge all my projects to - * single brut.common . - */ public static void copyResourceDir(Class class_, String dirPath, File out) throws BrutException { if (!out.exists()) { out.mkdirs(); @@ -122,11 +115,6 @@ public abstract class TestUtils { } } - /** - * - * @throws AndrolibException - * @throws BrutException - */ public static void cleanFrameworkFile() throws AndrolibException, BrutException { File framework = new File(getFrameworkDir(), "1.apk"); @@ -135,12 +123,6 @@ public abstract class TestUtils { } } - /** - * - * @return byte[] - * @throws FileNotFoundException - * @throws IOException - */ public static byte[] readHeaderOfFile(File file, int size) throws IOException { byte[] buffer = new byte[size]; InputStream inputStream = new FileInputStream(file); @@ -152,12 +134,7 @@ public abstract class TestUtils { return buffer; } - /** - * - * @return File - * @throws AndrolibException - */ - public static File getFrameworkDir() throws AndrolibException { + static File getFrameworkDir() throws AndrolibException { AndrolibResources androlibResources = new AndrolibResources(); androlibResources.apkOptions = new ApkOptions(); return androlibResources.getFrameworkDir(); diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/UnknownCompressionTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/UnknownCompressionTest.java index a8b78c71..be1cf693 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/UnknownCompressionTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/UnknownCompressionTest.java @@ -32,7 +32,7 @@ import static org.junit.Assert.assertNotSame; /** * @author Connor Tumbleson */ -public class UnknownCompressionTest { +public class UnknownCompressionTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -44,17 +44,17 @@ public class UnknownCompressionTest { ApkOptions apkOptions = new ApkOptions(); apkOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath(); - sOriginalFile = new ExtFile(sTmpDir, apk); + sTestOrigDir = new ExtFile(sTmpDir, apk); // decode deflated_unknowns.apk - ApkDecoder apkDecoder = new ApkDecoder(sOriginalFile); - apkDecoder.setOutDir(new File(sOriginalFile.getAbsolutePath() + ".out")); + ApkDecoder apkDecoder = new ApkDecoder(sTestOrigDir); + apkDecoder.setOutDir(new File(sTestOrigDir.getAbsolutePath() + ".out")); apkDecoder.decode(); // build deflated_unknowns - ExtFile clientApkFolder = new ExtFile(sOriginalFile.getAbsolutePath() + ".out"); + ExtFile clientApkFolder = new ExtFile(sTestOrigDir.getAbsolutePath() + ".out"); new Androlib(apkOptions).build(clientApkFolder, null); - sBuiltFile = new ExtFile(clientApkFolder, "dist" + File.separator + apk); + sTestNewDir = new ExtFile(clientApkFolder, "dist" + File.separator + apk); } @AfterClass @@ -64,8 +64,8 @@ public class UnknownCompressionTest { @Test public void pkmExtensionDeflatedTest() throws BrutException, IOException { - Integer control = sOriginalFile.getDirectory().getCompressionLevel("assets/bin/Data/test.pkm"); - Integer rebuilt = sBuiltFile.getDirectory().getCompressionLevel("assets/bin/Data/test.pkm"); + Integer control = sTestOrigDir.getDirectory().getCompressionLevel("assets/bin/Data/test.pkm"); + Integer rebuilt = sTestNewDir.getDirectory().getCompressionLevel("assets/bin/Data/test.pkm"); // Check that control = rebuilt (both deflated) // Add extra check for checking not equal to 0, just in case control gets broken @@ -75,8 +75,8 @@ public class UnknownCompressionTest { @Test public void doubleExtensionStoredTest() throws BrutException, IOException { - Integer control = sOriginalFile.getDirectory().getCompressionLevel("assets/bin/Data/two.extension.file"); - Integer rebuilt = sBuiltFile.getDirectory().getCompressionLevel("assets/bin/Data/two.extension.file"); + Integer control = sTestOrigDir.getDirectory().getCompressionLevel("assets/bin/Data/two.extension.file"); + Integer rebuilt = sTestNewDir.getDirectory().getCompressionLevel("assets/bin/Data/two.extension.file"); // Check that control = rebuilt (both stored) // Add extra check for checking = 0 to enforce check for stored just in case control breaks @@ -86,8 +86,8 @@ public class UnknownCompressionTest { @Test public void confirmJsonFileIsDeflatedTest() throws BrutException, IOException { - Integer control = sOriginalFile.getDirectory().getCompressionLevel("test.json"); - Integer rebuilt = sOriginalFile.getDirectory().getCompressionLevel("test.json"); + Integer control = sTestOrigDir.getDirectory().getCompressionLevel("test.json"); + Integer rebuilt = sTestOrigDir.getDirectory().getCompressionLevel("test.json"); assertEquals(control, rebuilt); assertEquals(new Integer(8), rebuilt); @@ -95,15 +95,10 @@ public class UnknownCompressionTest { @Test public void confirmPngFileIsCorrectlyDeflatedTest() throws BrutException, IOException { - Integer control = sOriginalFile.getDirectory().getCompressionLevel("950x150.png"); - Integer rebuilt = sOriginalFile.getDirectory().getCompressionLevel("950x150.png"); + Integer control = sTestOrigDir.getDirectory().getCompressionLevel("950x150.png"); + Integer rebuilt = sTestOrigDir.getDirectory().getCompressionLevel("950x150.png"); assertEquals(control, rebuilt); assertEquals(new Integer(8), rebuilt); } - - private static ExtFile sTmpDir; - - private static ExtFile sOriginalFile; - private static ExtFile sBuiltFile; } \ No newline at end of file diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/UnknownDirectoryTraversalTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/UnknownDirectoryTraversalTest.java index 9ff37e35..a5c46947 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/UnknownDirectoryTraversalTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/UnknownDirectoryTraversalTest.java @@ -36,7 +36,7 @@ import static org.junit.Assert.assertTrue; /** * @author Connor Tumbleson */ -public class UnknownDirectoryTraversalTest { +public class UnknownDirectoryTraversalTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -74,6 +74,4 @@ public class UnknownDirectoryTraversalTest { String validFilename = BrutIO.sanitizeUnknownFile(sTmpDir, "dir" + File.separator + "file"); assertEquals("dir" + File.separator + "file", validFilename); } - - public static File sTmpDir; } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/VectorDrawableTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/VectorDrawableTest.java index 4fc5c837..503dc8f1 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/VectorDrawableTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/VectorDrawableTest.java @@ -28,7 +28,7 @@ import java.io.IOException; import static org.junit.Assert.assertTrue; -public class VectorDrawableTest { +public class VectorDrawableTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -57,12 +57,9 @@ public class VectorDrawableTest { checkFileExists("res/drawable/ic_android_black_24dp.xml"); } - private void checkFileExists(String path) throws BrutException { + private void checkFileExists(String path) { File f = new File(sTestOrigDir, path); assertTrue(f.isFile()); } - - private static ExtFile sTmpDir; - private static ExtFile sTestOrigDir; } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt2/BuildAndDecodeTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt2/BuildAndDecodeTest.java index ebc0f74a..af183295 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt2/BuildAndDecodeTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt2/BuildAndDecodeTest.java @@ -16,42 +16,22 @@ */ package brut.androlib.aapt2; -import brut.androlib.Androlib; -import brut.androlib.ApkDecoder; -import brut.androlib.ApkOptions; -import brut.androlib.TestUtils; -import brut.androlib.meta.MetaInfo; +import brut.androlib.*; import brut.common.BrutException; import brut.directory.ExtFile; -import brut.directory.FileDirectory; import brut.util.OS; -import brut.util.OSDetection; -import org.custommonkey.xmlunit.DetailedDiff; -import org.custommonkey.xmlunit.Diff; -import org.custommonkey.xmlunit.ElementNameAndAttributeQualifier; -import org.custommonkey.xmlunit.ElementQualifier; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.xml.sax.SAXException; -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.Reader; -import java.util.Map; -import java.util.Set; -import java.util.logging.Logger; import static org.junit.Assert.*; -import static org.junit.Assume.assumeTrue; /** * @author Ryszard Wiśniewski */ -public class BuildAndDecodeTest { +public class BuildAndDecodeTest extends BaseTest { @BeforeClass public static void beforeClass() throws Exception { @@ -86,555 +66,4 @@ public class BuildAndDecodeTest { public void buildAndDecodeTest() throws BrutException { assertTrue(sTestNewDir.isDirectory()); } - - @Test - public void manifestTaggingNotSupressed() throws BrutException { - compareXmlFiles("AndroidManifest.xml"); - } - - @Test - public void valuesAnimsTest() throws BrutException { - compareValuesFiles("values-mcc001/anims.xml"); - } - - @Test - public void valuesArraysTest() throws BrutException { - compareValuesFiles("values-mcc001/arrays.xml"); - } - - @Test - public void valuesArraysCastingTest() throws BrutException { - compareValuesFiles("values-mcc002/arrays.xml"); - compareValuesFiles("values-mcc003/arrays.xml"); - } - - @Test - public void valuesAttrsTest() throws BrutException { - compareValuesFiles("values/attrs.xml"); - } - - @Test - public void valuesBoolsTest() throws BrutException { - compareValuesFiles("values-mcc001/bools.xml"); - } - - @Test - public void valuesColorsTest() throws BrutException { - compareValuesFiles("values-mcc001/colors.xml"); - } - - @Test - public void bug702Test() throws BrutException { - compareValuesFiles("values-mcc001-mnc00/strings.xml"); - } - - @Test - public void valuesDimensTest() throws BrutException { - compareValuesFiles("values-mcc001/dimens.xml"); - } - - @Test - public void valuesDrawablesTest() throws BrutException { - compareValuesFiles("values-mcc001/drawables.xml"); - } - - @Test - public void valuesIdsTest() throws BrutException { - compareValuesFiles("values-mcc001/ids.xml"); - } - - @Test - public void valuesIntegersTest() throws BrutException { - compareValuesFiles("values-mcc001/integers.xml"); - } - - @Test - public void valuesLayoutsTest() throws BrutException { - compareValuesFiles("values-mcc001/layouts.xml"); - } - - @Test - public void xmlPluralsTest() throws BrutException { - compareValuesFiles("values-mcc001/plurals.xml"); - } - - @Test - public void valuesStringsTest() throws BrutException { - compareValuesFiles("values-mcc001/strings.xml"); - } - - @Test - public void valuesStylesTest() throws BrutException { - compareValuesFiles("values-mcc001/styles.xml"); - } - - @Test - public void valuesReferencesTest() throws BrutException { - compareValuesFiles("values-mcc002/strings.xml"); - } - - @Test - public void valuesExtraLongTest() throws BrutException { - compareValuesFiles("values-en/strings.xml"); - } - - @Test - public void valuesExtraLongExactLengthTest() throws BrutException { - Map strs = TestUtils.parseStringsXml(new File(sTestNewDir, "res/values-en/strings.xml")); - - // long_string6 should be exactly 0x8888 chars of "a" - // the valuesExtraLongTest() should handle this - // but such an edge case, want a specific test - String aaaa = strs.get("long_string6"); - assertEquals(0x8888, aaaa.length()); - } - - @Test - public void crossTypeTest() throws BrutException { - compareValuesFiles("values-mcc003/strings.xml"); - compareValuesFiles("values-mcc003/integers.xml"); - compareValuesFiles("values-mcc003/bools.xml"); - } - - @Test - public void xmlLiteralsTest() throws BrutException { - compareXmlFiles("res/xml/literals.xml"); - } - - @Test - public void xmlReferencesTest() throws BrutException { - compareXmlFiles("res/xml/references.xml"); - } - - @Test - public void xmlReferenceAttributeTest() throws BrutException { - compareXmlFiles("res/layout/issue1040.xml"); - } - - @Test - public void xmlCustomAttributeTest() throws BrutException { - compareXmlFiles("res/layout/issue1063.xml"); - } - - @Test - public void xmlSmallNumbersDontEscapeTest() throws BrutException { - compareXmlFiles("res/layout/issue1130.xml"); - } - - @Test - public void xmlUniformAutoTextTest() throws BrutException { - compareXmlFiles("res/layout/issue1674.xml"); - } - - @Test(expected = AssertionError.class) - public void xmlFillParentBecomesMatchTest() throws BrutException { - compareXmlFiles("res/layout/issue1274.xml"); - } - - @Test - public void xmlCustomAttrsNotAndroidTest() throws BrutException { - compareXmlFiles("res/layout/issue1157.xml"); - } - - @Test - public void qualifiersTest() throws BrutException { - compareValuesFiles("values-mcc004-mnc4-en-rUS-ldrtl-sw100dp-w200dp-h300dp" - + "-xlarge-long-round-highdr-land-desk-night-xhdpi-finger-keyssoft-12key" - + "-navhidden-dpad-v26/strings.xml"); - } - - @Test - public void shortendedMncTest() throws BrutException { - compareValuesFiles("values-mcc001-mnc1/strings.xml"); - } - - @Test - public void shortMncHtcTest() throws BrutException { - compareValuesFiles("values-mnc1/strings.xml"); - } - - @Test - public void shortMncv2Test() throws BrutException { - compareValuesFiles("values-mcc238-mnc6/strings.xml"); - } - - @Test - public void longMncTest() throws BrutException { - compareValuesFiles("values-mcc238-mnc870/strings.xml"); - } - - @Test - public void anyDpiTest() throws BrutException, IOException { - compareValuesFiles("values-watch/strings.xml"); - } - - @Test - public void packed3CharsTest() throws BrutException, IOException { - compareValuesFiles("values-ast-rES/strings.xml"); - } - - @Test - public void rightToLeftTest() throws BrutException, IOException { - compareValuesFiles("values-ldrtl/strings.xml"); - } - - @Test - public void scriptBcp47Test() throws BrutException, IOException { - compareValuesFiles("values-b+en+Latn+US/strings.xml"); - } - - @Test - public void threeLetterLangBcp47Test() throws BrutException, IOException { - compareValuesFiles("values-ast/strings.xml"); - } - - @Test - public void androidOStringTest() throws BrutException, IOException { - compareValuesFiles("values-ast/strings.xml"); - } - - @Test - public void twoLetterNotHandledAsBcpTest() throws BrutException, IOException { - checkFolderExists("res/values-fr"); - } - - @Test - public void twoLetterLangBcp47Test() throws BrutException, IOException { - compareValuesFiles("values-en-rUS/strings.xml"); - } - - @Test - public void variantBcp47Test() throws BrutException, IOException { - compareValuesFiles("values-b+en+US+POSIX/strings.xml"); - } - - @Test - public void fourpartBcp47Test() throws BrutException, IOException { - compareValuesFiles("values-b+ast+Latn+IT+AREVELA/strings.xml"); - } - - @Test - public void RegionLocaleBcp47Test() throws BrutException, IOException { - compareValuesFiles("values-b+en+Latn+419/strings.xml"); - } - - @Test - public void numericalRegionBcp47Test() throws BrutException, IOException { - compareValuesFiles("values-b+eng+419/strings.xml"); - } - - @Test - public void api23ConfigurationsTest() throws BrutException, IOException { - compareValuesFiles("values-round/strings.xml"); - compareValuesFiles("values-notround/strings.xml"); - } - - @Test - public void api26ConfigurationsTest() throws BrutException, IOException { - compareValuesFiles("values-widecg-v26/strings.xml"); - compareValuesFiles("values-lowdr-v26/strings.xml"); - compareValuesFiles("values-nowidecg-v26/strings.xml"); - compareValuesFiles("values-vrheadset-v26/strings.xml"); - } - - @Test - public void fontTest() throws BrutException, IOException { - File fontXml = new File((sTestNewDir + "/res/font"), "lobster.xml"); - File fontFile = new File((sTestNewDir + "/res/font"), "lobster_regular.otf"); - - // Per #1662, ensure font file is not encoded. - assertTrue(fontXml.isFile()); - compareXmlFiles("/res/font/lobster.xml"); - - // If we properly skipped decoding the font (otf) file, this file should not exist - assertFalse((new File((sTestNewDir + "/res/values"), "fonts.xml")).isFile()); - assertTrue(fontFile.isFile()); - } - - @Test - public void drawableNoDpiTest() throws BrutException, IOException { - compareResFolder("drawable-nodpi"); - } - - @Test - public void drawableAnyDpiTest() throws BrutException, IOException { - compareResFolder("drawable-anydpi"); - } - - @Test - public void drawableNumberedDpiTest() throws BrutException, IOException { - compareResFolder("drawable-534dpi"); - } - - @Test - public void drawableLdpiTest() throws BrutException, IOException { - compareResFolder("drawable-ldpi"); - } - - @Test - public void drawableMdpiTest() throws BrutException, IOException { - compareResFolder("drawable-mdpi"); - } - - @Test - public void drawableTvdpiTest() throws BrutException, IOException { - compareResFolder("drawable-tvdpi"); - } - - @Test - public void drawableXhdpiTest() throws BrutException, IOException { - compareResFolder("drawable-xhdpi"); - } - - @Test - public void ninePatchImageColorTest() throws BrutException, IOException { - char slash = File.separatorChar; - String location = slash + "res" + slash + "drawable-xhdpi" + slash; - - File control = new File((sTestOrigDir + location), "9patch.9.png"); - File test = new File((sTestNewDir + location), "9patch.9.png"); - - BufferedImage controlImage = ImageIO.read(control); - BufferedImage testImage = ImageIO.read(test); - - // lets start with 0,0 - empty - assertEquals(controlImage.getRGB(0, 0), testImage.getRGB(0, 0)); - - // then with 30, 0 - black - assertEquals(controlImage.getRGB(30, 0), testImage.getRGB(30, 0)); - - // then 30, 30 - blue - assertEquals(controlImage.getRGB(30, 30), testImage.getRGB(30, 30)); - } - - @Test - public void issue1508Test() throws BrutException, IOException { - char slash = File.separatorChar; - String location = slash + "res" + slash + "drawable-xhdpi" + slash; - - File control = new File((sTestOrigDir + location), "btn_zoom_up_normal.9.png"); - File test = new File((sTestNewDir + location), "btn_zoom_up_normal.9.png"); - - BufferedImage controlImage = ImageIO.read(control); - BufferedImage testImage = ImageIO.read(test); - - // 0, 0 = clear - assertEquals(controlImage.getRGB(0, 0), testImage.getRGB(0, 0)); - - // 30, 0 = black line - assertEquals(controlImage.getRGB(0, 30), testImage.getRGB(0, 30)); - - // 30, 30 = greyish button - assertEquals(controlImage.getRGB(30, 30), testImage.getRGB(30, 30)); - } - - @Test - public void issue1511Test() throws BrutException, IOException { - char slash = File.separatorChar; - String location = slash + "res" + slash + "drawable-xxhdpi" + slash; - - File control = new File((sTestOrigDir + location), "textfield_activated_holo_dark.9.png"); - File test = new File((sTestNewDir + location), "textfield_activated_holo_dark.9.png"); - - BufferedImage controlImage = ImageIO.read(control); - BufferedImage testImage = ImageIO.read(test); - - // Check entire image as we cannot mess this up - final int w = controlImage.getWidth(), - h = controlImage.getHeight(); - - final int[] controlImageGrid = controlImage.getRGB(0, 0, w, h, null, 0, w); - final int[] testImageGrid = testImage.getRGB(0, 0, w, h, null, 0, w); - - for (int i = 0; i < controlImageGrid.length; i++) { - assertEquals("Image lost Optical Bounds at i = " + i, controlImageGrid[i], testImageGrid[i]); - } - } - - @Test - public void robust9patchTest() throws BrutException, IOException { - String[] ninePatches = {"ic_notification_overlay.9.png", "status_background.9.png", - "search_bg_transparent.9.png", "screenshot_panel.9.png", "recents_lower_gradient.9.png"}; - - char slash = File.separatorChar; - String location = slash + "res" + slash + "drawable-xxhdpi" + slash; - - for (String ninePatch : ninePatches) { - File control = new File((sTestOrigDir + location), ninePatch); - File test = new File((sTestNewDir + location), ninePatch); - - BufferedImage controlImage = ImageIO.read(control); - BufferedImage testImage = ImageIO.read(test); - - int w = controlImage.getWidth(), h = controlImage.getHeight(); - - // Check the entire horizontal line - for (int i = 1; i < w; i++) { - if (isTransparent(controlImage.getRGB(i, 0))) { - assertTrue(isTransparent(testImage.getRGB(i, 0))); - } else { - assertEquals("Image lost npTc chunk on image " + ninePatch + " at (x, y) (" + i + "," + 0 + ")", - controlImage.getRGB(i, 0), testImage.getRGB(i, 0)); - } - } - - // Check the entire vertical line - for (int i = 1; i < h; i++) { - if (isTransparent(controlImage.getRGB(0, i))) { - assertTrue(isTransparent(testImage.getRGB(0, i))); - } else { - assertEquals("Image lost npTc chunk on image " + ninePatch + " at (x, y) (" + 0 + "," + i + ")", - controlImage.getRGB(0, i), testImage.getRGB(0, i)); - } - } - } - } - - @Test - public void drawableXxhdpiTest() throws BrutException, IOException { - compareResFolder("drawable-xxhdpi"); - } - - @Test - public void drawableXxxhdpiTest() throws BrutException, IOException { - compareResFolder("drawable-xxxhdpi"); - } - - @Test - public void resRawTest() throws BrutException, IOException { - compareResFolder("raw"); - } - - @Test - public void libsTest() throws BrutException, IOException { - compareLibsFolder("libs"); - } - - @Test - public void unknownFolderTest() throws BrutException, IOException { - compareUnknownFiles(); - } - - @Test - public void fileAssetTest() throws BrutException, IOException { - compareAssetsFolder("txt"); - } - - @Test - public void unicodeAssetTest() throws BrutException, IOException { - assumeTrue(! OSDetection.isWindows()); - compareAssetsFolder("unicode-txt"); - } - - @Test - public void multipleDexTest() throws BrutException, IOException { - compareBinaryFolder("/smali_classes2", false); - } - - @Test - public void singleDexTest() throws BrutException, IOException { - compareBinaryFolder("/smali", false); - } - - @Test - public void confirmKotlinFolderPersistsTest() throws BrutException, IOException { - checkFolderExists("/kotlin"); - } - - @SuppressWarnings("unchecked") - private void compareUnknownFiles() throws BrutException, IOException { - MetaInfo control = new Androlib().readMetaFile(sTestOrigDir); - MetaInfo test = new Androlib().readMetaFile(sTestNewDir); - assertNotNull(control.unknownFiles); - assertNotNull(test.unknownFiles); - - Map control_files = control.unknownFiles; - Map test_files = test.unknownFiles; - assertTrue(control_files.size() == test_files.size()); - - // Make sure that the compression methods are still the same - for (Map.Entry controlEntry : control_files.entrySet()) { - assertTrue(controlEntry.getValue().equals(test_files.get(controlEntry.getKey()))); - } - } - - private void compareBinaryFolder(String path, boolean res) throws BrutException, IOException { - Boolean exists = true; - - String tmp = ""; - if (res) { - tmp = File.separatorChar + "res" + File.separatorChar; - } - - String location = tmp + path; - - FileDirectory fileDirectory = new FileDirectory(sTestOrigDir, location); - - Set files = fileDirectory.getFiles(true); - for (String filename : files) { - - File control = new File((sTestOrigDir + location), filename); - File test = new File((sTestNewDir + location), filename); - - if (! test.isFile() || ! control.isFile()) { - exists = false; - } - } - - assertTrue(exists); - } - - private void compareResFolder(String path) throws BrutException, IOException { - compareBinaryFolder(path, true); - } - - private void compareLibsFolder(String path) throws BrutException, IOException { - compareBinaryFolder(File.separatorChar + path, false); - } - - private void compareAssetsFolder(String path) throws BrutException, IOException { - compareBinaryFolder(File.separatorChar + "assets" + File.separatorChar + path, false); - } - - private void compareValuesFiles(String path) throws BrutException { - compareXmlFiles("res/" + path, new ElementNameAndAttributeQualifier("name")); - } - - private void compareXmlFiles(String path) throws BrutException { - compareXmlFiles(path, null); - } - - private void checkFolderExists(String path) throws BrutException { - File f = new File(sTestNewDir, path); - - assertTrue(f.isDirectory()); - } - - private boolean isTransparent(int pixel) { - return pixel >> 24 == 0x00; - } - - private void compareXmlFiles(String path, ElementQualifier qualifier) throws BrutException { - DetailedDiff diff; - try { - Reader control = new FileReader(new File(sTestOrigDir, path)); - Reader test = new FileReader(new File(sTestNewDir, path)); - - diff = new DetailedDiff(new Diff(control, test)); - } catch (SAXException | IOException ex) { - throw new BrutException(ex); - } - - if (qualifier != null) { - diff.overrideElementQualifier(qualifier); - } - - assertTrue(path + ": " + diff.getAllDifferences().toString(), diff.similar()); - } - - private static ExtFile sTmpDir; - private static ExtFile sTestOrigDir; - private static ExtFile sTestNewDir; - - private final static Logger LOGGER = Logger.getLogger(BuildAndDecodeTest.class.getName()); }