Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: third_party/libaddressinput/chromium/cpp/test/address_ui_test.cc

Issue 208243005: Determine language code and type of format for address. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 struct LanguageCodeData {
125 LanguageCodeData(const std::string& region_code,
126 const std::string& ui_language_code,
127 const std::string& components_language_code)
128 : region_code(region_code),
129 ui_language_code(ui_language_code),
130 components_language_code(components_language_code) {}
131
132 ~LanguageCodeData() {}
133
134 std::string region_code;
135 std::string ui_language_code;
136 std::string components_language_code;
137 };
138
139 std::ostream& operator<<(std::ostream& out, const LanguageCodeData& data) {
140 out << "(" << data.region_code << ", " << data.ui_language_code << ", "
141 << data.components_language_code << ")";
142 return out;
143 }
144
145 // Tests for component language code.
146 class ComponentLanguageCodeTest
147 : public testing::TestWithParam<LanguageCodeData> {};
148
149 TEST_P(ComponentLanguageCodeTest, BasicTest) {
150 std::string components_language_code;
151 EXPECT_FALSE(BuildComponents(GetParam().region_code,
152 GetParam().ui_language_code,
153 &components_language_code).empty());
154 EXPECT_EQ(GetParam().components_language_code, components_language_code);
155 }
156
157 INSTANTIATE_TEST_CASE_P(
Evan Stade 2014/03/21 23:44:54 you know I disdain test_case_p
please use gerrit instead 2014/03/22 01:34:30 Replaced with an array of structs.
158 ComponentLanguageCodes, ComponentLanguageCodeTest,
159 testing::Values(
160 LanguageCodeData("AM", "hy", "hy"),
161 LanguageCodeData("AM", "en", "hy-latn"),
162 LanguageCodeData("CN", "zh-hans", "zh-hans"),
163 LanguageCodeData("CN", "zh-hant", "zh-hant"),
164 LanguageCodeData("CN", "zh", "zh"),
165 LanguageCodeData("CN", "zh-latn", "zh-latn"),
166 LanguageCodeData("CN", "en", "zh-latn"),
167 LanguageCodeData("CN", "ja", "zh-latn"),
168 LanguageCodeData("CN", "ko", "zh-latn"),
169 LanguageCodeData("HK", "zh", "zh"),
170 LanguageCodeData("HK", "zh-hans", "zh-hans"),
171 LanguageCodeData("HK", "zh-hant", "zh-hant"),
172 LanguageCodeData("HK", "zh-latn", "zh-latn"),
173 LanguageCodeData("HK", "en", "en"),
174 LanguageCodeData("HK", "fr", "zh-latn"),
175 LanguageCodeData("HK", "ja", "zh-latn"),
176 LanguageCodeData("HK", "ko", "zh-latn"),
177 LanguageCodeData("MO", "zh", "zh"),
178 LanguageCodeData("MO", "pt", "pt"),
179 LanguageCodeData("MO", "en", "zh-latn"),
180 LanguageCodeData("AQ", "en", "en"),
181 LanguageCodeData("AQ", "fr", "fr"),
182 LanguageCodeData("AQ", "es", "es"),
183 LanguageCodeData("AQ", "zh", "zh")));
122 184
123 } // namespace 185 } // namespace
124 186
125 } // namespace addressinput 187 } // namespace addressinput
126 } // namespace i18n 188 } // namespace i18n
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698