1 /* Copyright (c) 2004-2020. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include <xbt/config.hpp>
8 #include "simgrid/Exception.hpp"
14 XBT_PUBLIC_DATA simgrid::config::Config* simgrid_config;
16 TEST_CASE("xbt::config: Configuration support", "config")
18 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_cfg);
19 xbt_log_threshold_set(&_XBT_LOGV(xbt_cfg), xbt_log_priority_critical);
21 auto temp = simgrid_config;
22 simgrid_config = nullptr;
23 simgrid::config::declare_flag<int>("speed", "description", 0);
24 simgrid::config::declare_flag<std::string>("peername", "description", "");
25 simgrid::config::declare_flag<std::string>("user", "description", "");
27 SECTION("Alloc and free a config set")
29 INFO("Alloc and free a config set");
30 simgrid::config::set_parse("peername:veloce user:bidule");
33 SECTION("Data retrieving tests")
35 INFO("Get a single value");
36 /* get_single_value */
37 simgrid::config::set_parse("peername:toto:42 speed:42");
38 int ival = simgrid::config::get_value<int>("speed");
39 REQUIRE(ival == 42); // Unexpected value for speed
41 INFO("Access to a non-existent entry");
43 REQUIRE_THROWS_AS(simgrid::config::set_parse("color:blue"), std::out_of_range);
48 INFO("C++ declaration of flags");
50 simgrid::config::Flag<int> int_flag("int", "", 0);
51 simgrid::config::Flag<std::string> string_flag("string", "", "foo");
52 simgrid::config::Flag<double> double_flag("double", "", 0.32);
53 simgrid::config::Flag<bool> bool_flag1("bool1", "", false);
54 simgrid::config::Flag<bool> bool_flag2("bool2", "", true);
57 simgrid::config::set_parse("int:42 string:bar double:8.0 bool1:true bool2:false");
58 REQUIRE(int_flag == 42); // Check int flag
59 REQUIRE(string_flag == "bar"); // Check string flag
60 REQUIRE(double_flag == 8.0); // Check double flag
61 REQUIRE(bool_flag1); // Check bool1 flag
62 REQUIRE(not bool_flag2); // Check bool2 flag
65 simgrid::config::finalize();
66 simgrid_config = temp;