summaryrefslogtreecommitdiff
path: root/libs/androidfw/tests/ResTable_test.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2016-02-23 17:49:53 -0800
committerAdam Lesinski <adamlesinski@google.com>2016-03-09 17:33:14 -0800
commitff5808d223d6359448afc532717b8ccfdc5182d8 (patch)
tree39db02737ed994b392e44838612d7ec610f1edd4 /libs/androidfw/tests/ResTable_test.cpp
parent0dd17c840645e6d1fd67276b45420ca742df6110 (diff)
AssetManager: Cache a pre-filtered list of configurations
When we set the parameters for a ResTable, we can pre-filter which resources match and only look at that smaller list when getting entries. This helps A LOT with types that have many configurations, like strings and all their various locales. We must store the cached entries in a parallel data structure because parts of the main Type object are shared with other ResTables, causing data races. Bug:25499111 Change-Id: I63e37dcbd683fc9f1e7d0f3a6ed4c1c01e0fc575
Diffstat (limited to 'libs/androidfw/tests/ResTable_test.cpp')
-rw-r--r--libs/androidfw/tests/ResTable_test.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/libs/androidfw/tests/ResTable_test.cpp b/libs/androidfw/tests/ResTable_test.cpp
index dcfe91e3866d..7cd7fb5cd711 100644
--- a/libs/androidfw/tests/ResTable_test.cpp
+++ b/libs/androidfw/tests/ResTable_test.cpp
@@ -282,4 +282,46 @@ TEST(ResTableTest, U16StringToInt) {
testU16StringToInt(u"0x1ffffffff", 0U, false, true);
}
+TEST(ResTableTest, ShareButDontModifyResTable) {
+ ResTable sharedTable;
+ ASSERT_EQ(NO_ERROR, sharedTable.add(basic_arsc, basic_arsc_len));
+
+ ResTable_config param;
+ memset(&param, 0, sizeof(param));
+ param.language[0] = 'v';
+ param.language[1] = 's';
+ sharedTable.setParameters(&param);
+
+ // Check that we get the default value for @integer:number1
+ Res_value val;
+ ssize_t block = sharedTable.getResource(base::R::integer::number1, &val, MAY_NOT_BE_BAG);
+ ASSERT_GE(block, 0);
+ ASSERT_EQ(Res_value::TYPE_INT_DEC, val.dataType);
+ ASSERT_EQ(uint32_t(600), val.data);
+
+ // Create a new table that shares the entries of the shared table.
+ ResTable table;
+ ASSERT_EQ(NO_ERROR, table.add(&sharedTable, false));
+
+ // Set a new configuration on the new table.
+ memset(&param, 0, sizeof(param));
+ param.language[0] = 's';
+ param.language[1] = 'v';
+ param.country[0] = 'S';
+ param.country[1] = 'E';
+ table.setParameters(&param);
+
+ // Check that we get a new value in the new table.
+ block = table.getResource(base::R::integer::number1, &val, MAY_NOT_BE_BAG);
+ ASSERT_GE(block, 0);
+ ASSERT_EQ(Res_value::TYPE_INT_DEC, val.dataType);
+ ASSERT_EQ(uint32_t(400), val.data);
+
+ // Check that we still get the old value in the shared table.
+ block = sharedTable.getResource(base::R::integer::number1, &val, MAY_NOT_BE_BAG);
+ ASSERT_GE(block, 0);
+ ASSERT_EQ(Res_value::TYPE_INT_DEC, val.dataType);
+ ASSERT_EQ(uint32_t(600), val.data);
}
+
+} // namespace