Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: third_party/libaddressinput/chromium/cpp/test/validating_storage_test.cc

Issue 110533002: [rac] Temporarily copy libaddressinput to Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "validating_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 #include "fake_storage.h"
26
27 namespace {
28
29 using i18n::addressinput::BuildCallback;
30 using i18n::addressinput::FakeStorage;
31 using i18n::addressinput::scoped_ptr;
32 using i18n::addressinput::Storage;
33 using i18n::addressinput::ValidatingStorage;
34
35 // Tests for ValidatingStorage object.
36 class ValidatingStorageTest : public testing::Test {
37 protected:
38 ValidatingStorageTest()
39 : wrapped_storage_(new FakeStorage),
40 storage_(wrapped_storage_),
41 success_(false),
42 key_(),
43 data_() {}
44
45 virtual ~ValidatingStorageTest() {}
46
47 Storage::Callback* BuildCallback() {
48 return ::BuildCallback(this, &ValidatingStorageTest::OnDataReady);
49 }
50
51 FakeStorage* const wrapped_storage_; // Owned by |storage_|.
52 ValidatingStorage storage_;
53 bool success_;
54 std::string key_;
55 std::string data_;
56
57 private:
58 void OnDataReady(bool success,
59 const std::string& key,
60 const std::string& data) {
61 success_ = success;
62 key_ = key;
63 data_ = data;
64 }
65 };
66
67 TEST_F(ValidatingStorageTest, Basic) {
68 storage_.Put("key", "value");
69
70 scoped_ptr<Storage::Callback> callback(BuildCallback());
71 storage_.Get("key", *callback);
72
73 EXPECT_TRUE(success_);
74 EXPECT_EQ("key", key_);
75 EXPECT_EQ("value", data_);
76 }
77
78 TEST_F(ValidatingStorageTest, EmptyData) {
79 storage_.Put("key", std::string());
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_TRUE(data_.empty());
87 }
88
89 TEST_F(ValidatingStorageTest, MissingKey) {
90 scoped_ptr<Storage::Callback> callback(BuildCallback());
91 storage_.Get("key", *callback);
92
93 EXPECT_FALSE(success_);
94 EXPECT_EQ("key", key_);
95 EXPECT_TRUE(data_.empty());
96 }
97
98 TEST_F(ValidatingStorageTest, GarbageData) {
99 storage_.Put("key", "value");
100 wrapped_storage_->Put("key", "garbage");
101
102 scoped_ptr<Storage::Callback> callback(BuildCallback());
103 storage_.Get("key", *callback);
104
105 EXPECT_FALSE(success_);
106 EXPECT_EQ("key", key_);
107 EXPECT_TRUE(data_.empty());
108 }
109
110 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698