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 dbus::Bus::Options options; |
| 89 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); |
| 90 |
| 91 dbus::ObjectProxy* object_proxy1 = |
| 92 bus->GetObjectProxy("org.chromium.TestService", |
| 93 dbus::ObjectPath("/org/chromium/TestObject")); |
| 94 ASSERT_TRUE(object_proxy1); |
| 95 |
| 96 // Increment the reference count to the object proxy to avoid destroying it |
| 97 // while removing the object. |
| 98 object_proxy1->AddRef(); |
| 99 |
| 100 // Remove the object from the bus. This will invalidate any other usage of |
| 101 // object_proxy1 other than destroy it. |
| 102 bus->RemoveObjectProxy("org.chromium.TestService", |
| 103 dbus::ObjectPath("/org/chromium/TestObject")); |
| 104 |
| 105 // This should return a different object because the first object still |
| 106 // exists thanks to the increased reference. |
| 107 dbus::ObjectProxy* object_proxy2 = |
| 108 bus->GetObjectProxy("org.chromium.TestService", |
| 109 dbus::ObjectPath("/org/chromium/TestObject")); |
| 110 ASSERT_TRUE(object_proxy2); |
| 111 EXPECT_NE(object_proxy1, object_proxy2); |
| 112 |
| 113 // Release object_proxy1. |
| 114 object_proxy1->Release(); |
| 115 |
| 116 bus->ShutdownAndBlock(); |
| 117 } |
| 118 |
87 TEST(BusTest, GetExportedObject) { | 119 TEST(BusTest, GetExportedObject) { |
88 dbus::Bus::Options options; | 120 dbus::Bus::Options options; |
89 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); | 121 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); |
90 | 122 |
91 dbus::ExportedObject* object_proxy1 = | 123 dbus::ExportedObject* object_proxy1 = |
92 bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); | 124 bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); |
93 ASSERT_TRUE(object_proxy1); | 125 ASSERT_TRUE(object_proxy1); |
94 | 126 |
95 // This should return the same object. | 127 // This should return the same object. |
96 dbus::ExportedObject* object_proxy2 = | 128 dbus::ExportedObject* object_proxy2 = |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 ASSERT_FALSE(bus->AddFilterFunction(&DummyHandler, &data1)); | 214 ASSERT_FALSE(bus->AddFilterFunction(&DummyHandler, &data1)); |
183 // Can add the same function with different data. | 215 // Can add the same function with different data. |
184 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data2)); | 216 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data2)); |
185 | 217 |
186 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data1)); | 218 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data1)); |
187 ASSERT_FALSE(bus->RemoveFilterFunction(&DummyHandler, &data1)); | 219 ASSERT_FALSE(bus->RemoveFilterFunction(&DummyHandler, &data1)); |
188 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data2)); | 220 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data2)); |
189 | 221 |
190 bus->ShutdownAndBlock(); | 222 bus->ShutdownAndBlock(); |
191 } | 223 } |
OLD | NEW |