blob: fedf834fed8904afcd34f4303cf10dd928322ccf [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"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070020#include "shill/mock_service.h"
21#include "shill/property_store_unittest.h"
22#include "shill/shill_event.h"
23
24using std::map;
25using std::string;
26using std::vector;
27using ::testing::_;
28using ::testing::NiceMock;
29using ::testing::Return;
30using ::testing::Test;
Chris Masoneb925cc82011-06-22 15:39:57 -070031using ::testing::Values;
Chris Masone3bd3c8c2011-06-13 08:20:26 -070032
33namespace shill {
34
35class ServiceTest : public PropertyStoreTest {
36 public:
Chris Masoneb925cc82011-06-22 15:39:57 -070037 ServiceTest()
38 : service_(new MockService(&control_interface_,
39 &dispatcher_,
Chris Masoneb925cc82011-06-22 15:39:57 -070040 "mock-service")) {
41 }
42
Chris Masone3bd3c8c2011-06-13 08:20:26 -070043 virtual ~ServiceTest() {}
Chris Masoneb925cc82011-06-22 15:39:57 -070044
45 protected:
46 ServiceRefPtr service_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -070047};
48
49TEST_F(ServiceTest, Dispatch) {
mukesh agrawala903e412011-06-28 17:07:11 -070050 ::DBus::Error e1, e2, e3, e4;
Chris Masoneb925cc82011-06-22 15:39:57 -070051 EXPECT_TRUE(DBusAdaptor::DispatchOnType(service_.get(),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070052 flimflam::kSaveCredentialsProperty,
Chris Masoneb925cc82011-06-22 15:39:57 -070053 PropertyStoreTest::kBoolV,
mukesh agrawala903e412011-06-28 17:07:11 -070054 e1));
Chris Masoneb925cc82011-06-22 15:39:57 -070055 EXPECT_TRUE(DBusAdaptor::DispatchOnType(service_.get(),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070056 flimflam::kPriorityProperty,
Chris Masoneb925cc82011-06-22 15:39:57 -070057 PropertyStoreTest::kInt32V,
mukesh agrawala903e412011-06-28 17:07:11 -070058 e2));
Chris Masoneb925cc82011-06-22 15:39:57 -070059 EXPECT_TRUE(DBusAdaptor::DispatchOnType(service_.get(),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070060 flimflam::kEAPEAPProperty,
Chris Masoneb925cc82011-06-22 15:39:57 -070061 PropertyStoreTest::kStringV,
mukesh agrawala903e412011-06-28 17:07:11 -070062 e3));
Chris Masone3bd3c8c2011-06-13 08:20:26 -070063
Chris Masoneb925cc82011-06-22 15:39:57 -070064 // Ensure that an attempt to write a R/O property returns InvalidArgs error.
65 EXPECT_FALSE(DBusAdaptor::DispatchOnType(service_.get(),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070066 flimflam::kFavoriteProperty,
Chris Masoneb925cc82011-06-22 15:39:57 -070067 PropertyStoreTest::kBoolV,
mukesh agrawala903e412011-06-28 17:07:11 -070068 e4));
69 EXPECT_EQ(invalid_args_, e4.name());
Chris Masoneb925cc82011-06-22 15:39:57 -070070}
71
72TEST_P(ServiceTest, TestProperty) {
73 // Ensure that an attempt to write unknown properties returns InvalidProperty.
74 ::DBus::Error error;
75 EXPECT_FALSE(DBusAdaptor::DispatchOnType(service_.get(),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070076 "",
Chris Masoneb925cc82011-06-22 15:39:57 -070077 GetParam(),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070078 error));
79 EXPECT_EQ(invalid_prop_, error.name());
80}
81
Chris Masoneb925cc82011-06-22 15:39:57 -070082INSTANTIATE_TEST_CASE_P(
83 ServiceTestInstance,
84 ServiceTest,
85 Values(PropertyStoreTest::kBoolV,
86 PropertyStoreTest::kByteV,
87 PropertyStoreTest::kStringV,
88 PropertyStoreTest::kInt16V,
89 PropertyStoreTest::kInt32V,
90 PropertyStoreTest::kUint16V,
91 PropertyStoreTest::kUint32V,
92 PropertyStoreTest::kStringsV,
93 PropertyStoreTest::kStringmapV,
94 PropertyStoreTest::kStringmapsV));
95
Chris Masone3bd3c8c2011-06-13 08:20:26 -070096} // namespace shill