blob: f0fa69a5dd0503c17209241a099705d5b117949c [file] [log] [blame]
Ben Chanc07362b2012-05-12 10:54:11 -07001// 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/wimax_service.h"
6
Darin Petkove4b27022012-05-16 13:28:50 +02007#include <base/string_util.h>
8#include <chromeos/dbus/service_constants.h>
Ben Chanc07362b2012-05-12 10:54:11 -07009#include <gtest/gtest.h>
10
11#include "shill/error.h"
12#include "shill/nice_mock_control.h"
13#include "shill/mock_adaptors.h"
14#include "shill/mock_manager.h"
15#include "shill/mock_metrics.h"
16#include "shill/mock_wimax.h"
17
Darin Petkove4b27022012-05-16 13:28:50 +020018using std::string;
Ben Chanc07362b2012-05-12 10:54:11 -070019using testing::_;
20using testing::NiceMock;
21using testing::Return;
Ben Chan4e5c1312012-05-18 18:45:38 -070022using wimax_manager::kEAPAnonymousIdentity;
23using wimax_manager::kEAPUserIdentity;
24using wimax_manager::kEAPUserPassword;
Ben Chanc07362b2012-05-12 10:54:11 -070025
26namespace shill {
27
28namespace {
29
30const char kTestLinkName[] = "wm0";
Darin Petkove4b27022012-05-16 13:28:50 +020031const char kTestAddress[] = "0123456789AB";
Ben Chanc07362b2012-05-12 10:54:11 -070032const int kTestInterfaceIndex = 5;
Darin Petkove4b27022012-05-16 13:28:50 +020033const char kTestPath[] = "/org/chromium/WiMaxManager/Device/wm7";
Ben Chanc07362b2012-05-12 10:54:11 -070034
35} // namespace
36
37class WiMaxServiceTest : public testing::Test {
38 public:
39 WiMaxServiceTest()
40 : manager_(&control_, NULL, NULL, NULL),
41 wimax_(new MockWiMax(&control_, NULL, &metrics_, &manager_,
Ben Chan4e64d2d2012-05-16 00:02:25 -070042 kTestLinkName, kTestAddress, kTestInterfaceIndex,
43 kTestPath)),
Ben Chanc07362b2012-05-12 10:54:11 -070044 service_(new WiMaxService(&control_, NULL, &metrics_, &manager_,
45 wimax_)) {}
46
47 virtual ~WiMaxServiceTest() {}
48
49 protected:
50 NiceMockControl control_;
51 MockManager manager_;
52 MockMetrics metrics_;
Darin Petkovb72b62e2012-05-15 16:55:36 +020053 scoped_refptr<MockWiMax> wimax_;
Ben Chanc07362b2012-05-12 10:54:11 -070054 WiMaxServiceRefPtr service_;
55};
56
Ben Chan4e5c1312012-05-18 18:45:38 -070057TEST_F(WiMaxServiceTest, GetConnectParameters) {
58 {
59 DBusPropertiesMap parameters;
60 service_->GetConnectParameters(&parameters);
61
62 EXPECT_TRUE(ContainsKey(parameters, kEAPAnonymousIdentity));
63 EXPECT_STREQ("", parameters[kEAPAnonymousIdentity].reader().get_string());
64
65 EXPECT_TRUE(ContainsKey(parameters, kEAPUserIdentity));
66 EXPECT_STREQ("", parameters[kEAPUserIdentity].reader().get_string());
67
68 EXPECT_TRUE(ContainsKey(parameters, kEAPUserPassword));
69 EXPECT_STREQ("", parameters[kEAPUserPassword].reader().get_string());
70 }
71 {
72 Service::EapCredentials eap;
73 eap.anonymous_identity = "TestAnonymousIdentity";
74 eap.identity = "TestUserIdentity";
75 eap.password = "TestPassword";
76 service_->set_eap(eap);
77
78 DBusPropertiesMap parameters;
79 service_->GetConnectParameters(&parameters);
80
81 EXPECT_TRUE(ContainsKey(parameters, kEAPAnonymousIdentity));
82 EXPECT_EQ(eap.anonymous_identity,
83 parameters[kEAPAnonymousIdentity].reader().get_string());
84
85 EXPECT_TRUE(ContainsKey(parameters, kEAPUserIdentity));
86 EXPECT_EQ(eap.identity, parameters[kEAPUserIdentity].reader().get_string());
87
88 EXPECT_TRUE(ContainsKey(parameters, kEAPUserPassword));
89 EXPECT_EQ(eap.password, parameters[kEAPUserPassword].reader().get_string());
90 }
91}
92
Ben Chanc07362b2012-05-12 10:54:11 -070093TEST_F(WiMaxServiceTest, TechnologyIs) {
94 EXPECT_TRUE(service_->TechnologyIs(Technology::kWiMax));
95 EXPECT_FALSE(service_->TechnologyIs(Technology::kEthernet));
96}
97
Darin Petkove4b27022012-05-16 13:28:50 +020098TEST_F(WiMaxServiceTest, GetDeviceRpcId) {
99 Error error;
100 EXPECT_EQ(DeviceMockAdaptor::kRpcId, service_->GetDeviceRpcId(&error));
101 EXPECT_TRUE(error.IsSuccess());
102}
103
Ben Chanc07362b2012-05-12 10:54:11 -0700104} // namespace shill