blob: 3c7900523a2f11c44a7b87369d51acab8ad3abbd [file] [log] [blame]
Chris Masone3bd3c8c2011-06-13 08:20:26 -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/service.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/ethernet_service.h"
18#include "shill/manager.h"
19#include "shill/mock_control.h"
20#include "shill/mock_device.h"
21#include "shill/mock_service.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;
Chris Masoneb925cc82011-06-22 15:39:57 -070032using ::testing::Values;
Chris Masone3bd3c8c2011-06-13 08:20:26 -070033
34namespace shill {
35
36class ServiceTest : public PropertyStoreTest {
37 public:
Chris Masoneb925cc82011-06-22 15:39:57 -070038 ServiceTest()
39 : service_(new MockService(&control_interface_,
40 &dispatcher_,
41 new MockDevice(&control_interface_,
42 &dispatcher_,
43 &manager_,
44 "mock-device",
45 0),
46 "mock-service")) {
47 }
48
Chris Masone3bd3c8c2011-06-13 08:20:26 -070049 virtual ~ServiceTest() {}
Chris Masoneb925cc82011-06-22 15:39:57 -070050
51 protected:
52 ServiceRefPtr service_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -070053};
54
55TEST_F(ServiceTest, Dispatch) {
Chris Masone3bd3c8c2011-06-13 08:20:26 -070056 ::DBus::Error error;
Chris Masoneb925cc82011-06-22 15:39:57 -070057 EXPECT_TRUE(DBusAdaptor::DispatchOnType(service_.get(),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070058 flimflam::kSaveCredentialsProperty,
Chris Masoneb925cc82011-06-22 15:39:57 -070059 PropertyStoreTest::kBoolV,
Chris Masone3bd3c8c2011-06-13 08:20:26 -070060 error));
Chris Masoneb925cc82011-06-22 15:39:57 -070061 EXPECT_TRUE(DBusAdaptor::DispatchOnType(service_.get(),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070062 flimflam::kPriorityProperty,
Chris Masoneb925cc82011-06-22 15:39:57 -070063 PropertyStoreTest::kInt32V,
Chris Masone3bd3c8c2011-06-13 08:20:26 -070064 error));
Chris Masoneb925cc82011-06-22 15:39:57 -070065 EXPECT_TRUE(DBusAdaptor::DispatchOnType(service_.get(),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070066 flimflam::kEAPEAPProperty,
Chris Masoneb925cc82011-06-22 15:39:57 -070067 PropertyStoreTest::kStringV,
Chris Masone3bd3c8c2011-06-13 08:20:26 -070068 error));
69
Chris Masoneb925cc82011-06-22 15:39:57 -070070 // Ensure that an attempt to write a R/O property returns InvalidArgs error.
71 EXPECT_FALSE(DBusAdaptor::DispatchOnType(service_.get(),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070072 flimflam::kFavoriteProperty,
Chris Masoneb925cc82011-06-22 15:39:57 -070073 PropertyStoreTest::kBoolV,
Chris Masone3bd3c8c2011-06-13 08:20:26 -070074 error));
75 EXPECT_EQ(invalid_args_, error.name());
Chris Masoneb925cc82011-06-22 15:39:57 -070076}
77
78TEST_P(ServiceTest, TestProperty) {
79 // Ensure that an attempt to write unknown properties returns InvalidProperty.
80 ::DBus::Error error;
81 EXPECT_FALSE(DBusAdaptor::DispatchOnType(service_.get(),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070082 "",
Chris Masoneb925cc82011-06-22 15:39:57 -070083 GetParam(),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070084 error));
85 EXPECT_EQ(invalid_prop_, error.name());
86}
87
Chris Masoneb925cc82011-06-22 15:39:57 -070088INSTANTIATE_TEST_CASE_P(
89 ServiceTestInstance,
90 ServiceTest,
91 Values(PropertyStoreTest::kBoolV,
92 PropertyStoreTest::kByteV,
93 PropertyStoreTest::kStringV,
94 PropertyStoreTest::kInt16V,
95 PropertyStoreTest::kInt32V,
96 PropertyStoreTest::kUint16V,
97 PropertyStoreTest::kUint32V,
98 PropertyStoreTest::kStringsV,
99 PropertyStoreTest::kStringmapV,
100 PropertyStoreTest::kStringmapsV));
101
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700102} // namespace shill