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

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

Issue 2797283002: Fixing std::swap(x, x) in base. (Closed)
Patch Set: 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
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 std::swap(file, file);
115 EXPECT_TRUE(file.IsValid());
116 }
117
108 TEST(FileTest, Async) { 118 TEST(FileTest, Async) {
109 base::ScopedTempDir temp_dir; 119 base::ScopedTempDir temp_dir;
110 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 120 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
111 FilePath file_path = temp_dir.GetPath().AppendASCII("create_file"); 121 FilePath file_path = temp_dir.GetPath().AppendASCII("create_file");
112 122
113 { 123 {
114 File file(file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_ASYNC); 124 File file(file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_ASYNC);
115 EXPECT_TRUE(file.IsValid()); 125 EXPECT_TRUE(file.IsValid());
116 EXPECT_TRUE(file.async()); 126 EXPECT_TRUE(file.async());
117 } 127 }
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 ASSERT_TRUE(mapping.Initialize(file.Duplicate())); 676 ASSERT_TRUE(mapping.Initialize(file.Duplicate()));
667 ASSERT_EQ(5U, mapping.length()); 677 ASSERT_EQ(5U, mapping.length());
668 678
669 EXPECT_FALSE(file.DeleteOnClose(true)); 679 EXPECT_FALSE(file.DeleteOnClose(true));
670 } 680 }
671 681
672 file.Close(); 682 file.Close();
673 ASSERT_TRUE(base::PathExists(file_path)); 683 ASSERT_TRUE(base::PathExists(file_path));
674 } 684 }
675 #endif // defined(OS_WIN) 685 #endif // defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698