OLD | NEW |
1 // Copyright (C) 2013 Google Inc. | 1 // Copyright (C) 2013 Google Inc. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // 1) Verifies that a region code consists of two characters, for example "TW". | 68 // 1) Verifies that a region code consists of two characters, for example "TW". |
69 // 2) Verifies that BuildComponents() returns valid UI components for a region | 69 // 2) Verifies that BuildComponents() returns valid UI components for a region |
70 // code. | 70 // code. |
71 // 3) Verifies that BuildComponents() returns a non-empty vector for a region | 71 // 3) Verifies that BuildComponents() returns a non-empty vector for a region |
72 // code. | 72 // code. |
73 TEST(AddressUiTest, RegionsAndComponentsAreValid) { | 73 TEST(AddressUiTest, RegionsAndComponentsAreValid) { |
74 const std::vector<std::string>& region_codes = GetRegionCodes(); | 74 const std::vector<std::string>& region_codes = GetRegionCodes(); |
75 for (size_t i = 0; i < region_codes.size(); ++i) { | 75 for (size_t i = 0; i < region_codes.size(); ++i) { |
76 SCOPED_TRACE("Region code: " + region_codes[i]); | 76 SCOPED_TRACE("Region code: " + region_codes[i]); |
77 EXPECT_EQ(2U, region_codes[i].size()); | 77 EXPECT_EQ(2U, region_codes[i].size()); |
78 EXPECT_TRUE(ComponentsAreValid(BuildComponents(region_codes[i]))); | 78 EXPECT_TRUE(ComponentsAreValid( |
| 79 BuildComponents(region_codes[i], std::string(), NULL))); |
79 EXPECT_FALSE(GetRequiredFields(region_codes[i]).empty()); | 80 EXPECT_FALSE(GetRequiredFields(region_codes[i]).empty()); |
80 } | 81 } |
81 } | 82 } |
82 | 83 |
83 // Verifies that BuildComponents() and GetRequiredFields() return an empty | 84 // Verifies that BuildComponents() and GetRequiredFields() return an empty |
84 // vector for an invalid region code. | 85 // vector for an invalid region code. |
85 TEST(AddressUiTest, InvalidRegionCodeReturnsEmptyVector) { | 86 TEST(AddressUiTest, InvalidRegionCodeReturnsEmptyVector) { |
86 EXPECT_TRUE(BuildComponents("INVALID-REGION-CODE").empty()); | 87 EXPECT_TRUE( |
| 88 BuildComponents("INVALID-REGION-CODE", std::string(), NULL).empty()); |
87 EXPECT_TRUE(GetRequiredFields("INVALID-REGION-CODE").empty()); | 89 EXPECT_TRUE(GetRequiredFields("INVALID-REGION-CODE").empty()); |
88 } | 90 } |
89 | 91 |
90 struct SeparatorData { | 92 struct SeparatorData { |
91 SeparatorData(const std::string& language_code, | 93 SeparatorData(const std::string& language_code, |
92 const std::string& compact_line_separator) | 94 const std::string& compact_line_separator) |
93 : language_code(language_code), | 95 : language_code(language_code), |
94 compact_line_separator(compact_line_separator) {} | 96 compact_line_separator(compact_line_separator) {} |
95 | 97 |
96 ~SeparatorData() {} | 98 ~SeparatorData() {} |
(...skipping 15 matching lines...) Expand all Loading... |
112 CompactLineSeparators, CompactLineSeparatorTest, | 114 CompactLineSeparators, CompactLineSeparatorTest, |
113 testing::Values( | 115 testing::Values( |
114 SeparatorData("ja", ""), | 116 SeparatorData("ja", ""), |
115 SeparatorData("zh", ""), | 117 SeparatorData("zh", ""), |
116 SeparatorData("zh-hans", ""), | 118 SeparatorData("zh-hans", ""), |
117 SeparatorData("ar", "، "), | 119 SeparatorData("ar", "، "), |
118 SeparatorData("ko", " "), | 120 SeparatorData("ko", " "), |
119 SeparatorData("th", " "), | 121 SeparatorData("th", " "), |
120 SeparatorData("en", ", "))); | 122 SeparatorData("en", ", "))); |
121 | 123 |
| 124 TEST(AddressUiTest, ComponentLanguageCodeTest) { |
| 125 static const struct LanguageCodeData { |
| 126 const char* region_code; |
| 127 const char* ui_language_code; |
| 128 const char* components_language_code; |
| 129 } kLangugeCodes[] = { |
| 130 {"AM", "", "hy"}, |
| 131 {"AM", "hy", "hy"}, |
| 132 {"AM", "en", "hy-latn"}, |
| 133 {"CN", "zh-hans", "zh-hans"}, |
| 134 {"CN", "zh-hant", "zh-hant"}, |
| 135 {"CN", "zh", "zh"}, |
| 136 {"CN", "zh-latn", "zh-latn"}, |
| 137 {"CN", "en", "zh-latn"}, |
| 138 {"CN", "ja", "zh-latn"}, |
| 139 {"CN", "ko", "zh-latn"}, |
| 140 {"HK", "zh", "zh"}, |
| 141 {"HK", "zh-hans", "zh-hans"}, |
| 142 {"HK", "zh-hant", "zh-hant"}, |
| 143 {"HK", "zh-latn", "zh-latn"}, |
| 144 {"HK", "en", "en"}, |
| 145 {"HK", "fr", "zh-latn"}, |
| 146 {"HK", "ja", "zh-latn"}, |
| 147 {"HK", "ko", "zh-latn"}, |
| 148 {"MO", "zh", "zh"}, |
| 149 {"MO", "pt", "pt"}, |
| 150 {"MO", "en", "zh-latn"}, |
| 151 {"AQ", "en", "en"}, |
| 152 {"AQ", "fr", "fr"}, |
| 153 {"AQ", "es", "es"}, |
| 154 {"AQ", "zh", "zh"} |
| 155 }; |
| 156 static const size_t kArraySize = |
| 157 sizeof kLangugeCodes / sizeof (LanguageCodeData); |
| 158 for (size_t i = 0; i < kArraySize; ++i) { |
| 159 SCOPED_TRACE(std::string("region code = ") + |
| 160 kLangugeCodes[i].region_code + ", ui language code = " + |
| 161 kLangugeCodes[i].ui_language_code + ", components language code = " + |
| 162 kLangugeCodes[i].components_language_code); |
| 163 std::string components_language_code; |
| 164 EXPECT_FALSE(BuildComponents(kLangugeCodes[i].region_code, |
| 165 kLangugeCodes[i].ui_language_code, |
| 166 &components_language_code).empty()); |
| 167 EXPECT_EQ( |
| 168 kLangugeCodes[i].components_language_code, components_language_code); |
| 169 } |
| 170 } |
122 | 171 |
123 } // namespace | 172 } // namespace |
124 | 173 |
125 } // namespace addressinput | 174 } // namespace addressinput |
126 } // namespace i18n | 175 } // namespace i18n |
OLD | NEW |