aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Chromium Automerger <chromium-automerger@android>2014-07-29 12:29:24 +0000
committerAndroid Chromium Automerger <chromium-automerger@android>2014-07-29 12:29:24 +0000
commit54a1d3775be0a9fa03e19148df021d4ede38136c (patch)
treecfca6c61fb69eb22e64409a047e27ca24682c263
parentf496d663e1e3881f1200ed176fc8cf7a454cd29b (diff)
parentd75941244491c922456bf0fa4a987c098f082a76 (diff)
downloadsrc-54a1d3775be0a9fa03e19148df021d4ede38136c.tar.gz
Merge third_party/libaddressinput/src from https://chromium.googlesource.com/external/libaddressinput.git at d75941244491c922456bf0fa4a987c098f082a76
This commit was generated by merge_from_chromium.py. Change-Id: I705206ae4461b34c2863fc1b0fe69421625a901c
-rw-r--r--cpp/src/address_data.cc24
-rw-r--r--cpp/src/address_formatter.cc6
-rw-r--r--cpp/src/address_input_helper.cc2
-rw-r--r--cpp/src/address_ui.cc12
-rw-r--r--cpp/src/language.cc8
-rw-r--r--cpp/src/lookup_key.cc5
-rw-r--r--cpp/src/post_box_matchers.cc2
-rw-r--r--cpp/src/region_data_builder.cc27
-rw-r--r--cpp/src/region_data_constants.cc6
-rw-r--r--cpp/src/rule.cc2
-rw-r--r--cpp/src/rule.h8
-rw-r--r--cpp/src/util/json.cc4
-rw-r--r--cpp/src/validating_util.cc2
-rw-r--r--cpp/src/validation_task.cc5
-rw-r--r--cpp/src/validation_task.h6
-rw-r--r--cpp/test/address_field_util_test.cc4
-rw-r--r--cpp/test/address_input_helper_test.cc12
-rw-r--r--cpp/test/address_normalizer_test.cc13
-rw-r--r--cpp/test/address_validator_test.cc4
-rw-r--r--cpp/test/fake_downloader.cc12
-rw-r--r--cpp/test/fake_downloader_test.cc36
-rw-r--r--cpp/test/fake_storage_test.cc26
-rw-r--r--cpp/test/localization_test.cc144
-rw-r--r--cpp/test/null_storage_test.cc14
-rw-r--r--cpp/test/ondemand_supply_task_test.cc8
-rw-r--r--cpp/test/region_data_builder_test.cc12
-rw-r--r--cpp/test/retriever_test.cc32
-rw-r--r--cpp/test/rule_retriever_test.cc16
-rw-r--r--cpp/test/supplier_test.cc4
-rw-r--r--cpp/test/util/json_test.cc4
-rw-r--r--cpp/test/util/string_compare_test.cc44
-rw-r--r--cpp/test/validating_storage_test.cc31
32 files changed, 268 insertions, 267 deletions
diff --git a/cpp/src/address_data.cc b/cpp/src/address_data.cc
index a3549ed..644000e 100644
--- a/cpp/src/address_data.cc
+++ b/cpp/src/address_data.cc
@@ -76,9 +76,9 @@ bool AddressData::IsFieldEmpty(AddressField field) const {
return IsStringEmpty(value);
} else {
const std::vector<std::string>& value = GetRepeatedFieldValue(field);
- return std::find_if(value.begin(), value.end(),
- std::not1(std::ptr_fun(&IsStringEmpty))) ==
- value.end();
+ return std::find_if(value.begin(),
+ value.end(),
+ std::not1(std::ptr_fun(&IsStringEmpty))) == value.end();
}
}
@@ -104,16 +104,14 @@ const std::vector<std::string>& AddressData::GetRepeatedFieldValue(
}
bool AddressData::operator==(const AddressData& other) const {
- return
- region_code == other.region_code &&
- address_line == other.address_line &&
- administrative_area == other.administrative_area &&
- locality == other.locality &&
- dependent_locality == other.dependent_locality &&
- postal_code == other.postal_code &&
- sorting_code == other.sorting_code &&
- language_code == other.language_code &&
- recipient == other.recipient;
+ return region_code == other.region_code &&
+ address_line == other.address_line &&
+ administrative_area == other.administrative_area &&
+ locality == other.locality &&
+ dependent_locality == other.dependent_locality &&
+ postal_code == other.postal_code &&
+ sorting_code == other.sorting_code &&
+ language_code == other.language_code && recipient == other.recipient;
}
// static
diff --git a/cpp/src/address_formatter.cc b/cpp/src/address_formatter.cc
index 3440288..b866b8d 100644
--- a/cpp/src/address_formatter.cc
+++ b/cpp/src/address_formatter.cc
@@ -143,7 +143,8 @@ void GetFormattedNationalAddress(
// explicitly tagged as being Latin, then use the latinized formatting rules.
const std::vector<FormatElement>& format =
language.has_latin_script && !rule.GetLatinFormat().empty()
- ? rule.GetLatinFormat() : rule.GetFormat();
+ ? rule.GetLatinFormat()
+ : rule.GetFormat();
std::string line;
for (size_t i = 0; i < format.size(); ++i) {
@@ -162,7 +163,8 @@ void GetFormattedNationalAddress(
lines->push_back(line);
line.clear();
}
- lines->insert(lines->end(), address_data.address_line.begin(),
+ lines->insert(lines->end(),
+ address_data.address_line.begin(),
address_data.address_line.end());
} else {
line.append(address_data.GetFieldValue(field));
diff --git a/cpp/src/address_input_helper.cc b/cpp/src/address_input_helper.cc
index 39a6264..c492760 100644
--- a/cpp/src/address_input_helper.cc
+++ b/cpp/src/address_input_helper.cc
@@ -99,7 +99,7 @@ void FillAddressFromMatchedRules(
AddressInputHelper::AddressInputHelper(PreloadSupplier* supplier)
: supplier_(supplier) {
- assert(supplier_ != NULL);
+ assert(supplier_ != NULL);
}
AddressInputHelper::~AddressInputHelper() {
diff --git a/cpp/src/address_ui.cc b/cpp/src/address_ui.cc
index 06baac5..bf76cfd 100644
--- a/cpp/src/address_ui.cc
+++ b/cpp/src/address_ui.cc
@@ -98,9 +98,9 @@ std::vector<AddressUiComponent> BuildComponents(
*best_address_language_tag = best_address_language.tag;
const std::vector<FormatElement>& format =
- !rule.GetLatinFormat().empty() &&
- best_address_language.has_latin_script
- ? rule.GetLatinFormat() : rule.GetFormat();
+ !rule.GetLatinFormat().empty() && best_address_language.has_latin_script
+ ? rule.GetLatinFormat()
+ : rule.GetFormat();
// For avoiding showing an input field twice, when the field is displayed
// twice on an envelope.
@@ -126,8 +126,10 @@ std::vector<AddressUiComponent> BuildComponents(
: AddressUiComponent::HINT_SHORT;
preceded_by_newline = false;
component.field = format_it->GetField();
- component.name = GetLabelForField(localization, format_it->GetField(),
- rule.GetAdminAreaNameMessageId(), rule.GetPostalCodeNameMessageId());
+ component.name = GetLabelForField(localization,
+ format_it->GetField(),
+ rule.GetAdminAreaNameMessageId(),
+ rule.GetPostalCodeNameMessageId());
result.push_back(component);
}
diff --git a/cpp/src/language.cc b/cpp/src/language.cc
index 9e456f0..28817dc 100644
--- a/cpp/src/language.cc
+++ b/cpp/src/language.cc
@@ -32,13 +32,13 @@ Language::Language(const std::string& language_tag) : tag(language_tag),
// legacy code generates tags with '_' instead of '-'.
static const char kSubtagsSeparator = '-';
static const char kAlternativeSubtagsSeparator = '_';
- std::replace(tag.begin(), tag.end(), kAlternativeSubtagsSeparator,
- kSubtagsSeparator);
+ std::replace(
+ tag.begin(), tag.end(), kAlternativeSubtagsSeparator, kSubtagsSeparator);
// OK to use 'tolower' because BCP 47 tags are always in ASCII.
std::string lowercase = tag;
- std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(),
- tolower);
+ std::transform(
+ lowercase.begin(), lowercase.end(), lowercase.begin(), tolower);
base = lowercase.substr(0, lowercase.find(kSubtagsSeparator));
diff --git a/cpp/src/lookup_key.cc b/cpp/src/lookup_key.cc
index acde828..d793a2b 100644
--- a/cpp/src/lookup_key.cc
+++ b/cpp/src/lookup_key.cc
@@ -98,8 +98,9 @@ void LookupKey::FromAddress(const AddressData& address) {
}
}
Language address_language(address.language_code);
- std::string language_tag_no_latn = address_language.has_latin_script ?
- address_language.base : address_language.tag;
+ std::string language_tag_no_latn = address_language.has_latin_script
+ ? address_language.base
+ : address_language.tag;
if (ShouldSetLanguageForKey(language_tag_no_latn, address.region_code)) {
language_ = language_tag_no_latn;
}
diff --git a/cpp/src/post_box_matchers.cc b/cpp/src/post_box_matchers.cc
index e8628b5..f1ad6dd 100644
--- a/cpp/src/post_box_matchers.cc
+++ b/cpp/src/post_box_matchers.cc
@@ -97,7 +97,7 @@ std::map<std::string, const RE2ptr*> InitMatchers() {
return matchers;
}
-} // namespace
+} // namespace
// static
std::vector<const RE2ptr*> PostBoxMatchers::GetMatchers(
diff --git a/cpp/src/region_data_builder.cc b/cpp/src/region_data_builder.cc
index 82d223c..cf49c71 100644
--- a/cpp/src/region_data_builder.cc
+++ b/cpp/src/region_data_builder.cc
@@ -59,8 +59,8 @@ void BuildRegionTreeRecursively(PreloadSupplier* supplier,
? rule->GetLatinName() : local_name;
RegionData* region = parent_region->AddSubRegion(*key_it, name);
if (!rule->GetSubKeys().empty()) {
- BuildRegionTreeRecursively(supplier, lookup_key, region,
- rule->GetSubKeys(), prefer_latin_name);
+ BuildRegionTreeRecursively(
+ supplier, lookup_key, region, rule->GetSubKeys(), prefer_latin_name);
}
}
}
@@ -82,8 +82,11 @@ RegionData* BuildRegion(PreloadSupplier* supplier,
assert(rule != NULL);
RegionData* region = new RegionData(region_code);
- BuildRegionTreeRecursively(supplier, lookup_key, region,
- rule->GetSubKeys(), language.has_latin_script);
+ BuildRegionTreeRecursively(supplier,
+ lookup_key,
+ region,
+ rule->GetSubKeys(),
+ language.has_latin_script);
return region;
}
@@ -127,17 +130,21 @@ const RegionData& RegionDataBuilder::Build(
Rule rule;
rule.ParseSerializedRule(RegionDataConstants::GetRegionData(region_code));
static const Language kUndefinedLanguage("und");
- const Language& best_language = rule.GetLanguages().empty()
- ? kUndefinedLanguage
- : ChooseBestAddressLanguage(rule, Language(ui_language_tag));
+ const Language& best_language =
+ rule.GetLanguages().empty()
+ ? kUndefinedLanguage
+ : ChooseBestAddressLanguage(rule, Language(ui_language_tag));
*best_region_tree_language_tag = best_language.tag;
LanguageRegionMap::const_iterator language_it =
region_it->second->find(best_language.tag);
if (language_it == region_it->second->end()) {
- language_it = region_it->second->insert(std::make_pair(
- best_language.tag,
- BuildRegion(supplier_, region_code, best_language))).first;
+ language_it =
+ region_it->second->insert(std::make_pair(best_language.tag,
+ BuildRegion(supplier_,
+ region_code,
+ best_language)))
+ .first;
}
return *language_it->second;
diff --git a/cpp/src/region_data_constants.cc b/cpp/src/region_data_constants.cc
index 1dce6c3..3557536 100644
--- a/cpp/src/region_data_constants.cc
+++ b/cpp/src/region_data_constants.cc
@@ -1397,8 +1397,10 @@ struct SelectFirst {
std::vector<std::string> InitRegionCodes() {
std::vector<std::string> region_codes(GetAllRegionData().size());
- std::transform(GetAllRegionData().begin(), GetAllRegionData().end(),
- region_codes.begin(), SelectFirst());
+ std::transform(GetAllRegionData().begin(),
+ GetAllRegionData().end(),
+ region_codes.begin(),
+ SelectFirst());
return region_codes;
}
diff --git a/cpp/src/rule.cc b/cpp/src/rule.cc
index a6fd9b5..7ab84e5 100644
--- a/cpp/src/rule.cc
+++ b/cpp/src/rule.cc
@@ -14,6 +14,7 @@
#include "rule.h"
+#include <cassert>
#include <cstddef>
#include <map>
#include <string>
@@ -137,6 +138,7 @@ const Rule& Rule::GetDefault() {
}
void Rule::CopyFrom(const Rule& rule) {
+ assert(this != &rule);
id_ = rule.id_;
format_ = rule.format_;
latin_format_ = rule.latin_format_;
diff --git a/cpp/src/rule.h b/cpp/src/rule.h
index 10615f4..1286bcb 100644
--- a/cpp/src/rule.h
+++ b/cpp/src/rule.h
@@ -98,9 +98,7 @@ class Rule {
}
// Returns the sole postal code for this rule, if there is one.
- const std::string& GetSolePostalCode() const {
- return sole_postal_code_;
- }
+ const std::string& GetSolePostalCode() const { return sole_postal_code_; }
// The message string identifier for admin area name. If not set, then
// INVALID_MESSAGE_ID.
@@ -126,9 +124,7 @@ class Rule {
}
// Returns the post service URL string for this rule.
- const std::string& GetPostServiceUrl() const {
- return post_service_url_;
- }
+ const std::string& GetPostServiceUrl() const { return post_service_url_; }
private:
std::string id_;
diff --git a/cpp/src/util/json.cc b/cpp/src/util/json.cc
index 352c62b..4f26069 100644
--- a/cpp/src/util/json.cc
+++ b/cpp/src/util/json.cc
@@ -85,9 +85,7 @@ class Json::JsonImpl {
(void)inserted;
}
- const std::vector<std::string>& GetKeys() const {
- return keys_;
- }
+ const std::vector<std::string>& GetKeys() const { return keys_; }
private:
void BuildKeyList() {
diff --git a/cpp/src/validating_util.cc b/cpp/src/validating_util.cc
index df3fc06..084c09c 100644
--- a/cpp/src/validating_util.cc
+++ b/cpp/src/validating_util.cc
@@ -111,7 +111,7 @@ bool ValidatingUtil::UnwrapTimestamp(std::string* data, time_t now) {
std::string timestamp_string;
if (!UnwrapHeader(
- kTimestampPrefix, kTimestampPrefixLength, data, &timestamp_string)) {
+ kTimestampPrefix, kTimestampPrefixLength, data, &timestamp_string)) {
return false;
}
diff --git a/cpp/src/validation_task.cc b/cpp/src/validation_task.cc
index 074847b..727de6a 100644
--- a/cpp/src/validation_task.cc
+++ b/cpp/src/validation_task.cc
@@ -256,9 +256,10 @@ void ValidationTask::ReportProblemMaybe(AddressField field,
bool ValidationTask::ShouldReport(AddressField field,
AddressProblem problem) const {
return filter_ == NULL || filter_->empty() ||
- std::find(filter_->begin(), filter_->end(),
+ std::find(filter_->begin(),
+ filter_->end(),
FieldProblemMap::value_type(field, problem)) !=
- filter_->end();
+ filter_->end();
}
} // namespace addressinput
diff --git a/cpp/src/validation_task.h b/cpp/src/validation_task.h
index 5ab1b8f..1658678 100644
--- a/cpp/src/validation_task.h
+++ b/cpp/src/validation_task.h
@@ -65,16 +65,14 @@ class ValidationTask {
void CheckMissingRequiredField(const std::string& region_code) const;
// Checks the hierarchical fields for UNKNOWN_VALUE problems.
- void CheckUnknownValue(
- const Supplier::RuleHierarchy& hierarchy) const;
+ void CheckUnknownValue(const Supplier::RuleHierarchy& hierarchy) const;
// Checks the POSTAL_CODE field for problems.
void CheckPostalCodeFormatAndValue(
const Supplier::RuleHierarchy& hierarchy) const;
// Checks the STREET_ADDRESS field for USES_P_O_BOX problems.
- void CheckUsesPoBox(
- const Supplier::RuleHierarchy& hierarchy) const;
+ void CheckUsesPoBox(const Supplier::RuleHierarchy& hierarchy) const;
// Writes (|field|,|problem|) to |problems_|.
void ReportProblem(AddressField field, AddressProblem problem) const;
diff --git a/cpp/test/address_field_util_test.cc b/cpp/test/address_field_util_test.cc
index 6e3bd6a..0db6bf5 100644
--- a/cpp/test/address_field_util_test.cc
+++ b/cpp/test/address_field_util_test.cc
@@ -36,7 +36,7 @@ using i18n::addressinput::STREET_ADDRESS;
TEST(AddressFieldUtilTest, FormatParseNewline) {
std::vector<FormatElement> actual;
- ParseFormatRule("%O%n%N%n%A%nAX-%Z %C%nÅLAND", &actual);
+ ParseFormatRule("%O%n%N%n%A%nAX-%Z %C%n\xC3\x85LAND", &actual); /* "ÅLAND" */
std::vector<FormatElement> expected;
// Organization is skipped.
@@ -50,7 +50,7 @@ TEST(AddressFieldUtilTest, FormatParseNewline) {
expected.push_back(FormatElement(" "));
expected.push_back(FormatElement(LOCALITY));
expected.push_back(FormatElement());
- expected.push_back(FormatElement("ÅLAND"));
+ expected.push_back(FormatElement("\xC3\x85LAND")); /* "ÅLAND" */
EXPECT_EQ(expected, actual);
}
diff --git a/cpp/test/address_input_helper_test.cc b/cpp/test/address_input_helper_test.cc
index bb683da..5580ec7 100644
--- a/cpp/test/address_input_helper_test.cc
+++ b/cpp/test/address_input_helper_test.cc
@@ -65,9 +65,7 @@ class AddressInputHelperTest : public testing::Test {
private:
// Used to preload data that we need.
- void Loaded(bool success, const std::string&, int) {
- ASSERT_TRUE(success);
- }
+ void Loaded(bool success, const std::string&, int) { ASSERT_TRUE(success); }
PreloadSupplier supplier_;
const AddressInputHelper address_input_helper_;
@@ -194,8 +192,8 @@ TEST_F(AddressInputHelperTest, AddressWithPostalCodeMatchingMultipleValues) {
address.postal_code = "527-111";
AddressData expected = address;
- /* The province, Jeonnam - 전라남도 - is known, but we have several locality
- * matches so none of them are populated. */
+ /* The province, Jeonnam - 전라남도 - is known, but we have several locality
+ * matches so none of them are populated. */
expected.administrative_area =
"\xEC\xA0\x84\xEB\x9D\xBC\xEB\x82\xA8\xEB\x8F\x84";
FillAddress(&address);
@@ -271,9 +269,7 @@ class AddressInputHelperMockDataTest : public testing::Test {
private:
// Our mock downloader we assume will always succeed.
- void Loaded(bool success, const std::string&, int) {
- ASSERT_TRUE(success);
- }
+ void Loaded(bool success, const std::string&, int) { ASSERT_TRUE(success); }
PreloadSupplier supplier_;
const AddressInputHelper address_input_helper_;
diff --git a/cpp/test/address_normalizer_test.cc b/cpp/test/address_normalizer_test.cc
index 4253867..fc4404b 100644
--- a/cpp/test/address_normalizer_test.cc
+++ b/cpp/test/address_normalizer_test.cc
@@ -88,12 +88,13 @@ TEST_F(AddressNormalizerTest, GangwonKoreanName) {
AddressData address;
address.language_code = "ko-KR";
address.region_code = "KR";
- address.administrative_area = "강원";
+ address.administrative_area = "\xEA\xB0\x95\xEC\x9B\x90"; /* "강원" */
normalizer_.Normalize(&address);
- EXPECT_EQ("강원도", address.administrative_area);
+ EXPECT_EQ(
+ "\xEA\xB0\x95\xEC\x9B\x90\xEB\x8F\x84", /* "강원도" */
+ address.administrative_area);
}
-
TEST_F(AddressNormalizerTest, DontSwitchLatinScriptForUnknownLanguage) {
supplier_.LoadRules("KR", *loaded_);
AddressData address;
@@ -107,9 +108,11 @@ TEST_F(AddressNormalizerTest, DontSwitchLocalScriptForUnknownLanguage) {
supplier_.LoadRules("KR", *loaded_);
AddressData address;
address.region_code = "KR";
- address.administrative_area = "강원";
+ address.administrative_area = "\xEA\xB0\x95\xEC\x9B\x90"; /* "강원" */
normalizer_.Normalize(&address);
- EXPECT_EQ("강원도", address.administrative_area);
+ EXPECT_EQ(
+ "\xEA\xB0\x95\xEC\x9B\x90\xEB\x8F\x84", /* "강원도" */
+ address.administrative_area);
}
} // namespace
diff --git a/cpp/test/address_validator_test.cc b/cpp/test/address_validator_test.cc
index fce9777..b90eef9 100644
--- a/cpp/test/address_validator_test.cc
+++ b/cpp/test/address_validator_test.cc
@@ -132,9 +132,7 @@ class PreloadValidatorWrapper : public ValidatorWrapper {
validator_(&supplier_),
loaded_(BuildCallback(this, &PreloadValidatorWrapper::Loaded)) {}
- void Loaded(bool success, const std::string&, int) {
- ASSERT_TRUE(success);
- }
+ void Loaded(bool success, const std::string&, int) { ASSERT_TRUE(success); }
PreloadSupplier supplier_;
const AddressValidator validator_;
diff --git a/cpp/test/fake_downloader.cc b/cpp/test/fake_downloader.cc
index 2f18db7..c642eac 100644
--- a/cpp/test/fake_downloader.cc
+++ b/cpp/test/fake_downloader.cc
@@ -16,7 +16,9 @@
#include <cassert>
#include <cstddef>
+#include <cstdlib>
#include <fstream>
+#include <iostream>
#include <map>
#include <string>
#include <utility>
@@ -72,7 +74,10 @@ const LookupKeyUtil& GetAggregateLookupKeyUtil() {
std::map<std::string, std::string> InitData() {
std::map<std::string, std::string> data;
std::ifstream file(kDataFileName);
- assert(file.is_open());
+ if (!file.is_open()) {
+ std::cerr << "Error opening \"" << kDataFileName << "\"." << std::endl;
+ std::exit(EXIT_FAILURE);
+ }
std::string line;
while (file.good()) {
@@ -101,8 +106,9 @@ std::map<std::string, std::string> InitData() {
kDataKeyPrefixLength) == 0) {
// Example aggregate URL:
// test:///aggregate/data/CH
- const std::string& aggregate_url = GetAggregateLookupKeyUtil()
- .GetUrlForKey(key.substr(0, kAggregateDataKeyLength));
+ const std::string& aggregate_url =
+ GetAggregateLookupKeyUtil().GetUrlForKey(
+ key.substr(0, kAggregateDataKeyLength));
std::map<std::string, std::string>::iterator aggregate_data_it =
data.find(aggregate_url);
diff --git a/cpp/test/fake_downloader_test.cc b/cpp/test/fake_downloader_test.cc
index 2d9825f..29a3983 100644
--- a/cpp/test/fake_downloader_test.cc
+++ b/cpp/test/fake_downloader_test.cc
@@ -28,6 +28,7 @@
namespace {
+using i18n::addressinput::BuildCallback;
using i18n::addressinput::Downloader;
using i18n::addressinput::FakeDownloader;
using i18n::addressinput::RegionDataConstants;
@@ -36,18 +37,20 @@ using i18n::addressinput::scoped_ptr;
// Tests for FakeDownloader object.
class FakeDownloaderTest : public testing::TestWithParam<std::string> {
protected:
- FakeDownloaderTest() : downloader_(), success_(false), url_(), data_() {}
- virtual ~FakeDownloaderTest() {}
+ FakeDownloaderTest()
+ : downloader_(),
+ success_(false),
+ url_(),
+ data_(),
+ downloaded_(BuildCallback(this, &FakeDownloaderTest::OnDownloaded)) {}
- Downloader::Callback* BuildCallback() {
- return i18n::addressinput::BuildCallback(
- this, &FakeDownloaderTest::OnDownloaded);
- }
+ virtual ~FakeDownloaderTest() {}
FakeDownloader downloader_;
bool success_;
std::string url_;
std::string data_;
+ const scoped_ptr<const Downloader::Callback> downloaded_;
private:
void OnDownloaded(bool success, const std::string& url, std::string* data) {
@@ -95,8 +98,7 @@ testing::AssertionResult DataIsValid(const std::string& data,
TEST_P(FakeDownloaderTest, FakeDownloaderHasValidDataForRegion) {
std::string key = "data/" + GetParam();
std::string url = std::string(FakeDownloader::kFakeDataUrl) + key;
- const scoped_ptr<const Downloader::Callback> callback(BuildCallback());
- downloader_.Download(url, *callback);
+ downloader_.Download(url, *downloaded_);
EXPECT_TRUE(success_);
EXPECT_EQ(url, url_);
@@ -136,8 +138,7 @@ testing::AssertionResult AggregateDataIsValid(const std::string& data,
TEST_P(FakeDownloaderTest, FakeDownloaderHasValidAggregatedDataForRegion) {
std::string key = "data/" + GetParam();
std::string url = std::string(FakeDownloader::kFakeAggregateDataUrl) + key;
- const scoped_ptr<const Downloader::Callback> callback(BuildCallback());
- downloader_.Download(url, *callback);
+ downloader_.Download(url, *downloaded_);
EXPECT_TRUE(success_);
EXPECT_EQ(url, url_);
@@ -154,8 +155,7 @@ TEST_F(FakeDownloaderTest, DownloadExistingData) {
static const std::string kKey = "data";
static const std::string kUrl =
std::string(FakeDownloader::kFakeDataUrl) + kKey;
- const scoped_ptr<const Downloader::Callback> callback(BuildCallback());
- downloader_.Download(kUrl, *callback);
+ downloader_.Download(kUrl, *downloaded_);
EXPECT_TRUE(success_);
EXPECT_EQ(kUrl, url_);
@@ -166,8 +166,7 @@ TEST_F(FakeDownloaderTest, DownloadExistingData) {
TEST_F(FakeDownloaderTest, DownloadMissingKeyReturnsEmptyDictionary) {
static const std::string kJunkUrl =
std::string(FakeDownloader::kFakeDataUrl) + "junk";
- const scoped_ptr<const Downloader::Callback> callback(BuildCallback());
- downloader_.Download(kJunkUrl, *callback);
+ downloader_.Download(kJunkUrl, *downloaded_);
EXPECT_TRUE(success_);
EXPECT_EQ(kJunkUrl, url_);
@@ -178,8 +177,7 @@ TEST_F(FakeDownloaderTest, DownloadMissingKeyReturnsEmptyDictionary) {
TEST_F(FakeDownloaderTest, AggregateDownloadMissingKeyReturnsEmptyDictionary) {
static const std::string kJunkUrl =
std::string(FakeDownloader::kFakeAggregateDataUrl) + "junk";
- const scoped_ptr<const Downloader::Callback> callback(BuildCallback());
- downloader_.Download(kJunkUrl, *callback);
+ downloader_.Download(kJunkUrl, *downloaded_);
EXPECT_TRUE(success_);
EXPECT_EQ(kJunkUrl, url_);
@@ -189,8 +187,7 @@ TEST_F(FakeDownloaderTest, AggregateDownloadMissingKeyReturnsEmptyDictionary) {
// Verifies that downloading an empty key will return "{}".
TEST_F(FakeDownloaderTest, DownloadEmptyKeyReturnsEmptyDictionary) {
static const std::string kPrefixOnlyUrl = FakeDownloader::kFakeDataUrl;
- const scoped_ptr<const Downloader::Callback> callback(BuildCallback());
- downloader_.Download(kPrefixOnlyUrl, *callback);
+ downloader_.Download(kPrefixOnlyUrl, *downloaded_);
EXPECT_TRUE(success_);
EXPECT_EQ(kPrefixOnlyUrl, url_);
@@ -200,8 +197,7 @@ TEST_F(FakeDownloaderTest, DownloadEmptyKeyReturnsEmptyDictionary) {
// Verifies that downloading a real URL fails.
TEST_F(FakeDownloaderTest, DownloadRealUrlFals) {
static const std::string kRealUrl = "http://www.google.com/";
- const scoped_ptr<const Downloader::Callback> callback(BuildCallback());
- downloader_.Download(kRealUrl, *callback);
+ downloader_.Download(kRealUrl, *downloaded_);
EXPECT_FALSE(success_);
EXPECT_EQ(kRealUrl, url_);
diff --git a/cpp/test/fake_storage_test.cc b/cpp/test/fake_storage_test.cc
index ec1695d..94fed9e 100644
--- a/cpp/test/fake_storage_test.cc
+++ b/cpp/test/fake_storage_test.cc
@@ -26,6 +26,7 @@
namespace {
+using i18n::addressinput::BuildCallback;
using i18n::addressinput::FakeStorage;
using i18n::addressinput::scoped_ptr;
using i18n::addressinput::Storage;
@@ -33,18 +34,20 @@ using i18n::addressinput::Storage;
// Tests for FakeStorage object.
class FakeStorageTest : public testing::Test {
protected:
- FakeStorageTest() : storage_(), success_(false), key_(), data_() {}
- virtual ~FakeStorageTest() {}
+ FakeStorageTest()
+ : storage_(),
+ success_(false),
+ key_(),
+ data_(),
+ data_ready_(BuildCallback(this, &FakeStorageTest::OnDataReady)) {}
- Storage::Callback* BuildCallback() {
- return i18n::addressinput::BuildCallback(
- this, &FakeStorageTest::OnDataReady);
- }
+ virtual ~FakeStorageTest() {}
FakeStorage storage_;
bool success_;
std::string key_;
std::string data_;
+ const scoped_ptr<const Storage::Callback> data_ready_;
private:
void OnDataReady(bool success,
@@ -63,8 +66,7 @@ class FakeStorageTest : public testing::Test {
};
TEST_F(FakeStorageTest, GetWithoutPutReturnsEmptyData) {
- const scoped_ptr<const Storage::Callback> callback(BuildCallback());
- storage_.Get("key", *callback);
+ storage_.Get("key", *data_ready_);
EXPECT_FALSE(success_);
EXPECT_EQ("key", key_);
@@ -73,9 +75,7 @@ TEST_F(FakeStorageTest, GetWithoutPutReturnsEmptyData) {
TEST_F(FakeStorageTest, GetReturnsWhatWasPut) {
storage_.Put("key", new std::string("value"));
-
- const scoped_ptr<const Storage::Callback> callback(BuildCallback());
- storage_.Get("key", *callback);
+ storage_.Get("key", *data_ready_);
EXPECT_TRUE(success_);
EXPECT_EQ("key", key_);
@@ -85,9 +85,7 @@ TEST_F(FakeStorageTest, GetReturnsWhatWasPut) {
TEST_F(FakeStorageTest, SecondPutOverwritesData) {
storage_.Put("key", new std::string("bad-value"));
storage_.Put("key", new std::string("good-value"));
-
- const scoped_ptr<const Storage::Callback> callback(BuildCallback());
- storage_.Get("key", *callback);
+ storage_.Get("key", *data_ready_);
EXPECT_TRUE(success_);
EXPECT_EQ("key", key_);
diff --git a/cpp/test/localization_test.cc b/cpp/test/localization_test.cc
index e0f3e00..b47d5c8 100644
--- a/cpp/test/localization_test.cc
+++ b/cpp/test/localization_test.cc
@@ -127,9 +127,9 @@ TEST(LocalizationGetErrorMessageTest, MissingRequiredPostalCode) {
Localization localization;
AddressData address;
address.region_code = "CH";
- EXPECT_EQ(std::string("You must provide a postal code, for example 2544.") +
- " Don't know your postal code? Find it out" +
- " <a href=\"http://www.post.ch/db/owa/pv_plz_pack/pr_main\">" +
+ EXPECT_EQ("You must provide a postal code, for example 2544."
+ " Don't know your postal code? Find it out"
+ " <a href=\"http://www.post.ch/db/owa/pv_plz_pack/pr_main\">"
"here</a>.",
localization.GetErrorMessage(address, POSTAL_CODE,
MISSING_REQUIRED_FIELD, true, true));
@@ -148,9 +148,9 @@ TEST(LocalizationGetErrorMessageTest, MissingRequiredZipCode) {
Localization localization;
AddressData address;
address.region_code = "US";
- EXPECT_EQ(std::string("You must provide a ZIP code, for example 95014.") +
- " Don't know your ZIP code? Find it out" +
- " <a href=\"https://tools.usps.com/go/ZipLookupAction!" +
+ EXPECT_EQ("You must provide a ZIP code, for example 95014."
+ " Don't know your ZIP code? Find it out"
+ " <a href=\"https://tools.usps.com/go/ZipLookupAction!"
"input.action\">here</a>.",
localization.GetErrorMessage(address, POSTAL_CODE,
MISSING_REQUIRED_FIELD, true, true));
@@ -207,115 +207,115 @@ TEST(LocalizationGetErrorMessageTest, UnknownValueOtherFields) {
address_line.push_back("bad address line 2");
address.address_line = address_line;
address.recipient = "bad recipient";
- EXPECT_EQ(std::string("US ") +
+ EXPECT_EQ("US "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, COUNTRY, UNKNOWN_VALUE, true, true));
- EXPECT_EQ(std::string("US ") +
+ EXPECT_EQ("US "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, COUNTRY, UNKNOWN_VALUE, true, false));
- EXPECT_EQ(std::string("US ") +
+ EXPECT_EQ("US "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, COUNTRY, UNKNOWN_VALUE, false, false));
- EXPECT_EQ(std::string("US ") +
+ EXPECT_EQ("US "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, COUNTRY, UNKNOWN_VALUE, false, true));
- EXPECT_EQ(std::string("bad admin area ") +
+ EXPECT_EQ("bad admin area "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, ADMIN_AREA, UNKNOWN_VALUE, true, true));
- EXPECT_EQ(std::string("bad admin area ") +
+ EXPECT_EQ("bad admin area "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, ADMIN_AREA, UNKNOWN_VALUE, true, false));
- EXPECT_EQ(std::string("bad admin area ") +
+ EXPECT_EQ("bad admin area "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, ADMIN_AREA, UNKNOWN_VALUE, false, false));
- EXPECT_EQ(std::string("bad admin area ") +
+ EXPECT_EQ("bad admin area "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, ADMIN_AREA, UNKNOWN_VALUE, false, true));
- EXPECT_EQ(std::string("bad locality ") +
+ EXPECT_EQ("bad locality "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, LOCALITY, UNKNOWN_VALUE, true, true));
- EXPECT_EQ(std::string("bad locality ") +
+ EXPECT_EQ("bad locality "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, LOCALITY, UNKNOWN_VALUE, true, false));
- EXPECT_EQ(std::string("bad locality ") +
+ EXPECT_EQ("bad locality "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, LOCALITY, UNKNOWN_VALUE, false, false));
- EXPECT_EQ(std::string("bad locality ") +
+ EXPECT_EQ("bad locality "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, LOCALITY, UNKNOWN_VALUE, false, true));
- EXPECT_EQ(std::string("bad dependent locality ") +
+ EXPECT_EQ("bad dependent locality "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, DEPENDENT_LOCALITY, UNKNOWN_VALUE, true, true));
- EXPECT_EQ(std::string("bad dependent locality ") +
+ EXPECT_EQ("bad dependent locality "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, DEPENDENT_LOCALITY, UNKNOWN_VALUE, true, false));
- EXPECT_EQ(std::string("bad dependent locality ") +
+ EXPECT_EQ("bad dependent locality "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, DEPENDENT_LOCALITY, UNKNOWN_VALUE, false, false));
- EXPECT_EQ(std::string("bad dependent locality ") +
+ EXPECT_EQ("bad dependent locality "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, DEPENDENT_LOCALITY, UNKNOWN_VALUE, false, true));
- EXPECT_EQ(std::string("bad sorting code ") +
+ EXPECT_EQ("bad sorting code "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, SORTING_CODE, UNKNOWN_VALUE, true, true));
- EXPECT_EQ(std::string("bad sorting code ") +
+ EXPECT_EQ("bad sorting code "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, SORTING_CODE, UNKNOWN_VALUE, true, false));
- EXPECT_EQ(std::string("bad sorting code ") +
+ EXPECT_EQ("bad sorting code "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, SORTING_CODE, UNKNOWN_VALUE, false, false));
- EXPECT_EQ(std::string("bad sorting code ") +
+ EXPECT_EQ("bad sorting code "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, SORTING_CODE, UNKNOWN_VALUE, false, true));
- EXPECT_EQ(std::string("bad address line 1 ") +
+ EXPECT_EQ("bad address line 1 "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, STREET_ADDRESS, UNKNOWN_VALUE, true, true));
- EXPECT_EQ(std::string("bad address line 1 ") +
+ EXPECT_EQ("bad address line 1 "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, STREET_ADDRESS, UNKNOWN_VALUE, true, false));
- EXPECT_EQ(std::string("bad address line 1 ") +
+ EXPECT_EQ("bad address line 1 "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, STREET_ADDRESS, UNKNOWN_VALUE, false, false));
- EXPECT_EQ(std::string("bad address line 1 ") +
+ EXPECT_EQ("bad address line 1 "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, STREET_ADDRESS, UNKNOWN_VALUE, false, true));
- EXPECT_EQ(std::string("bad recipient ") +
+ EXPECT_EQ("bad recipient "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, RECIPIENT, UNKNOWN_VALUE, true, true));
- EXPECT_EQ(std::string("bad recipient ") +
+ EXPECT_EQ("bad recipient "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, RECIPIENT, UNKNOWN_VALUE, true, false));
- EXPECT_EQ(std::string("bad recipient ") +
+ EXPECT_EQ("bad recipient "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, RECIPIENT, UNKNOWN_VALUE, false, false));
- EXPECT_EQ(std::string("bad recipient ") +
+ EXPECT_EQ("bad recipient "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, RECIPIENT, UNKNOWN_VALUE, false, true));
@@ -325,14 +325,14 @@ TEST(LocalizationGetErrorMessageTest, InvalidFormatPostalCode) {
Localization localization;
AddressData address;
address.region_code = "CH";
- EXPECT_EQ(std::string("This postal code format is not recognized. Example ") +
- "of a valid postal code: 2544." +
- " Don't know your postal code? Find it out" +
- " <a href=\"http://www.post.ch/db/owa/pv_plz_pack/pr_main\">" +
+ EXPECT_EQ("This postal code format is not recognized. Example "
+ "of a valid postal code: 2544."
+ " Don't know your postal code? Find it out"
+ " <a href=\"http://www.post.ch/db/owa/pv_plz_pack/pr_main\">"
"here</a>.",
localization.GetErrorMessage(address, POSTAL_CODE,
INVALID_FORMAT, true, true));
- EXPECT_EQ(std::string("This postal code format is not recognized. Example ") +
+ EXPECT_EQ("This postal code format is not recognized. Example "
"of a valid postal code: 2544.",
localization.GetErrorMessage(address, POSTAL_CODE,
INVALID_FORMAT, true, false));
@@ -348,14 +348,14 @@ TEST(LocalizationGetErrorMessageTest, InvalidFormatZipCode) {
Localization localization;
AddressData address;
address.region_code = "US";
- EXPECT_EQ(std::string("This ZIP code format is not recognized. Example of ") +
- "a valid ZIP code: 95014." +
- " Don't know your ZIP code? Find it out" +
- " <a href=\"https://tools.usps.com/go/ZipLookupAction!" +
+ EXPECT_EQ("This ZIP code format is not recognized. Example of "
+ "a valid ZIP code: 95014."
+ " Don't know your ZIP code? Find it out"
+ " <a href=\"https://tools.usps.com/go/ZipLookupAction!"
"input.action\">here</a>.",
localization.GetErrorMessage(address, POSTAL_CODE,
INVALID_FORMAT, true, true));
- EXPECT_EQ(std::string("This ZIP code format is not recognized. Example of ") +
+ EXPECT_EQ("This ZIP code format is not recognized. Example of "
"a valid ZIP code: 95014.",
localization.GetErrorMessage(address, POSTAL_CODE,
INVALID_FORMAT, true, false));
@@ -371,25 +371,25 @@ TEST(LocalizationGetErrorMessageTest, MismatchingValuePostalCode) {
Localization localization;
AddressData address;
address.region_code = "CH";
- EXPECT_EQ(std::string("This postal code does not appear to match the rest ") +
- "of this address." +
- " Don't know your postal code? Find it out" +
- " <a href=\"http://www.post.ch/db/owa/pv_plz_pack/pr_main\">" +
+ EXPECT_EQ("This postal code does not appear to match the rest "
+ "of this address."
+ " Don't know your postal code? Find it out"
+ " <a href=\"http://www.post.ch/db/owa/pv_plz_pack/pr_main\">"
"here</a>.",
localization.GetErrorMessage(address, POSTAL_CODE,
MISMATCHING_VALUE, true, true));
- EXPECT_EQ(std::string("This postal code does not appear to match the rest ") +
+ EXPECT_EQ("This postal code does not appear to match the rest "
"of this address.",
localization.GetErrorMessage(address, POSTAL_CODE,
MISMATCHING_VALUE, true, false));
- EXPECT_EQ(std::string("This postal code does not appear to match the rest ") +
+ EXPECT_EQ("This postal code does not appear to match the rest "
"of this address.",
localization.GetErrorMessage(address, POSTAL_CODE,
MISMATCHING_VALUE, false, false));
- EXPECT_EQ(std::string("This postal code does not appear to match the rest ") +
- "of this address." +
- " Don't know your postal code? Find it out" +
- " <a href=\"http://www.post.ch/db/owa/pv_plz_pack/pr_main\">" +
+ EXPECT_EQ("This postal code does not appear to match the rest "
+ "of this address."
+ " Don't know your postal code? Find it out"
+ " <a href=\"http://www.post.ch/db/owa/pv_plz_pack/pr_main\">"
"here</a>.",
localization.GetErrorMessage(address, POSTAL_CODE,
MISMATCHING_VALUE, false, true));
@@ -399,25 +399,25 @@ TEST(LocalizationGetErrorMessageTest, MismatchingValueZipCode) {
Localization localization;
AddressData address;
address.region_code = "US";
- EXPECT_EQ(std::string("This ZIP code does not appear to match the rest of ") +
- "this address." +
- " Don't know your ZIP code? Find it out" +
- " <a href=\"https://tools.usps.com/go/ZipLookupAction!" +
+ EXPECT_EQ("This ZIP code does not appear to match the rest of "
+ "this address."
+ " Don't know your ZIP code? Find it out"
+ " <a href=\"https://tools.usps.com/go/ZipLookupAction!"
"input.action\">here</a>.",
localization.GetErrorMessage(address, POSTAL_CODE,
MISMATCHING_VALUE, true, true));
- EXPECT_EQ(std::string("This ZIP code does not appear to match the rest of ") +
+ EXPECT_EQ("This ZIP code does not appear to match the rest of "
"this address.",
localization.GetErrorMessage(address, POSTAL_CODE,
MISMATCHING_VALUE, true, false));
- EXPECT_EQ(std::string("This ZIP code does not appear to match the rest of ") +
+ EXPECT_EQ("This ZIP code does not appear to match the rest of "
"this address.",
localization.GetErrorMessage(address, POSTAL_CODE,
MISMATCHING_VALUE, false, false));
- EXPECT_EQ(std::string("This ZIP code does not appear to match the rest of ") +
- "this address." +
- " Don't know your ZIP code? Find it out" +
- " <a href=\"https://tools.usps.com/go/ZipLookupAction!" +
+ EXPECT_EQ("This ZIP code does not appear to match the rest of "
+ "this address."
+ " Don't know your ZIP code? Find it out"
+ " <a href=\"https://tools.usps.com/go/ZipLookupAction!"
"input.action\">here</a>.",
localization.GetErrorMessage(address, POSTAL_CODE,
MISMATCHING_VALUE, false, true));
@@ -437,23 +437,23 @@ TEST(LocalizationGetErrorMessageTest, UsesPOBoxOtherFields) {
other_fields.push_back(RECIPIENT);
for (std::vector<AddressField>::iterator it = other_fields.begin();
it != other_fields.end(); it++) {
- EXPECT_EQ(std::string("This address line appears to contain a post ") +
- "office box. Please use a street" +
+ EXPECT_EQ("This address line appears to contain a post "
+ "office box. Please use a street"
" or building address.",
localization.GetErrorMessage(
address, *it, USES_P_O_BOX, true, true));
- EXPECT_EQ(std::string("This address line appears to contain a post ") +
- "office box. Please use a street" +
+ EXPECT_EQ("This address line appears to contain a post "
+ "office box. Please use a street"
" or building address.",
localization.GetErrorMessage(
address, *it, USES_P_O_BOX, true, false));
- EXPECT_EQ(std::string("This address line appears to contain a post ") +
- "office box. Please use a street" +
+ EXPECT_EQ("This address line appears to contain a post "
+ "office box. Please use a street"
" or building address.",
localization.GetErrorMessage(
address, *it, USES_P_O_BOX, false, false));
- EXPECT_EQ(std::string("This address line appears to contain a post ") +
- "office box. Please use a street" +
+ EXPECT_EQ("This address line appears to contain a post "
+ "office box. Please use a street"
" or building address.",
localization.GetErrorMessage(
address, *it, USES_P_O_BOX, false, true));
diff --git a/cpp/test/null_storage_test.cc b/cpp/test/null_storage_test.cc
index 82ad0f5..8284554 100644
--- a/cpp/test/null_storage_test.cc
+++ b/cpp/test/null_storage_test.cc
@@ -26,24 +26,23 @@
namespace {
+using i18n::addressinput::BuildCallback;
using i18n::addressinput::NullStorage;
using i18n::addressinput::scoped_ptr;
using i18n::addressinput::Storage;
class NullStorageTest : public testing::Test {
protected:
- NullStorageTest() {}
- virtual ~NullStorageTest() {}
+ NullStorageTest()
+ : data_ready_(BuildCallback(this, &NullStorageTest::OnDataReady)) {}
- Storage::Callback* BuildCallback() {
- return i18n::addressinput::BuildCallback(
- this, &NullStorageTest::OnDataReady);
- }
+ virtual ~NullStorageTest() {}
NullStorage storage_;
bool success_;
std::string key_;
std::string data_;
+ const scoped_ptr<const Storage::Callback> data_ready_;
static const char kKey[];
@@ -70,8 +69,7 @@ TEST_F(NullStorageTest, Put) {
}
TEST_F(NullStorageTest, Get) {
- const scoped_ptr<const Storage::Callback> callback(BuildCallback());
- storage_.Get(kKey, *callback);
+ storage_.Get(kKey, *data_ready_);
EXPECT_FALSE(success_);
EXPECT_EQ(kKey, key_);
EXPECT_TRUE(data_.empty());
diff --git a/cpp/test/ondemand_supply_task_test.cc b/cpp/test/ondemand_supply_task_test.cc
index 84b2f65..64f55d0 100644
--- a/cpp/test/ondemand_supply_task_test.cc
+++ b/cpp/test/ondemand_supply_task_test.cc
@@ -67,13 +67,9 @@ class OndemandSupplyTaskTest : public testing::Test {
}
}
- void Queue(const std::string& key) {
- task_->Queue(key);
- }
+ void Queue(const std::string& key) { task_->Queue(key); }
- void Retrieve() {
- task_->Retrieve(*retriever_);
- }
+ void Retrieve() { task_->Retrieve(*retriever_); }
bool success_; // Expected status from MockDownloader.
LookupKey lookup_key_; // Stub.
diff --git a/cpp/test/region_data_builder_test.cc b/cpp/test/region_data_builder_test.cc
index a042689..b8e0ddd 100644
--- a/cpp/test/region_data_builder_test.cc
+++ b/cpp/test/region_data_builder_test.cc
@@ -108,7 +108,9 @@ TEST_F(RegionDataBuilderTest,
const RegionData& tree = builder_.Build("KR", "ko-Latn", &best_language_);
EXPECT_EQ("ko-Latn", best_language_);
ASSERT_FALSE(tree.sub_regions().empty());
- EXPECT_EQ("강원도", tree.sub_regions().front()->key());
+ EXPECT_EQ(
+ "\xEA\xB0\x95\xEC\x9B\x90\xEB\x8F\x84", /* "강원도" */
+ tree.sub_regions().front()->key());
EXPECT_EQ("Gangwon", tree.sub_regions().front()->name());
}
@@ -117,8 +119,12 @@ TEST_F(RegionDataBuilderTest, KrWithKoKrLanguageHasKoreanKeysAndNames) {
const RegionData& tree = builder_.Build("KR", "ko-KR", &best_language_);
EXPECT_EQ("ko", best_language_);
ASSERT_FALSE(tree.sub_regions().empty());
- EXPECT_EQ("강원도", tree.sub_regions().front()->key());
- EXPECT_EQ("강원", tree.sub_regions().front()->name());
+ EXPECT_EQ(
+ "\xEA\xB0\x95\xEC\x9B\x90\xEB\x8F\x84", /* "강원도" */
+ tree.sub_regions().front()->key());
+ EXPECT_EQ(
+ "\xEA\xB0\x95\xEC\x9B\x90", /* "강원" */
+ tree.sub_regions().front()->name());
}
} // namespace
diff --git a/cpp/test/retriever_test.cc b/cpp/test/retriever_test.cc
index 54a752b..978e9f0 100644
--- a/cpp/test/retriever_test.cc
+++ b/cpp/test/retriever_test.cc
@@ -34,6 +34,7 @@
namespace {
+using i18n::addressinput::BuildCallback;
using i18n::addressinput::FakeDownloader;
using i18n::addressinput::MockDownloader;
using i18n::addressinput::NullStorage;
@@ -63,19 +64,16 @@ class RetrieverTest : public testing::Test {
new NullStorage),
success_(false),
key_(),
- data_() {}
+ data_(),
+ data_ready_(BuildCallback(this, &RetrieverTest::OnDataReady)) {}
virtual ~RetrieverTest() {}
- Retriever::Callback* BuildCallback() {
- return i18n::addressinput::BuildCallback(
- this, &RetrieverTest::OnDataReady);
- }
-
Retriever retriever_;
bool success_;
std::string key_;
std::string data_;
+ const scoped_ptr<const Retriever::Callback> data_ready_;
private:
void OnDataReady(bool success,
@@ -90,8 +88,7 @@ class RetrieverTest : public testing::Test {
};
TEST_F(RetrieverTest, RetrieveData) {
- const scoped_ptr<const Retriever::Callback> callback(BuildCallback());
- retriever_.Retrieve(kKey, *callback);
+ retriever_.Retrieve(kKey, *data_ready_);
EXPECT_TRUE(success_);
EXPECT_EQ(kKey, key_);
@@ -100,11 +97,8 @@ TEST_F(RetrieverTest, RetrieveData) {
}
TEST_F(RetrieverTest, ReadDataFromStorage) {
- const scoped_ptr<const Retriever::Callback> callback1(BuildCallback());
- retriever_.Retrieve(kKey, *callback1);
-
- const scoped_ptr<const Retriever::Callback> callback2(BuildCallback());
- retriever_.Retrieve(kKey, *callback2);
+ retriever_.Retrieve(kKey, *data_ready_);
+ retriever_.Retrieve(kKey, *data_ready_);
EXPECT_TRUE(success_);
EXPECT_EQ(kKey, key_);
@@ -115,8 +109,7 @@ TEST_F(RetrieverTest, ReadDataFromStorage) {
TEST_F(RetrieverTest, MissingKeyReturnsEmptyData) {
static const char kMissingKey[] = "junk";
- const scoped_ptr<const Retriever::Callback> callback(BuildCallback());
- retriever_.Retrieve(kMissingKey, *callback);
+ retriever_.Retrieve(kMissingKey, *data_ready_);
EXPECT_TRUE(success_);
EXPECT_EQ(kMissingKey, key_);
@@ -129,8 +122,7 @@ TEST_F(RetrieverTest, FaultyDownloader) {
new MockDownloader,
new NullStorage);
- const scoped_ptr<const Retriever::Callback> callback(BuildCallback());
- bad_retriever.Retrieve(kKey, *callback);
+ bad_retriever.Retrieve(kKey, *data_ready_);
EXPECT_FALSE(success_);
EXPECT_EQ(kKey, key_);
@@ -167,8 +159,7 @@ TEST_F(RetrieverTest, UseStaleDataWhenDownloaderFails) {
Retriever resilient_retriever(
MockDownloader::kMockDataUrl, new MockDownloader, stale_storage);
- const scoped_ptr<const Retriever::Callback> callback(BuildCallback());
- resilient_retriever.Retrieve(kKey, *callback);
+ resilient_retriever.Retrieve(kKey, *data_ready_);
EXPECT_TRUE(success_);
EXPECT_EQ(kKey, key_);
@@ -182,8 +173,7 @@ TEST_F(RetrieverTest, DoNotUseStaleDataWhenDownloaderSucceeds) {
Retriever resilient_retriever(
FakeDownloader::kFakeDataUrl, new FakeDownloader, stale_storage);
- const scoped_ptr<const Retriever::Callback> callback(BuildCallback());
- resilient_retriever.Retrieve(kKey, *callback);
+ resilient_retriever.Retrieve(kKey, *data_ready_);
EXPECT_TRUE(success_);
EXPECT_EQ(kKey, key_);
diff --git a/cpp/test/rule_retriever_test.cc b/cpp/test/rule_retriever_test.cc
index bc7fdbf..7442bb4 100644
--- a/cpp/test/rule_retriever_test.cc
+++ b/cpp/test/rule_retriever_test.cc
@@ -29,6 +29,7 @@
namespace {
+using i18n::addressinput::BuildCallback;
using i18n::addressinput::FakeDownloader;
using i18n::addressinput::NullStorage;
using i18n::addressinput::Retriever;
@@ -45,19 +46,16 @@ class RuleRetrieverTest : public testing::Test {
new NullStorage)),
success_(false),
key_(),
- rule_() {}
+ rule_(),
+ rule_ready_(BuildCallback(this, &RuleRetrieverTest::OnRuleReady)) {}
virtual ~RuleRetrieverTest() {}
- RuleRetriever::Callback* BuildCallback() {
- return i18n::addressinput::BuildCallback(
- this, &RuleRetrieverTest::OnRuleReady);
- }
-
RuleRetriever rule_retriever_;
bool success_;
std::string key_;
Rule rule_;
+ const scoped_ptr<const RuleRetriever::Callback> rule_ready_;
private:
void OnRuleReady(bool success,
@@ -74,8 +72,7 @@ class RuleRetrieverTest : public testing::Test {
TEST_F(RuleRetrieverTest, ExistingRule) {
static const char kExistingKey[] = "data/CA";
- const scoped_ptr<const RuleRetriever::Callback> callback(BuildCallback());
- rule_retriever_.RetrieveRule(kExistingKey, *callback);
+ rule_retriever_.RetrieveRule(kExistingKey, *rule_ready_);
EXPECT_TRUE(success_);
EXPECT_EQ(kExistingKey, key_);
@@ -85,8 +82,7 @@ TEST_F(RuleRetrieverTest, ExistingRule) {
TEST_F(RuleRetrieverTest, MissingRule) {
static const char kMissingKey[] = "junk";
- const scoped_ptr<const RuleRetriever::Callback> callback(BuildCallback());
- rule_retriever_.RetrieveRule(kMissingKey, *callback);
+ rule_retriever_.RetrieveRule(kMissingKey, *rule_ready_);
EXPECT_TRUE(success_); // The server returns "{}" for bad keys.
EXPECT_EQ(kMissingKey, key_);
diff --git a/cpp/test/supplier_test.cc b/cpp/test/supplier_test.cc
index c51c5f7..f1e2704 100644
--- a/cpp/test/supplier_test.cc
+++ b/cpp/test/supplier_test.cc
@@ -112,9 +112,7 @@ class PreloadSupplierWrapper : public SupplierWrapper {
new NullStorage),
loaded_(BuildCallback(this, &PreloadSupplierWrapper::Loaded)) {}
- void Loaded(bool success, const std::string&, int) {
- ASSERT_TRUE(success);
- }
+ void Loaded(bool success, const std::string&, int) { ASSERT_TRUE(success); }
PreloadSupplier preload_supplier_;
const scoped_ptr<const PreloadSupplier::Callback> loaded_;
diff --git a/cpp/test/util/json_test.cc b/cpp/test/util/json_test.cc
index 46d26c5..ff23ea6 100644
--- a/cpp/test/util/json_test.cc
+++ b/cpp/test/util/json_test.cc
@@ -74,10 +74,10 @@ TEST(JsonTest, EmptyValueIsValid) {
TEST(JsonTest, Utf8EncodingIsValid) {
Json json;
- ASSERT_TRUE(json.ParseObject("{\"key\": \"Ü\"}"));
+ ASSERT_TRUE(json.ParseObject("{\"key\": \"\xC3\x9C\"}")); /* "Ü" */
std::string value;
EXPECT_TRUE(json.GetStringValueForKey("key", &value));
- EXPECT_EQ("Ü", value);
+ EXPECT_EQ("\xC3\x9C", value); /* "Ü" */
}
TEST(JsonTest, InvalidUtf8IsNotValid) {
diff --git a/cpp/test/util/string_compare_test.cc b/cpp/test/util/string_compare_test.cc
index 8f8d4d5..cad36c1 100644
--- a/cpp/test/util/string_compare_test.cc
+++ b/cpp/test/util/string_compare_test.cc
@@ -63,15 +63,39 @@ TEST_P(StringCompareTest, CorrectLess) {
INSTANTIATE_TEST_CASE_P(
Comparisons, StringCompareTest,
- testing::Values(TestCase("foo", "foo", true, false),
- TestCase("foo", "FOO", true, false),
- TestCase("bar", "foo", false, true),
- TestCase("강원도", "강원도", true, false),
- TestCase("강원도", "대구광역시", false, true),
- TestCase("ZÜRICH", "zürich", true, false),
- TestCase("абв", "где", false, true),
- TestCase("абв", "ГДЕ", false, true),
- TestCase("где", "абв", false, false),
- TestCase("где", "АБВ", false, false)));
+ testing::Values(
+ TestCase("foo", "foo", true, false),
+ TestCase("foo", "FOO", true, false),
+ TestCase("bar", "foo", false, true),
+ TestCase(
+ "\xEA\xB0\x95\xEC\x9B\x90\xEB\x8F\x84", /* "강원도" */
+ "\xEA\xB0\x95\xEC\x9B\x90\xEB\x8F\x84", /* "강원도" */
+ true, false),
+ TestCase(
+ /* "강원도" */
+ "\xEA\xB0\x95\xEC\x9B\x90\xEB\x8F\x84",
+ /* "대구광역시" */
+ "\xEB\x8C\x80\xEA\xB5\xAC\xEA\xB4\x91\xEC\x97\xAD\xEC\x8B\x9C",
+ false, true),
+ TestCase(
+ "Z\xC3\x9CRICH", /* "ZÜRICH" */
+ "z\xC3\xBCrich", /* "zürich" */
+ true, false),
+ TestCase(
+ "\xD0\xB0\xD0\xB1\xD0\xB2", /* "абв" */
+ "\xD0\xB3\xD0\xB4\xD0\xB5", /* "где" */
+ false, true),
+ TestCase(
+ "\xD0\xB0\xD0\xB1\xD0\xB2", /* "абв" */
+ "\xD0\x93\xD0\x94\xD0\x95", /* "ГДЕ" */
+ false, true),
+ TestCase(
+ "\xD0\xB3\xD0\xB4\xD0\xB5", /* "где" */
+ "\xD0\xB0\xD0\xB1\xD0\xB2", /* "абв" */
+ false, false),
+ TestCase(
+ "\xD0\xB3\xD0\xB4\xD0\xB5", /* "где" */
+ "\xD0\x90\xD0\x91\xD0\x92", /* "АБВ" */
+ false, false)));
} // namespace
diff --git a/cpp/test/validating_storage_test.cc b/cpp/test/validating_storage_test.cc
index 1efe60e..36f85d9 100644
--- a/cpp/test/validating_storage_test.cc
+++ b/cpp/test/validating_storage_test.cc
@@ -32,6 +32,7 @@
namespace {
+using i18n::addressinput::BuildCallback;
using i18n::addressinput::FakeStorage;
using i18n::addressinput::scoped_ptr;
using i18n::addressinput::Storage;
@@ -45,27 +46,24 @@ const char kStaleWrappedData[] = "timestamp=" OLD_TIMESTAMP "\n"
const char kEmptyData[] = "";
// Tests for ValidatingStorage object.
-class ValidatingStorageTest : public testing::Test {
+class ValidatingStorageTest : public testing::Test {
protected:
ValidatingStorageTest()
: wrapped_storage_(new FakeStorage),
storage_(wrapped_storage_),
success_(false),
key_(),
- data_() {}
+ data_(),
+ data_ready_(BuildCallback(this, &ValidatingStorageTest::OnDataReady)) {}
virtual ~ValidatingStorageTest() {}
- ValidatingStorage::Callback* BuildCallback() {
- return i18n::addressinput::BuildCallback(
- this, &ValidatingStorageTest::OnDataReady);
- }
-
Storage* const wrapped_storage_; // Owned by |storage_|.
ValidatingStorage storage_;
bool success_;
std::string key_;
std::string data_;
+ const scoped_ptr<const ValidatingStorage::Callback> data_ready_;
private:
void OnDataReady(bool success, const std::string& key, std::string* data) {
@@ -83,9 +81,7 @@ class ValidatingStorageTest : public testing::Test {
TEST_F(ValidatingStorageTest, GoodData) {
storage_.Put(kKey, new std::string(kValidatedData));
-
- const scoped_ptr<const ValidatingStorage::Callback> callback(BuildCallback());
- storage_.Get(kKey, *callback);
+ storage_.Get(kKey, *data_ready_);
EXPECT_TRUE(success_);
EXPECT_EQ(kKey, key_);
@@ -94,9 +90,7 @@ TEST_F(ValidatingStorageTest, GoodData) {
TEST_F(ValidatingStorageTest, EmptyData) {
storage_.Put(kKey, new std::string(kEmptyData));
-
- const scoped_ptr<const ValidatingStorage::Callback> callback(BuildCallback());
- storage_.Get(kKey, *callback);
+ storage_.Get(kKey, *data_ready_);
EXPECT_TRUE(success_);
EXPECT_EQ(kKey, key_);
@@ -104,8 +98,7 @@ TEST_F(ValidatingStorageTest, EmptyData) {
}
TEST_F(ValidatingStorageTest, MissingKey) {
- const scoped_ptr<const ValidatingStorage::Callback> callback(BuildCallback());
- storage_.Get(kKey, *callback);
+ storage_.Get(kKey, *data_ready_);
EXPECT_FALSE(success_);
EXPECT_EQ(kKey, key_);
@@ -115,9 +108,7 @@ TEST_F(ValidatingStorageTest, MissingKey) {
TEST_F(ValidatingStorageTest, GarbageData) {
storage_.Put(kKey, new std::string(kValidatedData));
wrapped_storage_->Put(kKey, new std::string("garbage"));
-
- const scoped_ptr<const ValidatingStorage::Callback> callback(BuildCallback());
- storage_.Get(kKey, *callback);
+ storage_.Get(kKey, *data_ready_);
EXPECT_FALSE(success_);
EXPECT_EQ(kKey, key_);
@@ -127,9 +118,7 @@ TEST_F(ValidatingStorageTest, GarbageData) {
TEST_F(ValidatingStorageTest, StaleData) {
storage_.Put(kKey, new std::string(kValidatedData));
wrapped_storage_->Put(kKey, new std::string(kStaleWrappedData));
-
- const scoped_ptr<const ValidatingStorage::Callback> callback(BuildCallback());
- storage_.Get(kKey, *callback);
+ storage_.Get(kKey, *data_ready_);
EXPECT_FALSE(success_);
EXPECT_EQ(kKey, key_);