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

Side by Side Diff: base/scoped_temp_dir_unittest.cc

Issue 8972009: Fix file leaks in a ETW test and a ScopedTempDir test. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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 | « no previous file | base/win/event_trace_controller_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>
6
5 #include "base/file_util.h" 7 #include "base/file_util.h"
6 #include "base/platform_file.h" 8 #include "base/platform_file.h"
7 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
8 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
9 11
10 TEST(ScopedTempDir, FullPath) { 12 TEST(ScopedTempDir, FullPath) {
11 FilePath test_path; 13 FilePath test_path;
12 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_temp_dir"), 14 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_temp_dir"),
13 &test_path); 15 &test_path);
14 16
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 FilePath tmp_dir; 55 FilePath tmp_dir;
54 EXPECT_TRUE(file_util::GetTempDir(&tmp_dir)); 56 EXPECT_TRUE(file_util::GetTempDir(&tmp_dir));
55 EXPECT_TRUE(test_path.value().find(tmp_dir.value()) != std::string::npos); 57 EXPECT_TRUE(test_path.value().find(tmp_dir.value()) != std::string::npos);
56 } 58 }
57 EXPECT_FALSE(file_util::DirectoryExists(test_path)); 59 EXPECT_FALSE(file_util::DirectoryExists(test_path));
58 } 60 }
59 61
60 TEST(ScopedTempDir, UniqueTempDirUnderPath) { 62 TEST(ScopedTempDir, UniqueTempDirUnderPath) {
61 // Create a path which will contain a unique temp path. 63 // Create a path which will contain a unique temp path.
62 FilePath base_path; 64 FilePath base_path;
63 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("base_dir"), 65 ASSERT_TRUE(file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("base_dir"),
64 &base_path); 66 &base_path));
65 67
66 FilePath test_path; 68 FilePath test_path;
67 { 69 {
68 ScopedTempDir dir; 70 ScopedTempDir dir;
69 EXPECT_TRUE(dir.CreateUniqueTempDirUnderPath(base_path)); 71 EXPECT_TRUE(dir.CreateUniqueTempDirUnderPath(base_path));
70 test_path = dir.path(); 72 test_path = dir.path();
71 EXPECT_TRUE(file_util::DirectoryExists(test_path)); 73 EXPECT_TRUE(file_util::DirectoryExists(test_path));
72 EXPECT_TRUE(base_path.IsParent(test_path)); 74 EXPECT_TRUE(base_path.IsParent(test_path));
73 EXPECT_TRUE(test_path.value().find(base_path.value()) != std::string::npos); 75 EXPECT_TRUE(test_path.value().find(base_path.value()) != std::string::npos);
74 } 76 }
75 EXPECT_FALSE(file_util::DirectoryExists(test_path)); 77 EXPECT_FALSE(file_util::DirectoryExists(test_path));
78 file_util::Delete(base_path, true);
76 } 79 }
77 80
78 TEST(ScopedTempDir, MultipleInvocations) { 81 TEST(ScopedTempDir, MultipleInvocations) {
79 ScopedTempDir dir; 82 ScopedTempDir dir;
80 EXPECT_TRUE(dir.CreateUniqueTempDir()); 83 EXPECT_TRUE(dir.CreateUniqueTempDir());
81 EXPECT_FALSE(dir.CreateUniqueTempDir()); 84 EXPECT_FALSE(dir.CreateUniqueTempDir());
82 EXPECT_TRUE(dir.Delete()); 85 EXPECT_TRUE(dir.Delete());
83 EXPECT_TRUE(dir.CreateUniqueTempDir()); 86 EXPECT_TRUE(dir.CreateUniqueTempDir());
84 EXPECT_FALSE(dir.CreateUniqueTempDir()); 87 EXPECT_FALSE(dir.CreateUniqueTempDir());
85 ScopedTempDir other_dir; 88 ScopedTempDir other_dir;
(...skipping 15 matching lines...) Expand all
101 NULL, &error_code); 104 NULL, &error_code);
102 EXPECT_NE(base::kInvalidPlatformFileValue, file); 105 EXPECT_NE(base::kInvalidPlatformFileValue, file);
103 EXPECT_EQ(base::PLATFORM_FILE_OK, error_code); 106 EXPECT_EQ(base::PLATFORM_FILE_OK, error_code);
104 EXPECT_FALSE(dir.Delete()); // We should not be able to delete. 107 EXPECT_FALSE(dir.Delete()); // We should not be able to delete.
105 EXPECT_FALSE(dir.path().empty()); // We should still have a valid path. 108 EXPECT_FALSE(dir.path().empty()); // We should still have a valid path.
106 EXPECT_TRUE(base::ClosePlatformFile(file)); 109 EXPECT_TRUE(base::ClosePlatformFile(file));
107 // Now, we should be able to delete. 110 // Now, we should be able to delete.
108 EXPECT_TRUE(dir.Delete()); 111 EXPECT_TRUE(dir.Delete());
109 } 112 }
110 #endif // defined(OS_WIN) 113 #endif // defined(OS_WIN)
OLDNEW
« no previous file with comments | « no previous file | base/win/event_trace_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698