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

Unified Diff: third_party/libaddressinput/chromium/storage_test_runner.cc

Issue 298863012: Use upstream libaddressinput in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows compile. Created 6 years, 5 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/libaddressinput/chromium/storage_test_runner.cc
diff --git a/third_party/libaddressinput/chromium/storage_test_runner.cc b/third_party/libaddressinput/chromium/storage_test_runner.cc
new file mode 100644
index 0000000000000000000000000000000000000000..453f0f292895382f94d166a35aea210b17e2b160
--- /dev/null
+++ b/third_party/libaddressinput/chromium/storage_test_runner.cc
@@ -0,0 +1,88 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "third_party/libaddressinput/chromium/storage_test_runner.h"
+
+#include <cassert>
+#include <cstddef>
+#include <string>
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/callback.h"
+
+namespace autofill {
+
+using ::i18n::addressinput::Storage;
+
+StorageTestRunner::StorageTestRunner(Storage* storage)
+ : storage_(storage),
+ success_(false),
+ key_(),
+ data_() {}
+
+StorageTestRunner::~StorageTestRunner() {}
+
+void StorageTestRunner::RunAllTests() {
+ EXPECT_NO_FATAL_FAILURE(GetWithoutPutReturnsEmptyData());
+ EXPECT_NO_FATAL_FAILURE(GetReturnsWhatWasPut());
+ EXPECT_NO_FATAL_FAILURE(SecondPutOverwritesData());
+}
+
+void StorageTestRunner::ClearValues() {
+ success_ = false;
+ key_.clear();
+ data_.clear();
+}
+
+scoped_ptr<Storage::Callback> StorageTestRunner::BuildCallback() {
+ return scoped_ptr<Storage::Callback>(::i18n::addressinput::BuildCallback(
+ this, &StorageTestRunner::OnDataReady));
+}
+
+void StorageTestRunner::OnDataReady(bool success,
+ const std::string& key,
+ std::string* data) {
+ assert(!success || data != NULL);
+ success_ = success;
+ key_ = key;
+ if (data != NULL) {
+ data_ = *data;
+ delete data;
+ }
+}
+
+void StorageTestRunner::GetWithoutPutReturnsEmptyData() {
+ ClearValues();
+ scoped_ptr<Storage::Callback> callback(BuildCallback());
+ storage_->Get("key", *callback);
+
+ EXPECT_FALSE(success_);
+ EXPECT_EQ("key", key_);
+ EXPECT_TRUE(data_.empty());
+}
+
+void StorageTestRunner::GetReturnsWhatWasPut() {
+ ClearValues();
+ storage_->Put("key", new std::string("value"));
+ scoped_ptr<Storage::Callback> callback(BuildCallback());
+ storage_->Get("key", *callback);
+
+ EXPECT_TRUE(success_);
+ EXPECT_EQ("key", key_);
+ EXPECT_EQ("value", data_);
+}
+
+void StorageTestRunner::SecondPutOverwritesData() {
+ ClearValues();
+ storage_->Put("key", new std::string("bad-value"));
+ storage_->Put("key", new std::string("good-value"));
+ scoped_ptr<Storage::Callback> callback(BuildCallback());
+ storage_->Get("key", *callback);
+
+ EXPECT_TRUE(success_);
+ EXPECT_EQ("key", key_);
+ EXPECT_EQ("good-value", data_);
+}
+
+} // namespace autofill
« no previous file with comments | « third_party/libaddressinput/chromium/storage_test_runner.h ('k') | third_party/libaddressinput/chromium/string_compare.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698