blob: 6d842217c99dcf6ae364c443ba2c66ed613f8023 [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
Darin Petkovafa6fc42011-06-21 16:21:08 -07005#include "shill/device.h"
Darin Petkovafa6fc42011-06-21 16:21:08 -07006
Chris Masone3bd3c8c2011-06-13 08:20:26 -07007#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
25using std::map;
26using std::string;
27using std::vector;
28using ::testing::_;
29using ::testing::NiceMock;
30using ::testing::Return;
31using ::testing::Test;
Darin Petkovafa6fc42011-06-21 16:21:08 -070032
33namespace shill {
34
35namespace {
36const char kDeviceName[] = "testdevice";
37} // namespace {}
38
Chris Masone3bd3c8c2011-06-13 08:20:26 -070039class DeviceTest : public PropertyStoreTest {
Darin Petkovafa6fc42011-06-21 16:21:08 -070040 public:
41 DeviceTest()
42 : device_(new Device(&control_interface_, NULL, NULL, kDeviceName, 0)) {
43 DHCPProvider::GetInstance()->glib_ = &glib_;
44 }
Chris Masone3bd3c8c2011-06-13 08:20:26 -070045 virtual ~DeviceTest() {}
Darin Petkovafa6fc42011-06-21 16:21:08 -070046
47 protected:
48 MockGLib glib_;
49 MockControl control_interface_;
50 DeviceRefPtr device_;
51};
52
Chris Masone3bd3c8c2011-06-13 08:20:26 -070053TEST_F(DeviceTest, Contains) {
54 EXPECT_TRUE(device_->Contains(flimflam::kNameProperty));
55 EXPECT_FALSE(device_->Contains(""));
56}
57
58TEST_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 Petkovafa6fc42011-06-21 16:21:08 -0700104TEST_F(DeviceTest, TechnologyIs) {
105 EXPECT_FALSE(device_->TechnologyIs(Device::kEthernet));
106}
107
108TEST_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
115TEST_F(DeviceTest, DestroyIPConfigNULL) {
116 ASSERT_FALSE(device_->ipconfig_.get());
117 device_->DestroyIPConfig();
118 ASSERT_FALSE(device_->ipconfig_.get());
119}
120
121TEST_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