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 "fake_storage.h" |
| 16 |
| 17 #include <libaddressinput/callback.h> |
| 18 #include <libaddressinput/storage.h> |
| 19 #include <libaddressinput/util/scoped_ptr.h> |
| 20 |
| 21 #include <string> |
| 22 |
| 23 #include <gtest/gtest.h> |
| 24 |
| 25 namespace { |
| 26 |
| 27 using i18n::addressinput::BuildCallback; |
| 28 using i18n::addressinput::FakeStorage; |
| 29 using i18n::addressinput::scoped_ptr; |
| 30 using i18n::addressinput::Storage; |
| 31 |
| 32 // Tests for FakeStorage object. |
| 33 class FakeStorageTest : public testing::Test { |
| 34 protected: |
| 35 FakeStorageTest() : storage_(), success_(false), key_(), data_() {} |
| 36 virtual ~FakeStorageTest() {} |
| 37 |
| 38 Storage::Callback* BuildCallback() { |
| 39 return ::BuildCallback(this, &FakeStorageTest::OnDataReady); |
| 40 } |
| 41 |
| 42 FakeStorage storage_; |
| 43 bool success_; |
| 44 std::string key_; |
| 45 std::string data_; |
| 46 |
| 47 private: |
| 48 void OnDataReady(bool success, |
| 49 const std::string& key, |
| 50 const std::string& data) { |
| 51 success_ = success; |
| 52 key_ = key; |
| 53 data_ = data; |
| 54 } |
| 55 }; |
| 56 |
| 57 TEST_F(FakeStorageTest, GetWithoutPutReturnsEmptyData) { |
| 58 scoped_ptr<Storage::Callback> callback(BuildCallback()); |
| 59 storage_.Get("key", *callback); |
| 60 |
| 61 EXPECT_FALSE(success_); |
| 62 EXPECT_EQ("key", key_); |
| 63 EXPECT_TRUE(data_.empty()); |
| 64 } |
| 65 |
| 66 TEST_F(FakeStorageTest, GetReturnsWhatWasPut) { |
| 67 storage_.Put("key", "value"); |
| 68 |
| 69 scoped_ptr<Storage::Callback> callback(BuildCallback()); |
| 70 storage_.Get("key", *callback); |
| 71 |
| 72 EXPECT_TRUE(success_); |
| 73 EXPECT_EQ("key", key_); |
| 74 EXPECT_EQ("value", data_); |
| 75 } |
| 76 |
| 77 TEST_F(FakeStorageTest, SecondPutOverwritesData) { |
| 78 storage_.Put("key", "bad-value"); |
| 79 storage_.Put("key", "good-value"); |
| 80 |
| 81 scoped_ptr<Storage::Callback> callback(BuildCallback()); |
| 82 storage_.Get("key", *callback); |
| 83 |
| 84 EXPECT_TRUE(success_); |
| 85 EXPECT_EQ("key", key_); |
| 86 EXPECT_EQ("good-value", data_); |
| 87 } |
| 88 |
| 89 } // namespace |
OLD | NEW |