blob: 2dd049cc0551c58cba09f675993f629f129cc8f9 [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/property_store_unittest.h"
6
7#include <map>
8#include <string>
9#include <vector>
10
11#include <dbus-c++/dbus.h>
12#include <gtest/gtest.h>
13#include <gmock/gmock.h>
14
15#include "shill/dbus_adaptor.h"
16#include "shill/error.h"
17#include "shill/manager.h"
18#include "shill/mock_control.h"
19#include "shill/property_store.h"
20#include "shill/shill_event.h"
21
22using std::string;
23using std::map;
24using std::vector;
Chris Masone8a56ad62011-07-02 15:27:57 -070025using ::testing::Values;
Chris Masoneb925cc82011-06-22 15:39:57 -070026
27namespace shill {
28
29// static
30const ::DBus::Variant PropertyStoreTest::kBoolV = DBusAdaptor::BoolToVariant(0);
31// static
32const ::DBus::Variant PropertyStoreTest::kByteV = DBusAdaptor::ByteToVariant(0);
33// static
34const ::DBus::Variant PropertyStoreTest::kInt16V =
35 DBusAdaptor::Int16ToVariant(0);
36// static
37const ::DBus::Variant PropertyStoreTest::kInt32V =
38 DBusAdaptor::Int32ToVariant(0);
39// static
40const ::DBus::Variant PropertyStoreTest::kStringV =
41 DBusAdaptor::StringToVariant("");
42// static
43const ::DBus::Variant PropertyStoreTest::kStringmapV =
Chris Masonea8a2c252011-06-27 22:16:30 -070044 DBusAdaptor::StringmapToVariant(Stringmap());
Chris Masoneb925cc82011-06-22 15:39:57 -070045// static
46const ::DBus::Variant PropertyStoreTest::kStringmapsV =
47 DBusAdaptor::StringmapsToVariant(vector<map<string, string> >());
48// static
49const ::DBus::Variant PropertyStoreTest::kStringsV =
Chris Masonea8a2c252011-06-27 22:16:30 -070050 DBusAdaptor::StringsToVariant(Strings(1, ""));
Chris Masoneb925cc82011-06-22 15:39:57 -070051// static
52const ::DBus::Variant PropertyStoreTest::kUint16V =
53 DBusAdaptor::Uint16ToVariant(0);
54// static
55const ::DBus::Variant PropertyStoreTest::kUint32V =
56 DBusAdaptor::Uint32ToVariant(0);
57
58PropertyStoreTest::PropertyStoreTest()
59 : manager_(&control_interface_, &dispatcher_),
60 invalid_args_(Error::kErrorNames[Error::kInvalidArguments]),
61 invalid_prop_(Error::kErrorNames[Error::kInvalidProperty]) {
62}
63
64PropertyStoreTest::~PropertyStoreTest() {}
65
Chris Masone8a56ad62011-07-02 15:27:57 -070066TEST_P(PropertyStoreTest, TestProperty) {
67 // Ensure that an attempt to write unknown properties returns InvalidProperty.
68 PropertyStore store;
69 ::DBus::Error error;
70 EXPECT_FALSE(DBusAdaptor::DispatchOnType(&store, "", GetParam(), &error));
71 EXPECT_EQ(invalid_prop_, error.name());
72}
73
74INSTANTIATE_TEST_CASE_P(
75 PropertyStoreTestInstance,
76 PropertyStoreTest,
77 Values(PropertyStoreTest::kBoolV,
78 PropertyStoreTest::kByteV,
79 PropertyStoreTest::kStringV,
80 PropertyStoreTest::kInt16V,
81 PropertyStoreTest::kInt32V,
82 PropertyStoreTest::kUint16V,
83 PropertyStoreTest::kUint32V,
84 PropertyStoreTest::kStringsV,
85 PropertyStoreTest::kStringmapV,
86 PropertyStoreTest::kStringmapsV));
87
Chris Masoneb925cc82011-06-22 15:39:57 -070088} // namespace shill