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

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

Issue 368243007: Reland of "Use address_data.h from upstream libaddressinput". (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update BUILD.gn, fix a test. Created 6 years, 5 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) 2014 Google Inc. 1 // Copyright (C) 2014 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 "fields", &fields_json)); 95 "fields", &fields_json));
96 96
97 AddressData address; 97 AddressData address;
98 for (int i = 1; i < 10; ++i) { 98 for (int i = 1; i < 10; ++i) {
99 std::string street_key = "street"; 99 std::string street_key = "street";
100 street_key.append(1, static_cast<char>('0' + i)); 100 street_key.append(1, static_cast<char>('0' + i));
101 std::string street_field; 101 std::string street_field;
102 if (!fields_json->GetStringValueForKey(street_key, &street_field)) 102 if (!fields_json->GetStringValueForKey(street_key, &street_field))
103 break; 103 break;
104 104
105 address.address_lines.push_back(street_field); 105 address.address_line.push_back(street_field);
106 } 106 }
107 address.country_code = country; 107 address.region_code = country;
108 fields_json->GetStringValueForKey("state", &address.administrative_area); 108 fields_json->GetStringValueForKey("state", &address.administrative_area);
109 fields_json->GetStringValueForKey("city", &address.locality); 109 fields_json->GetStringValueForKey("city", &address.locality);
110 fields_json->GetStringValueForKey("locality", &address.dependent_locality); 110 fields_json->GetStringValueForKey("locality", &address.dependent_locality);
111 fields_json->GetStringValueForKey("sorting_code", &address.sorting_code); 111 fields_json->GetStringValueForKey("sorting_code", &address.sorting_code);
112 fields_json->GetStringValueForKey("zip", &address.postal_code); 112 fields_json->GetStringValueForKey("zip", &address.postal_code);
113 fields_json->GetStringValueForKey("name", &address.recipient); 113 fields_json->GetStringValueForKey("name", &address.recipient);
114 114
115 AddressProblems problems; 115 AddressProblems problems;
116 EXPECT_EQ(AddressValidator::SUCCESS, validator_->ValidateAddress( 116 EXPECT_EQ(AddressValidator::SUCCESS, validator_->ValidateAddress(
117 address, AddressProblemFilter(), &problems)); 117 address, AddressProblemFilter(), &problems));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 scoped_ptr<Json>* newjson) { 174 scoped_ptr<Json>* newjson) {
175 DownloadJson(key, json); 175 DownloadJson(key, json);
176 ASSERT_TRUE((*json)->GetJsonValueForKey(key, newjson)); 176 ASSERT_TRUE((*json)->GetJsonValueForKey(key, newjson));
177 } 177 }
178 178
179 private: 179 private:
180 // LoadRulesDelegate implementation. 180 // LoadRulesDelegate implementation.
181 virtual void OnAddressValidationRulesLoaded(const std::string& country_code, 181 virtual void OnAddressValidationRulesLoaded(const std::string& country_code,
182 bool success) { 182 bool success) {
183 AddressData address_data; 183 AddressData address_data;
184 address_data.country_code = country_code; 184 address_data.region_code = country_code;
185 AddressValidator::Status status = 185 AddressValidator::Status status =
186 validator_->ValidateAddress(address_data, AddressProblemFilter(), NULL); 186 validator_->ValidateAddress(address_data, AddressProblemFilter(), NULL);
187 EXPECT_TRUE(success); 187 EXPECT_TRUE(success);
188 EXPECT_EQ(AddressValidator::SUCCESS, status); 188 EXPECT_EQ(AddressValidator::SUCCESS, status);
189 } 189 }
190 }; 190 };
191 191
192 TEST_F(ExampleAddressValidatorTest, examples) { 192 TEST_F(ExampleAddressValidatorTest, examples) {
193 scoped_ptr<Json> json(Json::Build()); 193 scoped_ptr<Json> json(Json::Build());
194 scoped_ptr<Json> json_examples; 194 scoped_ptr<Json> json_examples;
195 DownloadJsonValueForKey("examples", &json, &json_examples); 195 DownloadJsonValueForKey("examples", &json, &json_examples);
196 196
197 std::string countries_str; 197 std::string countries_str;
198 ASSERT_TRUE(json_examples->GetStringValueForKey("countries", &countries_str)); 198 ASSERT_TRUE(json_examples->GetStringValueForKey("countries", &countries_str));
199 std::vector<std::string> countries; 199 std::vector<std::string> countries;
200 SplitString(countries_str, '~', &countries); 200 SplitString(countries_str, '~', &countries);
201 201
202 for (std::vector<std::string>::const_iterator it = countries.begin(); 202 for (std::vector<std::string>::const_iterator it = countries.begin();
203 it != countries.end(); ++it) { 203 it != countries.end(); ++it) {
204 TestCountry(*it); 204 TestCountry(*it);
205 } 205 }
206 } 206 }
207 207
208 } // addressinput 208 } // addressinput
209 } // i18n 209 } // i18n
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698