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" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 bus->GetObjectProxyWithOptions( | 77 bus->GetObjectProxyWithOptions( |
78 "org.chromium.TestService", | 78 "org.chromium.TestService", |
79 dbus::ObjectPath("/org/chromium/DifferentTestObject"), | 79 dbus::ObjectPath("/org/chromium/DifferentTestObject"), |
80 dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); | 80 dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); |
81 ASSERT_TRUE(object_proxy3); | 81 ASSERT_TRUE(object_proxy3); |
82 EXPECT_NE(object_proxy1, object_proxy3); | 82 EXPECT_NE(object_proxy1, object_proxy3); |
83 | 83 |
84 bus->ShutdownAndBlock(); | 84 bus->ShutdownAndBlock(); |
85 } | 85 } |
86 | 86 |
| 87 TEST(BusTest, RemoveObjectProxy) { |
| 88 // Setup the current thread's MessageLoop. |
| 89 MessageLoop message_loop; |
| 90 |
| 91 // Start the D-Bus thread. |
| 92 base::Thread::Options thread_options; |
| 93 thread_options.message_loop_type = MessageLoop::TYPE_IO; |
| 94 base::Thread dbus_thread("D-Bus thread"); |
| 95 dbus_thread.StartWithOptions(thread_options); |
| 96 |
| 97 // Create the bus. |
| 98 dbus::Bus::Options options; |
| 99 options.dbus_thread_message_loop_proxy = dbus_thread.message_loop_proxy(); |
| 100 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); |
| 101 ASSERT_FALSE(bus->shutdown_completed()); |
| 102 |
| 103 // Try to remove a non existant object proxy should return false. |
| 104 ASSERT_FALSE( |
| 105 bus->RemoveObjectProxy("org.chromium.TestService", |
| 106 dbus::ObjectPath("/org/chromium/TestObject"), |
| 107 base::Bind(&base::DoNothing))); |
| 108 |
| 109 dbus::ObjectProxy* object_proxy1 = |
| 110 bus->GetObjectProxy("org.chromium.TestService", |
| 111 dbus::ObjectPath("/org/chromium/TestObject")); |
| 112 ASSERT_TRUE(object_proxy1); |
| 113 |
| 114 // Increment the reference count to the object proxy to avoid destroying it |
| 115 // while removing the object. |
| 116 object_proxy1->AddRef(); |
| 117 |
| 118 // Remove the object from the bus. This will invalidate any other usage of |
| 119 // object_proxy1 other than destroy it. We keep this object for a comparison |
| 120 // at a later time. |
| 121 ASSERT_TRUE( |
| 122 bus->RemoveObjectProxy("org.chromium.TestService", |
| 123 dbus::ObjectPath("/org/chromium/TestObject"), |
| 124 base::Bind(&base::DoNothing))); |
| 125 |
| 126 // This should return a different object because the first object was removed |
| 127 // from the bus, but not deleted from memory. |
| 128 dbus::ObjectProxy* object_proxy2 = |
| 129 bus->GetObjectProxy("org.chromium.TestService", |
| 130 dbus::ObjectPath("/org/chromium/TestObject")); |
| 131 ASSERT_TRUE(object_proxy2); |
| 132 |
| 133 // Compare the new object with the first object. The first object still exists |
| 134 // thanks to the increased reference. |
| 135 EXPECT_NE(object_proxy1, object_proxy2); |
| 136 |
| 137 // Release object_proxy1. |
| 138 object_proxy1->Release(); |
| 139 |
| 140 // Shut down synchronously. |
| 141 bus->ShutdownOnDBusThreadAndBlock(); |
| 142 EXPECT_TRUE(bus->shutdown_completed()); |
| 143 dbus_thread.Stop(); |
| 144 } |
| 145 |
87 TEST(BusTest, GetExportedObject) { | 146 TEST(BusTest, GetExportedObject) { |
88 dbus::Bus::Options options; | 147 dbus::Bus::Options options; |
89 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); | 148 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); |
90 | 149 |
91 dbus::ExportedObject* object_proxy1 = | 150 dbus::ExportedObject* object_proxy1 = |
92 bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); | 151 bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); |
93 ASSERT_TRUE(object_proxy1); | 152 ASSERT_TRUE(object_proxy1); |
94 | 153 |
95 // This should return the same object. | 154 // This should return the same object. |
96 dbus::ExportedObject* object_proxy2 = | 155 dbus::ExportedObject* object_proxy2 = |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 ASSERT_FALSE(bus->AddFilterFunction(&DummyHandler, &data1)); | 249 ASSERT_FALSE(bus->AddFilterFunction(&DummyHandler, &data1)); |
191 // Can add the same function with different data. | 250 // Can add the same function with different data. |
192 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data2)); | 251 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data2)); |
193 | 252 |
194 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data1)); | 253 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data1)); |
195 ASSERT_FALSE(bus->RemoveFilterFunction(&DummyHandler, &data1)); | 254 ASSERT_FALSE(bus->RemoveFilterFunction(&DummyHandler, &data1)); |
196 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data2)); | 255 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data2)); |
197 | 256 |
198 bus->ShutdownAndBlock(); | 257 bus->ShutdownAndBlock(); |
199 } | 258 } |
OLD | NEW |