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

Side by Side Diff: dbus/end_to_end_sync_unittest.cc

Issue 7491029: Implement Bus and ObjectProxy classes for our D-Bus library. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: another clang challenge Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dbus/end_to_end_async_unittest.cc ('k') | dbus/exported_object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/memory/ref_counted.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "dbus/bus.h"
8 #include "dbus/message.h"
9 #include "dbus/object_proxy.h"
10 #include "dbus/test_service.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 // The end-to-end test exercises the synchronos APIs in ObjectProxy and
14 // ExportedObject. The test will launch a thread for the service side
15 // operations (i.e. ExportedObject side).
16 class EndToEndSyncTest : public testing::Test {
17 public:
18 EndToEndSyncTest() {
19 }
20
21 void SetUp() {
22 // Start the test service;
23 test_service_.reset(new dbus::TestService);
24 test_service_->StartService();
25 test_service_->WaitUntilServiceIsStarted();
26
27 // Create the client.
28 dbus::Bus::Options client_bus_options;
29 client_bus_options.bus_type = dbus::Bus::SESSION;
30 client_bus_options.connection_type = dbus::Bus::PRIVATE;
31 client_bus_ = new dbus::Bus(client_bus_options);
32 object_proxy_ = client_bus_->GetObjectProxy("org.chromium.TestService",
33 "/org/chromium/TestObject");
34 }
35
36 void TearDown() {
37 test_service_->Stop();
38 client_bus_->ShutdownAndBlock();
39 }
40
41 protected:
42 scoped_ptr<dbus::TestService> test_service_;
43 scoped_refptr<dbus::Bus> client_bus_;
44 dbus::ObjectProxy* object_proxy_;
45 };
46
47 TEST_F(EndToEndSyncTest, Echo) {
48 const std::string kHello = "hello";
49
50 // Create the method call.
51 dbus::MethodCall method_call("org.chromium.TestInterface", "Echo");
52 dbus::MessageWriter writer(&method_call);
53 writer.AppendString(kHello);
54
55 // Call the method.
56 dbus::Response response;
57 const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
58 const bool success =
59 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms, &response);
60 ASSERT_TRUE(success);
61
62 // Check the response. kHello should be echoed back.
63 dbus::MessageReader reader(&response);
64 std::string returned_message;
65 ASSERT_TRUE(reader.PopString(&returned_message));
66 EXPECT_EQ(kHello, returned_message);
67 }
68
69 TEST_F(EndToEndSyncTest, Timeout) {
70 const std::string kHello = "hello";
71
72 // Create the method call.
73 dbus::MethodCall method_call("org.chromium.TestInterface", "DelayedEcho");
74 dbus::MessageWriter writer(&method_call);
75 writer.AppendString(kHello);
76
77 // Call the method with timeout smaller than TestService::kSlowEchoSleepMs.
78 dbus::Response response;
79 const int timeout_ms = dbus::TestService::kSlowEchoSleepMs / 10;
80 const bool success =
81 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms, &response);
82 // Should fail because of timeout.
83 ASSERT_FALSE(success);
84 }
85
86 TEST_F(EndToEndSyncTest, NonexistentMethod) {
87 dbus::MethodCall method_call("org.chromium.TestInterface", "Nonexistent");
88
89 dbus::Response response;
90 const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
91 const bool success =
92 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms, &response);
93 ASSERT_FALSE(success);
94 }
95
96 TEST_F(EndToEndSyncTest, BrokenMethod) {
97 dbus::MethodCall method_call("org.chromium.TestInterface", "BrokenMethod");
98
99 dbus::Response response;
100 const int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT;
101 const bool success =
102 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms, &response);
103 ASSERT_FALSE(success);
104 }
OLDNEW
« no previous file with comments | « dbus/end_to_end_async_unittest.cc ('k') | dbus/exported_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698