X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=test%2Fcore%2Fmain.cpp;fp=test%2Fcore%2Fmain.cpp;h=d804ab06de73a84a83f3f31b021bd8bf63063b1f;hb=bebea4009ed5a273fbf9ed3644a2140a8f477f99;hp=92087554213ee7e8768c0d4512287d42d5d96219;hpb=a6974c96b83e3c9056574010a40a7eaa391e23d9;p=anna.git diff --git a/test/core/main.cpp b/test/core/main.cpp index 9208755..d804ab0 100644 --- a/test/core/main.cpp +++ b/test/core/main.cpp @@ -44,6 +44,8 @@ #include #include +#include +#include #include using namespace std; @@ -111,3 +113,46 @@ BOOST_AUTO_TEST_CASE(functions_asString) { BOOST_REQUIRE_EQUAL(anna::functions::asString(d, "%4.2f"), cad_aux); } +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(); + + BOOST_CHECK_THROW(env.getValue("WRONG_ENV_VAR", true /* exception if missing */), anna::RuntimeException); + BOOST_CHECK_THROW(env.getValue(NULL), anna::RuntimeException); + BOOST_REQUIRE_EQUAL(env.getValue("HOME"), std::string("/home/eramos")); + BOOST_REQUIRE_EQUAL(env.getValue("MISSING_ENV_VAR"), std::string("")); +} +