summaryrefslogtreecommitdiffstats
path: root/dbus/end_to_end_async_unittest.cc
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-23 07:29:21 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-23 07:29:21 +0000
commit3beaaa4e9b8c41be94e1688a075357b5ae58a280 (patch)
tree1c7b6d7abc4a6d54346334c132ceb5f71869661c /dbus/end_to_end_async_unittest.cc
parent852754acf9190bd253e8c2e9b45d2b761cf7a12a (diff)
downloadchromium_src-3beaaa4e9b8c41be94e1688a075357b5ae58a280.zip
chromium_src-3beaaa4e9b8c41be94e1688a075357b5ae58a280.tar.gz
chromium_src-3beaaa4e9b8c41be94e1688a075357b5ae58a280.tar.bz2
Add support for sending and receiving D-Bus signals.
ObjectProxy is used to receive signals from the remote object. ExportedObject is used to send signals from the exported object. Note that signals are asynchronos so we don't have a test in end_to_end_sync_unittest.cc BUG=90036 TEST=run unit tests Review URL: http://codereview.chromium.org/7655033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97831 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus/end_to_end_async_unittest.cc')
-rw-r--r--dbus/end_to_end_async_unittest.cc45
1 files changed, 45 insertions, 0 deletions
diff --git a/dbus/end_to_end_async_unittest.cc b/dbus/end_to_end_async_unittest.cc
index 3ce6b6d..cf22a41 100644
--- a/dbus/end_to_end_async_unittest.cc
+++ b/dbus/end_to_end_async_unittest.cc
@@ -52,6 +52,17 @@ class EndToEndAsyncTest : public testing::Test {
object_proxy_ = bus_->GetObjectProxy("org.chromium.TestService",
"/org/chromium/TestObject");
ASSERT_TRUE(bus_->HasDBusThread());
+
+ // Connect to the "Test" signal from the remote object.
+ object_proxy_->ConnectToSignal(
+ "org.chromium.TestInterface",
+ "Test",
+ base::Bind(&EndToEndAsyncTest::OnTestSignal,
+ base::Unretained(this)),
+ base::Bind(&EndToEndAsyncTest::OnConnected,
+ base::Unretained(this)));
+ // Wait until the object proxy is connected to the signal.
+ message_loop_.Run();
}
void TearDown() {
@@ -111,12 +122,36 @@ class EndToEndAsyncTest : public testing::Test {
message_loop_.Quit();
}
+ // 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);
+ ASSERT_TRUE(reader.PopString(&test_signal_string_));
+ message_loop_.Quit();
+ }
+
+ // Called when connected to the signal.
+ void OnConnected(const std::string& interface_name,
+ const std::string& signal_name,
+ bool success) {
+ ASSERT_TRUE(success);
+ message_loop_.Quit();
+ }
+
+ // Wait for the hey signal to be received.
+ void WaitForTestSignal() {
+ // OnTestSignal() will quit the message loop.
+ message_loop_.Run();
+ }
+
MessageLoop message_loop_;
std::vector<std::string> response_strings_;
scoped_ptr<base::Thread> dbus_thread_;
scoped_refptr<dbus::Bus> bus_;
dbus::ObjectProxy* object_proxy_;
scoped_ptr<dbus::TestService> test_service_;
+ // Text message from "Test" signal.
+ std::string test_signal_string_;
};
TEST_F(EndToEndAsyncTest, Echo) {
@@ -198,3 +233,13 @@ TEST_F(EndToEndAsyncTest, BrokenMethod) {
// Should fail because the method is broken.
ASSERT_EQ("", response_strings_[0]);
}
+
+TEST_F(EndToEndAsyncTest, TestSignal) {
+ const char kMessage[] = "hello, world";
+ // Send the test signal from the exported object.
+ test_service_->SendTestSignal(kMessage);
+ // Receive the signal with the object proxy. The signal is handeled in
+ // EndToEndAsyncTest::OnTestSignal() in the main thread.
+ WaitForTestSignal();
+ ASSERT_EQ(kMessage, test_signal_string_);
+}