76 lines
1.8 KiB
C++
76 lines
1.8 KiB
C++
#include <cxxtest/TestSuite.h>
|
|
|
|
#include "userinterface.hh"
|
|
|
|
#include <string>
|
|
#include <fstream>
|
|
|
|
class UserInterface_test: public CxxTest::TestSuite
|
|
{
|
|
private:
|
|
std::string config_file_name ;
|
|
std::vector<std::string> 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) ;
|
|
|
|
// Fill name and contents of the test config file
|
|
config_file_name = "/tmp/UserInterface_test_config_file.csv" ;
|
|
config_lines.push_back("\n") ;
|
|
config_lines.push_back("[input]\n") ;
|
|
config_lines.push_back("\n") ;
|
|
config_lines.push_back("udp-port = 42\n") ;
|
|
config_lines.push_back("\n") ;
|
|
TestUtil::fill_file(config_file_name, config_lines) ;
|
|
|
|
// Back to the normal behaviour (i.e. do not abort on fail)
|
|
CxxTest::setAbortTestOnFail(false) ;
|
|
}
|
|
|
|
|
|
~UserInterface_test(void)
|
|
{
|
|
// Delete the test config file
|
|
TestUtil::remove_file(config_file_name) ;
|
|
}
|
|
|
|
|
|
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<char**>(argv)) ;
|
|
|
|
TS_ASSERT(Configuration::is_configured("input.udp-port")) ;
|
|
TS_ASSERT(Configuration::is_configured("config-file")) ;
|
|
|
|
TS_ASSERT_EQUALS(Configuration::int_value("input.udp-port"), 42) ;
|
|
TS_ASSERT_EQUALS(Configuration::string_value("config-file"),
|
|
config_file_name) ;
|
|
}
|
|
|
|
} ;
|