1 // Copyright (C) 2013 Google Inc.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include "region_data_constants.h"
17 #include <libaddressinput/util/basictypes.h>
21 #include <gtest/gtest.h>
25 using i18n::addressinput::RegionDataConstants;
27 // Tests for region codes, for example "ZA".
28 class RegionCodeTest : public testing::TestWithParam<std::string> {
33 DISALLOW_COPY_AND_ASSIGN(RegionCodeTest);
36 // Verifies that a region code consists of two characters, for example "ZA".
37 TEST_P(RegionCodeTest, RegionCodeHasTwoCharacters) {
38 EXPECT_EQ(2, GetParam().length());
41 // Test all region codes.
42 INSTANTIATE_TEST_CASE_P(
43 AllRegionCodes, RegionCodeTest,
44 testing::ValuesIn(RegionDataConstants::GetRegionCodes()));
46 // Returns AssertionSuccess if |data| begins with '{' and ends with '}'.
47 testing::AssertionResult HasCurlyBraces(const std::string& data) {
49 return testing::AssertionFailure() << "data is empty";
52 return testing::AssertionFailure() << data << " does not start with '{'";
54 if (data[data.length() - 1] != '}') {
55 return testing::AssertionFailure() << data << " does not end with '}'";
57 return testing::AssertionSuccess();
60 // Verifies that the default region data begins with '{' and ends with '}'.
61 TEST(DefaultRegionDataTest, DefaultRegionHasCurlyBraces) {
62 EXPECT_TRUE(HasCurlyBraces(RegionDataConstants::GetDefaultRegionData()));
65 // Tests for region data, for example "{\"fmt\":\"%C%S\"}".
66 class RegionDataTest : public testing::TestWithParam<std::string> {
70 const std::string& GetData() const {
71 return RegionDataConstants::GetRegionData(GetParam());
75 DISALLOW_COPY_AND_ASSIGN(RegionDataTest);
78 // Verifies that a region data value begins with '{' and end with '}', for
79 // example "{\"fmt\":\"%C%S\"}".
80 TEST_P(RegionDataTest, RegionDataHasCurlyBraces) {
81 EXPECT_TRUE(HasCurlyBraces(GetData()));
84 // Test all region data.
85 INSTANTIATE_TEST_CASE_P(
86 AllRegionData, RegionDataTest,
87 testing::ValuesIn(RegionDataConstants::GetRegionCodes()));
89 TEST(RegionDataConstantsTest, GetMaxLookupKeyDepth) {
90 EXPECT_EQ(0, RegionDataConstants::GetMaxLookupKeyDepth("NZ"));
91 EXPECT_EQ(1, RegionDataConstants::GetMaxLookupKeyDepth("KY"));
92 EXPECT_EQ(2, RegionDataConstants::GetMaxLookupKeyDepth("US"));
93 EXPECT_EQ(3, RegionDataConstants::GetMaxLookupKeyDepth("CN"));