OLD | NEW |
1 // Copyright (C) 2013 Google Inc. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // found in the LICENSE file. |
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 | 4 |
15 #include "storage_test_runner.h" | 5 #include "third_party/libaddressinput/chromium/storage_test_runner.h" |
16 | 6 |
17 #include <libaddressinput/callback.h> | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/callback.h
" |
18 | 9 |
19 #include <gtest/gtest.h> | 10 namespace autofill { |
20 | 11 |
21 namespace i18n { | 12 using ::i18n::addressinput::Storage; |
22 namespace addressinput { | |
23 | 13 |
24 StorageTestRunner::StorageTestRunner(Storage* storage) | 14 StorageTestRunner::StorageTestRunner(Storage* storage) |
25 : storage_(storage), | 15 : storage_(storage), |
26 success_(false), | 16 success_(false), |
27 key_(), | 17 key_(), |
28 data_() {} | 18 data_() {} |
29 | 19 |
| 20 StorageTestRunner::~StorageTestRunner() {} |
| 21 |
30 void StorageTestRunner::RunAllTests() { | 22 void StorageTestRunner::RunAllTests() { |
31 EXPECT_NO_FATAL_FAILURE(GetWithoutPutReturnsEmptyData()); | 23 EXPECT_NO_FATAL_FAILURE(GetWithoutPutReturnsEmptyData()); |
32 EXPECT_NO_FATAL_FAILURE(GetReturnsWhatWasPut()); | 24 EXPECT_NO_FATAL_FAILURE(GetReturnsWhatWasPut()); |
33 EXPECT_NO_FATAL_FAILURE(SecondPutOverwritesData()); | 25 EXPECT_NO_FATAL_FAILURE(SecondPutOverwritesData()); |
34 } | 26 } |
35 | 27 |
36 void StorageTestRunner::ClearValues() { | 28 void StorageTestRunner::ClearValues() { |
37 success_ = false; | 29 success_ = false; |
38 key_.clear(); | 30 key_.clear(); |
39 data_.clear(); | 31 data_.clear(); |
40 } | 32 } |
41 | 33 |
42 scoped_ptr<Storage::Callback> StorageTestRunner::BuildCallback() { | 34 scoped_ptr<Storage::Callback> StorageTestRunner::BuildCallback() { |
43 return ::i18n::addressinput::BuildCallback( | 35 return scoped_ptr<Storage::Callback>(::i18n::addressinput::BuildCallback( |
44 this, &StorageTestRunner::OnDataReady); | 36 this, &StorageTestRunner::OnDataReady)); |
45 } | 37 } |
46 | 38 |
47 void StorageTestRunner::OnDataReady(bool success, | 39 void StorageTestRunner::OnDataReady(bool success, |
48 const std::string& key, | 40 const std::string& key, |
49 const std::string& data) { | 41 const std::string& data) { |
50 success_ = success; | 42 success_ = success; |
51 key_ = key; | 43 key_ = key; |
52 data_ = data; | 44 data_ = data; |
53 } | 45 } |
54 | 46 |
55 void StorageTestRunner::GetWithoutPutReturnsEmptyData() { | 47 void StorageTestRunner::GetWithoutPutReturnsEmptyData() { |
56 ClearValues(); | 48 ClearValues(); |
57 storage_->Get("key", BuildCallback()); | 49 scoped_ptr<Storage::Callback> callback(BuildCallback()); |
| 50 storage_->Get("key", *callback); |
58 | 51 |
59 EXPECT_FALSE(success_); | 52 EXPECT_FALSE(success_); |
60 EXPECT_EQ("key", key_); | 53 EXPECT_EQ("key", key_); |
61 EXPECT_TRUE(data_.empty()); | 54 EXPECT_TRUE(data_.empty()); |
62 } | 55 } |
63 | 56 |
64 void StorageTestRunner::GetReturnsWhatWasPut() { | 57 void StorageTestRunner::GetReturnsWhatWasPut() { |
65 ClearValues(); | 58 ClearValues(); |
66 storage_->Put("key", make_scoped_ptr(new std::string("value"))); | 59 storage_->Put("key", "value"); |
67 storage_->Get("key", BuildCallback()); | 60 scoped_ptr<Storage::Callback> callback(BuildCallback()); |
| 61 storage_->Get("key", *callback); |
68 | 62 |
69 EXPECT_TRUE(success_); | 63 EXPECT_TRUE(success_); |
70 EXPECT_EQ("key", key_); | 64 EXPECT_EQ("key", key_); |
71 EXPECT_EQ("value", data_); | 65 EXPECT_EQ("value", data_); |
72 } | 66 } |
73 | 67 |
74 void StorageTestRunner::SecondPutOverwritesData() { | 68 void StorageTestRunner::SecondPutOverwritesData() { |
75 ClearValues(); | 69 ClearValues(); |
76 storage_->Put("key", make_scoped_ptr(new std::string("bad-value"))); | 70 storage_->Put("key", "bad-value"); |
77 storage_->Put("key", make_scoped_ptr(new std::string("good-value"))); | 71 storage_->Put("key", "good-value"); |
78 storage_->Get("key", BuildCallback()); | 72 scoped_ptr<Storage::Callback> callback(BuildCallback()); |
| 73 storage_->Get("key", *callback); |
79 | 74 |
80 EXPECT_TRUE(success_); | 75 EXPECT_TRUE(success_); |
81 EXPECT_EQ("key", key_); | 76 EXPECT_EQ("key", key_); |
82 EXPECT_EQ("good-value", data_); | 77 EXPECT_EQ("good-value", data_); |
83 } | 78 } |
84 | 79 |
85 } // addressinput | 80 } // namespace autofill |
86 } // i18n | |
OLD | NEW |