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" | |
13 #include "dbus/object_proxy.h" | 12 #include "dbus/object_proxy.h" |
14 | 13 |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 | 15 |
17 namespace { | 16 namespace { |
18 | 17 |
19 // Used to test AddFilterFunction(). | 18 // Used to test AddFilterFunction(). |
20 DBusHandlerResult DummyHandler(DBusConnection* connection, | 19 DBusHandlerResult DummyHandler(DBusConnection* connection, |
21 DBusMessage* raw_message, | 20 DBusMessage* raw_message, |
22 void* user_data) { | 21 void* user_data) { |
23 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 22 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
24 } | 23 } |
25 | 24 |
26 } // namespace | 25 } // namespace |
27 | 26 |
28 TEST(BusTest, GetObjectProxy) { | 27 TEST(BusTest, GetObjectProxy) { |
29 dbus::Bus::Options options; | 28 dbus::Bus::Options options; |
30 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); | 29 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); |
31 | 30 |
32 dbus::ObjectProxy* object_proxy1 = | 31 dbus::ObjectProxy* object_proxy1 = |
33 bus->GetObjectProxy("org.chromium.TestService", | 32 bus->GetObjectProxy("org.chromium.TestService", |
34 dbus::ObjectPath("/org/chromium/TestObject")); | 33 "/org/chromium/TestObject"); |
35 ASSERT_TRUE(object_proxy1); | 34 ASSERT_TRUE(object_proxy1); |
36 | 35 |
37 // This should return the same object. | 36 // This should return the same object. |
38 dbus::ObjectProxy* object_proxy2 = | 37 dbus::ObjectProxy* object_proxy2 = |
39 bus->GetObjectProxy("org.chromium.TestService", | 38 bus->GetObjectProxy("org.chromium.TestService", |
40 dbus::ObjectPath("/org/chromium/TestObject")); | 39 "/org/chromium/TestObject"); |
41 ASSERT_TRUE(object_proxy2); | 40 ASSERT_TRUE(object_proxy2); |
42 EXPECT_EQ(object_proxy1, object_proxy2); | 41 EXPECT_EQ(object_proxy1, object_proxy2); |
43 | 42 |
44 // This should not. | 43 // This should not. |
45 dbus::ObjectProxy* object_proxy3 = | 44 dbus::ObjectProxy* object_proxy3 = |
46 bus->GetObjectProxy( | 45 bus->GetObjectProxy("org.chromium.TestService", |
47 "org.chromium.TestService", | 46 "/org/chromium/DifferentTestObject"); |
48 dbus::ObjectPath("/org/chromium/DifferentTestObject")); | |
49 ASSERT_TRUE(object_proxy3); | 47 ASSERT_TRUE(object_proxy3); |
50 EXPECT_NE(object_proxy1, object_proxy3); | 48 EXPECT_NE(object_proxy1, object_proxy3); |
51 | 49 |
52 bus->ShutdownAndBlock(); | 50 bus->ShutdownAndBlock(); |
53 } | 51 } |
54 | 52 |
55 TEST(BusTest, GetObjectProxyIgnoreUnknownService) { | 53 TEST(BusTest, GetObjectProxyIgnoreUnknownService) { |
56 dbus::Bus::Options options; | 54 dbus::Bus::Options options; |
57 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); | 55 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); |
58 | 56 |
59 dbus::ObjectProxy* object_proxy1 = | 57 dbus::ObjectProxy* object_proxy1 = |
60 bus->GetObjectProxyWithOptions( | 58 bus->GetObjectProxyWithOptions( |
61 "org.chromium.TestService", | 59 "org.chromium.TestService", |
62 dbus::ObjectPath("/org/chromium/TestObject"), | 60 "/org/chromium/TestObject", |
63 dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); | 61 dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); |
64 ASSERT_TRUE(object_proxy1); | 62 ASSERT_TRUE(object_proxy1); |
65 | 63 |
66 // This should return the same object. | 64 // This should return the same object. |
67 dbus::ObjectProxy* object_proxy2 = | 65 dbus::ObjectProxy* object_proxy2 = |
68 bus->GetObjectProxyWithOptions( | 66 bus->GetObjectProxyWithOptions( |
69 "org.chromium.TestService", | 67 "org.chromium.TestService", |
70 dbus::ObjectPath("/org/chromium/TestObject"), | 68 "/org/chromium/TestObject", |
71 dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); | 69 dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); |
72 ASSERT_TRUE(object_proxy2); | 70 ASSERT_TRUE(object_proxy2); |
73 EXPECT_EQ(object_proxy1, object_proxy2); | 71 EXPECT_EQ(object_proxy1, object_proxy2); |
74 | 72 |
75 // This should not. | 73 // This should not. |
76 dbus::ObjectProxy* object_proxy3 = | 74 dbus::ObjectProxy* object_proxy3 = |
77 bus->GetObjectProxyWithOptions( | 75 bus->GetObjectProxyWithOptions( |
78 "org.chromium.TestService", | 76 "org.chromium.TestService", |
79 dbus::ObjectPath("/org/chromium/DifferentTestObject"), | 77 "/org/chromium/DifferentTestObject", |
80 dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); | 78 dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); |
81 ASSERT_TRUE(object_proxy3); | 79 ASSERT_TRUE(object_proxy3); |
82 EXPECT_NE(object_proxy1, object_proxy3); | 80 EXPECT_NE(object_proxy1, object_proxy3); |
83 | 81 |
84 bus->ShutdownAndBlock(); | 82 bus->ShutdownAndBlock(); |
85 } | 83 } |
86 | 84 |
87 TEST(BusTest, GetExportedObject) { | 85 TEST(BusTest, GetExportedObject) { |
88 dbus::Bus::Options options; | 86 dbus::Bus::Options options; |
89 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); | 87 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); |
90 | 88 |
91 dbus::ExportedObject* object_proxy1 = | 89 dbus::ExportedObject* object_proxy1 = |
92 bus->GetExportedObject("org.chromium.TestService", | 90 bus->GetExportedObject("org.chromium.TestService", |
93 dbus::ObjectPath("/org/chromium/TestObject")); | 91 "/org/chromium/TestObject"); |
94 ASSERT_TRUE(object_proxy1); | 92 ASSERT_TRUE(object_proxy1); |
95 | 93 |
96 // This should return the same object. | 94 // This should return the same object. |
97 dbus::ExportedObject* object_proxy2 = | 95 dbus::ExportedObject* object_proxy2 = |
98 bus->GetExportedObject("org.chromium.TestService", | 96 bus->GetExportedObject("org.chromium.TestService", |
99 dbus::ObjectPath("/org/chromium/TestObject")); | 97 "/org/chromium/TestObject"); |
100 ASSERT_TRUE(object_proxy2); | 98 ASSERT_TRUE(object_proxy2); |
101 EXPECT_EQ(object_proxy1, object_proxy2); | 99 EXPECT_EQ(object_proxy1, object_proxy2); |
102 | 100 |
103 // This should not. | 101 // This should not. |
104 dbus::ExportedObject* object_proxy3 = | 102 dbus::ExportedObject* object_proxy3 = |
105 bus->GetExportedObject( | 103 bus->GetExportedObject("org.chromium.TestService", |
106 "org.chromium.TestService", | 104 "/org/chromium/DifferentTestObject"); |
107 dbus::ObjectPath("/org/chromium/DifferentTestObject")); | |
108 ASSERT_TRUE(object_proxy3); | 105 ASSERT_TRUE(object_proxy3); |
109 EXPECT_NE(object_proxy1, object_proxy3); | 106 EXPECT_NE(object_proxy1, object_proxy3); |
110 | 107 |
111 bus->ShutdownAndBlock(); | 108 bus->ShutdownAndBlock(); |
112 } | 109 } |
113 | 110 |
114 TEST(BusTest, ShutdownAndBlock) { | 111 TEST(BusTest, ShutdownAndBlock) { |
115 dbus::Bus::Options options; | 112 dbus::Bus::Options options; |
116 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); | 113 scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); |
117 ASSERT_FALSE(bus->shutdown_completed()); | 114 ASSERT_FALSE(bus->shutdown_completed()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 ASSERT_FALSE(bus->AddFilterFunction(&DummyHandler, &data1)); | 150 ASSERT_FALSE(bus->AddFilterFunction(&DummyHandler, &data1)); |
154 // Can add the same function with different data. | 151 // Can add the same function with different data. |
155 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data2)); | 152 ASSERT_TRUE(bus->AddFilterFunction(&DummyHandler, &data2)); |
156 | 153 |
157 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data1)); | 154 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data1)); |
158 ASSERT_FALSE(bus->RemoveFilterFunction(&DummyHandler, &data1)); | 155 ASSERT_FALSE(bus->RemoveFilterFunction(&DummyHandler, &data1)); |
159 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data2)); | 156 ASSERT_TRUE(bus->RemoveFilterFunction(&DummyHandler, &data2)); |
160 | 157 |
161 bus->ShutdownAndBlock(); | 158 bus->ShutdownAndBlock(); |
162 } | 159 } |
OLD | NEW |