1 // Copyright (C) 2013 Google Inc.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include "storage_test_runner.h"
17 #include <libaddressinput/callback.h>
19 #include <gtest/gtest.h>
22 namespace addressinput {
24 StorageTestRunner::StorageTestRunner(Storage* storage)
30 void StorageTestRunner::RunAllTests() {
31 EXPECT_NO_FATAL_FAILURE(GetWithoutPutReturnsEmptyData());
32 EXPECT_NO_FATAL_FAILURE(GetReturnsWhatWasPut());
33 EXPECT_NO_FATAL_FAILURE(SecondPutOverwritesData());
36 void StorageTestRunner::ClearValues() {
42 scoped_ptr<Storage::Callback> StorageTestRunner::BuildCallback() {
43 return ::i18n::addressinput::BuildCallback(
44 this, &StorageTestRunner::OnDataReady);
47 void StorageTestRunner::OnDataReady(bool success,
48 const std::string& key,
49 const std::string& data) {
55 void StorageTestRunner::GetWithoutPutReturnsEmptyData() {
57 storage_->Get("key", BuildCallback());
59 EXPECT_FALSE(success_);
60 EXPECT_EQ("key", key_);
61 EXPECT_TRUE(data_.empty());
64 void StorageTestRunner::GetReturnsWhatWasPut() {
66 storage_->Put("key", make_scoped_ptr(new std::string("value")));
67 storage_->Get("key", BuildCallback());
69 EXPECT_TRUE(success_);
70 EXPECT_EQ("key", key_);
71 EXPECT_EQ("value", data_);
74 void StorageTestRunner::SecondPutOverwritesData() {
76 storage_->Put("key", make_scoped_ptr(new std::string("bad-value")));
77 storage_->Put("key", make_scoped_ptr(new std::string("good-value")));
78 storage_->Get("key", BuildCallback());
80 EXPECT_TRUE(success_);
81 EXPECT_EQ("key", key_);
82 EXPECT_EQ("good-value", data_);