| OLD | NEW |
| 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 #include "dbus/bus.h" | 5 #include "dbus/bus.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "dbus/exported_object.h" | 11 #include "dbus/exported_object.h" |
| 12 #include "dbus/object_path.h" | 12 #include "dbus/object_path.h" |
| 13 #include "dbus/object_proxy.h" | 13 #include "dbus/object_proxy.h" |
| 14 #include "dbus/scoped_dbus_error.h" |
| 14 | 15 |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // Used to test AddFilterFunction(). | 20 // Used to test AddFilterFunction(). |
| 20 DBusHandlerResult DummyHandler(DBusConnection* connection, | 21 DBusHandlerResult DummyHandler(DBusConnection* connection, |
| 21 DBusMessage* raw_message, | 22 DBusMessage* raw_message, |
| 22 void* user_data) { | 23 void* user_data) { |
| 23 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 24 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 ASSERT_FALSE(bus->AddFilterFunction(&DummyHandler, &data1)); | 191 ASSERT_FALSE(bus->AddFilterFunction(&DummyHandler, &data1)); |
| 191 // Can add the same function with different data. | 192 // Can add the same function with different data. |
| 192 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data2)); | 193 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data2)); |
| 193 | 194 |
| 194 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data1)); | 195 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data1)); |
| 195 ASSERT_FALSE(bus->RemoveFilterFunction(&DummyHandler, &data1)); | 196 ASSERT_FALSE(bus->RemoveFilterFunction(&DummyHandler, &data1)); |
| 196 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data2)); | 197 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data2)); |
| 197 | 198 |
| 198 bus->ShutdownAndBlock(); | 199 bus->ShutdownAndBlock(); |
| 199 } | 200 } |
| 201 |
| 202 TEST(BusTest, DoubleAddAndRemoveMatch) { |
| 203 dbus::Bus::Options options; |
| 204 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); |
| 205 dbus::ScopedDBusError error; |
| 206 |
| 207 bus->Connect(); |
| 208 |
| 209 // Adds the same rule twice. |
| 210 bus->AddMatch( |
| 211 "type='signal',interface='org.chromium.TestService',path='/'", |
| 212 error.get()); |
| 213 ASSERT_FALSE(error.is_set()); |
| 214 |
| 215 bus->AddMatch( |
| 216 "type='signal',interface='org.chromium.TestService',path='/'", |
| 217 error.get()); |
| 218 ASSERT_FALSE(error.is_set()); |
| 219 |
| 220 // Removes the same rule twice. |
| 221 ASSERT_TRUE(bus->RemoveMatch( |
| 222 "type='signal',interface='org.chromium.TestService',path='/'", |
| 223 error.get())); |
| 224 ASSERT_FALSE(error.is_set()); |
| 225 |
| 226 // The rule should be still in the bus since it was removed only once. |
| 227 // A second removal shouldn't give an error. |
| 228 ASSERT_TRUE(bus->RemoveMatch( |
| 229 "type='signal',interface='org.chromium.TestService',path='/'", |
| 230 error.get())); |
| 231 ASSERT_FALSE(error.is_set()); |
| 232 |
| 233 // A third attemp to remove the same rule should fail. |
| 234 ASSERT_FALSE(bus->RemoveMatch( |
| 235 "type='signal',interface='org.chromium.TestService',path='/'", |
| 236 error.get())); |
| 237 |
| 238 bus->ShutdownAndBlock(); |
| 239 } |
| OLD | NEW |