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

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

Issue 110533002: [rac] Temporarily copy libaddressinput to Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Avoid redefinition of basictypes.h Created 7 years 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
(Empty)
1 // Copyright (C) 2013 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <libaddressinput/address_ui.h>
16
17 #include <libaddressinput/address_field.h>
18 #include <libaddressinput/address_ui_component.h>
19 #include <libaddressinput/localization.h>
20
21 #include <string>
22 #include <vector>
23
24 #include <gtest/gtest.h>
25
26 namespace {
27
28 using i18n::addressinput::AddressField;
29 using i18n::addressinput::AddressUiComponent;
30 using i18n::addressinput::BuildComponents;
31 using i18n::addressinput::COUNTRY;
32 using i18n::addressinput::GetRegionCodes;
33 using i18n::addressinput::Localization;
34 using i18n::addressinput::RECIPIENT;
35
36 // Returns testing::AssertionSuccess if the |components| are valid. Uses
37 // |region_code| in test failure messages.
38 testing::AssertionResult ComponentsAreValid(
39 const std::vector<AddressUiComponent>& components) {
40 if (components.empty()) {
41 return testing::AssertionFailure() << "no components";
42 }
43
44 for (std::vector<AddressUiComponent>::const_iterator
45 component_it = components.begin();
46 component_it != components.end(); ++component_it) {
47 static const AddressField kMinAddressField = COUNTRY;
48 static const AddressField kMaxAddressField = RECIPIENT;
49 if (component_it->field < kMinAddressField ||
50 component_it->field > kMaxAddressField) {
51 return testing::AssertionFailure() << "unexpected field "
52 << component_it->field;
53 }
54
55 if (component_it->name.empty()) {
56 return testing::AssertionFailure() << "empty field name for field "
57 << component_it->field;
58 }
59 }
60
61 return testing::AssertionSuccess();
62 }
63
64 // Tests for address UI functions.
65 class AddressUiTest : public testing::TestWithParam<std::string> {
66 protected:
67 Localization localization_;
68 };
69
70 // Verifies that a region code consists of two characters, for example "TW".
71 TEST_P(AddressUiTest, RegionCodeHasTwoCharacters) {
72 EXPECT_EQ(2, GetParam().size());
73 }
74
75 // Verifies that BuildComponents() returns valid UI components for a region
76 // code.
77 TEST_P(AddressUiTest, ComponentsAreValid) {
78 EXPECT_TRUE(ComponentsAreValid(BuildComponents(GetParam(), localization_)));
79 }
80
81 // Test all regions codes.
82 INSTANTIATE_TEST_CASE_P(
83 AllRegions, AddressUiTest,
84 testing::ValuesIn(GetRegionCodes()));
85
86 // Verifies that BuildComponents() returns an empty vector for an invalid region
87 // code.
88 TEST_F(AddressUiTest, InvalidRegionCodeReturnsEmptyVector) {
89 EXPECT_TRUE(BuildComponents("INVALID-REGION-CODE", localization_).empty());
90 }
91
92 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698