예제 #1
0
/**
 * Test that choice_option correctly reports its capabilities.
 */
TEST(choice_option_test, capabilities)
{
    auto short_name = std::string("f");
    auto name = std::string("foo");
    auto option = qflags::choice_option(name.c_str(), short_name.c_str(), {"bar", "baz"}, "bar");

    EXPECT_EQ(name, option.name());
    EXPECT_EQ(short_name, option.short_name());
    EXPECT_EQ(false, option.is_set());
    EXPECT_EQ(false, option.is_flag());
    EXPECT_EQ(false, option.is_command());
    EXPECT_EQ(false, option.is_array());
    EXPECT_EQ(false, option.is_boolean());
    EXPECT_EQ(false, option.is_integer());
    EXPECT_EQ(true, option.is_string());
    EXPECT_EQ(0u, option.array_size());

    EXPECT_THROW(option.value_boolean(), std::logic_error);
    EXPECT_THROW(option.value_integer(), std::logic_error);
    EXPECT_EQ("bar", option.value_string());
    EXPECT_THROW(option.value_array(0), std::logic_error);

    EXPECT_THROW(static_cast<bool>(option), std::logic_error);
    EXPECT_THROW(static_cast<int64_t>(option), std::logic_error);
    EXPECT_THROW(static_cast<int>(option), std::logic_error);
    EXPECT_EQ("bar", static_cast<std::string>(option));
}
bool
paramList::getBoolean(unsigned int const paramNumber) const {

    if (paramNumber >= this->paramVector.size())
        throw(fault("Not enough parameters", fault::CODE_TYPE));

    if (this->paramVector[paramNumber].type() != value::TYPE_BOOLEAN)
        throw(fault("Parameter that is supposed to be boolean is not", 
                    fault::CODE_TYPE));

    return static_cast<bool>(value_boolean(this->paramVector[paramNumber]));
}