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