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

Side by Side Diff: base/file_descriptor_shuffle_unittest.cc

Issue 10004001: Add virtual and OVERRIDE to base/ implementation files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win Fix -> Missing header Created 8 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 | Annotate | Revision Log
« no previous file with comments | « base/environment.cc ('k') | base/file_path_unittest.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/file_descriptor_shuffle.h" 5 #include "base/file_descriptor_shuffle.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 namespace { 8 namespace {
9 9
10 // 'Duplicated' file descriptors start at this number 10 // 'Duplicated' file descriptors start at this number
(...skipping 26 matching lines...) Expand all
37 int fd1; 37 int fd1;
38 int fd2; 38 int fd2;
39 }; 39 };
40 40
41 class InjectionTracer : public InjectionDelegate { 41 class InjectionTracer : public InjectionDelegate {
42 public: 42 public:
43 InjectionTracer() 43 InjectionTracer()
44 : next_duplicate_(kDuplicateBase) { 44 : next_duplicate_(kDuplicateBase) {
45 } 45 }
46 46
47 bool Duplicate(int* result, int fd) { 47 virtual bool Duplicate(int* result, int fd) OVERRIDE {
48 *result = next_duplicate_++; 48 *result = next_duplicate_++;
49 actions_.push_back(Action(Action::DUPLICATE, *result, fd)); 49 actions_.push_back(Action(Action::DUPLICATE, *result, fd));
50 return true; 50 return true;
51 } 51 }
52 52
53 bool Move(int src, int dest) { 53 virtual bool Move(int src, int dest) OVERRIDE {
54 actions_.push_back(Action(Action::MOVE, src, dest)); 54 actions_.push_back(Action(Action::MOVE, src, dest));
55 return true; 55 return true;
56 } 56 }
57 57
58 void Close(int fd) { 58 virtual void Close(int fd) OVERRIDE {
59 actions_.push_back(Action(Action::CLOSE, fd)); 59 actions_.push_back(Action(Action::CLOSE, fd));
60 } 60 }
61 61
62 const std::vector<Action>& actions() const { return actions_; } 62 const std::vector<Action>& actions() const { return actions_; }
63 63
64 private: 64 private:
65 int next_duplicate_; 65 int next_duplicate_;
66 std::vector<Action> actions_; 66 std::vector<Action> actions_;
67 }; 67 };
68 68
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 243
244 EXPECT_TRUE(PerformInjectiveMultimap(map, &tracer)); 244 EXPECT_TRUE(PerformInjectiveMultimap(map, &tracer));
245 ASSERT_EQ(3u, tracer.actions().size()); 245 ASSERT_EQ(3u, tracer.actions().size());
246 EXPECT_TRUE(tracer.actions()[0] == Action(Action::MOVE, 0, 1)); 246 EXPECT_TRUE(tracer.actions()[0] == Action(Action::MOVE, 0, 1));
247 EXPECT_TRUE(tracer.actions()[1] == Action(Action::MOVE, 0, 2)); 247 EXPECT_TRUE(tracer.actions()[1] == Action(Action::MOVE, 0, 2));
248 EXPECT_TRUE(tracer.actions()[2] == Action(Action::CLOSE, 0)); 248 EXPECT_TRUE(tracer.actions()[2] == Action(Action::CLOSE, 0));
249 } 249 }
250 250
251 class FailingDelegate : public InjectionDelegate { 251 class FailingDelegate : public InjectionDelegate {
252 public: 252 public:
253 bool Duplicate(int* result, int fd) { 253 virtual bool Duplicate(int* result, int fd) OVERRIDE {
254 return false; 254 return false;
255 } 255 }
256 256
257 bool Move(int src, int dest) { 257 virtual bool Move(int src, int dest) OVERRIDE {
258 return false; 258 return false;
259 } 259 }
260 260
261 void Close(int fd) { 261 virtual void Close(int fd) OVERRIDE {}
262 }
263 }; 262 };
264 263
265 TEST(FileDescriptorShuffleTest, EmptyWithFailure) { 264 TEST(FileDescriptorShuffleTest, EmptyWithFailure) {
266 InjectiveMultimap map; 265 InjectiveMultimap map;
267 FailingDelegate failing; 266 FailingDelegate failing;
268 267
269 EXPECT_TRUE(PerformInjectiveMultimap(map, &failing)); 268 EXPECT_TRUE(PerformInjectiveMultimap(map, &failing));
270 } 269 }
271 270
272 TEST(FileDescriptorShuffleTest, NoopWithFailure) { 271 TEST(FileDescriptorShuffleTest, NoopWithFailure) {
273 InjectiveMultimap map; 272 InjectiveMultimap map;
274 FailingDelegate failing; 273 FailingDelegate failing;
275 map.push_back(InjectionArc(0, 0, false)); 274 map.push_back(InjectionArc(0, 0, false));
276 275
277 EXPECT_TRUE(PerformInjectiveMultimap(map, &failing)); 276 EXPECT_TRUE(PerformInjectiveMultimap(map, &failing));
278 } 277 }
279 278
280 TEST(FileDescriptorShuffleTest, Simple1WithFailure) { 279 TEST(FileDescriptorShuffleTest, Simple1WithFailure) {
281 InjectiveMultimap map; 280 InjectiveMultimap map;
282 FailingDelegate failing; 281 FailingDelegate failing;
283 map.push_back(InjectionArc(0, 1, false)); 282 map.push_back(InjectionArc(0, 1, false));
284 283
285 EXPECT_FALSE(PerformInjectiveMultimap(map, &failing)); 284 EXPECT_FALSE(PerformInjectiveMultimap(map, &failing));
286 } 285 }
287 286
288 } // namespace base 287 } // namespace base
OLDNEW
« no previous file with comments | « base/environment.cc ('k') | base/file_path_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698