| 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" |
| 18 | 8 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/callback.h
" |
| 19 #include <gtest/gtest.h> | |
| 20 | 9 |
| 21 namespace i18n { | 10 namespace i18n { |
| 22 namespace addressinput { | 11 namespace addressinput { |
| 23 | 12 |
| 24 StorageTestRunner::StorageTestRunner(Storage* storage) | 13 StorageTestRunner::StorageTestRunner(Storage* storage) |
| 25 : storage_(storage), | 14 : storage_(storage), |
| 26 success_(false), | 15 success_(false), |
| 27 key_(), | 16 key_(), |
| 28 data_() {} | 17 data_() {} |
| 29 | 18 |
| 30 void StorageTestRunner::RunAllTests() { | 19 void StorageTestRunner::RunAllTests() { |
| 31 EXPECT_NO_FATAL_FAILURE(GetWithoutPutReturnsEmptyData()); | 20 EXPECT_NO_FATAL_FAILURE(GetWithoutPutReturnsEmptyData()); |
| 32 EXPECT_NO_FATAL_FAILURE(GetReturnsWhatWasPut()); | 21 EXPECT_NO_FATAL_FAILURE(GetReturnsWhatWasPut()); |
| 33 EXPECT_NO_FATAL_FAILURE(SecondPutOverwritesData()); | 22 EXPECT_NO_FATAL_FAILURE(SecondPutOverwritesData()); |
| 34 } | 23 } |
| 35 | 24 |
| 36 void StorageTestRunner::ClearValues() { | 25 void StorageTestRunner::ClearValues() { |
| 37 success_ = false; | 26 success_ = false; |
| 38 key_.clear(); | 27 key_.clear(); |
| 39 data_.clear(); | 28 data_.clear(); |
| 40 } | 29 } |
| 41 | 30 |
| 42 scoped_ptr<Storage::Callback> StorageTestRunner::BuildCallback() { | 31 scoped_ptr<Storage::Callback> StorageTestRunner::BuildCallback() { |
| 43 return ::i18n::addressinput::BuildCallback( | 32 return scoped_ptr<Storage::Callback>(::i18n::addressinput::BuildCallback( |
| 44 this, &StorageTestRunner::OnDataReady); | 33 this, &StorageTestRunner::OnDataReady)); |
| 45 } | 34 } |
| 46 | 35 |
| 47 void StorageTestRunner::OnDataReady(bool success, | 36 void StorageTestRunner::OnDataReady(bool success, |
| 48 const std::string& key, | 37 const std::string& key, |
| 49 const std::string& data) { | 38 const std::string& data) { |
| 50 success_ = success; | 39 success_ = success; |
| 51 key_ = key; | 40 key_ = key; |
| 52 data_ = data; | 41 data_ = data; |
| 53 } | 42 } |
| 54 | 43 |
| 55 void StorageTestRunner::GetWithoutPutReturnsEmptyData() { | 44 void StorageTestRunner::GetWithoutPutReturnsEmptyData() { |
| 56 ClearValues(); | 45 ClearValues(); |
| 57 storage_->Get("key", BuildCallback()); | 46 scoped_ptr<Storage::Callback> callback(BuildCallback()); |
| 47 storage_->Get("key", *callback); |
| 58 | 48 |
| 59 EXPECT_FALSE(success_); | 49 EXPECT_FALSE(success_); |
| 60 EXPECT_EQ("key", key_); | 50 EXPECT_EQ("key", key_); |
| 61 EXPECT_TRUE(data_.empty()); | 51 EXPECT_TRUE(data_.empty()); |
| 62 } | 52 } |
| 63 | 53 |
| 64 void StorageTestRunner::GetReturnsWhatWasPut() { | 54 void StorageTestRunner::GetReturnsWhatWasPut() { |
| 65 ClearValues(); | 55 ClearValues(); |
| 66 storage_->Put("key", make_scoped_ptr(new std::string("value"))); | 56 storage_->Put("key", "value"); |
| 67 storage_->Get("key", BuildCallback()); | 57 scoped_ptr<Storage::Callback> callback(BuildCallback()); |
| 58 storage_->Get("key", *callback); |
| 68 | 59 |
| 69 EXPECT_TRUE(success_); | 60 EXPECT_TRUE(success_); |
| 70 EXPECT_EQ("key", key_); | 61 EXPECT_EQ("key", key_); |
| 71 EXPECT_EQ("value", data_); | 62 EXPECT_EQ("value", data_); |
| 72 } | 63 } |
| 73 | 64 |
| 74 void StorageTestRunner::SecondPutOverwritesData() { | 65 void StorageTestRunner::SecondPutOverwritesData() { |
| 75 ClearValues(); | 66 ClearValues(); |
| 76 storage_->Put("key", make_scoped_ptr(new std::string("bad-value"))); | 67 storage_->Put("key", "bad-value"); |
| 77 storage_->Put("key", make_scoped_ptr(new std::string("good-value"))); | 68 storage_->Put("key", "good-value"); |
| 78 storage_->Get("key", BuildCallback()); | 69 scoped_ptr<Storage::Callback> callback(BuildCallback()); |
| 70 storage_->Get("key", *callback); |
| 79 | 71 |
| 80 EXPECT_TRUE(success_); | 72 EXPECT_TRUE(success_); |
| 81 EXPECT_EQ("key", key_); | 73 EXPECT_EQ("key", key_); |
| 82 EXPECT_EQ("good-value", data_); | 74 EXPECT_EQ("good-value", data_); |
| 83 } | 75 } |
| 84 | 76 |
| 85 } // addressinput | 77 } // addressinput |
| 86 } // i18n | 78 } // i18n |
| OLD | NEW |