本文整理汇总了C++中OSArgument::valueAsString方法的典型用法代码示例。如果您正苦于以下问题:C++ OSArgument::valueAsString方法的具体用法?C++ OSArgument::valueAsString怎么用?C++ OSArgument::valueAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OSArgument
的用法示例。
在下文中一共展示了OSArgument::valueAsString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST_F(RulesetFixture, OSArgument_ClearValue) {
std::vector<std::string> choices;
choices.push_back("On");
choices.push_back("Off");
OSArgument boolArgument = OSArgument::makeBoolArgument("bool");
OSArgument doubleArgument = OSArgument::makeDoubleArgument("double");
OSArgument integerArgument = OSArgument::makeIntegerArgument("integer");
OSArgument stringArgument = OSArgument::makeStringArgument("string");
OSArgument choiceArgument = OSArgument::makeChoiceArgument("choice", choices);
EXPECT_TRUE(boolArgument.setValue(true));
EXPECT_TRUE(doubleArgument.setValue(1.0));
EXPECT_TRUE(doubleArgument.setValue((int)1)); // can also set double arg using int
EXPECT_TRUE(integerArgument.setValue((int)1));
EXPECT_TRUE(stringArgument.setValue(std::string("value")));
EXPECT_TRUE(choiceArgument.setValue(std::string("On")));
ASSERT_TRUE(boolArgument.hasValue());
ASSERT_TRUE(doubleArgument.hasValue());
ASSERT_TRUE(integerArgument.hasValue());
ASSERT_TRUE(stringArgument.hasValue());
ASSERT_TRUE(choiceArgument.hasValue());
boolArgument.clearValue();
doubleArgument.clearValue();
integerArgument.clearValue();
stringArgument.clearValue();
choiceArgument.clearValue();
EXPECT_FALSE(boolArgument.hasValue());
EXPECT_FALSE(doubleArgument.hasValue());
EXPECT_FALSE(integerArgument.hasValue());
EXPECT_FALSE(stringArgument.hasValue());
EXPECT_FALSE(choiceArgument.hasValue());
EXPECT_ANY_THROW(boolArgument.valueAsBool());
EXPECT_ANY_THROW(doubleArgument.valueAsDouble());
EXPECT_ANY_THROW(integerArgument.valueAsInteger());
EXPECT_ANY_THROW(stringArgument.valueAsString());
EXPECT_ANY_THROW(choiceArgument.valueAsString());
}
示例2: convertOSArgumentVectorToMap
TEST_F(RulesetFixture, OSArgument_Clone) {
std::vector<std::string> choices;
choices.push_back("On");
choices.push_back("Off");
OSArgument boolArgument = OSArgument::makeBoolArgument("bool");
OSArgument doubleArgument = OSArgument::makeDoubleArgument("double");
OSArgument integerArgument = OSArgument::makeIntegerArgument("integer");
OSArgument stringArgument = OSArgument::makeStringArgument("string");
OSArgument choiceArgument = OSArgument::makeChoiceArgument("choice", choices);
EXPECT_FALSE(boolArgument.hasValue());
EXPECT_FALSE(doubleArgument.hasValue());
EXPECT_FALSE(integerArgument.hasValue());
EXPECT_FALSE(stringArgument.hasValue());
EXPECT_FALSE(choiceArgument.hasValue());
EXPECT_TRUE(boolArgument.setValue(true));
EXPECT_TRUE(doubleArgument.setValue(1.0));
EXPECT_TRUE(doubleArgument.setValue((int)1)); // can also set double arg using int
EXPECT_TRUE(integerArgument.setValue((int)1));
EXPECT_TRUE(stringArgument.setValue(std::string("value")));
EXPECT_TRUE(choiceArgument.setValue(std::string("On")));
ASSERT_TRUE(boolArgument.hasValue());
ASSERT_TRUE(doubleArgument.hasValue());
ASSERT_TRUE(integerArgument.hasValue());
ASSERT_TRUE(stringArgument.hasValue());
ASSERT_TRUE(choiceArgument.hasValue());
EXPECT_EQ(true, boolArgument.valueAsBool());
EXPECT_EQ(1.0, doubleArgument.valueAsDouble());
EXPECT_EQ(1, integerArgument.valueAsInteger());
EXPECT_EQ("value", stringArgument.valueAsString());
EXPECT_EQ("On", choiceArgument.valueAsString());
OSArgument boolArgument2 = boolArgument.clone();
OSArgument doubleArgument2 = doubleArgument.clone();
OSArgument integerArgument2 = integerArgument.clone();
OSArgument stringArgument2 = stringArgument.clone();
OSArgument choiceArgument2 = choiceArgument.clone();
ASSERT_TRUE(boolArgument2.hasValue());
ASSERT_TRUE(doubleArgument2.hasValue());
ASSERT_TRUE(integerArgument2.hasValue());
ASSERT_TRUE(stringArgument2.hasValue());
ASSERT_TRUE(choiceArgument2.hasValue());
EXPECT_EQ(true, boolArgument2.valueAsBool());
EXPECT_EQ(1.0, doubleArgument2.valueAsDouble());
EXPECT_EQ(1, integerArgument2.valueAsInteger());
EXPECT_EQ("value", stringArgument2.valueAsString());
EXPECT_EQ("On", choiceArgument2.valueAsString());
std::vector<OSArgument> argumentVector;
argumentVector.push_back(boolArgument);
argumentVector.push_back(doubleArgument);
argumentVector.push_back(integerArgument);
argumentVector.push_back(stringArgument);
argumentVector.push_back(choiceArgument);
std::map<std::string,OSArgument> argumentMap = convertOSArgumentVectorToMap(argumentVector);
ASSERT_FALSE(argumentMap.find("bool") == argumentMap.end());
ASSERT_FALSE(argumentMap.find("double") == argumentMap.end());
ASSERT_FALSE(argumentMap.find("integer") == argumentMap.end());
ASSERT_FALSE(argumentMap.find("string") == argumentMap.end());
ASSERT_FALSE(argumentMap.find("choice") == argumentMap.end());
ASSERT_TRUE(argumentMap.find("bool")->second.hasValue());
ASSERT_TRUE(argumentMap.find("double")->second.hasValue());
ASSERT_TRUE(argumentMap.find("integer")->second.hasValue());
ASSERT_TRUE(argumentMap.find("string")->second.hasValue());
ASSERT_TRUE(argumentMap.find("choice")->second.hasValue());
EXPECT_EQ(true, argumentMap.find("bool")->second.valueAsBool());
EXPECT_EQ(1.0, argumentMap.find("double")->second.valueAsDouble());
EXPECT_EQ(1, argumentMap.find("integer")->second.valueAsInteger());
EXPECT_EQ("value", argumentMap.find("string")->second.valueAsString());
EXPECT_EQ("On", argumentMap.find("choice")->second.valueAsString());
}