blob: 0b819544552f858e69038bf59e9484dda8d1c8e0 [file] [log] [blame]
Darin Petkovafa6fc42011-06-21 16:21:08 -07001// 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
12using testing::_;
13using testing::Return;
14using testing::Test;
15
16namespace shill {
17
18namespace {
19const char kDeviceName[] = "testdevice";
20} // namespace {}
21
22class 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
35TEST_F(DeviceTest, TechnologyIs) {
36 EXPECT_FALSE(device_->TechnologyIs(Device::kEthernet));
37}
38
39TEST_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
46TEST_F(DeviceTest, DestroyIPConfigNULL) {
47 ASSERT_FALSE(device_->ipconfig_.get());
48 device_->DestroyIPConfig();
49 ASSERT_FALSE(device_->ipconfig_.get());
50}
51
52TEST_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