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

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

Issue 16998003: Update CrOS to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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
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/modem_messaging_client.h" 5 #include "chromeos/dbus/modem_messaging_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "dbus/message.h" 10 #include "dbus/message.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 options.bus_type = dbus::Bus::SYSTEM; 68 options.bus_type = dbus::Bus::SYSTEM;
69 mock_bus_ = new dbus::MockBus(options); 69 mock_bus_ = new dbus::MockBus(options);
70 70
71 // Create a mock proxy. 71 // Create a mock proxy.
72 mock_proxy_ = new dbus::MockObjectProxy(mock_bus_.get(), 72 mock_proxy_ = new dbus::MockObjectProxy(mock_bus_.get(),
73 kServiceName, 73 kServiceName,
74 dbus::ObjectPath(kObjectPath)); 74 dbus::ObjectPath(kObjectPath));
75 75
76 // Set an expectation so mock_proxy's ConnectToSignal() will use 76 // Set an expectation so mock_proxy's ConnectToSignal() will use
77 // OnConnectToSignal() to run the callback. 77 // OnConnectToSignal() to run the callback.
78 EXPECT_CALL(*mock_proxy_, ConnectToSignal( 78 EXPECT_CALL(*mock_proxy_.get(),
79 modemmanager::kModemManager1MessagingInterface, 79 ConnectToSignal(modemmanager::kModemManager1MessagingInterface,
80 modemmanager::kSMSAddedSignal, _, _)) 80 modemmanager::kSMSAddedSignal,
81 _,
82 _))
81 .WillRepeatedly( 83 .WillRepeatedly(
82 Invoke(this, &ModemMessagingClientTest::OnConnectToSignal)); 84 Invoke(this, &ModemMessagingClientTest::OnConnectToSignal));
83 85
84 // Set an expectation so mock_bus's GetObjectProxy() for the given 86 // Set an expectation so mock_bus's GetObjectProxy() for the given
85 // service name and the object path will return mock_proxy_. 87 // service name and the object path will return mock_proxy_.
86 EXPECT_CALL(*mock_bus_, GetObjectProxy(kServiceName, 88 EXPECT_CALL(*mock_bus_.get(),
87 dbus::ObjectPath(kObjectPath))) 89 GetObjectProxy(kServiceName, dbus::ObjectPath(kObjectPath)))
88 .WillOnce(Return(mock_proxy_.get())); 90 .WillOnce(Return(mock_proxy_.get()));
89 91
90 // ShutdownAndBlock() will be called in TearDown(). 92 // ShutdownAndBlock() will be called in TearDown().
91 EXPECT_CALL(*mock_bus_, ShutdownAndBlock()).WillOnce(Return()); 93 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return());
92 94
93 // Create a client with the mock bus. 95 // Create a client with the mock bus.
94 client_.reset(ModemMessagingClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, 96 client_.reset(ModemMessagingClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION,
95 mock_bus_)); 97 mock_bus_.get()));
96 } 98 }
97 99
98 virtual void TearDown() OVERRIDE { 100 virtual void TearDown() OVERRIDE {
99 mock_bus_->ShutdownAndBlock(); 101 mock_bus_->ShutdownAndBlock();
100 } 102 }
101 103
102 // Handles Delete method call. 104 // Handles Delete method call.
103 void OnDelete(dbus::MethodCall* method_call, 105 void OnDelete(dbus::MethodCall* method_call,
104 int timeout_ms, 106 int timeout_ms,
105 const dbus::ObjectProxy::ResponseCallback& callback) { 107 const dbus::ObjectProxy::ResponseCallback& callback) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // Reset handler. 194 // Reset handler.
193 client_->ResetSmsReceivedHandler(kServiceName, dbus::ObjectPath(kObjectPath)); 195 client_->ResetSmsReceivedHandler(kServiceName, dbus::ObjectPath(kObjectPath));
194 // Send signal again. 196 // Send signal again.
195 sms_received_callback_.Run(&signal); 197 sms_received_callback_.Run(&signal);
196 } 198 }
197 199
198 TEST_F(ModemMessagingClientTest, Delete) { 200 TEST_F(ModemMessagingClientTest, Delete) {
199 // Set expectations. 201 // Set expectations.
200 const dbus::ObjectPath kSmsPath("/SMS/0"); 202 const dbus::ObjectPath kSmsPath("/SMS/0");
201 expected_sms_path_ = kSmsPath; 203 expected_sms_path_ = kSmsPath;
202 EXPECT_CALL(*mock_proxy_, CallMethod(_, _, _)) 204 EXPECT_CALL(*mock_proxy_.get(), CallMethod(_, _, _))
203 .WillOnce(Invoke(this, &ModemMessagingClientTest::OnDelete)); 205 .WillOnce(Invoke(this, &ModemMessagingClientTest::OnDelete));
204 MockDeleteCallback callback; 206 MockDeleteCallback callback;
205 EXPECT_CALL(callback, Run()).Times(1); 207 EXPECT_CALL(callback, Run()).Times(1);
206 // Create response. 208 // Create response.
207 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 209 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
208 response_ = response.get(); 210 response_ = response.get();
209 // Call Delete. 211 // Call Delete.
210 client_->Delete(kServiceName, dbus::ObjectPath(kObjectPath), kSmsPath, 212 client_->Delete(kServiceName, dbus::ObjectPath(kObjectPath), kSmsPath,
211 base::Bind(&MockDeleteCallback::Run, 213 base::Bind(&MockDeleteCallback::Run,
212 base::Unretained(&callback))); 214 base::Unretained(&callback)));
213 215
214 // Run the message loop. 216 // Run the message loop.
215 message_loop_.RunUntilIdle(); 217 message_loop_.RunUntilIdle();
216 } 218 }
217 219
218 TEST_F(ModemMessagingClientTest, List) { 220 TEST_F(ModemMessagingClientTest, List) {
219 // Set expectations. 221 // Set expectations.
220 EXPECT_CALL(*mock_proxy_, CallMethod(_, _, _)) 222 EXPECT_CALL(*mock_proxy_.get(), CallMethod(_, _, _))
221 .WillOnce(Invoke(this, &ModemMessagingClientTest::OnList)); 223 .WillOnce(Invoke(this, &ModemMessagingClientTest::OnList));
222 MockListCallback callback; 224 MockListCallback callback;
223 EXPECT_CALL(callback, Run(_)) 225 EXPECT_CALL(callback, Run(_))
224 .WillOnce(Invoke(this, &ModemMessagingClientTest::CheckResult)); 226 .WillOnce(Invoke(this, &ModemMessagingClientTest::CheckResult));
225 // Create response. 227 // Create response.
226 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 228 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
227 dbus::ObjectPath path1("/SMS/1"); 229 dbus::ObjectPath path1("/SMS/1");
228 dbus::ObjectPath path2("/SMS/2"); 230 dbus::ObjectPath path2("/SMS/2");
229 std::vector<dbus::ObjectPath> expected_result; 231 std::vector<dbus::ObjectPath> expected_result;
230 expected_result.push_back(path1); 232 expected_result.push_back(path1);
231 expected_result.push_back(path2); 233 expected_result.push_back(path2);
232 234
233 dbus::MessageWriter writer(response.get()); 235 dbus::MessageWriter writer(response.get());
234 writer.AppendArrayOfObjectPaths(expected_result); 236 writer.AppendArrayOfObjectPaths(expected_result);
235 response_ = response.get(); 237 response_ = response.get();
236 238
237 // Save expected result. 239 // Save expected result.
238 expected_result_ = &expected_result; 240 expected_result_ = &expected_result;
239 // Call List. 241 // Call List.
240 client_->List(kServiceName, dbus::ObjectPath(kObjectPath), 242 client_->List(kServiceName, dbus::ObjectPath(kObjectPath),
241 base::Bind(&MockListCallback::Run, 243 base::Bind(&MockListCallback::Run,
242 base::Unretained(&callback))); 244 base::Unretained(&callback)));
243 245
244 // Run the message loop. 246 // Run the message loop.
245 message_loop_.RunUntilIdle(); 247 message_loop_.RunUntilIdle();
246 } 248 }
247 249
248 } // namespace chromeos 250 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/ibus/ibus_panel_service_unittest.cc ('k') | chromeos/dbus/shill_client_unittest_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698