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

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

Issue 134903003: libaddressinput string translations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include <libaddressinput/address_ui.h> 15 #include <libaddressinput/address_ui.h>
16 16
17 #include <libaddressinput/address_field.h> 17 #include <libaddressinput/address_field.h>
18 #include <libaddressinput/address_ui_component.h> 18 #include <libaddressinput/address_ui_component.h>
19 #include <libaddressinput/localization.h>
20 19
21 #include <string> 20 #include <string>
22 #include <vector> 21 #include <vector>
23 22
24 #include <gtest/gtest.h> 23 #include <gtest/gtest.h>
25 24
26 namespace { 25 namespace {
27 26
28 using i18n::addressinput::AddressField; 27 using i18n::addressinput::AddressField;
29 using i18n::addressinput::AddressUiComponent; 28 using i18n::addressinput::AddressUiComponent;
30 using i18n::addressinput::BuildComponents; 29 using i18n::addressinput::BuildComponents;
31 using i18n::addressinput::COUNTRY; 30 using i18n::addressinput::COUNTRY;
32 using i18n::addressinput::GetRegionCodes; 31 using i18n::addressinput::GetRegionCodes;
33 using i18n::addressinput::Localization;
34 using i18n::addressinput::RECIPIENT; 32 using i18n::addressinput::RECIPIENT;
35 33
36 // Returns testing::AssertionSuccess if the |components| are valid. Uses 34 // Returns testing::AssertionSuccess if the |components| are valid. Uses
37 // |region_code| in test failure messages. 35 // |region_code| in test failure messages.
38 testing::AssertionResult ComponentsAreValid( 36 testing::AssertionResult ComponentsAreValid(
39 const std::vector<AddressUiComponent>& components) { 37 const std::vector<AddressUiComponent>& components) {
40 if (components.empty()) { 38 if (components.empty()) {
41 return testing::AssertionFailure() << "no components"; 39 return testing::AssertionFailure() << "no components";
42 } 40 }
43 41
44 for (std::vector<AddressUiComponent>::const_iterator 42 for (std::vector<AddressUiComponent>::const_iterator
45 component_it = components.begin(); 43 component_it = components.begin();
46 component_it != components.end(); ++component_it) { 44 component_it != components.end(); ++component_it) {
47 static const AddressField kMinAddressField = COUNTRY; 45 static const AddressField kMinAddressField = COUNTRY;
48 static const AddressField kMaxAddressField = RECIPIENT; 46 static const AddressField kMaxAddressField = RECIPIENT;
49 if (component_it->field < kMinAddressField || 47 if (component_it->field < kMinAddressField ||
50 component_it->field > kMaxAddressField) { 48 component_it->field > kMaxAddressField) {
51 return testing::AssertionFailure() << "unexpected field " 49 return testing::AssertionFailure() << "unexpected field "
52 << component_it->field; 50 << component_it->field;
53 } 51 }
54 52
55 if (component_it->name.empty()) { 53 if (component_it->name_id == 0) {
please use gerrit instead 2014/01/13 18:50:13 Use INVALID_MESSAGE_ID instead of 0. It's defined
Evan Stade 2014/01/13 23:36:07 This is a concrete example of this CL not being re
56 return testing::AssertionFailure() << "empty field name for field " 54 return testing::AssertionFailure() << "invalid field name_id for field "
57 << component_it->field; 55 << component_it->field;
58 } 56 }
59 } 57 }
60 58
61 return testing::AssertionSuccess(); 59 return testing::AssertionSuccess();
62 } 60 }
63 61
64 // Tests for address UI functions. 62 // Tests for address UI functions.
65 class AddressUiTest : public testing::TestWithParam<std::string> { 63 class AddressUiTest : public testing::TestWithParam<std::string> {};
66 protected:
67 Localization localization_;
68 };
69 64
70 // Verifies that a region code consists of two characters, for example "TW". 65 // Verifies that a region code consists of two characters, for example "TW".
71 TEST_P(AddressUiTest, RegionCodeHasTwoCharacters) { 66 TEST_P(AddressUiTest, RegionCodeHasTwoCharacters) {
72 EXPECT_EQ(2, GetParam().size()); 67 EXPECT_EQ(2, GetParam().size());
73 } 68 }
74 69
75 // Verifies that BuildComponents() returns valid UI components for a region 70 // Verifies that BuildComponents() returns valid UI components for a region
76 // code. 71 // code.
77 TEST_P(AddressUiTest, ComponentsAreValid) { 72 TEST_P(AddressUiTest, ComponentsAreValid) {
78 EXPECT_TRUE(ComponentsAreValid(BuildComponents(GetParam(), localization_))); 73 EXPECT_TRUE(ComponentsAreValid(BuildComponents(GetParam())));
79 } 74 }
80 75
81 // Test all regions codes. 76 // Test all regions codes.
82 INSTANTIATE_TEST_CASE_P( 77 INSTANTIATE_TEST_CASE_P(
83 AllRegions, AddressUiTest, 78 AllRegions, AddressUiTest,
84 testing::ValuesIn(GetRegionCodes())); 79 testing::ValuesIn(GetRegionCodes()));
85 80
86 // Verifies that BuildComponents() returns an empty vector for an invalid region 81 // Verifies that BuildComponents() returns an empty vector for an invalid region
87 // code. 82 // code.
88 TEST_F(AddressUiTest, InvalidRegionCodeReturnsEmptyVector) { 83 TEST_F(AddressUiTest, InvalidRegionCodeReturnsEmptyVector) {
89 EXPECT_TRUE(BuildComponents("INVALID-REGION-CODE", localization_).empty()); 84 EXPECT_TRUE(BuildComponents("INVALID-REGION-CODE").empty());
90 } 85 }
91 86
92 } // namespace 87 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698