config: setup

Added implementation of config Manager and tests.

reviewer=Ebsi
review
url=https://git.mediacube.at/egraether.mmt-b2009/masterproject/merge_request/3
This commit is contained in:
malte_langkabel
2014-04-04 14:32:10 +02:00
parent b854cb1f46
commit a1de92c58d
13 changed files with 6056 additions and 14 deletions
+1
View File
@@ -1,4 +1,5 @@
add_files(
TEST_FILES
ConfigManagerTestSuite.h
UtilityTestSuite.h
)
+73
View File
@@ -0,0 +1,73 @@
#include "cxxtest/TestSuite.h"
#include "utility/ConfigManager.h"
class ConfigManagerTestSuite: public CxxTest::TestSuite
{
public:
void test_config_manager_returns_true_when_key_is_found()
{
std::shared_ptr<ConfigManager> config = ConfigManager::createAndLoad("data/test_config.xml");
float value;
bool success = config->getValue("path/to/single_value", value);
TS_ASSERT(success);
}
void test_config_manager_returns_false_when_key_is_not_found()
{
std::shared_ptr<ConfigManager> config = ConfigManager::createAndLoad("data/test_config.xml");
float value;
bool success = config->getValue("path/to/nowhere", value);
TS_ASSERT(!success);
}
void test_config_manager_returns_correct_string_for_key()
{
std::shared_ptr<ConfigManager> config = ConfigManager::createAndLoad("data/test_config.xml");
std::string value;
config->getValue("path/to/single_value", value);
TS_ASSERT_EQUALS("42", value);
}
void test_config_manager_returns_correct_float_for_key()
{
std::shared_ptr<ConfigManager> config = ConfigManager::createAndLoad("data/test_config.xml");
float value;
config->getValue("path/to/single_value", value);
TS_ASSERT_DELTA(42.0f, value, 0.0001f);
}
void test_config_manager_returns_correct_bool_for_key_if_value_is_true()
{
std::shared_ptr<ConfigManager> config = ConfigManager::createAndLoad("data/test_config.xml");
float value;
bool success(config->getValue("path/to/bool_that_is_true", value));
TS_ASSERT(success);
TS_ASSERT(value);
}
void test_config_manager_returns_correct_bool_for_key_if_value_is_false()
{
std::shared_ptr<ConfigManager> config = ConfigManager::createAndLoad("data/test_config.xml");
float value;
bool success(config->getValue("path/to/bool_that_is_false", value));
TS_ASSERT(success);
TS_ASSERT(!value);
}
};