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"
19 #include <gtest/gtest.h>
23 using i18n::addressinput::RegionDataConstants;
25 // Tests for region codes, for example "ZA".
26 class RegionCodeTest : public testing::TestWithParam<std::string> {};
28 // Verifies that a region code consists of two characters, for example "ZA".
29 TEST_P(RegionCodeTest, RegionCodeHasTwoCharacters) {
30 EXPECT_EQ(2, GetParam().length());
33 // Test all region codes.
34 INSTANTIATE_TEST_CASE_P(
35 AllRegionCodes, RegionCodeTest,
36 testing::ValuesIn(RegionDataConstants::GetRegionCodes()));
38 // Returns AssertionSuccess if |data| begins with '{' and ends with '}'.
39 testing::AssertionResult HasCurlyBraces(const std::string& data) {
41 return testing::AssertionFailure() << "data is empty";
44 return testing::AssertionFailure() << data << " does not start with '{'";
46 if (data[data.length() - 1] != '}') {
47 return testing::AssertionFailure() << data << " does not end with '}'";
49 return testing::AssertionSuccess();
52 // Verifies that the default region data begins with '{' and ends with '}'.
53 TEST(DefaultRegionDataTest, DefaultRegionHasCurlyBraces) {
54 EXPECT_TRUE(HasCurlyBraces(RegionDataConstants::GetDefaultRegionData()));
57 // Tests for region data, for example "{\"fmt\":\"%C%S\"}".
58 class RegionDataTest : public testing::TestWithParam<std::string> {
60 const std::string& GetData() const {
61 return RegionDataConstants::GetRegionData(GetParam());
65 // Verifies that a region data value begins with '{' and end with '}', for
66 // example "{\"fmt\":\"%C%S\"}".
67 TEST_P(RegionDataTest, RegionDataHasCurlyBraces) {
68 EXPECT_TRUE(HasCurlyBraces(GetData()));
71 // Test all region data.
72 INSTANTIATE_TEST_CASE_P(
73 AllRegionData, RegionDataTest,
74 testing::ValuesIn(RegionDataConstants::GetRegionCodes()));
76 TEST(RegionDataConstantsTest, GetMaxLookupKeyDepth) {
77 EXPECT_EQ(0, RegionDataConstants::GetMaxLookupKeyDepth("NZ"));
78 EXPECT_EQ(1, RegionDataConstants::GetMaxLookupKeyDepth("HK"));
79 EXPECT_EQ(2, RegionDataConstants::GetMaxLookupKeyDepth("US"));
80 EXPECT_EQ(3, RegionDataConstants::GetMaxLookupKeyDepth("CN"));