aapt2: refactor testsuite

- split from aapt1/aapt2 (those that do building)
 - tests that just test decode (no aapt) split
 - categories for androlib/encdoers/util for various others
This commit is contained in:
Connor Tumbleson 2018-02-28 15:11:39 -05:00
parent 09148902ef
commit 646eb54102
28 changed files with 144 additions and 70 deletions

View File

@ -20,10 +20,7 @@ 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.custommonkey.xmlunit.*;
import org.xml.sax.SAXException;
import java.io.File;
@ -36,10 +33,11 @@ import java.util.logging.Logger;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
public class BaseTest {
void compareUnknownFiles() throws BrutException {
protected void compareUnknownFiles() throws BrutException {
MetaInfo control = new Androlib().readMetaFile(sTestOrigDir);
MetaInfo test = new Androlib().readMetaFile(sTestNewDir);
assertNotNull(control.unknownFiles);
@ -55,7 +53,7 @@ public class BaseTest {
}
}
void compareBinaryFolder(String path, boolean res) throws BrutException, IOException {
protected void compareBinaryFolder(String path, boolean res) throws BrutException, IOException {
Boolean exists = true;
String prefixPath = "";
@ -81,33 +79,33 @@ public class BaseTest {
assertTrue(exists);
}
void compareResFolder(String path) throws BrutException, IOException {
protected void compareResFolder(String path) throws BrutException, IOException {
compareBinaryFolder(path, true);
}
void compareLibsFolder(String path) throws BrutException, IOException {
protected void compareLibsFolder(String path) throws BrutException, IOException {
compareBinaryFolder(File.separatorChar + path, false);
}
void compareAssetsFolder(String path) throws BrutException, IOException {
protected void compareAssetsFolder(String path) throws BrutException, IOException {
compareBinaryFolder(File.separatorChar + "assets" + File.separatorChar + path, false);
}
void compareValuesFiles(String path) throws BrutException {
protected void compareValuesFiles(String path) throws BrutException {
compareXmlFiles("res/" + path, new ElementNameAndAttributeQualifier("name"));
}
void compareXmlFiles(String path) throws BrutException {
protected void compareXmlFiles(String path) throws BrutException {
compareXmlFiles(path, null);
}
void checkFolderExists(String path) {
protected void checkFolderExists(String path) {
File f = new File(sTestNewDir, path);
assertTrue(f.isDirectory());
}
boolean isTransparent(int pixel) {
protected boolean isTransparent(int pixel) {
return pixel >> 24 == 0x00;
}
@ -117,15 +115,19 @@ public class BaseTest {
Reader control = new FileReader(new File(sTestOrigDir, path));
Reader test = new FileReader(new File(sTestNewDir, path));
XMLUnit.setIgnoreWhitespace(true);
if (qualifier == null) {
assertXMLEqual(control, test);
return;
}
diff = new DetailedDiff(new Diff(control, test));
} catch (SAXException | IOException ex) {
throw new BrutException(ex);
}
if (qualifier != null) {
diff.overrideElementQualifier(qualifier);
}
diff.overrideElementQualifier(qualifier);
assertTrue(path + ": " + diff.getAllDifferences().toString(), diff.similar());
}

View File

@ -115,7 +115,7 @@ public abstract class TestUtils {
}
}
public static void cleanFrameworkFile() throws AndrolibException, BrutException {
public static void cleanFrameworkFile() throws BrutException {
File framework = new File(getFrameworkDir(), "1.apk");
if (Files.exists(framework.toPath())) {

View File

@ -14,8 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.aapt1;
import brut.androlib.*;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;

View File

@ -14,8 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.aapt1;
import brut.androlib.*;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
@ -38,7 +39,7 @@ public class AndroidOreoSparseTest extends BaseTest {
sTestOrigDir = new ExtFile(sTmpDir, "issue1594-orig");
sTestNewDir = new ExtFile(sTmpDir, "issue1594-new");
LOGGER.info("Unpacking sparse.apk...");
TestUtils.copyResourceDir(AndroidOreoNotSparseTest.class, "brut/apktool/issue1594", sTestOrigDir);
TestUtils.copyResourceDir(AndroidOreoSparseTest.class, "brut/apktool/issue1594", sTestOrigDir);
File testApk = new File(sTestOrigDir, "sparse.apk");

View File

@ -14,8 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.aapt1;
import brut.androlib.Androlib;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
@ -57,7 +61,7 @@ public class BuildAndDecodeJarTest extends BaseTest {
}
@Test
public void buildAndDecodeTest() throws BrutException {
public void buildAndDecodeTest() {
assertTrue(sTestNewDir.isDirectory());
}
}

View File

@ -14,8 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.aapt1;
import brut.androlib.Androlib;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
@ -63,7 +67,7 @@ public class BuildAndDecodeTest extends BaseTest {
}
@Test
public void buildAndDecodeTest() throws BrutException {
public void buildAndDecodeTest() {
assertTrue(sTestNewDir.isDirectory());
}
@ -244,73 +248,73 @@ public class BuildAndDecodeTest extends BaseTest {
}
@Test
public void anyDpiTest() throws BrutException, IOException {
public void anyDpiTest() throws BrutException {
compareValuesFiles("values-watch/strings.xml");
}
@Test
public void packed3CharsTest() throws BrutException, IOException {
public void packed3CharsTest() throws BrutException {
compareValuesFiles("values-ast-rES/strings.xml");
}
@Test
public void rightToLeftTest() throws BrutException, IOException {
public void rightToLeftTest() throws BrutException {
compareValuesFiles("values-ldrtl/strings.xml");
}
@Test
public void scriptBcp47Test() throws BrutException, IOException {
public void scriptBcp47Test() throws BrutException {
compareValuesFiles("values-b+en+Latn+US/strings.xml");
}
@Test
public void threeLetterLangBcp47Test() throws BrutException, IOException {
public void threeLetterLangBcp47Test() throws BrutException {
compareValuesFiles("values-ast/strings.xml");
}
@Test
public void androidOStringTest() throws BrutException, IOException {
public void androidOStringTest() throws BrutException {
compareValuesFiles("values-ast/strings.xml");
}
@Test
public void twoLetterNotHandledAsBcpTest() throws BrutException, IOException {
public void twoLetterNotHandledAsBcpTest() {
checkFolderExists("res/values-fr");
}
@Test
public void twoLetterLangBcp47Test() throws BrutException, IOException {
public void twoLetterLangBcp47Test() throws BrutException {
compareValuesFiles("values-en-rUS/strings.xml");
}
@Test
public void variantBcp47Test() throws BrutException, IOException {
public void variantBcp47Test() throws BrutException {
compareValuesFiles("values-b+en+US+POSIX/strings.xml");
}
@Test
public void fourpartBcp47Test() throws BrutException, IOException {
public void fourpartBcp47Test() throws BrutException {
compareValuesFiles("values-b+ast+Latn+IT+AREVELA/strings.xml");
}
@Test
public void RegionLocaleBcp47Test() throws BrutException, IOException {
public void RegionLocaleBcp47Test() throws BrutException {
compareValuesFiles("values-b+en+Latn+419/strings.xml");
}
@Test
public void numericalRegionBcp47Test() throws BrutException, IOException {
public void numericalRegionBcp47Test() throws BrutException {
compareValuesFiles("values-b+eng+419/strings.xml");
}
@Test
public void api23ConfigurationsTest() throws BrutException, IOException {
public void api23ConfigurationsTest() throws BrutException {
compareValuesFiles("values-round/strings.xml");
compareValuesFiles("values-notround/strings.xml");
}
@Test
public void api26ConfigurationsTest() throws BrutException, IOException {
public void api26ConfigurationsTest() throws BrutException {
compareValuesFiles("values-widecg-v26/strings.xml");
compareValuesFiles("values-lowdr-v26/strings.xml");
compareValuesFiles("values-nowidecg-v26/strings.xml");
@ -318,7 +322,7 @@ public class BuildAndDecodeTest extends BaseTest {
}
@Test
public void fontTest() throws BrutException, IOException {
public void fontTest() throws BrutException {
File fontXml = new File((sTestNewDir + "/res/font"), "lobster.xml");
File fontFile = new File((sTestNewDir + "/res/font"), "lobster_regular.otf");
@ -367,7 +371,7 @@ public class BuildAndDecodeTest extends BaseTest {
}
@Test
public void ninePatchImageColorTest() throws BrutException, IOException {
public void ninePatchImageColorTest() throws IOException {
char slash = File.separatorChar;
String location = slash + "res" + slash + "drawable-xhdpi" + slash;
@ -388,7 +392,7 @@ public class BuildAndDecodeTest extends BaseTest {
}
@Test
public void issue1508Test() throws BrutException, IOException {
public void issue1508Test() throws IOException {
char slash = File.separatorChar;
String location = slash + "res" + slash + "drawable-xhdpi" + slash;
@ -409,7 +413,7 @@ public class BuildAndDecodeTest extends BaseTest {
}
@Test
public void issue1511Test() throws BrutException, IOException {
public void issue1511Test() throws IOException {
char slash = File.separatorChar;
String location = slash + "res" + slash + "drawable-xxhdpi" + slash;
@ -432,7 +436,7 @@ public class BuildAndDecodeTest extends BaseTest {
}
@Test
public void robust9patchTest() throws BrutException, IOException {
public void robust9patchTest() throws 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"};

View File

@ -14,8 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.aapt1;
import brut.androlib.*;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
@ -43,7 +44,7 @@ public class DebugTagRetainedTest extends BaseTest {
sTestOrigDir = new ExtFile(sTmpDir, "issue1235-orig");
sTestNewDir = new ExtFile(sTmpDir, "issue1235-new");
LOGGER.info("Unpacking issue1235...");
TestUtils.copyResourceDir(BuildAndDecodeJarTest.class, "brut/apktool/issue1235/", sTestOrigDir);
TestUtils.copyResourceDir(DebugTagRetainedTest.class, "brut/apktool/issue1235/", sTestOrigDir);
LOGGER.info("Building issue1235.apk...");
ApkOptions apkOptions = new ApkOptions();

View File

@ -14,8 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.aapt1;
import brut.androlib.Androlib;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.common.BrutException;
import brut.directory.ExtFile;
import brut.util.OS;

View File

@ -14,8 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.aapt1;
import brut.androlib.Androlib;
import brut.androlib.ApkDecoder;
import brut.androlib.ApkOptions;
import brut.androlib.TestUtils;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
@ -59,7 +63,7 @@ public class EmptyResourcesArscTest {
}
@Test
public void buildAndDecodeTest() throws BrutException {
public void buildAndDecodeTest() {
assertTrue(sTestNewDir.isDirectory());
assertTrue(sTestOrigDir.isDirectory());
}

View File

@ -14,8 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.aapt1;
import brut.androlib.Androlib;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;

View File

@ -14,8 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.aapt1;
import brut.androlib.Androlib;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;

View File

@ -14,8 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.aapt1;
import brut.androlib.Androlib;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.androlib.meta.MetaInfo;
import brut.directory.ExtFile;
import brut.common.BrutException;

View File

@ -14,8 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.aapt1;
import brut.androlib.*;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;

View File

@ -14,8 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.aapt1;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;

View File

@ -14,8 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.aapt1;
import brut.androlib.*;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;

View File

@ -14,8 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.androlib;
import brut.androlib.BaseTest;
import brut.androlib.res.AndrolibResources;
import java.util.LinkedHashMap;
import java.util.Map;

View File

@ -14,8 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.decode;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;

View File

@ -14,8 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.decode;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;
@ -26,7 +29,6 @@ import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;
import static org.junit.Assert.assertTrue;

View File

@ -14,8 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.decode;
import brut.androlib.Androlib;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.androlib.meta.MetaInfo;
import brut.directory.ExtFile;
import brut.common.BrutException;

View File

@ -14,8 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.decode;
import brut.androlib.Androlib;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;

View File

@ -14,8 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.decode;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.common.BrutException;
import brut.directory.ExtFile;
import brut.util.OS;

View File

@ -14,8 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.decode;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.directory.ExtFile;
import brut.common.BrutException;
import brut.util.OS;

View File

@ -14,8 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.decode;
import brut.androlib.Androlib;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.androlib.meta.MetaInfo;
import brut.directory.ExtFile;
import brut.common.BrutException;

View File

@ -14,8 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.decode;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.common.BrutException;
import brut.directory.ExtFile;
import brut.util.OS;
@ -37,7 +40,7 @@ public class OutsideOfDirectoryEntryTest extends BaseTest {
public static void beforeClass() throws Exception {
TestUtils.cleanFrameworkFile();
sTmpDir = new ExtFile(OS.createTempDirectory());
TestUtils.copyResourceDir(DecodeKotlinTest.class, "brut/apktool/issue1589/", sTmpDir);
TestUtils.copyResourceDir(OutsideOfDirectoryEntryTest.class, "brut/apktool/issue1589/", sTmpDir);
String apk = "issue1589.apk";

View File

@ -14,8 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.decode;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.common.BrutException;
import brut.directory.ExtFile;
import brut.util.OS;

View File

@ -14,8 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.decode;
import brut.androlib.ApkDecoder;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.common.BrutException;
import brut.directory.ExtFile;
import brut.util.OS;

View File

@ -14,8 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.encoders;
import brut.androlib.BaseTest;
import brut.androlib.res.xml.ResXmlEncoders;
import org.junit.Test;

View File

@ -14,8 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib;
package brut.androlib.util;
import brut.androlib.BaseTest;
import brut.androlib.TestUtils;
import brut.common.BrutException;
import brut.common.InvalidUnknownFileException;
import brut.common.RootUnknownFileException;