blob: 2030c9e0698b26fb927c417a37ea476aca81bbca [file] [log] [blame]
Thieu Le3426c8f2012-01-11 17:35:11 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Chris Masoneb925cc82011-06-22 15:39:57 -07002// 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
mukesh agrawal4d260da2012-01-30 11:53:52 -080012#include <base/basictypes.h>
Chris Masoneb925cc82011-06-22 15:39:57 -070013#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 Stewart26b327e2011-10-19 11:38:09 -070019#include "shill/event_dispatcher.h"
Chris Masoneb925cc82011-06-22 15:39:57 -070020#include "shill/manager.h"
21#include "shill/mock_control.h"
mukesh agrawal4d260da2012-01-30 11:53:52 -080022#include "shill/property_accessor.h"
Chris Masoneb925cc82011-06-22 15:39:57 -070023#include "shill/property_store.h"
Chris Masoneb925cc82011-06-22 15:39:57 -070024
mukesh agrawalbebf1b82013-04-23 15:06:33 -070025using base::Bind;
26using base::Unretained;
Chris Masoneb925cc82011-06-22 15:39:57 -070027using std::map;
Chris Masone889666b2011-07-03 12:58:50 -070028using std::string;
Chris Masoneb925cc82011-06-22 15:39:57 -070029using std::vector;
mukesh agrawalbebf1b82013-04-23 15:06:33 -070030using ::testing::_;
Chris Masone8a56ad62011-07-02 15:27:57 -070031using ::testing::Values;
Chris Masoneb925cc82011-06-22 15:39:57 -070032
33namespace shill {
34
35// static
36const ::DBus::Variant PropertyStoreTest::kBoolV = DBusAdaptor::BoolToVariant(0);
37// static
38const ::DBus::Variant PropertyStoreTest::kByteV = DBusAdaptor::ByteToVariant(0);
39// static
40const ::DBus::Variant PropertyStoreTest::kInt16V =
41 DBusAdaptor::Int16ToVariant(0);
42// static
43const ::DBus::Variant PropertyStoreTest::kInt32V =
44 DBusAdaptor::Int32ToVariant(0);
45// static
Darin Petkov63138a92012-02-06 14:09:15 +010046const ::DBus::Variant PropertyStoreTest::kKeyValueStoreV =
47 DBusAdaptor::KeyValueStoreToVariant(KeyValueStore());
48// static
Chris Masoneb925cc82011-06-22 15:39:57 -070049const ::DBus::Variant PropertyStoreTest::kStringV =
50 DBusAdaptor::StringToVariant("");
51// static
52const ::DBus::Variant PropertyStoreTest::kStringmapV =
Chris Masonea8a2c252011-06-27 22:16:30 -070053 DBusAdaptor::StringmapToVariant(Stringmap());
Chris Masoneb925cc82011-06-22 15:39:57 -070054// static
55const ::DBus::Variant PropertyStoreTest::kStringmapsV =
Chris Masone889666b2011-07-03 12:58:50 -070056 DBusAdaptor::StringmapsToVariant(Stringmaps());
Chris Masoneb925cc82011-06-22 15:39:57 -070057// static
58const ::DBus::Variant PropertyStoreTest::kStringsV =
Chris Masonea8a2c252011-06-27 22:16:30 -070059 DBusAdaptor::StringsToVariant(Strings(1, ""));
Chris Masoneb925cc82011-06-22 15:39:57 -070060// static
61const ::DBus::Variant PropertyStoreTest::kUint16V =
62 DBusAdaptor::Uint16ToVariant(0);
63// static
64const ::DBus::Variant PropertyStoreTest::kUint32V =
65 DBusAdaptor::Uint32ToVariant(0);
Paul Stewarte18c33b2012-07-10 20:48:44 -070066// static
67const ::DBus::Variant PropertyStoreTest::kUint64V =
68 DBusAdaptor::Uint64ToVariant(0);
Chris Masoneb925cc82011-06-22 15:39:57 -070069
70PropertyStoreTest::PropertyStoreTest()
mukesh agrawalffa3d042011-10-06 15:26:10 -070071 : internal_error_(Error::GetName(Error::kInternalError)),
72 invalid_args_(Error::GetName(Error::kInvalidArguments)),
Chris Masone9d779932011-08-25 16:33:41 -070073 invalid_prop_(Error::GetName(Error::kInvalidProperty)),
74 path_(dir_.CreateUniqueTempDir() ? dir_.path().value() : ""),
Thieu Le6c1e3bb2013-02-06 15:20:35 -080075 metrics_(dispatcher()),
Chris Masone2176a882011-09-14 22:29:15 -070076 manager_(control_interface(),
77 dispatcher(),
Thieu Le3426c8f2012-01-11 17:35:11 -080078 metrics(),
Chris Masone2176a882011-09-14 22:29:15 -070079 glib(),
Chris Masone9d779932011-08-25 16:33:41 -070080 run_path(),
81 storage_path(),
82 string()) {
Chris Masoneb925cc82011-06-22 15:39:57 -070083}
84
85PropertyStoreTest::~PropertyStoreTest() {}
86
Chris Masone9d779932011-08-25 16:33:41 -070087void PropertyStoreTest::SetUp() {
88 ASSERT_FALSE(run_path().empty());
89 ASSERT_FALSE(storage_path().empty());
90}
91
mukesh agrawalbebf1b82013-04-23 15:06:33 -070092TEST_P(PropertyStoreTest, SetPropertyNonexistent) {
93 // Ensure that an attempt to write unknown properties returns
94 // InvalidProperty, and does not yield a PropertyChange callback.
95 PropertyStore store(Bind(&PropertyStoreTest::TestCallback,
96 Unretained(this)));
Chris Masone8a56ad62011-07-02 15:27:57 -070097 ::DBus::Error error;
mukesh agrawalbebf1b82013-04-23 15:06:33 -070098 EXPECT_CALL(*this, TestCallback(_)).Times(0);
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -080099 EXPECT_FALSE(DBusAdaptor::SetProperty(&store, "", GetParam(), &error));
Chris Masone9d779932011-08-25 16:33:41 -0700100 EXPECT_EQ(invalid_prop(), error.name());
Chris Masone8a56ad62011-07-02 15:27:57 -0700101}
102
103INSTANTIATE_TEST_CASE_P(
104 PropertyStoreTestInstance,
105 PropertyStoreTest,
106 Values(PropertyStoreTest::kBoolV,
107 PropertyStoreTest::kByteV,
Chris Masone8a56ad62011-07-02 15:27:57 -0700108 PropertyStoreTest::kInt16V,
109 PropertyStoreTest::kInt32V,
Darin Petkov63138a92012-02-06 14:09:15 +0100110 PropertyStoreTest::kStringV,
Chris Masone8a56ad62011-07-02 15:27:57 -0700111 PropertyStoreTest::kStringmapV,
Chris Masone889666b2011-07-03 12:58:50 -0700112 PropertyStoreTest::kStringsV,
Chris Masone889666b2011-07-03 12:58:50 -0700113 PropertyStoreTest::kUint16V,
Paul Stewarte18c33b2012-07-10 20:48:44 -0700114 PropertyStoreTest::kUint32V,
115 PropertyStoreTest::kUint64V));
Chris Masone8a56ad62011-07-02 15:27:57 -0700116
mukesh agrawal4d260da2012-01-30 11:53:52 -0800117template <typename T>
118class PropertyStoreTypedTest : public PropertyStoreTest {
119 protected:
120 void RegisterProperty(
121 PropertyStore &store, const string &name, T *storage);
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700122 bool SetProperty(
123 PropertyStore &store, const string &name, Error *error);
mukesh agrawal4d260da2012-01-30 11:53:52 -0800124};
125
126typedef ::testing::Types<
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700127 bool, int16, int32, string, Stringmap, Stringmaps, Strings, uint8, uint16,
128 uint32> PropertyTypes;
mukesh agrawal4d260da2012-01-30 11:53:52 -0800129TYPED_TEST_CASE(PropertyStoreTypedTest, PropertyTypes);
130
131TYPED_TEST(PropertyStoreTypedTest, ClearProperty) {
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700132 PropertyStore store(Bind(&PropertyStoreTest::TestCallback,
133 Unretained(this)));
mukesh agrawal4d260da2012-01-30 11:53:52 -0800134 Error error;
135 TypeParam property;
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700136
Han Shenfc349252012-08-30 11:36:04 -0700137 // |this| required due to two-phase lookup.
138 this->RegisterProperty(store, "some property", &property);
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700139 EXPECT_CALL(*this, TestCallback(_));
mukesh agrawal4d260da2012-01-30 11:53:52 -0800140 EXPECT_TRUE(store.ClearProperty("some property", &error));
141}
142
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700143TYPED_TEST(PropertyStoreTypedTest, SetProperty) {
144 PropertyStore store(Bind(&PropertyStoreTest::TestCallback,
145 Unretained(this)));
146 Error error;
147 TypeParam property = TypeParam(); // value-initialize primitives
148
149 // |this| required due to two-phase lookup.
150 this->RegisterProperty(store, "some property", &property);
151
152 // Change the value from the default (initialized above). Should
153 // generate a change callback. The second SetProperty, however,
154 // should not. Hence, we should get exactly one callback.
155 EXPECT_CALL(*this, TestCallback(_)).Times(1);
156 EXPECT_TRUE(this->SetProperty(store, "some property", &error));
157 EXPECT_FALSE(this->SetProperty(store, "some property", &error));
158}
159
mukesh agrawal4d260da2012-01-30 11:53:52 -0800160template<> void PropertyStoreTypedTest<bool>::RegisterProperty(
161 PropertyStore &store, const string &name, bool *storage) {
162 store.RegisterBool(name, storage);
163}
164
165template<> void PropertyStoreTypedTest<int16>::RegisterProperty(
166 PropertyStore &store, const string &name, int16 *storage) {
167 store.RegisterInt16(name, storage);
168}
169
170template<> void PropertyStoreTypedTest<int32>::RegisterProperty(
171 PropertyStore &store, const string &name, int32 *storage) {
172 store.RegisterInt32(name, storage);
173}
174
mukesh agrawal4d260da2012-01-30 11:53:52 -0800175template<> void PropertyStoreTypedTest<string>::RegisterProperty(
176 PropertyStore &store, const string &name, string *storage) {
177 store.RegisterString(name, storage);
178}
179
180template<> void PropertyStoreTypedTest<Stringmap>::RegisterProperty(
181 PropertyStore &store, const string &name, Stringmap *storage) {
182 store.RegisterStringmap(name, storage);
183}
184
185template<> void PropertyStoreTypedTest<Stringmaps>::RegisterProperty(
186 PropertyStore &store, const string &name, Stringmaps *storage) {
187 store.RegisterStringmaps(name, storage);
188}
189
190template<> void PropertyStoreTypedTest<Strings>::RegisterProperty(
191 PropertyStore &store, const string &name, Strings *storage) {
192 store.RegisterStrings(name, storage);
193}
194
195template<> void PropertyStoreTypedTest<uint8>::RegisterProperty(
196 PropertyStore &store, const string &name, uint8 *storage) {
197 store.RegisterUint8(name, storage);
198}
199
200template<> void PropertyStoreTypedTest<uint16>::RegisterProperty(
201 PropertyStore &store, const string &name, uint16 *storage) {
202 store.RegisterUint16(name, storage);
203}
204
205template<> void PropertyStoreTypedTest<uint32>::RegisterProperty(
206 PropertyStore &store, const string &name, uint32 *storage) {
207 store.RegisterUint32(name, storage);
208}
209
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700210template<> bool PropertyStoreTypedTest<bool>::SetProperty(
211 PropertyStore &store, const string &name, Error *error) {
212 bool new_value = true;
213 return store.SetBoolProperty(name, new_value, error);
214}
215
216template<> bool PropertyStoreTypedTest<int16>::SetProperty(
217 PropertyStore &store, const string &name, Error *error) {
218 int16 new_value = 1;
219 return store.SetInt16Property(name, new_value, error);
220}
221
222template<> bool PropertyStoreTypedTest<int32>::SetProperty(
223 PropertyStore &store, const string &name, Error *error) {
224 int32 new_value = 1;
225 return store.SetInt32Property(name, new_value, error);
226}
227
228template<> bool PropertyStoreTypedTest<string>::SetProperty(
229 PropertyStore &store, const string &name, Error *error) {
230 string new_value = "new value";
231 return store.SetStringProperty(name, new_value, error);
232}
233
234template<> bool PropertyStoreTypedTest<Stringmap>::SetProperty(
235 PropertyStore &store, const string &name, Error *error) {
236 Stringmap new_value;
237 new_value["new key"] = "new value";
238 return store.SetStringmapProperty(name, new_value, error);
239}
240
241template<> bool PropertyStoreTypedTest<Stringmaps>::SetProperty(
242 PropertyStore &store, const string &name, Error *error) {
243 Stringmaps new_value(1);
244 new_value[0]["new key"] = "new value";
245 return store.SetStringmapsProperty(name, new_value, error);
246}
247
248template<> bool PropertyStoreTypedTest<Strings>::SetProperty(
249 PropertyStore &store, const string &name, Error *error) {
250 Strings new_value(1);
251 new_value[0] = "new value";
252 return store.SetStringsProperty(name, new_value, error);
253}
254
255template<> bool PropertyStoreTypedTest<uint8>::SetProperty(
256 PropertyStore &store, const string &name, Error *error) {
257 uint8 new_value = 1;
258 return store.SetUint8Property(name, new_value, error);
259}
260
261template<> bool PropertyStoreTypedTest<uint16>::SetProperty(
262 PropertyStore &store, const string &name, Error *error) {
263 uint16 new_value = 1;
264 return store.SetUint16Property(name, new_value, error);
265}
266
267template<> bool PropertyStoreTypedTest<uint32>::SetProperty(
268 PropertyStore &store, const string &name, Error *error) {
269 uint32 new_value = 1;
270 return store.SetUint32Property(name, new_value, error);
271}
272
mukesh agrawal4d260da2012-01-30 11:53:52 -0800273TEST_F(PropertyStoreTest, ClearBoolProperty) {
274 // We exercise both possibilities for the default value here,
275 // to ensure that Clear actually resets the property based on
276 // the property's initial value (rather than the language's
277 // default value for the type).
278 static const bool kDefaults[] = {true, false};
279 for (size_t i = 0; i < arraysize(kDefaults); ++i) {
280 PropertyStore store;
281 Error error;
282
283 const bool default_value = kDefaults[i];
284 bool flag = default_value;
285 store.RegisterBool("some bool", &flag);
286
287 EXPECT_TRUE(store.ClearProperty("some bool", &error));
288 EXPECT_EQ(default_value, flag);
289 }
290}
291
292TEST_F(PropertyStoreTest, ClearPropertyNonexistent) {
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700293 PropertyStore store(Bind(&PropertyStoreTest::TestCallback,
294 Unretained(this)));
mukesh agrawal4d260da2012-01-30 11:53:52 -0800295 Error error;
296
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700297 EXPECT_CALL(*this, TestCallback(_)).Times(0);
mukesh agrawal4d260da2012-01-30 11:53:52 -0800298 EXPECT_FALSE(store.ClearProperty("", &error));
299 EXPECT_EQ(Error::kInvalidProperty, error.type());
300}
301
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700302// Separate from SetPropertyNonexistent, because
303// DBusAdaptor::SetProperty doesn't support Stringmaps.
mukesh agrawalffa3d042011-10-06 15:26:10 -0700304TEST_F(PropertyStoreTest, SetStringmapsProperty) {
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700305 PropertyStore store(Bind(&PropertyStoreTest::TestCallback,
306 Unretained(this)));
mukesh agrawalffa3d042011-10-06 15:26:10 -0700307 ::DBus::Error error;
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700308 EXPECT_CALL(*this, TestCallback(_)).Times(0);
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -0800309 EXPECT_FALSE(DBusAdaptor::SetProperty(
mukesh agrawalffa3d042011-10-06 15:26:10 -0700310 &store, "", PropertyStoreTest::kStringmapsV, &error));
311 EXPECT_EQ(internal_error(), error.name());
312}
313
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700314// Separate from SetPropertyNonexistent, because
315// DBusAdaptor::SetProperty doesn't support KeyValueStore.
Eric Shienbroodb23d4b92012-02-16 12:32:42 -0500316TEST_F(PropertyStoreTest, SetKeyValueStoreProperty) {
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700317 PropertyStore store(Bind(&PropertyStoreTest::TestCallback,
318 Unretained(this)));
Eric Shienbroodb23d4b92012-02-16 12:32:42 -0500319 ::DBus::Error error;
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700320 EXPECT_CALL(*this, TestCallback(_)).Times(0);
Eric Shienbroodb23d4b92012-02-16 12:32:42 -0500321 EXPECT_FALSE(DBusAdaptor::SetProperty(
322 &store, "", PropertyStoreTest::kKeyValueStoreV, &error));
323 EXPECT_EQ(internal_error(), error.name());
324}
325
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800326TEST_F(PropertyStoreTest, WriteOnlyProperties) {
327 // Test that properties registered as write-only are not returned
328 // when using Get*PropertiesIter().
329 PropertyStore store;
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800330 {
331 const string keys[] = {"boolp1", "boolp2"};
332 bool values[] = {true, true};
333 store.RegisterWriteOnlyBool(keys[0], &values[0]);
334 store.RegisterBool(keys[1], &values[1]);
335
336 ReadablePropertyConstIterator<bool> it = store.GetBoolPropertiesIter();
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800337 EXPECT_FALSE(it.AtEnd());
338 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200339 EXPECT_TRUE(values[1] == it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800340 it.Advance();
341 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800342
343 Error errors[2];
344 EXPECT_FALSE(store.GetBoolProperty(keys[0], NULL, &errors[0]));
345 EXPECT_EQ(Error::kPermissionDenied, errors[0].type());
346 bool test_value;
347 EXPECT_TRUE(store.GetBoolProperty(keys[1], &test_value, &errors[1]));
348 EXPECT_TRUE(errors[1].IsSuccess());
349 EXPECT_EQ(values[1], test_value);
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800350 }
351 {
352 const string keys[] = {"int16p1", "int16p2"};
353 int16 values[] = {127, 128};
354 store.RegisterWriteOnlyInt16(keys[0], &values[0]);
355 store.RegisterInt16(keys[1], &values[1]);
356
357 ReadablePropertyConstIterator<int16> it = store.GetInt16PropertiesIter();
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800358 EXPECT_FALSE(it.AtEnd());
359 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200360 EXPECT_EQ(values[1], it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800361 it.Advance();
362 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800363
364 Error errors[2];
365 EXPECT_FALSE(store.GetInt16Property(keys[0], NULL, &errors[0]));
366 EXPECT_EQ(Error::kPermissionDenied, errors[0].type());
367 int16 test_value;
368 EXPECT_TRUE(store.GetInt16Property(keys[1], &test_value, &errors[1]));
369 EXPECT_TRUE(errors[1].IsSuccess());
370 EXPECT_EQ(values[1], test_value);
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800371 }
372 {
373 const string keys[] = {"int32p1", "int32p2"};
374 int32 values[] = {127, 128};
375 store.RegisterWriteOnlyInt32(keys[0], &values[0]);
376 store.RegisterInt32(keys[1], &values[1]);
377
378 ReadablePropertyConstIterator<int32> it = store.GetInt32PropertiesIter();
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800379 EXPECT_FALSE(it.AtEnd());
380 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200381 EXPECT_EQ(values[1], it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800382 it.Advance();
383 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800384
385 Error errors[2];
386 EXPECT_FALSE(store.GetInt32Property(keys[0], NULL, &errors[0]));
387 EXPECT_EQ(Error::kPermissionDenied, errors[0].type());
388 int32 test_value;
389 EXPECT_TRUE(store.GetInt32Property(keys[1], &test_value, &errors[1]));
390 EXPECT_TRUE(errors[1].IsSuccess());
391 EXPECT_EQ(values[1], test_value);
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800392 }
393 {
394 const string keys[] = {"stringp1", "stringp2"};
395 string values[] = {"noooo", "yesss"};
396 store.RegisterWriteOnlyString(keys[0], &values[0]);
397 store.RegisterString(keys[1], &values[1]);
398
399 ReadablePropertyConstIterator<string> it = store.GetStringPropertiesIter();
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800400 EXPECT_FALSE(it.AtEnd());
401 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200402 EXPECT_EQ(values[1], it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800403 it.Advance();
404 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800405
406 Error errors[2];
407 EXPECT_FALSE(store.GetStringProperty(keys[0], NULL, &errors[0]));
408 EXPECT_EQ(Error::kPermissionDenied, errors[0].type());
409 string test_value;
410 EXPECT_TRUE(store.GetStringProperty(keys[1], &test_value, &errors[1]));
411 EXPECT_TRUE(errors[1].IsSuccess());
412 EXPECT_EQ(values[1], test_value);
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800413 }
414 {
415 const string keys[] = {"stringmapp1", "stringmapp2"};
416 Stringmap values[2];
417 values[0]["noooo"] = "yesss";
418 values[1]["yesss"] = "noooo";
419 store.RegisterWriteOnlyStringmap(keys[0], &values[0]);
420 store.RegisterStringmap(keys[1], &values[1]);
421
422 ReadablePropertyConstIterator<Stringmap> it =
423 store.GetStringmapPropertiesIter();
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800424 EXPECT_FALSE(it.AtEnd());
425 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200426 EXPECT_TRUE(values[1] == it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800427 it.Advance();
428 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800429
430 Error errors[2];
431 EXPECT_FALSE(store.GetStringmapProperty(keys[0], NULL, &errors[0]));
432 EXPECT_EQ(Error::kPermissionDenied, errors[0].type());
433 Stringmap test_value;
434 EXPECT_TRUE(store.GetStringmapProperty(keys[1], &test_value, &errors[1]));
435 EXPECT_TRUE(errors[1].IsSuccess());
436 EXPECT_TRUE(values[1] == test_value);
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800437 }
438 {
439 const string keys[] = {"stringmapsp1", "stringmapsp2"};
440 Stringmaps values[2];
441 Stringmap element;
442 element["noooo"] = "yesss";
443 values[0].push_back(element);
444 element["yesss"] = "noooo";
445 values[1].push_back(element);
446
447 store.RegisterWriteOnlyStringmaps(keys[0], &values[0]);
448 store.RegisterStringmaps(keys[1], &values[1]);
449
450 ReadablePropertyConstIterator<Stringmaps> it =
451 store.GetStringmapsPropertiesIter();
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800452 EXPECT_FALSE(it.AtEnd());
453 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200454 EXPECT_TRUE(values[1] == it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800455 it.Advance();
456 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800457
458 Error errors[2];
459 EXPECT_FALSE(store.GetStringmapsProperty(keys[0], NULL, &errors[0]));
460 EXPECT_EQ(Error::kPermissionDenied, errors[0].type());
461 Stringmaps test_value;
462 EXPECT_TRUE(store.GetStringmapsProperty(keys[1], &test_value, &errors[1]));
463 EXPECT_TRUE(errors[1].IsSuccess());
464 EXPECT_TRUE(values[1] == test_value);
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800465 }
466 {
467 const string keys[] = {"stringsp1", "stringsp2"};
468 Strings values[2];
469 string element;
470 element = "noooo";
471 values[0].push_back(element);
472 element = "yesss";
473 values[1].push_back(element);
474 store.RegisterWriteOnlyStrings(keys[0], &values[0]);
475 store.RegisterStrings(keys[1], &values[1]);
476
477 ReadablePropertyConstIterator<Strings> it =
478 store.GetStringsPropertiesIter();
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800479 EXPECT_FALSE(it.AtEnd());
480 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200481 EXPECT_TRUE(values[1] == it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800482 it.Advance();
483 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800484
485 Error errors[2];
486 EXPECT_FALSE(store.GetStringsProperty(keys[0], NULL, &errors[0]));
487 EXPECT_EQ(Error::kPermissionDenied, errors[0].type());
488 Strings test_value;
489 EXPECT_TRUE(store.GetStringsProperty(keys[1], &test_value, &errors[1]));
490 EXPECT_TRUE(errors[1].IsSuccess());
491 EXPECT_TRUE(values[1] == test_value);
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800492 }
493 {
494 const string keys[] = {"uint8p1", "uint8p2"};
495 uint8 values[] = {127, 128};
496 store.RegisterWriteOnlyUint8(keys[0], &values[0]);
497 store.RegisterUint8(keys[1], &values[1]);
498
499 ReadablePropertyConstIterator<uint8> it = store.GetUint8PropertiesIter();
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800500 EXPECT_FALSE(it.AtEnd());
501 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200502 EXPECT_EQ(values[1], it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800503 it.Advance();
504 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800505
506 Error errors[2];
507 EXPECT_FALSE(store.GetUint8Property(keys[0], NULL, &errors[0]));
508 EXPECT_EQ(Error::kPermissionDenied, errors[0].type());
509 uint8 test_value;
510 EXPECT_TRUE(store.GetUint8Property(keys[1], &test_value, &errors[1]));
511 EXPECT_TRUE(errors[1].IsSuccess());
512 EXPECT_EQ(values[1], test_value);
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800513 }
514 {
515 const string keys[] = {"uint16p", "uint16p1"};
516 uint16 values[] = {127, 128};
517 store.RegisterWriteOnlyUint16(keys[0], &values[0]);
518 store.RegisterUint16(keys[1], &values[1]);
519
520 ReadablePropertyConstIterator<uint16> it = store.GetUint16PropertiesIter();
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800521 EXPECT_FALSE(it.AtEnd());
522 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200523 EXPECT_EQ(values[1], it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800524 it.Advance();
525 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800526
527 Error errors[2];
528 EXPECT_FALSE(store.GetUint16Property(keys[0], NULL, &errors[0]));
529 EXPECT_EQ(Error::kPermissionDenied, errors[0].type());
530 uint16 test_value;
531 EXPECT_TRUE(store.GetUint16Property(keys[1], &test_value, &errors[1]));
532 EXPECT_TRUE(errors[1].IsSuccess());
533 EXPECT_EQ(values[1], test_value);
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800534 }
535}
536
Chris Masoneb925cc82011-06-22 15:39:57 -0700537} // namespace shill