| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 241 |
| 242 std::string test_serialization; | 242 std::string test_serialization; |
| 243 JSONStringValueSerializer mutable_serializer(&test_serialization); | 243 JSONStringValueSerializer mutable_serializer(&test_serialization); |
| 244 ASSERT_TRUE(mutable_serializer.Serialize(*root_dict)); | 244 ASSERT_TRUE(mutable_serializer.Serialize(*root_dict)); |
| 245 ASSERT_EQ(kOriginalSerialization, test_serialization); | 245 ASSERT_EQ(kOriginalSerialization, test_serialization); |
| 246 | 246 |
| 247 mutable_serializer.set_pretty_print(true); | 247 mutable_serializer.set_pretty_print(true); |
| 248 ASSERT_TRUE(mutable_serializer.Serialize(*root_dict)); | 248 ASSERT_TRUE(mutable_serializer.Serialize(*root_dict)); |
| 249 // JSON output uses a different newline style on Windows than on other | 249 // JSON output uses a different newline style on Windows than on other |
| 250 // platforms. | 250 // platforms. |
| 251 #if defined(OS_WIN) | |
| 252 #define JSON_NEWLINE "\r\n" | |
| 253 #else | |
| 254 #define JSON_NEWLINE "\n" | 251 #define JSON_NEWLINE "\n" |
| 255 #endif | |
| 256 const std::string pretty_serialization = | 252 const std::string pretty_serialization = |
| 257 "{" JSON_NEWLINE | 253 "{" JSON_NEWLINE |
| 258 " \"bool\": true," JSON_NEWLINE | 254 " \"bool\": true," JSON_NEWLINE |
| 259 " \"double\": 3.14," JSON_NEWLINE | 255 " \"double\": 3.14," JSON_NEWLINE |
| 260 " \"int\": 42," JSON_NEWLINE | 256 " \"int\": 42," JSON_NEWLINE |
| 261 " \"list\": [ 1, 2 ]," JSON_NEWLINE | 257 " \"list\": [ 1, 2 ]," JSON_NEWLINE |
| 262 " \"null\": null" JSON_NEWLINE | 258 " \"null\": null" JSON_NEWLINE |
| 263 "}" JSON_NEWLINE; | 259 "}" JSON_NEWLINE; |
| 264 #undef JSON_NEWLINE | 260 #undef JSON_NEWLINE |
| 265 ASSERT_EQ(pretty_serialization, test_serialization); | 261 ASSERT_EQ(pretty_serialization, test_serialization); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 ASSERT_TRUE(PathExists(source_file_path)); | 484 ASSERT_TRUE(PathExists(source_file_path)); |
| 489 JSONFileValueDeserializer deserializer(source_file_path); | 485 JSONFileValueDeserializer deserializer(source_file_path); |
| 490 scoped_ptr<Value> root; | 486 scoped_ptr<Value> root; |
| 491 root.reset(deserializer.Deserialize(NULL, NULL)); | 487 root.reset(deserializer.Deserialize(NULL, NULL)); |
| 492 ASSERT_TRUE(root.get()); | 488 ASSERT_TRUE(root.get()); |
| 493 } | 489 } |
| 494 | 490 |
| 495 } // namespace | 491 } // namespace |
| 496 | 492 |
| 497 } // namespace base | 493 } // namespace base |
| OLD | NEW |