aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2016-08-01 15:48:01 +0000
committerGravatar Yun Peng <pcloudy@google.com>2016-08-02 07:32:55 +0000
commit7eaa816646c2faa488b26c709ab173512b91cf37 (patch)
tree0241054811f9a0207edc4f6dea755ccba8f62811 /src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java
parent32994caee8e2d06dad9006c8a6e0931e03818403 (diff)
Tolerate missing field value in binary's R.txt
The binary's R.txt might not be superset of symbols in the various library R.txt files. The R.java writer had tolerated this, as did an older version of the RClassGen (lost in refactoring). Bring back the null check. This can happen if the binary has res overrides that *remove* symbols. E.g., if noop/res/layout/stats.xml overrides dev/.../stats.xml, and the noop version removes elements not needed for production. Test mocks can do something similar. -- MOS_MIGRATED_REVID=128989080
Diffstat (limited to 'src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java b/src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java
index 33a75b89ed..0b53d86264 100644
--- a/src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java
+++ b/src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java
@@ -181,6 +181,45 @@ public class RClassGeneratorTest {
}
@Test
+ public void binaryDropsLibraryFields() throws Exception {
+ boolean finalFields = true;
+ // Test what happens if the binary R.txt is not a strict superset of the
+ // library R.txt (overrides that drop elements).
+ SymbolLoader symbolValues = createSymbolFile("R.txt",
+ "int layout stubbable_activity 0x7f020000");
+ SymbolLoader symbolsInLibrary = createSymbolFile("lib.R.txt",
+ "int id debug_text_field 0x1",
+ "int id debug_text_field2 0x1",
+ "int layout stubbable_activity 0x1");
+ Path out = temp.resolve("classes");
+ Files.createDirectories(out);
+ RClassGenerator writer = RClassGenerator.fromSymbols(out, "com.foo",
+ symbolValues, ImmutableList.of(symbolsInLibrary), finalFields);
+ writer.write();
+
+ Path packageDir = out.resolve("com/foo");
+ checkFilesInPackage(packageDir, "R.class", "R$id.class", "R$layout.class");
+ Class<?> outerClass = checkTopLevelClass(out,
+ "com.foo.R",
+ "com.foo.R$id",
+ "com.foo.R$layout");
+ checkInnerClass(out,
+ "com.foo.R$id",
+ outerClass,
+ ImmutableMap.<String, Integer>of(),
+ ImmutableMap.<String, List<Integer>>of(),
+ finalFields
+ );
+ checkInnerClass(out,
+ "com.foo.R$layout",
+ outerClass,
+ ImmutableMap.of("stubbable_activity", 0x7f020000),
+ ImmutableMap.<String, List<Integer>>of(),
+ finalFields
+ );
+ }
+
+ @Test
public void intArraysFinal() throws Exception {
checkIntArrays(true);
}