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

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

Issue 2797283002: Fixing std::swap(x, x) in base. (Closed)
Patch Set: Rebase. Created 3 years, 8 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/file.cc ('k') | base/pickle.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 "base/files/file.h" 5 #include "base/files/file.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ | 98 base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ |
99 base::File::FLAG_DELETE_ON_CLOSE); 99 base::File::FLAG_DELETE_ON_CLOSE);
100 EXPECT_TRUE(file.IsValid()); 100 EXPECT_TRUE(file.IsValid());
101 EXPECT_TRUE(file.created()); 101 EXPECT_TRUE(file.created());
102 EXPECT_EQ(base::File::FILE_OK, file.error_details()); 102 EXPECT_EQ(base::File::FILE_OK, file.error_details());
103 } 103 }
104 104
105 EXPECT_FALSE(base::PathExists(file_path)); 105 EXPECT_FALSE(base::PathExists(file_path));
106 } 106 }
107 107
108 TEST(FileTest, SelfSwap) {
109 base::ScopedTempDir temp_dir;
110 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
111 FilePath file_path = temp_dir.GetPath().AppendASCII("create_file_1");
112 File file(file_path,
113 base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_DELETE_ON_CLOSE);
114 using namespace std;
115 swap(file, file);
116 EXPECT_TRUE(file.IsValid());
117 }
118
108 TEST(FileTest, Async) { 119 TEST(FileTest, Async) {
109 base::ScopedTempDir temp_dir; 120 base::ScopedTempDir temp_dir;
110 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 121 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
111 FilePath file_path = temp_dir.GetPath().AppendASCII("create_file"); 122 FilePath file_path = temp_dir.GetPath().AppendASCII("create_file");
112 123
113 { 124 {
114 File file(file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_ASYNC); 125 File file(file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_ASYNC);
115 EXPECT_TRUE(file.IsValid()); 126 EXPECT_TRUE(file.IsValid());
116 EXPECT_TRUE(file.async()); 127 EXPECT_TRUE(file.async());
117 } 128 }
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 ASSERT_TRUE(mapping.Initialize(file.Duplicate())); 677 ASSERT_TRUE(mapping.Initialize(file.Duplicate()));
667 ASSERT_EQ(5U, mapping.length()); 678 ASSERT_EQ(5U, mapping.length());
668 679
669 EXPECT_FALSE(file.DeleteOnClose(true)); 680 EXPECT_FALSE(file.DeleteOnClose(true));
670 } 681 }
671 682
672 file.Close(); 683 file.Close();
673 ASSERT_TRUE(base::PathExists(file_path)); 684 ASSERT_TRUE(base::PathExists(file_path));
674 } 685 }
675 #endif // defined(OS_WIN) 686 #endif // defined(OS_WIN)
OLDNEW
« no previous file with comments | « base/files/file.cc ('k') | base/pickle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698