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 "storage_test_runner.h" | |
16 | |
17 #include <libaddressinput/callback.h> | |
18 | |
19 #include <gtest/gtest.h> | |
20 | |
21 namespace i18n { | |
22 namespace addressinput { | |
23 | |
24 StorageTestRunner::StorageTestRunner(Storage* storage) | |
25 : storage_(storage), | |
26 success_(false), | |
27 key_(), | |
28 data_() {} | |
29 | |
30 void StorageTestRunner::RunAllTests() { | |
31 EXPECT_NO_FATAL_FAILURE(GetWithoutPutReturnsEmptyData()); | |
please use gerrit instead
2013/12/20 02:04:40
Also GetReturnsWhatWasPut() and SecondPutOverwrite
Evan Stade
2013/12/20 03:21:56
Done.
| |
32 } | |
33 | |
34 void StorageTestRunner::ClearValues() { | |
35 success_ = false; | |
36 key_.clear(); | |
37 data_.clear(); | |
38 } | |
39 | |
40 scoped_ptr<Storage::Callback> StorageTestRunner::BuildCallback() { | |
41 return ::i18n::addressinput::BuildCallback( | |
42 this, &StorageTestRunner::OnDataReady); | |
43 } | |
44 | |
45 void StorageTestRunner::OnDataReady(bool success, | |
46 const std::string& key, | |
47 const std::string& data) { | |
48 success_ = success; | |
49 key_ = key; | |
50 data_ = data; | |
51 } | |
52 | |
53 void StorageTestRunner::GetWithoutPutReturnsEmptyData() { | |
54 ClearValues(); | |
55 storage_->Get("key", BuildCallback()); | |
56 | |
57 EXPECT_FALSE(success_); | |
58 EXPECT_EQ("key", key_); | |
59 EXPECT_TRUE(data_.empty()); | |
60 } | |
61 | |
62 void StorageTestRunner::GetReturnsWhatWasPut() { | |
63 ClearValues(); | |
64 storage_->Put("key", "value"); | |
65 storage_->Get("key", BuildCallback()); | |
66 | |
67 EXPECT_TRUE(success_); | |
68 EXPECT_EQ("key", key_); | |
69 EXPECT_EQ("value", data_); | |
70 } | |
71 | |
72 void StorageTestRunner::SecondPutOverwritesData() { | |
73 ClearValues(); | |
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 } | |
82 | |
83 } // addressinput | |
84 } // i18n | |
OLD | NEW |