OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/platform_file.h" | |
6 #include "base/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
8 | 9 |
9 TEST(ScopedTempDir, FullPath) { | 10 TEST(ScopedTempDir, FullPath) { |
10 FilePath test_path; | 11 FilePath test_path; |
11 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_temp_dir"), | 12 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_temp_dir"), |
12 &test_path); | 13 &test_path); |
13 | 14 |
14 // Against an existing dir, it should get destroyed when leaving scope. | 15 // Against an existing dir, it should get destroyed when leaving scope. |
15 EXPECT_TRUE(file_util::DirectoryExists(test_path)); | 16 EXPECT_TRUE(file_util::DirectoryExists(test_path)); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 EXPECT_FALSE(dir.CreateUniqueTempDir()); | 81 EXPECT_FALSE(dir.CreateUniqueTempDir()); |
81 dir.Delete(); | 82 dir.Delete(); |
82 EXPECT_TRUE(dir.CreateUniqueTempDir()); | 83 EXPECT_TRUE(dir.CreateUniqueTempDir()); |
83 EXPECT_FALSE(dir.CreateUniqueTempDir()); | 84 EXPECT_FALSE(dir.CreateUniqueTempDir()); |
84 ScopedTempDir other_dir; | 85 ScopedTempDir other_dir; |
85 other_dir.Set(dir.Take()); | 86 other_dir.Set(dir.Take()); |
86 EXPECT_TRUE(dir.CreateUniqueTempDir()); | 87 EXPECT_TRUE(dir.CreateUniqueTempDir()); |
87 EXPECT_FALSE(dir.CreateUniqueTempDir()); | 88 EXPECT_FALSE(dir.CreateUniqueTempDir()); |
88 EXPECT_FALSE(other_dir.CreateUniqueTempDir()); | 89 EXPECT_FALSE(other_dir.CreateUniqueTempDir()); |
89 } | 90 } |
91 | |
92 #if defined(OS_WIN) | |
93 | |
Paweł Hajdan Jr.
2010/11/27 14:57:07
nit: Remove empty line.
tommi (sloooow) - chröme
2010/11/28 02:37:03
Done.
| |
94 TEST(ScopedTempDir, LockedTempDir) { | |
95 ScopedTempDir dir; | |
96 EXPECT_TRUE(dir.CreateUniqueTempDir()); | |
97 int file_flags = base::PLATFORM_FILE_CREATE_ALWAYS | | |
98 base::PLATFORM_FILE_WRITE; | |
99 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; | |
100 FilePath file_path(dir.path().Append(FILE_PATH_LITERAL("temp"))); | |
101 base::PlatformFile file = base::CreatePlatformFile(file_path, file_flags, | |
102 NULL, &error_code); | |
103 EXPECT_NE(base::kInvalidPlatformFileValue, file); | |
104 EXPECT_EQ(base::PLATFORM_FILE_OK, error_code); | |
105 EXPECT_FALSE(dir.Delete()); // We should not be able to delete. | |
106 EXPECT_FALSE(dir.path().empty()); // We should still have a valid path. | |
107 EXPECT_TRUE(base::ClosePlatformFile(file)); | |
108 // Now, we should be able to delete. | |
109 EXPECT_TRUE(dir.Delete()); | |
110 } | |
111 | |
Paweł Hajdan Jr.
2010/11/27 14:57:07
nit: Remove empty line.
tommi (sloooow) - chröme
2010/11/28 02:37:03
Done.
| |
112 #endif | |
Paweł Hajdan Jr.
2010/11/27 14:57:07
nit: // defined(OS_WIN)
tommi (sloooow) - chröme
2010/11/28 02:37:03
Done.
| |
OLD | NEW |