OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifdef HAVE_DBUS_GLIB | 11 #ifdef HAVE_DBUS_GLIB |
12 | 12 |
| 13 #include <memory> |
| 14 |
13 #include "webrtc/base/dbus.h" | 15 #include "webrtc/base/dbus.h" |
14 #include "webrtc/base/gunit.h" | 16 #include "webrtc/base/gunit.h" |
15 #include "webrtc/base/thread.h" | 17 #include "webrtc/base/thread.h" |
16 | 18 |
17 namespace rtc { | 19 namespace rtc { |
18 | 20 |
19 #define SIG_NAME "NameAcquired" | 21 #define SIG_NAME "NameAcquired" |
20 | 22 |
21 static const uint32_t kTimeoutMs = 5000U; | 23 static const uint32_t kTimeoutMs = 5000U; |
22 | 24 |
(...skipping 21 matching lines...) Expand all Loading... |
44 virtual void ProcessSignal(DBusMessage *message) { | 46 virtual void ProcessSignal(DBusMessage *message) { |
45 EXPECT_TRUE(message != NULL); | 47 EXPECT_TRUE(message != NULL); |
46 message_received_ = true; | 48 message_received_ = true; |
47 } | 49 } |
48 | 50 |
49 bool message_received_; | 51 bool message_received_; |
50 }; | 52 }; |
51 | 53 |
52 TEST(DBusMonitorTest, StartStopStartStop) { | 54 TEST(DBusMonitorTest, StartStopStartStop) { |
53 DBusSigFilterTest filter; | 55 DBusSigFilterTest filter; |
54 rtc::scoped_ptr<rtc::DBusMonitor> monitor; | 56 std::unique_ptr<rtc::DBusMonitor> monitor; |
55 monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); | 57 monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); |
56 if (monitor) { | 58 if (monitor) { |
57 EXPECT_TRUE(monitor->AddFilter(&filter)); | 59 EXPECT_TRUE(monitor->AddFilter(&filter)); |
58 | 60 |
59 EXPECT_TRUE(monitor->StopMonitoring()); | 61 EXPECT_TRUE(monitor->StopMonitoring()); |
60 EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_NOT_INITIALIZED); | 62 EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_NOT_INITIALIZED); |
61 | 63 |
62 EXPECT_TRUE(monitor->StartMonitoring()); | 64 EXPECT_TRUE(monitor->StartMonitoring()); |
63 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs); | 65 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs); |
64 EXPECT_TRUE(monitor->StopMonitoring()); | 66 EXPECT_TRUE(monitor->StopMonitoring()); |
(...skipping 11 matching lines...) Expand all Loading... |
76 LOG(LS_WARNING) << "DBus Monitor not started. Skipping test."; | 78 LOG(LS_WARNING) << "DBus Monitor not started. Skipping test."; |
77 } | 79 } |
78 } | 80 } |
79 | 81 |
80 // DBusMonitorTest listens on DBus service itself for "NameAcquired" signal. | 82 // DBusMonitorTest listens on DBus service itself for "NameAcquired" signal. |
81 // This signal should be received when the application connects to DBus | 83 // This signal should be received when the application connects to DBus |
82 // service and gains ownership of a name. | 84 // service and gains ownership of a name. |
83 // This test is to make sure that we capture the "NameAcquired" signal. | 85 // This test is to make sure that we capture the "NameAcquired" signal. |
84 TEST(DBusMonitorTest, ReceivedNameAcquiredSignal) { | 86 TEST(DBusMonitorTest, ReceivedNameAcquiredSignal) { |
85 DBusSigFilterTest filter; | 87 DBusSigFilterTest filter; |
86 rtc::scoped_ptr<rtc::DBusMonitor> monitor; | 88 std::unique_ptr<rtc::DBusMonitor> monitor; |
87 monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); | 89 monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); |
88 if (monitor) { | 90 if (monitor) { |
89 EXPECT_TRUE(monitor->AddFilter(&filter)); | 91 EXPECT_TRUE(monitor->AddFilter(&filter)); |
90 | 92 |
91 EXPECT_TRUE(monitor->StartMonitoring()); | 93 EXPECT_TRUE(monitor->StartMonitoring()); |
92 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs); | 94 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs); |
93 EXPECT_TRUE_WAIT(filter.MessageReceived(), kTimeoutMs); | 95 EXPECT_TRUE_WAIT(filter.MessageReceived(), kTimeoutMs); |
94 EXPECT_TRUE(monitor->StopMonitoring()); | 96 EXPECT_TRUE(monitor->StopMonitoring()); |
95 EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED); | 97 EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED); |
96 } else { | 98 } else { |
97 LOG(LS_WARNING) << "DBus Monitor not started. Skipping test."; | 99 LOG(LS_WARNING) << "DBus Monitor not started. Skipping test."; |
98 } | 100 } |
99 } | 101 } |
100 | 102 |
101 TEST(DBusMonitorTest, ConcurrentMonitors) { | 103 TEST(DBusMonitorTest, ConcurrentMonitors) { |
102 DBusSigFilterTest filter1; | 104 DBusSigFilterTest filter1; |
103 rtc::scoped_ptr<rtc::DBusMonitor> monitor1; | 105 std::unique_ptr<rtc::DBusMonitor> monitor1; |
104 monitor1.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); | 106 monitor1.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); |
105 if (monitor1) { | 107 if (monitor1) { |
106 EXPECT_TRUE(monitor1->AddFilter(&filter1)); | 108 EXPECT_TRUE(monitor1->AddFilter(&filter1)); |
107 DBusSigFilterTest filter2; | 109 DBusSigFilterTest filter2; |
108 rtc::scoped_ptr<rtc::DBusMonitor> monitor2; | 110 std::unique_ptr<rtc::DBusMonitor> monitor2; |
109 monitor2.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); | 111 monitor2.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); |
110 EXPECT_TRUE(monitor2->AddFilter(&filter2)); | 112 EXPECT_TRUE(monitor2->AddFilter(&filter2)); |
111 | 113 |
112 EXPECT_TRUE(monitor1->StartMonitoring()); | 114 EXPECT_TRUE(monitor1->StartMonitoring()); |
113 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor1->GetStatus(), kTimeoutMs); | 115 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor1->GetStatus(), kTimeoutMs); |
114 EXPECT_TRUE(monitor2->StartMonitoring()); | 116 EXPECT_TRUE(monitor2->StartMonitoring()); |
115 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor2->GetStatus(), kTimeoutMs); | 117 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor2->GetStatus(), kTimeoutMs); |
116 | 118 |
117 EXPECT_TRUE_WAIT(filter2.MessageReceived(), kTimeoutMs); | 119 EXPECT_TRUE_WAIT(filter2.MessageReceived(), kTimeoutMs); |
118 EXPECT_TRUE(monitor2->StopMonitoring()); | 120 EXPECT_TRUE(monitor2->StopMonitoring()); |
119 EXPECT_EQ(monitor2->GetStatus(), DBusMonitor::DMS_STOPPED); | 121 EXPECT_EQ(monitor2->GetStatus(), DBusMonitor::DMS_STOPPED); |
120 | 122 |
121 EXPECT_TRUE_WAIT(filter1.MessageReceived(), kTimeoutMs); | 123 EXPECT_TRUE_WAIT(filter1.MessageReceived(), kTimeoutMs); |
122 EXPECT_TRUE(monitor1->StopMonitoring()); | 124 EXPECT_TRUE(monitor1->StopMonitoring()); |
123 EXPECT_EQ(monitor1->GetStatus(), DBusMonitor::DMS_STOPPED); | 125 EXPECT_EQ(monitor1->GetStatus(), DBusMonitor::DMS_STOPPED); |
124 } else { | 126 } else { |
125 LOG(LS_WARNING) << "DBus Monitor not started. Skipping test."; | 127 LOG(LS_WARNING) << "DBus Monitor not started. Skipping test."; |
126 } | 128 } |
127 } | 129 } |
128 | 130 |
129 TEST(DBusMonitorTest, ConcurrentFilters) { | 131 TEST(DBusMonitorTest, ConcurrentFilters) { |
130 DBusSigFilterTest filter1; | 132 DBusSigFilterTest filter1; |
131 DBusSigFilterTest filter2; | 133 DBusSigFilterTest filter2; |
132 rtc::scoped_ptr<rtc::DBusMonitor> monitor; | 134 std::unique_ptr<rtc::DBusMonitor> monitor; |
133 monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); | 135 monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); |
134 if (monitor) { | 136 if (monitor) { |
135 EXPECT_TRUE(monitor->AddFilter(&filter1)); | 137 EXPECT_TRUE(monitor->AddFilter(&filter1)); |
136 EXPECT_TRUE(monitor->AddFilter(&filter2)); | 138 EXPECT_TRUE(monitor->AddFilter(&filter2)); |
137 | 139 |
138 EXPECT_TRUE(monitor->StartMonitoring()); | 140 EXPECT_TRUE(monitor->StartMonitoring()); |
139 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs); | 141 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs); |
140 | 142 |
141 EXPECT_TRUE_WAIT(filter1.MessageReceived(), kTimeoutMs); | 143 EXPECT_TRUE_WAIT(filter1.MessageReceived(), kTimeoutMs); |
142 EXPECT_TRUE_WAIT(filter2.MessageReceived(), kTimeoutMs); | 144 EXPECT_TRUE_WAIT(filter2.MessageReceived(), kTimeoutMs); |
143 | 145 |
144 EXPECT_TRUE(monitor->StopMonitoring()); | 146 EXPECT_TRUE(monitor->StopMonitoring()); |
145 EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED); | 147 EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED); |
146 } else { | 148 } else { |
147 LOG(LS_WARNING) << "DBus Monitor not started. Skipping test."; | 149 LOG(LS_WARNING) << "DBus Monitor not started. Skipping test."; |
148 } | 150 } |
149 } | 151 } |
150 | 152 |
151 TEST(DBusMonitorTest, NoAddFilterIfRunning) { | 153 TEST(DBusMonitorTest, NoAddFilterIfRunning) { |
152 DBusSigFilterTest filter1; | 154 DBusSigFilterTest filter1; |
153 DBusSigFilterTest filter2; | 155 DBusSigFilterTest filter2; |
154 rtc::scoped_ptr<rtc::DBusMonitor> monitor; | 156 std::unique_ptr<rtc::DBusMonitor> monitor; |
155 monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); | 157 monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); |
156 if (monitor) { | 158 if (monitor) { |
157 EXPECT_TRUE(monitor->AddFilter(&filter1)); | 159 EXPECT_TRUE(monitor->AddFilter(&filter1)); |
158 | 160 |
159 EXPECT_TRUE(monitor->StartMonitoring()); | 161 EXPECT_TRUE(monitor->StartMonitoring()); |
160 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs); | 162 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs); |
161 EXPECT_FALSE(monitor->AddFilter(&filter2)); | 163 EXPECT_FALSE(monitor->AddFilter(&filter2)); |
162 | 164 |
163 EXPECT_TRUE(monitor->StopMonitoring()); | 165 EXPECT_TRUE(monitor->StopMonitoring()); |
164 EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED); | 166 EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED); |
165 } else { | 167 } else { |
166 LOG(LS_WARNING) << "DBus Monitor not started. Skipping test."; | 168 LOG(LS_WARNING) << "DBus Monitor not started. Skipping test."; |
167 } | 169 } |
168 } | 170 } |
169 | 171 |
170 TEST(DBusMonitorTest, AddFilterAfterStop) { | 172 TEST(DBusMonitorTest, AddFilterAfterStop) { |
171 DBusSigFilterTest filter1; | 173 DBusSigFilterTest filter1; |
172 DBusSigFilterTest filter2; | 174 DBusSigFilterTest filter2; |
173 rtc::scoped_ptr<rtc::DBusMonitor> monitor; | 175 std::unique_ptr<rtc::DBusMonitor> monitor; |
174 monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); | 176 monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); |
175 if (monitor) { | 177 if (monitor) { |
176 EXPECT_TRUE(monitor->AddFilter(&filter1)); | 178 EXPECT_TRUE(monitor->AddFilter(&filter1)); |
177 EXPECT_TRUE(monitor->StartMonitoring()); | 179 EXPECT_TRUE(monitor->StartMonitoring()); |
178 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs); | 180 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs); |
179 EXPECT_TRUE_WAIT(filter1.MessageReceived(), kTimeoutMs); | 181 EXPECT_TRUE_WAIT(filter1.MessageReceived(), kTimeoutMs); |
180 EXPECT_TRUE(monitor->StopMonitoring()); | 182 EXPECT_TRUE(monitor->StopMonitoring()); |
181 EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED); | 183 EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED); |
182 | 184 |
183 EXPECT_TRUE(monitor->AddFilter(&filter2)); | 185 EXPECT_TRUE(monitor->AddFilter(&filter2)); |
184 EXPECT_TRUE(monitor->StartMonitoring()); | 186 EXPECT_TRUE(monitor->StartMonitoring()); |
185 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs); | 187 EXPECT_EQ_WAIT(DBusMonitor::DMS_RUNNING, monitor->GetStatus(), kTimeoutMs); |
186 EXPECT_TRUE_WAIT(filter1.MessageReceived(), kTimeoutMs); | 188 EXPECT_TRUE_WAIT(filter1.MessageReceived(), kTimeoutMs); |
187 EXPECT_TRUE_WAIT(filter2.MessageReceived(), kTimeoutMs); | 189 EXPECT_TRUE_WAIT(filter2.MessageReceived(), kTimeoutMs); |
188 EXPECT_TRUE(monitor->StopMonitoring()); | 190 EXPECT_TRUE(monitor->StopMonitoring()); |
189 EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED); | 191 EXPECT_EQ(monitor->GetStatus(), DBusMonitor::DMS_STOPPED); |
190 } else { | 192 } else { |
191 LOG(LS_WARNING) << "DBus Monitor not started. Skipping test."; | 193 LOG(LS_WARNING) << "DBus Monitor not started. Skipping test."; |
192 } | 194 } |
193 } | 195 } |
194 | 196 |
195 TEST(DBusMonitorTest, StopRightAfterStart) { | 197 TEST(DBusMonitorTest, StopRightAfterStart) { |
196 DBusSigFilterTest filter; | 198 DBusSigFilterTest filter; |
197 rtc::scoped_ptr<rtc::DBusMonitor> monitor; | 199 std::unique_ptr<rtc::DBusMonitor> monitor; |
198 monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); | 200 monitor.reset(rtc::DBusMonitor::Create(DBUS_BUS_SYSTEM)); |
199 if (monitor) { | 201 if (monitor) { |
200 EXPECT_TRUE(monitor->AddFilter(&filter)); | 202 EXPECT_TRUE(monitor->AddFilter(&filter)); |
201 | 203 |
202 EXPECT_TRUE(monitor->StartMonitoring()); | 204 EXPECT_TRUE(monitor->StartMonitoring()); |
203 EXPECT_TRUE(monitor->StopMonitoring()); | 205 EXPECT_TRUE(monitor->StopMonitoring()); |
204 | 206 |
205 // Stop the monitoring thread right after it had been started. | 207 // Stop the monitoring thread right after it had been started. |
206 // If the monitoring thread got a chance to receive a DBus signal, it would | 208 // If the monitoring thread got a chance to receive a DBus signal, it would |
207 // post a message to the main thread and signal the main thread wakeup. | 209 // post a message to the main thread and signal the main thread wakeup. |
(...skipping 15 matching lines...) Expand all Loading... |
223 (DBUS_TYPE "='" DBUS_SIGNAL "'," DBUS_PATH "='p'," | 225 (DBUS_TYPE "='" DBUS_SIGNAL "'," DBUS_PATH "='p'," |
224 DBUS_INTERFACE "='i'")); | 226 DBUS_INTERFACE "='i'")); |
225 EXPECT_EQ(DBusSigFilter::BuildFilterString("p","i","m"), | 227 EXPECT_EQ(DBusSigFilter::BuildFilterString("p","i","m"), |
226 (DBUS_TYPE "='" DBUS_SIGNAL "'," DBUS_PATH "='p'," | 228 (DBUS_TYPE "='" DBUS_SIGNAL "'," DBUS_PATH "='p'," |
227 DBUS_INTERFACE "='i'," DBUS_MEMBER "='m'")); | 229 DBUS_INTERFACE "='i'," DBUS_MEMBER "='m'")); |
228 } | 230 } |
229 | 231 |
230 } // namespace rtc | 232 } // namespace rtc |
231 | 233 |
232 #endif // HAVE_DBUS_GLIB | 234 #endif // HAVE_DBUS_GLIB |
OLD | NEW |