OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
15 #include "dbus/bus.h" | 15 #include "dbus/bus.h" |
16 #include "dbus/message.h" | 16 #include "dbus/message.h" |
17 #include "dbus/object_proxy.h" | 17 #include "dbus/object_proxy.h" |
18 #include "dbus/test_service.h" | 18 #include "dbus/test_service.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 // The end-to-end test exercises the asynchronos APIs in ObjectProxy and | 21 // The end-to-end test exercises the asynchronos APIs in ObjectProxy and |
22 // ExportedObject. | 22 // ExportedObject. |
23 class EndToEndAsyncTest : public testing::Test { | 23 class EndToEndAsyncTest : public testing::Test { |
24 public: | 24 public: |
25 EndToEndAsyncTest() { | 25 EndToEndAsyncTest() { |
26 } | 26 } |
27 | 27 |
28 void SetUp() { | 28 virtual void SetUp() { |
29 // Make the main thread not to allow IO. | 29 // Make the main thread not to allow IO. |
30 base::ThreadRestrictions::SetIOAllowed(false); | 30 base::ThreadRestrictions::SetIOAllowed(false); |
31 | 31 |
32 // Start the D-Bus thread. | 32 // Start the D-Bus thread. |
33 dbus_thread_.reset(new base::Thread("D-Bus Thread")); | 33 dbus_thread_.reset(new base::Thread("D-Bus Thread")); |
34 base::Thread::Options thread_options; | 34 base::Thread::Options thread_options; |
35 thread_options.message_loop_type = MessageLoop::TYPE_IO; | 35 thread_options.message_loop_type = MessageLoop::TYPE_IO; |
36 ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options)); | 36 ASSERT_TRUE(dbus_thread_->StartWithOptions(thread_options)); |
37 | 37 |
38 // Start the test service, using the D-Bus thread. | 38 // Start the test service, using the D-Bus thread. |
(...skipping 19 matching lines...) Expand all Loading... |
58 "org.chromium.TestInterface", | 58 "org.chromium.TestInterface", |
59 "Test", | 59 "Test", |
60 base::Bind(&EndToEndAsyncTest::OnTestSignal, | 60 base::Bind(&EndToEndAsyncTest::OnTestSignal, |
61 base::Unretained(this)), | 61 base::Unretained(this)), |
62 base::Bind(&EndToEndAsyncTest::OnConnected, | 62 base::Bind(&EndToEndAsyncTest::OnConnected, |
63 base::Unretained(this))); | 63 base::Unretained(this))); |
64 // Wait until the object proxy is connected to the signal. | 64 // Wait until the object proxy is connected to the signal. |
65 message_loop_.Run(); | 65 message_loop_.Run(); |
66 } | 66 } |
67 | 67 |
68 void TearDown() { | 68 virtual void TearDown() { |
69 bus_->Shutdown(base::Bind(&EndToEndAsyncTest::OnShutdown, | 69 bus_->Shutdown(base::Bind(&EndToEndAsyncTest::OnShutdown, |
70 base::Unretained(this))); | 70 base::Unretained(this))); |
71 // Wait until the bus is shutdown. OnShutdown() will be called in | 71 // Wait until the bus is shutdown. OnShutdown() will be called in |
72 // mesage_loop_. | 72 // mesage_loop_. |
73 message_loop_.Run(); | 73 message_loop_.Run(); |
74 | 74 |
75 // Shut down the service. | 75 // Shut down the service. |
76 test_service_->Shutdown(); | 76 test_service_->Shutdown(); |
77 ASSERT_TRUE(test_service_->WaitUntilServiceIsShutdown()); | 77 ASSERT_TRUE(test_service_->WaitUntilServiceIsShutdown()); |
78 | 78 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 236 |
237 TEST_F(EndToEndAsyncTest, TestSignal) { | 237 TEST_F(EndToEndAsyncTest, TestSignal) { |
238 const char kMessage[] = "hello, world"; | 238 const char kMessage[] = "hello, world"; |
239 // Send the test signal from the exported object. | 239 // Send the test signal from the exported object. |
240 test_service_->SendTestSignal(kMessage); | 240 test_service_->SendTestSignal(kMessage); |
241 // Receive the signal with the object proxy. The signal is handeled in | 241 // Receive the signal with the object proxy. The signal is handeled in |
242 // EndToEndAsyncTest::OnTestSignal() in the main thread. | 242 // EndToEndAsyncTest::OnTestSignal() in the main thread. |
243 WaitForTestSignal(); | 243 WaitForTestSignal(); |
244 ASSERT_EQ(kMessage, test_signal_string_); | 244 ASSERT_EQ(kMessage, test_signal_string_); |
245 } | 245 } |
OLD | NEW |