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 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | #include "shill/device.h" |
| 8 | #include "shill/dhcp_provider.h" |
| 9 | #include "shill/mock_control.h" |
| 10 | #include "shill/mock_glib.h" |
| 11 | |
| 12 | using testing::_; |
| 13 | using testing::Return; |
| 14 | using testing::Test; |
| 15 | |
| 16 | namespace shill { |
| 17 | |
| 18 | namespace { |
| 19 | const char kDeviceName[] = "testdevice"; |
| 20 | } // namespace {} |
| 21 | |
| 22 | class DeviceTest : public Test { |
| 23 | public: |
| 24 | DeviceTest() |
| 25 | : device_(new Device(&control_interface_, NULL, NULL, kDeviceName, 0)) { |
| 26 | DHCPProvider::GetInstance()->glib_ = &glib_; |
| 27 | } |
| 28 | |
| 29 | protected: |
| 30 | MockGLib glib_; |
| 31 | MockControl control_interface_; |
| 32 | DeviceRefPtr device_; |
| 33 | }; |
| 34 | |
| 35 | TEST_F(DeviceTest, TechnologyIs) { |
| 36 | EXPECT_FALSE(device_->TechnologyIs(Device::kEthernet)); |
| 37 | } |
| 38 | |
| 39 | TEST_F(DeviceTest, DestroyIPConfig) { |
| 40 | ASSERT_FALSE(device_->ipconfig_.get()); |
| 41 | device_->ipconfig_ = new IPConfig(kDeviceName); |
| 42 | device_->DestroyIPConfig(); |
| 43 | ASSERT_FALSE(device_->ipconfig_.get()); |
| 44 | } |
| 45 | |
| 46 | TEST_F(DeviceTest, DestroyIPConfigNULL) { |
| 47 | ASSERT_FALSE(device_->ipconfig_.get()); |
| 48 | device_->DestroyIPConfig(); |
| 49 | ASSERT_FALSE(device_->ipconfig_.get()); |
| 50 | } |
| 51 | |
| 52 | TEST_F(DeviceTest, AcquireDHCPConfig) { |
| 53 | device_->ipconfig_ = new IPConfig("randomname"); |
| 54 | EXPECT_CALL(glib_, SpawnAsync(_, _, _, _, _, _, _, _)) |
| 55 | .WillOnce(Return(false)); |
| 56 | EXPECT_FALSE(device_->AcquireDHCPConfig()); |
| 57 | ASSERT_TRUE(device_->ipconfig_.get()); |
| 58 | EXPECT_EQ(kDeviceName, device_->ipconfig_->device_name()); |
| 59 | EXPECT_TRUE(device_->ipconfig_->update_callback_.get()); |
| 60 | } |
| 61 | |
| 62 | } // namespace shill |