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/property_store_unittest.h" |
| 6 | |
| 7 | #include <map> |
| 8 | #include <string> |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 9 | #include <utility> |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 10 | #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" |
| 18 | #include "shill/manager.h" |
| 19 | #include "shill/mock_control.h" |
| 20 | #include "shill/property_store.h" |
| 21 | #include "shill/shill_event.h" |
| 22 | |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 23 | using std::make_pair; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 24 | using std::map; |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 25 | using std::string; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 26 | using std::vector; |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 27 | using ::testing::Values; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 28 | |
| 29 | namespace shill { |
| 30 | |
| 31 | // static |
| 32 | const ::DBus::Variant PropertyStoreTest::kBoolV = DBusAdaptor::BoolToVariant(0); |
| 33 | // static |
| 34 | const ::DBus::Variant PropertyStoreTest::kByteV = DBusAdaptor::ByteToVariant(0); |
| 35 | // static |
| 36 | const ::DBus::Variant PropertyStoreTest::kInt16V = |
| 37 | DBusAdaptor::Int16ToVariant(0); |
| 38 | // static |
| 39 | const ::DBus::Variant PropertyStoreTest::kInt32V = |
| 40 | DBusAdaptor::Int32ToVariant(0); |
| 41 | // static |
| 42 | const ::DBus::Variant PropertyStoreTest::kStringV = |
| 43 | DBusAdaptor::StringToVariant(""); |
| 44 | // static |
| 45 | const ::DBus::Variant PropertyStoreTest::kStringmapV = |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 46 | DBusAdaptor::StringmapToVariant(Stringmap()); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 47 | // static |
| 48 | const ::DBus::Variant PropertyStoreTest::kStringmapsV = |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 49 | DBusAdaptor::StringmapsToVariant(Stringmaps()); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 50 | // static |
| 51 | const ::DBus::Variant PropertyStoreTest::kStringsV = |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 52 | DBusAdaptor::StringsToVariant(Strings(1, "")); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 53 | // static |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 54 | const ::DBus::Variant PropertyStoreTest::kStrIntPairV = |
| 55 | DBusAdaptor::StrIntPairToVariant(StrIntPair(make_pair("", ""), |
| 56 | make_pair("", 12))); |
| 57 | // static |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 58 | const ::DBus::Variant PropertyStoreTest::kUint16V = |
| 59 | DBusAdaptor::Uint16ToVariant(0); |
| 60 | // static |
| 61 | const ::DBus::Variant PropertyStoreTest::kUint32V = |
| 62 | DBusAdaptor::Uint32ToVariant(0); |
| 63 | |
| 64 | PropertyStoreTest::PropertyStoreTest() |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame^] | 65 | : internal_error_(Error::GetName(Error::kInternalError)), |
| 66 | invalid_args_(Error::GetName(Error::kInvalidArguments)), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 67 | invalid_prop_(Error::GetName(Error::kInvalidProperty)), |
| 68 | path_(dir_.CreateUniqueTempDir() ? dir_.path().value() : ""), |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 69 | manager_(control_interface(), |
| 70 | dispatcher(), |
| 71 | glib(), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 72 | run_path(), |
| 73 | storage_path(), |
| 74 | string()) { |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | PropertyStoreTest::~PropertyStoreTest() {} |
| 78 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 79 | void PropertyStoreTest::SetUp() { |
| 80 | ASSERT_FALSE(run_path().empty()); |
| 81 | ASSERT_FALSE(storage_path().empty()); |
| 82 | } |
| 83 | |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 84 | TEST_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 Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 89 | EXPECT_EQ(invalid_prop(), error.name()); |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | INSTANTIATE_TEST_CASE_P( |
| 93 | PropertyStoreTestInstance, |
| 94 | PropertyStoreTest, |
| 95 | Values(PropertyStoreTest::kBoolV, |
| 96 | PropertyStoreTest::kByteV, |
| 97 | PropertyStoreTest::kStringV, |
| 98 | PropertyStoreTest::kInt16V, |
| 99 | PropertyStoreTest::kInt32V, |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 100 | PropertyStoreTest::kStringmapV, |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 101 | PropertyStoreTest::kStringsV, |
| 102 | PropertyStoreTest::kStrIntPairV, |
| 103 | PropertyStoreTest::kUint16V, |
| 104 | PropertyStoreTest::kUint32V)); |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 105 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame^] | 106 | TEST_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 Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 114 | } // namespace shill |