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

Side by Side Diff: base/files/scoped_temp_dir_unittest.cc

Issue 2275553005: //base: Make ScopedTempDir::path() a GetPath() with a DCHECK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments Created 4 years, 3 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
« no previous file with comments | « base/files/scoped_temp_dir.cc ('k') | base/json/json_value_serializer_unittest.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.h" 7 #include "base/files/file.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 EXPECT_FALSE(DirectoryExists(test_path)); 46 EXPECT_FALSE(DirectoryExists(test_path));
47 } 47 }
48 48
49 TEST(ScopedTempDir, TempDir) { 49 TEST(ScopedTempDir, TempDir) {
50 // In this case, just verify that a directory was created and that it's a 50 // In this case, just verify that a directory was created and that it's a
51 // child of TempDir. 51 // child of TempDir.
52 FilePath test_path; 52 FilePath test_path;
53 { 53 {
54 ScopedTempDir dir; 54 ScopedTempDir dir;
55 EXPECT_TRUE(dir.CreateUniqueTempDir()); 55 EXPECT_TRUE(dir.CreateUniqueTempDir());
56 test_path = dir.path(); 56 test_path = dir.GetPath();
57 EXPECT_TRUE(DirectoryExists(test_path)); 57 EXPECT_TRUE(DirectoryExists(test_path));
58 FilePath tmp_dir; 58 FilePath tmp_dir;
59 EXPECT_TRUE(base::GetTempDir(&tmp_dir)); 59 EXPECT_TRUE(base::GetTempDir(&tmp_dir));
60 EXPECT_TRUE(test_path.value().find(tmp_dir.value()) != std::string::npos); 60 EXPECT_TRUE(test_path.value().find(tmp_dir.value()) != std::string::npos);
61 } 61 }
62 EXPECT_FALSE(DirectoryExists(test_path)); 62 EXPECT_FALSE(DirectoryExists(test_path));
63 } 63 }
64 64
65 TEST(ScopedTempDir, UniqueTempDirUnderPath) { 65 TEST(ScopedTempDir, UniqueTempDirUnderPath) {
66 // Create a path which will contain a unique temp path. 66 // Create a path which will contain a unique temp path.
67 FilePath base_path; 67 FilePath base_path;
68 ASSERT_TRUE(base::CreateNewTempDirectory(FILE_PATH_LITERAL("base_dir"), 68 ASSERT_TRUE(base::CreateNewTempDirectory(FILE_PATH_LITERAL("base_dir"),
69 &base_path)); 69 &base_path));
70 70
71 FilePath test_path; 71 FilePath test_path;
72 { 72 {
73 ScopedTempDir dir; 73 ScopedTempDir dir;
74 EXPECT_TRUE(dir.CreateUniqueTempDirUnderPath(base_path)); 74 EXPECT_TRUE(dir.CreateUniqueTempDirUnderPath(base_path));
75 test_path = dir.path(); 75 test_path = dir.GetPath();
76 EXPECT_TRUE(DirectoryExists(test_path)); 76 EXPECT_TRUE(DirectoryExists(test_path));
77 EXPECT_TRUE(base_path.IsParent(test_path)); 77 EXPECT_TRUE(base_path.IsParent(test_path));
78 EXPECT_TRUE(test_path.value().find(base_path.value()) != std::string::npos); 78 EXPECT_TRUE(test_path.value().find(base_path.value()) != std::string::npos);
79 } 79 }
80 EXPECT_FALSE(DirectoryExists(test_path)); 80 EXPECT_FALSE(DirectoryExists(test_path));
81 base::DeleteFile(base_path, true); 81 base::DeleteFile(base_path, true);
82 } 82 }
83 83
84 TEST(ScopedTempDir, MultipleInvocations) { 84 TEST(ScopedTempDir, MultipleInvocations) {
85 ScopedTempDir dir; 85 ScopedTempDir dir;
86 EXPECT_TRUE(dir.CreateUniqueTempDir()); 86 EXPECT_TRUE(dir.CreateUniqueTempDir());
87 EXPECT_FALSE(dir.CreateUniqueTempDir()); 87 EXPECT_FALSE(dir.CreateUniqueTempDir());
88 EXPECT_TRUE(dir.Delete()); 88 EXPECT_TRUE(dir.Delete());
89 EXPECT_TRUE(dir.CreateUniqueTempDir()); 89 EXPECT_TRUE(dir.CreateUniqueTempDir());
90 EXPECT_FALSE(dir.CreateUniqueTempDir()); 90 EXPECT_FALSE(dir.CreateUniqueTempDir());
91 ScopedTempDir other_dir; 91 ScopedTempDir other_dir;
92 EXPECT_TRUE(other_dir.Set(dir.Take())); 92 EXPECT_TRUE(other_dir.Set(dir.Take()));
93 EXPECT_TRUE(dir.CreateUniqueTempDir()); 93 EXPECT_TRUE(dir.CreateUniqueTempDir());
94 EXPECT_FALSE(dir.CreateUniqueTempDir()); 94 EXPECT_FALSE(dir.CreateUniqueTempDir());
95 EXPECT_FALSE(other_dir.CreateUniqueTempDir()); 95 EXPECT_FALSE(other_dir.CreateUniqueTempDir());
96 } 96 }
97 97
98 #if defined(OS_WIN) 98 #if defined(OS_WIN)
99 TEST(ScopedTempDir, LockedTempDir) { 99 TEST(ScopedTempDir, LockedTempDir) {
100 ScopedTempDir dir; 100 ScopedTempDir dir;
101 EXPECT_TRUE(dir.CreateUniqueTempDir()); 101 EXPECT_TRUE(dir.CreateUniqueTempDir());
102 base::File file(dir.path().Append(FILE_PATH_LITERAL("temp")), 102 base::File file(dir.GetPath().Append(FILE_PATH_LITERAL("temp")),
103 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); 103 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
104 EXPECT_TRUE(file.IsValid()); 104 EXPECT_TRUE(file.IsValid());
105 EXPECT_EQ(base::File::FILE_OK, file.error_details()); 105 EXPECT_EQ(base::File::FILE_OK, file.error_details());
106 EXPECT_FALSE(dir.Delete()); // We should not be able to delete. 106 EXPECT_FALSE(dir.Delete()); // We should not be able to delete.
107 EXPECT_FALSE(dir.path().empty()); // We should still have a valid path. 107 EXPECT_FALSE(dir.GetPath().empty()); // We should still have a valid path.
108 file.Close(); 108 file.Close();
109 // Now, we should be able to delete. 109 // Now, we should be able to delete.
110 EXPECT_TRUE(dir.Delete()); 110 EXPECT_TRUE(dir.Delete());
111 } 111 }
112 #endif // defined(OS_WIN) 112 #endif // defined(OS_WIN)
113 113
114 } // namespace base 114 } // namespace base
OLDNEW
« no previous file with comments | « base/files/scoped_temp_dir.cc ('k') | base/json/json_value_serializer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698