コード例 #1
0
  public void testCombinedJarHeaderMapping() throws IOException {
    File outputHeaderMappingFile = new File(tempDir, "mappings.j2objc");
    Options.setOutputHeaderMappingFile(outputHeaderMappingFile);
    Options.setOutputStyle(Options.OutputStyleOption.SOURCE);
    addSourceFile("package unit; public class Test { }", "unit/Test.java");
    addSourceFile(
        "package unit; public class AnotherTest extends Test { }", "unit/AnotherTest.java");
    addSourceFile(
        "package unit2;" + "import unit.Test;" + "public class AnotherTest extends Test { }",
        "unit2/AnotherTest.java");
    addSourceFile(
        "package unit2;"
            + "import unit.AnotherTest;"
            + "public class YetAnotherTest extends AnotherTest { }",
        "unit2/YetAnotherTest.java");

    translateCombinedFiles("unit/Foo", ".h", "unit/Test.java", "unit/AnotherTest.java");
    String header2 =
        translateCombinedFiles(
            "unit2/Foo", ".h", "unit2/AnotherTest.java", "unit2/YetAnotherTest.java");

    HeaderMap headerMap = Options.getHeaderMap();
    assertEquals("unit/Foo.h", headerMap.get("unit.Test"));
    assertEquals("unit/Foo.h", headerMap.get("unit.AnotherTest"));
    assertTranslation(header2, "#include \"unit/Foo.h\"");
    assertEquals("unit2/Foo.h", headerMap.get("unit2.AnotherTest"));
    assertEquals("unit2/Foo.h", headerMap.get("unit2.YetAnotherTest"));
  }
コード例 #2
0
  public void testOutputHeaderFileMapping() throws IOException {
    Options.setHeaderMappingFiles(Lists.newArrayList("testMappings.j2objc"));
    Options.setOutputStyle(Options.OutputStyleOption.SOURCE);
    addSourceFile("package unit.test; public class Dummy {}", "unit/test/Dummy.java");
    addSourceFile(
        "package unit.test;"
            + "public class AnotherDummy extends Dummy { "
            + "    public AnotherDummy() {}"
            + "}",
        "unit/test/AnotherDummy.java");

    preprocessFiles("unit/test/Dummy.java", "unit/test/AnotherDummy.java");
    loadHeaderMappings();

    String translation =
        translateSourceFile(
            getTranslatedFile("unit/test/AnotherDummy.java"), "AnotherDummy", "AnotherDummy.h");
    assertTranslation(translation, "#include \"unit/test/Dummy.h\"");

    HeaderMap headerMap = Options.getHeaderMap();
    assertEquals(headerMap.get("unit.test.Dummy"), "unit/test/Dummy.h");
    assertEquals(headerMap.get("unit.test.AnotherDummy"), "unit/test/AnotherDummy.h");
    assertEquals(headerMap.get("unit.mapping.custom.Test"), "my/mapping/custom/Test.h");
    assertEquals(headerMap.get("unit.mapping.custom.AnotherTest"), "my/mapping/custom/Test.h");
  }