Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / libaddressinput / src / cpp / test / region_data_constants_test.cc
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 "region_data_constants.h"
16
17 #include <string>
18
19 #include <gtest/gtest.h>
20
21 namespace {
22
23 using i18n::addressinput::RegionDataConstants;
24
25 // Tests for region codes, for example "ZA".
26 class RegionCodeTest : public testing::TestWithParam<std::string> {};
27
28 // Verifies that a region code consists of two characters, for example "ZA".
29 TEST_P(RegionCodeTest, RegionCodeHasTwoCharacters) {
30   EXPECT_EQ(2, GetParam().length());
31 }
32
33 // Test all region codes.
34 INSTANTIATE_TEST_CASE_P(
35     AllRegionCodes, RegionCodeTest,
36     testing::ValuesIn(RegionDataConstants::GetRegionCodes()));
37
38 // Returns AssertionSuccess if |data| begins with '{' and ends with '}'.
39 testing::AssertionResult HasCurlyBraces(const std::string& data) {
40   if (data.empty()) {
41     return testing::AssertionFailure() << "data is empty";
42   }
43   if (data[0] != '{') {
44     return testing::AssertionFailure() << data << " does not start with '{'";
45   }
46   if (data[data.length() - 1] != '}') {
47     return testing::AssertionFailure() << data << " does not end with '}'";
48   }
49   return testing::AssertionSuccess();
50 }
51
52 // Verifies that the default region data begins with '{' and ends with '}'.
53 TEST(DefaultRegionDataTest, DefaultRegionHasCurlyBraces) {
54   EXPECT_TRUE(HasCurlyBraces(RegionDataConstants::GetDefaultRegionData()));
55 }
56
57 // Tests for region data, for example "{\"fmt\":\"%C%S\"}".
58 class RegionDataTest : public testing::TestWithParam<std::string> {
59  protected:
60   const std::string& GetData() const {
61     return RegionDataConstants::GetRegionData(GetParam());
62   }
63 };
64
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()));
69 }
70
71 // Test all region data.
72 INSTANTIATE_TEST_CASE_P(
73     AllRegionData, RegionDataTest,
74     testing::ValuesIn(RegionDataConstants::GetRegionCodes()));
75
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"));
81 }
82
83 }  // namespace