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

Side by Side Diff: net/tools/quic/test_tools/mock_epoll_server.h

Issue 1884453002: Revert of Convert //net and //chromecast to std::unordered_* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « net/tools/quic/quic_simple_server_session.h ('k') | net/url_request/url_request_filter.h » ('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 NET_TOOLS_QUIC_TEST_TOOLS_MOCK_EPOLL_SERVER_H_ 5 #ifndef NET_TOOLS_QUIC_TEST_TOOLS_MOCK_EPOLL_SERVER_H_
6 #define NET_TOOLS_QUIC_TEST_TOOLS_MOCK_EPOLL_SERVER_H_ 6 #define NET_TOOLS_QUIC_TEST_TOOLS_MOCK_EPOLL_SERVER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <unordered_map>
12 #include <unordered_set>
13
14 #include "base/logging.h" 11 #include "base/logging.h"
15 #include "base/macros.h" 12 #include "base/macros.h"
16 #include "net/tools/epoll_server/epoll_server.h" 13 #include "net/tools/epoll_server/epoll_server.h"
17 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
18 15
19 namespace net { 16 namespace net {
20 namespace test { 17 namespace test {
21 18
22 // Unlike the full MockEpollServer, this only lies about the time but lets 19 // Unlike the full MockEpollServer, this only lies about the time but lets
23 // fd events operate normally. Usefully when interacting with real backends 20 // fd events operate normally. Usefully when interacting with real backends
(...skipping 24 matching lines...) Expand all
48 } 45 }
49 46
50 private: 47 private:
51 int64_t now_in_usec_; 48 int64_t now_in_usec_;
52 49
53 DISALLOW_COPY_AND_ASSIGN(FakeTimeEpollServer); 50 DISALLOW_COPY_AND_ASSIGN(FakeTimeEpollServer);
54 }; 51 };
55 52
56 class MockEpollServer : public FakeTimeEpollServer { 53 class MockEpollServer : public FakeTimeEpollServer {
57 public: // type definitions 54 public: // type definitions
58 using EventQueue = std::unordered_multimap<int64_t, struct epoll_event>; 55 typedef base::hash_multimap<int64_t, struct epoll_event> EventQueue;
59 56
60 MockEpollServer(); 57 MockEpollServer();
61 ~MockEpollServer() override; 58 ~MockEpollServer() override;
62 59
63 // time_in_usec is the time at which the event specified 60 // time_in_usec is the time at which the event specified
64 // by 'ee' will be delivered. Note that it -is- possible 61 // by 'ee' will be delivered. Note that it -is- possible
65 // to add an event for a time which has already been passed.. 62 // to add an event for a time which has already been passed..
66 // .. upon the next time that the callbacks are invoked, 63 // .. upon the next time that the callbacks are invoked,
67 // all events which are in the 'past' will be delivered. 64 // all events which are in the 'past' will be delivered.
68 void AddEvent(int64_t time_in_usec, const struct epoll_event& ee) { 65 void AddEvent(int64_t time_in_usec, const struct epoll_event& ee) {
69 event_queue_.insert(std::make_pair(time_in_usec, ee)); 66 event_queue_.insert(std::make_pair(time_in_usec, ee));
70 } 67 }
71 68
72 // Advances the virtual 'now' by advancement_usec, 69 // Advances the virtual 'now' by advancement_usec,
73 // and ensure that the next invocation of 70 // and ensure that the next invocation of
74 // WaitForEventsAndExecuteCallbacks goes no farther than 71 // WaitForEventsAndExecuteCallbacks goes no farther than
75 // advancement_usec from the current time. 72 // advancement_usec from the current time.
76 void AdvanceByExactly(int64_t advancement_usec) { 73 void AdvanceByExactly(int64_t advancement_usec) {
77 until_in_usec_ = NowInUsec() + advancement_usec; 74 until_in_usec_ = NowInUsec() + advancement_usec;
78 set_now_in_usec(NowInUsec() + advancement_usec); 75 set_now_in_usec(NowInUsec() + advancement_usec);
79 } 76 }
80 77
81 // As above, except calls WaitForEventsAndExecuteCallbacks. 78 // As above, except calls WaitForEventsAndExecuteCallbacks.
82 void AdvanceByExactlyAndCallCallbacks(int64_t advancement_usec) { 79 void AdvanceByExactlyAndCallCallbacks(int64_t advancement_usec) {
83 AdvanceByExactly(advancement_usec); 80 AdvanceByExactly(advancement_usec);
84 WaitForEventsAndExecuteCallbacks(); 81 WaitForEventsAndExecuteCallbacks();
85 } 82 }
86 83
87 std::unordered_set<AlarmCB*>::size_type NumberOfAlarms() const { 84 base::hash_set<AlarmCB*>::size_type NumberOfAlarms() const {
88 return all_alarms_.size(); 85 return all_alarms_.size();
89 } 86 }
90 87
91 protected: // functions 88 protected: // functions
92 // These functions do nothing here, as we're not actually 89 // These functions do nothing here, as we're not actually
93 // using the epoll_* syscalls. 90 // using the epoll_* syscalls.
94 void DelFD(int fd) const override {} 91 void DelFD(int fd) const override {}
95 void AddFD(int fd, int event_mask) const override {} 92 void AddFD(int fd, int event_mask) const override {}
96 void ModFD(int fd, int event_mask) const override {} 93 void ModFD(int fd, int event_mask) const override {}
97 94
98 // Replaces the epoll_server's epoll_wait_impl. 95 // Replaces the epoll_server's epoll_wait_impl.
99 int epoll_wait_impl(int epfd, 96 int epoll_wait_impl(int epfd,
100 struct epoll_event* events, 97 struct epoll_event* events,
101 int max_events, 98 int max_events,
102 int timeout_in_ms) override; 99 int timeout_in_ms) override;
103 void SetNonblocking(int fd) override {} 100 void SetNonblocking(int fd) override {}
104 101
105 private: // members 102 private: // members
106 EventQueue event_queue_; 103 EventQueue event_queue_;
107 int64_t until_in_usec_; 104 int64_t until_in_usec_;
108 105
109 DISALLOW_COPY_AND_ASSIGN(MockEpollServer); 106 DISALLOW_COPY_AND_ASSIGN(MockEpollServer);
110 }; 107 };
111 108
112 } // namespace test 109 } // namespace test
113 } // namespace net 110 } // namespace net
114 111
115 #endif // NET_TOOLS_QUIC_TEST_TOOLS_MOCK_EPOLL_SERVER_H_ 112 #endif // NET_TOOLS_QUIC_TEST_TOOLS_MOCK_EPOLL_SERVER_H_
OLDNEW
« no previous file with comments | « net/tools/quic/quic_simple_server_session.h ('k') | net/url_request/url_request_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698