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

Side by Side Diff: chromeos/dbus/shill_client_unittest_base.cc

Issue 10915106: Renaming instances of "flimflam" with "shill", now that we're only (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Upload after merge Created 8 years, 3 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
« no previous file with comments | « chromeos/dbus/shill_client_unittest_base.h ('k') | chromeos/dbus/shill_device_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chromeos/dbus/flimflam_client_unittest_base.h" 5 #include "chromeos/dbus/shill_client_unittest_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "dbus/message.h" 10 #include "dbus/message.h"
11 #include "dbus/object_path.h" 11 #include "dbus/object_path.h"
12 #include "dbus/values_util.h" 12 #include "dbus/values_util.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h" 15 #include "third_party/cros_system_api/dbus/service_constants.h"
16 16
17 using ::testing::_; 17 using ::testing::_;
18 using ::testing::Invoke; 18 using ::testing::Invoke;
19 using ::testing::Return; 19 using ::testing::Return;
20 20
21 namespace chromeos { 21 namespace chromeos {
22 22
23 namespace { 23 namespace {
24 24
25 // Runs the given task. This function is used to implement the mock bus. 25 // Runs the given task. This function is used to implement the mock bus.
26 void RunTask(const tracked_objects::Location& from_here, 26 void RunTask(const tracked_objects::Location& from_here,
27 const base::Closure& task) { 27 const base::Closure& task) {
28 task.Run(); 28 task.Run();
29 } 29 }
30 30
31 } // namespace 31 } // namespace
32 32
33 FlimflamClientUnittestBase::MockClosure::MockClosure() {} 33 ShillClientUnittestBase::MockClosure::MockClosure() {}
34 34
35 FlimflamClientUnittestBase::MockClosure::~MockClosure() {} 35 ShillClientUnittestBase::MockClosure::~MockClosure() {}
36 36
37 base::Closure FlimflamClientUnittestBase::MockClosure::GetCallback() { 37 base::Closure ShillClientUnittestBase::MockClosure::GetCallback() {
38 return base::Bind(&MockClosure::Run, base::Unretained(this)); 38 return base::Bind(&MockClosure::Run, base::Unretained(this));
39 } 39 }
40 40
41 41
42 FlimflamClientUnittestBase::MockErrorCallback::MockErrorCallback() {} 42 ShillClientUnittestBase::MockErrorCallback::MockErrorCallback() {}
43 43
44 FlimflamClientUnittestBase::MockErrorCallback::~MockErrorCallback() {} 44 ShillClientUnittestBase::MockErrorCallback::~MockErrorCallback() {}
45 45
46 FlimflamClientHelper::ErrorCallback 46 ShillClientHelper::ErrorCallback
47 FlimflamClientUnittestBase::MockErrorCallback::GetCallback() { 47 ShillClientUnittestBase::MockErrorCallback::GetCallback() {
48 return base::Bind(&MockErrorCallback::Run, base::Unretained(this)); 48 return base::Bind(&MockErrorCallback::Run, base::Unretained(this));
49 } 49 }
50 50
51 51
52 FlimflamClientUnittestBase::FlimflamClientUnittestBase( 52 ShillClientUnittestBase::ShillClientUnittestBase(
53 const std::string& interface_name, 53 const std::string& interface_name,
54 const dbus::ObjectPath& object_path) 54 const dbus::ObjectPath& object_path)
55 : interface_name_(interface_name), 55 : interface_name_(interface_name),
56 object_path_(object_path), 56 object_path_(object_path),
57 response_(NULL) { 57 response_(NULL) {
58 } 58 }
59 59
60 FlimflamClientUnittestBase::~FlimflamClientUnittestBase() { 60 ShillClientUnittestBase::~ShillClientUnittestBase() {
61 } 61 }
62 62
63 void FlimflamClientUnittestBase::SetUp() { 63 void ShillClientUnittestBase::SetUp() {
64 // Create a mock bus. 64 // Create a mock bus.
65 dbus::Bus::Options options; 65 dbus::Bus::Options options;
66 options.bus_type = dbus::Bus::SYSTEM; 66 options.bus_type = dbus::Bus::SYSTEM;
67 mock_bus_ = new dbus::MockBus(options); 67 mock_bus_ = new dbus::MockBus(options);
68 68
69 // Create a mock proxy. 69 // Create a mock proxy.
70 mock_proxy_ = new dbus::MockObjectProxy( 70 mock_proxy_ = new dbus::MockObjectProxy(
71 mock_bus_.get(), 71 mock_bus_.get(),
72 flimflam::kFlimflamServiceName, 72 flimflam::kFlimflamServiceName,
73 object_path_); 73 object_path_);
74 74
75 // Set an expectation so mock_proxy's CallMethodAndBlock() will use 75 // Set an expectation so mock_proxy's CallMethodAndBlock() will use
76 // OnCallMethodAndBlock() to return responses. 76 // OnCallMethodAndBlock() to return responses.
77 EXPECT_CALL(*mock_proxy_, CallMethodAndBlock(_, _)) 77 EXPECT_CALL(*mock_proxy_, CallMethodAndBlock(_, _))
78 .WillRepeatedly(Invoke( 78 .WillRepeatedly(Invoke(
79 this, &FlimflamClientUnittestBase::OnCallMethodAndBlock)); 79 this, &ShillClientUnittestBase::OnCallMethodAndBlock));
80 80
81 // Set an expectation so mock_proxy's CallMethod() will use OnCallMethod() 81 // Set an expectation so mock_proxy's CallMethod() will use OnCallMethod()
82 // to return responses. 82 // to return responses.
83 EXPECT_CALL(*mock_proxy_, CallMethod(_, _, _)) 83 EXPECT_CALL(*mock_proxy_, CallMethod(_, _, _))
84 .WillRepeatedly(Invoke(this, &FlimflamClientUnittestBase::OnCallMethod)); 84 .WillRepeatedly(Invoke(this, &ShillClientUnittestBase::OnCallMethod));
85 85
86 // Set an expectation so mock_proxy's CallMethodWithErrorCallback() will use 86 // Set an expectation so mock_proxy's CallMethodWithErrorCallback() will use
87 // OnCallMethodWithErrorCallback() to return responses. 87 // OnCallMethodWithErrorCallback() to return responses.
88 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _)) 88 EXPECT_CALL(*mock_proxy_, CallMethodWithErrorCallback(_, _, _, _))
89 .WillRepeatedly(Invoke( 89 .WillRepeatedly(Invoke(
90 this, &FlimflamClientUnittestBase::OnCallMethodWithErrorCallback)); 90 this, &ShillClientUnittestBase::OnCallMethodWithErrorCallback));
91 91
92 // Set an expectation so mock_proxy's ConnectToSignal() will use 92 // Set an expectation so mock_proxy's ConnectToSignal() will use
93 // OnConnectToSignal() to run the callback. 93 // OnConnectToSignal() to run the callback.
94 EXPECT_CALL(*mock_proxy_, ConnectToSignal( 94 EXPECT_CALL(*mock_proxy_, ConnectToSignal(
95 interface_name_, 95 interface_name_,
96 flimflam::kMonitorPropertyChanged, _, _)) 96 flimflam::kMonitorPropertyChanged, _, _))
97 .WillRepeatedly(Invoke(this, 97 .WillRepeatedly(Invoke(this,
98 &FlimflamClientUnittestBase::OnConnectToSignal)); 98 &ShillClientUnittestBase::OnConnectToSignal));
99 99
100 // Set an expectation so mock_bus's GetObjectProxy() for the given 100 // Set an expectation so mock_bus's GetObjectProxy() for the given
101 // service name and the object path will return mock_proxy_. 101 // service name and the object path will return mock_proxy_.
102 EXPECT_CALL(*mock_bus_, GetObjectProxy(flimflam::kFlimflamServiceName, 102 EXPECT_CALL(*mock_bus_, GetObjectProxy(flimflam::kFlimflamServiceName,
103 object_path_)) 103 object_path_))
104 .WillOnce(Return(mock_proxy_.get())); 104 .WillOnce(Return(mock_proxy_.get()));
105 105
106 // Set an expectation so mock_bus's PostTaskToDBusThread() will run the 106 // Set an expectation so mock_bus's PostTaskToDBusThread() will run the
107 // given task. 107 // given task.
108 EXPECT_CALL(*mock_bus_, PostTaskToDBusThread(_, _)) 108 EXPECT_CALL(*mock_bus_, PostTaskToDBusThread(_, _))
109 .WillRepeatedly(Invoke(&RunTask)); 109 .WillRepeatedly(Invoke(&RunTask));
110 110
111 // ShutdownAndBlock() will be called in TearDown(). 111 // ShutdownAndBlock() will be called in TearDown().
112 EXPECT_CALL(*mock_bus_, ShutdownAndBlock()).WillOnce(Return()); 112 EXPECT_CALL(*mock_bus_, ShutdownAndBlock()).WillOnce(Return());
113 } 113 }
114 114
115 void FlimflamClientUnittestBase::TearDown() { 115 void ShillClientUnittestBase::TearDown() {
116 mock_bus_->ShutdownAndBlock(); 116 mock_bus_->ShutdownAndBlock();
117 } 117 }
118 118
119 void FlimflamClientUnittestBase::PrepareForMethodCall( 119 void ShillClientUnittestBase::PrepareForMethodCall(
120 const std::string& method_name, 120 const std::string& method_name,
121 const ArgumentCheckCallback& argument_checker, 121 const ArgumentCheckCallback& argument_checker,
122 dbus::Response* response) { 122 dbus::Response* response) {
123 expected_method_name_ = method_name; 123 expected_method_name_ = method_name;
124 argument_checker_ = argument_checker; 124 argument_checker_ = argument_checker;
125 response_ = response; 125 response_ = response;
126 } 126 }
127 127
128 void FlimflamClientUnittestBase::SendPropertyChangedSignal( 128 void ShillClientUnittestBase::SendPropertyChangedSignal(
129 dbus::Signal* signal) { 129 dbus::Signal* signal) {
130 ASSERT_FALSE(property_changed_handler_.is_null()); 130 ASSERT_FALSE(property_changed_handler_.is_null());
131 property_changed_handler_.Run(signal); 131 property_changed_handler_.Run(signal);
132 } 132 }
133 133
134 // static 134 // static
135 void FlimflamClientUnittestBase::ExpectPropertyChanged( 135 void ShillClientUnittestBase::ExpectPropertyChanged(
136 const std::string& expected_name, 136 const std::string& expected_name,
137 const base::Value* expected_value, 137 const base::Value* expected_value,
138 const std::string& name, 138 const std::string& name,
139 const base::Value& value) { 139 const base::Value& value) {
140 EXPECT_EQ(expected_name, name); 140 EXPECT_EQ(expected_name, name);
141 EXPECT_TRUE(expected_value->Equals(&value)); 141 EXPECT_TRUE(expected_value->Equals(&value));
142 } 142 }
143 143
144 // static 144 // static
145 void FlimflamClientUnittestBase::ExpectNoArgument(dbus::MessageReader* reader) { 145 void ShillClientUnittestBase::ExpectNoArgument(dbus::MessageReader* reader) {
146 EXPECT_FALSE(reader->HasMoreData()); 146 EXPECT_FALSE(reader->HasMoreData());
147 } 147 }
148 148
149 // static 149 // static
150 void FlimflamClientUnittestBase::ExpectStringArgument( 150 void ShillClientUnittestBase::ExpectStringArgument(
151 const std::string& expected_string, 151 const std::string& expected_string,
152 dbus::MessageReader* reader) { 152 dbus::MessageReader* reader) {
153 std::string str; 153 std::string str;
154 ASSERT_TRUE(reader->PopString(&str)); 154 ASSERT_TRUE(reader->PopString(&str));
155 EXPECT_EQ(expected_string, str); 155 EXPECT_EQ(expected_string, str);
156 EXPECT_FALSE(reader->HasMoreData()); 156 EXPECT_FALSE(reader->HasMoreData());
157 } 157 }
158 158
159 // static 159 // static
160 void FlimflamClientUnittestBase::ExpectValueArgument( 160 void ShillClientUnittestBase::ExpectValueArgument(
161 const base::Value* expected_value, 161 const base::Value* expected_value,
162 dbus::MessageReader* reader) { 162 dbus::MessageReader* reader) {
163 scoped_ptr<base::Value> value(dbus::PopDataAsValue(reader)); 163 scoped_ptr<base::Value> value(dbus::PopDataAsValue(reader));
164 ASSERT_TRUE(value.get()); 164 ASSERT_TRUE(value.get());
165 EXPECT_TRUE(value->Equals(expected_value)); 165 EXPECT_TRUE(value->Equals(expected_value));
166 EXPECT_FALSE(reader->HasMoreData()); 166 EXPECT_FALSE(reader->HasMoreData());
167 } 167 }
168 168
169 // static 169 // static
170 void FlimflamClientUnittestBase::ExpectStringAndValueArguments( 170 void ShillClientUnittestBase::ExpectStringAndValueArguments(
171 const std::string& expected_string, 171 const std::string& expected_string,
172 const base::Value* expected_value, 172 const base::Value* expected_value,
173 dbus::MessageReader* reader) { 173 dbus::MessageReader* reader) {
174 std::string str; 174 std::string str;
175 ASSERT_TRUE(reader->PopString(&str)); 175 ASSERT_TRUE(reader->PopString(&str));
176 EXPECT_EQ(expected_string, str); 176 EXPECT_EQ(expected_string, str);
177 scoped_ptr<base::Value> value(dbus::PopDataAsValue(reader)); 177 scoped_ptr<base::Value> value(dbus::PopDataAsValue(reader));
178 ASSERT_TRUE(value.get()); 178 ASSERT_TRUE(value.get());
179 EXPECT_TRUE(value->Equals(expected_value)); 179 EXPECT_TRUE(value->Equals(expected_value));
180 EXPECT_FALSE(reader->HasMoreData()); 180 EXPECT_FALSE(reader->HasMoreData());
181 } 181 }
182 182
183 // static 183 // static
184 void FlimflamClientUnittestBase::ExpectNoResultValue( 184 void ShillClientUnittestBase::ExpectNoResultValue(
185 DBusMethodCallStatus call_status) { 185 DBusMethodCallStatus call_status) {
186 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status); 186 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status);
187 } 187 }
188 188
189 // static 189 // static
190 void FlimflamClientUnittestBase::ExpectObjectPathResult( 190 void ShillClientUnittestBase::ExpectObjectPathResult(
191 const dbus::ObjectPath& expected_result, 191 const dbus::ObjectPath& expected_result,
192 DBusMethodCallStatus call_status, 192 DBusMethodCallStatus call_status,
193 const dbus::ObjectPath& result) { 193 const dbus::ObjectPath& result) {
194 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status); 194 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status);
195 EXPECT_EQ(expected_result, result); 195 EXPECT_EQ(expected_result, result);
196 } 196 }
197 197
198 // static 198 // static
199 void FlimflamClientUnittestBase::ExpectDictionaryValueResult( 199 void ShillClientUnittestBase::ExpectDictionaryValueResult(
200 const base::DictionaryValue* expected_result, 200 const base::DictionaryValue* expected_result,
201 DBusMethodCallStatus call_status, 201 DBusMethodCallStatus call_status,
202 const base::DictionaryValue& result) { 202 const base::DictionaryValue& result) {
203 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status); 203 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status);
204 std::string expected_result_string; 204 std::string expected_result_string;
205 base::JSONWriter::Write(expected_result, &expected_result_string); 205 base::JSONWriter::Write(expected_result, &expected_result_string);
206 std::string result_string; 206 std::string result_string;
207 base::JSONWriter::Write(&result, &result_string); 207 base::JSONWriter::Write(&result, &result_string);
208 EXPECT_EQ(expected_result_string, result_string); 208 EXPECT_EQ(expected_result_string, result_string);
209 } 209 }
210 210
211 void FlimflamClientUnittestBase::OnConnectToSignal( 211 void ShillClientUnittestBase::OnConnectToSignal(
212 const std::string& interface_name, 212 const std::string& interface_name,
213 const std::string& signal_name, 213 const std::string& signal_name,
214 const dbus::ObjectProxy::SignalCallback& signal_callback, 214 const dbus::ObjectProxy::SignalCallback& signal_callback,
215 const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback) { 215 const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback) {
216 property_changed_handler_ = signal_callback; 216 property_changed_handler_ = signal_callback;
217 const bool success = true; 217 const bool success = true;
218 message_loop_.PostTask(FROM_HERE, 218 message_loop_.PostTask(FROM_HERE,
219 base::Bind(on_connected_callback, 219 base::Bind(on_connected_callback,
220 interface_name, 220 interface_name,
221 signal_name, 221 signal_name,
222 success)); 222 success));
223 } 223 }
224 224
225 void FlimflamClientUnittestBase::OnCallMethod( 225 void ShillClientUnittestBase::OnCallMethod(
226 dbus::MethodCall* method_call, 226 dbus::MethodCall* method_call,
227 int timeout_ms, 227 int timeout_ms,
228 const dbus::ObjectProxy::ResponseCallback& response_callback) { 228 const dbus::ObjectProxy::ResponseCallback& response_callback) {
229 EXPECT_EQ(interface_name_, method_call->GetInterface()); 229 EXPECT_EQ(interface_name_, method_call->GetInterface());
230 EXPECT_EQ(expected_method_name_, method_call->GetMember()); 230 EXPECT_EQ(expected_method_name_, method_call->GetMember());
231 dbus::MessageReader reader(method_call); 231 dbus::MessageReader reader(method_call);
232 argument_checker_.Run(&reader); 232 argument_checker_.Run(&reader);
233 message_loop_.PostTask(FROM_HERE, 233 message_loop_.PostTask(FROM_HERE,
234 base::Bind(response_callback, response_)); 234 base::Bind(response_callback, response_));
235 } 235 }
236 236
237 void FlimflamClientUnittestBase::OnCallMethodWithErrorCallback( 237 void ShillClientUnittestBase::OnCallMethodWithErrorCallback(
238 dbus::MethodCall* method_call, 238 dbus::MethodCall* method_call,
239 int timeout_ms, 239 int timeout_ms,
240 const dbus::ObjectProxy::ResponseCallback& response_callback, 240 const dbus::ObjectProxy::ResponseCallback& response_callback,
241 const dbus::ObjectProxy::ErrorCallback& error_callback) { 241 const dbus::ObjectProxy::ErrorCallback& error_callback) {
242 OnCallMethod(method_call, timeout_ms, response_callback); 242 OnCallMethod(method_call, timeout_ms, response_callback);
243 } 243 }
244 244
245 dbus::Response* FlimflamClientUnittestBase::OnCallMethodAndBlock( 245 dbus::Response* ShillClientUnittestBase::OnCallMethodAndBlock(
246 dbus::MethodCall* method_call, 246 dbus::MethodCall* method_call,
247 int timeout_ms) { 247 int timeout_ms) {
248 EXPECT_EQ(interface_name_, method_call->GetInterface()); 248 EXPECT_EQ(interface_name_, method_call->GetInterface());
249 EXPECT_EQ(expected_method_name_, method_call->GetMember()); 249 EXPECT_EQ(expected_method_name_, method_call->GetMember());
250 dbus::MessageReader reader(method_call); 250 dbus::MessageReader reader(method_call);
251 argument_checker_.Run(&reader); 251 argument_checker_.Run(&reader);
252 return dbus::Response::FromRawMessage( 252 return dbus::Response::FromRawMessage(
253 dbus_message_copy(response_->raw_message())); 253 dbus_message_copy(response_->raw_message()));
254 } 254 }
255 255
256 } // namespace chromeos 256 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/shill_client_unittest_base.h ('k') | chromeos/dbus/shill_device_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698