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

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

Issue 2862873002: base: add a unit test for SetCloseOnExec() function (Closed)
Patch Set: Created 3 years, 7 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 | « no previous file | no next file » | 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <fstream> 9 #include <fstream>
10 #include <initializer_list> 10 #include <initializer_list>
(...skipping 2249 matching lines...) Expand 10 before | Expand all | Expand 10 after
2260 EXPECT_FALSE(SetNonBlocking(kInvalidFd)); 2260 EXPECT_FALSE(SetNonBlocking(kInvalidFd));
2261 2261
2262 base::FilePath path; 2262 base::FilePath path;
2263 ASSERT_TRUE(PathService::Get(base::DIR_TEST_DATA, &path)); 2263 ASSERT_TRUE(PathService::Get(base::DIR_TEST_DATA, &path));
2264 path = path.Append(FPL("file_util")).Append(FPL("original.txt")); 2264 path = path.Append(FPL("file_util")).Append(FPL("original.txt"));
2265 ScopedFD fd(open(path.value().c_str(), O_RDONLY)); 2265 ScopedFD fd(open(path.value().c_str(), O_RDONLY));
2266 ASSERT_GE(fd.get(), 0); 2266 ASSERT_GE(fd.get(), 0);
2267 EXPECT_TRUE(SetNonBlocking(fd.get())); 2267 EXPECT_TRUE(SetNonBlocking(fd.get()));
2268 } 2268 }
2269 2269
2270 TEST_F(FileUtilTest, SetCloseOnExec) {
2271 const int kInvalidFd = 99999;
2272 EXPECT_FALSE(SetCloseOnExec(kInvalidFd));
2273
2274 base::FilePath path;
2275 ASSERT_TRUE(PathService::Get(base::DIR_TEST_DATA, &path));
2276 path = path.Append(FPL("file_util")).Append(FPL("original.txt"));
2277 ScopedFD fd(open(path.value().c_str(), O_RDONLY));
2278 ASSERT_GE(fd.get(), 0);
2279 EXPECT_TRUE(SetCloseOnExec(fd.get()));
2280 }
2281
2270 // Testing VerifyPathControlledByAdmin() is hard, because there is no 2282 // Testing VerifyPathControlledByAdmin() is hard, because there is no
2271 // way a test can make a file owned by root, or change file paths 2283 // way a test can make a file owned by root, or change file paths
2272 // at the root of the file system. VerifyPathControlledByAdmin() 2284 // at the root of the file system. VerifyPathControlledByAdmin()
2273 // is implemented as a call to VerifyPathControlledByUser, which gives 2285 // is implemented as a call to VerifyPathControlledByUser, which gives
2274 // us the ability to test with paths under the test's temp directory, 2286 // us the ability to test with paths under the test's temp directory,
2275 // using a user id we control. 2287 // using a user id we control.
2276 // Pull tests of VerifyPathControlledByUserTest() into a separate test class 2288 // Pull tests of VerifyPathControlledByUserTest() into a separate test class
2277 // with a common SetUp() method. 2289 // with a common SetUp() method.
2278 class VerifyPathControlledByUserTest : public FileUtilTest { 2290 class VerifyPathControlledByUserTest : public FileUtilTest {
2279 protected: 2291 protected:
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
2629 // Trying to close it should crash. This is important for security. 2641 // Trying to close it should crash. This is important for security.
2630 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); 2642 EXPECT_DEATH(CloseWithScopedFD(fds[1]), "");
2631 #endif 2643 #endif
2632 } 2644 }
2633 2645
2634 #endif // defined(OS_POSIX) 2646 #endif // defined(OS_POSIX)
2635 2647
2636 } // namespace 2648 } // namespace
2637 2649
2638 } // namespace base 2650 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698