本文整理汇总了C++中Configurator::getConfiguration方法的典型用法代码示例。如果您正苦于以下问题:C++ Configurator::getConfiguration方法的具体用法?C++ Configurator::getConfiguration怎么用?C++ Configurator::getConfiguration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Configurator
的用法示例。
在下文中一共展示了Configurator::getConfiguration方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: file
// Check that spaces before and after the = signs in config files are ignored
TEST_WITH_WORKDIR(ConfiguratorTest, ConfigFileSpacesIgnored)
{
if (mkdir("conf", 0755) != 0)
FAIL() << "Failed to create directory conf";
ofstream file("conf/mesos.conf");
file << "test1=coffee # beans are tasty\n";
file << "# just a comment\n";
file << " \t # comment with spaces in front\n";
file << "\n";
file << "test2 =tea\n";
file << "test3= water\n";
file << " test4 = milk\n";
file << " test5 = hot chocolate\t\n";
file << "\ttest6 = juice# #\n";
file.close();
Configurator conf;
setenv("MESOS_CONF", "conf", 1);
EXPECT_NO_THROW(conf.load());
unsetenv("MESOS_CONF");
EXPECT_EQ("coffee", conf.getConfiguration()["test1"]);
EXPECT_EQ("tea", conf.getConfiguration()["test2"]);
EXPECT_EQ("water", conf.getConfiguration()["test3"]);
EXPECT_EQ("milk", conf.getConfiguration()["test4"]);
EXPECT_EQ("hot chocolate", conf.getConfiguration()["test5"]);
EXPECT_EQ("juice", conf.getConfiguration()["test6"]);
}
示例2: setenv
TEST(ConfiguratorTest, Environment)
{
setenv("MESOS_TEST", "working", true);
Configurator conf;
conf.load();
unsetenv("MESOS_TEST");
EXPECT_EQ("working", conf.getConfiguration()["test"]);
}
示例3:
TEST(ConfiguratorTest, DefaultOptions)
{
const int ARGC = 5;
char* argv[ARGC];
argv[0] = (char*) "bin/filename";
argv[1] = (char*) "--test1=501";
argv[2] = (char*) "--test2";
argv[3] = (char*) "--excp=txt";
argv[4] = (char*) "--test8=foo";
Configurator conf;
EXPECT_NO_THROW(conf.addOption<int>("test1", "Testing option", 500));
EXPECT_NO_THROW(conf.addOption<bool>("test2", "Another tester", 0));
EXPECT_NO_THROW(conf.addOption<long>("test3", "Tests the default", 2010));
EXPECT_NO_THROW(conf.addOption<string>("test4", "Option without default"));
EXPECT_NO_THROW(conf.addOption<string>("test5", "Option with a default",
"default"));
EXPECT_NO_THROW(conf.addOption<bool>("test6", "Toggler...", false));
EXPECT_NO_THROW(conf.addOption<bool>("test7", "Toggler...", true));
EXPECT_NO_THROW(conf.addOption<string>("test8", "Overridden default",
"default"));
EXPECT_NO_THROW(conf.load(ARGC, argv));
EXPECT_NO_THROW(conf.addOption<int>("excp", "Exception tester.", 50));
EXPECT_THROW(conf.validate(), ConfigurationException);
conf.getConfiguration()["excp"] = "27";
EXPECT_NO_THROW(conf.validate());
EXPECT_EQ("501", conf.getConfiguration()["test1"]);
EXPECT_EQ("1", conf.getConfiguration()["test2"]);
EXPECT_EQ("2010", conf.getConfiguration()["test3"]);
EXPECT_EQ("", conf.getConfiguration()["test4"]);
EXPECT_EQ("default", conf.getConfiguration()["test5"]);
EXPECT_EQ("27", conf.getConfiguration()["excp"]);
EXPECT_EQ("0", conf.getConfiguration()["test6"]);
EXPECT_EQ("1", conf.getConfiguration()["test7"]);
EXPECT_EQ("foo", conf.getConfiguration()["test8"]);
}