Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 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 | |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 12 | #include <base/basictypes.h> |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 13 | #include <dbus-c++/dbus.h> |
| 14 | #include <gtest/gtest.h> |
| 15 | #include <gmock/gmock.h> |
| 16 | |
| 17 | #include "shill/dbus_adaptor.h" |
| 18 | #include "shill/error.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 19 | #include "shill/event_dispatcher.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 20 | #include "shill/manager.h" |
| 21 | #include "shill/mock_control.h" |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 22 | #include "shill/property_accessor.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 23 | #include "shill/property_store.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 24 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 25 | using base::Bind; |
| 26 | using base::Unretained; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 27 | using std::map; |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 28 | using std::string; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 29 | using std::vector; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 30 | using ::testing::_; |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 31 | using ::testing::Values; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 32 | |
| 33 | namespace shill { |
| 34 | |
| 35 | // static |
| 36 | const ::DBus::Variant PropertyStoreTest::kBoolV = DBusAdaptor::BoolToVariant(0); |
| 37 | // static |
| 38 | const ::DBus::Variant PropertyStoreTest::kByteV = DBusAdaptor::ByteToVariant(0); |
| 39 | // static |
| 40 | const ::DBus::Variant PropertyStoreTest::kInt16V = |
| 41 | DBusAdaptor::Int16ToVariant(0); |
| 42 | // static |
| 43 | const ::DBus::Variant PropertyStoreTest::kInt32V = |
| 44 | DBusAdaptor::Int32ToVariant(0); |
| 45 | // static |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 46 | const ::DBus::Variant PropertyStoreTest::kKeyValueStoreV = |
| 47 | DBusAdaptor::KeyValueStoreToVariant(KeyValueStore()); |
| 48 | // static |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 49 | const ::DBus::Variant PropertyStoreTest::kStringV = |
| 50 | DBusAdaptor::StringToVariant(""); |
| 51 | // static |
| 52 | const ::DBus::Variant PropertyStoreTest::kStringmapV = |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 53 | DBusAdaptor::StringmapToVariant(Stringmap()); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 54 | // static |
| 55 | const ::DBus::Variant PropertyStoreTest::kStringmapsV = |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 56 | DBusAdaptor::StringmapsToVariant(Stringmaps()); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 57 | // static |
| 58 | const ::DBus::Variant PropertyStoreTest::kStringsV = |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 59 | DBusAdaptor::StringsToVariant(Strings(1, "")); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 60 | // static |
| 61 | const ::DBus::Variant PropertyStoreTest::kUint16V = |
| 62 | DBusAdaptor::Uint16ToVariant(0); |
| 63 | // static |
mukesh agrawal | e7c7e65 | 2013-06-18 17:19:39 -0700 | [diff] [blame] | 64 | const ::DBus::Variant PropertyStoreTest::kUint16sV = |
| 65 | DBusAdaptor::Uint16sToVariant(Uint16s{0}); |
| 66 | // static |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 67 | const ::DBus::Variant PropertyStoreTest::kUint32V = |
| 68 | DBusAdaptor::Uint32ToVariant(0); |
Paul Stewart | e18c33b | 2012-07-10 20:48:44 -0700 | [diff] [blame] | 69 | // static |
| 70 | const ::DBus::Variant PropertyStoreTest::kUint64V = |
| 71 | DBusAdaptor::Uint64ToVariant(0); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 72 | |
| 73 | PropertyStoreTest::PropertyStoreTest() |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 74 | : internal_error_(Error::GetName(Error::kInternalError)), |
| 75 | invalid_args_(Error::GetName(Error::kInvalidArguments)), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 76 | invalid_prop_(Error::GetName(Error::kInvalidProperty)), |
| 77 | path_(dir_.CreateUniqueTempDir() ? dir_.path().value() : ""), |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 78 | metrics_(dispatcher()), |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 79 | manager_(control_interface(), |
| 80 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 81 | metrics(), |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 82 | glib(), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 83 | run_path(), |
| 84 | storage_path(), |
| 85 | string()) { |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | PropertyStoreTest::~PropertyStoreTest() {} |
| 89 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 90 | void PropertyStoreTest::SetUp() { |
| 91 | ASSERT_FALSE(run_path().empty()); |
| 92 | ASSERT_FALSE(storage_path().empty()); |
| 93 | } |
| 94 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 95 | TEST_P(PropertyStoreTest, SetPropertyNonexistent) { |
| 96 | // Ensure that an attempt to write unknown properties returns |
| 97 | // InvalidProperty, and does not yield a PropertyChange callback. |
| 98 | PropertyStore store(Bind(&PropertyStoreTest::TestCallback, |
| 99 | Unretained(this))); |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 100 | ::DBus::Error error; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 101 | EXPECT_CALL(*this, TestCallback(_)).Times(0); |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 102 | EXPECT_FALSE(DBusAdaptor::SetProperty(&store, "", GetParam(), &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 103 | EXPECT_EQ(invalid_prop(), error.name()); |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | INSTANTIATE_TEST_CASE_P( |
| 107 | PropertyStoreTestInstance, |
| 108 | PropertyStoreTest, |
| 109 | Values(PropertyStoreTest::kBoolV, |
| 110 | PropertyStoreTest::kByteV, |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 111 | PropertyStoreTest::kInt16V, |
| 112 | PropertyStoreTest::kInt32V, |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 113 | PropertyStoreTest::kStringV, |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 114 | PropertyStoreTest::kStringmapV, |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 115 | PropertyStoreTest::kStringsV, |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 116 | PropertyStoreTest::kUint16V, |
mukesh agrawal | e7c7e65 | 2013-06-18 17:19:39 -0700 | [diff] [blame] | 117 | PropertyStoreTest::kUint16sV, |
Paul Stewart | e18c33b | 2012-07-10 20:48:44 -0700 | [diff] [blame] | 118 | PropertyStoreTest::kUint32V, |
| 119 | PropertyStoreTest::kUint64V)); |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 120 | |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 121 | template <typename T> |
| 122 | class PropertyStoreTypedTest : public PropertyStoreTest { |
| 123 | protected: |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 124 | bool SetProperty( |
| 125 | PropertyStore &store, const string &name, Error *error); |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 126 | }; |
| 127 | |
mukesh agrawal | e7c7e65 | 2013-06-18 17:19:39 -0700 | [diff] [blame] | 128 | TYPED_TEST_CASE(PropertyStoreTypedTest, PropertyStoreTest::PropertyTypes); |
| 129 | |
| 130 | TYPED_TEST(PropertyStoreTypedTest, RegisterProperty) { |
| 131 | PropertyStore store(Bind(&PropertyStoreTest::TestCallback, |
| 132 | Unretained(this))); |
| 133 | Error error; |
| 134 | TypeParam property; |
| 135 | PropertyStoreTest::RegisterProperty(&store, "some property", &property); |
| 136 | EXPECT_TRUE(store.Contains("some property")); |
| 137 | } |
| 138 | |
| 139 | TYPED_TEST(PropertyStoreTypedTest, GetProperty) { |
| 140 | PropertyStore store(Bind(&PropertyStoreTest::TestCallback, |
| 141 | Unretained(this))); |
| 142 | Error error; |
| 143 | TypeParam property; |
| 144 | PropertyStoreTest::RegisterProperty(&store, "some property", &property); |
| 145 | |
| 146 | TypeParam read_value; |
| 147 | EXPECT_CALL(*this, TestCallback(_)).Times(0); |
| 148 | EXPECT_TRUE(PropertyStoreTest::GetProperty( |
| 149 | store, "some property", &read_value, &error)); |
| 150 | EXPECT_EQ(property, read_value); |
| 151 | } |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 152 | |
| 153 | TYPED_TEST(PropertyStoreTypedTest, ClearProperty) { |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 154 | PropertyStore store(Bind(&PropertyStoreTest::TestCallback, |
| 155 | Unretained(this))); |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 156 | Error error; |
| 157 | TypeParam property; |
mukesh agrawal | e7c7e65 | 2013-06-18 17:19:39 -0700 | [diff] [blame] | 158 | PropertyStoreTest::RegisterProperty(&store, "some property", &property); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 159 | EXPECT_CALL(*this, TestCallback(_)); |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 160 | EXPECT_TRUE(store.ClearProperty("some property", &error)); |
| 161 | } |
| 162 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 163 | TYPED_TEST(PropertyStoreTypedTest, SetProperty) { |
| 164 | PropertyStore store(Bind(&PropertyStoreTest::TestCallback, |
| 165 | Unretained(this))); |
| 166 | Error error; |
| 167 | TypeParam property = TypeParam(); // value-initialize primitives |
mukesh agrawal | e7c7e65 | 2013-06-18 17:19:39 -0700 | [diff] [blame] | 168 | PropertyStoreTest::RegisterProperty(&store, "some property", &property); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 169 | |
| 170 | // Change the value from the default (initialized above). Should |
| 171 | // generate a change callback. The second SetProperty, however, |
| 172 | // should not. Hence, we should get exactly one callback. |
| 173 | EXPECT_CALL(*this, TestCallback(_)).Times(1); |
| 174 | EXPECT_TRUE(this->SetProperty(store, "some property", &error)); |
| 175 | EXPECT_FALSE(this->SetProperty(store, "some property", &error)); |
| 176 | } |
| 177 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 178 | template<> bool PropertyStoreTypedTest<bool>::SetProperty( |
| 179 | PropertyStore &store, const string &name, Error *error) { |
| 180 | bool new_value = true; |
| 181 | return store.SetBoolProperty(name, new_value, error); |
| 182 | } |
| 183 | |
| 184 | template<> bool PropertyStoreTypedTest<int16>::SetProperty( |
| 185 | PropertyStore &store, const string &name, Error *error) { |
| 186 | int16 new_value = 1; |
| 187 | return store.SetInt16Property(name, new_value, error); |
| 188 | } |
| 189 | |
| 190 | template<> bool PropertyStoreTypedTest<int32>::SetProperty( |
| 191 | PropertyStore &store, const string &name, Error *error) { |
| 192 | int32 new_value = 1; |
| 193 | return store.SetInt32Property(name, new_value, error); |
| 194 | } |
| 195 | |
| 196 | template<> bool PropertyStoreTypedTest<string>::SetProperty( |
| 197 | PropertyStore &store, const string &name, Error *error) { |
| 198 | string new_value = "new value"; |
| 199 | return store.SetStringProperty(name, new_value, error); |
| 200 | } |
| 201 | |
| 202 | template<> bool PropertyStoreTypedTest<Stringmap>::SetProperty( |
| 203 | PropertyStore &store, const string &name, Error *error) { |
| 204 | Stringmap new_value; |
| 205 | new_value["new key"] = "new value"; |
| 206 | return store.SetStringmapProperty(name, new_value, error); |
| 207 | } |
| 208 | |
| 209 | template<> bool PropertyStoreTypedTest<Stringmaps>::SetProperty( |
| 210 | PropertyStore &store, const string &name, Error *error) { |
| 211 | Stringmaps new_value(1); |
| 212 | new_value[0]["new key"] = "new value"; |
| 213 | return store.SetStringmapsProperty(name, new_value, error); |
| 214 | } |
| 215 | |
| 216 | template<> bool PropertyStoreTypedTest<Strings>::SetProperty( |
| 217 | PropertyStore &store, const string &name, Error *error) { |
| 218 | Strings new_value(1); |
| 219 | new_value[0] = "new value"; |
| 220 | return store.SetStringsProperty(name, new_value, error); |
| 221 | } |
| 222 | |
| 223 | template<> bool PropertyStoreTypedTest<uint8>::SetProperty( |
| 224 | PropertyStore &store, const string &name, Error *error) { |
| 225 | uint8 new_value = 1; |
| 226 | return store.SetUint8Property(name, new_value, error); |
| 227 | } |
| 228 | |
| 229 | template<> bool PropertyStoreTypedTest<uint16>::SetProperty( |
| 230 | PropertyStore &store, const string &name, Error *error) { |
| 231 | uint16 new_value = 1; |
| 232 | return store.SetUint16Property(name, new_value, error); |
| 233 | } |
| 234 | |
mukesh agrawal | e7c7e65 | 2013-06-18 17:19:39 -0700 | [diff] [blame] | 235 | template<> bool PropertyStoreTypedTest<Uint16s>::SetProperty( |
| 236 | PropertyStore &store, const string &name, Error *error) { |
| 237 | Uint16s new_value{1}; |
| 238 | return store.SetUint16sProperty(name, new_value, error); |
| 239 | } |
| 240 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 241 | template<> bool PropertyStoreTypedTest<uint32>::SetProperty( |
| 242 | PropertyStore &store, const string &name, Error *error) { |
| 243 | uint32 new_value = 1; |
| 244 | return store.SetUint32Property(name, new_value, error); |
| 245 | } |
| 246 | |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 247 | TEST_F(PropertyStoreTest, ClearBoolProperty) { |
| 248 | // We exercise both possibilities for the default value here, |
| 249 | // to ensure that Clear actually resets the property based on |
| 250 | // the property's initial value (rather than the language's |
| 251 | // default value for the type). |
| 252 | static const bool kDefaults[] = {true, false}; |
| 253 | for (size_t i = 0; i < arraysize(kDefaults); ++i) { |
| 254 | PropertyStore store; |
| 255 | Error error; |
| 256 | |
| 257 | const bool default_value = kDefaults[i]; |
| 258 | bool flag = default_value; |
| 259 | store.RegisterBool("some bool", &flag); |
| 260 | |
| 261 | EXPECT_TRUE(store.ClearProperty("some bool", &error)); |
| 262 | EXPECT_EQ(default_value, flag); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | TEST_F(PropertyStoreTest, ClearPropertyNonexistent) { |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 267 | PropertyStore store(Bind(&PropertyStoreTest::TestCallback, |
| 268 | Unretained(this))); |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 269 | Error error; |
| 270 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 271 | EXPECT_CALL(*this, TestCallback(_)).Times(0); |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 272 | EXPECT_FALSE(store.ClearProperty("", &error)); |
| 273 | EXPECT_EQ(Error::kInvalidProperty, error.type()); |
| 274 | } |
| 275 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 276 | // Separate from SetPropertyNonexistent, because |
| 277 | // DBusAdaptor::SetProperty doesn't support Stringmaps. |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 278 | TEST_F(PropertyStoreTest, SetStringmapsProperty) { |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 279 | PropertyStore store(Bind(&PropertyStoreTest::TestCallback, |
| 280 | Unretained(this))); |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 281 | ::DBus::Error error; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 282 | EXPECT_CALL(*this, TestCallback(_)).Times(0); |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 283 | EXPECT_FALSE(DBusAdaptor::SetProperty( |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 284 | &store, "", PropertyStoreTest::kStringmapsV, &error)); |
| 285 | EXPECT_EQ(internal_error(), error.name()); |
| 286 | } |
| 287 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 288 | // Separate from SetPropertyNonexistent, because |
| 289 | // DBusAdaptor::SetProperty doesn't support KeyValueStore. |
Eric Shienbrood | b23d4b9 | 2012-02-16 12:32:42 -0500 | [diff] [blame] | 290 | TEST_F(PropertyStoreTest, SetKeyValueStoreProperty) { |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 291 | PropertyStore store(Bind(&PropertyStoreTest::TestCallback, |
| 292 | Unretained(this))); |
Eric Shienbrood | b23d4b9 | 2012-02-16 12:32:42 -0500 | [diff] [blame] | 293 | ::DBus::Error error; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 294 | EXPECT_CALL(*this, TestCallback(_)).Times(0); |
Eric Shienbrood | b23d4b9 | 2012-02-16 12:32:42 -0500 | [diff] [blame] | 295 | EXPECT_FALSE(DBusAdaptor::SetProperty( |
| 296 | &store, "", PropertyStoreTest::kKeyValueStoreV, &error)); |
| 297 | EXPECT_EQ(internal_error(), error.name()); |
| 298 | } |
| 299 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 300 | TEST_F(PropertyStoreTest, WriteOnlyProperties) { |
| 301 | // Test that properties registered as write-only are not returned |
| 302 | // when using Get*PropertiesIter(). |
| 303 | PropertyStore store; |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 304 | { |
| 305 | const string keys[] = {"boolp1", "boolp2"}; |
| 306 | bool values[] = {true, true}; |
| 307 | store.RegisterWriteOnlyBool(keys[0], &values[0]); |
| 308 | store.RegisterBool(keys[1], &values[1]); |
| 309 | |
| 310 | ReadablePropertyConstIterator<bool> it = store.GetBoolPropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 311 | EXPECT_FALSE(it.AtEnd()); |
| 312 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 313 | EXPECT_TRUE(values[1] == it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 314 | it.Advance(); |
| 315 | EXPECT_TRUE(it.AtEnd()); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 316 | |
| 317 | Error errors[2]; |
| 318 | EXPECT_FALSE(store.GetBoolProperty(keys[0], NULL, &errors[0])); |
| 319 | EXPECT_EQ(Error::kPermissionDenied, errors[0].type()); |
| 320 | bool test_value; |
| 321 | EXPECT_TRUE(store.GetBoolProperty(keys[1], &test_value, &errors[1])); |
| 322 | EXPECT_TRUE(errors[1].IsSuccess()); |
| 323 | EXPECT_EQ(values[1], test_value); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 324 | } |
| 325 | { |
| 326 | const string keys[] = {"int16p1", "int16p2"}; |
| 327 | int16 values[] = {127, 128}; |
| 328 | store.RegisterWriteOnlyInt16(keys[0], &values[0]); |
| 329 | store.RegisterInt16(keys[1], &values[1]); |
| 330 | |
| 331 | ReadablePropertyConstIterator<int16> it = store.GetInt16PropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 332 | EXPECT_FALSE(it.AtEnd()); |
| 333 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 334 | EXPECT_EQ(values[1], it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 335 | it.Advance(); |
| 336 | EXPECT_TRUE(it.AtEnd()); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 337 | |
| 338 | Error errors[2]; |
| 339 | EXPECT_FALSE(store.GetInt16Property(keys[0], NULL, &errors[0])); |
| 340 | EXPECT_EQ(Error::kPermissionDenied, errors[0].type()); |
| 341 | int16 test_value; |
| 342 | EXPECT_TRUE(store.GetInt16Property(keys[1], &test_value, &errors[1])); |
| 343 | EXPECT_TRUE(errors[1].IsSuccess()); |
| 344 | EXPECT_EQ(values[1], test_value); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 345 | } |
| 346 | { |
| 347 | const string keys[] = {"int32p1", "int32p2"}; |
| 348 | int32 values[] = {127, 128}; |
| 349 | store.RegisterWriteOnlyInt32(keys[0], &values[0]); |
| 350 | store.RegisterInt32(keys[1], &values[1]); |
| 351 | |
| 352 | ReadablePropertyConstIterator<int32> it = store.GetInt32PropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 353 | EXPECT_FALSE(it.AtEnd()); |
| 354 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 355 | EXPECT_EQ(values[1], it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 356 | it.Advance(); |
| 357 | EXPECT_TRUE(it.AtEnd()); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 358 | |
| 359 | Error errors[2]; |
| 360 | EXPECT_FALSE(store.GetInt32Property(keys[0], NULL, &errors[0])); |
| 361 | EXPECT_EQ(Error::kPermissionDenied, errors[0].type()); |
| 362 | int32 test_value; |
| 363 | EXPECT_TRUE(store.GetInt32Property(keys[1], &test_value, &errors[1])); |
| 364 | EXPECT_TRUE(errors[1].IsSuccess()); |
| 365 | EXPECT_EQ(values[1], test_value); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 366 | } |
| 367 | { |
| 368 | const string keys[] = {"stringp1", "stringp2"}; |
| 369 | string values[] = {"noooo", "yesss"}; |
| 370 | store.RegisterWriteOnlyString(keys[0], &values[0]); |
| 371 | store.RegisterString(keys[1], &values[1]); |
| 372 | |
| 373 | ReadablePropertyConstIterator<string> it = store.GetStringPropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 374 | EXPECT_FALSE(it.AtEnd()); |
| 375 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 376 | EXPECT_EQ(values[1], it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 377 | it.Advance(); |
| 378 | EXPECT_TRUE(it.AtEnd()); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 379 | |
| 380 | Error errors[2]; |
| 381 | EXPECT_FALSE(store.GetStringProperty(keys[0], NULL, &errors[0])); |
| 382 | EXPECT_EQ(Error::kPermissionDenied, errors[0].type()); |
| 383 | string test_value; |
| 384 | EXPECT_TRUE(store.GetStringProperty(keys[1], &test_value, &errors[1])); |
| 385 | EXPECT_TRUE(errors[1].IsSuccess()); |
| 386 | EXPECT_EQ(values[1], test_value); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 387 | } |
| 388 | { |
| 389 | const string keys[] = {"stringmapp1", "stringmapp2"}; |
| 390 | Stringmap values[2]; |
| 391 | values[0]["noooo"] = "yesss"; |
| 392 | values[1]["yesss"] = "noooo"; |
| 393 | store.RegisterWriteOnlyStringmap(keys[0], &values[0]); |
| 394 | store.RegisterStringmap(keys[1], &values[1]); |
| 395 | |
| 396 | ReadablePropertyConstIterator<Stringmap> it = |
| 397 | store.GetStringmapPropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 398 | EXPECT_FALSE(it.AtEnd()); |
| 399 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 400 | EXPECT_TRUE(values[1] == it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 401 | it.Advance(); |
| 402 | EXPECT_TRUE(it.AtEnd()); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 403 | |
| 404 | Error errors[2]; |
| 405 | EXPECT_FALSE(store.GetStringmapProperty(keys[0], NULL, &errors[0])); |
| 406 | EXPECT_EQ(Error::kPermissionDenied, errors[0].type()); |
| 407 | Stringmap test_value; |
| 408 | EXPECT_TRUE(store.GetStringmapProperty(keys[1], &test_value, &errors[1])); |
| 409 | EXPECT_TRUE(errors[1].IsSuccess()); |
| 410 | EXPECT_TRUE(values[1] == test_value); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 411 | } |
| 412 | { |
| 413 | const string keys[] = {"stringmapsp1", "stringmapsp2"}; |
| 414 | Stringmaps values[2]; |
| 415 | Stringmap element; |
| 416 | element["noooo"] = "yesss"; |
| 417 | values[0].push_back(element); |
| 418 | element["yesss"] = "noooo"; |
| 419 | values[1].push_back(element); |
| 420 | |
| 421 | store.RegisterWriteOnlyStringmaps(keys[0], &values[0]); |
| 422 | store.RegisterStringmaps(keys[1], &values[1]); |
| 423 | |
| 424 | ReadablePropertyConstIterator<Stringmaps> it = |
| 425 | store.GetStringmapsPropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 426 | EXPECT_FALSE(it.AtEnd()); |
| 427 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 428 | EXPECT_TRUE(values[1] == it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 429 | it.Advance(); |
| 430 | EXPECT_TRUE(it.AtEnd()); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 431 | |
| 432 | Error errors[2]; |
| 433 | EXPECT_FALSE(store.GetStringmapsProperty(keys[0], NULL, &errors[0])); |
| 434 | EXPECT_EQ(Error::kPermissionDenied, errors[0].type()); |
| 435 | Stringmaps test_value; |
| 436 | EXPECT_TRUE(store.GetStringmapsProperty(keys[1], &test_value, &errors[1])); |
| 437 | EXPECT_TRUE(errors[1].IsSuccess()); |
| 438 | EXPECT_TRUE(values[1] == test_value); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 439 | } |
| 440 | { |
| 441 | const string keys[] = {"stringsp1", "stringsp2"}; |
| 442 | Strings values[2]; |
| 443 | string element; |
| 444 | element = "noooo"; |
| 445 | values[0].push_back(element); |
| 446 | element = "yesss"; |
| 447 | values[1].push_back(element); |
| 448 | store.RegisterWriteOnlyStrings(keys[0], &values[0]); |
| 449 | store.RegisterStrings(keys[1], &values[1]); |
| 450 | |
| 451 | ReadablePropertyConstIterator<Strings> it = |
| 452 | store.GetStringsPropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 453 | EXPECT_FALSE(it.AtEnd()); |
| 454 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 455 | EXPECT_TRUE(values[1] == it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 456 | it.Advance(); |
| 457 | EXPECT_TRUE(it.AtEnd()); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 458 | |
| 459 | Error errors[2]; |
| 460 | EXPECT_FALSE(store.GetStringsProperty(keys[0], NULL, &errors[0])); |
| 461 | EXPECT_EQ(Error::kPermissionDenied, errors[0].type()); |
| 462 | Strings test_value; |
| 463 | EXPECT_TRUE(store.GetStringsProperty(keys[1], &test_value, &errors[1])); |
| 464 | EXPECT_TRUE(errors[1].IsSuccess()); |
| 465 | EXPECT_TRUE(values[1] == test_value); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 466 | } |
| 467 | { |
| 468 | const string keys[] = {"uint8p1", "uint8p2"}; |
| 469 | uint8 values[] = {127, 128}; |
| 470 | store.RegisterWriteOnlyUint8(keys[0], &values[0]); |
| 471 | store.RegisterUint8(keys[1], &values[1]); |
| 472 | |
| 473 | ReadablePropertyConstIterator<uint8> it = store.GetUint8PropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 474 | EXPECT_FALSE(it.AtEnd()); |
| 475 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 476 | EXPECT_EQ(values[1], it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 477 | it.Advance(); |
| 478 | EXPECT_TRUE(it.AtEnd()); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 479 | |
| 480 | Error errors[2]; |
| 481 | EXPECT_FALSE(store.GetUint8Property(keys[0], NULL, &errors[0])); |
| 482 | EXPECT_EQ(Error::kPermissionDenied, errors[0].type()); |
| 483 | uint8 test_value; |
| 484 | EXPECT_TRUE(store.GetUint8Property(keys[1], &test_value, &errors[1])); |
| 485 | EXPECT_TRUE(errors[1].IsSuccess()); |
| 486 | EXPECT_EQ(values[1], test_value); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 487 | } |
| 488 | { |
| 489 | const string keys[] = {"uint16p", "uint16p1"}; |
| 490 | uint16 values[] = {127, 128}; |
| 491 | store.RegisterWriteOnlyUint16(keys[0], &values[0]); |
| 492 | store.RegisterUint16(keys[1], &values[1]); |
| 493 | |
| 494 | ReadablePropertyConstIterator<uint16> it = store.GetUint16PropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 495 | EXPECT_FALSE(it.AtEnd()); |
| 496 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 497 | EXPECT_EQ(values[1], it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 498 | it.Advance(); |
| 499 | EXPECT_TRUE(it.AtEnd()); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 500 | |
| 501 | Error errors[2]; |
| 502 | EXPECT_FALSE(store.GetUint16Property(keys[0], NULL, &errors[0])); |
| 503 | EXPECT_EQ(Error::kPermissionDenied, errors[0].type()); |
| 504 | uint16 test_value; |
| 505 | EXPECT_TRUE(store.GetUint16Property(keys[1], &test_value, &errors[1])); |
| 506 | EXPECT_TRUE(errors[1].IsSuccess()); |
| 507 | EXPECT_EQ(values[1], test_value); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 511 | } // namespace shill |