本文整理汇总了C++中ola::StringValidator方法的典型用法代码示例。如果您正苦于以下问题:C++ ola::StringValidator方法的具体用法?C++ ola::StringValidator怎么用?C++ ola::StringValidator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ola
的用法示例。
在下文中一共展示了ola::StringValidator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testGetSetRemove
/*
* 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));
}
示例2: testGetSetRemove
/*
* 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));
//.........这里部分代码省略.........