OLD | NEW |
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 "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_proxy.h" | 12 #include "dbus/object_proxy.h" |
13 | 13 |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
| 16 namespace { |
| 17 |
| 18 // Used to test AddFilterFunction(). |
| 19 DBusHandlerResult DummyHandler(DBusConnection* connection, |
| 20 DBusMessage* raw_message, |
| 21 void* user_data) { |
| 22 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
16 TEST(BusTest, GetObjectProxy) { | 27 TEST(BusTest, GetObjectProxy) { |
17 dbus::Bus::Options options; | 28 dbus::Bus::Options options; |
18 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); | 29 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); |
19 | 30 |
20 dbus::ObjectProxy* object_proxy1 = | 31 dbus::ObjectProxy* object_proxy1 = |
21 bus->GetObjectProxy("org.chromium.TestService", | 32 bus->GetObjectProxy("org.chromium.TestService", |
22 "/org/chromium/TestObject"); | 33 "/org/chromium/TestObject"); |
23 ASSERT_TRUE(object_proxy1); | 34 ASSERT_TRUE(object_proxy1); |
24 | 35 |
25 // This should return the same object. | 36 // This should return the same object. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 dbus::Bus::Options options; | 93 dbus::Bus::Options options; |
83 options.dbus_thread_message_loop_proxy = dbus_thread.message_loop_proxy(); | 94 options.dbus_thread_message_loop_proxy = dbus_thread.message_loop_proxy(); |
84 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); | 95 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); |
85 ASSERT_FALSE(bus->shutdown_completed()); | 96 ASSERT_FALSE(bus->shutdown_completed()); |
86 | 97 |
87 // Shut down synchronously. | 98 // Shut down synchronously. |
88 bus->ShutdownOnDBusThreadAndBlock(); | 99 bus->ShutdownOnDBusThreadAndBlock(); |
89 EXPECT_TRUE(bus->shutdown_completed()); | 100 EXPECT_TRUE(bus->shutdown_completed()); |
90 dbus_thread.Stop(); | 101 dbus_thread.Stop(); |
91 } | 102 } |
| 103 |
| 104 TEST(BusTest, AddFilterFunction) { |
| 105 dbus::Bus::Options options; |
| 106 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); |
| 107 // Should connect before calling AddFilterFunction(). |
| 108 bus->Connect(); |
| 109 |
| 110 int data1 = 100; |
| 111 int data2 = 200; |
| 112 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data1)); |
| 113 // Cannot add the same function with the same data. |
| 114 ASSERT_FALSE(bus->AddFilterFunction(&DummyHandler, &data1)); |
| 115 // Can add the same function with different data. |
| 116 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data2)); |
| 117 |
| 118 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data1)); |
| 119 ASSERT_FALSE(bus->RemoveFilterFunction(&DummyHandler, &data1)); |
| 120 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data2)); |
| 121 |
| 122 bus->ShutdownAndBlock(); |
| 123 } |
OLD | NEW |