mirror of
https://github.com/revanced/Apktool.git
synced 2025-05-02 06:54:25 +02:00
adjust spacing in test files, removed unused imports
This commit is contained in:
parent
d2fc74d984
commit
6d5d889c27
@ -20,10 +20,7 @@ import brut.common.BrutException;
|
|||||||
import brut.directory.FileDirectory;
|
import brut.directory.FileDirectory;
|
||||||
import brut.util.OS;
|
import brut.util.OS;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.*;
|
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.custommonkey.xmlunit.*;
|
import org.custommonkey.xmlunit.*;
|
||||||
@ -36,14 +33,14 @@ import org.xml.sax.SAXException;
|
|||||||
*/
|
*/
|
||||||
public class BuildAndDecodeTest {
|
public class BuildAndDecodeTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() throws Exception, BrutException {
|
public static void beforeClass() throws Exception, BrutException {
|
||||||
sTmpDir = new ExtFile(OS.createTempDirectory());
|
sTmpDir = new ExtFile(OS.createTempDirectory());
|
||||||
sTestOrigDir = new ExtFile(sTmpDir, "testapp-orig");
|
sTestOrigDir = new ExtFile(sTmpDir, "testapp-orig");
|
||||||
sTestNewDir = new ExtFile(sTmpDir, "testapp-new");
|
sTestNewDir = new ExtFile(sTmpDir, "testapp-new");
|
||||||
LOGGER.info("Unpacking testapp...");
|
LOGGER.info("Unpacking testapp...");
|
||||||
TestUtils.copyResourceDir(BuildAndDecodeTest.class,
|
TestUtils.copyResourceDir(BuildAndDecodeTest.class,
|
||||||
"brut/apktool/testapp/", sTestOrigDir);
|
"brut/apktool/testapp/", sTestOrigDir);
|
||||||
|
|
||||||
LOGGER.info("Building testapp.apk...");
|
LOGGER.info("Building testapp.apk...");
|
||||||
File testApk = new File(sTmpDir, "testapp.apk");
|
File testApk = new File(sTmpDir, "testapp.apk");
|
||||||
@ -54,68 +51,68 @@ public class BuildAndDecodeTest {
|
|||||||
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
ApkDecoder apkDecoder = new ApkDecoder(testApk);
|
||||||
apkDecoder.setOutDir(sTestNewDir);
|
apkDecoder.setOutDir(sTestNewDir);
|
||||||
apkDecoder.decode();
|
apkDecoder.decode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void afterClass() throws BrutException {
|
public static void afterClass() throws BrutException {
|
||||||
OS.rmdir(sTmpDir);
|
OS.rmdir(sTmpDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildAndDecodeTest() throws BrutException {
|
public void buildAndDecodeTest() throws BrutException {
|
||||||
assertTrue(sTestNewDir.isDirectory());
|
assertTrue(sTestNewDir.isDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAaptInstalledTest() throws Exception {
|
public void isAaptInstalledTest() throws Exception {
|
||||||
assertEquals(true, isAaptPresent());
|
assertEquals(true, isAaptPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void valuesAnimsTest() throws BrutException {
|
public void valuesAnimsTest() throws BrutException {
|
||||||
compareValuesFiles("values-mcc001/anims.xml");
|
compareValuesFiles("values-mcc001/anims.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void valuesArraysTest() throws BrutException {
|
public void valuesArraysTest() throws BrutException {
|
||||||
compareValuesFiles("values-mcc001/arrays.xml");
|
compareValuesFiles("values-mcc001/arrays.xml");
|
||||||
compareValuesFiles("values-mcc002/arrays.xml");
|
compareValuesFiles("values-mcc002/arrays.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void valuesAttrsTest() throws BrutException {
|
public void valuesAttrsTest() throws BrutException {
|
||||||
compareValuesFiles("values/attrs.xml");
|
compareValuesFiles("values/attrs.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void valuesBoolsTest() throws BrutException {
|
public void valuesBoolsTest() throws BrutException {
|
||||||
compareValuesFiles("values-mcc001/bools.xml");
|
compareValuesFiles("values-mcc001/bools.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void valuesColorsTest() throws BrutException {
|
public void valuesColorsTest() throws BrutException {
|
||||||
compareValuesFiles("values-mcc001/colors.xml");
|
compareValuesFiles("values-mcc001/colors.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void valuesDimensTest() throws BrutException {
|
public void valuesDimensTest() throws BrutException {
|
||||||
compareValuesFiles("values-mcc001/dimens.xml");
|
compareValuesFiles("values-mcc001/dimens.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void valuesDrawablesTest() throws BrutException {
|
public void valuesDrawablesTest() throws BrutException {
|
||||||
compareValuesFiles("values-mcc001/drawables.xml");
|
compareValuesFiles("values-mcc001/drawables.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void valuesIdsTest() throws BrutException {
|
public void valuesIdsTest() throws BrutException {
|
||||||
compareValuesFiles("values-mcc001/ids.xml");
|
compareValuesFiles("values-mcc001/ids.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void valuesIntegersTest() throws BrutException {
|
public void valuesIntegersTest() throws BrutException {
|
||||||
compareValuesFiles("values-mcc001/integers.xml");
|
compareValuesFiles("values-mcc001/integers.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void valuesLayoutsTest() throws BrutException {
|
public void valuesLayoutsTest() throws BrutException {
|
||||||
@ -127,44 +124,44 @@ public class BuildAndDecodeTest {
|
|||||||
compareValuesFiles("values-mcc001/plurals.xml");
|
compareValuesFiles("values-mcc001/plurals.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void valuesStringsTest() throws BrutException {
|
public void valuesStringsTest() throws BrutException {
|
||||||
compareValuesFiles("values-mcc001/strings.xml");
|
compareValuesFiles("values-mcc001/strings.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void valuesStylesTest() throws BrutException {
|
public void valuesStylesTest() throws BrutException {
|
||||||
compareValuesFiles("values-mcc001/styles.xml");
|
compareValuesFiles("values-mcc001/styles.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void valuesReferencesTest() throws BrutException {
|
public void valuesReferencesTest() throws BrutException {
|
||||||
compareValuesFiles("values-mcc002/strings.xml");
|
compareValuesFiles("values-mcc002/strings.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void crossTypeTest() throws BrutException {
|
public void crossTypeTest() throws BrutException {
|
||||||
compareValuesFiles("values-mcc003/strings.xml");
|
compareValuesFiles("values-mcc003/strings.xml");
|
||||||
compareValuesFiles("values-mcc003/integers.xml");
|
compareValuesFiles("values-mcc003/integers.xml");
|
||||||
compareValuesFiles("values-mcc003/bools.xml");
|
compareValuesFiles("values-mcc003/bools.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void xmlLiteralsTest() throws BrutException {
|
public void xmlLiteralsTest() throws BrutException {
|
||||||
compareXmlFiles("res/xml/literals.xml");
|
compareXmlFiles("res/xml/literals.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void xmlReferencesTest() throws BrutException {
|
public void xmlReferencesTest() throws BrutException {
|
||||||
compareXmlFiles("res/xml/references.xml");
|
compareXmlFiles("res/xml/references.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void qualifiersTest() throws BrutException {
|
public void qualifiersTest() throws BrutException {
|
||||||
compareValuesFiles("values-mcc004-mnc4-en-rUS-ldrtl-sw100dp-w200dp-h300dp"
|
compareValuesFiles("values-mcc004-mnc4-en-rUS-ldrtl-sw100dp-w200dp-h300dp"
|
||||||
+ "-xlarge-long-land-desk-night-xhdpi-finger-keyssoft-12key"
|
+ "-xlarge-long-land-desk-night-xhdpi-finger-keyssoft-12key"
|
||||||
+ "-navhidden-dpad/strings.xml");
|
+ "-navhidden-dpad/strings.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void drawableNoDpiTest() throws BrutException, IOException {
|
public void drawableNoDpiTest() throws BrutException, IOException {
|
||||||
@ -211,20 +208,20 @@ public class BuildAndDecodeTest {
|
|||||||
compareLibsFolder("libs");
|
compareLibsFolder("libs");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isAaptPresent() throws Exception {
|
private static boolean isAaptPresent() throws Exception {
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
try {
|
try {
|
||||||
Process proc = Runtime.getRuntime().exec("aapt");
|
Process proc = Runtime.getRuntime().exec("aapt");
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(
|
BufferedReader br = new BufferedReader(new InputStreamReader(
|
||||||
proc.getErrorStream()));
|
proc.getErrorStream()));
|
||||||
String line = null;
|
String line = null;
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean compareBinaryFolder(String path, boolean res) throws BrutException, IOException {
|
private boolean compareBinaryFolder(String path, boolean res) throws BrutException, IOException {
|
||||||
|
|
||||||
@ -259,53 +256,53 @@ public class BuildAndDecodeTest {
|
|||||||
return compareBinaryFolder(File.separatorChar + path,false);
|
return compareBinaryFolder(File.separatorChar + path,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void compareValuesFiles(String path) throws BrutException {
|
private void compareValuesFiles(String path) throws BrutException {
|
||||||
compareXmlFiles("res/" + path, new ElementNameAndAttributeQualifier(
|
compareXmlFiles("res/" + path, new ElementNameAndAttributeQualifier(
|
||||||
"name"));
|
"name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void compareXmlFiles(String path) throws BrutException {
|
private void compareXmlFiles(String path) throws BrutException {
|
||||||
compareXmlFiles(path, null);
|
compareXmlFiles(path, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void compareXmlFiles(String path, ElementQualifier qualifier)
|
private void compareXmlFiles(String path, ElementQualifier qualifier)
|
||||||
throws BrutException {
|
throws BrutException {
|
||||||
DetailedDiff diff;
|
DetailedDiff diff;
|
||||||
try {
|
try {
|
||||||
Reader control = new FileReader(new File(sTestOrigDir, path));
|
Reader control = new FileReader(new File(sTestOrigDir, path));
|
||||||
Reader test = new FileReader(new File(sTestNewDir, path));
|
Reader test = new FileReader(new File(sTestNewDir, path));
|
||||||
|
|
||||||
diff = new DetailedDiff(new Diff(control, test));
|
diff = new DetailedDiff(new Diff(control, test));
|
||||||
} catch (SAXException ex) {
|
} catch (SAXException ex) {
|
||||||
throw new BrutException(ex);
|
throw new BrutException(ex);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new BrutException(ex);
|
throw new BrutException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qualifier != null) {
|
if (qualifier != null) {
|
||||||
diff.overrideElementQualifier(qualifier);
|
diff.overrideElementQualifier(qualifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue(path + ": " + diff.getAllDifferences().toString(),
|
assertTrue(path + ": " + diff.getAllDifferences().toString(),
|
||||||
diff.similar());
|
diff.similar());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashMap<String, Boolean> returnStock() throws BrutException {
|
private static HashMap<String, Boolean> returnStock() throws BrutException {
|
||||||
HashMap<String, Boolean> tmp = new HashMap<String, Boolean>();
|
HashMap<String, Boolean> tmp = new HashMap<String, Boolean>();
|
||||||
tmp.put("forceBuildAll", false);
|
tmp.put("forceBuildAll", false);
|
||||||
tmp.put("debug", false);
|
tmp.put("debug", false);
|
||||||
tmp.put("verbose", false);
|
tmp.put("verbose", false);
|
||||||
tmp.put("framework", false);
|
tmp.put("framework", false);
|
||||||
tmp.put("update", false);
|
tmp.put("update", false);
|
||||||
tmp.put("copyOriginal", false);
|
tmp.put("copyOriginal", false);
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ExtFile sTmpDir;
|
private static ExtFile sTmpDir;
|
||||||
private static ExtFile sTestOrigDir;
|
private static ExtFile sTestOrigDir;
|
||||||
private static ExtFile sTestNewDir;
|
private static ExtFile sTestNewDir;
|
||||||
|
|
||||||
private final static Logger LOGGER = Logger
|
private final static Logger LOGGER = Logger
|
||||||
.getLogger(BuildAndDecodeTest.class.getName());
|
.getLogger(BuildAndDecodeTest.class.getName());
|
||||||
}
|
}
|
||||||
|
@ -32,110 +32,110 @@ import org.xmlpull.v1.*;
|
|||||||
*/
|
*/
|
||||||
public abstract class TestUtils {
|
public abstract class TestUtils {
|
||||||
|
|
||||||
public static Map<String, String> parseStringsXml(File file)
|
public static Map<String, String> parseStringsXml(File file)
|
||||||
throws BrutException {
|
throws BrutException {
|
||||||
try {
|
try {
|
||||||
XmlPullParser xpp = XmlPullParserFactory.newInstance()
|
XmlPullParser xpp = XmlPullParserFactory.newInstance()
|
||||||
.newPullParser();
|
.newPullParser();
|
||||||
xpp.setInput(new FileReader(file));
|
xpp.setInput(new FileReader(file));
|
||||||
|
|
||||||
int eventType;
|
int eventType;
|
||||||
String key = null;
|
String key = null;
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
while ((eventType = xpp.next()) != XmlPullParser.END_DOCUMENT) {
|
while ((eventType = xpp.next()) != XmlPullParser.END_DOCUMENT) {
|
||||||
switch (eventType) {
|
switch (eventType) {
|
||||||
case XmlPullParser.START_TAG:
|
case XmlPullParser.START_TAG:
|
||||||
if ("string".equals(xpp.getName())) {
|
if ("string".equals(xpp.getName())) {
|
||||||
int attrCount = xpp.getAttributeCount();
|
int attrCount = xpp.getAttributeCount();
|
||||||
for (int i = 0; i < attrCount; i++) {
|
for (int i = 0; i < attrCount; i++) {
|
||||||
if ("name".equals(xpp.getAttributeName(i))) {
|
if ("name".equals(xpp.getAttributeName(i))) {
|
||||||
key = xpp.getAttributeValue(i);
|
key = xpp.getAttributeValue(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case XmlPullParser.END_TAG:
|
case XmlPullParser.END_TAG:
|
||||||
if ("string".equals(xpp.getName())) {
|
if ("string".equals(xpp.getName())) {
|
||||||
key = null;
|
key = null;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case XmlPullParser.TEXT:
|
case XmlPullParser.TEXT:
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
map.put(key, xpp.getText());
|
map.put(key, xpp.getText());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new BrutException(ex);
|
throw new BrutException(ex);
|
||||||
} catch (XmlPullParserException ex) {
|
} catch (XmlPullParserException ex) {
|
||||||
throw new BrutException(ex);
|
throw new BrutException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: move to brut.util.Jar - it's not possible for now, because below
|
* 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
|
* implementation uses brut.dir. I think I should merge all my projects to
|
||||||
* single brut.common .
|
* single brut.common .
|
||||||
*/
|
*/
|
||||||
public static void copyResourceDir(Class class_, String dirPath, File out)
|
public static void copyResourceDir(Class class_, String dirPath, File out)
|
||||||
throws BrutException {
|
throws BrutException {
|
||||||
if (!out.exists()) {
|
if (!out.exists()) {
|
||||||
out.mkdirs();
|
out.mkdirs();
|
||||||
}
|
}
|
||||||
copyResourceDir(class_, dirPath, new FileDirectory(out));
|
copyResourceDir(class_, dirPath, new FileDirectory(out));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyResourceDir(Class class_, String dirPath,
|
public static void copyResourceDir(Class class_, String dirPath,
|
||||||
Directory out) throws BrutException {
|
Directory out) throws BrutException {
|
||||||
if (class_ == null) {
|
if (class_ == null) {
|
||||||
class_ = Class.class;
|
class_ = Class.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
URL dirURL = class_.getClassLoader().getResource(dirPath);
|
URL dirURL = class_.getClassLoader().getResource(dirPath);
|
||||||
if (dirURL != null && dirURL.getProtocol().equals("file")) {
|
if (dirURL != null && dirURL.getProtocol().equals("file")) {
|
||||||
DirUtil.copyToDir(new FileDirectory(dirURL.getFile()), out);
|
DirUtil.copyToDir(new FileDirectory(dirURL.getFile()), out);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dirURL == null) {
|
if (dirURL == null) {
|
||||||
String className = class_.getName().replace(".", "/") + ".class";
|
String className = class_.getName().replace(".", "/") + ".class";
|
||||||
dirURL = class_.getClassLoader().getResource(className);
|
dirURL = class_.getClassLoader().getResource(className);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dirURL.getProtocol().equals("jar")) {
|
if (dirURL.getProtocol().equals("jar")) {
|
||||||
String jarPath;
|
String jarPath;
|
||||||
try {
|
try {
|
||||||
jarPath = URLDecoder.decode(
|
jarPath = URLDecoder.decode(
|
||||||
dirURL.getPath().substring(5,
|
dirURL.getPath().substring(5,
|
||||||
dirURL.getPath().indexOf("!")), "UTF-8");
|
dirURL.getPath().indexOf("!")), "UTF-8");
|
||||||
} catch (UnsupportedEncodingException ex) {
|
} catch (UnsupportedEncodingException ex) {
|
||||||
throw new BrutException(ex);
|
throw new BrutException(ex);
|
||||||
}
|
}
|
||||||
DirUtil.copyToDir(new FileDirectory(jarPath), out);
|
DirUtil.copyToDir(new FileDirectory(jarPath), out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ResValueElementQualifier implements ElementQualifier {
|
public static class ResValueElementQualifier implements ElementQualifier {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean qualifyForComparison(Element control, Element test) {
|
public boolean qualifyForComparison(Element control, Element test) {
|
||||||
String controlType = control.getTagName();
|
String controlType = control.getTagName();
|
||||||
if ("item".equals(controlType)) {
|
if ("item".equals(controlType)) {
|
||||||
controlType = control.getAttribute("type");
|
controlType = control.getAttribute("type");
|
||||||
}
|
}
|
||||||
|
|
||||||
String testType = test.getTagName();
|
String testType = test.getTagName();
|
||||||
if ("item".equals(testType)) {
|
if ("item".equals(testType)) {
|
||||||
testType = test.getAttribute("type");
|
testType = test.getAttribute("type");
|
||||||
}
|
}
|
||||||
|
|
||||||
return controlType.equals(testType)
|
return controlType.equals(testType)
|
||||||
&& control.getAttribute("name").equals(
|
&& control.getAttribute("name").equals(
|
||||||
test.getAttribute("name"));
|
test.getAttribute("name"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user