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

Side by Side Diff: base/json/json_value_serializer_unittest.cc

Issue 16950028: Move file_util::Delete to the base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/files/scoped_temp_dir_unittest.cc ('k') | base/memory/shared_memory_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_util.h" 7 #include "base/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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 temp_dir_.path().Append(FILE_PATH_LITERAL("test_output.js")); 418 temp_dir_.path().Append(FILE_PATH_LITERAL("test_output.js"));
419 419
420 ASSERT_FALSE(file_util::PathExists(written_file_path)); 420 ASSERT_FALSE(file_util::PathExists(written_file_path));
421 JSONFileValueSerializer serializer(written_file_path); 421 JSONFileValueSerializer serializer(written_file_path);
422 ASSERT_TRUE(serializer.Serialize(*root)); 422 ASSERT_TRUE(serializer.Serialize(*root));
423 ASSERT_TRUE(file_util::PathExists(written_file_path)); 423 ASSERT_TRUE(file_util::PathExists(written_file_path));
424 424
425 // Now compare file contents. 425 // Now compare file contents.
426 EXPECT_TRUE(file_util::TextContentsEqual(original_file_path, 426 EXPECT_TRUE(file_util::TextContentsEqual(original_file_path,
427 written_file_path)); 427 written_file_path));
428 EXPECT_TRUE(file_util::Delete(written_file_path, false)); 428 EXPECT_TRUE(base::Delete(written_file_path, false));
429 } 429 }
430 430
431 TEST_F(JSONFileValueSerializerTest, RoundtripNested) { 431 TEST_F(JSONFileValueSerializerTest, RoundtripNested) {
432 base::FilePath original_file_path; 432 base::FilePath original_file_path;
433 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &original_file_path)); 433 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &original_file_path));
434 original_file_path = original_file_path.Append( 434 original_file_path = original_file_path.Append(
435 FILE_PATH_LITERAL("serializer_nested_test.json")); 435 FILE_PATH_LITERAL("serializer_nested_test.json"));
436 436
437 ASSERT_TRUE(file_util::PathExists(original_file_path)); 437 ASSERT_TRUE(file_util::PathExists(original_file_path));
438 438
439 JSONFileValueSerializer deserializer(original_file_path); 439 JSONFileValueSerializer deserializer(original_file_path);
440 scoped_ptr<Value> root; 440 scoped_ptr<Value> root;
441 root.reset(deserializer.Deserialize(NULL, NULL)); 441 root.reset(deserializer.Deserialize(NULL, NULL));
442 ASSERT_TRUE(root.get()); 442 ASSERT_TRUE(root.get());
443 443
444 // Now try writing. 444 // Now try writing.
445 base::FilePath written_file_path = temp_dir_.path().Append( 445 base::FilePath written_file_path = temp_dir_.path().Append(
446 FILE_PATH_LITERAL("test_output.json")); 446 FILE_PATH_LITERAL("test_output.json"));
447 447
448 ASSERT_FALSE(file_util::PathExists(written_file_path)); 448 ASSERT_FALSE(file_util::PathExists(written_file_path));
449 JSONFileValueSerializer serializer(written_file_path); 449 JSONFileValueSerializer serializer(written_file_path);
450 ASSERT_TRUE(serializer.Serialize(*root)); 450 ASSERT_TRUE(serializer.Serialize(*root));
451 ASSERT_TRUE(file_util::PathExists(written_file_path)); 451 ASSERT_TRUE(file_util::PathExists(written_file_path));
452 452
453 // Now compare file contents. 453 // Now compare file contents.
454 EXPECT_TRUE(file_util::TextContentsEqual(original_file_path, 454 EXPECT_TRUE(file_util::TextContentsEqual(original_file_path,
455 written_file_path)); 455 written_file_path));
456 EXPECT_TRUE(file_util::Delete(written_file_path, false)); 456 EXPECT_TRUE(base::Delete(written_file_path, false));
457 } 457 }
458 458
459 TEST_F(JSONFileValueSerializerTest, NoWhitespace) { 459 TEST_F(JSONFileValueSerializerTest, NoWhitespace) {
460 base::FilePath source_file_path; 460 base::FilePath source_file_path;
461 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &source_file_path)); 461 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &source_file_path));
462 source_file_path = source_file_path.Append( 462 source_file_path = source_file_path.Append(
463 FILE_PATH_LITERAL("serializer_test_nowhitespace.json")); 463 FILE_PATH_LITERAL("serializer_test_nowhitespace.json"));
464 ASSERT_TRUE(file_util::PathExists(source_file_path)); 464 ASSERT_TRUE(file_util::PathExists(source_file_path));
465 JSONFileValueSerializer serializer(source_file_path); 465 JSONFileValueSerializer serializer(source_file_path);
466 scoped_ptr<Value> root; 466 scoped_ptr<Value> root;
467 root.reset(serializer.Deserialize(NULL, NULL)); 467 root.reset(serializer.Deserialize(NULL, NULL));
468 ASSERT_TRUE(root.get()); 468 ASSERT_TRUE(root.get());
469 } 469 }
470 470
471 } // namespace 471 } // namespace
472 472
473 } // namespace base 473 } // namespace base
OLDNEW
« no previous file with comments | « base/files/scoped_temp_dir_unittest.cc ('k') | base/memory/shared_memory_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698