| OLD | NEW |
| 1 // Copyright (C) 2014 Google Inc. | 1 // Copyright (C) 2014 Google Inc. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "fake_downloader.h" | 27 #include "fake_downloader.h" |
| 28 #include "fake_storage.h" | 28 #include "fake_storage.h" |
| 29 | 29 |
| 30 namespace i18n { | 30 namespace i18n { |
| 31 namespace addressinput { | 31 namespace addressinput { |
| 32 | 32 |
| 33 class AddressValidatorTest : public testing::Test, public LoadRulesDelegate { | 33 class AddressValidatorTest : public testing::Test, public LoadRulesDelegate { |
| 34 public: | 34 public: |
| 35 AddressValidatorTest() | 35 AddressValidatorTest() |
| 36 : validator_(AddressValidator::Build( | 36 : validator_(AddressValidator::Build( |
| 37 scoped_ptr<Downloader>(new FakeDownloader), | 37 scoped_ptr<Downloader>(new FakeDownloader), &storage_, this)) {} |
| 38 scoped_ptr<Storage>(new FakeStorage), | |
| 39 this)) {} | |
| 40 | 38 |
| 41 virtual ~AddressValidatorTest() {} | 39 virtual ~AddressValidatorTest() {} |
| 42 | 40 |
| 43 protected: | 41 protected: |
| 44 scoped_ptr<AddressValidator> validator_; | 42 scoped_ptr<AddressValidator> validator_; |
| 45 | 43 |
| 46 private: | 44 private: |
| 47 // LoadRulesDelegate implementation. | 45 // LoadRulesDelegate implementation. |
| 48 virtual void OnAddressValidationRulesLoaded(const std::string& country_code, | 46 virtual void OnAddressValidationRulesLoaded(const std::string& country_code, |
| 49 bool success) { | 47 bool success) { |
| 48 EXPECT_TRUE(success); |
| 50 } | 49 } |
| 50 |
| 51 FakeStorage storage_; |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 TEST_F(AddressValidatorTest, EmptyAddressNoFatalFailure) { | 54 TEST_F(AddressValidatorTest, EmptyAddressNoFatalFailure) { |
| 54 validator_->LoadRules("US"); | 55 validator_->LoadRules("US"); |
| 56 |
| 55 AddressData address; | 57 AddressData address; |
| 56 address.country_code = "US"; | 58 address.country_code = "US"; |
| 59 |
| 57 AddressProblems problems; | 60 AddressProblems problems; |
| 58 EXPECT_EQ( | 61 EXPECT_EQ( |
| 59 AddressValidator::SUCCESS, | 62 AddressValidator::SUCCESS, |
| 60 validator_->ValidateAddress(address, AddressProblemFilter(), &problems)); | 63 validator_->ValidateAddress(address, AddressProblemFilter(), &problems)); |
| 61 } | 64 } |
| 62 | 65 |
| 66 TEST_F(AddressValidatorTest, USZipCode) { |
| 67 validator_->LoadRules("US"); |
| 68 |
| 69 AddressData address; |
| 70 address.address_lines.push_back("340 Main St."); |
| 71 address.locality = "Venice"; |
| 72 address.administrative_area = "CA"; |
| 73 address.postal_code = "12345"; |
| 74 address.country_code = "US"; |
| 75 |
| 76 AddressProblems problems; |
| 77 EXPECT_EQ( |
| 78 AddressValidator::SUCCESS, |
| 79 validator_->ValidateAddress(address, AddressProblemFilter(), &problems)); |
| 80 |
| 81 ASSERT_EQ(1U, problems.size()); |
| 82 EXPECT_EQ(problems[0].field, AddressField::POSTAL_CODE); |
| 83 EXPECT_EQ(problems[0].type, AddressProblem::MISMATCHING_VALUE); |
| 84 |
| 85 problems.clear(); |
| 86 |
| 87 address.postal_code = "90291"; |
| 88 EXPECT_EQ( |
| 89 AddressValidator::SUCCESS, |
| 90 validator_->ValidateAddress(address, AddressProblemFilter(), &problems)); |
| 91 EXPECT_EQ(0U, problems.size()); |
| 92 } |
| 93 |
| 63 } // namespace addressinput | 94 } // namespace addressinput |
| 64 } // namespace i18n | 95 } // namespace i18n |
| OLD | NEW |