| 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.aapt1; |
| 18 |
|
| 19 |
import brut.androlib.*; |
| 20 |
import brut.androlib.options.BuildOptions; |
| 21 |
import brut.directory.ExtFile; |
| 22 |
import brut.common.BrutException; |
| 23 |
import brut.util.OS; |
| 24 |
import org.junit.AfterClass; |
| 25 |
import org.junit.BeforeClass; |
| 26 |
import org.junit.Test; |
| 27 |
|
| 28 |
import java.io.File; |
| 29 |
import java.io.IOException; |
| 30 |
import java.nio.file.Files; |
| 31 |
import java.nio.file.Paths; |
| 32 |
|
| 33 |
import static org.junit.Assert.assertTrue; |
| 34 |
|
| 35 |
public class SharedLibraryTest extends BaseTest { |
| 36 |
|
| 37 |
@BeforeClass |
| 38 |
public static void beforeClass() throws BrutException { |
| 39 |
TestUtils.cleanFrameworkFile(); |
| 40 |
sTmpDir = new ExtFile(OS.createTempDirectory()); |
| 41 |
TestUtils.copyResourceDir(SharedLibraryTest.class, "aapt1/shared_libraries/", sTmpDir); |
| 42 |
} |
| 43 |
|
| 44 |
@AfterClass |
| 45 |
public static void afterClass() throws BrutException { |
| 46 |
OS.rmdir(sTmpDir); |
| 47 |
} |
| 48 |
|
| 49 |
@Test |
| 50 |
public void isFrameworkTaggingWorking() throws AndrolibException { |
| 51 |
String apkName = "library.apk"; |
| 52 |
|
| 53 |
BuildOptions buildOptions = new BuildOptions(); |
| 54 |
buildOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath(); |
| 55 |
buildOptions.frameworkTag = "building"; |
| 56 |
|
| 57 |
new Androlib(buildOptions).installFramework(new File(sTmpDir + File.separator + apkName)); |
| 58 |
|
| 59 |
assertTrue(fileExists("2-building.apk")); |
| 60 |
} |
| 61 |
|
| 62 |
@Test |
| 63 |
public void isFrameworkInstallingWorking() throws AndrolibException { |
| 64 |
String apkName = "library.apk"; |
| 65 |
|
| 66 |
BuildOptions buildOptions = new BuildOptions(); |
| 67 |
buildOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath(); |
| 68 |
|
| 69 |
new Androlib(buildOptions).installFramework(new File(sTmpDir + File.separator + apkName)); |
| 70 |
|
| 71 |
assertTrue(fileExists("2.apk")); |
| 72 |
} |
| 73 |
|
| 74 |
@Test |
| 75 |
public void isSharedResourceDecodingAndRebuildingWorking() throws IOException, BrutException { |
| 76 |
String library = "library.apk"; |
| 77 |
String client = "client.apk"; |
| 78 |
|
| 79 |
// setup apkOptions |
| 80 |
BuildOptions buildOptions = new BuildOptions(); |
| 81 |
buildOptions.frameworkFolderLocation = sTmpDir.getAbsolutePath(); |
| 82 |
buildOptions.frameworkTag = "shared"; |
| 83 |
|
| 84 |
// install library/framework |
| 85 |
new Androlib(buildOptions).installFramework(new File(sTmpDir + File.separator + library)); |
| 86 |
assertTrue(fileExists("2-shared.apk")); |
| 87 |
|
| 88 |
// decode client.apk |
| 89 |
ApkDecoder apkDecoder = new ApkDecoder(new File(sTmpDir + File.separator + client)); |
| 90 |
apkDecoder.setOutDir(new File(sTmpDir + File.separator + client + ".out")); |
| 91 |
apkDecoder.setFrameworkDir(buildOptions.frameworkFolderLocation); |
| 92 |
apkDecoder.setFrameworkTag(buildOptions.frameworkTag); |
| 93 |
apkDecoder.decode(); |
| 94 |
|
| 95 |
// decode library.apk |
| 96 |
ApkDecoder libraryDecoder = new ApkDecoder(new File(sTmpDir + File.separator + library)); |
| 97 |
libraryDecoder.setOutDir(new File(sTmpDir + File.separator + library + ".out")); |
| 98 |
libraryDecoder.setFrameworkDir(buildOptions.frameworkFolderLocation); |
| 99 |
libraryDecoder.setFrameworkTag(buildOptions.frameworkTag); |
| 100 |
libraryDecoder.decode(); |
| 101 |
|
| 102 |
// build client.apk |
| 103 |
ExtFile clientApk = new ExtFile(sTmpDir, client + ".out"); |
| 104 |
new Androlib(buildOptions).build(clientApk, null); |
| 105 |
assertTrue(fileExists(client + ".out" + File.separator + "dist" + File.separator + client)); |
| 106 |
|
| 107 |
// build library.apk (shared library) |
| 108 |
ExtFile libraryApk = new ExtFile(sTmpDir, library + ".out"); |
| 109 |
new Androlib(buildOptions).build(libraryApk, null); |
| 110 |
assertTrue(fileExists(library + ".out" + File.separator + "dist" + File.separator + library)); |
| 111 |
} |
| 112 |
|
| 113 |
private boolean fileExists(String filepath) { |
| 114 |
return Files.exists(Paths.get(sTmpDir.getAbsolutePath() + File.separator + filepath)); |
| 115 |
} |
| 116 |
} |