blob: 03bdd616fbb5bdfe78d3823a46dce6d5333ad9b5 [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
mukesh agrawale7c7e652013-06-18 17:19:39 -070064const ::DBus::Variant PropertyStoreTest::kUint16sV =
65 DBusAdaptor::Uint16sToVariant(Uint16s{0});
66// static
Chris Masoneb925cc82011-06-22 15:39:57 -070067const ::DBus::Variant PropertyStoreTest::kUint32V =
68 DBusAdaptor::Uint32ToVariant(0);
Paul Stewarte18c33b2012-07-10 20:48:44 -070069// static
70const ::DBus::Variant PropertyStoreTest::kUint64V =
71 DBusAdaptor::Uint64ToVariant(0);
Chris Masoneb925cc82011-06-22 15:39:57 -070072
73PropertyStoreTest::PropertyStoreTest()
mukesh agrawalffa3d042011-10-06 15:26:10 -070074 : internal_error_(Error::GetName(Error::kInternalError)),
75 invalid_args_(Error::GetName(Error::kInvalidArguments)),
Chris Masone9d779932011-08-25 16:33:41 -070076 invalid_prop_(Error::GetName(Error::kInvalidProperty)),
77 path_(dir_.CreateUniqueTempDir() ? dir_.path().value() : ""),
Thieu Le6c1e3bb2013-02-06 15:20:35 -080078 metrics_(dispatcher()),
Chris Masone2176a882011-09-14 22:29:15 -070079 manager_(control_interface(),
80 dispatcher(),
Thieu Le3426c8f2012-01-11 17:35:11 -080081 metrics(),
Chris Masone2176a882011-09-14 22:29:15 -070082 glib(),
Chris Masone9d779932011-08-25 16:33:41 -070083 run_path(),
84 storage_path(),
85 string()) {
Chris Masoneb925cc82011-06-22 15:39:57 -070086}
87
88PropertyStoreTest::~PropertyStoreTest() {}
89
Chris Masone9d779932011-08-25 16:33:41 -070090void PropertyStoreTest::SetUp() {
91 ASSERT_FALSE(run_path().empty());
92 ASSERT_FALSE(storage_path().empty());
93}
94
mukesh agrawalbebf1b82013-04-23 15:06:33 -070095TEST_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 Masone8a56ad62011-07-02 15:27:57 -0700100 ::DBus::Error error;
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700101 EXPECT_CALL(*this, TestCallback(_)).Times(0);
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -0800102 EXPECT_FALSE(DBusAdaptor::SetProperty(&store, "", GetParam(), &error));
Chris Masone9d779932011-08-25 16:33:41 -0700103 EXPECT_EQ(invalid_prop(), error.name());
Chris Masone8a56ad62011-07-02 15:27:57 -0700104}
105
106INSTANTIATE_TEST_CASE_P(
107 PropertyStoreTestInstance,
108 PropertyStoreTest,
109 Values(PropertyStoreTest::kBoolV,
110 PropertyStoreTest::kByteV,
Chris Masone8a56ad62011-07-02 15:27:57 -0700111 PropertyStoreTest::kInt16V,
112 PropertyStoreTest::kInt32V,
Darin Petkov63138a92012-02-06 14:09:15 +0100113 PropertyStoreTest::kStringV,
Chris Masone8a56ad62011-07-02 15:27:57 -0700114 PropertyStoreTest::kStringmapV,
Chris Masone889666b2011-07-03 12:58:50 -0700115 PropertyStoreTest::kStringsV,
Chris Masone889666b2011-07-03 12:58:50 -0700116 PropertyStoreTest::kUint16V,
mukesh agrawale7c7e652013-06-18 17:19:39 -0700117 PropertyStoreTest::kUint16sV,
Paul Stewarte18c33b2012-07-10 20:48:44 -0700118 PropertyStoreTest::kUint32V,
119 PropertyStoreTest::kUint64V));
Chris Masone8a56ad62011-07-02 15:27:57 -0700120
mukesh agrawal4d260da2012-01-30 11:53:52 -0800121template <typename T>
122class PropertyStoreTypedTest : public PropertyStoreTest {
123 protected:
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700124 bool SetProperty(
125 PropertyStore &store, const string &name, Error *error);
mukesh agrawal4d260da2012-01-30 11:53:52 -0800126};
127
mukesh agrawale7c7e652013-06-18 17:19:39 -0700128TYPED_TEST_CASE(PropertyStoreTypedTest, PropertyStoreTest::PropertyTypes);
129
130TYPED_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
139TYPED_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 agrawal4d260da2012-01-30 11:53:52 -0800152
153TYPED_TEST(PropertyStoreTypedTest, ClearProperty) {
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700154 PropertyStore store(Bind(&PropertyStoreTest::TestCallback,
155 Unretained(this)));
mukesh agrawal4d260da2012-01-30 11:53:52 -0800156 Error error;
157 TypeParam property;
mukesh agrawale7c7e652013-06-18 17:19:39 -0700158 PropertyStoreTest::RegisterProperty(&store, "some property", &property);
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700159 EXPECT_CALL(*this, TestCallback(_));
mukesh agrawal4d260da2012-01-30 11:53:52 -0800160 EXPECT_TRUE(store.ClearProperty("some property", &error));
161}
162
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700163TYPED_TEST(PropertyStoreTypedTest, SetProperty) {
164 PropertyStore store(Bind(&PropertyStoreTest::TestCallback,
165 Unretained(this)));
166 Error error;
167 TypeParam property = TypeParam(); // value-initialize primitives
mukesh agrawale7c7e652013-06-18 17:19:39 -0700168 PropertyStoreTest::RegisterProperty(&store, "some property", &property);
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700169
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 agrawalbebf1b82013-04-23 15:06:33 -0700178template<> 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
184template<> 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
190template<> 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
196template<> 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
202template<> 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
209template<> 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
216template<> 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
223template<> 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
229template<> 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 agrawale7c7e652013-06-18 17:19:39 -0700235template<> 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 agrawalbebf1b82013-04-23 15:06:33 -0700241template<> 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 agrawal4d260da2012-01-30 11:53:52 -0800247TEST_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
266TEST_F(PropertyStoreTest, ClearPropertyNonexistent) {
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700267 PropertyStore store(Bind(&PropertyStoreTest::TestCallback,
268 Unretained(this)));
mukesh agrawal4d260da2012-01-30 11:53:52 -0800269 Error error;
270
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700271 EXPECT_CALL(*this, TestCallback(_)).Times(0);
mukesh agrawal4d260da2012-01-30 11:53:52 -0800272 EXPECT_FALSE(store.ClearProperty("", &error));
273 EXPECT_EQ(Error::kInvalidProperty, error.type());
274}
275
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700276// Separate from SetPropertyNonexistent, because
277// DBusAdaptor::SetProperty doesn't support Stringmaps.
mukesh agrawalffa3d042011-10-06 15:26:10 -0700278TEST_F(PropertyStoreTest, SetStringmapsProperty) {
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700279 PropertyStore store(Bind(&PropertyStoreTest::TestCallback,
280 Unretained(this)));
mukesh agrawalffa3d042011-10-06 15:26:10 -0700281 ::DBus::Error error;
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700282 EXPECT_CALL(*this, TestCallback(_)).Times(0);
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -0800283 EXPECT_FALSE(DBusAdaptor::SetProperty(
mukesh agrawalffa3d042011-10-06 15:26:10 -0700284 &store, "", PropertyStoreTest::kStringmapsV, &error));
285 EXPECT_EQ(internal_error(), error.name());
286}
287
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700288// Separate from SetPropertyNonexistent, because
289// DBusAdaptor::SetProperty doesn't support KeyValueStore.
Eric Shienbroodb23d4b92012-02-16 12:32:42 -0500290TEST_F(PropertyStoreTest, SetKeyValueStoreProperty) {
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700291 PropertyStore store(Bind(&PropertyStoreTest::TestCallback,
292 Unretained(this)));
Eric Shienbroodb23d4b92012-02-16 12:32:42 -0500293 ::DBus::Error error;
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700294 EXPECT_CALL(*this, TestCallback(_)).Times(0);
Eric Shienbroodb23d4b92012-02-16 12:32:42 -0500295 EXPECT_FALSE(DBusAdaptor::SetProperty(
296 &store, "", PropertyStoreTest::kKeyValueStoreV, &error));
297 EXPECT_EQ(internal_error(), error.name());
298}
299
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800300TEST_F(PropertyStoreTest, WriteOnlyProperties) {
301 // Test that properties registered as write-only are not returned
302 // when using Get*PropertiesIter().
303 PropertyStore store;
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800304 {
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 Shah1b7a6162011-11-09 11:41:01 -0800311 EXPECT_FALSE(it.AtEnd());
312 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200313 EXPECT_TRUE(values[1] == it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800314 it.Advance();
315 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800316
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 Shah1b7a6162011-11-09 11:41:01 -0800324 }
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 Shah1b7a6162011-11-09 11:41:01 -0800332 EXPECT_FALSE(it.AtEnd());
333 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200334 EXPECT_EQ(values[1], it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800335 it.Advance();
336 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800337
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 Shah1b7a6162011-11-09 11:41:01 -0800345 }
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 Shah1b7a6162011-11-09 11:41:01 -0800353 EXPECT_FALSE(it.AtEnd());
354 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200355 EXPECT_EQ(values[1], it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800356 it.Advance();
357 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800358
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 Shah1b7a6162011-11-09 11:41:01 -0800366 }
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 Shah1b7a6162011-11-09 11:41:01 -0800374 EXPECT_FALSE(it.AtEnd());
375 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200376 EXPECT_EQ(values[1], it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800377 it.Advance();
378 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800379
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 Shah1b7a6162011-11-09 11:41:01 -0800387 }
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 Shah1b7a6162011-11-09 11:41:01 -0800398 EXPECT_FALSE(it.AtEnd());
399 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200400 EXPECT_TRUE(values[1] == it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800401 it.Advance();
402 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800403
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 Shah1b7a6162011-11-09 11:41:01 -0800411 }
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 Shah1b7a6162011-11-09 11:41:01 -0800426 EXPECT_FALSE(it.AtEnd());
427 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200428 EXPECT_TRUE(values[1] == it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800429 it.Advance();
430 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800431
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 Shah1b7a6162011-11-09 11:41:01 -0800439 }
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 Shah1b7a6162011-11-09 11:41:01 -0800453 EXPECT_FALSE(it.AtEnd());
454 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200455 EXPECT_TRUE(values[1] == it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800456 it.Advance();
457 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800458
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 Shah1b7a6162011-11-09 11:41:01 -0800466 }
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 Shah1b7a6162011-11-09 11:41:01 -0800474 EXPECT_FALSE(it.AtEnd());
475 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200476 EXPECT_EQ(values[1], it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800477 it.Advance();
478 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800479
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 Shah1b7a6162011-11-09 11:41:01 -0800487 }
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 Shah1b7a6162011-11-09 11:41:01 -0800495 EXPECT_FALSE(it.AtEnd());
496 EXPECT_EQ(keys[1], it.Key());
Darin Petkov4682aa82012-05-31 16:24:11 +0200497 EXPECT_EQ(values[1], it.value());
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800498 it.Advance();
499 EXPECT_TRUE(it.AtEnd());
Paul Stewarte6e8e492013-01-17 11:00:50 -0800500
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 Shah1b7a6162011-11-09 11:41:01 -0800508 }
509}
510
Chris Masoneb925cc82011-06-22 15:39:57 -0700511} // namespace shill