#include #include "userinterface.hh" #include #include class UserInterface_test: public CxxTest::TestSuite { private: std::string config_file_name ; std::vector config_lines ; // Test config file contents public: UserInterface_test(void) { // If we cannot open the file, we want to stop the test CxxTest::setAbortTestOnFail(true) ; // Filling name and contents of the config test file config_file_name = "/tmp/UserInterface_test_config_file.csv" ; config_lines.push_back("\n") ; config_lines.push_back("[server]\n") ; config_lines.push_back("\n") ; config_lines.push_back("port = 42\n") ; config_lines.push_back("\n") ; // Opening the file std::ofstream config_file ; config_file.open(config_file_name.c_str()) ; if (! config_file) TS_FAIL("Cannot open test config file for creation!") ; // Writing contents to the file for (std::vector::const_iterator i = config_lines.begin() ; i != config_lines.end() ; ++i) config_file << *i ; config_file.close() ; // Back to the normal behaviour (i.e. do not abort on fail) CxxTest::setAbortTestOnFail(false) ; } ~UserInterface_test(void) { // Deleting the test config file if (remove(config_file_name.c_str()) == -1) TS_WARN("Cannot remove test config file!") ; } static UserInterface_test* createSuite(void) { return new UserInterface_test() ; } static void destroySuite(UserInterface_test *suite) { delete suite ; } void test_constructors(void) { // Note: as --help makes the program exit, we cannot test it. const char *argv[] = { "owlps-positioning", // program name "--config-file", config_file_name.c_str() } ; int argc = 3 ; UserInterface ui(argc, const_cast(argv)) ; TS_ASSERT(Configuration::is_configured("server.port")) ; TS_ASSERT(Configuration::is_configured("config-file")) ; TS_ASSERT_EQUALS(Configuration::get_int_value("server.port"), 42) ; TS_ASSERT_EQUALS(Configuration::get_string_value("config-file"), config_file_name) ; } } ;