Chris Masone | b925cc8 | 2011-06-22 15:39:57 -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 "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 | |
| 22 | using std::map; |
| 23 | using std::string; |
| 24 | using std::vector; |
| 25 | using ::testing::_; |
| 26 | using ::testing::NiceMock; |
| 27 | using ::testing::Return; |
| 28 | using ::testing::Test; |
| 29 | using ::testing::Values; |
| 30 | |
| 31 | namespace shill { |
| 32 | |
| 33 | class 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 | |
| 44 | TEST_F(CellularTest, Contains) { |
| 45 | EXPECT_TRUE(device_->Contains(flimflam::kNameProperty)); |
| 46 | EXPECT_FALSE(device_->Contains("")); |
| 47 | } |
| 48 | |
| 49 | TEST_F(CellularTest, Dispatch) { |
| 50 | ::DBus::Error error; |
| 51 | EXPECT_TRUE(DBusAdaptor::DispatchOnType( |
| 52 | device_.get(), |
| 53 | flimflam::kCellularAllowRoamingProperty, |
| 54 | PropertyStoreTest::kBoolV, |
| 55 | error)); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 56 | 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 | |
| 79 | TEST_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 | |
| 86 | INSTANTIATE_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 |