OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 // This test is POSIX only. | 5 // This test is POSIX only. |
6 | 6 |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/eintr_wrappers.h" |
11 #include "chrome/common/file_descriptor_set_posix.h" | 12 #include "chrome/common/file_descriptor_set_posix.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 // The FileDescriptorSet will try and close some of the descriptor numbers | 15 // The FileDescriptorSet will try and close some of the descriptor numbers |
15 // which we given it. This is the base descriptor value. It's great enough such | 16 // which we given it. This is the base descriptor value. It's great enough such |
16 // that no real descriptor will accidently be closed. | 17 // that no real descriptor will accidently be closed. |
17 static const int kFDBase = 50000; | 18 static const int kFDBase = 50000; |
18 | 19 |
19 TEST(FileDescriptorSet, BasicAdd) { | 20 TEST(FileDescriptorSet, BasicAdd) { |
20 scoped_refptr<FileDescriptorSet> set = new FileDescriptorSet; | 21 scoped_refptr<FileDescriptorSet> set = new FileDescriptorSet; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 134 |
134 TEST(FileDescriptorSet, DontClose) { | 135 TEST(FileDescriptorSet, DontClose) { |
135 scoped_refptr<FileDescriptorSet> set = new FileDescriptorSet; | 136 scoped_refptr<FileDescriptorSet> set = new FileDescriptorSet; |
136 | 137 |
137 const int fd = open("/dev/null", O_RDONLY); | 138 const int fd = open("/dev/null", O_RDONLY); |
138 ASSERT_TRUE(set->Add(fd)); | 139 ASSERT_TRUE(set->Add(fd)); |
139 set->CommitAll(); | 140 set->CommitAll(); |
140 | 141 |
141 const int duped = dup(fd); | 142 const int duped = dup(fd); |
142 ASSERT_GE(duped, 0); | 143 ASSERT_GE(duped, 0); |
143 close(duped); | 144 HANDLE_EINTR(close(duped)); |
144 close(fd); | 145 HANDLE_EINTR(close(fd)); |
145 } | 146 } |
146 | 147 |
147 TEST(FileDescriptorSet, DoClose) { | 148 TEST(FileDescriptorSet, DoClose) { |
148 scoped_refptr<FileDescriptorSet> set = new FileDescriptorSet; | 149 scoped_refptr<FileDescriptorSet> set = new FileDescriptorSet; |
149 | 150 |
150 const int fd = open("/dev/null", O_RDONLY); | 151 const int fd = open("/dev/null", O_RDONLY); |
151 ASSERT_TRUE(set->AddAndAutoClose(fd)); | 152 ASSERT_TRUE(set->AddAndAutoClose(fd)); |
152 set->CommitAll(); | 153 set->CommitAll(); |
153 | 154 |
154 const int duped = dup(fd); | 155 const int duped = dup(fd); |
155 ASSERT_EQ(duped, -1); | 156 ASSERT_EQ(duped, -1); |
156 close(fd); | 157 HANDLE_EINTR(close(fd)); |
157 } | 158 } |
OLD | NEW |