summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceParser_test.cpp
diff options
context:
space:
mode:
authorMihai Nita <mnita@google.com>2019-03-26 13:47:45 -0700
committerMihai Nita <mnita@google.com>2019-03-29 17:15:18 -0700
commitd1a6521cc35fc882c9b4c5b31babd7748b445698 (patch)
treeb1fa72782f535e72df99b2f99174fa0ba4d3a36e /tools/aapt2/ResourceParser_test.cpp
parente4329dc3ef4c8bc67effb61722019693e92d8518 (diff)
Fix aapt2 pseudo-translating donottranslate* files
Bug: 126423638 Test: After building android doing this in the 'out' folder: Test: Test: ./soong/host/linux-x86/bin/aapt d --values resources \ Test: ./target/product/sailfish/system/product/priv-app/SystemUIGoogle/SystemUIGoogle.apk \ Test: | less Test: Test: search for `system_ui_aod_date_pattern` in the output, found this: Test: (string8) "[éééḾḾḾð one two]" Test: (string8) "<U+200F><U+202E>eeeMMMd<U+202C><U+200F>" Test: (the en-XA and ar-XB pseudo-translated versions of the string) Test: Test: After the fix and rebuild the dump only finds the original English string ("eeeMMMd") Test: Also flashed the image, switched to en-XA, and left the phone around for more than 24 hours. Change-Id: I2fb7c5b5ee7d3d3200410593346682ed16559056
Diffstat (limited to 'tools/aapt2/ResourceParser_test.cpp')
-rw-r--r--tools/aapt2/ResourceParser_test.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp
index 53361414e9b8..857792192902 100644
--- a/tools/aapt2/ResourceParser_test.cpp
+++ b/tools/aapt2/ResourceParser_test.cpp
@@ -217,6 +217,29 @@ TEST_F(ResourceParserTest, ParseStyledStringWithWhitespace) {
EXPECT_THAT(str->value->spans[1].last_char, Eq(13u));
}
+TEST_F(ResourceParserTest, ParseStringTranslatableAttribute) {
+ // If there is no translate attribute the default is 'true'
+ EXPECT_TRUE(TestParse(R"(<string name="foo1">Translate</string>)"));
+ String* str = test::GetValue<String>(&table_, "string/foo1");
+ ASSERT_THAT(str, NotNull());
+ ASSERT_TRUE(str->IsTranslatable());
+
+ // Explicit 'true' translate attribute
+ EXPECT_TRUE(TestParse(R"(<string name="foo2" translatable="true">Translate</string>)"));
+ str = test::GetValue<String>(&table_, "string/foo2");
+ ASSERT_THAT(str, NotNull());
+ ASSERT_TRUE(str->IsTranslatable());
+
+ // Explicit 'false' translate attribute
+ EXPECT_TRUE(TestParse(R"(<string name="foo3" translatable="false">Do not translate</string>)"));
+ str = test::GetValue<String>(&table_, "string/foo3");
+ ASSERT_THAT(str, NotNull());
+ ASSERT_FALSE(str->IsTranslatable());
+
+ // Invalid value for the translate attribute, should be boolean ('true' or 'false')
+ EXPECT_FALSE(TestParse(R"(<string name="foo4" translatable="yes">Translate</string>)"));
+}
+
TEST_F(ResourceParserTest, IgnoreXliffTagsOtherThanG) {
std::string input = R"(
<string name="foo" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">