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