Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 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 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 5 | #include "shill/device.h" |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 6 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame^] | 7 | #include <map> |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include <dbus-c++/dbus.h> |
| 12 | #include <chromeos/dbus/service_constants.h> |
| 13 | #include <gtest/gtest.h> |
| 14 | #include <gmock/gmock.h> |
| 15 | |
| 16 | #include "shill/dbus_adaptor.h" |
| 17 | #include "shill/dhcp_provider.h" |
| 18 | #include "shill/manager.h" |
| 19 | #include "shill/mock_control.h" |
| 20 | #include "shill/mock_device.h" |
| 21 | #include "shill/mock_glib.h" |
| 22 | #include "shill/property_store_unittest.h" |
| 23 | #include "shill/shill_event.h" |
| 24 | |
| 25 | using std::map; |
| 26 | using std::string; |
| 27 | using std::vector; |
| 28 | using ::testing::_; |
| 29 | using ::testing::NiceMock; |
| 30 | using ::testing::Return; |
| 31 | using ::testing::Test; |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 32 | |
| 33 | namespace shill { |
| 34 | |
| 35 | namespace { |
| 36 | const char kDeviceName[] = "testdevice"; |
| 37 | } // namespace {} |
| 38 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame^] | 39 | class DeviceTest : public PropertyStoreTest { |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 40 | public: |
| 41 | DeviceTest() |
| 42 | : device_(new Device(&control_interface_, NULL, NULL, kDeviceName, 0)) { |
| 43 | DHCPProvider::GetInstance()->glib_ = &glib_; |
| 44 | } |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame^] | 45 | virtual ~DeviceTest() {} |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 46 | |
| 47 | protected: |
| 48 | MockGLib glib_; |
| 49 | MockControl control_interface_; |
| 50 | DeviceRefPtr device_; |
| 51 | }; |
| 52 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame^] | 53 | TEST_F(DeviceTest, Contains) { |
| 54 | EXPECT_TRUE(device_->Contains(flimflam::kNameProperty)); |
| 55 | EXPECT_FALSE(device_->Contains("")); |
| 56 | } |
| 57 | |
| 58 | TEST_F(DeviceTest, Dispatch) { |
| 59 | ::DBus::Error error; |
| 60 | EXPECT_TRUE(DBusAdaptor::DispatchOnType(device_.get(), |
| 61 | flimflam::kPoweredProperty, |
| 62 | bool_v_, |
| 63 | error)); |
| 64 | EXPECT_TRUE(DBusAdaptor::DispatchOnType( |
| 65 | device_.get(), |
| 66 | flimflam::kBgscanSignalThresholdProperty, |
| 67 | int32_v_, |
| 68 | error)); |
| 69 | EXPECT_TRUE(DBusAdaptor::DispatchOnType(device_.get(), |
| 70 | flimflam::kScanIntervalProperty, |
| 71 | uint16_v_, |
| 72 | error)); |
| 73 | |
| 74 | EXPECT_FALSE(DBusAdaptor::DispatchOnType(device_.get(), "", byte_v_, error)); |
| 75 | EXPECT_EQ(invalid_prop_, error.name()); |
| 76 | EXPECT_FALSE(DBusAdaptor::DispatchOnType(device_.get(), |
| 77 | "", |
| 78 | stringmap_v_, |
| 79 | error)); |
| 80 | EXPECT_EQ(invalid_prop_, error.name()); |
| 81 | EXPECT_FALSE(DBusAdaptor::DispatchOnType(device_.get(), |
| 82 | "", |
| 83 | uint32_v_, |
| 84 | error)); |
| 85 | EXPECT_EQ(invalid_prop_, error.name()); |
| 86 | |
| 87 | EXPECT_FALSE(DBusAdaptor::DispatchOnType(device_.get(), |
| 88 | flimflam::kCarrierProperty, |
| 89 | string_v_, |
| 90 | error)); |
| 91 | EXPECT_EQ(invalid_args_, error.name()); |
| 92 | EXPECT_FALSE(DBusAdaptor::DispatchOnType(device_.get(), |
| 93 | flimflam::kNetworksProperty, |
| 94 | strings_v_, |
| 95 | error)); |
| 96 | EXPECT_EQ(invalid_args_, error.name()); |
| 97 | EXPECT_FALSE(DBusAdaptor::DispatchOnType(device_.get(), |
| 98 | flimflam::kPRLVersionProperty, |
| 99 | int16_v_, |
| 100 | error)); |
| 101 | EXPECT_EQ(invalid_args_, error.name()); |
| 102 | } |
| 103 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 104 | TEST_F(DeviceTest, TechnologyIs) { |
| 105 | EXPECT_FALSE(device_->TechnologyIs(Device::kEthernet)); |
| 106 | } |
| 107 | |
| 108 | TEST_F(DeviceTest, DestroyIPConfig) { |
| 109 | ASSERT_FALSE(device_->ipconfig_.get()); |
| 110 | device_->ipconfig_ = new IPConfig(kDeviceName); |
| 111 | device_->DestroyIPConfig(); |
| 112 | ASSERT_FALSE(device_->ipconfig_.get()); |
| 113 | } |
| 114 | |
| 115 | TEST_F(DeviceTest, DestroyIPConfigNULL) { |
| 116 | ASSERT_FALSE(device_->ipconfig_.get()); |
| 117 | device_->DestroyIPConfig(); |
| 118 | ASSERT_FALSE(device_->ipconfig_.get()); |
| 119 | } |
| 120 | |
| 121 | TEST_F(DeviceTest, AcquireDHCPConfig) { |
| 122 | device_->ipconfig_ = new IPConfig("randomname"); |
| 123 | EXPECT_CALL(glib_, SpawnAsync(_, _, _, _, _, _, _, _)) |
| 124 | .WillOnce(Return(false)); |
| 125 | EXPECT_FALSE(device_->AcquireDHCPConfig()); |
| 126 | ASSERT_TRUE(device_->ipconfig_.get()); |
| 127 | EXPECT_EQ(kDeviceName, device_->ipconfig_->device_name()); |
| 128 | EXPECT_TRUE(device_->ipconfig_->update_callback_.get()); |
| 129 | } |
| 130 | |
| 131 | } // namespace shill |