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

Side by Side Diff: base/file_util_unittest.cc

Issue 19724: Properly honor base::SharedMemory semantics for name="" to mean... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_util_posix.cc ('k') | base/file_util_win.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 std::wstring read_contents = ReadTextFile(FilePath(resolved_name)); 681 std::wstring read_contents = ReadTextFile(FilePath(resolved_name));
682 EXPECT_EQ(file_contents, read_contents); 682 EXPECT_EQ(file_contents, read_contents);
683 683
684 DeleteFile(target_file.value().c_str()); 684 DeleteFile(target_file.value().c_str());
685 DeleteFile(link_file.value().c_str()); 685 DeleteFile(link_file.value().c_str());
686 CoUninitialize(); 686 CoUninitialize();
687 } 687 }
688 #endif 688 #endif
689 689
690 TEST_F(FileUtilTest, CreateTemporaryFileNameTest) { 690 TEST_F(FileUtilTest, CreateTemporaryFileNameTest) {
691 std::wstring temp_file; 691 std::wstring temp_files[3];
692 ASSERT_TRUE(file_util::CreateTemporaryFileName(&temp_file)); 692 for (int i = 0; i < 3; i++) {
693 EXPECT_TRUE(file_util::PathExists(temp_file)); 693 ASSERT_TRUE(file_util::CreateTemporaryFileName(&(temp_files[i])));
694 EXPECT_TRUE(file_util::Delete(temp_file, false)); 694 EXPECT_TRUE(file_util::PathExists(temp_files[i]));
695 EXPECT_FALSE(file_util::DirectoryExists(temp_files[i]));
696 }
697 for (int i = 0; i < 3; i++)
698 EXPECT_FALSE(temp_files[i] == temp_files[(i+1)%3]);
699 for (int i = 0; i < 3; i++)
700 EXPECT_TRUE(file_util::Delete(temp_files[i], false));
701 }
702
703 TEST_F(FileUtilTest, CreateAndOpenTemporaryFileNameTest) {
704 FilePath names[3];
705 FILE *fps[3];
706 int i;
707
708 // Create; make sure they are open and exist.
709 for (i = 0; i < 3; ++i) {
710 fps[i] = file_util::CreateAndOpenTemporaryFile(&(names[i]));
711 ASSERT_TRUE(fps[i]);
712 EXPECT_TRUE(file_util::PathExists(names[i]));
713 }
714
715 // Make sure all names are unique.
716 for (i = 0; i < 3; ++i) {
717 EXPECT_FALSE(names[i] == names[(i+1)%3]);
718 }
719
720 // Close and delete.
721 for (i = 0; i < 3; ++i) {
722 EXPECT_TRUE(file_util::CloseFile(fps[i]));
723 EXPECT_TRUE(file_util::Delete(names[i], false));
724 }
695 } 725 }
696 726
697 TEST_F(FileUtilTest, CreateNewTempDirectoryTest) { 727 TEST_F(FileUtilTest, CreateNewTempDirectoryTest) {
698 std::wstring temp_dir; 728 std::wstring temp_dir;
699 ASSERT_TRUE(file_util::CreateNewTempDirectory(std::wstring(), &temp_dir)); 729 ASSERT_TRUE(file_util::CreateNewTempDirectory(std::wstring(), &temp_dir));
700 EXPECT_TRUE(file_util::PathExists(temp_dir)); 730 EXPECT_TRUE(file_util::PathExists(temp_dir));
701 EXPECT_TRUE(file_util::Delete(temp_dir, false)); 731 EXPECT_TRUE(file_util::Delete(temp_dir, false));
702 } 732 }
703 733
734 TEST_F(FileUtilTest, GetShmemTempDirTest) {
735 FilePath dir;
736 EXPECT_TRUE(file_util::GetShmemTempDir(&dir));
737 EXPECT_TRUE(file_util::DirectoryExists(dir));
738 }
739
704 TEST_F(FileUtilTest, CreateDirectoryTest) { 740 TEST_F(FileUtilTest, CreateDirectoryTest) {
705 FilePath test_root = 741 FilePath test_root =
706 test_dir_.Append(FILE_PATH_LITERAL("create_directory_test")); 742 test_dir_.Append(FILE_PATH_LITERAL("create_directory_test"));
707 #if defined(OS_WIN) 743 #if defined(OS_WIN)
708 FilePath test_path = 744 FilePath test_path =
709 test_root.Append(FILE_PATH_LITERAL("dir\\tree\\likely\\doesnt\\exist\\")); 745 test_root.Append(FILE_PATH_LITERAL("dir\\tree\\likely\\doesnt\\exist\\"));
710 #elif defined(OS_POSIX) 746 #elif defined(OS_POSIX)
711 FilePath test_path = 747 FilePath test_path =
712 test_root.Append(FILE_PATH_LITERAL("dir/tree/likely/doesnt/exist/")); 748 test_root.Append(FILE_PATH_LITERAL("dir/tree/likely/doesnt/exist/"));
713 #endif 749 #endif
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 EXPECT_TRUE(file_util::ContainsPath(foo, bar)); 1042 EXPECT_TRUE(file_util::ContainsPath(foo, bar));
1007 EXPECT_FALSE(file_util::ContainsPath(foo, baz)); 1043 EXPECT_FALSE(file_util::ContainsPath(foo, baz));
1008 EXPECT_FALSE(file_util::ContainsPath(foo, foobar)); 1044 EXPECT_FALSE(file_util::ContainsPath(foo, foobar));
1009 EXPECT_FALSE(file_util::ContainsPath(foo, foo)); 1045 EXPECT_FALSE(file_util::ContainsPath(foo, foo));
1010 1046
1011 // Platform-specific concerns 1047 // Platform-specific concerns
1012 FilePath foo_caps(data_dir.Append(FILE_PATH_LITERAL("FOO"))); 1048 FilePath foo_caps(data_dir.Append(FILE_PATH_LITERAL("FOO")));
1013 #if defined(OS_WIN) 1049 #if defined(OS_WIN)
1014 EXPECT_TRUE(file_util::ContainsPath(foo, 1050 EXPECT_TRUE(file_util::ContainsPath(foo,
1015 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); 1051 foo_caps.Append(FILE_PATH_LITERAL("bar.txt"))));
1016 EXPECT_TRUE(file_util::ContainsPath(foo, 1052 EXPECT_TRUE(file_util::ContainsPath(foo,
1017 FilePath(foo.value() + FILE_PATH_LITERAL("/bar.txt")))); 1053 FilePath(foo.value() + FILE_PATH_LITERAL("/bar.txt"))));
1018 #elif defined(OS_LINUX) 1054 #elif defined(OS_LINUX)
1019 EXPECT_FALSE(file_util::ContainsPath(foo, 1055 EXPECT_FALSE(file_util::ContainsPath(foo,
1020 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); 1056 foo_caps.Append(FILE_PATH_LITERAL("bar.txt"))));
1021 #else 1057 #else
1022 // We can't really do this test on osx since the case-sensitivity of the 1058 // We can't really do this test on osx since the case-sensitivity of the
1023 // filesystem is configurable. 1059 // filesystem is configurable.
1024 #endif 1060 #endif
1025 } 1061 }
1026 1062
1027 } // namespace 1063 } // namespace
OLDNEW
« no previous file with comments | « base/file_util_posix.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698