Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: dbus/mock_unittest.cc

Issue 16012018: Cleanup: Put DBus unit tests in the dbus namespace, so one does not need to write dbus:: everywhere… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dbus/message_unittest.cc ('k') | dbus/object_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/mock_unittest.cc
===================================================================
--- dbus/mock_unittest.cc (revision 205628)
+++ dbus/mock_unittest.cc (working copy)
@@ -20,6 +20,8 @@
using ::testing::Return;
using ::testing::Unused;
+namespace dbus {
+
class MockTest : public testing::Test {
public:
MockTest() {
@@ -27,15 +29,15 @@
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 @@
// 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 @@
}
// 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 @@
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 @@
// 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 @@
// 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 @@
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 @@
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 @@
EXPECT_EQ(kHello, response_string_);
}
+
+} // namespace dbus
« no previous file with comments | « dbus/message_unittest.cc ('k') | dbus/object_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698