Search in sources :

Example 31 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class MiniAaptTest method testInvalidItemResource.

@Test(expected = ResourceParseException.class)
public void testInvalidItemResource() throws IOException, ResourceParseException {
    ImmutableList<String> lines = ImmutableList.<String>builder().add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<resources>", "<item name=\"number\">100</item>", "</resources>").build();
    filesystem.writeLinesToPath(lines, Paths.get("values.xml"));
    MiniAapt aapt = new MiniAapt(resolver, filesystem, new FakeSourcePath(filesystem, "res"), Paths.get("R.txt"), ImmutableSet.of());
    aapt.processValuesFile(filesystem, Paths.get("values.xml"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 32 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class MiniAaptTest method testParsingCustomDrawables.

@Test
public void testParsingCustomDrawables() throws IOException, ResourceParseException {
    ImmutableList<String> lines = ImmutableList.<String>builder().add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<app-network xmlns:android=\"http://schemas.android.com/apk/res/android\">", "  xmlns:fbui=\"http://schemas.android.com/apk/res-auto\"", "  fbui:imageUri=\"http://facebook.com\"", "  android:width=\"128px\"", "  android:height=\"128px\"", "  fbui:density=\"160\"", "  >", "</app-network>").build();
    filesystem.writeLinesToPath(lines, Paths.get("custom_drawable.xml"));
    MiniAapt aapt = new MiniAapt(resolver, filesystem, new FakeSourcePath(filesystem, "res"), Paths.get("R.txt"), ImmutableSet.of());
    aapt.processDrawables(filesystem, Paths.get("custom_drawable.xml"));
    Set<RDotTxtEntry> definitions = aapt.getResourceCollector().getResources();
    assertThat(definitions, IsEqual.equalToObject(ImmutableSet.<RDotTxtEntry>of(new FakeRDotTxtEntry(IdType.INT, RType.DRAWABLE, "custom_drawable", RDotTxtEntry.CustomDrawableType.CUSTOM))));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 33 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class MiniAaptTest method testParsingGrayscaleImage.

@Test
public void testParsingGrayscaleImage() throws IOException, ResourceParseException {
    ImmutableList<String> lines = ImmutableList.<String>builder().add("").build();
    filesystem.writeLinesToPath(lines, Paths.get("fbui_tomato.png"));
    MiniAapt aapt = new MiniAapt(resolver, filesystem, new FakeSourcePath(filesystem, "res"), Paths.get("R.txt"), ImmutableSet.of(), /* resourceUnion */
    false, /* isGrayscaleImageProcessingEnabled */
    true);
    aapt.processDrawables(filesystem, Paths.get("fbui_tomato.g.png"));
    Set<RDotTxtEntry> definitions = aapt.getResourceCollector().getResources();
    assertThat(definitions, IsEqual.equalToObject(ImmutableSet.<RDotTxtEntry>of(new FakeRDotTxtEntry(IdType.INT, RType.DRAWABLE, "fbui_tomato", RDotTxtEntry.CustomDrawableType.GRAYSCALE_IMAGE))));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 34 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class MiniAaptTest method testInvalidResourceType.

@Test(expected = ResourceParseException.class)
public void testInvalidResourceType() throws IOException, ResourceParseException {
    ImmutableList<String> lines = ImmutableList.<String>builder().add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<resources>", "<resourcetype name=\"number\">100</resourcetype>", "</resources>").build();
    filesystem.writeLinesToPath(lines, Paths.get("values.xml"));
    MiniAapt aapt = new MiniAapt(resolver, filesystem, new FakeSourcePath(filesystem, "res"), Paths.get("R.txt"), ImmutableSet.of());
    aapt.processValuesFile(filesystem, Paths.get("values.xml"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 35 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class MiniAaptTest method testFindingResourceIdsInXml.

@Test
public void testFindingResourceIdsInXml() throws IOException, XPathExpressionException, ResourceParseException {
    filesystem.writeLinesToPath(RESOURCES, Paths.get("resource.xml"));
    MiniAapt aapt = new MiniAapt(resolver, filesystem, new FakeSourcePath(filesystem, "res"), Paths.get("R.txt"), ImmutableSet.of());
    ImmutableSet.Builder<RDotTxtEntry> references = ImmutableSet.builder();
    aapt.processXmlFile(filesystem, Paths.get("resource.xml"), references);
    Set<RDotTxtEntry> definitions = aapt.getResourceCollector().getResources();
    assertEquals(definitions, ImmutableSet.<RDotTxtEntry>of(new FakeRDotTxtEntry(IdType.INT, RType.ID, "button1"), new FakeRDotTxtEntry(IdType.INT, RType.ID, "button3")));
    assertEquals(references.build(), ImmutableSet.<RDotTxtEntry>of(new FakeRDotTxtEntry(IdType.INT, RType.DRAWABLE, "some_image"), new FakeRDotTxtEntry(IdType.INT, RType.STRING, "text"), new FakeRDotTxtEntry(IdType.INT, RType.STYLE, "Buck_Theme"), new FakeRDotTxtEntry(IdType.INT, RType.ID, "button2")));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ImmutableSet(com.google.common.collect.ImmutableSet) Test(org.junit.Test)

Aggregations

FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)318 Test (org.junit.Test)297 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)188 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)188 BuildTarget (com.facebook.buck.model.BuildTarget)182 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)116 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)104 SourcePath (com.facebook.buck.rules.SourcePath)90 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)85 TargetGraph (com.facebook.buck.rules.TargetGraph)84 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)68 Path (java.nio.file.Path)67 BuildRule (com.facebook.buck.rules.BuildRule)52 PathSourcePath (com.facebook.buck.rules.PathSourcePath)48 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)46 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)45 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)45 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)35 CxxLibraryBuilder (com.facebook.buck.cxx.CxxLibraryBuilder)25 NSString (com.dd.plist.NSString)24