This source file includes following definitions.
- data_
- RunAllTests
- ClearValues
- BuildCallback
- OnDataReady
- GetWithoutPutReturnsEmptyData
- GetReturnsWhatWasPut
- SecondPutOverwritesData
#include "storage_test_runner.h"
#include <libaddressinput/callback.h>
#include <gtest/gtest.h>
namespace i18n {
namespace addressinput {
StorageTestRunner::StorageTestRunner(Storage* storage)
: storage_(storage),
success_(false),
key_(),
data_() {}
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 ::i18n::addressinput::BuildCallback(
this, &StorageTestRunner::OnDataReady);
}
void StorageTestRunner::OnDataReady(bool success,
const std::string& key,
const std::string& data) {
success_ = success;
key_ = key;
data_ = data;
}
void StorageTestRunner::GetWithoutPutReturnsEmptyData() {
ClearValues();
storage_->Get("key", BuildCallback());
EXPECT_FALSE(success_);
EXPECT_EQ("key", key_);
EXPECT_TRUE(data_.empty());
}
void StorageTestRunner::GetReturnsWhatWasPut() {
ClearValues();
storage_->Put("key", make_scoped_ptr(new std::string("value")));
storage_->Get("key", BuildCallback());
EXPECT_TRUE(success_);
EXPECT_EQ("key", key_);
EXPECT_EQ("value", data_);
}
void StorageTestRunner::SecondPutOverwritesData() {
ClearValues();
storage_->Put("key", make_scoped_ptr(new std::string("bad-value")));
storage_->Put("key", make_scoped_ptr(new std::string("good-value")));
storage_->Get("key", BuildCallback());
EXPECT_TRUE(success_);
EXPECT_EQ("key", key_);
EXPECT_EQ("good-value", data_);
}
}
}