blob: 397e13317fc7555fe058f8912150652fa128a37e [file] [log] [blame]
Chris Masoneb925cc82011-06-22 15:39:57 -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 "shill/cellular.h"
6
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/manager.h"
18#include "shill/mock_control.h"
19#include "shill/mock_device.h"
20#include "shill/property_store_unittest.h"
21
22using std::map;
23using std::string;
24using std::vector;
25using ::testing::_;
26using ::testing::NiceMock;
27using ::testing::Return;
28using ::testing::Test;
29using ::testing::Values;
30
31namespace shill {
32
33class CellularTest : public PropertyStoreTest {
34 public:
35 CellularTest()
36 : device_(new Cellular(&control_interface_, NULL, NULL, "3G", 0)) {
37 }
38 virtual ~CellularTest() {}
39
40 protected:
41 DeviceRefPtr device_;
42};
43
44TEST_F(CellularTest, Contains) {
45 EXPECT_TRUE(device_->Contains(flimflam::kNameProperty));
46 EXPECT_FALSE(device_->Contains(""));
47}
48
49TEST_F(CellularTest, Dispatch) {
50 ::DBus::Error error;
51 EXPECT_TRUE(DBusAdaptor::DispatchOnType(
52 device_.get(),
53 flimflam::kCellularAllowRoamingProperty,
54 PropertyStoreTest::kBoolV,
55 error));
Chris Masoneb925cc82011-06-22 15:39:57 -070056 EXPECT_TRUE(DBusAdaptor::DispatchOnType(device_.get(),
57 flimflam::kScanIntervalProperty,
58 PropertyStoreTest::kUint16V,
59 error));
60
61 // Ensure that an attempt to write a R/O property returns InvalidArgs error.
62 EXPECT_FALSE(DBusAdaptor::DispatchOnType(device_.get(),
63 flimflam::kAddressProperty,
64 PropertyStoreTest::kStringV,
65 error));
66 EXPECT_EQ(invalid_args_, error.name());
67 EXPECT_FALSE(DBusAdaptor::DispatchOnType(device_.get(),
68 flimflam::kCarrierProperty,
69 PropertyStoreTest::kStringV,
70 error));
71 EXPECT_EQ(invalid_args_, error.name());
72 EXPECT_FALSE(DBusAdaptor::DispatchOnType(device_.get(),
73 flimflam::kPRLVersionProperty,
74 PropertyStoreTest::kInt16V,
75 error));
76 EXPECT_EQ(invalid_args_, error.name());
77}
78
79TEST_P(CellularTest, TestProperty) {
80 // Ensure that an attempt to write unknown properties returns InvalidProperty.
81 ::DBus::Error error;
82 EXPECT_FALSE(DBusAdaptor::DispatchOnType(&manager_, "", GetParam(), error));
83 EXPECT_EQ(invalid_prop_, error.name());
84}
85
86INSTANTIATE_TEST_CASE_P(
87 CellularTestInstance,
88 CellularTest,
89 Values(PropertyStoreTest::kBoolV,
90 PropertyStoreTest::kByteV,
91 PropertyStoreTest::kStringV,
92 PropertyStoreTest::kInt16V,
93 PropertyStoreTest::kInt32V,
94 PropertyStoreTest::kUint16V,
95 PropertyStoreTest::kUint32V,
96 PropertyStoreTest::kStringsV,
97 PropertyStoreTest::kStringmapV,
98 PropertyStoreTest::kStringmapsV));
99
100} // namespace shill