| 1 |
/* |
| 2 |
* Copyright (C) 2010 Ryszard Wiśniewski <[email protected]> |
| 3 |
* Copyright (C) 2010 Connor Tumbleson <[email protected]> |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
* you may not use this file except in compliance with the License. |
| 7 |
* You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* https://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
*/ |
| 17 |
package brut.androlib.aapt2; |
| 18 |
|
| 19 |
import brut.androlib.*; |
| 20 |
import brut.androlib.meta.MetaInfo; |
| 21 |
import brut.androlib.options.BuildOptions; |
| 22 |
import brut.common.BrutException; |
| 23 |
import brut.directory.ExtFile; |
| 24 |
import brut.util.OS; |
| 25 |
import org.junit.AfterClass; |
| 26 |
import org.junit.BeforeClass; |
| 27 |
import org.junit.Test; |
| 28 |
|
| 29 |
import java.io.File; |
| 30 |
import java.io.IOException; |
| 31 |
|
| 32 |
import static org.junit.Assert.*; |
| 33 |
|
| 34 |
public class BuildAndDecodeTest extends BaseTest { |
| 35 |
|
| 36 |
@BeforeClass |
| 37 |
public static void beforeClass() throws Exception { |
| 38 |
TestUtils.cleanFrameworkFile(); |
| 39 |
|
| 40 |
sTmpDir = new ExtFile(OS.createTempDirectory()); |
| 41 |
sTestOrigDir = new ExtFile(sTmpDir, "testapp-orig"); |
| 42 |
sTestNewDir = new ExtFile(sTmpDir, "testapp-new"); |
| 43 |
LOGGER.info("Unpacking testapp..."); |
| 44 |
TestUtils.copyResourceDir(BuildAndDecodeTest.class, "aapt2/testapp/", sTestOrigDir); |
| 45 |
|
| 46 |
BuildOptions buildOptions = new BuildOptions(); |
| 47 |
buildOptions.useAapt2 = true; |
| 48 |
buildOptions.verbose = true; |
| 49 |
|
| 50 |
LOGGER.info("Building testapp.apk..."); |
| 51 |
File testApk = new File(sTmpDir, "testapp.apk"); |
| 52 |
new Androlib(buildOptions).build(sTestOrigDir, testApk); |
| 53 |
|
| 54 |
LOGGER.info("Decoding testapp.apk..."); |
| 55 |
ApkDecoder apkDecoder = new ApkDecoder(testApk); |
| 56 |
apkDecoder.setOutDir(sTestNewDir); |
| 57 |
apkDecoder.decode(); |
| 58 |
} |
| 59 |
|
| 60 |
@AfterClass |
| 61 |
public static void afterClass() throws BrutException { |
| 62 |
OS.rmdir(sTmpDir); |
| 63 |
} |
| 64 |
|
| 65 |
@Test |
| 66 |
public void buildAndDecodeTest() { |
| 67 |
assertTrue(sTestNewDir.isDirectory()); |
| 68 |
} |
| 69 |
|
| 70 |
@Test |
| 71 |
public void valuesStringsTest() throws BrutException { |
| 72 |
compareValuesFiles("values/strings.xml"); |
| 73 |
} |
| 74 |
|
| 75 |
@Test |
| 76 |
public void valuesMaxLengthTest() throws BrutException { |
| 77 |
compareValuesFiles("values-es/strings.xml"); |
| 78 |
} |
| 79 |
|
| 80 |
@Test |
| 81 |
public void confirmZeroByteFileExtensionIsNotStored() throws BrutException { |
| 82 |
MetaInfo metaInfo = new Androlib().readMetaFile(sTestNewDir); |
| 83 |
assertFalse(metaInfo.doNotCompress.contains("jpg")); |
| 84 |
} |
| 85 |
|
| 86 |
@Test |
| 87 |
public void confirmZeroByteFileIsStored() throws BrutException { |
| 88 |
MetaInfo metaInfo = new Androlib().readMetaFile(sTestNewDir); |
| 89 |
assertTrue(metaInfo.doNotCompress.contains("assets/0byte_file.jpg")); |
| 90 |
} |
| 91 |
|
| 92 |
@Test |
| 93 |
public void navigationResourceTest() throws BrutException { |
| 94 |
compareXmlFiles("res/navigation/nav_graph.xml"); |
| 95 |
} |
| 96 |
|
| 97 |
@Test |
| 98 |
public void xmlIdsEmptyTest() throws BrutException { |
| 99 |
compareXmlFiles("res/values/ids.xml"); |
| 100 |
} |
| 101 |
|
| 102 |
@Test |
| 103 |
public void leadingDollarSignResourceNameTest() throws BrutException { |
| 104 |
compareXmlFiles("res/drawable/$avd_hide_password__0.xml"); |
| 105 |
compareXmlFiles("res/drawable/$avd_show_password__0.xml"); |
| 106 |
compareXmlFiles("res/drawable/$avd_show_password__1.xml"); |
| 107 |
compareXmlFiles("res/drawable/$avd_show_password__2.xml"); |
| 108 |
compareXmlFiles("res/drawable/avd_show_password.xml"); |
| 109 |
} |
| 110 |
|
| 111 |
@Test |
| 112 |
public void samsungQmgFilesHandledTest() throws IOException, BrutException { |
| 113 |
compareBinaryFolder("drawable-xhdpi", true); |
| 114 |
} |
| 115 |
|
| 116 |
@Test |
| 117 |
public void confirmManifestStructureTest() throws BrutException { |
| 118 |
compareXmlFiles("AndroidManifest.xml"); |
| 119 |
} |
| 120 |
|
| 121 |
@Test |
| 122 |
public void xmlXsdFileTest() throws BrutException { |
| 123 |
compareXmlFiles("res/xml/ww_box_styles_schema.xsd"); |
| 124 |
} |
| 125 |
|
| 126 |
@Test |
| 127 |
public void multipleDexTest() throws BrutException, IOException { |
| 128 |
compareBinaryFolder("/smali_classes2", false); |
| 129 |
compareBinaryFolder("/smali_classes3", false); |
| 130 |
|
| 131 |
File classes2Dex = new File(sTestOrigDir, "build/apk/classes2.dex"); |
| 132 |
File classes3Dex = new File(sTestOrigDir, "build/apk/classes3.dex"); |
| 133 |
|
| 134 |
assertTrue(classes2Dex.isFile()); |
| 135 |
assertTrue(classes3Dex.isFile()); |
| 136 |
} |
| 137 |
|
| 138 |
@Test |
| 139 |
public void singleDexTest() throws BrutException, IOException { |
| 140 |
compareBinaryFolder("/smali", false); |
| 141 |
|
| 142 |
File classesDex = new File(sTestOrigDir, "build/apk/classes.dex"); |
| 143 |
assertTrue(classesDex.isFile()); |
| 144 |
} |
| 145 |
} |