/* * Check that we can get/set the preferences */ void PreferencesTest::testGetSetRemove() { MemoryPreferencesFactory factory; Preferences *preferences = factory.NewPreference("dummy"); string key1 = "foo"; string value1 = "bar"; string value2 = "baz"; // test get/set single values OLA_ASSERT_EQ(string(""), preferences->GetValue(key1)); preferences->SetValue(key1, value1); OLA_ASSERT_EQ(value1, preferences->GetValue(key1)); preferences->SetValue(key1, value2); OLA_ASSERT_EQ(value2, preferences->GetValue(key1)); preferences->RemoveValue(key1); OLA_ASSERT_EQ(string(""), preferences->GetValue(key1)); // test get/set multiple value string key2 = "bat"; vector<string> values = preferences->GetMultipleValue(key2); OLA_ASSERT_EQ((size_t) 0, values.size()); preferences->SetMultipleValue(key2, value1); values = preferences->GetMultipleValue(key2); OLA_ASSERT_EQ((size_t) 1, values.size()); OLA_ASSERT_EQ(value1, values.at(0)); preferences->SetMultipleValue(key2, value2); values = preferences->GetMultipleValue(key2); OLA_ASSERT_EQ((size_t) 2, values.size()); OLA_ASSERT_EQ(value1, values.at(0)); OLA_ASSERT_EQ(value2, values.at(1)); // test SetDefaultValue OLA_ASSERT(preferences->SetDefaultValue(key1, StringValidator(), value1)); OLA_ASSERT_EQ(value1, preferences->GetValue(key1)); OLA_ASSERT_FALSE(preferences->SetDefaultValue(key1, StringValidator(), value2)); OLA_ASSERT_EQ(value1, preferences->GetValue(key1)); }
/* * Check that we can get/set the preferences */ void PreferencesTest::testGetSetRemove() { MemoryPreferencesFactory factory; Preferences *preferences = factory.NewPreference("dummy"); string key1 = "foo"; string key2 = "bat"; string value1 = "bar"; string value2 = "baz"; unsigned int value3 = 1; unsigned int value4 = 2; int value5 = 3; int value6 = 4; // test get/set/has single values string OLA_ASSERT_EQ(string(""), preferences->GetValue(key1)); preferences->SetValue(key1, value1); OLA_ASSERT_EQ(value1, preferences->GetValue(key1)); OLA_ASSERT(preferences->HasKey(key1)); preferences->SetValue(key1, value2); OLA_ASSERT_EQ(value2, preferences->GetValue(key1)); preferences->RemoveValue(key1); OLA_ASSERT_EQ(string(""), preferences->GetValue(key1)); OLA_ASSERT_FALSE(preferences->HasKey(key1)); // test get/set/has single values uint OLA_ASSERT_EQ(string(""), preferences->GetValue(key1)); preferences->SetValue(key1, value3); OLA_ASSERT_EQ(IntToString(value3), preferences->GetValue(key1)); OLA_ASSERT(preferences->HasKey(key1)); preferences->SetValue(key1, value4); OLA_ASSERT_EQ(IntToString(value4), preferences->GetValue(key1)); preferences->RemoveValue(key1); OLA_ASSERT_EQ(string(""), preferences->GetValue(key1)); OLA_ASSERT_FALSE(preferences->HasKey(key1)); // test get/set/has single values int OLA_ASSERT_EQ(string(""), preferences->GetValue(key1)); preferences->SetValue(key1, value5); OLA_ASSERT_EQ(IntToString(value5), preferences->GetValue(key1)); OLA_ASSERT(preferences->HasKey(key1)); preferences->SetValue(key1, value6); OLA_ASSERT_EQ(IntToString(value6), preferences->GetValue(key1)); preferences->RemoveValue(key1); OLA_ASSERT_EQ(string(""), preferences->GetValue(key1)); OLA_ASSERT_FALSE(preferences->HasKey(key1)); vector<string> values; // test get/set multiple value string values = preferences->GetMultipleValue(key2); OLA_ASSERT_EQ((size_t) 0, values.size()); preferences->SetMultipleValue(key2, value1); values = preferences->GetMultipleValue(key2); OLA_ASSERT(preferences->HasKey(key2)); OLA_ASSERT_EQ((size_t) 1, values.size()); OLA_ASSERT_EQ(value1, values.at(0)); preferences->SetMultipleValue(key2, value2); values = preferences->GetMultipleValue(key2); OLA_ASSERT_EQ((size_t) 2, values.size()); OLA_ASSERT_EQ(value1, values.at(0)); OLA_ASSERT_EQ(value2, values.at(1)); preferences->RemoveValue(key2); // test get/set multiple value uint values = preferences->GetMultipleValue(key2); OLA_ASSERT_EQ((size_t) 0, values.size()); preferences->SetMultipleValue(key2, value3); values = preferences->GetMultipleValue(key2); OLA_ASSERT(preferences->HasKey(key2)); OLA_ASSERT_EQ((size_t) 1, values.size()); OLA_ASSERT_EQ(IntToString(value3), values.at(0)); preferences->SetMultipleValue(key2, value4); values = preferences->GetMultipleValue(key2); OLA_ASSERT_EQ((size_t) 2, values.size()); OLA_ASSERT_EQ(IntToString(value3), values.at(0)); OLA_ASSERT_EQ(IntToString(value4), values.at(1)); preferences->RemoveValue(key2); // test get/set multiple value int values = preferences->GetMultipleValue(key2); OLA_ASSERT_EQ((size_t) 0, values.size()); preferences->SetMultipleValue(key2, value5); values = preferences->GetMultipleValue(key2); OLA_ASSERT(preferences->HasKey(key2)); OLA_ASSERT_EQ((size_t) 1, values.size()); OLA_ASSERT_EQ(IntToString(value5), values.at(0)); preferences->SetMultipleValue(key2, value6); values = preferences->GetMultipleValue(key2); OLA_ASSERT_EQ((size_t) 2, values.size()); OLA_ASSERT_EQ(IntToString(value5), values.at(0)); OLA_ASSERT_EQ(IntToString(value6), values.at(1)); preferences->RemoveValue(key2); // test SetDefaultValue String OLA_ASSERT(preferences->SetDefaultValue(key1, StringValidator(), value1)); OLA_ASSERT_EQ(value1, preferences->GetValue(key1)); OLA_ASSERT_FALSE(preferences->SetDefaultValue(key1, StringValidator(), value2)); OLA_ASSERT_EQ(value1, preferences->GetValue(key1)); OLA_ASSERT(preferences->HasKey(key1)); preferences->RemoveValue(key1); // test SetDefaultValue uint UIntValidator uint_validator(0, 3); OLA_ASSERT(preferences->SetDefaultValue(key1, uint_validator, value3)); OLA_ASSERT_EQ(IntToString(value3), preferences->GetValue(key1)); OLA_ASSERT_FALSE(preferences->SetDefaultValue(key1, uint_validator, value4)); OLA_ASSERT_EQ(IntToString(value3), preferences->GetValue(key1)); OLA_ASSERT(preferences->HasKey(key1)); preferences->RemoveValue(key1); // test SetDefaultValue int IntValidator int_validator(0, 5); OLA_ASSERT(preferences->SetDefaultValue(key1, int_validator, value5)); OLA_ASSERT_EQ(IntToString(value5), preferences->GetValue(key1)); OLA_ASSERT_FALSE(preferences->SetDefaultValue(key1, int_validator, value6)); OLA_ASSERT_EQ(IntToString(value5), preferences->GetValue(key1)); OLA_ASSERT(preferences->HasKey(key1)); preferences->RemoveValue(key1); }