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. | |
satorux1
2013/01/29 03:58:39
Maybe add: We keep this object for a comparison at
deymo
2013/01/29 04:09:05
Done.
| |
120 ASSERT_TRUE( | |
121 bus->RemoveObjectProxy("org.chromium.TestService", | |
122 dbus::ObjectPath("/org/chromium/TestObject"), | |
123 base::Bind(&base::DoNothing))); | |
124 | |
125 // This should return a different object because the first object still | |
126 // exists thanks to the increased reference. | |
satorux1
2013/01/29 03:58:39
The comment was a bit confusing. Maybe:
// This s
deymo
2013/01/29 04:09:05
Done but added the fact that the object_proxy1 is
| |
127 dbus::ObjectProxy* object_proxy2 = | |
128 bus->GetObjectProxy("org.chromium.TestService", | |
129 dbus::ObjectPath("/org/chromium/TestObject")); | |
130 ASSERT_TRUE(object_proxy2); | |
satorux1
2013/01/29 03:58:39
Then add something like
// Compare the new object
deymo
2013/01/29 04:09:05
Done.
| |
131 EXPECT_NE(object_proxy1, object_proxy2); | |
132 | |
133 // Release object_proxy1. | |
134 object_proxy1->Release(); | |
135 | |
136 // Shut down synchronously. | |
137 bus->ShutdownOnDBusThreadAndBlock(); | |
138 EXPECT_TRUE(bus->shutdown_completed()); | |
139 dbus_thread.Stop(); | |
140 } | |
141 | |
87 TEST(BusTest, GetExportedObject) { | 142 TEST(BusTest, GetExportedObject) { |
88 dbus::Bus::Options options; | 143 dbus::Bus::Options options; |
89 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); | 144 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); |
90 | 145 |
91 dbus::ExportedObject* object_proxy1 = | 146 dbus::ExportedObject* object_proxy1 = |
92 bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); | 147 bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); |
93 ASSERT_TRUE(object_proxy1); | 148 ASSERT_TRUE(object_proxy1); |
94 | 149 |
95 // This should return the same object. | 150 // This should return the same object. |
96 dbus::ExportedObject* object_proxy2 = | 151 dbus::ExportedObject* object_proxy2 = |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 ASSERT_FALSE(bus->AddFilterFunction(&DummyHandler, &data1)); | 245 ASSERT_FALSE(bus->AddFilterFunction(&DummyHandler, &data1)); |
191 // Can add the same function with different data. | 246 // Can add the same function with different data. |
192 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data2)); | 247 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data2)); |
193 | 248 |
194 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data1)); | 249 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data1)); |
195 ASSERT_FALSE(bus->RemoveFilterFunction(&DummyHandler, &data1)); | 250 ASSERT_FALSE(bus->RemoveFilterFunction(&DummyHandler, &data1)); |
196 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data2)); | 251 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data2)); |
197 | 252 |
198 bus->ShutdownAndBlock(); | 253 bus->ShutdownAndBlock(); |
199 } | 254 } |
OLD | NEW |