Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 1 | // 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 Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 7 | #include <base/string_util.h> |
| 8 | #include <chromeos/dbus/service_constants.h> |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 9 | #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 Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 18 | using std::string; |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 19 | using testing::_; |
| 20 | using testing::NiceMock; |
| 21 | using testing::Return; |
Ben Chan | 4e5c131 | 2012-05-18 18:45:38 -0700 | [diff] [blame] | 22 | using wimax_manager::kEAPAnonymousIdentity; |
| 23 | using wimax_manager::kEAPUserIdentity; |
| 24 | using wimax_manager::kEAPUserPassword; |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 25 | |
| 26 | namespace shill { |
| 27 | |
| 28 | namespace { |
| 29 | |
| 30 | const char kTestLinkName[] = "wm0"; |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 31 | const char kTestAddress[] = "0123456789AB"; |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 32 | const int kTestInterfaceIndex = 5; |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 33 | const char kTestPath[] = "/org/chromium/WiMaxManager/Device/wm7"; |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 34 | |
| 35 | } // namespace |
| 36 | |
| 37 | class WiMaxServiceTest : public testing::Test { |
| 38 | public: |
| 39 | WiMaxServiceTest() |
| 40 | : manager_(&control_, NULL, NULL, NULL), |
| 41 | wimax_(new MockWiMax(&control_, NULL, &metrics_, &manager_, |
Ben Chan | 4e64d2d | 2012-05-16 00:02:25 -0700 | [diff] [blame] | 42 | kTestLinkName, kTestAddress, kTestInterfaceIndex, |
| 43 | kTestPath)), |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 44 | 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 Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 53 | scoped_refptr<MockWiMax> wimax_; |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 54 | WiMaxServiceRefPtr service_; |
| 55 | }; |
| 56 | |
Ben Chan | 4e5c131 | 2012-05-18 18:45:38 -0700 | [diff] [blame] | 57 | TEST_F(WiMaxServiceTest, GetConnectParameters) { |
| 58 | { |
| 59 | DBusPropertiesMap parameters; |
| 60 | service_->GetConnectParameters(¶meters); |
| 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(¶meters); |
| 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 Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 93 | TEST_F(WiMaxServiceTest, TechnologyIs) { |
| 94 | EXPECT_TRUE(service_->TechnologyIs(Technology::kWiMax)); |
| 95 | EXPECT_FALSE(service_->TechnologyIs(Technology::kEthernet)); |
| 96 | } |
| 97 | |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 98 | TEST_F(WiMaxServiceTest, GetDeviceRpcId) { |
| 99 | Error error; |
| 100 | EXPECT_EQ(DeviceMockAdaptor::kRpcId, service_->GetDeviceRpcId(&error)); |
| 101 | EXPECT_TRUE(error.IsSuccess()); |
| 102 | } |
| 103 | |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 104 | } // namespace shill |