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

Side by Side Diff: base/test/test_pending_task_info.h

Issue 2627863002: Split Closure part of TestPendingTask out of the struct (Closed)
Patch Set: rebase Created 3 years, 11 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 | « base/test/test_pending_task.cc ('k') | base/test/test_pending_task_info.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) 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 #ifndef BASE_TEST_TEST_PENDING_TASK_H_ 5 #ifndef BASE_TEST_TEST_PENDING_TASK_INFO_H_
6 #define BASE_TEST_TEST_PENDING_TASK_H_ 6 #define BASE_TEST_TEST_PENDING_TASK_INFO_H_
7 7
8 #include <deque>
9 #include <iosfwd>
10 #include <memory>
8 #include <string> 11 #include <string>
9 12
10 #include "base/callback.h" 13 #include "base/callback_forward.h"
11 #include "base/location.h" 14 #include "base/location.h"
12 #include "base/time/time.h" 15 #include "base/time/time.h"
13 #include "base/trace_event/trace_event_argument.h" 16 #include "base/trace_event/trace_event_argument.h"
14 17
15 namespace base { 18 namespace base {
16 19
17 // TestPendingTask is a helper class for test TaskRunner 20 // TestPendingTaskInfo is a helper class for test TaskRunner
18 // implementations. See test_simple_task_runner.h for example usage. 21 // implementations. See test_simple_task_runner.h for example usage.
19 22
20 struct TestPendingTask { 23 struct TestPendingTaskInfo {
21 enum TestNestability { NESTABLE, NON_NESTABLE }; 24 enum TestNestability { NESTABLE, NON_NESTABLE };
22 25
23 TestPendingTask(); 26 TestPendingTaskInfo();
24 TestPendingTask(const TestPendingTask& other); 27 TestPendingTaskInfo(const TestPendingTaskInfo& other);
25 TestPendingTask(const tracked_objects::Location& location, 28 TestPendingTaskInfo(const tracked_objects::Location& location,
26 const Closure& task, 29 TimeTicks post_time,
27 TimeTicks post_time, 30 TimeDelta delay,
28 TimeDelta delay, 31 TestNestability nestability);
29 TestNestability nestability); 32 ~TestPendingTaskInfo();
30 ~TestPendingTask();
31 33
32 // Returns post_time + delay. 34 // Returns post_time + delay.
33 TimeTicks GetTimeToRun() const; 35 TimeTicks GetTimeToRun() const;
34 36
35 // Returns true if this task is nestable and |other| isn't, or if 37 // Returns true if this task is nestable and |other| isn't, or if
36 // this task's time to run is strictly earlier than |other|'s time 38 // this task's time to run is strictly earlier than |other|'s time
37 // to run. 39 // to run.
38 // 40 //
39 // Note that two tasks may both have the same nestability and delay. 41 // Note that two tasks may both have the same nestability and delay.
40 // In that case, the caller must use some other criterion (probably 42 // In that case, the caller must use some other criterion (probably
41 // the position in some queue) to break the tie. Conveniently, the 43 // the position in some queue) to break the tie. Conveniently, the
42 // following STL functions already do so: 44 // following STL functions already do so:
43 // 45 //
44 // - std::min_element 46 // - std::min_element
45 // - std::stable_sort 47 // - std::stable_sort
46 // 48 //
47 // but the following STL functions don't: 49 // but the following STL functions don't:
48 // 50 //
49 // - std::max_element 51 // - std::max_element
50 // - std::sort. 52 // - std::sort.
51 bool ShouldRunBefore(const TestPendingTask& other) const; 53 bool ShouldRunBefore(const TestPendingTaskInfo& other) const;
52 54
53 tracked_objects::Location location; 55 tracked_objects::Location location;
54 Closure task;
55 TimeTicks post_time; 56 TimeTicks post_time;
56 TimeDelta delay; 57 TimeDelta delay;
57 TestNestability nestability; 58 TestNestability nestability = NESTABLE;
58 59
59 // Functions for using test pending task with tracing, useful in unit 60 // Functions for using test pending task with tracing, useful in unit
60 // testing. 61 // testing.
61 void AsValueInto(base::trace_event::TracedValue* state) const; 62 void AsValueInto(base::trace_event::TracedValue* state) const;
62 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; 63 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const;
63 std::string ToString() const; 64 std::string ToString() const;
64 }; 65 };
65 66
67 using TestPendingTaskQueue =
68 std::deque<std::pair<TestPendingTaskInfo, OnceClosure>>;
69
66 // gtest helpers which allow pretty printing of the tasks, very useful in unit 70 // gtest helpers which allow pretty printing of the tasks, very useful in unit
67 // testing. 71 // testing.
68 std::ostream& operator<<(std::ostream& os, const TestPendingTask& task); 72 std::ostream& operator<<(std::ostream& os, const TestPendingTaskInfo& task);
69 void PrintTo(const TestPendingTask& task, std::ostream* os); 73 void PrintTo(const TestPendingTaskInfo& task, std::ostream* os);
70 74
71 } // namespace base 75 } // namespace base
72 76
73 #endif // BASE_TEST_TEST_PENDING_TASK_H_ 77 #endif // BASE_TEST_TEST_PENDING_TASK_INFO_H_
OLDNEW
« no previous file with comments | « base/test/test_pending_task.cc ('k') | base/test/test_pending_task_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698