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 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 25 | using std::map; |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 26 | using std::string; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 27 | using std::vector; |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 28 | using ::testing::Values; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 29 | |
| 30 | namespace shill { |
| 31 | |
| 32 | // static |
| 33 | const ::DBus::Variant PropertyStoreTest::kBoolV = DBusAdaptor::BoolToVariant(0); |
| 34 | // static |
| 35 | const ::DBus::Variant PropertyStoreTest::kByteV = DBusAdaptor::ByteToVariant(0); |
| 36 | // static |
| 37 | const ::DBus::Variant PropertyStoreTest::kInt16V = |
| 38 | DBusAdaptor::Int16ToVariant(0); |
| 39 | // static |
| 40 | const ::DBus::Variant PropertyStoreTest::kInt32V = |
| 41 | DBusAdaptor::Int32ToVariant(0); |
| 42 | // static |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 43 | const ::DBus::Variant PropertyStoreTest::kKeyValueStoreV = |
| 44 | DBusAdaptor::KeyValueStoreToVariant(KeyValueStore()); |
| 45 | // static |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 46 | const ::DBus::Variant PropertyStoreTest::kStringV = |
| 47 | DBusAdaptor::StringToVariant(""); |
| 48 | // static |
| 49 | const ::DBus::Variant PropertyStoreTest::kStringmapV = |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 50 | DBusAdaptor::StringmapToVariant(Stringmap()); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 51 | // static |
| 52 | const ::DBus::Variant PropertyStoreTest::kStringmapsV = |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 53 | DBusAdaptor::StringmapsToVariant(Stringmaps()); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 54 | // static |
| 55 | const ::DBus::Variant PropertyStoreTest::kStringsV = |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 56 | DBusAdaptor::StringsToVariant(Strings(1, "")); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 57 | // static |
| 58 | const ::DBus::Variant PropertyStoreTest::kUint16V = |
| 59 | DBusAdaptor::Uint16ToVariant(0); |
| 60 | // static |
| 61 | const ::DBus::Variant PropertyStoreTest::kUint32V = |
| 62 | DBusAdaptor::Uint32ToVariant(0); |
Paul Stewart | e18c33b | 2012-07-10 20:48:44 -0700 | [diff] [blame] | 63 | // static |
| 64 | const ::DBus::Variant PropertyStoreTest::kUint64V = |
| 65 | DBusAdaptor::Uint64ToVariant(0); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 66 | |
| 67 | PropertyStoreTest::PropertyStoreTest() |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 68 | : internal_error_(Error::GetName(Error::kInternalError)), |
| 69 | invalid_args_(Error::GetName(Error::kInvalidArguments)), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 70 | invalid_prop_(Error::GetName(Error::kInvalidProperty)), |
| 71 | path_(dir_.CreateUniqueTempDir() ? dir_.path().value() : ""), |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 72 | manager_(control_interface(), |
| 73 | dispatcher(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 74 | metrics(), |
Chris Masone | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame] | 75 | glib(), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 76 | run_path(), |
| 77 | storage_path(), |
| 78 | string()) { |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | PropertyStoreTest::~PropertyStoreTest() {} |
| 82 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 83 | void PropertyStoreTest::SetUp() { |
| 84 | ASSERT_FALSE(run_path().empty()); |
| 85 | ASSERT_FALSE(storage_path().empty()); |
| 86 | } |
| 87 | |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 88 | TEST_P(PropertyStoreTest, TestProperty) { |
| 89 | // Ensure that an attempt to write unknown properties returns InvalidProperty. |
| 90 | PropertyStore store; |
| 91 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 92 | EXPECT_FALSE(DBusAdaptor::SetProperty(&store, "", GetParam(), &error)); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 93 | EXPECT_EQ(invalid_prop(), error.name()); |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | INSTANTIATE_TEST_CASE_P( |
| 97 | PropertyStoreTestInstance, |
| 98 | PropertyStoreTest, |
| 99 | Values(PropertyStoreTest::kBoolV, |
| 100 | PropertyStoreTest::kByteV, |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 101 | PropertyStoreTest::kInt16V, |
| 102 | PropertyStoreTest::kInt32V, |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 103 | PropertyStoreTest::kStringV, |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 104 | PropertyStoreTest::kStringmapV, |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 105 | PropertyStoreTest::kStringsV, |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 106 | PropertyStoreTest::kUint16V, |
Paul Stewart | e18c33b | 2012-07-10 20:48:44 -0700 | [diff] [blame] | 107 | PropertyStoreTest::kUint32V, |
| 108 | PropertyStoreTest::kUint64V)); |
Chris Masone | 8a56ad6 | 2011-07-02 15:27:57 -0700 | [diff] [blame] | 109 | |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 110 | template <typename T> |
| 111 | class PropertyStoreTypedTest : public PropertyStoreTest { |
| 112 | protected: |
| 113 | void RegisterProperty( |
| 114 | PropertyStore &store, const string &name, T *storage); |
| 115 | }; |
| 116 | |
| 117 | typedef ::testing::Types< |
| 118 | bool, int16, int32, KeyValueStore, string, Stringmap, Stringmaps, Strings, |
| 119 | uint8, uint16, uint32> PropertyTypes; |
| 120 | TYPED_TEST_CASE(PropertyStoreTypedTest, PropertyTypes); |
| 121 | |
| 122 | TYPED_TEST(PropertyStoreTypedTest, ClearProperty) { |
| 123 | PropertyStore store; |
| 124 | Error error; |
| 125 | TypeParam property; |
Han Shen | fc34925 | 2012-08-30 11:36:04 -0700 | [diff] [blame] | 126 | // |this| required due to two-phase lookup. |
| 127 | this->RegisterProperty(store, "some property", &property); |
mukesh agrawal | 4d260da | 2012-01-30 11:53:52 -0800 | [diff] [blame] | 128 | EXPECT_TRUE(store.ClearProperty("some property", &error)); |
| 129 | } |
| 130 | |
| 131 | template<> void PropertyStoreTypedTest<bool>::RegisterProperty( |
| 132 | PropertyStore &store, const string &name, bool *storage) { |
| 133 | store.RegisterBool(name, storage); |
| 134 | } |
| 135 | |
| 136 | template<> void PropertyStoreTypedTest<int16>::RegisterProperty( |
| 137 | PropertyStore &store, const string &name, int16 *storage) { |
| 138 | store.RegisterInt16(name, storage); |
| 139 | } |
| 140 | |
| 141 | template<> void PropertyStoreTypedTest<int32>::RegisterProperty( |
| 142 | PropertyStore &store, const string &name, int32 *storage) { |
| 143 | store.RegisterInt32(name, storage); |
| 144 | } |
| 145 | |
| 146 | template<> void PropertyStoreTypedTest<KeyValueStore>::RegisterProperty( |
| 147 | PropertyStore &store, const string &name, KeyValueStore *storage) { |
| 148 | // We use |RegisterDerivedKeyValueStore|, because there is no non-derived |
| 149 | // version. (And it's not clear that we'll need one, outside of this |
| 150 | // test.) |
| 151 | store.RegisterDerivedKeyValueStore( |
| 152 | name, KeyValueStoreAccessor( |
| 153 | new PropertyAccessor<KeyValueStore>(storage))); |
| 154 | } |
| 155 | |
| 156 | template<> void PropertyStoreTypedTest<string>::RegisterProperty( |
| 157 | PropertyStore &store, const string &name, string *storage) { |
| 158 | store.RegisterString(name, storage); |
| 159 | } |
| 160 | |
| 161 | template<> void PropertyStoreTypedTest<Stringmap>::RegisterProperty( |
| 162 | PropertyStore &store, const string &name, Stringmap *storage) { |
| 163 | store.RegisterStringmap(name, storage); |
| 164 | } |
| 165 | |
| 166 | template<> void PropertyStoreTypedTest<Stringmaps>::RegisterProperty( |
| 167 | PropertyStore &store, const string &name, Stringmaps *storage) { |
| 168 | store.RegisterStringmaps(name, storage); |
| 169 | } |
| 170 | |
| 171 | template<> void PropertyStoreTypedTest<Strings>::RegisterProperty( |
| 172 | PropertyStore &store, const string &name, Strings *storage) { |
| 173 | store.RegisterStrings(name, storage); |
| 174 | } |
| 175 | |
| 176 | template<> void PropertyStoreTypedTest<uint8>::RegisterProperty( |
| 177 | PropertyStore &store, const string &name, uint8 *storage) { |
| 178 | store.RegisterUint8(name, storage); |
| 179 | } |
| 180 | |
| 181 | template<> void PropertyStoreTypedTest<uint16>::RegisterProperty( |
| 182 | PropertyStore &store, const string &name, uint16 *storage) { |
| 183 | store.RegisterUint16(name, storage); |
| 184 | } |
| 185 | |
| 186 | template<> void PropertyStoreTypedTest<uint32>::RegisterProperty( |
| 187 | PropertyStore &store, const string &name, uint32 *storage) { |
| 188 | store.RegisterUint32(name, storage); |
| 189 | } |
| 190 | |
| 191 | TEST_F(PropertyStoreTest, ClearBoolProperty) { |
| 192 | // We exercise both possibilities for the default value here, |
| 193 | // to ensure that Clear actually resets the property based on |
| 194 | // the property's initial value (rather than the language's |
| 195 | // default value for the type). |
| 196 | static const bool kDefaults[] = {true, false}; |
| 197 | for (size_t i = 0; i < arraysize(kDefaults); ++i) { |
| 198 | PropertyStore store; |
| 199 | Error error; |
| 200 | |
| 201 | const bool default_value = kDefaults[i]; |
| 202 | bool flag = default_value; |
| 203 | store.RegisterBool("some bool", &flag); |
| 204 | |
| 205 | EXPECT_TRUE(store.ClearProperty("some bool", &error)); |
| 206 | EXPECT_EQ(default_value, flag); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | TEST_F(PropertyStoreTest, ClearPropertyNonexistent) { |
| 211 | PropertyStore store; |
| 212 | Error error; |
| 213 | |
| 214 | EXPECT_FALSE(store.ClearProperty("", &error)); |
| 215 | EXPECT_EQ(Error::kInvalidProperty, error.type()); |
| 216 | } |
| 217 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 218 | TEST_F(PropertyStoreTest, SetStringmapsProperty) { |
| 219 | PropertyStore store; |
| 220 | ::DBus::Error error; |
mukesh agrawal | 6bb9e7c | 2012-01-30 14:57:54 -0800 | [diff] [blame] | 221 | EXPECT_FALSE(DBusAdaptor::SetProperty( |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 222 | &store, "", PropertyStoreTest::kStringmapsV, &error)); |
| 223 | EXPECT_EQ(internal_error(), error.name()); |
| 224 | } |
| 225 | |
Eric Shienbrood | b23d4b9 | 2012-02-16 12:32:42 -0500 | [diff] [blame] | 226 | TEST_F(PropertyStoreTest, SetKeyValueStoreProperty) { |
| 227 | PropertyStore store; |
| 228 | ::DBus::Error error; |
| 229 | EXPECT_FALSE(DBusAdaptor::SetProperty( |
| 230 | &store, "", PropertyStoreTest::kKeyValueStoreV, &error)); |
| 231 | EXPECT_EQ(internal_error(), error.name()); |
| 232 | } |
| 233 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 234 | TEST_F(PropertyStoreTest, WriteOnlyProperties) { |
| 235 | // Test that properties registered as write-only are not returned |
| 236 | // when using Get*PropertiesIter(). |
| 237 | PropertyStore store; |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 238 | { |
| 239 | const string keys[] = {"boolp1", "boolp2"}; |
| 240 | bool values[] = {true, true}; |
| 241 | store.RegisterWriteOnlyBool(keys[0], &values[0]); |
| 242 | store.RegisterBool(keys[1], &values[1]); |
| 243 | |
| 244 | ReadablePropertyConstIterator<bool> it = store.GetBoolPropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 245 | EXPECT_FALSE(it.AtEnd()); |
| 246 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 247 | EXPECT_TRUE(values[1] == it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 248 | it.Advance(); |
| 249 | EXPECT_TRUE(it.AtEnd()); |
| 250 | } |
| 251 | { |
| 252 | const string keys[] = {"int16p1", "int16p2"}; |
| 253 | int16 values[] = {127, 128}; |
| 254 | store.RegisterWriteOnlyInt16(keys[0], &values[0]); |
| 255 | store.RegisterInt16(keys[1], &values[1]); |
| 256 | |
| 257 | ReadablePropertyConstIterator<int16> it = store.GetInt16PropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 258 | EXPECT_FALSE(it.AtEnd()); |
| 259 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 260 | EXPECT_EQ(values[1], it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 261 | it.Advance(); |
| 262 | EXPECT_TRUE(it.AtEnd()); |
| 263 | } |
| 264 | { |
| 265 | const string keys[] = {"int32p1", "int32p2"}; |
| 266 | int32 values[] = {127, 128}; |
| 267 | store.RegisterWriteOnlyInt32(keys[0], &values[0]); |
| 268 | store.RegisterInt32(keys[1], &values[1]); |
| 269 | |
| 270 | ReadablePropertyConstIterator<int32> it = store.GetInt32PropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 271 | EXPECT_FALSE(it.AtEnd()); |
| 272 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 273 | EXPECT_EQ(values[1], it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 274 | it.Advance(); |
| 275 | EXPECT_TRUE(it.AtEnd()); |
| 276 | } |
| 277 | { |
| 278 | const string keys[] = {"stringp1", "stringp2"}; |
| 279 | string values[] = {"noooo", "yesss"}; |
| 280 | store.RegisterWriteOnlyString(keys[0], &values[0]); |
| 281 | store.RegisterString(keys[1], &values[1]); |
| 282 | |
| 283 | ReadablePropertyConstIterator<string> it = store.GetStringPropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 284 | EXPECT_FALSE(it.AtEnd()); |
| 285 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 286 | EXPECT_EQ(values[1], it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 287 | it.Advance(); |
| 288 | EXPECT_TRUE(it.AtEnd()); |
| 289 | } |
| 290 | { |
| 291 | const string keys[] = {"stringmapp1", "stringmapp2"}; |
| 292 | Stringmap values[2]; |
| 293 | values[0]["noooo"] = "yesss"; |
| 294 | values[1]["yesss"] = "noooo"; |
| 295 | store.RegisterWriteOnlyStringmap(keys[0], &values[0]); |
| 296 | store.RegisterStringmap(keys[1], &values[1]); |
| 297 | |
| 298 | ReadablePropertyConstIterator<Stringmap> it = |
| 299 | store.GetStringmapPropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 300 | EXPECT_FALSE(it.AtEnd()); |
| 301 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 302 | EXPECT_TRUE(values[1] == it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 303 | it.Advance(); |
| 304 | EXPECT_TRUE(it.AtEnd()); |
| 305 | } |
| 306 | { |
| 307 | const string keys[] = {"stringmapsp1", "stringmapsp2"}; |
| 308 | Stringmaps values[2]; |
| 309 | Stringmap element; |
| 310 | element["noooo"] = "yesss"; |
| 311 | values[0].push_back(element); |
| 312 | element["yesss"] = "noooo"; |
| 313 | values[1].push_back(element); |
| 314 | |
| 315 | store.RegisterWriteOnlyStringmaps(keys[0], &values[0]); |
| 316 | store.RegisterStringmaps(keys[1], &values[1]); |
| 317 | |
| 318 | ReadablePropertyConstIterator<Stringmaps> it = |
| 319 | store.GetStringmapsPropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 320 | EXPECT_FALSE(it.AtEnd()); |
| 321 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 322 | EXPECT_TRUE(values[1] == it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 323 | it.Advance(); |
| 324 | EXPECT_TRUE(it.AtEnd()); |
| 325 | } |
| 326 | { |
| 327 | const string keys[] = {"stringsp1", "stringsp2"}; |
| 328 | Strings values[2]; |
| 329 | string element; |
| 330 | element = "noooo"; |
| 331 | values[0].push_back(element); |
| 332 | element = "yesss"; |
| 333 | values[1].push_back(element); |
| 334 | store.RegisterWriteOnlyStrings(keys[0], &values[0]); |
| 335 | store.RegisterStrings(keys[1], &values[1]); |
| 336 | |
| 337 | ReadablePropertyConstIterator<Strings> it = |
| 338 | store.GetStringsPropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 339 | EXPECT_FALSE(it.AtEnd()); |
| 340 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 341 | EXPECT_TRUE(values[1] == it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 342 | it.Advance(); |
| 343 | EXPECT_TRUE(it.AtEnd()); |
| 344 | } |
| 345 | { |
| 346 | const string keys[] = {"uint8p1", "uint8p2"}; |
| 347 | uint8 values[] = {127, 128}; |
| 348 | store.RegisterWriteOnlyUint8(keys[0], &values[0]); |
| 349 | store.RegisterUint8(keys[1], &values[1]); |
| 350 | |
| 351 | ReadablePropertyConstIterator<uint8> it = store.GetUint8PropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 352 | EXPECT_FALSE(it.AtEnd()); |
| 353 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 354 | EXPECT_EQ(values[1], it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 355 | it.Advance(); |
| 356 | EXPECT_TRUE(it.AtEnd()); |
| 357 | } |
| 358 | { |
| 359 | const string keys[] = {"uint16p", "uint16p1"}; |
| 360 | uint16 values[] = {127, 128}; |
| 361 | store.RegisterWriteOnlyUint16(keys[0], &values[0]); |
| 362 | store.RegisterUint16(keys[1], &values[1]); |
| 363 | |
| 364 | ReadablePropertyConstIterator<uint16> it = store.GetUint16PropertiesIter(); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 365 | EXPECT_FALSE(it.AtEnd()); |
| 366 | EXPECT_EQ(keys[1], it.Key()); |
Darin Petkov | 4682aa8 | 2012-05-31 16:24:11 +0200 | [diff] [blame] | 367 | EXPECT_EQ(values[1], it.value()); |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 368 | it.Advance(); |
| 369 | EXPECT_TRUE(it.AtEnd()); |
| 370 | } |
| 371 | } |
| 372 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 373 | } // namespace shill |