| OLD | NEW |
| 1 // Copyright (C) 2013 Google Inc. | 1 // Copyright (C) 2013 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, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "fake_storage.h" | 15 #include "fake_storage.h" |
| 16 | 16 |
| 17 #include <libaddressinput/callback.h> | |
| 18 #include <libaddressinput/storage.h> | |
| 19 #include <libaddressinput/util/scoped_ptr.h> | |
| 20 | |
| 21 #include <string> | 17 #include <string> |
| 22 | 18 |
| 23 #include <gtest/gtest.h> | 19 #include <gtest/gtest.h> |
| 24 | 20 |
| 21 #include "storage_test_runner.h" |
| 22 |
| 25 namespace i18n { | 23 namespace i18n { |
| 26 namespace addressinput { | 24 namespace addressinput { |
| 27 | 25 |
| 28 namespace { | 26 namespace { |
| 29 | 27 |
| 30 // Tests for FakeStorage object. | 28 // Tests for FakeStorage object. |
| 31 class FakeStorageTest : public testing::Test { | 29 class FakeStorageTest : public testing::Test { |
| 32 protected: | 30 protected: |
| 33 FakeStorageTest() : storage_(), success_(false), key_(), data_() {} | 31 FakeStorageTest() : storage_(), runner_(&storage_) {} |
| 34 virtual ~FakeStorageTest() {} | 32 virtual ~FakeStorageTest() {} |
| 35 | 33 |
| 36 scoped_ptr<Storage::Callback> BuildCallback() { | |
| 37 return ::i18n::addressinput::BuildCallback( | |
| 38 this, &FakeStorageTest::OnDataReady); | |
| 39 } | |
| 40 | |
| 41 FakeStorage storage_; | 34 FakeStorage storage_; |
| 42 bool success_; | 35 StorageTestRunner runner_; |
| 43 std::string key_; | |
| 44 std::string data_; | |
| 45 | |
| 46 private: | |
| 47 void OnDataReady(bool success, | |
| 48 const std::string& key, | |
| 49 const std::string& data) { | |
| 50 success_ = success; | |
| 51 key_ = key; | |
| 52 data_ = data; | |
| 53 } | |
| 54 }; | 36 }; |
| 55 | 37 |
| 56 TEST_F(FakeStorageTest, GetWithoutPutReturnsEmptyData) { | 38 TEST_F(FakeStorageTest, StandardStorageTests) { |
| 57 storage_.Get("key", BuildCallback()); | 39 EXPECT_NO_FATAL_FAILURE(runner_.RunAllTests()); |
| 58 | |
| 59 EXPECT_FALSE(success_); | |
| 60 EXPECT_EQ("key", key_); | |
| 61 EXPECT_TRUE(data_.empty()); | |
| 62 } | |
| 63 | |
| 64 TEST_F(FakeStorageTest, GetReturnsWhatWasPut) { | |
| 65 storage_.Put("key", "value"); | |
| 66 storage_.Get("key", BuildCallback()); | |
| 67 | |
| 68 EXPECT_TRUE(success_); | |
| 69 EXPECT_EQ("key", key_); | |
| 70 EXPECT_EQ("value", data_); | |
| 71 } | |
| 72 | |
| 73 TEST_F(FakeStorageTest, SecondPutOverwritesData) { | |
| 74 storage_.Put("key", "bad-value"); | |
| 75 storage_.Put("key", "good-value"); | |
| 76 storage_.Get("key", BuildCallback()); | |
| 77 | |
| 78 EXPECT_TRUE(success_); | |
| 79 EXPECT_EQ("key", key_); | |
| 80 EXPECT_EQ("good-value", data_); | |
| 81 } | 40 } |
| 82 | 41 |
| 83 } // namespace | 42 } // namespace |
| 84 | 43 |
| 85 } // namespace addressinput | 44 } // namespace addressinput |
| 86 } // namespace i18n | 45 } // namespace i18n |
| OLD | NEW |