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

Unified Diff: base/json/json_value_serializer_unittest.cc

Issue 925783002: Split ValueSerializer into separate Serializer and Deserializer classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated as per review comment. Created 5 years, 10 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: base/json/json_value_serializer_unittest.cc
diff --git a/base/json/json_value_serializer_unittest.cc b/base/json/json_value_serializer_unittest.cc
index d2a84dea89622b60c5898a6f0d2c34c961ab2bf3..a422676251435d22713e21cfe34d4fd641dfbc28 100644
--- a/base/json/json_value_serializer_unittest.cc
+++ b/base/json/json_value_serializer_unittest.cc
@@ -89,7 +89,7 @@ void ValidateJsonList(const std::string& json) {
// Test proper JSON [de]serialization from string is working.
TEST(JSONValueSerializerTest, ReadProperJSONFromString) {
// Try to deserialize it through the serializer.
- JSONStringValueSerializer str_deserializer(kProperJSON);
+ JSONStringValueDeserializer str_deserializer(kProperJSON);
int error_code = 0;
std::string error_message;
@@ -107,7 +107,7 @@ TEST(JSONValueSerializerTest, ReadProperJSONFromStringPointer) {
// Try to deserialize a string pointer through the serializer. (This exercises
// a separate code path to passing a StringPiece.)
std::string proper_json(kProperJSON);
- JSONStringValueSerializer str_deserializer(&proper_json);
+ JSONStringValueDeserializer str_deserializer(proper_json);
int error_code = 0;
std::string error_message;
@@ -126,7 +126,7 @@ TEST(JSONValueSerializerTest, ReadProperJSONFromStringPiece) {
// kProperJSON.
base::StringPiece proper_json(kProperJSONPadded);
proper_json = proper_json.substr(5, proper_json.length() - 10);
- JSONStringValueSerializer str_deserializer(proper_json);
+ JSONStringValueDeserializer str_deserializer(proper_json);
int error_code = 0;
std::string error_message;
@@ -143,7 +143,7 @@ TEST(JSONValueSerializerTest, ReadProperJSONFromStringPiece) {
// the proper flag for that is set.
TEST(JSONValueSerializerTest, ReadJSONWithTrailingCommasFromString) {
// Try to deserialize it through the serializer.
- JSONStringValueSerializer str_deserializer(kProperJSONWithCommas);
+ JSONStringValueDeserializer str_deserializer(kProperJSONWithCommas);
int error_code = 0;
std::string error_message;
@@ -171,7 +171,7 @@ TEST(JSONValueSerializerTest, ReadProperJSONFromFile) {
WriteFile(temp_file, kProperJSON, strlen(kProperJSON)));
// Try to deserialize it through the serializer.
- JSONFileValueSerializer file_deserializer(temp_file);
+ JSONFileValueDeserializer file_deserializer(temp_file);
int error_code = 0;
std::string error_message;
@@ -196,7 +196,7 @@ TEST(JSONValueSerializerTest, ReadJSONWithCommasFromFile) {
strlen(kProperJSONWithCommas)));
// Try to deserialize it through the serializer.
- JSONFileValueSerializer file_deserializer(temp_file);
+ JSONFileValueDeserializer file_deserializer(temp_file);
// This must fail without the proper flag.
int error_code = 0;
std::string error_message;
@@ -217,8 +217,8 @@ TEST(JSONValueSerializerTest, ReadJSONWithCommasFromFile) {
TEST(JSONValueSerializerTest, Roundtrip) {
static const char kOriginalSerialization[] =
"{\"bool\":true,\"double\":3.14,\"int\":42,\"list\":[1,2],\"null\":null}";
- JSONStringValueSerializer serializer(kOriginalSerialization);
- scoped_ptr<Value> root(serializer.Deserialize(NULL, NULL));
+ JSONStringValueDeserializer deserializer(kOriginalSerialization);
+ scoped_ptr<Value> root(deserializer.Deserialize(NULL, NULL));
ASSERT_TRUE(root.get());
ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY));
@@ -241,10 +241,6 @@ TEST(JSONValueSerializerTest, Roundtrip) {
ASSERT_TRUE(root_dict->GetDouble("double", &double_value));
ASSERT_DOUBLE_EQ(3.14, double_value);
- // We shouldn't be able to write using this serializer, since it was
- // initialized with a const string.
- ASSERT_FALSE(serializer.Serialize(*root_dict));
-
std::string test_serialization;
JSONStringValueSerializer mutable_serializer(&test_serialization);
ASSERT_TRUE(mutable_serializer.Serialize(*root_dict));
@@ -331,7 +327,7 @@ TEST(JSONValueSerializerTest, UnicodeStrings) {
ASSERT_EQ(kExpected, actual);
// escaped ascii text -> json
- JSONStringValueSerializer deserializer(kExpected);
+ JSONStringValueDeserializer deserializer(kExpected);
scoped_ptr<Value> deserial_root(deserializer.Deserialize(NULL, NULL));
ASSERT_TRUE(deserial_root.get());
DictionaryValue* dict_root =
@@ -355,7 +351,7 @@ TEST(JSONValueSerializerTest, HexStrings) {
ASSERT_EQ(kExpected, actual);
// escaped ascii text -> json
- JSONStringValueSerializer deserializer(kExpected);
+ JSONStringValueDeserializer deserializer(kExpected);
scoped_ptr<Value> deserial_root(deserializer.Deserialize(NULL, NULL));
ASSERT_TRUE(deserial_root.get());
DictionaryValue* dict_root =
@@ -366,7 +362,7 @@ TEST(JSONValueSerializerTest, HexStrings) {
// Test converting escaped regular chars
static const char kEscapedChars[] = "{\"test\":\"\\u0067\\u006f\"}";
- JSONStringValueSerializer deserializer2(kEscapedChars);
+ JSONStringValueDeserializer deserializer2(kEscapedChars);
deserial_root.reset(deserializer2.Deserialize(NULL, NULL));
ASSERT_TRUE(deserial_root.get());
dict_root = static_cast<DictionaryValue*>(deserial_root.get());
@@ -380,12 +376,12 @@ TEST(JSONValueSerializerTest, AllowTrailingComma) {
static const char kTestWithCommas[] = "{\"key\": [true,],}";
static const char kTestNoCommas[] = "{\"key\": [true]}";
- JSONStringValueSerializer serializer(kTestWithCommas);
- serializer.set_allow_trailing_comma(true);
- JSONStringValueSerializer serializer_expected(kTestNoCommas);
- root.reset(serializer.Deserialize(NULL, NULL));
+ JSONStringValueDeserializer deserializer(kTestWithCommas);
+ deserializer.set_allow_trailing_comma(true);
+ JSONStringValueDeserializer deserializer_expected(kTestNoCommas);
+ root.reset(deserializer.Deserialize(NULL, NULL));
ASSERT_TRUE(root.get());
- root_expected.reset(serializer_expected.Deserialize(NULL, NULL));
+ root_expected.reset(deserializer_expected.Deserialize(NULL, NULL));
ASSERT_TRUE(root_expected.get());
ASSERT_TRUE(root->Equals(root_expected.get()));
}
@@ -435,7 +431,7 @@ TEST_F(JSONFileValueSerializerTest, Roundtrip) {
ASSERT_TRUE(PathExists(original_file_path));
- JSONFileValueSerializer deserializer(original_file_path);
+ JSONFileValueDeserializer deserializer(original_file_path);
scoped_ptr<Value> root;
root.reset(deserializer.Deserialize(NULL, NULL));
@@ -483,7 +479,7 @@ TEST_F(JSONFileValueSerializerTest, RoundtripNested) {
ASSERT_TRUE(PathExists(original_file_path));
- JSONFileValueSerializer deserializer(original_file_path);
+ JSONFileValueDeserializer deserializer(original_file_path);
scoped_ptr<Value> root;
root.reset(deserializer.Deserialize(NULL, NULL));
ASSERT_TRUE(root.get());
@@ -508,9 +504,9 @@ TEST_F(JSONFileValueSerializerTest, NoWhitespace) {
source_file_path = source_file_path.Append(
FILE_PATH_LITERAL("serializer_test_nowhitespace.json"));
ASSERT_TRUE(PathExists(source_file_path));
- JSONFileValueSerializer serializer(source_file_path);
+ JSONFileValueDeserializer deserializer(source_file_path);
scoped_ptr<Value> root;
- root.reset(serializer.Deserialize(NULL, NULL));
+ root.reset(deserializer.Deserialize(NULL, NULL));
ASSERT_TRUE(root.get());
}

Powered by Google App Engine
This is Rietveld 408576698