| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/json/json_writer.h" | 5 #include "base/json/json_writer.h" |
| 6 #include "base/values.h" | 6 #include "base/values.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace base { | 9 namespace base { |
| 10 | 10 |
| 11 TEST(JSONWriterTest, Writing) { | 11 TEST(JSONWriterTest, Writing) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 Value::CreateIntegerValue(1)); | 86 Value::CreateIntegerValue(1)); |
| 87 period_dict.SetWithoutPathExpansion("d.e.f", period_dict2); | 87 period_dict.SetWithoutPathExpansion("d.e.f", period_dict2); |
| 88 JSONWriter::Write(&period_dict, false, &output_js); | 88 JSONWriter::Write(&period_dict, false, &output_js); |
| 89 ASSERT_EQ("{\"a.b\":3,\"c\":2,\"d.e.f\":{\"g.h.i.j\":1}}", output_js); | 89 ASSERT_EQ("{\"a.b\":3,\"c\":2,\"d.e.f\":{\"g.h.i.j\":1}}", output_js); |
| 90 | 90 |
| 91 DictionaryValue period_dict3; | 91 DictionaryValue period_dict3; |
| 92 period_dict3.Set("a.b", Value::CreateIntegerValue(2)); | 92 period_dict3.Set("a.b", Value::CreateIntegerValue(2)); |
| 93 period_dict3.SetWithoutPathExpansion("a.b", Value::CreateIntegerValue(1)); | 93 period_dict3.SetWithoutPathExpansion("a.b", Value::CreateIntegerValue(1)); |
| 94 JSONWriter::Write(&period_dict3, false, &output_js); | 94 JSONWriter::Write(&period_dict3, false, &output_js); |
| 95 ASSERT_EQ("{\"a\":{\"b\":2},\"a.b\":1}", output_js); | 95 ASSERT_EQ("{\"a\":{\"b\":2},\"a.b\":1}", output_js); |
| 96 | |
| 97 // Test ignoring binary values. | |
| 98 root = BinaryValue::CreateWithCopiedBuffer("asdf", 4); | |
| 99 JSONWriter::WriteWithOptions(root, false, | |
| 100 JSONWriter::OPTIONS_OMIT_BINARY_VALUES, | |
| 101 &output_js); | |
| 102 ASSERT_TRUE(output_js.empty()); | |
| 103 delete root; | |
| 104 | |
| 105 ListValue binary_list; | |
| 106 binary_list.Append(Value::CreateIntegerValue(5)); | |
| 107 binary_list.Append(BinaryValue::CreateWithCopiedBuffer("asdf", 4)); | |
| 108 binary_list.Append(Value::CreateIntegerValue(2)); | |
| 109 JSONWriter::WriteWithOptions(&binary_list, false, | |
| 110 JSONWriter::OPTIONS_OMIT_BINARY_VALUES, | |
| 111 &output_js); | |
| 112 ASSERT_EQ("[5,2]", output_js); | |
| 113 | |
| 114 DictionaryValue binary_dict; | |
| 115 binary_dict.Set("a", Value::CreateIntegerValue(5)); | |
| 116 binary_dict.Set("b", BinaryValue::CreateWithCopiedBuffer("asdf", 4)); | |
| 117 binary_dict.Set("c", Value::CreateIntegerValue(2)); | |
| 118 JSONWriter::WriteWithOptions(&binary_dict, false, | |
| 119 JSONWriter::OPTIONS_OMIT_BINARY_VALUES, | |
| 120 &output_js); | |
| 121 ASSERT_EQ("{\"a\":5,\"c\":2}", output_js); | |
| 122 } | 96 } |
| 123 | 97 |
| 124 } // namespace base | 98 } // namespace base |
| OLD | NEW |