diff options
Diffstat (limited to 'src/DllPlugInTester/CommandLineParserTest.cpp')
| -rw-r--r-- | src/DllPlugInTester/CommandLineParserTest.cpp | 221 |
1 files changed, 221 insertions, 0 deletions
diff --git a/src/DllPlugInTester/CommandLineParserTest.cpp b/src/DllPlugInTester/CommandLineParserTest.cpp new file mode 100644 index 0000000..8f2f2bf --- /dev/null +++ b/src/DllPlugInTester/CommandLineParserTest.cpp @@ -0,0 +1,221 @@ +#include "CommandLineParser.h" +#include "CommandLineParserTest.h" + +CPPUNIT_TEST_SUITE_REGISTRATION( CommandLineParserTest ); + + +CommandLineParserTest::CommandLineParserTest() : + CppUnit::TestCase() +{ +} + + +CommandLineParserTest::~CommandLineParserTest() +{ +} + + +void +CommandLineParserTest::setUp() +{ + _parser = NULL; +} + + +void +CommandLineParserTest::tearDown() +{ + delete _parser; +} + + +void +CommandLineParserTest::parse( char **lines ) +{ + int count =0; + for ( char **line = lines; *line != NULL; ++line, ++count ); + + delete _parser; + _parser = new CommandLineParser( count, lines ); + _parser->parse(); +} + + +void +CommandLineParserTest::testEmptyCommandLine() +{ + static char *lines[] = { "", NULL }; + parse( lines ); + + std::string none; + CPPUNIT_ASSERT_EQUAL( none, _parser->getEncoding() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getTestPath() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getXmlFileName() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getXmlStyleSheet() ); + CPPUNIT_ASSERT( !_parser->noTestProgress() ); + CPPUNIT_ASSERT( !_parser->useBriefTestProgress() ); + CPPUNIT_ASSERT( !_parser->useCompilerOutputter() ); + CPPUNIT_ASSERT( !_parser->useCoutStream() ); + CPPUNIT_ASSERT( !_parser->useTextOutputter() ); + CPPUNIT_ASSERT( !_parser->useXmlOutputter() ); +} + + +void +CommandLineParserTest::testFlagCompiler() +{ + static char *lines[] = { "", "-c", NULL }; + parse( lines ); + + std::string none; + CPPUNIT_ASSERT_EQUAL( none, _parser->getEncoding() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getTestPath() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getXmlFileName() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getXmlStyleSheet() ); + CPPUNIT_ASSERT( !_parser->noTestProgress() ); + CPPUNIT_ASSERT( !_parser->useBriefTestProgress() ); + CPPUNIT_ASSERT( _parser->useCompilerOutputter() ); + CPPUNIT_ASSERT( !_parser->useCoutStream() ); + CPPUNIT_ASSERT( !_parser->useTextOutputter() ); + CPPUNIT_ASSERT( !_parser->useXmlOutputter() ); + CPPUNIT_ASSERT_EQUAL( 0, _parser->getPlugInCount() ); +} + + +void +CommandLineParserTest::testLongFlagBriefProgress() +{ + static char *lines[] = { "", "--brief-progress", NULL }; + parse( lines ); + + std::string none; + CPPUNIT_ASSERT_EQUAL( none, _parser->getEncoding() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getTestPath() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getXmlFileName() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getXmlStyleSheet() ); + CPPUNIT_ASSERT( !_parser->noTestProgress() ); + CPPUNIT_ASSERT( _parser->useBriefTestProgress() ); + CPPUNIT_ASSERT( !_parser->useCompilerOutputter() ); + CPPUNIT_ASSERT( !_parser->useCoutStream() ); + CPPUNIT_ASSERT( !_parser->useTextOutputter() ); + CPPUNIT_ASSERT( !_parser->useXmlOutputter() ); + CPPUNIT_ASSERT_EQUAL( 0, _parser->getPlugInCount() ); +} + + +void +CommandLineParserTest::testFileName() +{ + static char *lines[] = { "", "TestPlugIn.dll", NULL }; + parse( lines ); + + std::string none; + CPPUNIT_ASSERT_EQUAL( none, _parser->getEncoding() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getTestPath() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getXmlFileName() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getXmlStyleSheet() ); + CPPUNIT_ASSERT( !_parser->noTestProgress() ); + CPPUNIT_ASSERT( !_parser->useBriefTestProgress() ); + CPPUNIT_ASSERT( !_parser->useCompilerOutputter() ); + CPPUNIT_ASSERT( !_parser->useCoutStream() ); + CPPUNIT_ASSERT( !_parser->useTextOutputter() ); + CPPUNIT_ASSERT( !_parser->useXmlOutputter() ); + + CPPUNIT_ASSERT_EQUAL( 1, _parser->getPlugInCount() ); + + CommandLinePlugInInfo info( _parser->getPlugInAt( 0 ) ); + CPPUNIT_ASSERT_EQUAL( std::string("TestPlugIn.dll"), info.m_fileName ); + CPPUNIT_ASSERT_EQUAL( 0, int(info.m_parameters.size()) ); +} + + +void +CommandLineParserTest::testTestPath() +{ + static char *lines[] = { "", ":Core", NULL }; + parse( lines ); + + std::string none; + CPPUNIT_ASSERT_EQUAL( none, _parser->getEncoding() ); + CPPUNIT_ASSERT_EQUAL( std::string("Core"), _parser->getTestPath() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getXmlFileName() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getXmlStyleSheet() ); + CPPUNIT_ASSERT( !_parser->noTestProgress() ); + CPPUNIT_ASSERT( !_parser->useBriefTestProgress() ); + CPPUNIT_ASSERT( !_parser->useCompilerOutputter() ); + CPPUNIT_ASSERT( !_parser->useCoutStream() ); + CPPUNIT_ASSERT( !_parser->useTextOutputter() ); + CPPUNIT_ASSERT( !_parser->useXmlOutputter() ); + CPPUNIT_ASSERT_EQUAL( 0, _parser->getPlugInCount() ); +} + + +void +CommandLineParserTest::testParameterWithSpace() +{ + static char *lines[] = { "", "--xml", "Test Results.xml", NULL }; + parse( lines ); + + std::string none; + CPPUNIT_ASSERT_EQUAL( none, _parser->getEncoding() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getTestPath() ); + CPPUNIT_ASSERT_EQUAL( std::string("Test Results.xml"), + _parser->getXmlFileName() ); + CPPUNIT_ASSERT_EQUAL( none, _parser->getXmlStyleSheet() ); + CPPUNIT_ASSERT( !_parser->noTestProgress() ); + CPPUNIT_ASSERT( !_parser->useBriefTestProgress() ); + CPPUNIT_ASSERT( !_parser->useCompilerOutputter() ); + CPPUNIT_ASSERT( !_parser->useCoutStream() ); + CPPUNIT_ASSERT( !_parser->useTextOutputter() ); + CPPUNIT_ASSERT( _parser->useXmlOutputter() ); + CPPUNIT_ASSERT_EQUAL( 0, _parser->getPlugInCount() ); +} + + +void +CommandLineParserTest::testMissingStyleSheetParameterThrow() +{ + static char *lines[] = { "", "--xsl", NULL }; + parse( lines ); +} + + +void +CommandLineParserTest::testMissingEncodingParameterThrow() +{ + static char *lines[] = { "", "--encoding", NULL }; + parse( lines ); +} + + +void +CommandLineParserTest::testXmlFileNameIsOptional() +{ + static char *lines[] = { "", "--xml", NULL }; + parse( lines ); + + std::string none; + CPPUNIT_ASSERT_EQUAL( none, _parser->getXmlFileName() ); +} + + +void +CommandLineParserTest::testPlugInsWithParameters() +{ + static char *lines[] = { "", "TestPlugIn1.dll=login = lain", + "Clocker.dll", NULL }; + parse( lines ); + + CPPUNIT_ASSERT_EQUAL( 2, _parser->getPlugInCount() ); + + CommandLinePlugInInfo info1( _parser->getPlugInAt( 0 ) ); + + CPPUNIT_ASSERT_EQUAL( std::string("TestPlugIn1.dll"), info1.m_fileName ); + CPPUNIT_ASSERT_EQUAL( 1, int(info1.m_parameters.size()) ); + CPPUNIT_ASSERT_EQUAL( std::string("login = lain"), + info1.m_parameters[0] ); + + CommandLinePlugInInfo info2( _parser->getPlugInAt( 1 ) ); + CPPUNIT_ASSERT_EQUAL( std::string("Clocker.dll"), info2.m_fileName ); + CPPUNIT_ASSERT_EQUAL( 0, int(info2.m_parameters.size()) ); +} |
