blob: 878850218dae830bd5d63a89b1c50420a639680a [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:
20 RPCTaskTest() : notify_calls_(0), task_(&control_, this) {}
21
22 // Inherited from RPCTaskDelegate.
23 virtual void Notify(const string &reason, const map<string, string> &dict);
24
25 protected:
26 int notify_calls_;
27 string last_notify_reason_;
28 map<string, string> last_notify_dict_;
29 NiceMockControl control_;
30 RPCTask task_;
31};
32
33void RPCTaskTest::Notify(const string &reason,
34 const map<string, string> &dict) {
35
36 notify_calls_++;
37 last_notify_reason_ = reason;
38 last_notify_dict_ = dict;
39}
40
41TEST_F(RPCTaskTest, GetRpcIdentifiers) {
42 EXPECT_EQ(RPCTaskMockAdaptor::kRpcId, task_.GetRpcIdentifier());
43 EXPECT_EQ(RPCTaskMockAdaptor::kRpcInterfaceId,
44 task_.GetRpcInterfaceIdentifier());
45 EXPECT_EQ(RPCTaskMockAdaptor::kRpcConnId, task_.GetRpcConnectionIdentifier());
46}
47
48TEST_F(RPCTaskTest, Notify) {
49 static const char kReason[] = "up";
50 map<string, string> dict;
51 dict["foo"] = "bar";
52 task_.Notify(kReason, dict);
53 EXPECT_EQ(1, notify_calls_);
54 EXPECT_EQ(kReason, last_notify_reason_);
55 EXPECT_EQ("bar", last_notify_dict_["foo"]);
56}
57
58} // namespace shill