blob: c35b2c3b88f9d2a0f30ea924e4dda8534a1f2ae1 [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>
Chris Masone889666b2011-07-03 12:58:50 -07009#include <utility>
Chris Masoneb925cc82011-06-22 15:39:57 -070010#include <vector>
11
12#include <dbus-c++/dbus.h>
13#include <gtest/gtest.h>
14#include <gmock/gmock.h>
15
16#include "shill/dbus_adaptor.h"
17#include "shill/error.h"
Paul Stewart26b327e2011-10-19 11:38:09 -070018#include "shill/event_dispatcher.h"
Chris Masoneb925cc82011-06-22 15:39:57 -070019#include "shill/manager.h"
20#include "shill/mock_control.h"
21#include "shill/property_store.h"
Chris Masoneb925cc82011-06-22 15:39:57 -070022
Chris Masone889666b2011-07-03 12:58:50 -070023using std::make_pair;
Chris Masoneb925cc82011-06-22 15:39:57 -070024using std::map;
Chris Masone889666b2011-07-03 12:58:50 -070025using std::string;
Chris Masoneb925cc82011-06-22 15:39:57 -070026using std::vector;
Chris Masone8a56ad62011-07-02 15:27:57 -070027using ::testing::Values;
Chris Masoneb925cc82011-06-22 15:39:57 -070028
29namespace shill {
30
31// static
32const ::DBus::Variant PropertyStoreTest::kBoolV = DBusAdaptor::BoolToVariant(0);
33// static
34const ::DBus::Variant PropertyStoreTest::kByteV = DBusAdaptor::ByteToVariant(0);
35// static
36const ::DBus::Variant PropertyStoreTest::kInt16V =
37 DBusAdaptor::Int16ToVariant(0);
38// static
39const ::DBus::Variant PropertyStoreTest::kInt32V =
40 DBusAdaptor::Int32ToVariant(0);
41// static
42const ::DBus::Variant PropertyStoreTest::kStringV =
43 DBusAdaptor::StringToVariant("");
44// static
45const ::DBus::Variant PropertyStoreTest::kStringmapV =
Chris Masonea8a2c252011-06-27 22:16:30 -070046 DBusAdaptor::StringmapToVariant(Stringmap());
Chris Masoneb925cc82011-06-22 15:39:57 -070047// static
48const ::DBus::Variant PropertyStoreTest::kStringmapsV =
Chris Masone889666b2011-07-03 12:58:50 -070049 DBusAdaptor::StringmapsToVariant(Stringmaps());
Chris Masoneb925cc82011-06-22 15:39:57 -070050// static
51const ::DBus::Variant PropertyStoreTest::kStringsV =
Chris Masonea8a2c252011-06-27 22:16:30 -070052 DBusAdaptor::StringsToVariant(Strings(1, ""));
Chris Masoneb925cc82011-06-22 15:39:57 -070053// static
Chris Masone889666b2011-07-03 12:58:50 -070054const ::DBus::Variant PropertyStoreTest::kStrIntPairV =
55 DBusAdaptor::StrIntPairToVariant(StrIntPair(make_pair("", ""),
56 make_pair("", 12)));
57// static
Chris Masoneb925cc82011-06-22 15:39:57 -070058const ::DBus::Variant PropertyStoreTest::kUint16V =
59 DBusAdaptor::Uint16ToVariant(0);
60// static
61const ::DBus::Variant PropertyStoreTest::kUint32V =
62 DBusAdaptor::Uint32ToVariant(0);
63
64PropertyStoreTest::PropertyStoreTest()
mukesh agrawalffa3d042011-10-06 15:26:10 -070065 : internal_error_(Error::GetName(Error::kInternalError)),
66 invalid_args_(Error::GetName(Error::kInvalidArguments)),
Chris Masone9d779932011-08-25 16:33:41 -070067 invalid_prop_(Error::GetName(Error::kInvalidProperty)),
68 path_(dir_.CreateUniqueTempDir() ? dir_.path().value() : ""),
Chris Masone2176a882011-09-14 22:29:15 -070069 manager_(control_interface(),
70 dispatcher(),
71 glib(),
Chris Masone9d779932011-08-25 16:33:41 -070072 run_path(),
73 storage_path(),
74 string()) {
Chris Masoneb925cc82011-06-22 15:39:57 -070075}
76
77PropertyStoreTest::~PropertyStoreTest() {}
78
Chris Masone9d779932011-08-25 16:33:41 -070079void PropertyStoreTest::SetUp() {
80 ASSERT_FALSE(run_path().empty());
81 ASSERT_FALSE(storage_path().empty());
82}
83
Chris Masone8a56ad62011-07-02 15:27:57 -070084TEST_P(PropertyStoreTest, TestProperty) {
85 // Ensure that an attempt to write unknown properties returns InvalidProperty.
86 PropertyStore store;
87 ::DBus::Error error;
88 EXPECT_FALSE(DBusAdaptor::DispatchOnType(&store, "", GetParam(), &error));
Chris Masone9d779932011-08-25 16:33:41 -070089 EXPECT_EQ(invalid_prop(), error.name());
Chris Masone8a56ad62011-07-02 15:27:57 -070090}
91
92INSTANTIATE_TEST_CASE_P(
93 PropertyStoreTestInstance,
94 PropertyStoreTest,
95 Values(PropertyStoreTest::kBoolV,
96 PropertyStoreTest::kByteV,
97 PropertyStoreTest::kStringV,
98 PropertyStoreTest::kInt16V,
99 PropertyStoreTest::kInt32V,
Chris Masone8a56ad62011-07-02 15:27:57 -0700100 PropertyStoreTest::kStringmapV,
Chris Masone889666b2011-07-03 12:58:50 -0700101 PropertyStoreTest::kStringsV,
102 PropertyStoreTest::kStrIntPairV,
103 PropertyStoreTest::kUint16V,
104 PropertyStoreTest::kUint32V));
Chris Masone8a56ad62011-07-02 15:27:57 -0700105
mukesh agrawalffa3d042011-10-06 15:26:10 -0700106TEST_F(PropertyStoreTest, SetStringmapsProperty) {
107 PropertyStore store;
108 ::DBus::Error error;
109 EXPECT_FALSE(DBusAdaptor::DispatchOnType(
110 &store, "", PropertyStoreTest::kStringmapsV, &error));
111 EXPECT_EQ(internal_error(), error.name());
112}
113
Chris Masoneb925cc82011-06-22 15:39:57 -0700114} // namespace shill