Index: util/posix/scoped_fcntl_flags_test.cc |
diff --git a/util/posix/scoped_fcntl_flags_test.cc b/util/posix/scoped_fcntl_flags_test.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..80b0fd9792c2b20125161373a926dbe472657278 |
--- /dev/null |
+++ b/util/posix/scoped_fcntl_flags_test.cc |
@@ -0,0 +1,65 @@ |
+// Copyright 2014 The Crashpad Authors. All rights reserved. |
+// |
+// Licensed under the Apache License, Version 2.0 (the "License"); |
+// you may not use this file except in compliance with the License. |
+// You may obtain a copy of the License at |
+// |
+// http://www.apache.org/licenses/LICENSE-2.0 |
+// |
+// Unless required by applicable law or agreed to in writing, software |
+// distributed under the License is distributed on an "AS IS" BASIS, |
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+// See the License for the specific language governing permissions and |
+// limitations under the License. |
+ |
+#include "util/posix/scoped_fcntl_flags.h" |
+ |
+#include <fcntl.h> |
+#include <paths.h> |
+ |
+#include "base/files/scoped_file.h" |
+#include "base/logging.h" |
+#include "base/posix/eintr_wrapper.h" |
+#include "gtest/gtest.h" |
+#include "util/test/errors.h" |
+ |
+namespace crashpad { |
+namespace test { |
+namespace { |
+ |
+// Returns the value of the file descriptor |fd|’s status flags as |
+// fcntl(fd, F_GETFL) does. On error, terminates execution. |
+int FcntlFlags(int fd) { |
+ int rv = fcntl(fd, F_GETFL, 0); |
+ PCHECK(rv != -1) << "fcntl"; |
Robert Sesek
2014/10/13 19:09:39
Use EXPECT_ instead so you don't crash the test?
|
+ |
+ return rv; |
+} |
+ |
+TEST(ScopedFcntlFlags, ScopedFcntlFlags) { |
+ int fd = HANDLE_EINTR(open(_PATH_DEVNULL, O_RDWR)); |
+ ASSERT_GE(fd, 0) << ErrnoMessage("open"); |
+ |
+ base::ScopedFD fd_owner(fd); |
+ |
+ int flags = FcntlFlags(fd); |
+ EXPECT_EQ(O_RDWR, flags); |
+ |
+ { |
+ ScopedFcntlFlags fcntl_flags(fd, O_NONBLOCK, 0); |
+ EXPECT_EQ(O_RDWR | O_NONBLOCK, FcntlFlags(fd)); |
+ |
+ { |
+ ScopedFcntlFlags fcntl_flags(fd, 0, O_NONBLOCK); |
+ EXPECT_EQ(O_RDWR, FcntlFlags(fd)); |
+ } |
+ |
+ EXPECT_EQ(O_RDWR | O_NONBLOCK, FcntlFlags(fd)); |
+ } |
+ |
+ EXPECT_EQ(O_RDWR, flags); |
+} |
+ |
+} // namespace |
+} // namespace test |
+} // namespace crashpad |