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( | 78 EXPECT_TRUE(ComponentsAreValid(BuildComponents(region_codes[i]))); |
79 BuildComponents(region_codes[i], std::string(), NULL))); | |
80 EXPECT_FALSE(GetRequiredFields(region_codes[i]).empty()); | 79 EXPECT_FALSE(GetRequiredFields(region_codes[i]).empty()); |
81 } | 80 } |
82 } | 81 } |
83 | 82 |
84 // Verifies that BuildComponents() and GetRequiredFields() return an empty | 83 // Verifies that BuildComponents() and GetRequiredFields() return an empty |
85 // vector for an invalid region code. | 84 // vector for an invalid region code. |
86 TEST(AddressUiTest, InvalidRegionCodeReturnsEmptyVector) { | 85 TEST(AddressUiTest, InvalidRegionCodeReturnsEmptyVector) { |
87 EXPECT_TRUE( | 86 EXPECT_TRUE(BuildComponents("INVALID-REGION-CODE").empty()); |
88 BuildComponents("INVALID-REGION-CODE", std::string(), NULL).empty()); | |
89 EXPECT_TRUE(GetRequiredFields("INVALID-REGION-CODE").empty()); | 87 EXPECT_TRUE(GetRequiredFields("INVALID-REGION-CODE").empty()); |
90 } | 88 } |
91 | 89 |
92 struct SeparatorData { | 90 struct SeparatorData { |
93 SeparatorData(const std::string& language_code, | 91 SeparatorData(const std::string& language_code, |
94 const std::string& compact_line_separator) | 92 const std::string& compact_line_separator) |
95 : language_code(language_code), | 93 : language_code(language_code), |
96 compact_line_separator(compact_line_separator) {} | 94 compact_line_separator(compact_line_separator) {} |
97 | 95 |
98 ~SeparatorData() {} | 96 ~SeparatorData() {} |
(...skipping 15 matching lines...) Expand all Loading... |
114 CompactLineSeparators, CompactLineSeparatorTest, | 112 CompactLineSeparators, CompactLineSeparatorTest, |
115 testing::Values( | 113 testing::Values( |
116 SeparatorData("ja", ""), | 114 SeparatorData("ja", ""), |
117 SeparatorData("zh", ""), | 115 SeparatorData("zh", ""), |
118 SeparatorData("zh-hans", ""), | 116 SeparatorData("zh-hans", ""), |
119 SeparatorData("ar", "، "), | 117 SeparatorData("ar", "، "), |
120 SeparatorData("ko", " "), | 118 SeparatorData("ko", " "), |
121 SeparatorData("th", " "), | 119 SeparatorData("th", " "), |
122 SeparatorData("en", ", "))); | 120 SeparatorData("en", ", "))); |
123 | 121 |
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 } | |
171 | 122 |
172 } // namespace | 123 } // namespace |
173 | 124 |
174 } // namespace addressinput | 125 } // namespace addressinput |
175 } // namespace i18n | 126 } // namespace i18n |
OLD | NEW |