| 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 #include "chromeos/dbus/shill_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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 base::Closure ShillClientUnittestBase::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 ShillClientUnittestBase::MockErrorCallback::MockErrorCallback() {} | 42 ShillClientUnittestBase::MockErrorCallback::MockErrorCallback() {} |
| 43 | 43 |
| 44 ShillClientUnittestBase::MockErrorCallback::~MockErrorCallback() {} | 44 ShillClientUnittestBase::MockErrorCallback::~MockErrorCallback() {} |
| 45 | 45 |
| 46 ShillClientUnittestBase::MockPropertyChangeObserver:: |
| 47 MockPropertyChangeObserver() {} |
| 48 |
| 49 ShillClientUnittestBase::MockPropertyChangeObserver:: |
| 50 ~MockPropertyChangeObserver() {} |
| 51 |
| 46 ShillClientHelper::ErrorCallback | 52 ShillClientHelper::ErrorCallback |
| 47 ShillClientUnittestBase::MockErrorCallback::GetCallback() { | 53 ShillClientUnittestBase::MockErrorCallback::GetCallback() { |
| 48 return base::Bind(&MockErrorCallback::Run, base::Unretained(this)); | 54 return base::Bind(&MockErrorCallback::Run, base::Unretained(this)); |
| 49 } | 55 } |
| 50 | 56 |
| 51 | 57 |
| 52 ShillClientUnittestBase::ShillClientUnittestBase( | 58 ShillClientUnittestBase::ShillClientUnittestBase( |
| 53 const std::string& interface_name, | 59 const std::string& interface_name, |
| 54 const dbus::ObjectPath& object_path) | 60 const dbus::ObjectPath& object_path) |
| 55 : interface_name_(interface_name), | 61 : interface_name_(interface_name), |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 response_ = response; | 131 response_ = response; |
| 126 } | 132 } |
| 127 | 133 |
| 128 void ShillClientUnittestBase::SendPropertyChangedSignal( | 134 void ShillClientUnittestBase::SendPropertyChangedSignal( |
| 129 dbus::Signal* signal) { | 135 dbus::Signal* signal) { |
| 130 ASSERT_FALSE(property_changed_handler_.is_null()); | 136 ASSERT_FALSE(property_changed_handler_.is_null()); |
| 131 property_changed_handler_.Run(signal); | 137 property_changed_handler_.Run(signal); |
| 132 } | 138 } |
| 133 | 139 |
| 134 // static | 140 // static |
| 135 void ShillClientUnittestBase::ExpectPropertyChanged( | |
| 136 const std::string& expected_name, | |
| 137 const base::Value* expected_value, | |
| 138 const std::string& name, | |
| 139 const base::Value& value) { | |
| 140 EXPECT_EQ(expected_name, name); | |
| 141 EXPECT_TRUE(expected_value->Equals(&value)); | |
| 142 } | |
| 143 | |
| 144 // static | |
| 145 void ShillClientUnittestBase::ExpectNoArgument(dbus::MessageReader* reader) { | 141 void ShillClientUnittestBase::ExpectNoArgument(dbus::MessageReader* reader) { |
| 146 EXPECT_FALSE(reader->HasMoreData()); | 142 EXPECT_FALSE(reader->HasMoreData()); |
| 147 } | 143 } |
| 148 | 144 |
| 149 // static | 145 // static |
| 150 void ShillClientUnittestBase::ExpectStringArgument( | 146 void ShillClientUnittestBase::ExpectStringArgument( |
| 151 const std::string& expected_string, | 147 const std::string& expected_string, |
| 152 dbus::MessageReader* reader) { | 148 dbus::MessageReader* reader) { |
| 153 std::string str; | 149 std::string str; |
| 154 ASSERT_TRUE(reader->PopString(&str)); | 150 ASSERT_TRUE(reader->PopString(&str)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 // static | 185 // static |
| 190 void ShillClientUnittestBase::ExpectObjectPathResult( | 186 void ShillClientUnittestBase::ExpectObjectPathResult( |
| 191 const dbus::ObjectPath& expected_result, | 187 const dbus::ObjectPath& expected_result, |
| 192 DBusMethodCallStatus call_status, | 188 DBusMethodCallStatus call_status, |
| 193 const dbus::ObjectPath& result) { | 189 const dbus::ObjectPath& result) { |
| 194 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status); | 190 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status); |
| 195 EXPECT_EQ(expected_result, result); | 191 EXPECT_EQ(expected_result, result); |
| 196 } | 192 } |
| 197 | 193 |
| 198 // static | 194 // static |
| 199 void ShillClientUnittestBase::ExpectDictionaryValueResult( | 195 void ShillClientUnittestBase::ExpectDictionaryValueResultWithoutStatus( |
| 200 const base::DictionaryValue* expected_result, | 196 const base::DictionaryValue* expected_result, |
| 201 DBusMethodCallStatus call_status, | |
| 202 const base::DictionaryValue& result) { | 197 const base::DictionaryValue& result) { |
| 203 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status); | |
| 204 std::string expected_result_string; | 198 std::string expected_result_string; |
| 205 base::JSONWriter::Write(expected_result, &expected_result_string); | 199 base::JSONWriter::Write(expected_result, &expected_result_string); |
| 206 std::string result_string; | 200 std::string result_string; |
| 207 base::JSONWriter::Write(&result, &result_string); | 201 base::JSONWriter::Write(&result, &result_string); |
| 208 EXPECT_EQ(expected_result_string, result_string); | 202 EXPECT_EQ(expected_result_string, result_string); |
| 209 } | 203 } |
| 210 | 204 |
| 205 // static |
| 206 void ShillClientUnittestBase::ExpectDictionaryValueResult( |
| 207 const base::DictionaryValue* expected_result, |
| 208 DBusMethodCallStatus call_status, |
| 209 const base::DictionaryValue& result) { |
| 210 EXPECT_EQ(DBUS_METHOD_CALL_SUCCESS, call_status); |
| 211 ExpectDictionaryValueResultWithoutStatus(expected_result, result); |
| 212 } |
| 213 |
| 211 void ShillClientUnittestBase::OnConnectToSignal( | 214 void ShillClientUnittestBase::OnConnectToSignal( |
| 212 const std::string& interface_name, | 215 const std::string& interface_name, |
| 213 const std::string& signal_name, | 216 const std::string& signal_name, |
| 214 const dbus::ObjectProxy::SignalCallback& signal_callback, | 217 const dbus::ObjectProxy::SignalCallback& signal_callback, |
| 215 const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback) { | 218 const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback) { |
| 216 property_changed_handler_ = signal_callback; | 219 property_changed_handler_ = signal_callback; |
| 217 const bool success = true; | 220 const bool success = true; |
| 218 message_loop_.PostTask(FROM_HERE, | 221 message_loop_.PostTask(FROM_HERE, |
| 219 base::Bind(on_connected_callback, | 222 base::Bind(on_connected_callback, |
| 220 interface_name, | 223 interface_name, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 247 int timeout_ms) { | 250 int timeout_ms) { |
| 248 EXPECT_EQ(interface_name_, method_call->GetInterface()); | 251 EXPECT_EQ(interface_name_, method_call->GetInterface()); |
| 249 EXPECT_EQ(expected_method_name_, method_call->GetMember()); | 252 EXPECT_EQ(expected_method_name_, method_call->GetMember()); |
| 250 dbus::MessageReader reader(method_call); | 253 dbus::MessageReader reader(method_call); |
| 251 argument_checker_.Run(&reader); | 254 argument_checker_.Run(&reader); |
| 252 return dbus::Response::FromRawMessage( | 255 return dbus::Response::FromRawMessage( |
| 253 dbus_message_copy(response_->raw_message())); | 256 dbus_message_copy(response_->raw_message())); |
| 254 } | 257 } |
| 255 | 258 |
| 256 } // namespace chromeos | 259 } // namespace chromeos |
| OLD | NEW |