当前位置: 首页>>代码示例>>C++>>正文


C++ Configurator::getConfiguration方法代码示例

本文整理汇总了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"]);
}
开发者ID:adegtiar,项目名称:sceem,代码行数:29,代码来源:configurator_tests.cpp

示例2: setenv

TEST(ConfiguratorTest, Environment)
{
  setenv("MESOS_TEST", "working", true);
  Configurator conf;
  conf.load();
  unsetenv("MESOS_TEST");

  EXPECT_EQ("working", conf.getConfiguration()["test"]);
}
开发者ID:adegtiar,项目名称:sceem,代码行数:9,代码来源:configurator_tests.cpp

示例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"]);
}
开发者ID:adegtiar,项目名称:sceem,代码行数:39,代码来源:configurator_tests.cpp


注:本文中的Configurator::getConfiguration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。