Search in sources :

Example 51 with ZipInspector

use of com.facebook.buck.testutil.integration.ZipInspector in project buck by facebook.

the class ProjectFilesystemTest method testCreateZip.

@Test
public void testCreateZip() throws IOException {
    tmp.newFolder("foo");
    tmp.newFile("foo/bar.txt");
    tmp.newFile("foo/baz.txt");
    Path output = tmp.newFile("out.zip");
    filesystem.createZip(ImmutableList.of(Paths.get("foo/bar.txt"), Paths.get("foo/baz.txt")), output);
    ZipInspector zipInspector = new ZipInspector(output);
    assertEquals(ImmutableSet.of("foo/bar.txt", "foo/baz.txt"), zipInspector.getZipFileEntries());
}
Also used : Path(java.nio.file.Path) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) Test(org.junit.Test)

Example 52 with ZipInspector

use of com.facebook.buck.testutil.integration.ZipInspector in project buck by facebook.

the class AndroidResourceFilterIntegrationTest method testApkWithMdpiFilter.

@Test
public void testApkWithMdpiFilter() throws IOException {
    String target = "//apps/sample:app_mdpi";
    ProjectWorkspace.ProcessResult result = workspace.runBuckCommand("build", target);
    result.assertSuccess();
    Path apkFile = workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(target), "%s.apk"));
    ZipInspector zipInspector = new ZipInspector(apkFile);
    if (isBuildToolsNew) {
        zipInspector.assertFileExists("res/drawable-mdpi-v4/app_icon.png");
        zipInspector.assertFileDoesNotExist("res/drawable-hdpi-v4/app_icon.png");
        zipInspector.assertFileDoesNotExist("res/drawable-xhdpi-v4/app_icon.png");
    } else {
        zipInspector.assertFileExists("res/drawable-mdpi/app_icon.png");
        zipInspector.assertFileDoesNotExist("res/drawable-hdpi/app_icon.png");
        zipInspector.assertFileDoesNotExist("res/drawable-xhdpi/app_icon.png");
    }
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) Test(org.junit.Test)

Example 53 with ZipInspector

use of com.facebook.buck.testutil.integration.ZipInspector in project buck by facebook.

the class AndroidResourceFilterIntegrationTest method testApkWithStringsAsAssetsAndResourceFilter.

@Test
public void testApkWithStringsAsAssetsAndResourceFilter() throws IOException {
    String target = "//apps/sample:app_comp_str_xhdpi";
    ProjectWorkspace.ProcessResult result = workspace.runBuckBuild(target);
    result.assertSuccess();
    Path apkFile = workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(target), "%s.apk"));
    ZipInspector zipInspector = new ZipInspector(apkFile);
    zipInspector.assertFileExists("assets/strings/fr.fbstr");
    if (isBuildToolsNew) {
        zipInspector.assertFileExists("res/drawable-xhdpi-v4/app_icon.png");
        zipInspector.assertFileDoesNotExist("res/drawable-hdpi-v4/app_icon.png");
        zipInspector.assertFileDoesNotExist("res/drawable-mdpi-v4/app_icon.png");
    } else {
        zipInspector.assertFileExists("res/drawable-xhdpi/app_icon.png");
        zipInspector.assertFileDoesNotExist("res/drawable-hdpi/app_icon.png");
        zipInspector.assertFileDoesNotExist("res/drawable-mdpi/app_icon.png");
    }
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) Test(org.junit.Test)

Example 54 with ZipInspector

use of com.facebook.buck.testutil.integration.ZipInspector in project buck by facebook.

the class AndroidResourceFilterIntegrationTest method testApkWithoutResourceFilter.

@Test
public void testApkWithoutResourceFilter() throws IOException {
    String target = "//apps/sample:app";
    ProjectWorkspace.ProcessResult result = workspace.runBuckCommand("build", target);
    result.assertSuccess();
    Path apkFile = workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(target), "%s.apk"));
    ZipInspector zipInspector = new ZipInspector(apkFile);
    if (isBuildToolsNew) {
        zipInspector.assertFileExists("res/drawable-mdpi-v4/app_icon.png");
        zipInspector.assertFileExists("res/drawable-hdpi-v4/app_icon.png");
        zipInspector.assertFileExists("res/drawable-xhdpi-v4/app_icon.png");
    } else {
        zipInspector.assertFileExists("res/drawable-mdpi/app_icon.png");
        zipInspector.assertFileExists("res/drawable-hdpi/app_icon.png");
        zipInspector.assertFileExists("res/drawable-xhdpi/app_icon.png");
    }
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) Test(org.junit.Test)

Example 55 with ZipInspector

use of com.facebook.buck.testutil.integration.ZipInspector in project buck by facebook.

the class AndroidResourceFilterIntegrationTest method testModifyingImageRebuildsResourcesFilter.

@Test
public void testModifyingImageRebuildsResourcesFilter() throws IOException {
    String target = "//apps/sample:app_mdpi";
    ProjectWorkspace.ProcessResult result = workspace.runBuckBuild(target);
    result.assertSuccess();
    Path apkFile = workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(target), "%s.apk"));
    String iconPath = isBuildToolsNew ? "res/drawable-mdpi-v4/app_icon.png" : "res/drawable-mdpi/app_icon.png";
    long firstImageCrc = new ZipInspector(apkFile).getCrc(iconPath);
    workspace.copyFile("res/com/sample/base/res/drawable-hdpi/app_icon.png", "res/com/sample/base/res/drawable-mdpi/app_icon.png");
    workspace.resetBuildLogFile();
    result = workspace.runBuckBuild(target);
    result.assertSuccess();
    BuckBuildLog buildLog = workspace.getBuildLog();
    buildLog.assertTargetBuiltLocally(target);
    apkFile = workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(target), "%s.apk"));
    long secondImageCrc = new ZipInspector(apkFile).getCrc(iconPath);
    assertNotEquals(firstImageCrc, secondImageCrc);
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) Test(org.junit.Test)

Aggregations

ZipInspector (com.facebook.buck.testutil.integration.ZipInspector)63 Test (org.junit.Test)62 Path (java.nio.file.Path)34 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)29 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)15 BuildTarget (com.facebook.buck.model.BuildTarget)10 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 TestConsole (com.facebook.buck.testutil.TestConsole)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)3 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)3 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)3 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)3 ProcessResult (com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult)3 Clock (com.facebook.buck.timing.Clock)3 DefaultClock (com.facebook.buck.timing.DefaultClock)3 SymbolGetter (com.facebook.buck.android.AndroidNdkHelper.SymbolGetter)2 SymbolsAndDtNeeded (com.facebook.buck.android.AndroidNdkHelper.SymbolsAndDtNeeded)2 FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)2 ExecutionContext (com.facebook.buck.step.ExecutionContext)2