OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROMEOS_DBUS_FLIMFLAM_CLIENT_UNITTEST_BASE_H_ | 5 #ifndef CHROMEOS_DBUS_FLIMFLAM_CLIENT_UNITTEST_BASE_H_ |
6 #define CHROMEOS_DBUS_FLIMFLAM_CLIENT_UNITTEST_BASE_H_ | 6 #define CHROMEOS_DBUS_FLIMFLAM_CLIENT_UNITTEST_BASE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "chromeos/dbus/dbus_method_call_status.h" | 13 #include "chromeos/dbus/dbus_method_call_status.h" |
| 14 #include "chromeos/dbus/flimflam_client_helper.h" |
14 #include "dbus/mock_bus.h" | 15 #include "dbus/mock_bus.h" |
15 #include "dbus/mock_object_proxy.h" | 16 #include "dbus/mock_object_proxy.h" |
16 #include "dbus/object_proxy.h" | 17 #include "dbus/object_proxy.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 | 21 |
21 class Value; | 22 class Value; |
22 class DictionaryValue; | 23 class DictionaryValue; |
23 | 24 |
24 } // namespace base | 25 } // namespace base |
25 | 26 |
26 namespace dbus { | 27 namespace dbus { |
27 | 28 |
28 class MessageReader; | 29 class MessageReader; |
29 | 30 |
30 } // namespace dbus | 31 } // namespace dbus |
31 | 32 |
32 namespace chromeos { | 33 namespace chromeos { |
33 | 34 |
34 // A class to provide functionalities needed for testing Flimflam D-Bus clients. | 35 // A class to provide functionalities needed for testing Flimflam D-Bus clients. |
35 class FlimflamClientUnittestBase : public testing::Test { | 36 class FlimflamClientUnittestBase : public testing::Test { |
36 public: | 37 public: |
| 38 // A mock Closure. |
| 39 class MockClosure { |
| 40 public: |
| 41 MockClosure(); |
| 42 ~MockClosure(); |
| 43 MOCK_METHOD0(Run, void()); |
| 44 base::Closure GetCallback(); |
| 45 }; |
| 46 |
| 47 // A mock ErrorCallback. |
| 48 class MockErrorCallback { |
| 49 public: |
| 50 MockErrorCallback(); |
| 51 ~MockErrorCallback(); |
| 52 MOCK_METHOD2(Run, void(const std::string& error_name, |
| 53 const std::string& error_mesage)); |
| 54 FlimflamClientHelper::ErrorCallback GetCallback(); |
| 55 }; |
| 56 |
37 explicit FlimflamClientUnittestBase(const std::string& interface_name, | 57 explicit FlimflamClientUnittestBase(const std::string& interface_name, |
38 const dbus::ObjectPath& object_path); | 58 const dbus::ObjectPath& object_path); |
39 virtual ~FlimflamClientUnittestBase(); | 59 virtual ~FlimflamClientUnittestBase(); |
40 | 60 |
41 virtual void SetUp() OVERRIDE; | 61 virtual void SetUp() OVERRIDE; |
42 virtual void TearDown() OVERRIDE; | 62 virtual void TearDown() OVERRIDE; |
43 | 63 |
44 protected: | 64 protected: |
45 // A callback to intercept and check the method call arguments. | 65 // A callback to intercept and check the method call arguments. |
46 typedef base::Callback<void( | 66 typedef base::Callback<void( |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 126 |
107 // Checks the content of the method call and returns the response. | 127 // Checks the content of the method call and returns the response. |
108 // Used to implement the mock proxy. | 128 // Used to implement the mock proxy. |
109 void OnCallMethod( | 129 void OnCallMethod( |
110 dbus::MethodCall* method_call, | 130 dbus::MethodCall* method_call, |
111 int timeout_ms, | 131 int timeout_ms, |
112 const dbus::ObjectProxy::ResponseCallback& response_callback); | 132 const dbus::ObjectProxy::ResponseCallback& response_callback); |
113 | 133 |
114 // Checks the content of the method call and returns the response. | 134 // Checks the content of the method call and returns the response. |
115 // Used to implement the mock proxy. | 135 // Used to implement the mock proxy. |
| 136 void OnCallMethodWithErrorCallback( |
| 137 dbus::MethodCall* method_call, |
| 138 int timeout_ms, |
| 139 const dbus::ObjectProxy::ResponseCallback& response_callback, |
| 140 const dbus::ObjectProxy::ErrorCallback& error_callback); |
| 141 |
| 142 // Checks the content of the method call and returns the response. |
| 143 // Used to implement the mock proxy. |
116 dbus::Response* OnCallMethodAndBlock(dbus::MethodCall* method_call, | 144 dbus::Response* OnCallMethodAndBlock(dbus::MethodCall* method_call, |
117 int timeout_ms); | 145 int timeout_ms); |
118 | 146 |
119 // The interface name. | 147 // The interface name. |
120 const std::string interface_name_; | 148 const std::string interface_name_; |
121 // The object path. | 149 // The object path. |
122 const dbus::ObjectPath object_path_; | 150 const dbus::ObjectPath object_path_; |
123 // The mock object proxy. | 151 // The mock object proxy. |
124 scoped_refptr<dbus::MockObjectProxy> mock_proxy_; | 152 scoped_refptr<dbus::MockObjectProxy> mock_proxy_; |
125 // The PropertyChanged signal handler given by the tested client. | 153 // The PropertyChanged signal handler given by the tested client. |
126 dbus::ObjectProxy::SignalCallback property_changed_handler_; | 154 dbus::ObjectProxy::SignalCallback property_changed_handler_; |
127 // The name of the method which is expected to be called. | 155 // The name of the method which is expected to be called. |
128 std::string expected_method_name_; | 156 std::string expected_method_name_; |
129 // The response which the mock object proxy returns. | 157 // The response which the mock object proxy returns. |
130 dbus::Response* response_; | 158 dbus::Response* response_; |
131 // A callback to intercept and check the method call arguments. | 159 // A callback to intercept and check the method call arguments. |
132 ArgumentCheckCallback argument_checker_; | 160 ArgumentCheckCallback argument_checker_; |
133 }; | 161 }; |
134 | 162 |
135 } // namespace chromeos | 163 } // namespace chromeos |
136 | 164 |
137 #endif // CHROMEOS_DBUS_FLIMFLAM_CLIENT_UNITTEST_BASE_H_ | 165 #endif // CHROMEOS_DBUS_FLIMFLAM_CLIENT_UNITTEST_BASE_H_ |
OLD | NEW |