diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-13 06:37:19 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-13 06:37:19 +0000 |
commit | 2a57ca64048fe077fdf841cd49e76fa787a6c251 (patch) | |
tree | d36ef5ece5ac34e0beca6f5db4e773b05023d1ce /dbus | |
parent | acf883a85d1bafb447d4c4ebae4687da988bf1cc (diff) | |
download | chromium_src-2a57ca64048fe077fdf841cd49e76fa787a6c251.zip chromium_src-2a57ca64048fe077fdf841cd49e76fa787a6c251.tar.gz chromium_src-2a57ca64048fe077fdf841cd49e76fa787a6c251.tar.bz2 |
Cleanup: Put DBus unit tests in the dbus namespace, so one does not need to write dbus:: everywhere. Remove some other dbus:: usages in the dbus namespace.
Review URL: https://chromiumcodereview.appspot.com/16012018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206010 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/bus.cc | 16 | ||||
-rw-r--r-- | dbus/bus_unittest.cc | 116 | ||||
-rw-r--r-- | dbus/end_to_end_async_unittest.cc | 155 | ||||
-rw-r--r-- | dbus/end_to_end_sync_unittest.cc | 68 | ||||
-rw-r--r-- | dbus/exported_object.cc | 2 | ||||
-rw-r--r-- | dbus/message.cc | 8 | ||||
-rw-r--r-- | dbus/message_unittest.cc | 210 | ||||
-rw-r--r-- | dbus/mock_unittest.cc | 69 | ||||
-rw-r--r-- | dbus/object_manager_unittest.cc | 167 | ||||
-rw-r--r-- | dbus/property_unittest.cc | 50 | ||||
-rw-r--r-- | dbus/signal_sender_verification_unittest.cc | 40 | ||||
-rw-r--r-- | dbus/string_util_unittest.cc | 32 | ||||
-rw-r--r-- | dbus/test_service.cc | 113 | ||||
-rw-r--r-- | dbus/values_util_unittest.cc | 154 |
14 files changed, 610 insertions, 590 deletions
diff --git a/dbus/bus.cc b/dbus/bus.cc index c830f06..dd9ed34 100644 --- a/dbus/bus.cc +++ b/dbus/bus.cc @@ -123,7 +123,7 @@ class Timeout : public base::RefCountedThreadSafe<Timeout> { } // Starts monitoring the timeout. - void StartMonitoring(dbus::Bus* bus) { + void StartMonitoring(Bus* bus) { bus->PostDelayedTaskToDBusThread(FROM_HERE, base::Bind(&Timeout::HandleTimeout, this), @@ -227,7 +227,7 @@ ObjectProxy* Bus::GetObjectProxy(const std::string& service_name, } ObjectProxy* Bus::GetObjectProxyWithOptions(const std::string& service_name, - const dbus::ObjectPath& object_path, + const ObjectPath& object_path, int options) { AssertOnOriginThread(); @@ -255,7 +255,7 @@ bool Bus::RemoveObjectProxy(const std::string& service_name, } bool Bus::RemoveObjectProxyWithOptions(const std::string& service_name, - const dbus::ObjectPath& object_path, + const ObjectPath& object_path, int options, const base::Closure& callback) { AssertOnOriginThread(); @@ -276,9 +276,8 @@ bool Bus::RemoveObjectProxyWithOptions(const std::string& service_name, return false; } -void Bus::RemoveObjectProxyInternal( - scoped_refptr<dbus::ObjectProxy> object_proxy, - const base::Closure& callback) { +void Bus::RemoveObjectProxyInternal(scoped_refptr<ObjectProxy> object_proxy, + const base::Closure& callback) { AssertOnDBusThread(); object_proxy.get()->Detach(); @@ -325,7 +324,7 @@ void Bus::UnregisterExportedObject(const ObjectPath& object_path) { } void Bus::UnregisterExportedObjectInternal( - scoped_refptr<dbus::ExportedObject> exported_object) { + scoped_refptr<ExportedObject> exported_object) { AssertOnDBusThread(); exported_object->Unregister(); @@ -782,7 +781,8 @@ void Bus::ProcessAllIncomingDataIfAny() { if (dbus_connection_get_dispatch_status(connection_) == DBUS_DISPATCH_DATA_REMAINS) { while (dbus_connection_dispatch(connection_) == - DBUS_DISPATCH_DATA_REMAINS); + DBUS_DISPATCH_DATA_REMAINS) { + } } } diff --git a/dbus/bus_unittest.cc b/dbus/bus_unittest.cc index 3c453f7..f041dad 100644 --- a/dbus/bus_unittest.cc +++ b/dbus/bus_unittest.cc @@ -17,6 +17,8 @@ #include "testing/gtest/include/gtest/gtest.h" +namespace dbus { + namespace { // Used to test AddFilterFunction(). @@ -72,26 +74,26 @@ void OnServiceOwnerChanged(RunLoopWithExpectedCount* run_loop_state, } // namespace TEST(BusTest, GetObjectProxy) { - dbus::Bus::Options options; - scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); + Bus::Options options; + scoped_refptr<Bus> bus = new Bus(options); - dbus::ObjectProxy* object_proxy1 = + ObjectProxy* object_proxy1 = bus->GetObjectProxy("org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject")); + ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(object_proxy1); // This should return the same object. - dbus::ObjectProxy* object_proxy2 = + ObjectProxy* object_proxy2 = bus->GetObjectProxy("org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject")); + ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(object_proxy2); EXPECT_EQ(object_proxy1, object_proxy2); // This should not. - dbus::ObjectProxy* object_proxy3 = + ObjectProxy* object_proxy3 = bus->GetObjectProxy( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/DifferentTestObject")); + ObjectPath("/org/chromium/DifferentTestObject")); ASSERT_TRUE(object_proxy3); EXPECT_NE(object_proxy1, object_proxy3); @@ -99,31 +101,31 @@ TEST(BusTest, GetObjectProxy) { } TEST(BusTest, GetObjectProxyIgnoreUnknownService) { - dbus::Bus::Options options; - scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); + Bus::Options options; + scoped_refptr<Bus> bus = new Bus(options); - dbus::ObjectProxy* object_proxy1 = + ObjectProxy* object_proxy1 = bus->GetObjectProxyWithOptions( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject"), - dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); + ObjectPath("/org/chromium/TestObject"), + ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); ASSERT_TRUE(object_proxy1); // This should return the same object. - dbus::ObjectProxy* object_proxy2 = + ObjectProxy* object_proxy2 = bus->GetObjectProxyWithOptions( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject"), - dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); + ObjectPath("/org/chromium/TestObject"), + ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); ASSERT_TRUE(object_proxy2); EXPECT_EQ(object_proxy1, object_proxy2); // This should not. - dbus::ObjectProxy* object_proxy3 = + ObjectProxy* object_proxy3 = bus->GetObjectProxyWithOptions( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/DifferentTestObject"), - dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); + ObjectPath("/org/chromium/DifferentTestObject"), + ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); ASSERT_TRUE(object_proxy3); EXPECT_NE(object_proxy1, object_proxy3); @@ -141,20 +143,20 @@ TEST(BusTest, RemoveObjectProxy) { dbus_thread.StartWithOptions(thread_options); // Create the bus. - dbus::Bus::Options options; + Bus::Options options; options.dbus_task_runner = dbus_thread.message_loop_proxy(); - scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); + scoped_refptr<Bus> bus = new Bus(options); ASSERT_FALSE(bus->shutdown_completed()); // Try to remove a non existant object proxy should return false. ASSERT_FALSE( bus->RemoveObjectProxy("org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject"), + ObjectPath("/org/chromium/TestObject"), base::Bind(&base::DoNothing))); - dbus::ObjectProxy* object_proxy1 = + ObjectProxy* object_proxy1 = bus->GetObjectProxy("org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject")); + ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(object_proxy1); // Increment the reference count to the object proxy to avoid destroying it @@ -166,14 +168,14 @@ TEST(BusTest, RemoveObjectProxy) { // at a later time. ASSERT_TRUE( bus->RemoveObjectProxy("org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject"), + ObjectPath("/org/chromium/TestObject"), base::Bind(&base::DoNothing))); // This should return a different object because the first object was removed // from the bus, but not deleted from memory. - dbus::ObjectProxy* object_proxy2 = + ObjectProxy* object_proxy2 = bus->GetObjectProxy("org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject")); + ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(object_proxy2); // Compare the new object with the first object. The first object still exists @@ -190,23 +192,23 @@ TEST(BusTest, RemoveObjectProxy) { } TEST(BusTest, GetExportedObject) { - dbus::Bus::Options options; - scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); + Bus::Options options; + scoped_refptr<Bus> bus = new Bus(options); - dbus::ExportedObject* object_proxy1 = - bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); + ExportedObject* object_proxy1 = + bus->GetExportedObject(ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(object_proxy1); // This should return the same object. - dbus::ExportedObject* object_proxy2 = - bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); + ExportedObject* object_proxy2 = + bus->GetExportedObject(ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(object_proxy2); EXPECT_EQ(object_proxy1, object_proxy2); // This should not. - dbus::ExportedObject* object_proxy3 = + ExportedObject* object_proxy3 = bus->GetExportedObject( - dbus::ObjectPath("/org/chromium/DifferentTestObject")); + ObjectPath("/org/chromium/DifferentTestObject")); ASSERT_TRUE(object_proxy3); EXPECT_NE(object_proxy1, object_proxy3); @@ -221,13 +223,13 @@ TEST(BusTest, UnregisterExportedObject) { dbus_thread.StartWithOptions(thread_options); // Create the bus. - dbus::Bus::Options options; + Bus::Options options; options.dbus_task_runner = dbus_thread.message_loop_proxy(); - scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); + scoped_refptr<Bus> bus = new Bus(options); ASSERT_FALSE(bus->shutdown_completed()); - dbus::ExportedObject* object_proxy1 = - bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); + ExportedObject* object_proxy1 = + bus->GetExportedObject(ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(object_proxy1); // Increment the reference count to the object proxy to avoid destroying it @@ -235,12 +237,12 @@ TEST(BusTest, UnregisterExportedObject) { // not freed from memory. See http://crbug.com/137846 for details. object_proxy1->AddRef(); - bus->UnregisterExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); + bus->UnregisterExportedObject(ObjectPath("/org/chromium/TestObject")); // This should return a new object because the object_proxy1 is still in // alloc'ed memory. - dbus::ExportedObject* object_proxy2 = - bus->GetExportedObject(dbus::ObjectPath("/org/chromium/TestObject")); + ExportedObject* object_proxy2 = + bus->GetExportedObject(ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(object_proxy2); EXPECT_NE(object_proxy1, object_proxy2); @@ -254,8 +256,8 @@ TEST(BusTest, UnregisterExportedObject) { } TEST(BusTest, ShutdownAndBlock) { - dbus::Bus::Options options; - scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); + Bus::Options options; + scoped_refptr<Bus> bus = new Bus(options); ASSERT_FALSE(bus->shutdown_completed()); // Shut down synchronously. @@ -271,9 +273,9 @@ TEST(BusTest, ShutdownAndBlockWithDBusThread) { dbus_thread.StartWithOptions(thread_options); // Create the bus. - dbus::Bus::Options options; + Bus::Options options; options.dbus_task_runner = dbus_thread.message_loop_proxy(); - scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); + scoped_refptr<Bus> bus = new Bus(options); ASSERT_FALSE(bus->shutdown_completed()); // Shut down synchronously. @@ -283,8 +285,8 @@ TEST(BusTest, ShutdownAndBlockWithDBusThread) { } TEST(BusTest, AddFilterFunction) { - dbus::Bus::Options options; - scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); + Bus::Options options; + scoped_refptr<Bus> bus = new Bus(options); // Should connect before calling AddFilterFunction(). bus->Connect(); @@ -304,9 +306,9 @@ TEST(BusTest, AddFilterFunction) { } TEST(BusTest, DoubleAddAndRemoveMatch) { - dbus::Bus::Options options; - scoped_refptr<dbus::Bus> bus = new dbus::Bus(options); - dbus::ScopedDBusError error; + Bus::Options options; + scoped_refptr<Bus> bus = new Bus(options); + ScopedDBusError error; bus->Connect(); @@ -349,13 +351,13 @@ TEST(BusTest, ListenForServiceOwnerChange) { RunLoopWithExpectedCount run_loop_state; // Create the bus. - dbus::Bus::Options bus_options; - scoped_refptr<dbus::Bus> bus = new dbus::Bus(bus_options); + Bus::Options bus_options; + scoped_refptr<Bus> bus = new Bus(bus_options); // Add a listener. std::string service_owner1; int num_of_owner_changes1 = 0; - dbus::Bus::GetServiceOwnerCallback callback1 = + Bus::GetServiceOwnerCallback callback1 = base::Bind(&OnServiceOwnerChanged, &run_loop_state, &service_owner1, @@ -378,7 +380,7 @@ TEST(BusTest, ListenForServiceOwnerChange) { // the right value. std::string current_service_owner = bus->GetServiceOwnerAndBlock("org.chromium.TestService", - dbus::Bus::REPORT_ERRORS); + Bus::REPORT_ERRORS); ASSERT_FALSE(current_service_owner.empty()); // Make sure the listener heard about the new owner. @@ -391,7 +393,7 @@ TEST(BusTest, ListenForServiceOwnerChange) { // Add a second listener. std::string service_owner2; int num_of_owner_changes2 = 0; - dbus::Bus::GetServiceOwnerCallback callback2 = + Bus::GetServiceOwnerCallback callback2 = base::Bind(&OnServiceOwnerChanged, &run_loop_state, &service_owner2, @@ -418,3 +420,5 @@ TEST(BusTest, ListenForServiceOwnerChange) { bus->ShutdownAndBlock(); EXPECT_TRUE(bus->shutdown_completed()); } + +} // namespace dbus diff --git a/dbus/end_to_end_async_unittest.cc b/dbus/end_to_end_async_unittest.cc index 210431f..b13f533 100644 --- a/dbus/end_to_end_async_unittest.cc +++ b/dbus/end_to_end_async_unittest.cc @@ -20,6 +20,8 @@ #include "dbus/test_service.h" #include "testing/gtest/include/gtest/gtest.h" +namespace dbus { + namespace { // See comments in ObjectProxy::RunResponseCallback() for why the number was @@ -45,24 +47,24 @@ class EndToEndAsyncTest : public testing::Test { ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options)); // Start the test service, using the D-Bus thread. - dbus::TestService::Options options; + TestService::Options options; options.dbus_task_runner = dbus_thread_->message_loop_proxy(); - test_service_.reset(new dbus::TestService(options)); + test_service_.reset(new TestService(options)); ASSERT_TRUE(test_service_->StartService()); ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted()); ASSERT_TRUE(test_service_->HasDBusThread()); // Create the client, using the D-Bus thread. - dbus::Bus::Options bus_options; - bus_options.bus_type = dbus::Bus::SESSION; - bus_options.connection_type = dbus::Bus::PRIVATE; + Bus::Options bus_options; + bus_options.bus_type = Bus::SESSION; + bus_options.connection_type = Bus::PRIVATE; bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); bus_options.disconnected_callback = base::Bind(&EndToEndAsyncTest::OnDisconnected, base::Unretained(this)); - bus_ = new dbus::Bus(bus_options); + bus_ = new Bus(bus_options); object_proxy_ = bus_->GetObjectProxy( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject")); + ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(bus_->HasDBusThread()); // Connect to the "Test" signal of "org.chromium.TestInterface" from @@ -93,9 +95,8 @@ class EndToEndAsyncTest : public testing::Test { message_loop_.Run(); // Create a second object proxy for the root object. - root_object_proxy_ = bus_->GetObjectProxy( - "org.chromium.TestService", - dbus::ObjectPath("/")); + root_object_proxy_ = bus_->GetObjectProxy("org.chromium.TestService", + ObjectPath("/")); ASSERT_TRUE(bus_->HasDBusThread()); // Connect to the "Test" signal of "org.chromium.TestInterface" from @@ -133,23 +134,23 @@ class EndToEndAsyncTest : public testing::Test { // Create new bus with invalid address. const char kInvalidAddress[] = ""; - dbus::Bus::Options bus_options; - bus_options.bus_type = dbus::Bus::CUSTOM_ADDRESS; + Bus::Options bus_options; + bus_options.bus_type = Bus::CUSTOM_ADDRESS; bus_options.address = kInvalidAddress; - bus_options.connection_type = dbus::Bus::PRIVATE; + bus_options.connection_type = Bus::PRIVATE; bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); - bus_ = new dbus::Bus(bus_options); + bus_ = new Bus(bus_options); ASSERT_TRUE(bus_->HasDBusThread()); // Create new object proxy. object_proxy_ = bus_->GetObjectProxy( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject")); + ObjectPath("/org/chromium/TestObject")); } // Calls the method asynchronously. OnResponse() will be called once the // response is received. - void CallMethod(dbus::MethodCall* method_call, + void CallMethod(MethodCall* method_call, int timeout_ms) { object_proxy_->CallMethod(method_call, timeout_ms, @@ -159,7 +160,7 @@ class EndToEndAsyncTest : public testing::Test { // Calls the method asynchronously. OnResponse() will be called once the // response is received without error, otherwise OnError() will be called. - void CallMethodWithErrorCallback(dbus::MethodCall* method_call, + void CallMethodWithErrorCallback(MethodCall* method_call, int timeout_ms) { object_proxy_->CallMethodWithErrorCallback( method_call, @@ -176,11 +177,11 @@ class EndToEndAsyncTest : public testing::Test { } // Called when the response is received. - void OnResponse(dbus::Response* response) { + void OnResponse(Response* response) { // |response| will be deleted on exit of the function. Copy the // payload to |response_strings_|. if (response) { - dbus::MessageReader reader(response); + MessageReader reader(response); std::string response_string; ASSERT_TRUE(reader.PopString(&response_string)); response_strings_.push_back(response_string); @@ -198,7 +199,7 @@ class EndToEndAsyncTest : public testing::Test { } // Called when an error is received. - void OnError(dbus::ErrorResponse* error) { + void OnError(ErrorResponse* error) { // |error| will be deleted on exit of the function. Copy the payload to // |error_names_|. if (error) { @@ -212,8 +213,8 @@ class EndToEndAsyncTest : public testing::Test { // Called when the "Test" signal is received, in the main thread. // Copy the string payload to |test_signal_string_|. - void OnTestSignal(dbus::Signal* signal) { - dbus::MessageReader reader(signal); + void OnTestSignal(Signal* signal) { + MessageReader reader(signal); ASSERT_TRUE(reader.PopString(&test_signal_string_)); message_loop_.Quit(); } @@ -221,15 +222,15 @@ class EndToEndAsyncTest : public testing::Test { // Called when the "Test" signal is received, in the main thread, by // the root object proxy. Copy the string payload to // |root_test_signal_string_|. - void OnRootTestSignal(dbus::Signal* signal) { - dbus::MessageReader reader(signal); + void OnRootTestSignal(Signal* signal) { + MessageReader reader(signal); ASSERT_TRUE(reader.PopString(&root_test_signal_string_)); message_loop_.Quit(); } // Called when the "Test2" signal is received, in the main thread. - void OnTest2Signal(dbus::Signal* signal) { - dbus::MessageReader reader(signal); + void OnTest2Signal(Signal* signal) { + MessageReader reader(signal); message_loop_.Quit(); } @@ -257,10 +258,10 @@ class EndToEndAsyncTest : public testing::Test { std::vector<std::string> response_strings_; std::vector<std::string> error_names_; scoped_ptr<base::Thread> dbus_thread_; - scoped_refptr<dbus::Bus> bus_; - dbus::ObjectProxy* object_proxy_; - dbus::ObjectProxy* root_object_proxy_; - scoped_ptr<dbus::TestService> test_service_; + scoped_refptr<Bus> bus_; + ObjectProxy* object_proxy_; + ObjectProxy* root_object_proxy_; + scoped_ptr<TestService> test_service_; // Text message from "Test" signal. std::string test_signal_string_; // Text message from "Test" signal delivered to root. @@ -272,12 +273,12 @@ TEST_F(EndToEndAsyncTest, Echo) { const char* kHello = "hello"; // Create the method call. - dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); - dbus::MessageWriter writer(&method_call); + MethodCall method_call("org.chromium.TestInterface", "Echo"); + MessageWriter writer(&method_call); writer.AppendString(kHello); // Call the method. - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; CallMethod(&method_call, timeout_ms); // Check the response. @@ -289,12 +290,12 @@ TEST_F(EndToEndAsyncTest, EchoWithErrorCallback) { const char* kHello = "hello"; // Create the method call. - dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); - dbus::MessageWriter writer(&method_call); + MethodCall method_call("org.chromium.TestInterface", "Echo"); + MessageWriter writer(&method_call); writer.AppendString(kHello); // Call the method. - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; CallMethodWithErrorCallback(&method_call, timeout_ms); // Check the response. @@ -309,12 +310,12 @@ TEST_F(EndToEndAsyncTest, EchoThreeTimes) { for (size_t i = 0; i < arraysize(kMessages); ++i) { // Create the method call. - dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); - dbus::MessageWriter writer(&method_call); + MethodCall method_call("org.chromium.TestInterface", "Echo"); + MessageWriter writer(&method_call); writer.AppendString(kMessages[i]); // Call the method. - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; CallMethod(&method_call, timeout_ms); } @@ -331,12 +332,12 @@ TEST_F(EndToEndAsyncTest, Echo_HugePayload) { const std::string kHugePayload(kHugePayloadSize, 'o'); // Create the method call with a huge payload. - dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); - dbus::MessageWriter writer(&method_call); + MethodCall method_call("org.chromium.TestInterface", "Echo"); + MessageWriter writer(&method_call); writer.AppendString(kHugePayload); // Call the method. - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; CallMethod(&method_call, timeout_ms); // This caused a DCHECK failure before. Ensure that the issue is fixed. @@ -351,12 +352,12 @@ TEST_F(EndToEndAsyncTest, BrokenBus) { SetUpBrokenBus(); // Create the method call. - dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); - dbus::MessageWriter writer(&method_call); + MethodCall method_call("org.chromium.TestInterface", "Echo"); + MessageWriter writer(&method_call); writer.AppendString(kHello); // Call the method. - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; CallMethod(&method_call, timeout_ms); WaitForResponses(1); @@ -371,12 +372,12 @@ TEST_F(EndToEndAsyncTest, BrokenBusWithErrorCallback) { SetUpBrokenBus(); // Create the method call. - dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); - dbus::MessageWriter writer(&method_call); + MethodCall method_call("org.chromium.TestInterface", "Echo"); + MessageWriter writer(&method_call); writer.AppendString(kHello); // Call the method. - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; CallMethodWithErrorCallback(&method_call, timeout_ms); WaitForErrors(1); @@ -389,8 +390,8 @@ TEST_F(EndToEndAsyncTest, Timeout) { const char* kHello = "hello"; // Create the method call. - dbus::MethodCall method_call("org.chromium.TestInterface", "SlowEcho"); - dbus::MessageWriter writer(&method_call); + MethodCall method_call("org.chromium.TestInterface", "SlowEcho"); + MessageWriter writer(&method_call); writer.AppendString(kHello); // Call the method with timeout of 0ms. @@ -406,8 +407,8 @@ TEST_F(EndToEndAsyncTest, TimeoutWithErrorCallback) { const char* kHello = "hello"; // Create the method call. - dbus::MethodCall method_call("org.chromium.TestInterface", "SlowEcho"); - dbus::MessageWriter writer(&method_call); + MethodCall method_call("org.chromium.TestInterface", "SlowEcho"); + MessageWriter writer(&method_call); writer.AppendString(kHello); // Call the method with timeout of 0ms. @@ -425,12 +426,12 @@ TEST_F(EndToEndAsyncTest, AsyncEcho) { const char* kHello = "hello"; // Create the method call. - dbus::MethodCall method_call("org.chromium.TestInterface", "AsyncEcho"); - dbus::MessageWriter writer(&method_call); + MethodCall method_call("org.chromium.TestInterface", "AsyncEcho"); + MessageWriter writer(&method_call); writer.AppendString(kHello); // Call the method. - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; CallMethod(&method_call, timeout_ms); // Check the response. @@ -439,9 +440,9 @@ TEST_F(EndToEndAsyncTest, AsyncEcho) { } TEST_F(EndToEndAsyncTest, NonexistentMethod) { - dbus::MethodCall method_call("org.chromium.TestInterface", "Nonexistent"); + MethodCall method_call("org.chromium.TestInterface", "Nonexistent"); - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; CallMethod(&method_call, timeout_ms); WaitForResponses(1); @@ -450,9 +451,9 @@ TEST_F(EndToEndAsyncTest, NonexistentMethod) { } TEST_F(EndToEndAsyncTest, NonexistentMethodWithErrorCallback) { - dbus::MethodCall method_call("org.chromium.TestInterface", "Nonexistent"); + MethodCall method_call("org.chromium.TestInterface", "Nonexistent"); - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; CallMethodWithErrorCallback(&method_call, timeout_ms); WaitForErrors(1); @@ -462,9 +463,9 @@ TEST_F(EndToEndAsyncTest, NonexistentMethodWithErrorCallback) { } TEST_F(EndToEndAsyncTest, BrokenMethod) { - dbus::MethodCall method_call("org.chromium.TestInterface", "BrokenMethod"); + MethodCall method_call("org.chromium.TestInterface", "BrokenMethod"); - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; CallMethod(&method_call, timeout_ms); WaitForResponses(1); @@ -473,9 +474,9 @@ TEST_F(EndToEndAsyncTest, BrokenMethod) { } TEST_F(EndToEndAsyncTest, BrokenMethodWithErrorCallback) { - dbus::MethodCall method_call("org.chromium.TestInterface", "BrokenMethod"); + MethodCall method_call("org.chromium.TestInterface", "BrokenMethod"); - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; CallMethodWithErrorCallback(&method_call, timeout_ms); WaitForErrors(1); @@ -486,15 +487,15 @@ TEST_F(EndToEndAsyncTest, BrokenMethodWithErrorCallback) { TEST_F(EndToEndAsyncTest, InvalidObjectPath) { // Trailing '/' is only allowed for the root path. - const dbus::ObjectPath invalid_object_path("/org/chromium/TestObject/"); + const ObjectPath invalid_object_path("/org/chromium/TestObject/"); // Replace object proxy with new one. object_proxy_ = bus_->GetObjectProxy("org.chromium.TestService", invalid_object_path); - dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); + MethodCall method_call("org.chromium.TestInterface", "Echo"); - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; CallMethodWithErrorCallback(&method_call, timeout_ms); WaitForErrors(1); @@ -509,11 +510,11 @@ TEST_F(EndToEndAsyncTest, InvalidServiceName) { // Replace object proxy with new one. object_proxy_ = bus_->GetObjectProxy( - invalid_service_name, dbus::ObjectPath("org.chromium.TestObject")); + invalid_service_name, ObjectPath("org.chromium.TestObject")); - dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); + MethodCall method_call("org.chromium.TestInterface", "Echo"); - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; CallMethodWithErrorCallback(&method_call, timeout_ms); WaitForErrors(1); @@ -526,15 +527,15 @@ TEST_F(EndToEndAsyncTest, EmptyResponseCallback) { const char* kHello = "hello"; // Create the method call. - dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); - dbus::MessageWriter writer(&method_call); + MethodCall method_call("org.chromium.TestInterface", "Echo"); + MessageWriter writer(&method_call); writer.AppendString(kHello); // Call the method with an empty callback. - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; object_proxy_->CallMethod(&method_call, timeout_ms, - dbus::ObjectProxy::EmptyResponseCallback()); + ObjectProxy::EmptyResponseCallback()); // Post a delayed task to quit the message loop. message_loop_.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), @@ -580,7 +581,7 @@ TEST_F(EndToEndAsyncTest, TestHugeSignal) { TEST_F(EndToEndAsyncTest, DisconnectedSignal) { bus_->PostTaskToDBusThread(FROM_HERE, - base::Bind(&dbus::Bus::ClosePrivateConnection, + base::Bind(&Bus::ClosePrivateConnection, base::Unretained(bus_.get()))); // OnDisconnected callback quits message loop. message_loop_.Run(); @@ -613,8 +614,8 @@ class SignalMultipleHandlerTest : public EndToEndAsyncTest { protected: // Called when the "Test" signal is received, in the main thread. // Copy the string payload to |additional_test_signal_string_|. - void OnAdditionalTestSignal(dbus::Signal* signal) { - dbus::MessageReader reader(signal); + void OnAdditionalTestSignal(Signal* signal) { + MessageReader reader(signal); ASSERT_TRUE(reader.PopString(&additional_test_signal_string_)); message_loop_.Quit(); } @@ -642,3 +643,5 @@ TEST_F(SignalMultipleHandlerTest, TestMultipleHandlers) { // Verify the signal WAS ALSO received by the additional handler. ASSERT_EQ(kMessage, additional_test_signal_string_); } + +} // namespace dbus diff --git a/dbus/end_to_end_sync_unittest.cc b/dbus/end_to_end_sync_unittest.cc index 9cddea4..e3b316a 100644 --- a/dbus/end_to_end_sync_unittest.cc +++ b/dbus/end_to_end_sync_unittest.cc @@ -11,6 +11,8 @@ #include "dbus/test_service.h" #include "testing/gtest/include/gtest/gtest.h" +namespace dbus { + // The end-to-end test exercises the synchronous APIs in ObjectProxy and // ExportedObject. The test will launch a thread for the service side // operations (i.e. ExportedObject side). @@ -21,20 +23,20 @@ class EndToEndSyncTest : public testing::Test { virtual void SetUp() { // Start the test service; - dbus::TestService::Options options; - test_service_.reset(new dbus::TestService(options)); + TestService::Options options; + test_service_.reset(new TestService(options)); ASSERT_TRUE(test_service_->StartService()); ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted()); ASSERT_FALSE(test_service_->HasDBusThread()); // Create the client. - dbus::Bus::Options client_bus_options; - client_bus_options.bus_type = dbus::Bus::SESSION; - client_bus_options.connection_type = dbus::Bus::PRIVATE; - client_bus_ = new dbus::Bus(client_bus_options); + Bus::Options client_bus_options; + client_bus_options.bus_type = Bus::SESSION; + client_bus_options.connection_type = Bus::PRIVATE; + client_bus_ = new Bus(client_bus_options); object_proxy_ = client_bus_->GetObjectProxy( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject")); + ObjectPath("/org/chromium/TestObject")); ASSERT_FALSE(client_bus_->HasDBusThread()); } @@ -45,27 +47,27 @@ class EndToEndSyncTest : public testing::Test { } protected: - scoped_ptr<dbus::TestService> test_service_; - scoped_refptr<dbus::Bus> client_bus_; - dbus::ObjectProxy* object_proxy_; + scoped_ptr<TestService> test_service_; + scoped_refptr<Bus> client_bus_; + ObjectProxy* object_proxy_; }; TEST_F(EndToEndSyncTest, Echo) { const std::string kHello = "hello"; // Create the method call. - dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); - dbus::MessageWriter writer(&method_call); + MethodCall method_call("org.chromium.TestInterface", "Echo"); + MessageWriter writer(&method_call); writer.AppendString(kHello); // Call the method. - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; - scoped_ptr<dbus::Response> response( + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; + scoped_ptr<Response> response( object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); ASSERT_TRUE(response.get()); // Check the response. kHello should be echoed back. - dbus::MessageReader reader(response.get()); + MessageReader reader(response.get()); std::string returned_message; ASSERT_TRUE(reader.PopString(&returned_message)); EXPECT_EQ(kHello, returned_message); @@ -75,48 +77,48 @@ TEST_F(EndToEndSyncTest, Timeout) { const std::string kHello = "hello"; // Create the method call. - dbus::MethodCall method_call("org.chromium.TestInterface", "DelayedEcho"); - dbus::MessageWriter writer(&method_call); + MethodCall method_call("org.chromium.TestInterface", "DelayedEcho"); + MessageWriter writer(&method_call); writer.AppendString(kHello); // Call the method with timeout of 0ms. const int timeout_ms = 0; - scoped_ptr<dbus::Response> response( + scoped_ptr<Response> response( object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); // Should fail because of timeout. ASSERT_FALSE(response.get()); } TEST_F(EndToEndSyncTest, NonexistentMethod) { - dbus::MethodCall method_call("org.chromium.TestInterface", "Nonexistent"); + MethodCall method_call("org.chromium.TestInterface", "Nonexistent"); - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; - scoped_ptr<dbus::Response> response( + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; + scoped_ptr<Response> response( object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); ASSERT_FALSE(response.get()); } TEST_F(EndToEndSyncTest, BrokenMethod) { - dbus::MethodCall method_call("org.chromium.TestInterface", "BrokenMethod"); + MethodCall method_call("org.chromium.TestInterface", "BrokenMethod"); - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; - scoped_ptr<dbus::Response> response( + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; + scoped_ptr<Response> response( object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); ASSERT_FALSE(response.get()); } TEST_F(EndToEndSyncTest, InvalidObjectPath) { // Trailing '/' is only allowed for the root path. - const dbus::ObjectPath invalid_object_path("/org/chromium/TestObject/"); + const ObjectPath invalid_object_path("/org/chromium/TestObject/"); // Replace object proxy with new one. object_proxy_ = client_bus_->GetObjectProxy("org.chromium.TestService", invalid_object_path); - dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); + MethodCall method_call("org.chromium.TestInterface", "Echo"); - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; - scoped_ptr<dbus::Response> response( + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; + scoped_ptr<Response> response( object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); ASSERT_FALSE(response.get()); } @@ -127,12 +129,14 @@ TEST_F(EndToEndSyncTest, InvalidServiceName) { // Replace object proxy with new one. object_proxy_ = client_bus_->GetObjectProxy( - invalid_service_name, dbus::ObjectPath("org.chromium.TestObject")); + invalid_service_name, ObjectPath("org.chromium.TestObject")); - dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); + MethodCall method_call("org.chromium.TestInterface", "Echo"); - const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT; - scoped_ptr<dbus::Response> response( + const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; + scoped_ptr<Response> response( object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); ASSERT_FALSE(response.get()); } + +} // namespace dbus diff --git a/dbus/exported_object.cc b/dbus/exported_object.cc index b8cfbc5..d20813a 100644 --- a/dbus/exported_object.cc +++ b/dbus/exported_object.cc @@ -280,7 +280,7 @@ void ExportedObject::OnMethodCompleted(scoped_ptr<MethodCall> method_call, if (!response) { // Something bad happened in the method call. - scoped_ptr<dbus::ErrorResponse> error_response( + scoped_ptr<ErrorResponse> error_response( ErrorResponse::FromMethodCall( method_call.get(), DBUS_ERROR_FAILED, diff --git a/dbus/message.cc b/dbus/message.cc index 02fa090..e351716 100644 --- a/dbus/message.cc +++ b/dbus/message.cc @@ -452,9 +452,9 @@ scoped_ptr<ErrorResponse> ErrorResponse::FromMethodCall( // MessageWriter implementation. // -MessageWriter::MessageWriter(Message* message) : - message_(message), - container_is_open_(false) { +MessageWriter::MessageWriter(Message* message) + : message_(message), + container_is_open_(false) { memset(&raw_message_iter_, 0, sizeof(raw_message_iter_)); if (message) dbus_message_iter_init_append(message_->raw_message(), &raw_message_iter_); @@ -966,7 +966,7 @@ bool MessageReader::PopContainer(int dbus_type, MessageReader* sub_reader) { } bool MessageReader::PopVariantOfBasic(int dbus_type, void* value) { - dbus::MessageReader variant_reader(message_); + MessageReader variant_reader(message_); if (!PopVariant(&variant_reader)) return false; return variant_reader.PopBasic(dbus_type, value); diff --git a/dbus/message_unittest.cc b/dbus/message_unittest.cc index 383e1c1..16348df 100644 --- a/dbus/message_unittest.cc +++ b/dbus/message_unittest.cc @@ -12,16 +12,18 @@ #include "dbus/test_proto.pb.h" #include "testing/gtest/include/gtest/gtest.h" +namespace dbus { + // Test that a byte can be properly written and read. We only have this // test for byte, as repeating this for other basic types is too redundant. TEST(MessageTest, AppendAndPopByte) { - scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(message.get()); + scoped_ptr<Response> message(Response::CreateEmpty()); + MessageWriter writer(message.get()); writer.AppendByte(123); // The input is 123. - dbus::MessageReader reader(message.get()); + MessageReader reader(message.get()); ASSERT_TRUE(reader.HasMoreData()); // Should have data to read. - ASSERT_EQ(dbus::Message::BYTE, reader.GetDataType()); + ASSERT_EQ(Message::BYTE, reader.GetDataType()); bool bool_value = false; // Should fail as the type is not bool here. @@ -38,8 +40,8 @@ TEST(MessageTest, AppendAndPopByte) { // Check all basic types can be properly written and read. TEST(MessageTest, AppendAndPopBasicDataTypes) { - scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(message.get()); + scoped_ptr<Response> message(Response::CreateEmpty()); + MessageWriter writer(message.get()); // Append 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path". writer.AppendByte(0); @@ -52,7 +54,7 @@ TEST(MessageTest, AppendAndPopBasicDataTypes) { writer.AppendUint64(7); writer.AppendDouble(8.0); writer.AppendString("string"); - writer.AppendObjectPath(dbus::ObjectPath("/object/path")); + writer.AppendObjectPath(ObjectPath("/object/path")); uint8 byte_value = 0; bool bool_value = false; @@ -64,9 +66,9 @@ TEST(MessageTest, AppendAndPopBasicDataTypes) { uint64 uint64_value = 0; double double_value = 0; std::string string_value; - dbus::ObjectPath object_path_value; + ObjectPath object_path_value; - dbus::MessageReader reader(message.get()); + MessageReader reader(message.get()); ASSERT_TRUE(reader.HasMoreData()); ASSERT_TRUE(reader.PopByte(&byte_value)); ASSERT_TRUE(reader.PopBool(&bool_value)); @@ -92,21 +94,21 @@ TEST(MessageTest, AppendAndPopBasicDataTypes) { EXPECT_EQ(7U, uint64_value); EXPECT_DOUBLE_EQ(8.0, double_value); EXPECT_EQ("string", string_value); - EXPECT_EQ(dbus::ObjectPath("/object/path"), object_path_value); + EXPECT_EQ(ObjectPath("/object/path"), object_path_value); } // Check all basic types can be properly written and read. TEST(MessageTest, AppendAndPopFileDescriptor) { - if (!dbus::IsDBusTypeUnixFdSupported()) { + if (!IsDBusTypeUnixFdSupported()) { LOG(WARNING) << "FD passing is not supported"; return; } - scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(message.get()); + scoped_ptr<Response> message(Response::CreateEmpty()); + MessageWriter writer(message.get()); // Append stdout. - dbus::FileDescriptor temp(1); + FileDescriptor temp(1); // Descriptor should not be valid until checked. ASSERT_FALSE(temp.is_valid()); // NB: thread IO requirements not relevant for unit tests. @@ -114,9 +116,9 @@ TEST(MessageTest, AppendAndPopFileDescriptor) { ASSERT_TRUE(temp.is_valid()); writer.AppendFileDescriptor(temp); - dbus::FileDescriptor fd_value; + FileDescriptor fd_value; - dbus::MessageReader reader(message.get()); + MessageReader reader(message.get()); ASSERT_TRUE(reader.HasMoreData()); ASSERT_TRUE(reader.PopFileDescriptor(&fd_value)); ASSERT_FALSE(reader.HasMoreData()); @@ -130,17 +132,17 @@ TEST(MessageTest, AppendAndPopFileDescriptor) { // which should be identical. struct stat sb_stdout; int status_stdout = HANDLE_EINTR(fstat(1, &sb_stdout)); - ASSERT_TRUE(status_stdout >= 0); + ASSERT_GE(status_stdout, 0); struct stat sb_fd; int status_fd = HANDLE_EINTR(fstat(fd_value.value(), &sb_fd)); - ASSERT_TRUE(status_fd >= 0); + ASSERT_GE(status_fd, 0); EXPECT_EQ(sb_stdout.st_rdev, sb_fd.st_rdev); } // Check all variant types can be properly written and read. TEST(MessageTest, AppendAndPopVariantDataTypes) { - scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(message.get()); + scoped_ptr<Response> message(Response::CreateEmpty()); + MessageWriter writer(message.get()); // Append 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path". writer.AppendVariantOfByte(0); @@ -153,7 +155,7 @@ TEST(MessageTest, AppendAndPopVariantDataTypes) { writer.AppendVariantOfUint64(7); writer.AppendVariantOfDouble(8.0); writer.AppendVariantOfString("string"); - writer.AppendVariantOfObjectPath(dbus::ObjectPath("/object/path")); + writer.AppendVariantOfObjectPath(ObjectPath("/object/path")); uint8 byte_value = 0; bool bool_value = false; @@ -165,9 +167,9 @@ TEST(MessageTest, AppendAndPopVariantDataTypes) { uint64 uint64_value = 0; double double_value = 0; std::string string_value; - dbus::ObjectPath object_path_value; + ObjectPath object_path_value; - dbus::MessageReader reader(message.get()); + MessageReader reader(message.get()); ASSERT_TRUE(reader.HasMoreData()); ASSERT_TRUE(reader.PopVariantOfByte(&byte_value)); ASSERT_TRUE(reader.PopVariantOfBool(&bool_value)); @@ -193,19 +195,19 @@ TEST(MessageTest, AppendAndPopVariantDataTypes) { EXPECT_EQ(7U, uint64_value); EXPECT_DOUBLE_EQ(8.0, double_value); EXPECT_EQ("string", string_value); - EXPECT_EQ(dbus::ObjectPath("/object/path"), object_path_value); + EXPECT_EQ(ObjectPath("/object/path"), object_path_value); } TEST(MessageTest, ArrayOfBytes) { - scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(message.get()); + scoped_ptr<Response> message(Response::CreateEmpty()); + MessageWriter writer(message.get()); std::vector<uint8> bytes; bytes.push_back(1); bytes.push_back(2); bytes.push_back(3); writer.AppendArrayOfBytes(bytes.data(), bytes.size()); - dbus::MessageReader reader(message.get()); + MessageReader reader(message.get()); uint8* output_bytes = NULL; size_t length = 0; ASSERT_TRUE(reader.PopArrayOfBytes(&output_bytes, &length)); @@ -217,12 +219,12 @@ TEST(MessageTest, ArrayOfBytes) { } TEST(MessageTest, ArrayOfBytes_Empty) { - scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(message.get()); + scoped_ptr<Response> message(Response::CreateEmpty()); + MessageWriter writer(message.get()); std::vector<uint8> bytes; writer.AppendArrayOfBytes(bytes.data(), bytes.size()); - dbus::MessageReader reader(message.get()); + MessageReader reader(message.get()); uint8* output_bytes = NULL; size_t length = 0; ASSERT_TRUE(reader.PopArrayOfBytes(&output_bytes, &length)); @@ -232,8 +234,8 @@ TEST(MessageTest, ArrayOfBytes_Empty) { } TEST(MessageTest, ArrayOfStrings) { - scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(message.get()); + scoped_ptr<Response> message(Response::CreateEmpty()); + MessageWriter writer(message.get()); std::vector<std::string> strings; strings.push_back("fee"); strings.push_back("fie"); @@ -241,7 +243,7 @@ TEST(MessageTest, ArrayOfStrings) { strings.push_back("fum"); writer.AppendArrayOfStrings(strings); - dbus::MessageReader reader(message.get()); + MessageReader reader(message.get()); std::vector<std::string> output_strings; ASSERT_TRUE(reader.PopArrayOfStrings(&output_strings)); ASSERT_FALSE(reader.HasMoreData()); @@ -253,33 +255,33 @@ TEST(MessageTest, ArrayOfStrings) { } TEST(MessageTest, ArrayOfObjectPaths) { - scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(message.get()); - std::vector<dbus::ObjectPath> object_paths; - object_paths.push_back(dbus::ObjectPath("/object/path/1")); - object_paths.push_back(dbus::ObjectPath("/object/path/2")); - object_paths.push_back(dbus::ObjectPath("/object/path/3")); + scoped_ptr<Response> message(Response::CreateEmpty()); + MessageWriter writer(message.get()); + std::vector<ObjectPath> object_paths; + object_paths.push_back(ObjectPath("/object/path/1")); + object_paths.push_back(ObjectPath("/object/path/2")); + object_paths.push_back(ObjectPath("/object/path/3")); writer.AppendArrayOfObjectPaths(object_paths); - dbus::MessageReader reader(message.get()); - std::vector<dbus::ObjectPath> output_object_paths; + MessageReader reader(message.get()); + std::vector<ObjectPath> output_object_paths; ASSERT_TRUE(reader.PopArrayOfObjectPaths(&output_object_paths)); ASSERT_FALSE(reader.HasMoreData()); ASSERT_EQ(3U, output_object_paths.size()); - EXPECT_EQ(dbus::ObjectPath("/object/path/1"), output_object_paths[0]); - EXPECT_EQ(dbus::ObjectPath("/object/path/2"), output_object_paths[1]); - EXPECT_EQ(dbus::ObjectPath("/object/path/3"), output_object_paths[2]); + EXPECT_EQ(ObjectPath("/object/path/1"), output_object_paths[0]); + EXPECT_EQ(ObjectPath("/object/path/2"), output_object_paths[1]); + EXPECT_EQ(ObjectPath("/object/path/3"), output_object_paths[2]); } TEST(MessageTest, ProtoBuf) { - scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(message.get()); + scoped_ptr<Response> message(Response::CreateEmpty()); + MessageWriter writer(message.get()); TestProto send_message; send_message.set_text("testing"); send_message.set_number(123); writer.AppendProtoAsArrayOfBytes(send_message); - dbus::MessageReader reader(message.get()); + MessageReader reader(message.get()); TestProto receive_message; ASSERT_TRUE(reader.PopArrayOfBytesAsProto(&receive_message)); EXPECT_EQ(receive_message.text(), send_message.text()); @@ -291,18 +293,18 @@ TEST(MessageTest, ProtoBuf) { // test for array, as repeating this for other container types is too // redundant. TEST(MessageTest, OpenArrayAndPopArray) { - scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(message.get()); - dbus::MessageWriter array_writer(NULL); + scoped_ptr<Response> message(Response::CreateEmpty()); + MessageWriter writer(message.get()); + MessageWriter array_writer(NULL); writer.OpenArray("s", &array_writer); // Open an array of strings. array_writer.AppendString("foo"); array_writer.AppendString("bar"); array_writer.AppendString("baz"); writer.CloseContainer(&array_writer); - dbus::MessageReader reader(message.get()); - ASSERT_EQ(dbus::Message::ARRAY, reader.GetDataType()); - dbus::MessageReader array_reader(NULL); + MessageReader reader(message.get()); + ASSERT_EQ(Message::ARRAY, reader.GetDataType()); + MessageReader array_reader(NULL); ASSERT_TRUE(reader.PopArray(&array_reader)); ASSERT_FALSE(reader.HasMoreData()); // Should not have more data to read. @@ -320,16 +322,16 @@ TEST(MessageTest, OpenArrayAndPopArray) { // Create a complex message using array, struct, variant, dict entry, and // make sure it can be read properly. TEST(MessageTest, CreateComplexMessageAndReadIt) { - scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(message.get()); + scoped_ptr<Response> message(Response::CreateEmpty()); + MessageWriter writer(message.get()); { - dbus::MessageWriter array_writer(NULL); + MessageWriter array_writer(NULL); // Open an array of variants. writer.OpenArray("v", &array_writer); { // The first value in the array. { - dbus::MessageWriter variant_writer(NULL); + MessageWriter variant_writer(NULL); // Open a variant of a boolean. array_writer.OpenVariant("b", &variant_writer); variant_writer.AppendBool(true); @@ -338,11 +340,11 @@ TEST(MessageTest, CreateComplexMessageAndReadIt) { // The second value in the array. { - dbus::MessageWriter variant_writer(NULL); + MessageWriter variant_writer(NULL); // Open a variant of a struct that contains a string and an int32. array_writer.OpenVariant("(si)", &variant_writer); { - dbus::MessageWriter struct_writer(NULL); + MessageWriter struct_writer(NULL); variant_writer.OpenStruct(&struct_writer); struct_writer.AppendString("string"); struct_writer.AppendInt32(123); @@ -353,16 +355,16 @@ TEST(MessageTest, CreateComplexMessageAndReadIt) { // The third value in the array. { - dbus::MessageWriter variant_writer(NULL); + MessageWriter variant_writer(NULL); // Open a variant of an array of string-to-int64 dict entries. array_writer.OpenVariant("a{sx}", &variant_writer); { // Opens an array of string-to-int64 dict entries. - dbus::MessageWriter dict_array_writer(NULL); + MessageWriter dict_array_writer(NULL); variant_writer.OpenArray("{sx}", &dict_array_writer); { // Opens a string-to-int64 dict entries. - dbus::MessageWriter dict_entry_writer(NULL); + MessageWriter dict_entry_writer(NULL); dict_array_writer.OpenDictEntry(&dict_entry_writer); dict_entry_writer.AppendString("foo"); dict_entry_writer.AppendInt64(GG_INT64_C(1234567890123456789)); @@ -394,8 +396,8 @@ TEST(MessageTest, CreateComplexMessageAndReadIt) { "]\n", message->ToString()); - dbus::MessageReader reader(message.get()); - dbus::MessageReader array_reader(NULL); + MessageReader reader(message.get()); + MessageReader array_reader(NULL); ASSERT_TRUE(reader.PopArray(&array_reader)); // The first value in the array. @@ -405,10 +407,10 @@ TEST(MessageTest, CreateComplexMessageAndReadIt) { // The second value in the array. { - dbus::MessageReader variant_reader(NULL); + MessageReader variant_reader(NULL); ASSERT_TRUE(array_reader.PopVariant(&variant_reader)); { - dbus::MessageReader struct_reader(NULL); + MessageReader struct_reader(NULL); ASSERT_TRUE(variant_reader.PopStruct(&struct_reader)); std::string string_value; ASSERT_TRUE(struct_reader.PopString(&string_value)); @@ -423,13 +425,13 @@ TEST(MessageTest, CreateComplexMessageAndReadIt) { // The third value in the array. { - dbus::MessageReader variant_reader(NULL); + MessageReader variant_reader(NULL); ASSERT_TRUE(array_reader.PopVariant(&variant_reader)); { - dbus::MessageReader dict_array_reader(NULL); + MessageReader dict_array_reader(NULL); ASSERT_TRUE(variant_reader.PopArray(&dict_array_reader)); { - dbus::MessageReader dict_entry_reader(NULL); + MessageReader dict_entry_reader(NULL); ASSERT_TRUE(dict_array_reader.PopDictEntry(&dict_entry_reader)); std::string string_value; ASSERT_TRUE(dict_entry_reader.PopString(&string_value)); @@ -447,14 +449,14 @@ TEST(MessageTest, CreateComplexMessageAndReadIt) { } TEST(MessageTest, MethodCall) { - dbus::MethodCall method_call("com.example.Interface", "SomeMethod"); + MethodCall method_call("com.example.Interface", "SomeMethod"); EXPECT_TRUE(method_call.raw_message() != NULL); - EXPECT_EQ(dbus::Message::MESSAGE_METHOD_CALL, method_call.GetMessageType()); + EXPECT_EQ(Message::MESSAGE_METHOD_CALL, method_call.GetMessageType()); EXPECT_EQ("MESSAGE_METHOD_CALL", method_call.GetMessageTypeAsString()); method_call.SetDestination("com.example.Service"); - method_call.SetPath(dbus::ObjectPath("/com/example/Object")); + method_call.SetPath(ObjectPath("/com/example/Object")); - dbus::MessageWriter writer(&method_call); + MessageWriter writer(&method_call); writer.AppendString("payload"); EXPECT_EQ("message_type: MESSAGE_METHOD_CALL\n" @@ -473,20 +475,19 @@ TEST(MessageTest, MethodCall_FromRawMessage) { dbus_message_set_interface(raw_message, "com.example.Interface"); dbus_message_set_member(raw_message, "SomeMethod"); - scoped_ptr<dbus::MethodCall> method_call( - dbus::MethodCall::FromRawMessage(raw_message)); + scoped_ptr<MethodCall> method_call(MethodCall::FromRawMessage(raw_message)); EXPECT_EQ("com.example.Interface", method_call->GetInterface()); EXPECT_EQ("SomeMethod", method_call->GetMember()); } TEST(MessageTest, Signal) { - dbus::Signal signal("com.example.Interface", "SomeSignal"); + Signal signal("com.example.Interface", "SomeSignal"); EXPECT_TRUE(signal.raw_message() != NULL); - EXPECT_EQ(dbus::Message::MESSAGE_SIGNAL, signal.GetMessageType()); + EXPECT_EQ(Message::MESSAGE_SIGNAL, signal.GetMessageType()); EXPECT_EQ("MESSAGE_SIGNAL", signal.GetMessageTypeAsString()); - signal.SetPath(dbus::ObjectPath("/com/example/Object")); + signal.SetPath(ObjectPath("/com/example/Object")); - dbus::MessageWriter writer(&signal); + MessageWriter writer(&signal); writer.AppendString("payload"); EXPECT_EQ("message_type: MESSAGE_SIGNAL\n" @@ -504,27 +505,26 @@ TEST(MessageTest, Signal_FromRawMessage) { dbus_message_set_interface(raw_message, "com.example.Interface"); dbus_message_set_member(raw_message, "SomeSignal"); - scoped_ptr<dbus::Signal> signal( - dbus::Signal::FromRawMessage(raw_message)); + scoped_ptr<Signal> signal(Signal::FromRawMessage(raw_message)); EXPECT_EQ("com.example.Interface", signal->GetInterface()); EXPECT_EQ("SomeSignal", signal->GetMember()); } TEST(MessageTest, Response) { - scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + scoped_ptr<Response> response(Response::CreateEmpty()); EXPECT_TRUE(response->raw_message()); - EXPECT_EQ(dbus::Message::MESSAGE_METHOD_RETURN, response->GetMessageType()); + EXPECT_EQ(Message::MESSAGE_METHOD_RETURN, response->GetMessageType()); EXPECT_EQ("MESSAGE_METHOD_RETURN", response->GetMessageTypeAsString()); } TEST(MessageTest, Response_FromMethodCall) { const uint32 kSerial = 123; - dbus::MethodCall method_call("com.example.Interface", "SomeMethod"); + MethodCall method_call("com.example.Interface", "SomeMethod"); method_call.SetSerial(kSerial); - scoped_ptr<dbus::Response> response( - dbus::Response::FromMethodCall(&method_call)); - EXPECT_EQ(dbus::Message::MESSAGE_METHOD_RETURN, response->GetMessageType()); + scoped_ptr<Response> response( + Response::FromMethodCall(&method_call)); + EXPECT_EQ(Message::MESSAGE_METHOD_RETURN, response->GetMessageType()); EXPECT_EQ("MESSAGE_METHOD_RETURN", response->GetMessageTypeAsString()); // The serial should be copied to the reply serial. EXPECT_EQ(kSerial, response->GetReplySerial()); @@ -534,30 +534,30 @@ TEST(MessageTest, ErrorResponse_FromMethodCall) { const uint32 kSerial = 123; const char kErrorMessage[] = "error message"; - dbus::MethodCall method_call("com.example.Interface", "SomeMethod"); + MethodCall method_call("com.example.Interface", "SomeMethod"); method_call.SetSerial(kSerial); - scoped_ptr<dbus::ErrorResponse> error_response( - dbus::ErrorResponse::FromMethodCall(&method_call, - DBUS_ERROR_FAILED, - kErrorMessage)); - EXPECT_EQ(dbus::Message::MESSAGE_ERROR, error_response->GetMessageType()); + scoped_ptr<ErrorResponse> error_response( + ErrorResponse::FromMethodCall(&method_call, + DBUS_ERROR_FAILED, + kErrorMessage)); + EXPECT_EQ(Message::MESSAGE_ERROR, error_response->GetMessageType()); EXPECT_EQ("MESSAGE_ERROR", error_response->GetMessageTypeAsString()); // The serial should be copied to the reply serial. EXPECT_EQ(kSerial, error_response->GetReplySerial()); // Error message should be added to the payload. - dbus::MessageReader reader(error_response.get()); + MessageReader reader(error_response.get()); std::string error_message; ASSERT_TRUE(reader.PopString(&error_message)); EXPECT_EQ(kErrorMessage, error_message); } TEST(MessageTest, GetAndSetHeaders) { - scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); + scoped_ptr<Response> message(Response::CreateEmpty()); EXPECT_EQ("", message->GetDestination()); - EXPECT_EQ(dbus::ObjectPath(std::string()), message->GetPath()); + EXPECT_EQ(ObjectPath(std::string()), message->GetPath()); EXPECT_EQ("", message->GetInterface()); EXPECT_EQ("", message->GetMember()); EXPECT_EQ("", message->GetErrorName()); @@ -566,7 +566,7 @@ TEST(MessageTest, GetAndSetHeaders) { EXPECT_EQ(0U, message->GetReplySerial()); EXPECT_TRUE(message->SetDestination("org.chromium.destination")); - EXPECT_TRUE(message->SetPath(dbus::ObjectPath("/org/chromium/path"))); + EXPECT_TRUE(message->SetPath(ObjectPath("/org/chromium/path"))); EXPECT_TRUE(message->SetInterface("org.chromium.interface")); EXPECT_TRUE(message->SetMember("member")); EXPECT_TRUE(message->SetErrorName("org.chromium.error")); @@ -575,7 +575,7 @@ TEST(MessageTest, GetAndSetHeaders) { message->SetReplySerial(456); EXPECT_EQ("org.chromium.destination", message->GetDestination()); - EXPECT_EQ(dbus::ObjectPath("/org/chromium/path"), message->GetPath()); + EXPECT_EQ(ObjectPath("/org/chromium/path"), message->GetPath()); EXPECT_EQ("org.chromium.interface", message->GetInterface()); EXPECT_EQ("member", message->GetMember()); EXPECT_EQ("org.chromium.error", message->GetErrorName()); @@ -585,9 +585,9 @@ TEST(MessageTest, GetAndSetHeaders) { } TEST(MessageTest, SetInvalidHeaders) { - scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); + scoped_ptr<Response> message(Response::CreateEmpty()); EXPECT_EQ("", message->GetDestination()); - EXPECT_EQ(dbus::ObjectPath(std::string()), message->GetPath()); + EXPECT_EQ(ObjectPath(std::string()), message->GetPath()); EXPECT_EQ("", message->GetInterface()); EXPECT_EQ("", message->GetMember()); EXPECT_EQ("", message->GetErrorName()); @@ -596,7 +596,7 @@ TEST(MessageTest, SetInvalidHeaders) { // Empty element between periods. EXPECT_FALSE(message->SetDestination("org..chromium")); // Trailing '/' is only allowed for the root path. - EXPECT_FALSE(message->SetPath(dbus::ObjectPath("/org/chromium/"))); + EXPECT_FALSE(message->SetPath(ObjectPath("/org/chromium/"))); // Interface name cannot contain '/'. EXPECT_FALSE(message->SetInterface("org/chromium/interface")); // Member name cannot begin with a digit. @@ -607,7 +607,7 @@ TEST(MessageTest, SetInvalidHeaders) { EXPECT_FALSE(message->SetSender("?!#*")); EXPECT_EQ("", message->GetDestination()); - EXPECT_EQ(dbus::ObjectPath(std::string()), message->GetPath()); + EXPECT_EQ(ObjectPath(std::string()), message->GetPath()); EXPECT_EQ("", message->GetInterface()); EXPECT_EQ("", message->GetMember()); EXPECT_EQ("", message->GetErrorName()); @@ -617,8 +617,8 @@ TEST(MessageTest, SetInvalidHeaders) { TEST(MessageTest, ToString_LongString) { const std::string kLongString(1000, 'o'); - scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(message.get()); + scoped_ptr<Response> message(Response::CreateEmpty()); + MessageWriter writer(message.get()); writer.AppendString(kLongString); ASSERT_EQ("message_type: MESSAGE_METHOD_RETURN\n" @@ -628,3 +628,5 @@ TEST(MessageTest, ToString_LongString) { "(1000 bytes in total)\"\n", message->ToString()); } + +} // namespace dbus diff --git a/dbus/mock_unittest.cc b/dbus/mock_unittest.cc index a329fe8..be0f43d 100644 --- a/dbus/mock_unittest.cc +++ b/dbus/mock_unittest.cc @@ -20,6 +20,8 @@ using ::testing::Invoke; using ::testing::Return; using ::testing::Unused; +namespace dbus { + class MockTest : public testing::Test { public: MockTest() { @@ -27,15 +29,15 @@ class MockTest : public testing::Test { virtual void SetUp() { // Create a mock bus. - dbus::Bus::Options options; - options.bus_type = dbus::Bus::SYSTEM; - mock_bus_ = new dbus::MockBus(options); + Bus::Options options; + options.bus_type = Bus::SYSTEM; + mock_bus_ = new MockBus(options); // Create a mock proxy. - mock_proxy_ = new dbus::MockObjectProxy( + mock_proxy_ = new MockObjectProxy( mock_bus_.get(), "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject")); + ObjectPath("/org/chromium/TestObject")); // Set an expectation so mock_proxy's CallMethodAndBlock() will use // CreateMockProxyResponse() to return responses. @@ -51,7 +53,7 @@ class MockTest : public testing::Test { // service name and the object path will return mock_proxy_. EXPECT_CALL(*mock_bus_.get(), GetObjectProxy("org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject"))) + ObjectPath("/org/chromium/TestObject"))) .WillOnce(Return(mock_proxy_.get())); // ShutdownAndBlock() will be called in TearDown(). @@ -63,11 +65,11 @@ class MockTest : public testing::Test { } // Called when the response is received. - void OnResponse(dbus::Response* response) { + void OnResponse(Response* response) { // |response| will be deleted on exit of the function. Copy the // payload to |response_string_|. if (response) { - dbus::MessageReader reader(response); + MessageReader reader(response); ASSERT_TRUE(reader.PopString(&response_string_)); } message_loop_.Quit(); @@ -76,21 +78,21 @@ class MockTest : public testing::Test { protected: std::string response_string_; base::MessageLoop message_loop_; - scoped_refptr<dbus::MockBus> mock_bus_; - scoped_refptr<dbus::MockObjectProxy> mock_proxy_; + scoped_refptr<MockBus> mock_bus_; + scoped_refptr<MockObjectProxy> mock_proxy_; private: // Returns a response for the given method call. Used to implement // CallMethodAndBlock() for |mock_proxy_|. - dbus::Response* CreateMockProxyResponse(dbus::MethodCall* method_call, - int timeout_ms) { + Response* CreateMockProxyResponse(MethodCall* method_call, + int timeout_ms) { if (method_call->GetInterface() == "org.chromium.TestInterface" && method_call->GetMember() == "Echo") { - dbus::MessageReader reader(method_call); + MessageReader reader(method_call); std::string text_message; if (reader.PopString(&text_message)) { - scoped_ptr<dbus::Response> response = dbus::Response::CreateEmpty(); - dbus::MessageWriter writer(response.get()); + scoped_ptr<Response> response = Response::CreateEmpty(); + MessageWriter writer(response.get()); writer.AppendString(text_message); return response.release(); } @@ -103,11 +105,10 @@ class MockTest : public testing::Test { // Creates a response and runs the given response callback in the // message loop with the response. Used to implement for |mock_proxy_|. void HandleMockProxyResponseWithMessageLoop( - dbus::MethodCall* method_call, + MethodCall* method_call, int timeout_ms, - dbus::ObjectProxy::ResponseCallback response_callback) { - dbus::Response* response = CreateMockProxyResponse(method_call, - timeout_ms); + ObjectProxy::ResponseCallback response_callback) { + Response* response = CreateMockProxyResponse(method_call, timeout_ms); message_loop_.PostTask(FROM_HERE, base::Bind(&MockTest::RunResponseCallback, base::Unretained(this), @@ -117,8 +118,8 @@ class MockTest : public testing::Test { // Runs the given response callback with the given response. void RunResponseCallback( - dbus::ObjectProxy::ResponseCallback response_callback, - dbus::Response* response) { + ObjectProxy::ResponseCallback response_callback, + Response* response) { response_callback.Run(response); delete response; } @@ -129,23 +130,23 @@ class MockTest : public testing::Test { TEST_F(MockTest, CallMethodAndBlock) { const char kHello[] = "Hello"; // Get an object proxy from the mock bus. - dbus::ObjectProxy* proxy = mock_bus_->GetObjectProxy( + ObjectProxy* proxy = mock_bus_->GetObjectProxy( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject")); + ObjectPath("/org/chromium/TestObject")); // Create a method call. - dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); - dbus::MessageWriter writer(&method_call); + MethodCall method_call("org.chromium.TestInterface", "Echo"); + MessageWriter writer(&method_call); writer.AppendString(kHello); // Call the method. - scoped_ptr<dbus::Response> response( + scoped_ptr<Response> response( proxy->CallMethodAndBlock(&method_call, - dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); + ObjectProxy::TIMEOUT_USE_DEFAULT)); // Check the response. ASSERT_TRUE(response.get()); - dbus::MessageReader reader(response.get()); + MessageReader reader(response.get()); std::string text_message; ASSERT_TRUE(reader.PopString(&text_message)); // The text message should be echo'ed back. @@ -158,18 +159,18 @@ TEST_F(MockTest, CallMethod) { const char kHello[] = "hello"; // Get an object proxy from the mock bus. - dbus::ObjectProxy* proxy = mock_bus_->GetObjectProxy( + ObjectProxy* proxy = mock_bus_->GetObjectProxy( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject")); + ObjectPath("/org/chromium/TestObject")); // Create a method call. - dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); - dbus::MessageWriter writer(&method_call); + MethodCall method_call("org.chromium.TestInterface", "Echo"); + MessageWriter writer(&method_call); writer.AppendString(kHello); // Call the method. proxy->CallMethod(&method_call, - dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, + ObjectProxy::TIMEOUT_USE_DEFAULT, base::Bind(&MockTest::OnResponse, base::Unretained(this))); // Run the message loop to let OnResponse be called. @@ -177,3 +178,5 @@ TEST_F(MockTest, CallMethod) { EXPECT_EQ(kHello, response_string_); } + +} // namespace dbus diff --git a/dbus/object_manager_unittest.cc b/dbus/object_manager_unittest.cc index 79f4d21..c11bed6 100644 --- a/dbus/object_manager_unittest.cc +++ b/dbus/object_manager_unittest.cc @@ -19,26 +19,27 @@ #include "dbus/test_service.h" #include "testing/gtest/include/gtest/gtest.h" +namespace dbus { + // The object manager test exercises the asynchronous APIs in ObjectManager, // and by extension PropertySet and Property<>. class ObjectManagerTest : public testing::Test, - public dbus::ObjectManager::Interface { + public ObjectManager::Interface { public: ObjectManagerTest() { } - struct Properties : public dbus::PropertySet { - dbus::Property<std::string> name; - dbus::Property<int16> version; - dbus::Property<std::vector<std::string> > methods; - dbus::Property<std::vector<dbus::ObjectPath> > objects; + struct Properties : public PropertySet { + Property<std::string> name; + Property<int16> version; + Property<std::vector<std::string> > methods; + Property<std::vector<ObjectPath> > objects; - Properties(dbus::ObjectProxy* object_proxy, + Properties(ObjectProxy* object_proxy, const std::string& interface_name, PropertyChangedCallback property_changed_callback) - : dbus::PropertySet(object_proxy, interface_name, - property_changed_callback) { + : PropertySet(object_proxy, interface_name, property_changed_callback) { RegisterProperty("Name", &name); RegisterProperty("Version", &version); RegisterProperty("Methods", &methods); @@ -46,15 +47,15 @@ class ObjectManagerTest } }; - virtual dbus::PropertySet* CreateProperties( - dbus::ObjectProxy* object_proxy, - const dbus::ObjectPath& object_path, + virtual PropertySet* CreateProperties( + ObjectProxy* object_proxy, + const ObjectPath& object_path, const std::string& interface_name) OVERRIDE { Properties* properties = new Properties( object_proxy, interface_name, base::Bind(&ObjectManagerTest::OnPropertyChanged, base::Unretained(this), object_path)); - return static_cast<dbus::PropertySet*>(properties); + return static_cast<PropertySet*>(properties); } virtual void SetUp() { @@ -68,24 +69,24 @@ class ObjectManagerTest ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options)); // Start the test service, using the D-Bus thread. - dbus::TestService::Options options; + TestService::Options options; options.dbus_task_runner = dbus_thread_->message_loop_proxy(); - test_service_.reset(new dbus::TestService(options)); + test_service_.reset(new TestService(options)); ASSERT_TRUE(test_service_->StartService()); ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted()); ASSERT_TRUE(test_service_->HasDBusThread()); // Create the client, using the D-Bus thread. - dbus::Bus::Options bus_options; - bus_options.bus_type = dbus::Bus::SESSION; - bus_options.connection_type = dbus::Bus::PRIVATE; + Bus::Options bus_options; + bus_options.bus_type = Bus::SESSION; + bus_options.connection_type = Bus::PRIVATE; bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); - bus_ = new dbus::Bus(bus_options); + bus_ = new Bus(bus_options); ASSERT_TRUE(bus_->HasDBusThread()); object_manager_ = bus_->GetObjectManager( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestService")); + ObjectPath("/org/chromium/TestService")); object_manager_->RegisterInterface("org.chromium.TestInterface", this); object_manager_->GetManagedObjects(); @@ -106,28 +107,28 @@ class ObjectManagerTest test_service_->Stop(); } - void MethodCallback(dbus::Response* response) { + void MethodCallback(Response* response) { method_callback_called_ = true; message_loop_.Quit(); } -protected: + protected: // Called when an object is added. - virtual void ObjectAdded(const dbus::ObjectPath& object_path, - const std::string& interface_name) OVERRIDE { + virtual void ObjectAdded(const ObjectPath& object_path, + const std::string& interface_name) OVERRIDE { added_objects_.push_back(std::make_pair(object_path, interface_name)); message_loop_.Quit(); } // Called when an object is removed. - virtual void ObjectRemoved(const dbus::ObjectPath& object_path, + virtual void ObjectRemoved(const ObjectPath& object_path, const std::string& interface_name) OVERRIDE { removed_objects_.push_back(std::make_pair(object_path, interface_name)); message_loop_.Quit(); } // Called when a property value is updated. - void OnPropertyChanged(const dbus::ObjectPath& object_path, + void OnPropertyChanged(const ObjectPath& object_path, const std::string& name) { updated_properties_.push_back(name); message_loop_.Quit(); @@ -158,19 +159,18 @@ protected: method_callback_called_ = false; } - void PerformAction(const std::string& action, - const dbus::ObjectPath& object_path) { - dbus::ObjectProxy* object_proxy = bus_->GetObjectProxy( + void PerformAction(const std::string& action, const ObjectPath& object_path) { + ObjectProxy* object_proxy = bus_->GetObjectProxy( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject")); + ObjectPath("/org/chromium/TestObject")); - dbus::MethodCall method_call("org.chromium.TestInterface", "PerformAction"); - dbus::MessageWriter writer(&method_call); + MethodCall method_call("org.chromium.TestInterface", "PerformAction"); + MessageWriter writer(&method_call); writer.AppendString(action); writer.AppendObjectPath(object_path); object_proxy->CallMethod(&method_call, - dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, + ObjectProxy::TIMEOUT_USE_DEFAULT, base::Bind(&ObjectManagerTest::MethodCallback, base::Unretained(this))); WaitForMethodCallback(); @@ -178,12 +178,12 @@ protected: base::MessageLoop message_loop_; scoped_ptr<base::Thread> dbus_thread_; - scoped_refptr<dbus::Bus> bus_; - dbus::ObjectManager* object_manager_; - scoped_ptr<dbus::TestService> test_service_; + scoped_refptr<Bus> bus_; + ObjectManager* object_manager_; + scoped_ptr<TestService> test_service_; - std::vector<std::pair<dbus::ObjectPath, std::string> > added_objects_; - std::vector<std::pair<dbus::ObjectPath, std::string> > removed_objects_; + std::vector<std::pair<ObjectPath, std::string> > added_objects_; + std::vector<std::pair<ObjectPath, std::string> > removed_objects_; std::vector<std::string> updated_properties_; bool method_callback_called_; @@ -191,14 +191,13 @@ protected: TEST_F(ObjectManagerTest, InitialObject) { - dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy( - dbus::ObjectPath("/org/chromium/TestObject")); + ObjectProxy* object_proxy = object_manager_->GetObjectProxy( + ObjectPath("/org/chromium/TestObject")); EXPECT_TRUE(object_proxy != NULL); Properties* properties = static_cast<Properties*>( - object_manager_->GetProperties( - dbus::ObjectPath("/org/chromium/TestObject"), - "org.chromium.TestInterface")); + object_manager_->GetProperties(ObjectPath("/org/chromium/TestObject"), + "org.chromium.TestInterface")); EXPECT_TRUE(properties != NULL); EXPECT_EQ("TestService", properties->name.value()); @@ -211,129 +210,127 @@ TEST_F(ObjectManagerTest, InitialObject) { EXPECT_EQ("AsyncEcho", methods[2]); EXPECT_EQ("BrokenMethod", methods[3]); - std::vector<dbus::ObjectPath> objects = properties->objects.value(); + std::vector<ObjectPath> objects = properties->objects.value(); ASSERT_EQ(1U, objects.size()); - EXPECT_EQ(dbus::ObjectPath("/TestObjectPath"), objects[0]); + EXPECT_EQ(ObjectPath("/TestObjectPath"), objects[0]); } TEST_F(ObjectManagerTest, UnknownObjectProxy) { - dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy( - dbus::ObjectPath("/org/chromium/UnknownObject")); + ObjectProxy* object_proxy = object_manager_->GetObjectProxy( + ObjectPath("/org/chromium/UnknownObject")); EXPECT_TRUE(object_proxy == NULL); } TEST_F(ObjectManagerTest, UnknownObjectProperties) { Properties* properties = static_cast<Properties*>( - object_manager_->GetProperties( - dbus::ObjectPath("/org/chromium/UnknownObject"), - "org.chromium.TestInterface")); + object_manager_->GetProperties(ObjectPath("/org/chromium/UnknownObject"), + "org.chromium.TestInterface")); EXPECT_TRUE(properties == NULL); } TEST_F(ObjectManagerTest, UnknownInterfaceProperties) { Properties* properties = static_cast<Properties*>( - object_manager_->GetProperties( - dbus::ObjectPath("/org/chromium/TestObject"), - "org.chromium.UnknownService")); + object_manager_->GetProperties(ObjectPath("/org/chromium/TestObject"), + "org.chromium.UnknownService")); EXPECT_TRUE(properties == NULL); } TEST_F(ObjectManagerTest, GetObjects) { - std::vector<dbus::ObjectPath> object_paths = object_manager_->GetObjects(); + std::vector<ObjectPath> object_paths = object_manager_->GetObjects(); ASSERT_EQ(1U, object_paths.size()); - EXPECT_EQ(dbus::ObjectPath("/org/chromium/TestObject"), object_paths[0]); + EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[0]); } TEST_F(ObjectManagerTest, GetObjectsWithInterface) { - std::vector<dbus::ObjectPath> object_paths = + std::vector<ObjectPath> object_paths = object_manager_->GetObjectsWithInterface("org.chromium.TestInterface"); ASSERT_EQ(1U, object_paths.size()); - EXPECT_EQ(dbus::ObjectPath("/org/chromium/TestObject"), object_paths[0]); + EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[0]); } TEST_F(ObjectManagerTest, GetObjectsWithUnknownInterface) { - std::vector<dbus::ObjectPath> object_paths = + std::vector<ObjectPath> object_paths = object_manager_->GetObjectsWithInterface("org.chromium.UnknownService"); EXPECT_EQ(0U, object_paths.size()); } TEST_F(ObjectManagerTest, SameObject) { - dbus::ObjectManager* object_manager = bus_->GetObjectManager( + ObjectManager* object_manager = bus_->GetObjectManager( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestService")); + ObjectPath("/org/chromium/TestService")); EXPECT_EQ(object_manager_, object_manager); } TEST_F(ObjectManagerTest, DifferentObjectForService) { - dbus::ObjectManager* object_manager = bus_->GetObjectManager( + ObjectManager* object_manager = bus_->GetObjectManager( "org.chromium.DifferentService", - dbus::ObjectPath("/org/chromium/TestService")); + ObjectPath("/org/chromium/TestService")); EXPECT_NE(object_manager_, object_manager); } TEST_F(ObjectManagerTest, DifferentObjectForPath) { - dbus::ObjectManager* object_manager = bus_->GetObjectManager( + ObjectManager* object_manager = bus_->GetObjectManager( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/DifferentService")); + ObjectPath("/org/chromium/DifferentService")); EXPECT_NE(object_manager_, object_manager); } TEST_F(ObjectManagerTest, SecondObject) { - PerformAction("AddObject", dbus::ObjectPath("/org/chromium/SecondObject")); + PerformAction("AddObject", ObjectPath("/org/chromium/SecondObject")); WaitForObject(); - dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy( - dbus::ObjectPath("/org/chromium/SecondObject")); + ObjectProxy* object_proxy = object_manager_->GetObjectProxy( + ObjectPath("/org/chromium/SecondObject")); EXPECT_TRUE(object_proxy != NULL); Properties* properties = static_cast<Properties*>( - object_manager_->GetProperties( - dbus::ObjectPath("/org/chromium/SecondObject"), - "org.chromium.TestInterface")); + object_manager_->GetProperties(ObjectPath("/org/chromium/SecondObject"), + "org.chromium.TestInterface")); EXPECT_TRUE(properties != NULL); - std::vector<dbus::ObjectPath> object_paths = object_manager_->GetObjects(); + std::vector<ObjectPath> object_paths = object_manager_->GetObjects(); ASSERT_EQ(2U, object_paths.size()); std::sort(object_paths.begin(), object_paths.end()); - EXPECT_EQ(dbus::ObjectPath("/org/chromium/SecondObject"), object_paths[0]); - EXPECT_EQ(dbus::ObjectPath("/org/chromium/TestObject"), object_paths[1]); + EXPECT_EQ(ObjectPath("/org/chromium/SecondObject"), object_paths[0]); + EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[1]); object_paths = object_manager_->GetObjectsWithInterface("org.chromium.TestInterface"); ASSERT_EQ(2U, object_paths.size()); std::sort(object_paths.begin(), object_paths.end()); - EXPECT_EQ(dbus::ObjectPath("/org/chromium/SecondObject"), object_paths[0]); - EXPECT_EQ(dbus::ObjectPath("/org/chromium/TestObject"), object_paths[1]); + EXPECT_EQ(ObjectPath("/org/chromium/SecondObject"), object_paths[0]); + EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[1]); } TEST_F(ObjectManagerTest, RemoveSecondObject) { - PerformAction("AddObject", dbus::ObjectPath("/org/chromium/SecondObject")); + PerformAction("AddObject", ObjectPath("/org/chromium/SecondObject")); WaitForObject(); - std::vector<dbus::ObjectPath> object_paths = object_manager_->GetObjects(); + std::vector<ObjectPath> object_paths = object_manager_->GetObjects(); ASSERT_EQ(2U, object_paths.size()); - PerformAction("RemoveObject", dbus::ObjectPath("/org/chromium/SecondObject")); + PerformAction("RemoveObject", ObjectPath("/org/chromium/SecondObject")); WaitForRemoveObject(); - dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy( - dbus::ObjectPath("/org/chromium/SecondObject")); + ObjectProxy* object_proxy = object_manager_->GetObjectProxy( + ObjectPath("/org/chromium/SecondObject")); EXPECT_TRUE(object_proxy == NULL); Properties* properties = static_cast<Properties*>( - object_manager_->GetProperties( - dbus::ObjectPath("/org/chromium/SecondObject"), - "org.chromium.TestInterface")); + object_manager_->GetProperties(ObjectPath("/org/chromium/SecondObject"), + "org.chromium.TestInterface")); EXPECT_TRUE(properties == NULL); object_paths = object_manager_->GetObjects(); ASSERT_EQ(1U, object_paths.size()); - EXPECT_EQ(dbus::ObjectPath("/org/chromium/TestObject"), object_paths[0]); + EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[0]); object_paths = object_manager_->GetObjectsWithInterface("org.chromium.TestInterface"); ASSERT_EQ(1U, object_paths.size()); - EXPECT_EQ(dbus::ObjectPath("/org/chromium/TestObject"), object_paths[0]); + EXPECT_EQ(ObjectPath("/org/chromium/TestObject"), object_paths[0]); } + +} // namespace dbus diff --git a/dbus/property_unittest.cc b/dbus/property_unittest.cc index ed5bfc3..69211d3 100644 --- a/dbus/property_unittest.cc +++ b/dbus/property_unittest.cc @@ -19,6 +19,8 @@ #include "dbus/test_service.h" #include "testing/gtest/include/gtest/gtest.h" +namespace dbus { + // The property test exerises the asynchronous APIs in PropertySet and // Property<>. class PropertyTest : public testing::Test { @@ -26,17 +28,17 @@ class PropertyTest : public testing::Test { PropertyTest() { } - struct Properties : public dbus::PropertySet { - dbus::Property<std::string> name; - dbus::Property<int16> version; - dbus::Property<std::vector<std::string> > methods; - dbus::Property<std::vector<dbus::ObjectPath> > objects; + struct Properties : public PropertySet { + Property<std::string> name; + Property<int16> version; + Property<std::vector<std::string> > methods; + Property<std::vector<ObjectPath> > objects; - Properties(dbus::ObjectProxy* object_proxy, + Properties(ObjectProxy* object_proxy, PropertyChangedCallback property_changed_callback) - : dbus::PropertySet(object_proxy, - "org.chromium.TestInterface", - property_changed_callback) { + : PropertySet(object_proxy, + "org.chromium.TestInterface", + property_changed_callback) { RegisterProperty("Name", &name); RegisterProperty("Version", &version); RegisterProperty("Methods", &methods); @@ -55,22 +57,22 @@ class PropertyTest : public testing::Test { ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options)); // Start the test service, using the D-Bus thread. - dbus::TestService::Options options; + TestService::Options options; options.dbus_task_runner = dbus_thread_->message_loop_proxy(); - test_service_.reset(new dbus::TestService(options)); + test_service_.reset(new TestService(options)); ASSERT_TRUE(test_service_->StartService()); ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted()); ASSERT_TRUE(test_service_->HasDBusThread()); // Create the client, using the D-Bus thread. - dbus::Bus::Options bus_options; - bus_options.bus_type = dbus::Bus::SESSION; - bus_options.connection_type = dbus::Bus::PRIVATE; + Bus::Options bus_options; + bus_options.bus_type = Bus::SESSION; + bus_options.connection_type = Bus::PRIVATE; bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); - bus_ = new dbus::Bus(bus_options); + bus_ = new Bus(bus_options); object_proxy_ = bus_->GetObjectProxy( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject")); + ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(bus_->HasDBusThread()); // Create the properties structure @@ -138,10 +140,10 @@ class PropertyTest : public testing::Test { base::MessageLoop message_loop_; scoped_ptr<base::Thread> dbus_thread_; - scoped_refptr<dbus::Bus> bus_; - dbus::ObjectProxy* object_proxy_; + scoped_refptr<Bus> bus_; + ObjectProxy* object_proxy_; scoped_ptr<Properties> properties_; - scoped_ptr<dbus::TestService> test_service_; + scoped_ptr<TestService> test_service_; // Properties updated. std::vector<std::string> updated_properties_; // Last callback received. @@ -161,9 +163,9 @@ TEST_F(PropertyTest, InitialValues) { EXPECT_EQ("AsyncEcho", methods[2]); EXPECT_EQ("BrokenMethod", methods[3]); - std::vector<dbus::ObjectPath> objects = properties_->objects.value(); + std::vector<ObjectPath> objects = properties_->objects.value(); ASSERT_EQ(1U, objects.size()); - EXPECT_EQ(dbus::ObjectPath("/TestObjectPath"), objects[0]); + EXPECT_EQ(ObjectPath("/TestObjectPath"), objects[0]); } TEST_F(PropertyTest, UpdatedValues) { @@ -210,9 +212,9 @@ TEST_F(PropertyTest, UpdatedValues) { WaitForCallback("Objects"); WaitForUpdates(1); - std::vector<dbus::ObjectPath> objects = properties_->objects.value(); + std::vector<ObjectPath> objects = properties_->objects.value(); ASSERT_EQ(1U, objects.size()); - EXPECT_EQ(dbus::ObjectPath("/TestObjectPath"), objects[0]); + EXPECT_EQ(ObjectPath("/TestObjectPath"), objects[0]); } TEST_F(PropertyTest, Get) { @@ -245,3 +247,5 @@ TEST_F(PropertyTest, Set) { EXPECT_EQ("NewService", properties_->name.value()); } + +} // namespace dbus diff --git a/dbus/signal_sender_verification_unittest.cc b/dbus/signal_sender_verification_unittest.cc index ca9cb82..88367b5 100644 --- a/dbus/signal_sender_verification_unittest.cc +++ b/dbus/signal_sender_verification_unittest.cc @@ -17,6 +17,8 @@ #include "dbus/test_service.h" #include "testing/gtest/include/gtest/gtest.h" +namespace dbus { + // The test for sender verification in ObjectProxy. class SignalSenderVerificationTest : public testing::Test { public: @@ -38,14 +40,14 @@ class SignalSenderVerificationTest : public testing::Test { ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options)); // Create the client, using the D-Bus thread. - dbus::Bus::Options bus_options; - bus_options.bus_type = dbus::Bus::SESSION; - bus_options.connection_type = dbus::Bus::PRIVATE; + Bus::Options bus_options; + bus_options.bus_type = Bus::SESSION; + bus_options.connection_type = Bus::PRIVATE; bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); - bus_ = new dbus::Bus(bus_options); + bus_ = new Bus(bus_options); object_proxy_ = bus_->GetObjectProxy( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/TestObject")); + ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(bus_->HasDBusThread()); object_proxy_->SetNameOwnerChangedCallback( @@ -66,9 +68,9 @@ class SignalSenderVerificationTest : public testing::Test { message_loop_.Run(); // Start the test service, using the D-Bus thread. - dbus::TestService::Options options; + TestService::Options options; options.dbus_task_runner = dbus_thread_->message_loop_proxy(); - test_service_.reset(new dbus::TestService(options)); + test_service_.reset(new TestService(options)); ASSERT_TRUE(test_service_->StartService()); ASSERT_TRUE(test_service_->WaitUntilServiceIsStarted()); ASSERT_TRUE(test_service_->HasDBusThread()); @@ -76,7 +78,7 @@ class SignalSenderVerificationTest : public testing::Test { // Same setup for the second TestService. This service should not have the // ownership of the name at this point. - test_service2_.reset(new dbus::TestService(options)); + test_service2_.reset(new TestService(options)); ASSERT_TRUE(test_service2_->StartService()); ASSERT_TRUE(test_service2_->WaitUntilServiceIsStarted()); ASSERT_TRUE(test_service2_->HasDBusThread()); @@ -118,8 +120,8 @@ class SignalSenderVerificationTest : public testing::Test { message_loop_.Quit(); } - void OnNameOwnerChanged(bool* called_flag, dbus::Signal* signal) { - dbus::MessageReader reader(signal); + void OnNameOwnerChanged(bool* called_flag, Signal* signal) { + MessageReader reader(signal); std::string name, old_owner, new_owner; ASSERT_TRUE(reader.PopString(&name)); ASSERT_TRUE(reader.PopString(&old_owner)); @@ -131,8 +133,8 @@ class SignalSenderVerificationTest : public testing::Test { // Called when the "Test" signal is received, in the main thread. // Copy the string payload to |test_signal_string_|. - void OnTestSignal(dbus::Signal* signal) { - dbus::MessageReader reader(signal); + void OnTestSignal(Signal* signal) { + MessageReader reader(signal); ASSERT_TRUE(reader.PopString(&test_signal_string_)); message_loop_.Quit(); } @@ -154,10 +156,10 @@ class SignalSenderVerificationTest : public testing::Test { base::MessageLoop message_loop_; scoped_ptr<base::Thread> dbus_thread_; - scoped_refptr<dbus::Bus> bus_; - dbus::ObjectProxy* object_proxy_; - scoped_ptr<dbus::TestService> test_service_; - scoped_ptr<dbus::TestService> test_service2_; + scoped_refptr<Bus> bus_; + ObjectProxy* object_proxy_; + scoped_ptr<TestService> test_service_; + scoped_ptr<TestService> test_service2_; // Text message from "Test" signal. std::string test_signal_string_; @@ -248,9 +250,9 @@ TEST_F(SignalSenderVerificationTest, TestOwnerChanged) { TEST_F(SignalSenderVerificationTest, DISABLED_TestMultipleObjects) { const char kMessage[] = "hello, world"; - dbus::ObjectProxy* object_proxy2 = bus_->GetObjectProxy( + ObjectProxy* object_proxy2 = bus_->GetObjectProxy( "org.chromium.TestService", - dbus::ObjectPath("/org/chromium/DifferentObject")); + ObjectPath("/org/chromium/DifferentObject")); bool second_name_owner_changed_called = false; object_proxy2->SetNameOwnerChangedCallback( @@ -311,3 +313,5 @@ TEST_F(SignalSenderVerificationTest, DISABLED_TestMultipleObjects) { WaitForTestSignal(); ASSERT_EQ(kNewMessage, test_signal_string_); } + +} // namespace dbus diff --git a/dbus/string_util_unittest.cc b/dbus/string_util_unittest.cc index 99eb691..3d0ff51 100644 --- a/dbus/string_util_unittest.cc +++ b/dbus/string_util_unittest.cc @@ -5,23 +5,27 @@ #include "dbus/string_util.h" #include "testing/gtest/include/gtest/gtest.h" +namespace dbus { + TEST(StringUtilTest, IsValidObjectPath) { - EXPECT_TRUE(dbus::IsValidObjectPath("/")); - EXPECT_TRUE(dbus::IsValidObjectPath("/foo/bar")); - EXPECT_TRUE(dbus::IsValidObjectPath("/hoge_fuga/piyo123")); + EXPECT_TRUE(IsValidObjectPath("/")); + EXPECT_TRUE(IsValidObjectPath("/foo/bar")); + EXPECT_TRUE(IsValidObjectPath("/hoge_fuga/piyo123")); // Empty string. - EXPECT_FALSE(dbus::IsValidObjectPath(std::string())); - // Emptyr elemnt. - EXPECT_FALSE(dbus::IsValidObjectPath("//")); - EXPECT_FALSE(dbus::IsValidObjectPath("/foo//bar")); - EXPECT_FALSE(dbus::IsValidObjectPath("/foo///bar")); + EXPECT_FALSE(IsValidObjectPath(std::string())); + // Empty element. + EXPECT_FALSE(IsValidObjectPath("//")); + EXPECT_FALSE(IsValidObjectPath("/foo//bar")); + EXPECT_FALSE(IsValidObjectPath("/foo///bar")); // Trailing '/'. - EXPECT_FALSE(dbus::IsValidObjectPath("/foo/")); - EXPECT_FALSE(dbus::IsValidObjectPath("/foo/bar/")); + EXPECT_FALSE(IsValidObjectPath("/foo/")); + EXPECT_FALSE(IsValidObjectPath("/foo/bar/")); // Not beginning with '/'. - EXPECT_FALSE(dbus::IsValidObjectPath("foo/bar")); + EXPECT_FALSE(IsValidObjectPath("foo/bar")); // Invalid characters. - EXPECT_FALSE(dbus::IsValidObjectPath("/foo.bar")); - EXPECT_FALSE(dbus::IsValidObjectPath("/foo/*")); - EXPECT_FALSE(dbus::IsValidObjectPath("/foo/bar(1)")); + EXPECT_FALSE(IsValidObjectPath("/foo.bar")); + EXPECT_FALSE(IsValidObjectPath("/foo/*")); + EXPECT_FALSE(IsValidObjectPath("/foo/bar(1)")); } + +} // namespace dbus diff --git a/dbus/test_service.cc b/dbus/test_service.cc index c41d445..ae67bf7 100644 --- a/dbus/test_service.cc +++ b/dbus/test_service.cc @@ -91,15 +91,15 @@ void TestService::SendTestSignalFromRoot(const std::string& message) { } void TestService::SendTestSignalInternal(const std::string& message) { - dbus::Signal signal("org.chromium.TestInterface", "Test"); - dbus::MessageWriter writer(&signal); + Signal signal("org.chromium.TestInterface", "Test"); + MessageWriter writer(&signal); writer.AppendString(message); exported_object_->SendSignal(&signal); } void TestService::SendTestSignalFromRootInternal(const std::string& message) { - dbus::Signal signal("org.chromium.TestInterface", "Test"); - dbus::MessageWriter writer(&signal); + Signal signal("org.chromium.TestInterface", "Test"); + MessageWriter writer(&signal); writer.AppendString(message); bus_->RequestOwnership("org.chromium.TestService", @@ -108,8 +108,7 @@ void TestService::SendTestSignalFromRootInternal(const std::string& message) { base::Bind(&EmptyCallback))); // Use "/" just like dbus-send does. - ExportedObject* root_object = - bus_->GetExportedObject(dbus::ObjectPath("/")); + ExportedObject* root_object = bus_->GetExportedObject(ObjectPath("/")); root_object->SendSignal(&signal); } @@ -166,7 +165,7 @@ void TestService::Run(base::MessageLoop* message_loop) { base::Bind(&EmptyCallback))); exported_object_ = bus_->GetExportedObject( - dbus::ObjectPath("/org/chromium/TestObject")); + ObjectPath("/org/chromium/TestObject")); int num_methods = 0; exported_object_->ExportMethod( @@ -242,7 +241,7 @@ void TestService::Run(base::MessageLoop* message_loop) { ++num_methods; exported_object_manager_ = bus_->GetExportedObject( - dbus::ObjectPath("/org/chromium/TestService")); + ObjectPath("/org/chromium/TestService")); exported_object_manager_->ExportMethod( kObjectManagerInterface, @@ -262,11 +261,11 @@ void TestService::Run(base::MessageLoop* message_loop) { } void TestService::Echo(MethodCall* method_call, - dbus::ExportedObject::ResponseSender response_sender) { + ExportedObject::ResponseSender response_sender) { MessageReader reader(method_call); std::string text_message; if (!reader.PopString(&text_message)) { - response_sender.Run(scoped_ptr<dbus::Response>()); + response_sender.Run(scoped_ptr<Response>()); return; } @@ -276,16 +275,14 @@ void TestService::Echo(MethodCall* method_call, response_sender.Run(response.Pass()); } -void TestService::SlowEcho( - MethodCall* method_call, - dbus::ExportedObject::ResponseSender response_sender) { +void TestService::SlowEcho(MethodCall* method_call, + ExportedObject::ResponseSender response_sender) { base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); Echo(method_call, response_sender); } -void TestService::AsyncEcho( - MethodCall* method_call, - dbus::ExportedObject::ResponseSender response_sender) { +void TestService::AsyncEcho(MethodCall* method_call, + ExportedObject::ResponseSender response_sender) { // Schedule a call to Echo() to send an asynchronous response after we return. message_loop()->PostDelayedTask(FROM_HERE, base::Bind(&TestService::Echo, @@ -295,20 +292,19 @@ void TestService::AsyncEcho( TestTimeouts::tiny_timeout()); } -void TestService::BrokenMethod( - MethodCall* method_call, - dbus::ExportedObject::ResponseSender response_sender) { - response_sender.Run(scoped_ptr<dbus::Response>()); +void TestService::BrokenMethod(MethodCall* method_call, + ExportedObject::ResponseSender response_sender) { + response_sender.Run(scoped_ptr<Response>()); } void TestService::GetAllProperties( MethodCall* method_call, - dbus::ExportedObject::ResponseSender response_sender) { + ExportedObject::ResponseSender response_sender) { MessageReader reader(method_call); std::string interface; if (!reader.PopString(&interface)) { - response_sender.Run(scoped_ptr<dbus::Response>()); + response_sender.Run(scoped_ptr<Response>()); return; } @@ -320,19 +316,18 @@ void TestService::GetAllProperties( response_sender.Run(response.Pass()); } -void TestService::GetProperty( - MethodCall* method_call, - dbus::ExportedObject::ResponseSender response_sender) { +void TestService::GetProperty(MethodCall* method_call, + ExportedObject::ResponseSender response_sender) { MessageReader reader(method_call); std::string interface; if (!reader.PopString(&interface)) { - response_sender.Run(scoped_ptr<dbus::Response>()); + response_sender.Run(scoped_ptr<Response>()); return; } std::string name; if (!reader.PopString(&name)) { - response_sender.Run(scoped_ptr<dbus::Response>()); + response_sender.Run(scoped_ptr<Response>()); return; } @@ -382,42 +377,41 @@ void TestService::GetProperty( writer.OpenVariant("ao", &variant_writer); variant_writer.OpenArray("o", &variant_array_writer); - variant_array_writer.AppendObjectPath(dbus::ObjectPath("/TestObjectPath")); + variant_array_writer.AppendObjectPath(ObjectPath("/TestObjectPath")); variant_writer.CloseContainer(&variant_array_writer); writer.CloseContainer(&variant_writer); response_sender.Run(response.Pass()); } else { // Return error. - response_sender.Run(scoped_ptr<dbus::Response>()); + response_sender.Run(scoped_ptr<Response>()); return; } } -void TestService::SetProperty( - MethodCall* method_call, - dbus::ExportedObject::ResponseSender response_sender) { +void TestService::SetProperty(MethodCall* method_call, + ExportedObject::ResponseSender response_sender) { MessageReader reader(method_call); std::string interface; if (!reader.PopString(&interface)) { - response_sender.Run(scoped_ptr<dbus::Response>()); + response_sender.Run(scoped_ptr<Response>()); return; } std::string name; if (!reader.PopString(&name)) { - response_sender.Run(scoped_ptr<dbus::Response>()); + response_sender.Run(scoped_ptr<Response>()); return; } if (name != "Name") { - response_sender.Run(scoped_ptr<dbus::Response>()); + response_sender.Run(scoped_ptr<Response>()); return; } std::string value; if (!reader.PopVariantOfString(&value)) { - response_sender.Run(scoped_ptr<dbus::Response>()); + response_sender.Run(scoped_ptr<Response>()); return; } @@ -428,12 +422,12 @@ void TestService::SetProperty( void TestService::PerformAction( MethodCall* method_call, - dbus::ExportedObject::ResponseSender response_sender) { + ExportedObject::ResponseSender response_sender) { MessageReader reader(method_call); std::string action; - dbus::ObjectPath object_path; + ObjectPath object_path; if (!reader.PopString(&action) || !reader.PopObjectPath(&object_path)) { - response_sender.Run(scoped_ptr<dbus::Response>()); + response_sender.Run(scoped_ptr<Response>()); return; } @@ -448,7 +442,7 @@ void TestService::PerformAction( void TestService::GetManagedObjects( MethodCall* method_call, - dbus::ExportedObject::ResponseSender response_sender) { + ExportedObject::ResponseSender response_sender) { scoped_ptr<Response> response = Response::FromMethodCall(method_call); MessageWriter writer(response.get()); @@ -473,8 +467,7 @@ void TestService::GetManagedObjects( writer.OpenArray("{oa{sa{sv}}}", &array_writer); array_writer.OpenDictEntry(&dict_entry_writer); - dict_entry_writer.AppendObjectPath( - dbus::ObjectPath("/org/chromium/TestObject")); + dict_entry_writer.AppendObjectPath(ObjectPath("/org/chromium/TestObject")); dict_entry_writer.OpenArray("{sa{sv}}", &object_array_writer); object_array_writer.OpenDictEntry(&object_dict_entry_writer); @@ -490,8 +483,7 @@ void TestService::GetManagedObjects( response_sender.Run(response.Pass()); } -void TestService::AddPropertiesToWriter(MessageWriter* writer) -{ +void TestService::AddPropertiesToWriter(MessageWriter* writer) { // The properties response is a dictionary of strings identifying the // property and a variant containing the property value. We return all // of the properties, thus the response is: @@ -501,7 +493,7 @@ void TestService::AddPropertiesToWriter(MessageWriter* writer) // "Version": Variant<10>, // "Methods": Variant<["Echo", "SlowEcho", "AsyncEcho", "BrokenMethod"]>, // "Objects": Variant<[objectpath:"/TestObjectPath"]> - // ] + // } MessageWriter array_writer(NULL); MessageWriter dict_entry_writer(NULL); @@ -536,7 +528,7 @@ void TestService::AddPropertiesToWriter(MessageWriter* writer) dict_entry_writer.AppendString("Objects"); dict_entry_writer.OpenVariant("ao", &variant_writer); variant_writer.OpenArray("o", &variant_array_writer); - variant_array_writer.AppendObjectPath(dbus::ObjectPath("/TestObjectPath")); + variant_array_writer.AppendObjectPath(ObjectPath("/TestObjectPath")); variant_writer.CloseContainer(&variant_array_writer); dict_entry_writer.CloseContainer(&variant_writer); array_writer.CloseContainer(&dict_entry_writer); @@ -544,7 +536,7 @@ void TestService::AddPropertiesToWriter(MessageWriter* writer) writer->CloseContainer(&array_writer); } -void TestService::AddObject(const dbus::ObjectPath& object_path) { +void TestService::AddObject(const ObjectPath& object_path) { message_loop()->PostTask( FROM_HERE, base::Bind(&TestService::AddObjectInternal, @@ -552,9 +544,9 @@ void TestService::AddObject(const dbus::ObjectPath& object_path) { object_path)); } -void TestService::AddObjectInternal(const dbus::ObjectPath& object_path) { - dbus::Signal signal(kObjectManagerInterface, kObjectManagerInterfacesAdded); - dbus::MessageWriter writer(&signal); +void TestService::AddObjectInternal(const ObjectPath& object_path) { + Signal signal(kObjectManagerInterface, kObjectManagerInterfacesAdded); + MessageWriter writer(&signal); writer.AppendObjectPath(object_path); MessageWriter array_writer(NULL); @@ -570,17 +562,16 @@ void TestService::AddObjectInternal(const dbus::ObjectPath& object_path) { exported_object_manager_->SendSignal(&signal); } -void TestService::RemoveObject(const dbus::ObjectPath& object_path) { - message_loop()->PostTask( - FROM_HERE, - base::Bind(&TestService::RemoveObjectInternal, - base::Unretained(this), - object_path)); +void TestService::RemoveObject(const ObjectPath& object_path) { + message_loop()->PostTask(FROM_HERE, + base::Bind(&TestService::RemoveObjectInternal, + base::Unretained(this), + object_path)); } -void TestService::RemoveObjectInternal(const dbus::ObjectPath& object_path) { - dbus::Signal signal(kObjectManagerInterface, kObjectManagerInterfacesRemoved); - dbus::MessageWriter writer(&signal); +void TestService::RemoveObjectInternal(const ObjectPath& object_path) { + Signal signal(kObjectManagerInterface, kObjectManagerInterfacesRemoved); + MessageWriter writer(&signal); writer.AppendObjectPath(object_path); @@ -600,8 +591,8 @@ void TestService::SendPropertyChangedSignal(const std::string& name) { } void TestService::SendPropertyChangedSignalInternal(const std::string& name) { - dbus::Signal signal(kPropertiesInterface, kPropertiesChanged); - dbus::MessageWriter writer(&signal); + Signal signal(kPropertiesInterface, kPropertiesChanged); + MessageWriter writer(&signal); writer.AppendString("org.chromium.TestInterface"); MessageWriter array_writer(NULL); diff --git a/dbus/values_util_unittest.cc b/dbus/values_util_unittest.cc index 9e98bb9..2de12d7 100644 --- a/dbus/values_util_unittest.cc +++ b/dbus/values_util_unittest.cc @@ -13,10 +13,12 @@ #include "dbus/message.h" #include "testing/gtest/include/gtest/gtest.h" +namespace dbus { + TEST(ValuesUtilTest, PopBasicTypes) { - scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + scoped_ptr<Response> response(Response::CreateEmpty()); // Append basic type values. - dbus::MessageWriter writer(response.get()); + MessageWriter writer(response.get()); const uint8 kByteValue = 42; writer.AppendByte(kByteValue); const bool kBoolValue = true; @@ -39,81 +41,81 @@ TEST(ValuesUtilTest, PopBasicTypes) { writer.AppendString(kStringValue); const std::string kEmptyStringValue; writer.AppendString(kEmptyStringValue); - const dbus::ObjectPath kObjectPathValue("/ObjectPath"); + const ObjectPath kObjectPathValue("/ObjectPath"); writer.AppendObjectPath(kObjectPathValue); - dbus::MessageReader reader(response.get()); + MessageReader reader(response.get()); scoped_ptr<base::Value> value; scoped_ptr<base::Value> expected_value; // Pop a byte. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset(new base::FundamentalValue(kByteValue)); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop a bool. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset(new base::FundamentalValue(kBoolValue)); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop an int16. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset(new base::FundamentalValue(kInt16Value)); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop a uint16. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset(new base::FundamentalValue(kUint16Value)); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop an int32. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset(new base::FundamentalValue(kInt32Value)); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop a uint32. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset( new base::FundamentalValue(static_cast<double>(kUint32Value))); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop an int64. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset( new base::FundamentalValue(static_cast<double>(kInt64Value))); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop a uint64. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset( new base::FundamentalValue(static_cast<double>(kUint64Value))); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop a double. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset(new base::FundamentalValue(kDoubleValue)); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop a string. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset(new base::StringValue(kStringValue)); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop an empty string. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset(new base::StringValue(kEmptyStringValue)); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop an object path. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset(new base::StringValue(kObjectPathValue.value())); EXPECT_TRUE(value->Equals(expected_value.get())); } TEST(ValuesUtilTest, PopVariant) { - scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + scoped_ptr<Response> response(Response::CreateEmpty()); // Append variant values. - dbus::MessageWriter writer(response.get()); + MessageWriter writer(response.get()); const bool kBoolValue = true; writer.AppendVariantOfBool(kBoolValue); const int32 kInt32Value = -45; @@ -123,26 +125,26 @@ TEST(ValuesUtilTest, PopVariant) { const std::string kStringValue = "fifty"; writer.AppendVariantOfString(kStringValue); - dbus::MessageReader reader(response.get()); + MessageReader reader(response.get()); scoped_ptr<base::Value> value; scoped_ptr<base::Value> expected_value; // Pop a bool. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset(new base::FundamentalValue(kBoolValue)); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop an int32. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset(new base::FundamentalValue(kInt32Value)); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop a double. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset(new base::FundamentalValue(kDoubleValue)); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop a string. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset(new base::StringValue(kStringValue)); EXPECT_TRUE(value->Equals(expected_value.get())); @@ -151,20 +153,20 @@ TEST(ValuesUtilTest, PopVariant) { // Pop extremely large integers which cannot be precisely represented in // double. TEST(ValuesUtilTest, PopExtremelyLargeIntegers) { - scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + scoped_ptr<Response> response(Response::CreateEmpty()); // Append large integers. - dbus::MessageWriter writer(response.get()); + MessageWriter writer(response.get()); const int64 kInt64Value = -123456789012345689LL; writer.AppendInt64(kInt64Value); const uint64 kUint64Value = 9876543210987654321ULL; writer.AppendUint64(kUint64Value); - dbus::MessageReader reader(response.get()); + MessageReader reader(response.get()); scoped_ptr<base::Value> value; scoped_ptr<base::Value> expected_value; double double_value = 0; // Pop an int64. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset( new base::FundamentalValue(static_cast<double>(kInt64Value))); @@ -172,7 +174,7 @@ TEST(ValuesUtilTest, PopExtremelyLargeIntegers) { ASSERT_TRUE(value->GetAsDouble(&double_value)); EXPECT_NE(kInt64Value, static_cast<int64>(double_value)); // Pop a uint64. - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); expected_value.reset( new base::FundamentalValue(static_cast<double>(kUint64Value))); @@ -182,10 +184,10 @@ TEST(ValuesUtilTest, PopExtremelyLargeIntegers) { } TEST(ValuesUtilTest, PopIntArray) { - scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + scoped_ptr<Response> response(Response::CreateEmpty()); // Append an int32 array. - dbus::MessageWriter writer(response.get()); - dbus::MessageWriter sub_writer(NULL); + MessageWriter writer(response.get()); + MessageWriter sub_writer(NULL); std::vector<int32> data; data.push_back(0); data.push_back(1); @@ -201,17 +203,17 @@ TEST(ValuesUtilTest, PopIntArray) { list_value->Append(new base::FundamentalValue(data[i])); // Pop an int32 array. - dbus::MessageReader reader(response.get()); - scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); + MessageReader reader(response.get()); + scoped_ptr<base::Value> value(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(list_value.get())); } TEST(ValuesUtilTest, PopStringArray) { - scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + scoped_ptr<Response> response(Response::CreateEmpty()); // Append a string array. - dbus::MessageWriter writer(response.get()); - dbus::MessageWriter sub_writer(NULL); + MessageWriter writer(response.get()); + MessageWriter sub_writer(NULL); std::vector<std::string> data; data.push_back("Dreamlifter"); data.push_back("Beluga"); @@ -224,17 +226,17 @@ TEST(ValuesUtilTest, PopStringArray) { list_value->Append(new base::StringValue(data[i])); // Pop a string array. - dbus::MessageReader reader(response.get()); - scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); + MessageReader reader(response.get()); + scoped_ptr<base::Value> value(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(list_value.get())); } TEST(ValuesUtilTest, PopStruct) { - scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + scoped_ptr<Response> response(Response::CreateEmpty()); // Append a struct. - dbus::MessageWriter writer(response.get()); - dbus::MessageWriter sub_writer(NULL); + MessageWriter writer(response.get()); + MessageWriter sub_writer(NULL); writer.OpenStruct(&sub_writer); const bool kBoolValue = true; sub_writer.AppendBool(kBoolValue); @@ -254,18 +256,18 @@ TEST(ValuesUtilTest, PopStruct) { list_value.Append(new base::StringValue(kStringValue)); // Pop a struct. - dbus::MessageReader reader(response.get()); - scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); + MessageReader reader(response.get()); + scoped_ptr<base::Value> value(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&list_value)); } TEST(ValuesUtilTest, PopStringToVariantDictionary) { - scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + scoped_ptr<Response> response(Response::CreateEmpty()); // Append a dictionary. - dbus::MessageWriter writer(response.get()); - dbus::MessageWriter sub_writer(NULL); - dbus::MessageWriter entry_writer(NULL); + MessageWriter writer(response.get()); + MessageWriter sub_writer(NULL); + MessageWriter entry_writer(NULL); writer.OpenArray("{sv}", &sub_writer); sub_writer.OpenDictEntry(&entry_writer); const std::string kKey1 = "one"; @@ -301,18 +303,18 @@ TEST(ValuesUtilTest, PopStringToVariantDictionary) { dictionary_value.SetString(kKey4, kStringValue); // Pop a dictinoary. - dbus::MessageReader reader(response.get()); - scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); + MessageReader reader(response.get()); + scoped_ptr<base::Value> value(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&dictionary_value)); } TEST(ValuesUtilTest, PopDictionaryWithDottedStringKey) { - scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + scoped_ptr<Response> response(Response::CreateEmpty()); // Append a dictionary. - dbus::MessageWriter writer(response.get()); - dbus::MessageWriter sub_writer(NULL); - dbus::MessageWriter entry_writer(NULL); + MessageWriter writer(response.get()); + MessageWriter sub_writer(NULL); + MessageWriter entry_writer(NULL); writer.OpenArray("{sv}", &sub_writer); sub_writer.OpenDictEntry(&entry_writer); const std::string kKey1 = "www.example.com"; // String including dots. @@ -344,8 +346,8 @@ TEST(ValuesUtilTest, PopDictionaryWithDottedStringKey) { kKey3, new base::FundamentalValue(kDoubleValue)); // Pop a dictinoary. - dbus::MessageReader reader(response.get()); - scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); + MessageReader reader(response.get()); + scoped_ptr<base::Value> value(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&dictionary_value)); } @@ -359,12 +361,12 @@ TEST(ValuesUtilTest, PopDoubleToIntDictionary) { keys[i] = sqrt(values[i]); // Append a dictionary. - scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(response.get()); - dbus::MessageWriter sub_writer(NULL); + scoped_ptr<Response> response(Response::CreateEmpty()); + MessageWriter writer(response.get()); + MessageWriter sub_writer(NULL); writer.OpenArray("{di}", &sub_writer); for (size_t i = 0; i != values.size(); ++i) { - dbus::MessageWriter entry_writer(NULL); + MessageWriter entry_writer(NULL); sub_writer.OpenDictEntry(&entry_writer); entry_writer.AppendDouble(keys[i]); entry_writer.AppendInt32(values[i]); @@ -383,8 +385,8 @@ TEST(ValuesUtilTest, PopDoubleToIntDictionary) { } // Pop a dictionary. - dbus::MessageReader reader(response.get()); - scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); + MessageReader reader(response.get()); + scoped_ptr<base::Value> value(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&dictionary_value)); } @@ -395,25 +397,25 @@ TEST(ValuesUtilTest, AppendBasicTypes) { const base::FundamentalValue kDoubleValue(4.2); const base::StringValue kStringValue("string"); - scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(response.get()); + scoped_ptr<Response> response(Response::CreateEmpty()); + MessageWriter writer(response.get()); AppendBasicTypeValueData(&writer, kBoolValue); AppendBasicTypeValueData(&writer, kIntegerValue); AppendBasicTypeValueData(&writer, kDoubleValue); AppendBasicTypeValueData(&writer, kStringValue); - dbus::MessageReader reader(response.get()); + MessageReader reader(response.get()); scoped_ptr<base::Value> value; - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&kBoolValue)); - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&kIntegerValue)); - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&kDoubleValue)); - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&kStringValue)); } @@ -424,25 +426,27 @@ TEST(ValuesUtilTest, AppendBasicTypesAsVariant) { const base::FundamentalValue kDoubleValue(4.2); const base::StringValue kStringValue("string"); - scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); - dbus::MessageWriter writer(response.get()); + scoped_ptr<Response> response(Response::CreateEmpty()); + MessageWriter writer(response.get()); AppendBasicTypeValueDataAsVariant(&writer, kBoolValue); AppendBasicTypeValueDataAsVariant(&writer, kIntegerValue); AppendBasicTypeValueDataAsVariant(&writer, kDoubleValue); AppendBasicTypeValueDataAsVariant(&writer, kStringValue); - dbus::MessageReader reader(response.get()); + MessageReader reader(response.get()); scoped_ptr<base::Value> value; - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&kBoolValue)); - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&kIntegerValue)); - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&kDoubleValue)); - value.reset(dbus::PopDataAsValue(&reader)); + value.reset(PopDataAsValue(&reader)); ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&kStringValue)); } + +} // namespace dbus |