54 lines
1009 B
C++
54 lines
1009 B
C++
|
#include <cxxtest/TestSuite.h>
|
||
|
|
||
|
#include "textfilewriter.hh"
|
||
|
|
||
|
class TextFileWriter_test: public CxxTest::TestSuite
|
||
|
{
|
||
|
private:
|
||
|
std::string test_file_name ;
|
||
|
|
||
|
public:
|
||
|
|
||
|
TextFileWriter_test(void)
|
||
|
{
|
||
|
Stock::clear() ;
|
||
|
test_file_name = "/tmp/TextFileWriter_test_file.csv" ;
|
||
|
}
|
||
|
|
||
|
|
||
|
~TextFileWriter_test(void)
|
||
|
{
|
||
|
TestUtil::remove_file(test_file_name) ;
|
||
|
}
|
||
|
|
||
|
|
||
|
static TextFileWriter_test* createSuite(void)
|
||
|
{
|
||
|
return new TextFileWriter_test() ;
|
||
|
}
|
||
|
|
||
|
|
||
|
static void destroySuite(TextFileWriter_test *suite)
|
||
|
{
|
||
|
delete suite ;
|
||
|
}
|
||
|
|
||
|
|
||
|
void test_textfilewriter(void)
|
||
|
{
|
||
|
TextFileWriter *textfilewriter =
|
||
|
new TextFileWriter(test_file_name) ;
|
||
|
TS_ASSERT(textfilewriter->write_text("Hello\nWorld\n")) ;
|
||
|
delete textfilewriter ;
|
||
|
|
||
|
std::ifstream input_file(test_file_name.c_str()) ;
|
||
|
std::string line ;
|
||
|
getline(input_file, line) ;
|
||
|
TS_ASSERT_EQUALS(line, "Hello") ;
|
||
|
getline(input_file, line) ;
|
||
|
TS_ASSERT_EQUALS(line, "World") ;
|
||
|
input_file.close() ;
|
||
|
}
|
||
|
|
||
|
} ;
|