summaryrefslogtreecommitdiffstats
path: root/dbus/mock_unittest.cc
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-13 06:37:19 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-13 06:37:19 +0000
commit2a57ca64048fe077fdf841cd49e76fa787a6c251 (patch)
treed36ef5ece5ac34e0beca6f5db4e773b05023d1ce /dbus/mock_unittest.cc
parentacf883a85d1bafb447d4c4ebae4687da988bf1cc (diff)
downloadchromium_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/mock_unittest.cc')
-rw-r--r--dbus/mock_unittest.cc69
1 files changed, 36 insertions, 33 deletions
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