blob: a1b8f31410d07b2e1467a26fa128b79a69c69a0d [file] [log] [blame]
Darin Petkova9b1fed2012-02-29 11:49:05 +01001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "shill/rpc_task.h"
6
7#include <gtest/gtest.h>
8
9#include "shill/nice_mock_control.h"
10#include "shill/mock_adaptors.h"
11
12using std::map;
13using std::string;
14
15namespace shill {
16
17class RPCTaskTest : public testing::Test,
18 public RPCTaskDelegate {
19 public:
Darin Petkov209e6292012-04-20 11:33:32 +020020 RPCTaskTest()
21 : get_login_calls_(0),
22 notify_calls_(0),
23 task_(&control_, this) {}
Darin Petkova9b1fed2012-02-29 11:49:05 +010024
25 // Inherited from RPCTaskDelegate.
Darin Petkov209e6292012-04-20 11:33:32 +020026 virtual void GetLogin(string *user, string *password);
Darin Petkova9b1fed2012-02-29 11:49:05 +010027 virtual void Notify(const string &reason, const map<string, string> &dict);
28
29 protected:
Darin Petkov209e6292012-04-20 11:33:32 +020030 int get_login_calls_;
Darin Petkova9b1fed2012-02-29 11:49:05 +010031 int notify_calls_;
Darin Petkov209e6292012-04-20 11:33:32 +020032 string *last_user_;
33 string *last_password_;
Darin Petkova9b1fed2012-02-29 11:49:05 +010034 string last_notify_reason_;
35 map<string, string> last_notify_dict_;
36 NiceMockControl control_;
37 RPCTask task_;
38};
39
Darin Petkov209e6292012-04-20 11:33:32 +020040void RPCTaskTest::GetLogin(string *user, string *password) {
41 get_login_calls_++;
42 last_user_ = user;
43 last_password_ = password;
44}
45
Darin Petkova9b1fed2012-02-29 11:49:05 +010046void RPCTaskTest::Notify(const string &reason,
47 const map<string, string> &dict) {
48
49 notify_calls_++;
50 last_notify_reason_ = reason;
51 last_notify_dict_ = dict;
52}
53
54TEST_F(RPCTaskTest, GetRpcIdentifiers) {
55 EXPECT_EQ(RPCTaskMockAdaptor::kRpcId, task_.GetRpcIdentifier());
56 EXPECT_EQ(RPCTaskMockAdaptor::kRpcInterfaceId,
57 task_.GetRpcInterfaceIdentifier());
58 EXPECT_EQ(RPCTaskMockAdaptor::kRpcConnId, task_.GetRpcConnectionIdentifier());
59}
60
Darin Petkov209e6292012-04-20 11:33:32 +020061TEST_F(RPCTaskTest, GetLogin) {
62 string user, password;
63 task_.GetLogin(&user, &password);
64 EXPECT_EQ(1, get_login_calls_);
65 EXPECT_EQ(&user, last_user_);
66 EXPECT_EQ(&password, last_password_);
67}
68
Darin Petkova9b1fed2012-02-29 11:49:05 +010069TEST_F(RPCTaskTest, Notify) {
70 static const char kReason[] = "up";
71 map<string, string> dict;
72 dict["foo"] = "bar";
73 task_.Notify(kReason, dict);
74 EXPECT_EQ(1, notify_calls_);
75 EXPECT_EQ(kReason, last_notify_reason_);
76 EXPECT_EQ("bar", last_notify_dict_["foo"]);
77}
78
79} // namespace shill