| Index: dbus/bus_unittest.cc
|
| diff --git a/dbus/bus_unittest.cc b/dbus/bus_unittest.cc
|
| index 5cd198d9f50757f4bf614c5ce17b9d7b14fcf38d..5c34ab059e78bc3a0b9c374570d6bc3d9b070c2f 100644
|
| --- a/dbus/bus_unittest.cc
|
| +++ b/dbus/bus_unittest.cc
|
| @@ -4,13 +4,33 @@
|
|
|
| #include "dbus/bus.h"
|
|
|
| +#include "base/bind.h"
|
| +#include "base/message_loop.h"
|
| #include "base/memory/ref_counted.h"
|
| +#include "base/threading/thread.h"
|
| #include "dbus/exported_object.h"
|
| #include "dbus/object_proxy.h"
|
|
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| -TEST(BusTest, GetObjectProxy) {
|
| +class BusTest : public testing::Test {
|
| + public:
|
| + BusTest()
|
| + : on_shutdown_called_(false) {
|
| + }
|
| +
|
| + // Called when a Bus object is shut down by Bus::Shutdown().
|
| + void OnShutdown() {
|
| + on_shutdown_called_ = true;
|
| + message_loop_.Quit();
|
| + }
|
| +
|
| + protected:
|
| + MessageLoop message_loop_;
|
| + bool on_shutdown_called_;
|
| +};
|
| +
|
| +TEST_F(BusTest, GetObjectProxy) {
|
| dbus::Bus::Options options;
|
| scoped_refptr<dbus::Bus> bus = new dbus::Bus(options);
|
|
|
| @@ -34,7 +54,7 @@ TEST(BusTest, GetObjectProxy) {
|
| EXPECT_NE(object_proxy1, object_proxy3);
|
| }
|
|
|
| -TEST(BusTest, GetExportedObject) {
|
| +TEST_F(BusTest, GetExportedObject) {
|
| dbus::Bus::Options options;
|
| scoped_refptr<dbus::Bus> bus = new dbus::Bus(options);
|
|
|
| @@ -57,3 +77,45 @@ TEST(BusTest, GetExportedObject) {
|
| ASSERT_TRUE(object_proxy3);
|
| EXPECT_NE(object_proxy1, object_proxy3);
|
| }
|
| +
|
| +TEST_F(BusTest, ShutdownAndBlock) {
|
| + dbus::Bus::Options options;
|
| + scoped_refptr<dbus::Bus> bus = new dbus::Bus(options);
|
| + ASSERT_FALSE(bus->shutdown_completed());
|
| +
|
| + // Shut down synchronously.
|
| + bus->ShutdownAndBlock();
|
| + EXPECT_TRUE(bus->shutdown_completed());
|
| +}
|
| +
|
| +TEST_F(BusTest, Shutdown) {
|
| + dbus::Bus::Options options;
|
| + scoped_refptr<dbus::Bus> bus = new dbus::Bus(options);
|
| + ASSERT_FALSE(bus->shutdown_completed());
|
| +
|
| + // Shut down asynchronously using the message loop.
|
| + bus->Shutdown(base::Bind(&BusTest::OnShutdown,
|
| + base::Unretained(this)));
|
| + message_loop_.Run();
|
| + EXPECT_TRUE(on_shutdown_called_);
|
| + EXPECT_TRUE(bus->shutdown_completed());
|
| +}
|
| +
|
| +TEST_F(BusTest, ShutdownAndBlockWithDBusThread) {
|
| + // Start the D-Bus thread.
|
| + base::Thread::Options thread_options;
|
| + thread_options.message_loop_type = MessageLoop::TYPE_IO;
|
| + base::Thread dbus_thread("D-Bus thread");
|
| + dbus_thread.StartWithOptions(thread_options);
|
| +
|
| + // Create the bus.
|
| + dbus::Bus::Options options;
|
| + options.dbus_thread = &dbus_thread;
|
| + scoped_refptr<dbus::Bus> bus = new dbus::Bus(options);
|
| + ASSERT_FALSE(bus->shutdown_completed());
|
| +
|
| + // Shut down synchronously.
|
| + bus->ShutdownAndBlockWithDBusThread();
|
| + EXPECT_TRUE(bus->shutdown_completed());
|
| + dbus_thread.Stop();
|
| +}
|
|
|