+BOOST_AUTO_TEST_CASE(configuration) {
+ anna::Configuration conf;
+ BOOST_CHECK_THROW(conf.load("missing_file.cnf"), anna::RuntimeException);
+ BOOST_CHECK_NO_THROW(conf.load("test/core/example.cnf"));
+ //[ property ]
+ //thing = tshirt
+ //size = 1
+ //color = blue
+ //[ owner ]
+ //name = edu
+ //address = madrid
+ BOOST_CHECK_THROW(conf.getValue("property", "WRONG_VAR"), anna::RuntimeException);
+ BOOST_CHECK_THROW(conf.getValue("WRONG_SECTION", "thing"), anna::RuntimeException);
+ std::string value;
+ BOOST_REQUIRE_EQUAL(value = conf.getValue("property", "thing"), "tshirt");
+ BOOST_REQUIRE_EQUAL(conf.getIntegerValue("property", "size"), 1);
+ BOOST_REQUIRE_EQUAL(std::string(conf.getValue("property", "color")), "blue");
+ BOOST_REQUIRE_EQUAL(std::string(conf.getValue("owner", "name")), "edu");
+ BOOST_REQUIRE_EQUAL(std::string(conf.getValue("owner", "address")), "madrid");
+ conf.setDefaultValue("owner", "phone", "555 55 55");
+ BOOST_REQUIRE_EQUAL(std::string(conf.getValue("owner", "phone")), "555 55 55");
+ BOOST_REQUIRE(!conf.getValue("owner", "phone", true) /* query value is NULL: 'true = strict' even with default value assigned */);
+ BOOST_REQUIRE(!conf.exists("owner", "phone"));
+ BOOST_REQUIRE(conf.exists("owner", "name"));
+}
+
+BOOST_AUTO_TEST_CASE(environment) {
+ anna::Environment &env = anna::Environment::instantiate();
+ env.initialize();
+ BOOST_CHECK_THROW(env.getValue("WRONG_ENV_VAR", true), anna::RuntimeException); // true => exception if missing
+ BOOST_CHECK_THROW(env.getValue(NULL), anna::RuntimeException);
+ env.setVariable("TEST_VAR", "my test var value");
+ BOOST_REQUIRE_EQUAL(env.getValue("TEST_VAR"), std::string("my test var value"));
+ env.setVariable("TEST_VAR", "my new test var value", false /* no overwritting */);
+ BOOST_REQUIRE_EQUAL(env.getValue("TEST_VAR"), std::string("my test var value"));
+ env.unsetVariable("TEST_VAR");
+ BOOST_REQUIRE_EQUAL(env.getValue("TEST_VAR"), std::string(""));
+ BOOST_REQUIRE_EQUAL(env.getValue("MISSING_ENV_VAR"), std::string(""));
+}
+