From 6d5d889c27137a8855dda385bb2707280e4a519d Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Fri, 15 Nov 2013 13:08:27 -0600 Subject: [PATCH] adjust spacing in test files, removed unused imports --- .../brut/androlib/BuildAndDecodeTest.java | 251 +++++++++--------- .../test/java/brut/androlib/TestUtils.java | 190 ++++++------- 2 files changed, 219 insertions(+), 222 deletions(-) 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 f2b4c3e0..ccc78c7c 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 @@ -20,10 +20,7 @@ import brut.common.BrutException; import brut.directory.FileDirectory; import brut.util.OS; import java.io.*; -import java.nio.file.*; -import java.nio.file.attribute.BasicFileAttributes; import java.util.HashMap; -import java.util.Iterator; import java.util.Set; import java.util.logging.Logger; import org.custommonkey.xmlunit.*; @@ -36,14 +33,14 @@ import org.xml.sax.SAXException; */ public class BuildAndDecodeTest { - @BeforeClass - public static void beforeClass() throws Exception, BrutException { - sTmpDir = new ExtFile(OS.createTempDirectory()); - sTestOrigDir = new ExtFile(sTmpDir, "testapp-orig"); - sTestNewDir = new ExtFile(sTmpDir, "testapp-new"); - LOGGER.info("Unpacking testapp..."); - TestUtils.copyResourceDir(BuildAndDecodeTest.class, - "brut/apktool/testapp/", sTestOrigDir); + @BeforeClass + public static void beforeClass() throws Exception, BrutException { + sTmpDir = new ExtFile(OS.createTempDirectory()); + sTestOrigDir = new ExtFile(sTmpDir, "testapp-orig"); + sTestNewDir = new ExtFile(sTmpDir, "testapp-new"); + LOGGER.info("Unpacking testapp..."); + TestUtils.copyResourceDir(BuildAndDecodeTest.class, + "brut/apktool/testapp/", sTestOrigDir); LOGGER.info("Building testapp.apk..."); File testApk = new File(sTmpDir, "testapp.apk"); @@ -54,68 +51,68 @@ public class BuildAndDecodeTest { ApkDecoder apkDecoder = new ApkDecoder(testApk); apkDecoder.setOutDir(sTestNewDir); apkDecoder.decode(); - } + } - @AfterClass - public static void afterClass() throws BrutException { - OS.rmdir(sTmpDir); - } + @AfterClass + public static void afterClass() throws BrutException { + OS.rmdir(sTmpDir); + } @Test public void buildAndDecodeTest() throws BrutException { assertTrue(sTestNewDir.isDirectory()); } - @Test - public void isAaptInstalledTest() throws Exception { - assertEquals(true, isAaptPresent()); - } + @Test + public void isAaptInstalledTest() throws Exception { + assertEquals(true, isAaptPresent()); + } @Test public void valuesAnimsTest() throws BrutException { compareValuesFiles("values-mcc001/anims.xml"); } - @Test - public void valuesArraysTest() throws BrutException { - compareValuesFiles("values-mcc001/arrays.xml"); - compareValuesFiles("values-mcc002/arrays.xml"); - } + @Test + public void valuesArraysTest() throws BrutException { + compareValuesFiles("values-mcc001/arrays.xml"); + compareValuesFiles("values-mcc002/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 valuesBoolsTest() throws BrutException { + compareValuesFiles("values-mcc001/bools.xml"); + } - @Test - public void valuesColorsTest() throws BrutException { - compareValuesFiles("values-mcc001/colors.xml"); - } + @Test + public void valuesColorsTest() throws BrutException { + compareValuesFiles("values-mcc001/colors.xml"); + } - @Test - public void valuesDimensTest() throws BrutException { - compareValuesFiles("values-mcc001/dimens.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 valuesIdsTest() throws BrutException { + compareValuesFiles("values-mcc001/ids.xml"); + } - @Test - public void valuesIntegersTest() throws BrutException { - compareValuesFiles("values-mcc001/integers.xml"); - } + @Test + public void valuesIntegersTest() throws BrutException { + compareValuesFiles("values-mcc001/integers.xml"); + } @Test public void valuesLayoutsTest() throws BrutException { @@ -127,44 +124,44 @@ public class BuildAndDecodeTest { compareValuesFiles("values-mcc001/plurals.xml"); } - @Test - public void valuesStringsTest() throws BrutException { - compareValuesFiles("values-mcc001/strings.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 valuesReferencesTest() throws BrutException { + compareValuesFiles("values-mcc002/strings.xml"); + } - @Test - public void crossTypeTest() throws BrutException { - compareValuesFiles("values-mcc003/strings.xml"); - compareValuesFiles("values-mcc003/integers.xml"); - compareValuesFiles("values-mcc003/bools.xml"); - } + @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 xmlLiteralsTest() throws BrutException { + compareXmlFiles("res/xml/literals.xml"); + } - @Test - public void xmlReferencesTest() throws BrutException { - compareXmlFiles("res/xml/references.xml"); - } + @Test + public void xmlReferencesTest() throws BrutException { + compareXmlFiles("res/xml/references.xml"); + } - @Test - public void qualifiersTest() throws BrutException { - compareValuesFiles("values-mcc004-mnc4-en-rUS-ldrtl-sw100dp-w200dp-h300dp" - + "-xlarge-long-land-desk-night-xhdpi-finger-keyssoft-12key" - + "-navhidden-dpad/strings.xml"); - } + @Test + public void qualifiersTest() throws BrutException { + compareValuesFiles("values-mcc004-mnc4-en-rUS-ldrtl-sw100dp-w200dp-h300dp" + + "-xlarge-long-land-desk-night-xhdpi-finger-keyssoft-12key" + + "-navhidden-dpad/strings.xml"); + } @Test public void drawableNoDpiTest() throws BrutException, IOException { @@ -211,20 +208,20 @@ public class BuildAndDecodeTest { compareLibsFolder("libs"); } - private static boolean isAaptPresent() throws Exception { - boolean result = true; - try { - Process proc = Runtime.getRuntime().exec("aapt"); - BufferedReader br = new BufferedReader(new InputStreamReader( - proc.getErrorStream())); - String line = null; - while ((line = br.readLine()) != null) { - } - } catch (Exception ex) { - result = false; - } - return result; - } + private static boolean isAaptPresent() throws Exception { + boolean result = true; + try { + Process proc = Runtime.getRuntime().exec("aapt"); + BufferedReader br = new BufferedReader(new InputStreamReader( + proc.getErrorStream())); + String line = null; + while ((line = br.readLine()) != null) { + } + } catch (Exception ex) { + result = false; + } + return result; + } private boolean compareBinaryFolder(String path, boolean res) throws BrutException, IOException { @@ -259,53 +256,53 @@ public class BuildAndDecodeTest { return compareBinaryFolder(File.separatorChar + path,false); } - private void compareValuesFiles(String path) throws BrutException { - compareXmlFiles("res/" + path, new ElementNameAndAttributeQualifier( - "name")); - } + 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 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)); + 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 ex) { - throw new BrutException(ex); - } catch (IOException ex) { - throw new BrutException(ex); - } + diff = new DetailedDiff(new Diff(control, test)); + } catch (SAXException ex) { + throw new BrutException(ex); + } catch (IOException ex) { + throw new BrutException(ex); + } - if (qualifier != null) { - diff.overrideElementQualifier(qualifier); - } + if (qualifier != null) { + diff.overrideElementQualifier(qualifier); + } - assertTrue(path + ": " + diff.getAllDifferences().toString(), - diff.similar()); - } + assertTrue(path + ": " + diff.getAllDifferences().toString(), + diff.similar()); + } - private static HashMap returnStock() throws BrutException { - HashMap tmp = new HashMap(); - tmp.put("forceBuildAll", false); - tmp.put("debug", false); - tmp.put("verbose", false); - tmp.put("framework", false); - tmp.put("update", false); - tmp.put("copyOriginal", false); + private static HashMap returnStock() throws BrutException { + HashMap tmp = new HashMap(); + tmp.put("forceBuildAll", false); + tmp.put("debug", false); + tmp.put("verbose", false); + tmp.put("framework", false); + tmp.put("update", false); + tmp.put("copyOriginal", false); - return tmp; - } + return tmp; + } - private static ExtFile sTmpDir; - private static ExtFile sTestOrigDir; - private static ExtFile sTestNewDir; + private static ExtFile sTmpDir; + private static ExtFile sTestOrigDir; + private static ExtFile sTestNewDir; - private final static Logger LOGGER = Logger - .getLogger(BuildAndDecodeTest.class.getName()); + private final static Logger LOGGER = Logger + .getLogger(BuildAndDecodeTest.class.getName()); } 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 f422c165..5b5f3992 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 @@ -32,110 +32,110 @@ import org.xmlpull.v1.*; */ public abstract class TestUtils { - public static Map parseStringsXml(File file) - throws BrutException { - try { - XmlPullParser xpp = XmlPullParserFactory.newInstance() - .newPullParser(); - xpp.setInput(new FileReader(file)); + public static Map parseStringsXml(File file) + throws BrutException { + try { + XmlPullParser xpp = XmlPullParserFactory.newInstance() + .newPullParser(); + xpp.setInput(new FileReader(file)); - int eventType; - String key = null; - Map map = new HashMap(); - while ((eventType = xpp.next()) != XmlPullParser.END_DOCUMENT) { - switch (eventType) { - case XmlPullParser.START_TAG: - if ("string".equals(xpp.getName())) { - int attrCount = xpp.getAttributeCount(); - for (int i = 0; i < attrCount; i++) { - if ("name".equals(xpp.getAttributeName(i))) { - key = xpp.getAttributeValue(i); - break; - } - } - } - break; - case XmlPullParser.END_TAG: - if ("string".equals(xpp.getName())) { - key = null; - } - break; - case XmlPullParser.TEXT: - if (key != null) { - map.put(key, xpp.getText()); - } - break; - } - } + int eventType; + String key = null; + Map map = new HashMap(); + while ((eventType = xpp.next()) != XmlPullParser.END_DOCUMENT) { + switch (eventType) { + case XmlPullParser.START_TAG: + if ("string".equals(xpp.getName())) { + int attrCount = xpp.getAttributeCount(); + for (int i = 0; i < attrCount; i++) { + if ("name".equals(xpp.getAttributeName(i))) { + key = xpp.getAttributeValue(i); + break; + } + } + } + break; + case XmlPullParser.END_TAG: + if ("string".equals(xpp.getName())) { + key = null; + } + break; + case XmlPullParser.TEXT: + if (key != null) { + map.put(key, xpp.getText()); + } + break; + } + } - return map; - } catch (IOException ex) { - throw new BrutException(ex); - } catch (XmlPullParserException ex) { - throw new BrutException(ex); - } - } + return map; + } catch (IOException ex) { + throw new BrutException(ex); + } catch (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(); - } - copyResourceDir(class_, dirPath, new FileDirectory(out)); - } + /* + * 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(); + } + copyResourceDir(class_, dirPath, new FileDirectory(out)); + } - public static void copyResourceDir(Class class_, String dirPath, - Directory out) throws BrutException { - if (class_ == null) { - class_ = Class.class; - } + public static void copyResourceDir(Class class_, String dirPath, + Directory out) throws BrutException { + if (class_ == null) { + class_ = Class.class; + } - URL dirURL = class_.getClassLoader().getResource(dirPath); - if (dirURL != null && dirURL.getProtocol().equals("file")) { - DirUtil.copyToDir(new FileDirectory(dirURL.getFile()), out); - return; - } + URL dirURL = class_.getClassLoader().getResource(dirPath); + if (dirURL != null && dirURL.getProtocol().equals("file")) { + DirUtil.copyToDir(new FileDirectory(dirURL.getFile()), out); + return; + } - if (dirURL == null) { - String className = class_.getName().replace(".", "/") + ".class"; - dirURL = class_.getClassLoader().getResource(className); - } + if (dirURL == null) { + String className = class_.getName().replace(".", "/") + ".class"; + dirURL = class_.getClassLoader().getResource(className); + } - if (dirURL.getProtocol().equals("jar")) { - String jarPath; - try { - jarPath = URLDecoder.decode( - dirURL.getPath().substring(5, - dirURL.getPath().indexOf("!")), "UTF-8"); - } catch (UnsupportedEncodingException ex) { - throw new BrutException(ex); - } - DirUtil.copyToDir(new FileDirectory(jarPath), out); - } - } + if (dirURL.getProtocol().equals("jar")) { + String jarPath; + try { + jarPath = URLDecoder.decode( + dirURL.getPath().substring(5, + dirURL.getPath().indexOf("!")), "UTF-8"); + } catch (UnsupportedEncodingException ex) { + throw new BrutException(ex); + } + DirUtil.copyToDir(new FileDirectory(jarPath), out); + } + } - public static class ResValueElementQualifier implements ElementQualifier { + public static class ResValueElementQualifier implements ElementQualifier { - @Override - public boolean qualifyForComparison(Element control, Element test) { - String controlType = control.getTagName(); - if ("item".equals(controlType)) { - controlType = control.getAttribute("type"); - } + @Override + public boolean qualifyForComparison(Element control, Element test) { + String controlType = control.getTagName(); + if ("item".equals(controlType)) { + controlType = control.getAttribute("type"); + } - String testType = test.getTagName(); - if ("item".equals(testType)) { - testType = test.getAttribute("type"); - } + String testType = test.getTagName(); + if ("item".equals(testType)) { + testType = test.getAttribute("type"); + } - return controlType.equals(testType) - && control.getAttribute("name").equals( - test.getAttribute("name")); - } - } + return controlType.equals(testType) + && control.getAttribute("name").equals( + test.getAttribute("name")); + } + } }