This source file includes following definitions.
- SetUp
- TearDown
- OnServiceIsAvailable
- TEST_F
#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "dbus/bus.h"
#include "dbus/object_proxy.h"
#include "dbus/test_service.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace dbus {
namespace {
class ObjectProxyTest : public testing::Test {
protected:
virtual void SetUp() OVERRIDE {
Bus::Options bus_options;
bus_options.bus_type = Bus::SESSION;
bus_options.connection_type = Bus::PRIVATE;
bus_ = new Bus(bus_options);
object_proxy_ = bus_->GetObjectProxy(
"org.chromium.TestService", ObjectPath("/org/chromium/TestObject"));
}
virtual void TearDown() OVERRIDE {
bus_->ShutdownAndBlock();
}
base::MessageLoopForIO message_loop_;
scoped_refptr<Bus> bus_;
ObjectProxy* object_proxy_;
};
void OnServiceIsAvailable(scoped_ptr<base::RunLoop>* run_loop,
bool service_is_available) {
EXPECT_TRUE(service_is_available);
ASSERT_TRUE(*run_loop);
(*run_loop)->Quit();
}
TEST_F(ObjectProxyTest, WaitForServiceToBeAvailable) {
scoped_ptr<base::RunLoop> run_loop;
object_proxy_->WaitForServiceToBeAvailable(
base::Bind(&OnServiceIsAvailable, &run_loop));
base::RunLoop().RunUntilIdle();
TestService::Options options;
TestService test_service(options);
ASSERT_TRUE(test_service.StartService());
ASSERT_TRUE(test_service.WaitUntilServiceIsStarted());
ASSERT_TRUE(test_service.has_ownership());
run_loop.reset(new base::RunLoop);
run_loop->Run();
run_loop.reset(new base::RunLoop);
object_proxy_->WaitForServiceToBeAvailable(
base::Bind(&OnServiceIsAvailable, &run_loop));
run_loop->Run();
test_service.ShutdownAndBlock();
test_service.Stop();
}
}
}