Chromium Code Reviews| Index: chromeos/dbus/modem_messaging_client_unittest.cc |
| diff --git a/chromeos/dbus/gsm_sms_client_unittest.cc b/chromeos/dbus/modem_messaging_client_unittest.cc |
| similarity index 56% |
| copy from chromeos/dbus/gsm_sms_client_unittest.cc |
| copy to chromeos/dbus/modem_messaging_client_unittest.cc |
| index 6cbd5fddc184636e68dc01d033b3ab9bc249406e..8c6fa26c5775092b989b85eb64f427398ce07c1b 100644 |
| --- a/chromeos/dbus/gsm_sms_client_unittest.cc |
| +++ b/chromeos/dbus/modem_messaging_client_unittest.cc |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chromeos/dbus/gsm_sms_client.h" |
| +#include "chromeos/dbus/modem_messaging_client.h" |
| #include "base/bind.h" |
| #include "base/message_loop.h" |
| @@ -27,7 +27,7 @@ namespace { |
| // A mock SmsReceivedHandler. |
| class MockSmsReceivedHandler { |
| public: |
| - MOCK_METHOD2(Run, void(uint32 index, bool complete)); |
| + MOCK_METHOD2(Run, void(const dbus::ObjectPath &sms, bool complete)); |
| }; |
| // A mock DeleteCallback. |
| @@ -36,16 +36,10 @@ class MockDeleteCallback { |
| MOCK_METHOD0(Run, void()); |
| }; |
| -// A mock GetCallback. |
| -class MockGetCallback { |
| - public: |
| - MOCK_METHOD1(Run, void(const base::DictionaryValue& sms)); |
| -}; |
| - |
| // A mock ListCallback. |
| class MockListCallback { |
| public: |
| - MOCK_METHOD1(Run, void(const base::ListValue& result)); |
| + MOCK_METHOD1(Run, void(const std::vector<dbus::ObjectPath>& result)); |
| }; |
| // D-Bus service name used by test. |
| @@ -63,11 +57,10 @@ const char kExampleText[] = "Hello."; |
| } // namespace |
| -class GsmSMSClientTest : public testing::Test { |
| +class ModemMessagingClientTest : public testing::Test { |
| public: |
| - GsmSMSClientTest() : expected_index_(0), |
| - response_(NULL), |
| - expected_result_(NULL) {} |
| + ModemMessagingClientTest() : response_(NULL), |
| + expected_result_(NULL) {} |
| virtual void SetUp() OVERRIDE { |
| // Create a mock bus. |
| @@ -83,9 +76,10 @@ class GsmSMSClientTest : public testing::Test { |
| // Set an expectation so mock_proxy's ConnectToSignal() will use |
| // OnConnectToSignal() to run the callback. |
| EXPECT_CALL(*mock_proxy_, ConnectToSignal( |
| - modemmanager::kModemManagerSMSInterface, |
| - modemmanager::kSMSReceivedSignal, _, _)) |
| - .WillRepeatedly(Invoke(this, &GsmSMSClientTest::OnConnectToSignal)); |
| + modemmanager::kModemManager1MessagingInterface, |
| + modemmanager::kSMSAdded, _, _)) |
| + .WillRepeatedly( |
| + Invoke(this, &ModemMessagingClientTest::OnConnectToSignal)); |
| // Set an expectation so mock_bus's GetObjectProxy() for the given |
| // service name and the object path will return mock_proxy_. |
| @@ -97,8 +91,8 @@ class GsmSMSClientTest : public testing::Test { |
| EXPECT_CALL(*mock_bus_, ShutdownAndBlock()).WillOnce(Return()); |
| // Create a client with the mock bus. |
| - client_.reset(GsmSMSClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, |
| - mock_bus_)); |
| + client_.reset(ModemMessagingClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, |
| + mock_bus_)); |
| } |
| virtual void TearDown() OVERRIDE { |
| @@ -109,29 +103,13 @@ class GsmSMSClientTest : public testing::Test { |
| void OnDelete(dbus::MethodCall* method_call, |
| int timeout_ms, |
| const dbus::ObjectProxy::ResponseCallback& callback) { |
| - EXPECT_EQ(modemmanager::kModemManagerSMSInterface, |
| + EXPECT_EQ(modemmanager:kModemManager1MessagingInterface, |
| method_call->GetInterface()); |
| EXPECT_EQ(modemmanager::kSMSDeleteFunction, method_call->GetMember()); |
| - uint32 index = 0; |
| + dbus::ObjectPath sms_path; |
| dbus::MessageReader reader(method_call); |
| - EXPECT_TRUE(reader.PopUint32(&index)); |
| - EXPECT_EQ(expected_index_, index); |
| - EXPECT_FALSE(reader.HasMoreData()); |
| - |
| - message_loop_.PostTask(FROM_HERE, base::Bind(callback, response_)); |
| - } |
| - |
| - // Handles Get method call. |
| - void OnGet(dbus::MethodCall* method_call, |
| - int timeout_ms, |
| - const dbus::ObjectProxy::ResponseCallback& callback) { |
| - EXPECT_EQ(modemmanager::kModemManagerSMSInterface, |
| - method_call->GetInterface()); |
| - EXPECT_EQ(modemmanager::kSMSGetFunction, method_call->GetMember()); |
| - uint32 index = 0; |
| - dbus::MessageReader reader(method_call); |
| - EXPECT_TRUE(reader.PopUint32(&index)); |
| - EXPECT_EQ(expected_index_, index); |
| + EXPECT_TRUE(reader.PopObjectPath(&sms_path)); |
| + EXPECT_EQ(expected_sms_path_, sms_path); |
| EXPECT_FALSE(reader.HasMoreData()); |
| message_loop_.PostTask(FROM_HERE, base::Bind(callback, response_)); |
| @@ -141,7 +119,7 @@ class GsmSMSClientTest : public testing::Test { |
| void OnList(dbus::MethodCall* method_call, |
| int timeout_ms, |
| const dbus::ObjectProxy::ResponseCallback& callback) { |
| - EXPECT_EQ(modemmanager::kModemManagerSMSInterface, |
| + EXPECT_EQ(modemmanager:kModemManager1MessagingInterface, |
| method_call->GetInterface()); |
| EXPECT_EQ(modemmanager::kSMSListFunction, method_call->GetMember()); |
| dbus::MessageReader reader(method_call); |
| @@ -150,14 +128,14 @@ class GsmSMSClientTest : public testing::Test { |
| message_loop_.PostTask(FROM_HERE, base::Bind(callback, response_)); |
| } |
| - // Checks the results of Get and List. |
| - void CheckResult(const base::Value& result) { |
| + // Checks the results of List. |
| + void CheckResult(const std::vector<dbus::ObjectPath>& result) { |
| EXPECT_TRUE(result.Equals(expected_result_)); |
|
hashimoto
2012/06/06 07:19:44
Does this line compile?
|
| } |
| protected: |
| // The client to be tested. |
| - scoped_ptr<GsmSMSClient> client_; |
| + scoped_ptr<ModemMessagingClient> client_; |
| // A message loop to emulate asynchronous behavior. |
| MessageLoop message_loop_; |
| // The mock bus. |
| @@ -166,12 +144,12 @@ class GsmSMSClientTest : public testing::Test { |
| scoped_refptr<dbus::MockObjectProxy> mock_proxy_; |
| // The SmsReceived signal handler given by the tested client. |
| dbus::ObjectProxy::SignalCallback sms_received_callback_; |
| - // Expected argument for Delete and Get methods. |
| - uint32 expected_index_; |
| + // Expected argument for Delete method. |
| + dbus::ObjectPath expected_sms_path_; |
| // Response returned by mock methods. |
| dbus::Response* response_; |
| - // Expected result of Get and List methods. |
| - base::Value* expected_result_; |
| + // Expected result of List method. |
| + std::vector<dbus::ObjectPath>* expected_result_; |
| private: |
| // Used to implement the mock proxy. |
| @@ -189,12 +167,12 @@ class GsmSMSClientTest : public testing::Test { |
| } |
| }; |
| -TEST_F(GsmSMSClientTest, SmsReceived) { |
| +TEST_F(ModemMessagingClientTest, SmsReceived) { |
| // Set expectations. |
| - const uint32 kIndex = 42; |
| + const dbus::ObjectPath kSmsPath('/SMS/0'); |
| const bool kComplete = true; |
| MockSmsReceivedHandler handler; |
| - EXPECT_CALL(handler, Run(kIndex, kComplete)).Times(1); |
| + EXPECT_CALL(handler, Run(kSmsPath, kComplete)).Times(1); |
| // Set handler. |
| client_->SetSmsReceivedHandler(kServiceName, dbus::ObjectPath(kObjectPath), |
| base::Bind(&MockSmsReceivedHandler::Run, |
| @@ -204,10 +182,10 @@ TEST_F(GsmSMSClientTest, SmsReceived) { |
| message_loop_.RunAllPending(); |
| // Send signal. |
| - dbus::Signal signal(modemmanager::kModemManagerSMSInterface, |
| - modemmanager::kSMSReceivedSignal); |
| + dbus::Signal signal(modemmanager:kModemManager1MessagingInterface, |
| + modemmanager::kSMSAddedSignal); |
| dbus::MessageWriter writer(&signal); |
| - writer.AppendUint32(kIndex); |
| + writer.AppendObjectPath(kSmsPath); |
| writer.AppendBool(kComplete); |
| ASSERT_FALSE(sms_received_callback_.is_null()); |
| sms_received_callback_.Run(&signal); |
| @@ -217,19 +195,19 @@ TEST_F(GsmSMSClientTest, SmsReceived) { |
| sms_received_callback_.Run(&signal); |
| } |
| -TEST_F(GsmSMSClientTest, Delete) { |
| +TEST_F(ModemMessagingClientTest, Delete) { |
| // Set expectations. |
| - const uint32 kIndex = 42; |
| - expected_index_ = kIndex; |
| + const dbus::ObjectPath kSmsPath('/SMS/0'); |
| + expected_sms_path_ = kSmsPath; |
| EXPECT_CALL(*mock_proxy_, CallMethod(_, _, _)) |
| - .WillOnce(Invoke(this, &GsmSMSClientTest::OnDelete)); |
| + .WillOnce(Invoke(this, &ModemMessagingClientTest::OnDelete)); |
| MockDeleteCallback callback; |
| EXPECT_CALL(callback, Run()).Times(1); |
| // Create response. |
| scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| response_ = response.get(); |
| // Call Delete. |
| - client_->Delete(kServiceName, dbus::ObjectPath(kObjectPath), kIndex, |
| + client_->Delete(kServiceName, dbus::ObjectPath(kObjectPath), kSmsPath, |
| base::Bind(&MockDeleteCallback::Run, |
| base::Unretained(&callback))); |
| @@ -237,82 +215,31 @@ TEST_F(GsmSMSClientTest, Delete) { |
| message_loop_.RunAllPending(); |
| } |
| -TEST_F(GsmSMSClientTest, Get) { |
| +TEST_F(ModemMessagingClientTest, List) { |
| // Set expectations. |
| - const uint32 kIndex = 42; |
| - expected_index_ = kIndex; |
| EXPECT_CALL(*mock_proxy_, CallMethod(_, _, _)) |
| - .WillOnce(Invoke(this, &GsmSMSClientTest::OnGet)); |
| - MockGetCallback callback; |
| - EXPECT_CALL(callback, Run(_)) |
| - .WillOnce(Invoke(this, &GsmSMSClientTest::CheckResult)); |
| - // Create response. |
| - scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| - dbus::MessageWriter writer(response.get()); |
| - dbus::MessageWriter array_writer(NULL); |
| - writer.OpenArray("{sv}", &array_writer); |
| - dbus::MessageWriter entry_writer(NULL); |
| - array_writer.OpenDictEntry(&entry_writer); |
| - entry_writer.AppendString(kNumberKey); |
| - entry_writer.AppendVariantOfString(kExampleNumber); |
| - array_writer.CloseContainer(&entry_writer); |
| - array_writer.OpenDictEntry(&entry_writer); |
| - entry_writer.AppendString(kTextKey); |
| - entry_writer.AppendVariantOfString(kExampleText); |
| - array_writer.CloseContainer(&entry_writer); |
| - writer.CloseContainer(&array_writer); |
| - response_ = response.get(); |
| - // Create expected result. |
| - base::DictionaryValue expected_result; |
| - expected_result.SetWithoutPathExpansion( |
| - kNumberKey, base::Value::CreateStringValue(kExampleNumber)); |
| - expected_result.SetWithoutPathExpansion( |
| - kTextKey, base::Value::CreateStringValue(kExampleText)); |
| - expected_result_ = &expected_result; |
| - // Call Delete. |
| - client_->Get(kServiceName, dbus::ObjectPath(kObjectPath), kIndex, |
| - base::Bind(&MockGetCallback::Run, base::Unretained(&callback))); |
| - |
| - // Run the message loop. |
| - message_loop_.RunAllPending(); |
| -} |
| - |
| -TEST_F(GsmSMSClientTest, List) { |
| - // Set expectations. |
| - EXPECT_CALL(*mock_proxy_, CallMethod(_, _, _)) |
| - .WillOnce(Invoke(this, &GsmSMSClientTest::OnList)); |
| + .WillOnce(Invoke(this, &ModemMessagingClientTest::OnList)); |
| MockListCallback callback; |
| EXPECT_CALL(callback, Run(_)) |
| - .WillOnce(Invoke(this, &GsmSMSClientTest::CheckResult)); |
| + .WillOnce(Invoke(this, &ModemMessagingClientTest::CheckResult)); |
| // Create response. |
| scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| + dbus::ObjectPath path1("/SMS/1"); |
| + dbus::ObjectPath path2("/SMS/2"); |
| dbus::MessageWriter writer(response.get()); |
| dbus::MessageWriter array_writer(NULL); |
| - writer.OpenArray("a{sv}", &array_writer); |
| - dbus::MessageWriter sub_array_writer(NULL); |
| - array_writer.OpenArray("{sv}", &sub_array_writer); |
| - dbus::MessageWriter entry_writer(NULL); |
| - sub_array_writer.OpenDictEntry(&entry_writer); |
| - entry_writer.AppendString(kNumberKey); |
| - entry_writer.AppendVariantOfString(kExampleNumber); |
| - sub_array_writer.CloseContainer(&entry_writer); |
| - sub_array_writer.OpenDictEntry(&entry_writer); |
| - entry_writer.AppendString(kTextKey); |
| - entry_writer.AppendVariantOfString(kExampleText); |
| - sub_array_writer.CloseContainer(&entry_writer); |
| - array_writer.CloseContainer(&sub_array_writer); |
| + writer.OpenArray("ao", &array_writer); |
|
hashimoto
2012/06/06 07:19:44
I think this should be "o", not "ao".
Does this te
Jason Glasgow
2012/06/06 20:54:20
Done.
|
| + entry_writer.AppendObjectPath(path1); |
| + entry_writer.AppendObjectPath(path2); |
| writer.CloseContainer(&array_writer); |
| response_ = response.get(); |
| + |
| // Create expected result. |
| - base::ListValue expected_result; |
| - base::DictionaryValue* sms = new base::DictionaryValue; |
| - sms->SetWithoutPathExpansion( |
| - kNumberKey, base::Value::CreateStringValue(kExampleNumber)); |
| - sms->SetWithoutPathExpansion( |
| - kTextKey, base::Value::CreateStringValue(kExampleText)); |
| - expected_result.Append(sms); |
| + std::vector<dbus::ObjectPath> expected_result; |
| + expected_result.push_back(path1); |
| + expected_result.push_back(path2); |
| expected_result_ = &expected_result; |
| - // Call Delete. |
| + // Call List. |
| client_->List(kServiceName, dbus::ObjectPath(kObjectPath), |
| base::Bind(&MockListCallback::Run, |
| base::Unretained(&callback))); |