release version
This commit is contained in:
37
examples/cppunittest/BaseTestCase.cpp
Normal file
37
examples/cppunittest/BaseTestCase.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <cppunit/config/SourcePrefix.h>
|
||||
#include "BaseTestCase.h"
|
||||
|
||||
|
||||
BaseTestCase::BaseTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BaseTestCase::~BaseTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BaseTestCase::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BaseTestCase::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BaseTestCase::testUsingCheckIt()
|
||||
{
|
||||
checkIt();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BaseTestCase::checkIt()
|
||||
{
|
||||
}
|
32
examples/cppunittest/BaseTestCase.h
Normal file
32
examples/cppunittest/BaseTestCase.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef BASETESTCASE_H
|
||||
#define BASETESTCASE_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
||||
class BaseTestCase : public CPPUNIT_NS::TestCase
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( BaseTestCase );
|
||||
CPPUNIT_TEST( testUsingCheckIt );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
BaseTestCase();
|
||||
virtual ~BaseTestCase();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
void testUsingCheckIt();
|
||||
|
||||
protected:
|
||||
virtual void checkIt();
|
||||
|
||||
private:
|
||||
BaseTestCase( const BaseTestCase © );
|
||||
void operator =( const BaseTestCase © );
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // BASETESTCASE_H
|
12
examples/cppunittest/CoreSuite.h
Normal file
12
examples/cppunittest/CoreSuite.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef CPPUNITTEST_CORESUITE_H
|
||||
#define CPPUNITTEST_CORESUITE_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <string>
|
||||
|
||||
inline std::string coreSuiteName()
|
||||
{
|
||||
return "Core";
|
||||
}
|
||||
|
||||
#endif // CPPUNITTEST_CORESUITE_H
|
66
examples/cppunittest/CppUnitTestMain.cpp
Normal file
66
examples/cppunittest/CppUnitTestMain.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <cppunit/CompilerOutputter.h>
|
||||
#include <cppunit/TestResult.h>
|
||||
#include <cppunit/TestResultCollector.h>
|
||||
#include <cppunit/TestRunner.h>
|
||||
#include <cppunit/TextTestProgressListener.h>
|
||||
#include <cppunit/BriefTestProgressListener.h>
|
||||
#include <cppunit/XmlOutputter.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
int
|
||||
main( int argc, char* argv[] )
|
||||
{
|
||||
// Retreive test path from command line first argument. Default to "" which resolve
|
||||
// to the top level suite.
|
||||
std::string testPath = (argc > 1) ? std::string(argv[1]) : std::string("");
|
||||
|
||||
// Create the event manager and test controller
|
||||
CPPUNIT_NS::TestResult controller;
|
||||
|
||||
// Add a listener that colllects test result
|
||||
CPPUNIT_NS::TestResultCollector result;
|
||||
controller.addListener( &result );
|
||||
|
||||
// Add a listener that print dots as test run.
|
||||
#ifdef WIN32
|
||||
CPPUNIT_NS::TextTestProgressListener progress;
|
||||
#else
|
||||
CPPUNIT_NS::BriefTestProgressListener progress;
|
||||
#endif
|
||||
controller.addListener( &progress );
|
||||
|
||||
// Add the top suite to the test runner
|
||||
CPPUNIT_NS::TestRunner runner;
|
||||
runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
|
||||
try
|
||||
{
|
||||
CPPUNIT_NS::stdCOut() << "Running " << testPath;
|
||||
runner.run( controller, testPath );
|
||||
|
||||
CPPUNIT_NS::stdCOut() << "\n";
|
||||
|
||||
// Print test in a compiler compatible format.
|
||||
CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() );
|
||||
outputter.write();
|
||||
|
||||
// Uncomment this for XML output
|
||||
// std::ofstream file( "tests.xml" );
|
||||
// CPPUNIT_NS::XmlOutputter xml( &result, file );
|
||||
// xml.setStyleSheet( "report.xsl" );
|
||||
// xml.write();
|
||||
// file.close();
|
||||
}
|
||||
catch ( std::invalid_argument &e ) // Test path not resolved
|
||||
{
|
||||
CPPUNIT_NS::stdCOut() << "\n"
|
||||
<< "ERROR: " << e.what()
|
||||
<< "\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
return result.wasSuccessful() ? 0 : 1;
|
||||
}
|
||||
|
546
examples/cppunittest/CppUnitTestMain.dsp
Normal file
546
examples/cppunittest/CppUnitTestMain.dsp
Normal file
@@ -0,0 +1,546 @@
|
||||
# Microsoft Developer Studio Project File - Name="CppUnitTestMain" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=CppUnitTestMain - Win32 Debug DLL
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "CppUnitTestMain.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "CppUnitTestMain.mak" CFG="CppUnitTestMain - Win32 Debug DLL"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "CppUnitTestMain - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "CppUnitTestMain - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "CppUnitTestMain - Win32 Release DLL" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "CppUnitTestMain - Win32 Debug DLL" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "CppUnitTestMain - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GR /GX /Zd /O2 /I "../../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE RSC /l 0x40c /d "NDEBUG"
|
||||
# ADD RSC /l 0x40c /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib cppunit.lib /nologo /subsystem:console /machine:I386 /libpath:"../../lib/"
|
||||
# SUBTRACT LINK32 /incremental:yes
|
||||
# Begin Special Build Tool
|
||||
TargetPath=.\Release\CppUnitTestMain.exe
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Desc=Self test
|
||||
PostBuild_Cmds="$(TargetPath)"
|
||||
# End Special Build Tool
|
||||
|
||||
!ELSEIF "$(CFG)" == "CppUnitTestMain - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /Zi /Od /I "../../include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE RSC /l 0x40c /d "_DEBUG"
|
||||
# ADD RSC /l 0x40c /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib cppunitd.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /pdbtype:sept /libpath:"../../lib/"
|
||||
# Begin Special Build Tool
|
||||
TargetPath=.\Debug\CppUnitTestMain.exe
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Desc=Self test
|
||||
PostBuild_Cmds="$(TargetPath)"
|
||||
# End Special Build Tool
|
||||
|
||||
!ELSEIF "$(CFG)" == "CppUnitTestMain - Win32 Release DLL"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "CppUnitTestMain___Win32_Release_DLL"
|
||||
# PROP BASE Intermediate_Dir "CppUnitTestMain___Win32_Release_DLL"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "ReleaseDLL"
|
||||
# PROP Intermediate_Dir "ReleaseDLL"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MD /W3 /GR /GX /O2 /I "../../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "CPPUNIT_USE_TYPEINFO" /FD /c
|
||||
# SUBTRACT BASE CPP /YX /Yc /Yu
|
||||
# ADD CPP /nologo /MD /W3 /GR /GX /Zd /Ox /Ot /Oa /Ow /Og /Oi /Op /Ob0 /I "../../include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "CPPUNIT_DLL" /FD /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE RSC /l 0x40c /d "NDEBUG"
|
||||
# ADD RSC /l 0x40c /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ../../lib/cppunit.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib cppunit_dll.lib /nologo /subsystem:console /machine:I386 /libpath:"../../lib/"
|
||||
# SUBTRACT LINK32 /incremental:yes
|
||||
# Begin Special Build Tool
|
||||
TargetPath=.\ReleaseDLL\CppUnitTestMain.exe
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Desc=Self test
|
||||
PostBuild_Cmds=$(TargetPath)
|
||||
# End Special Build Tool
|
||||
|
||||
!ELSEIF "$(CFG)" == "CppUnitTestMain - Win32 Debug DLL"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "CppUnitTestMain___Win32_Debug_DLL"
|
||||
# PROP BASE Intermediate_Dir "CppUnitTestMain___Win32_Debug_DLL"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "DebugDLL"
|
||||
# PROP Intermediate_Dir "DebugDLL"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "../../include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c
|
||||
# SUBTRACT BASE CPP /YX /Yc /Yu
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /Zi /Od /I "../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "CPPUNIT_DLL" /FD /GZ /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE RSC /l 0x40c /d "_DEBUG"
|
||||
# ADD RSC /l 0x40c /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ../../lib/cppunitd.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib cppunitd_dll.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /pdbtype:sept /libpath:"../../lib/"
|
||||
# Begin Special Build Tool
|
||||
TargetPath=.\DebugDLL\CppUnitTestMain.exe
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Desc=Self test
|
||||
PostBuild_Cmds=$(TargetPath)
|
||||
# End Special Build Tool
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "CppUnitTestMain - Win32 Release"
|
||||
# Name "CppUnitTestMain - Win32 Debug"
|
||||
# Name "CppUnitTestMain - Win32 Release DLL"
|
||||
# Name "CppUnitTestMain - Win32 Debug DLL"
|
||||
# Begin Group "Tests"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Group "Core"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\assertion_traitsTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\assertion_traitsTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ExceptionTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ExceptionTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MessageTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MessageTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestAssertTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestAssertTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestCallerTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestCallerTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestCaseTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestCaseTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestFailureTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestFailureTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestPathTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestPathTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestResultTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestResultTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestSuiteTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestSuiteTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestTest.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "UnitTestTools"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlUniformiser.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlUniformiser.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlUniformiserTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlUniformiserTest.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Helper"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HelperMacrosTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HelperMacrosTest.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Extension"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ExceptionTestCaseDecoratorTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ExceptionTestCaseDecoratorTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\OrthodoxTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\OrthodoxTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\RepeatedTestTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\RepeatedTestTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestDecoratorTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestDecoratorTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestSetUpTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestSetUpTest.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Output"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestResultCollectorTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestResultCollectorTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlOutputterTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlOutputterTest.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Tools"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StringToolsTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StringToolsTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlElementTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlElementTest.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Group
|
||||
# Begin Group "TestSupport"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BaseTestCase.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BaseTestCase.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\FailureException.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MockFunctor.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MockProtector.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MockTestCase.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MockTestCase.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MockTestListener.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MockTestListener.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\SubclassedTestCase.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\SubclassedTestCase.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\SynchronizedTestResult.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TrackedTestCase.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TrackedTestCase.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Suites"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CoreSuite.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CppUnitTestSuite.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ExtensionSuite.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HelperSuite.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\OutputSuite.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ToolsSuite.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\UnitTestToolSuite.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\lib\cppunit_dll.dll
|
||||
|
||||
!IF "$(CFG)" == "CppUnitTestMain - Win32 Release"
|
||||
|
||||
# PROP Exclude_From_Build 1
|
||||
|
||||
!ELSEIF "$(CFG)" == "CppUnitTestMain - Win32 Debug"
|
||||
|
||||
# PROP Exclude_From_Build 1
|
||||
|
||||
!ELSEIF "$(CFG)" == "CppUnitTestMain - Win32 Release DLL"
|
||||
|
||||
# Begin Custom Build - Updating DLL: $(InputPath)
|
||||
IntDir=.\ReleaseDLL
|
||||
InputPath=..\..\lib\cppunit_dll.dll
|
||||
InputName=cppunit_dll
|
||||
|
||||
"$(IntDir)\$(InputName).dll" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
|
||||
copy "$(InputPath)" "$(IntDir)\$(InputName).dll"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
!ELSEIF "$(CFG)" == "CppUnitTestMain - Win32 Debug DLL"
|
||||
|
||||
# PROP Exclude_From_Build 1
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\lib\cppunitd_dll.dll
|
||||
|
||||
!IF "$(CFG)" == "CppUnitTestMain - Win32 Release"
|
||||
|
||||
# PROP Exclude_From_Build 1
|
||||
|
||||
!ELSEIF "$(CFG)" == "CppUnitTestMain - Win32 Debug"
|
||||
|
||||
# PROP Exclude_From_Build 1
|
||||
|
||||
!ELSEIF "$(CFG)" == "CppUnitTestMain - Win32 Release DLL"
|
||||
|
||||
# PROP Exclude_From_Build 1
|
||||
|
||||
!ELSEIF "$(CFG)" == "CppUnitTestMain - Win32 Debug DLL"
|
||||
|
||||
# Begin Custom Build - Updating DLL: $(InputPath)
|
||||
IntDir=.\DebugDLL
|
||||
InputPath=..\..\lib\cppunitd_dll.dll
|
||||
InputName=cppunitd_dll
|
||||
|
||||
"$(IntDir)\$(InputName).dll" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
|
||||
copy "$(InputPath)" "$(IntDir)\$(InputName).dll"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CppUnitTestMain.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Makefile.am
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
59
examples/cppunittest/CppUnitTestMain.dsw
Normal file
59
examples/cppunittest/CppUnitTestMain.dsw
Normal file
@@ -0,0 +1,59 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "CppUnitTestMain"=.\CppUnitTestMain.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name cppunit
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name cppunit_dll
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "cppunit"=..\..\src\cppunit\cppunit.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "cppunit_dll"=..\..\SRC\CPPUNIT\cppunit_dll.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
5
examples/cppunittest/CppUnitTestPlugIn.cpp
Normal file
5
examples/cppunittest/CppUnitTestPlugIn.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include <cppunit/plugin/TestPlugIn.h>
|
||||
|
||||
|
||||
// Implements all the plug-in stuffs, WinMain...
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
396
examples/cppunittest/CppUnitTestPlugIn.dsp
Normal file
396
examples/cppunittest/CppUnitTestPlugIn.dsp
Normal file
@@ -0,0 +1,396 @@
|
||||
# Microsoft Developer Studio Project File - Name="CppUnitTestPlugIn" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=CppUnitTestPlugIn - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "CppUnitTestPlugIn.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "CppUnitTestPlugIn.mak" CFG="CppUnitTestPlugIn - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "CppUnitTestPlugIn - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "CppUnitTestPlugIn - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "CppUnitTestPlugIn - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "ReleasePlugIn"
|
||||
# PROP Intermediate_Dir "ReleasePlugIn"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CPPUNITTESTPLUGIN_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GR /GX /Zd /O2 /I "../../include" /D "NDEBUG" /D "CPPUNITTESTPLUGIN_EXPORTS" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CPPUNIT_DLL" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x40c /d "NDEBUG"
|
||||
# ADD RSC /l 0x40c /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib cppunit_dll.lib /nologo /dll /machine:I386 /libpath:"../../lib/"
|
||||
# SUBTRACT LINK32 /incremental:yes
|
||||
|
||||
!ELSEIF "$(CFG)" == "CppUnitTestPlugIn - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "DebugPlugIn"
|
||||
# PROP Intermediate_Dir "DebugPlugIn"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CPPUNITTESTPLUGIN_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /Zi /Od /I "../../include" /D "_DEBUG" /D "CPPUNIT_DLL" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x40c /d "_DEBUG"
|
||||
# ADD RSC /l 0x40c /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib cppunitd_dll.lib /nologo /dll /incremental:no /debug /machine:I386 /out:"DebugPlugIn/CppUnitTestPlugInd.dll" /pdbtype:sept /libpath:"../../lib/"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "CppUnitTestPlugIn - Win32 Release"
|
||||
# Name "CppUnitTestPlugIn - Win32 Debug"
|
||||
# Begin Group "Suites"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CoreSuite.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CppUnitTestSuite.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CppUnitTestSuite.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ExtensionSuite.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HelperSuite.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\OutputSuite.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ToolsSuite.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\UnitTestToolSuite.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "TestSupport"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BaseTestCase.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BaseTestCase.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\FailureException.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MockFunctor.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MockProtector.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MockTestCase.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MockTestCase.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MockTestListener.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MockTestListener.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\SubclassedTestCase.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\SubclassedTestCase.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\SynchronizedTestResult.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TrackedTestCase.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TrackedTestCase.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Tests"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Group "Core"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ExceptionTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ExceptionTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MessageTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MessageTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestAssertTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestAssertTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestCallerTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestCallerTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestCaseTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestCaseTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestFailureTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestFailureTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestPathTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestPathTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestResultTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestResultTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestSuiteTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestSuiteTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestTest.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "UnitTestTools"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlUniformiser.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlUniformiser.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlUniformiserTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlUniformiserTest.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Helper"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HelperMacrosTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\HelperMacrosTest.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Extension"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ExceptionTestCaseDecoratorTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ExceptionTestCaseDecoratorTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\OrthodoxTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\OrthodoxTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\RepeatedTestTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\RepeatedTestTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestDecoratorTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestDecoratorTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestSetUpTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestSetUpTest.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Output"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestResultCollectorTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\TestResultCollectorTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlOutputterTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlOutputterTest.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Tools"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StringToolsTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StringToolsTest.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlElementTest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\XmlElementTest.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CppUnitTestPlugIn.cpp
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
15
examples/cppunittest/CppUnitTestSuite.cpp
Normal file
15
examples/cppunittest/CppUnitTestSuite.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <cppunit/config/SourcePrefix.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include "CoreSuite.h"
|
||||
#include "HelperSuite.h"
|
||||
#include "ExtensionSuite.h"
|
||||
#include "OutputSuite.h"
|
||||
#include "ToolsSuite.h"
|
||||
#include "UnitTestToolSuite.h"
|
||||
|
||||
CPPUNIT_REGISTRY_ADD_TO_DEFAULT( coreSuiteName() );
|
||||
CPPUNIT_REGISTRY_ADD_TO_DEFAULT( extensionSuiteName() );
|
||||
CPPUNIT_REGISTRY_ADD_TO_DEFAULT( helperSuiteName() );
|
||||
CPPUNIT_REGISTRY_ADD_TO_DEFAULT( outputSuiteName() );
|
||||
CPPUNIT_REGISTRY_ADD_TO_DEFAULT( toolsSuiteName() );
|
||||
CPPUNIT_REGISTRY_ADD_TO_DEFAULT( unitTestToolSuiteName() );
|
95
examples/cppunittest/ExceptionTest.cpp
Normal file
95
examples/cppunittest/ExceptionTest.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
#include "CoreSuite.h"
|
||||
#include "ExceptionTest.h"
|
||||
#include <cppunit/Exception.h>
|
||||
#include <memory>
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ExceptionTest,
|
||||
coreSuiteName() );
|
||||
|
||||
|
||||
ExceptionTest::ExceptionTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ExceptionTest::~ExceptionTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ExceptionTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ExceptionTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ExceptionTest::testConstructor()
|
||||
{
|
||||
const CPPUNIT_NS::Message message( "a message" );
|
||||
const CPPUNIT_NS::SourceLine sourceLine( "dir/afile.cpp", 17 );
|
||||
|
||||
CPPUNIT_NS::Exception e( message, sourceLine );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( message.shortDescription(), e.message().shortDescription() );
|
||||
CPPUNIT_ASSERT( sourceLine == e.sourceLine() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ExceptionTest::testDefaultConstructor()
|
||||
{
|
||||
CPPUNIT_NS::Exception e;
|
||||
|
||||
CPPUNIT_ASSERT( CPPUNIT_NS::Message() == e.message() );
|
||||
CPPUNIT_ASSERT( !e.sourceLine().isValid() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ExceptionTest::testCopyConstructor()
|
||||
{
|
||||
CPPUNIT_NS::SourceLine sourceLine( "fileName.cpp", 123 );
|
||||
CPPUNIT_NS::Exception e( CPPUNIT_NS::Message("message"), sourceLine );
|
||||
CPPUNIT_NS::Exception other( e );
|
||||
checkIsSame( e, other );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ExceptionTest::testAssignment()
|
||||
{
|
||||
CPPUNIT_NS::SourceLine sourceLine( "fileName.cpp", 123 );
|
||||
CPPUNIT_NS::Exception e( CPPUNIT_NS::Message("message"), sourceLine );
|
||||
CPPUNIT_NS::Exception other;
|
||||
other = e;
|
||||
checkIsSame( e, other );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ExceptionTest::testClone()
|
||||
{
|
||||
CPPUNIT_NS::SourceLine sourceLine( "fileName.cpp", 123 );
|
||||
CPPUNIT_NS::Exception e( CPPUNIT_NS::Message("message"), sourceLine );
|
||||
std::auto_ptr<CPPUNIT_NS::Exception> other( e.clone() );
|
||||
checkIsSame( e, *other.get() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ExceptionTest::checkIsSame( CPPUNIT_NS::Exception &e,
|
||||
CPPUNIT_NS::Exception &other )
|
||||
{
|
||||
std::string eWhat( e.what() );
|
||||
std::string otherWhat( other.what() );
|
||||
CPPUNIT_ASSERT_EQUAL( eWhat, otherWhat );
|
||||
CPPUNIT_ASSERT( e.sourceLine() == other.sourceLine() );
|
||||
}
|
41
examples/cppunittest/ExceptionTest.h
Normal file
41
examples/cppunittest/ExceptionTest.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef EXCEPTIONTEST_H
|
||||
#define EXCEPTIONTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
||||
class ExceptionTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( ExceptionTest );
|
||||
CPPUNIT_TEST( testConstructor );
|
||||
CPPUNIT_TEST( testDefaultConstructor );
|
||||
CPPUNIT_TEST( testCopyConstructor );
|
||||
CPPUNIT_TEST( testAssignment );
|
||||
CPPUNIT_TEST( testClone );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
ExceptionTest();
|
||||
virtual ~ExceptionTest();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
void testConstructor();
|
||||
void testDefaultConstructor();
|
||||
void testCopyConstructor();
|
||||
void testAssignment();
|
||||
void testClone();
|
||||
|
||||
private:
|
||||
ExceptionTest( const ExceptionTest © );
|
||||
void operator =( const ExceptionTest © );
|
||||
void checkIsSame( CPPUNIT_NS::Exception &e,
|
||||
CPPUNIT_NS::Exception &other );
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // EXCEPTIONTEST_H
|
71
examples/cppunittest/ExceptionTestCaseDecoratorTest.cpp
Normal file
71
examples/cppunittest/ExceptionTestCaseDecoratorTest.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
// //////////////////////////////////////////////////////////////////////////
|
||||
// Implementation file ExceptionTestCaseDecoratorTest.cpp for class ExceptionTestCaseDecoratorTest
|
||||
// (c)Copyright 2000, Baptiste Lepilleur.
|
||||
// Created: 2002/08/03
|
||||
// //////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "ExtensionSuite.h"
|
||||
#include "ExceptionTestCaseDecoratorTest.h"
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ExceptionTestCaseDecoratorTest,
|
||||
extensionSuiteName() );
|
||||
|
||||
|
||||
ExceptionTestCaseDecoratorTest::ExceptionTestCaseDecoratorTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ExceptionTestCaseDecoratorTest::~ExceptionTestCaseDecoratorTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ExceptionTestCaseDecoratorTest::setUp()
|
||||
{
|
||||
m_testListener = new MockTestListener( "mock-testlistener" );
|
||||
m_result = new CPPUNIT_NS::TestResult();
|
||||
m_result->addListener( m_testListener );
|
||||
|
||||
m_test = new MockTestCase( "mock-decorated-testcase" );
|
||||
m_decorator = new FailureExceptionTestCase( m_test );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ExceptionTestCaseDecoratorTest::tearDown()
|
||||
{
|
||||
delete m_decorator;
|
||||
delete m_result;
|
||||
delete m_testListener;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ExceptionTestCaseDecoratorTest::testNoExceptionThrownFailed()
|
||||
{
|
||||
m_testListener->setExpectedAddFailureCall(1);
|
||||
m_test->setExpectedSetUpCall();
|
||||
m_test->setExpectedRunTestCall();
|
||||
m_test->setExpectedTearDownCall();
|
||||
|
||||
m_decorator->run( m_result );
|
||||
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ExceptionTestCaseDecoratorTest::testExceptionThrownPass()
|
||||
{
|
||||
m_testListener->setExpectNoFailure();
|
||||
m_test->setExpectedSetUpCall();
|
||||
m_test->setExpectedRunTestCall();
|
||||
m_test->setExpectedTearDownCall();
|
||||
m_test->makeRunTestThrow();
|
||||
|
||||
m_decorator->run( m_result );
|
||||
|
||||
m_testListener->verify();
|
||||
}
|
61
examples/cppunittest/ExceptionTestCaseDecoratorTest.h
Normal file
61
examples/cppunittest/ExceptionTestCaseDecoratorTest.h
Normal file
@@ -0,0 +1,61 @@
|
||||
// //////////////////////////////////////////////////////////////////////////
|
||||
// Header file ExceptionTestCaseDecoratorTest.h for class ExceptionTestCaseDecoratorTest
|
||||
// (c)Copyright 2000, Baptiste Lepilleur.
|
||||
// Created: 2002/08/03
|
||||
// //////////////////////////////////////////////////////////////////////////
|
||||
#ifndef EXCEPTIONTESTCASEDECORATORTEST_H
|
||||
#define EXCEPTIONTESTCASEDECORATORTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/TestResult.h>
|
||||
#include "FailureException.h"
|
||||
#include "MockTestCase.h"
|
||||
#include "MockTestListener.h"
|
||||
|
||||
|
||||
/// Unit tests for ExceptionTestCaseDecoratorTest
|
||||
class ExceptionTestCaseDecoratorTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( ExceptionTestCaseDecoratorTest );
|
||||
CPPUNIT_TEST( testNoExceptionThrownFailed );
|
||||
CPPUNIT_TEST( testExceptionThrownPass );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
/*! Constructs a ExceptionTestCaseDecoratorTest object.
|
||||
*/
|
||||
ExceptionTestCaseDecoratorTest();
|
||||
|
||||
/// Destructor.
|
||||
virtual ~ExceptionTestCaseDecoratorTest();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
void testNoExceptionThrownFailed();
|
||||
void testExceptionThrownPass();
|
||||
|
||||
private:
|
||||
/// Prevents the use of the copy constructor.
|
||||
ExceptionTestCaseDecoratorTest( const ExceptionTestCaseDecoratorTest &other );
|
||||
|
||||
/// Prevents the use of the copy operator.
|
||||
void operator =( const ExceptionTestCaseDecoratorTest &other );
|
||||
|
||||
private:
|
||||
typedef CPPUNIT_NS::ExceptionTestCaseDecorator<FailureException> FailureExceptionTestCase;
|
||||
|
||||
CPPUNIT_NS::TestResult *m_result;
|
||||
MockTestListener *m_testListener;
|
||||
MockTestCase *m_test;
|
||||
FailureExceptionTestCase *m_decorator;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Inlines methods for ExceptionTestCaseDecoratorTest:
|
||||
// ---------------------------------------------------
|
||||
|
||||
|
||||
|
||||
#endif // EXCEPTIONTESTCASEDECORATORTEST_H
|
12
examples/cppunittest/ExtensionSuite.h
Normal file
12
examples/cppunittest/ExtensionSuite.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef CPPUNITTEST_EXTENSIONSSUITE_H
|
||||
#define CPPUNITTEST_EXTENSIONSSUITE_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <string>
|
||||
|
||||
inline std::string extensionSuiteName()
|
||||
{
|
||||
return "Extensions";
|
||||
}
|
||||
|
||||
#endif // CPPUNITTEST_EXTENSIONSSUITE_H
|
10
examples/cppunittest/FailureException.h
Normal file
10
examples/cppunittest/FailureException.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef FAILUREEXCEPTION_H
|
||||
#define FAILUREEXCEPTION_H
|
||||
|
||||
|
||||
class FailureException
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
#endif // FAILUREEXCEPTION_H
|
227
examples/cppunittest/HelperMacrosTest.cpp
Normal file
227
examples/cppunittest/HelperMacrosTest.cpp
Normal file
@@ -0,0 +1,227 @@
|
||||
#include <cppunit/config/SourcePrefix.h>
|
||||
#include "FailureException.h"
|
||||
#include "HelperMacrosTest.h"
|
||||
#include "HelperSuite.h"
|
||||
#include "MockTestCase.h"
|
||||
#include "SubclassedTestCase.h"
|
||||
#include <cppunit/TestResult.h>
|
||||
#include <memory>
|
||||
|
||||
/* Note:
|
||||
- no unit test for CPPUNIT_TEST_SUITE_REGISTRATION...
|
||||
*/
|
||||
|
||||
class FailTestFixture : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( FailTestFixture );
|
||||
CPPUNIT_TEST_FAIL( testFail );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
void testFail()
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE( "Failure", false );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class FailToFailTestFixture : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( FailToFailTestFixture );
|
||||
CPPUNIT_TEST_FAIL( testFailToFail );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
void testFailToFail()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ExceptionTestFixture : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( ExceptionTestFixture );
|
||||
CPPUNIT_TEST_EXCEPTION( testException, FailureException );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
void testException()
|
||||
{
|
||||
throw FailureException();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ExceptionNotCaughtTestFixture : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( ExceptionNotCaughtTestFixture );
|
||||
CPPUNIT_TEST_EXCEPTION( testExceptionNotCaught, FailureException );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
void testExceptionNotCaught()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class CustomsTestTestFixture : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( CustomsTestTestFixture );
|
||||
CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( addCustomTests );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
static void addCustomTests( TestSuiteBuilderContextType &context )
|
||||
{
|
||||
MockTestCase *test1 = new MockTestCase( context.getTestNameFor( "myCustomTest1" ) );
|
||||
test1->makeRunTestThrow();
|
||||
MockTestCase *test2 = new MockTestCase( context.getTestNameFor( "myCustomTest2" ) );
|
||||
context.addTest( test1 );
|
||||
context.addTest( test2 );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#undef TEST_ADD_N_MOCK
|
||||
#define TEST_ADD_N_MOCK( totalCount ) \
|
||||
{ \
|
||||
for ( int count = (totalCount); count > 0; --count ) \
|
||||
CPPUNIT_TEST_SUITE_ADD_TEST( \
|
||||
new MockTestCase( context.getTestNameFor( "dummyName" ) ) ); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
class AddTestTestFixture : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( AddTestTestFixture );
|
||||
TEST_ADD_N_MOCK( 7 );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HelperMacrosTest,
|
||||
helperSuiteName() );
|
||||
|
||||
|
||||
HelperMacrosTest::HelperMacrosTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HelperMacrosTest::~HelperMacrosTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HelperMacrosTest::setUp()
|
||||
{
|
||||
m_testListener = new MockTestListener( "mock-testlistener" );
|
||||
m_result = new CPPUNIT_NS::TestResult();
|
||||
m_result->addListener( m_testListener );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HelperMacrosTest::tearDown()
|
||||
{
|
||||
delete m_result;
|
||||
delete m_testListener;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HelperMacrosTest::testNoSubclassing()
|
||||
{
|
||||
std::auto_ptr<CPPUNIT_NS::TestSuite> suite( BaseTestCase::suite() );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, suite->countTestCases() );
|
||||
m_testListener->setExpectedStartTestCall( 1 );
|
||||
m_testListener->setExpectNoFailure();
|
||||
|
||||
suite->run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HelperMacrosTest::testSubclassing()
|
||||
{
|
||||
std::auto_ptr<CPPUNIT_NS::TestSuite> suite( SubclassedTestCase::suite() );
|
||||
CPPUNIT_ASSERT_EQUAL( 2, suite->countTestCases() );
|
||||
m_testListener->setExpectedStartTestCall( 2 );
|
||||
m_testListener->setExpectedAddFailureCall( 1 );
|
||||
|
||||
suite->run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HelperMacrosTest::testFail()
|
||||
{
|
||||
std::auto_ptr<CPPUNIT_NS::TestSuite> suite( FailTestFixture::suite() );
|
||||
m_testListener->setExpectedStartTestCall( 1 );
|
||||
m_testListener->setExpectNoFailure();
|
||||
|
||||
suite->run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HelperMacrosTest::testFailToFail()
|
||||
{
|
||||
std::auto_ptr<CPPUNIT_NS::TestSuite> suite( FailToFailTestFixture::suite() );
|
||||
m_testListener->setExpectedStartTestCall( 1 );
|
||||
m_testListener->setExpectedAddFailureCall( 1 );
|
||||
|
||||
suite->run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HelperMacrosTest::testException()
|
||||
{
|
||||
std::auto_ptr<CPPUNIT_NS::TestSuite> suite( ExceptionTestFixture::suite() );
|
||||
m_testListener->setExpectedStartTestCall( 1 );
|
||||
m_testListener->setExpectNoFailure();
|
||||
|
||||
suite->run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HelperMacrosTest::testExceptionNotCaught()
|
||||
{
|
||||
std::auto_ptr<CPPUNIT_NS::TestSuite> suite( ExceptionNotCaughtTestFixture::suite() );
|
||||
m_testListener->setExpectedStartTestCall( 1 );
|
||||
m_testListener->setExpectedAddFailureCall( 1 );
|
||||
|
||||
suite->run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HelperMacrosTest::testCustomTests()
|
||||
{
|
||||
std::auto_ptr<CPPUNIT_NS::TestSuite> suite( CustomsTestTestFixture::suite() );
|
||||
m_testListener->setExpectedStartTestCall( 2 );
|
||||
m_testListener->setExpectedAddFailureCall( 1 );
|
||||
|
||||
suite->run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HelperMacrosTest::testAddTest()
|
||||
{
|
||||
std::auto_ptr<CPPUNIT_NS::TestSuite> suite( AddTestTestFixture::suite() );
|
||||
m_testListener->setExpectedStartTestCall( 7 );
|
||||
m_testListener->setExpectedAddFailureCall( 0 );
|
||||
|
||||
suite->run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
53
examples/cppunittest/HelperMacrosTest.h
Normal file
53
examples/cppunittest/HelperMacrosTest.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef HELPERMACROSTEST_H
|
||||
#define HELPERMACROSTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include "MockTestListener.h"
|
||||
|
||||
|
||||
class HelperMacrosTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( HelperMacrosTest );
|
||||
CPPUNIT_TEST( testNoSubclassing );
|
||||
CPPUNIT_TEST( testSubclassing );
|
||||
CPPUNIT_TEST( testFail );
|
||||
CPPUNIT_TEST( testFailToFail );
|
||||
CPPUNIT_TEST( testException );
|
||||
CPPUNIT_TEST( testExceptionNotCaught );
|
||||
CPPUNIT_TEST( testCustomTests );
|
||||
CPPUNIT_TEST( testAddTest );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
HelperMacrosTest();
|
||||
virtual ~HelperMacrosTest();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
void testNoSubclassing();
|
||||
|
||||
void testSubclassing();
|
||||
|
||||
void testFail();
|
||||
void testFailToFail();
|
||||
|
||||
void testException();
|
||||
void testExceptionNotCaught();
|
||||
|
||||
void testCustomTest();
|
||||
void testCustomTests();
|
||||
void testAddTest();
|
||||
|
||||
private:
|
||||
HelperMacrosTest( const HelperMacrosTest © );
|
||||
void operator =( const HelperMacrosTest © );
|
||||
|
||||
private:
|
||||
CPPUNIT_NS::TestResult *m_result;
|
||||
MockTestListener *m_testListener;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // HELPERMACROSTEST_H
|
13
examples/cppunittest/HelperSuite.h
Normal file
13
examples/cppunittest/HelperSuite.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef CPPUNITTEST_HELPERSUITE_H
|
||||
#define CPPUNITTEST_HELPERSUITE_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <string>
|
||||
|
||||
inline std::string helperSuiteName()
|
||||
{
|
||||
return "Helpers";
|
||||
}
|
||||
|
||||
|
||||
#endif // CPPUNITTEST_HELPERSUITE_H
|
83
examples/cppunittest/Makefile.am
Normal file
83
examples/cppunittest/Makefile.am
Normal file
@@ -0,0 +1,83 @@
|
||||
EXTRA_DIST = CppUnitTestMain.dsw CppUnitTestMain.dsp CppUnitTestPlugIn.dsp CppUnitTestPlugIn.cpp
|
||||
|
||||
TESTS = cppunittestmain
|
||||
check_PROGRAMS = $(TESTS)
|
||||
|
||||
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include
|
||||
|
||||
cppunittestmain_SOURCES = \
|
||||
assertion_traitsTest.cpp \
|
||||
assertion_traitsTest.h \
|
||||
BaseTestCase.cpp \
|
||||
BaseTestCase.h \
|
||||
CoreSuite.h \
|
||||
CppUnitTestMain.cpp \
|
||||
CppUnitTestSuite.cpp \
|
||||
ExceptionTest.cpp \
|
||||
ExceptionTest.h \
|
||||
ExceptionTestCaseDecoratorTest.h \
|
||||
ExceptionTestCaseDecoratorTest.cpp \
|
||||
ExtensionSuite.h \
|
||||
FailureException.h \
|
||||
HelperMacrosTest.cpp \
|
||||
HelperMacrosTest.h \
|
||||
HelperSuite.h \
|
||||
MessageTest.h \
|
||||
MessageTest.cpp \
|
||||
MockFunctor.h \
|
||||
MockProtector.h \
|
||||
MockTestCase.h \
|
||||
MockTestCase.cpp \
|
||||
MockTestListener.cpp \
|
||||
MockTestListener.h \
|
||||
OrthodoxTest.cpp \
|
||||
OrthodoxTest.h \
|
||||
OutputSuite.h \
|
||||
RepeatedTestTest.cpp \
|
||||
RepeatedTestTest.h \
|
||||
StringToolsTest.h \
|
||||
StringToolsTest.cpp \
|
||||
SubclassedTestCase.cpp \
|
||||
SubclassedTestCase.h \
|
||||
SynchronizedTestResult.h \
|
||||
TestAssertTest.cpp \
|
||||
TestAssertTest.h \
|
||||
TestCallerTest.cpp \
|
||||
TestCallerTest.h \
|
||||
TestCaseTest.cpp \
|
||||
TestCaseTest.h \
|
||||
TestDecoratorTest.cpp \
|
||||
TestDecoratorTest.h \
|
||||
TestFailureTest.cpp \
|
||||
TestFailureTest.h \
|
||||
TestPathTest.h \
|
||||
TestPathTest.cpp \
|
||||
TestResultCollectorTest.cpp \
|
||||
TestResultCollectorTest.h \
|
||||
TestResultTest.cpp \
|
||||
TestResultTest.h \
|
||||
TestSetUpTest.cpp \
|
||||
TestSetUpTest.h \
|
||||
TestSuiteTest.cpp \
|
||||
TestSuiteTest.h \
|
||||
TestTest.cpp \
|
||||
TestTest.h \
|
||||
ToolsSuite.h \
|
||||
TrackedTestCase.cpp \
|
||||
TrackedTestCase.h \
|
||||
UnitTestToolSuite.h \
|
||||
XmlElementTest.h \
|
||||
XmlElementTest.cpp \
|
||||
XmlOutputterTest.h \
|
||||
XmlOutputterTest.cpp \
|
||||
XmlUniformiser.h \
|
||||
XmlUniformiser.cpp \
|
||||
XmlUniformiserTest.h \
|
||||
XmlUniformiserTest.cpp
|
||||
|
||||
cppunittestmain_LDADD= \
|
||||
$(top_builddir)/src/cppunit/libcppunit.la
|
||||
|
||||
cppunittestmain_LDFLAGS = $(LIBADD_DL)
|
||||
|
||||
|
669
examples/cppunittest/Makefile.in
Normal file
669
examples/cppunittest/Makefile.in
Normal file
@@ -0,0 +1,669 @@
|
||||
# Makefile.in generated by automake 1.10.1 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
@SET_MAKE@
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
TESTS = cppunittestmain$(EXEEXT)
|
||||
check_PROGRAMS = $(am__EXEEXT_1)
|
||||
subdir = examples/cppunittest
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = \
|
||||
$(top_srcdir)/config/ac_create_prefix_config_h.m4 \
|
||||
$(top_srcdir)/config/ac_cxx_have_sstream.m4 \
|
||||
$(top_srcdir)/config/ac_cxx_have_strstream.m4 \
|
||||
$(top_srcdir)/config/ac_cxx_namespaces.m4 \
|
||||
$(top_srcdir)/config/ac_cxx_rtti.m4 \
|
||||
$(top_srcdir)/config/ac_cxx_string_compare_string_first.m4 \
|
||||
$(top_srcdir)/config/ac_dll.m4 \
|
||||
$(top_srcdir)/config/ax_cxx_gcc_abi_demangle.m4 \
|
||||
$(top_srcdir)/config/ax_cxx_have_isfinite.m4 \
|
||||
$(top_srcdir)/config/bb_enable_doxygen.m4 \
|
||||
$(top_srcdir)/configure.in
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_HEADER = $(top_builddir)/config/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
am__EXEEXT_1 = cppunittestmain$(EXEEXT)
|
||||
am_cppunittestmain_OBJECTS = assertion_traitsTest.$(OBJEXT) \
|
||||
BaseTestCase.$(OBJEXT) CppUnitTestMain.$(OBJEXT) \
|
||||
CppUnitTestSuite.$(OBJEXT) ExceptionTest.$(OBJEXT) \
|
||||
ExceptionTestCaseDecoratorTest.$(OBJEXT) \
|
||||
HelperMacrosTest.$(OBJEXT) MessageTest.$(OBJEXT) \
|
||||
MockTestCase.$(OBJEXT) MockTestListener.$(OBJEXT) \
|
||||
OrthodoxTest.$(OBJEXT) RepeatedTestTest.$(OBJEXT) \
|
||||
StringToolsTest.$(OBJEXT) SubclassedTestCase.$(OBJEXT) \
|
||||
TestAssertTest.$(OBJEXT) TestCallerTest.$(OBJEXT) \
|
||||
TestCaseTest.$(OBJEXT) TestDecoratorTest.$(OBJEXT) \
|
||||
TestFailureTest.$(OBJEXT) TestPathTest.$(OBJEXT) \
|
||||
TestResultCollectorTest.$(OBJEXT) TestResultTest.$(OBJEXT) \
|
||||
TestSetUpTest.$(OBJEXT) TestSuiteTest.$(OBJEXT) \
|
||||
TestTest.$(OBJEXT) TrackedTestCase.$(OBJEXT) \
|
||||
XmlElementTest.$(OBJEXT) XmlOutputterTest.$(OBJEXT) \
|
||||
XmlUniformiser.$(OBJEXT) XmlUniformiserTest.$(OBJEXT)
|
||||
cppunittestmain_OBJECTS = $(am_cppunittestmain_OBJECTS)
|
||||
cppunittestmain_DEPENDENCIES = \
|
||||
$(top_builddir)/src/cppunit/libcppunit.la
|
||||
cppunittestmain_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
|
||||
$(CXXFLAGS) $(cppunittestmain_LDFLAGS) $(LDFLAGS) -o $@
|
||||
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/config
|
||||
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
|
||||
LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
|
||||
CXXLD = $(CXX)
|
||||
CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
SOURCES = $(cppunittestmain_SOURCES)
|
||||
DIST_SOURCES = $(cppunittestmain_SOURCES)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMTAR = @AMTAR@
|
||||
AR = @AR@
|
||||
AS = @AS@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CPPUNIT_BINARY_AGE = @CPPUNIT_BINARY_AGE@
|
||||
CPPUNIT_INTERFACE_AGE = @CPPUNIT_INTERFACE_AGE@
|
||||
CPPUNIT_MAJOR_VERSION = @CPPUNIT_MAJOR_VERSION@
|
||||
CPPUNIT_MICRO_VERSION = @CPPUNIT_MICRO_VERSION@
|
||||
CPPUNIT_MINOR_VERSION = @CPPUNIT_MINOR_VERSION@
|
||||
CPPUNIT_VERSION = @CPPUNIT_VERSION@
|
||||
CXX = @CXX@
|
||||
CXXCPP = @CXXCPP@
|
||||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DLLTOOL = @DLLTOOL@
|
||||
DOT = @DOT@
|
||||
DOXYGEN = @DOXYGEN@
|
||||
DSYMUTIL = @DSYMUTIL@
|
||||
ECHO = @ECHO@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
F77 = @F77@
|
||||
FFLAGS = @FFLAGS@
|
||||
GREP = @GREP@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBADD_DL = @LIBADD_DL@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
LT_AGE = @LT_AGE@
|
||||
LT_CURRENT = @LT_CURRENT@
|
||||
LT_RELEASE = @LT_RELEASE@
|
||||
LT_REVISION = @LT_REVISION@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MKDIR_P = @MKDIR_P@
|
||||
NMEDIT = @NMEDIT@
|
||||
OBJDUMP = @OBJDUMP@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
RANLIB = @RANLIB@
|
||||
SED = @SED@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
abs_builddir = @abs_builddir@
|
||||
abs_srcdir = @abs_srcdir@
|
||||
abs_top_builddir = @abs_top_builddir@
|
||||
abs_top_srcdir = @abs_top_srcdir@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_CXX = @ac_ct_CXX@
|
||||
ac_ct_F77 = @ac_ct_F77@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
builddir = @builddir@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
docdir = @docdir@
|
||||
dvidir = @dvidir@
|
||||
enable_dot = @enable_dot@
|
||||
enable_html_docs = @enable_html_docs@
|
||||
enable_latex_docs = @enable_latex_docs@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
htmldir = @htmldir@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
EXTRA_DIST = CppUnitTestMain.dsw CppUnitTestMain.dsp CppUnitTestPlugIn.dsp CppUnitTestPlugIn.cpp
|
||||
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include
|
||||
cppunittestmain_SOURCES = \
|
||||
assertion_traitsTest.cpp \
|
||||
assertion_traitsTest.h \
|
||||
BaseTestCase.cpp \
|
||||
BaseTestCase.h \
|
||||
CoreSuite.h \
|
||||
CppUnitTestMain.cpp \
|
||||
CppUnitTestSuite.cpp \
|
||||
ExceptionTest.cpp \
|
||||
ExceptionTest.h \
|
||||
ExceptionTestCaseDecoratorTest.h \
|
||||
ExceptionTestCaseDecoratorTest.cpp \
|
||||
ExtensionSuite.h \
|
||||
FailureException.h \
|
||||
HelperMacrosTest.cpp \
|
||||
HelperMacrosTest.h \
|
||||
HelperSuite.h \
|
||||
MessageTest.h \
|
||||
MessageTest.cpp \
|
||||
MockFunctor.h \
|
||||
MockProtector.h \
|
||||
MockTestCase.h \
|
||||
MockTestCase.cpp \
|
||||
MockTestListener.cpp \
|
||||
MockTestListener.h \
|
||||
OrthodoxTest.cpp \
|
||||
OrthodoxTest.h \
|
||||
OutputSuite.h \
|
||||
RepeatedTestTest.cpp \
|
||||
RepeatedTestTest.h \
|
||||
StringToolsTest.h \
|
||||
StringToolsTest.cpp \
|
||||
SubclassedTestCase.cpp \
|
||||
SubclassedTestCase.h \
|
||||
SynchronizedTestResult.h \
|
||||
TestAssertTest.cpp \
|
||||
TestAssertTest.h \
|
||||
TestCallerTest.cpp \
|
||||
TestCallerTest.h \
|
||||
TestCaseTest.cpp \
|
||||
TestCaseTest.h \
|
||||
TestDecoratorTest.cpp \
|
||||
TestDecoratorTest.h \
|
||||
TestFailureTest.cpp \
|
||||
TestFailureTest.h \
|
||||
TestPathTest.h \
|
||||
TestPathTest.cpp \
|
||||
TestResultCollectorTest.cpp \
|
||||
TestResultCollectorTest.h \
|
||||
TestResultTest.cpp \
|
||||
TestResultTest.h \
|
||||
TestSetUpTest.cpp \
|
||||
TestSetUpTest.h \
|
||||
TestSuiteTest.cpp \
|
||||
TestSuiteTest.h \
|
||||
TestTest.cpp \
|
||||
TestTest.h \
|
||||
ToolsSuite.h \
|
||||
TrackedTestCase.cpp \
|
||||
TrackedTestCase.h \
|
||||
UnitTestToolSuite.h \
|
||||
XmlElementTest.h \
|
||||
XmlElementTest.cpp \
|
||||
XmlOutputterTest.h \
|
||||
XmlOutputterTest.cpp \
|
||||
XmlUniformiser.h \
|
||||
XmlUniformiser.cpp \
|
||||
XmlUniformiserTest.h \
|
||||
XmlUniformiserTest.cpp
|
||||
|
||||
cppunittestmain_LDADD = \
|
||||
$(top_builddir)/src/cppunit/libcppunit.la
|
||||
|
||||
cppunittestmain_LDFLAGS = $(LIBADD_DL)
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .cpp .lo .o .obj
|
||||
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
|
||||
&& exit 0; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu examples/cppunittest/Makefile'; \
|
||||
cd $(top_srcdir) && \
|
||||
$(AUTOMAKE) --gnu examples/cppunittest/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
clean-checkPROGRAMS:
|
||||
@list='$(check_PROGRAMS)'; for p in $$list; do \
|
||||
f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
|
||||
echo " rm -f $$p $$f"; \
|
||||
rm -f $$p $$f ; \
|
||||
done
|
||||
cppunittestmain$(EXEEXT): $(cppunittestmain_OBJECTS) $(cppunittestmain_DEPENDENCIES)
|
||||
@rm -f cppunittestmain$(EXEEXT)
|
||||
$(cppunittestmain_LINK) $(cppunittestmain_OBJECTS) $(cppunittestmain_LDADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BaseTestCase.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CppUnitTestMain.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CppUnitTestSuite.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ExceptionTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ExceptionTestCaseDecoratorTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HelperMacrosTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MessageTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MockTestCase.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MockTestListener.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/OrthodoxTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RepeatedTestTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StringToolsTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SubclassedTestCase.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TestAssertTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TestCallerTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TestCaseTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TestDecoratorTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TestFailureTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TestPathTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TestResultCollectorTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TestResultTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TestSetUpTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TestSuiteTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TestTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TrackedTestCase.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/XmlElementTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/XmlOutputterTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/XmlUniformiser.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/XmlUniformiserTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/assertion_traitsTest.Po@am__quote@
|
||||
|
||||
.cpp.o:
|
||||
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
|
||||
|
||||
.cpp.obj:
|
||||
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
|
||||
.cpp.lo:
|
||||
@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $<
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
clean-libtool:
|
||||
-rm -rf .libs _libs
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
mkid -fID $$unique
|
||||
tags: TAGS
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$tags $$unique; \
|
||||
fi
|
||||
ctags: CTAGS
|
||||
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$tags $$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& cd $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) $$here
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
check-TESTS: $(TESTS)
|
||||
@failed=0; all=0; xfail=0; xpass=0; skip=0; ws='[ ]'; \
|
||||
srcdir=$(srcdir); export srcdir; \
|
||||
list=' $(TESTS) '; \
|
||||
if test -n "$$list"; then \
|
||||
for tst in $$list; do \
|
||||
if test -f ./$$tst; then dir=./; \
|
||||
elif test -f $$tst; then dir=; \
|
||||
else dir="$(srcdir)/"; fi; \
|
||||
if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \
|
||||
all=`expr $$all + 1`; \
|
||||
case " $(XFAIL_TESTS) " in \
|
||||
*$$ws$$tst$$ws*) \
|
||||
xpass=`expr $$xpass + 1`; \
|
||||
failed=`expr $$failed + 1`; \
|
||||
echo "XPASS: $$tst"; \
|
||||
;; \
|
||||
*) \
|
||||
echo "PASS: $$tst"; \
|
||||
;; \
|
||||
esac; \
|
||||
elif test $$? -ne 77; then \
|
||||
all=`expr $$all + 1`; \
|
||||
case " $(XFAIL_TESTS) " in \
|
||||
*$$ws$$tst$$ws*) \
|
||||
xfail=`expr $$xfail + 1`; \
|
||||
echo "XFAIL: $$tst"; \
|
||||
;; \
|
||||
*) \
|
||||
failed=`expr $$failed + 1`; \
|
||||
echo "FAIL: $$tst"; \
|
||||
;; \
|
||||
esac; \
|
||||
else \
|
||||
skip=`expr $$skip + 1`; \
|
||||
echo "SKIP: $$tst"; \
|
||||
fi; \
|
||||
done; \
|
||||
if test "$$failed" -eq 0; then \
|
||||
if test "$$xfail" -eq 0; then \
|
||||
banner="All $$all tests passed"; \
|
||||
else \
|
||||
banner="All $$all tests behaved as expected ($$xfail expected failures)"; \
|
||||
fi; \
|
||||
else \
|
||||
if test "$$xpass" -eq 0; then \
|
||||
banner="$$failed of $$all tests failed"; \
|
||||
else \
|
||||
banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \
|
||||
fi; \
|
||||
fi; \
|
||||
dashes="$$banner"; \
|
||||
skipped=""; \
|
||||
if test "$$skip" -ne 0; then \
|
||||
skipped="($$skip tests were not run)"; \
|
||||
test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
|
||||
dashes="$$skipped"; \
|
||||
fi; \
|
||||
report=""; \
|
||||
if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
|
||||
report="Please report to $(PACKAGE_BUGREPORT)"; \
|
||||
test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
|
||||
dashes="$$report"; \
|
||||
fi; \
|
||||
dashes=`echo "$$dashes" | sed s/./=/g`; \
|
||||
echo "$$dashes"; \
|
||||
echo "$$banner"; \
|
||||
test -z "$$skipped" || echo "$$skipped"; \
|
||||
test -z "$$report" || echo "$$report"; \
|
||||
echo "$$dashes"; \
|
||||
test "$$failed" -eq 0; \
|
||||
else :; fi
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
list='$(DISTFILES)'; \
|
||||
dist_files=`for file in $$list; do echo $$file; done | \
|
||||
sed -e "s|^$$srcdirstrip/||;t" \
|
||||
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
|
||||
case $$dist_files in \
|
||||
*/*) $(MKDIR_P) `echo "$$dist_files" | \
|
||||
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
|
||||
sort -u` ;; \
|
||||
esac; \
|
||||
for file in $$dist_files; do \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
|
||||
fi; \
|
||||
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
check-am: all-am
|
||||
$(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS)
|
||||
$(MAKE) $(AM_MAKEFLAGS) check-TESTS
|
||||
check: check-am
|
||||
all-am: Makefile
|
||||
installdirs:
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
`test -z '$(STRIP)' || \
|
||||
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-checkPROGRAMS clean-generic clean-libtool \
|
||||
mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am:
|
||||
|
||||
install-dvi: install-dvi-am
|
||||
|
||||
install-exec-am:
|
||||
|
||||
install-html: install-html-am
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-man:
|
||||
|
||||
install-pdf: install-pdf-am
|
||||
|
||||
install-ps: install-ps-am
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
|
||||
mostlyclean-libtool
|
||||
|
||||
pdf: pdf-am
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-am
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am:
|
||||
|
||||
.MAKE: install-am install-strip
|
||||
|
||||
.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \
|
||||
clean-checkPROGRAMS clean-generic clean-libtool ctags \
|
||||
distclean distclean-compile distclean-generic \
|
||||
distclean-libtool distclean-tags distdir dvi dvi-am html \
|
||||
html-am info info-am install install-am install-data \
|
||||
install-data-am install-dvi install-dvi-am install-exec \
|
||||
install-exec-am install-html install-html-am install-info \
|
||||
install-info-am install-man install-pdf install-pdf-am \
|
||||
install-ps install-ps-am install-strip installcheck \
|
||||
installcheck-am installdirs maintainer-clean \
|
||||
maintainer-clean-generic mostlyclean mostlyclean-compile \
|
||||
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
|
||||
tags uninstall uninstall-am
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
234
examples/cppunittest/MessageTest.cpp
Normal file
234
examples/cppunittest/MessageTest.cpp
Normal file
@@ -0,0 +1,234 @@
|
||||
#include "CoreSuite.h"
|
||||
#include "MessageTest.h"
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MessageTest,
|
||||
coreSuiteName() );
|
||||
|
||||
|
||||
MessageTest::MessageTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MessageTest::~MessageTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::setUp()
|
||||
{
|
||||
m_message = new CPPUNIT_NS::Message();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::tearDown()
|
||||
{
|
||||
delete m_message;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testDefaultConstructor()
|
||||
{
|
||||
std::string empty;
|
||||
CPPUNIT_ASSERT_EQUAL( empty, m_message->shortDescription() );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, m_message->detailCount() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testDetailAtThrowIfBadIndex()
|
||||
{
|
||||
m_message->detailAt( -1 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testDetailAtThrowIfBadIndex2()
|
||||
{
|
||||
m_message->detailAt( 0 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testAddDetail()
|
||||
{
|
||||
std::string expected( "first" );
|
||||
m_message->addDetail( expected );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, m_message->detailCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( expected, m_message->detailAt(0) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testAddDetail2()
|
||||
{
|
||||
std::string expected1( "first" );
|
||||
std::string expected2( "second" );
|
||||
m_message->addDetail( expected1, expected2 );
|
||||
CPPUNIT_ASSERT_EQUAL( 2, m_message->detailCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( expected1, m_message->detailAt(0) );
|
||||
CPPUNIT_ASSERT_EQUAL( expected2, m_message->detailAt(1) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testAddDetail3()
|
||||
{
|
||||
std::string expected1( "first" );
|
||||
std::string expected2( "second" );
|
||||
std::string expected3( "third" );
|
||||
m_message->addDetail( expected1, expected2, expected3 );
|
||||
CPPUNIT_ASSERT_EQUAL( 3, m_message->detailCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( expected1, m_message->detailAt(0) );
|
||||
CPPUNIT_ASSERT_EQUAL( expected2, m_message->detailAt(1) );
|
||||
CPPUNIT_ASSERT_EQUAL( expected3, m_message->detailAt(2) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testAddDetailEmptyMessage()
|
||||
{
|
||||
m_message->addDetail( CPPUNIT_NS::Message() );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, m_message->detailCount() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testAddDetailMessage()
|
||||
{
|
||||
std::string expected1( "first" );
|
||||
std::string expected2( "second" );
|
||||
m_message->addDetail( CPPUNIT_NS::Message( "shortDesc", expected1, expected2 ) );
|
||||
CPPUNIT_ASSERT_EQUAL( 2, m_message->detailCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( expected1, m_message->detailAt(0) );
|
||||
CPPUNIT_ASSERT_EQUAL( expected2, m_message->detailAt(1) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testSetShortDescription()
|
||||
{
|
||||
std::string expected( "shortDesc" );
|
||||
m_message->setShortDescription( expected );
|
||||
CPPUNIT_ASSERT_EQUAL( expected, m_message->shortDescription() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testClearDetails()
|
||||
{
|
||||
m_message->addDetail( "detail1" );
|
||||
m_message->clearDetails();
|
||||
CPPUNIT_ASSERT_EQUAL( 0, m_message->detailCount() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testConstructor()
|
||||
{
|
||||
std::string expected( "short" );
|
||||
CPPUNIT_NS::Message message( expected );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( expected, message.shortDescription() );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, message.detailCount() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testConstructorDetail1()
|
||||
{
|
||||
std::string expected( "short" );
|
||||
std::string expected1( "detail-1" );
|
||||
CPPUNIT_NS::Message message( expected, expected1 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( expected, message.shortDescription() );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, message.detailCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( expected1, message.detailAt(0) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testConstructorDetail2()
|
||||
{
|
||||
std::string expected( "short" );
|
||||
std::string expected1( "detail-1" );
|
||||
std::string expected2( "detail-2" );
|
||||
CPPUNIT_NS::Message message( expected, expected1, expected2 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( expected, message.shortDescription() );
|
||||
CPPUNIT_ASSERT_EQUAL( 2, message.detailCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( expected1, message.detailAt(0) );
|
||||
CPPUNIT_ASSERT_EQUAL( expected2, message.detailAt(1) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testConstructorDetail3()
|
||||
{
|
||||
std::string expected( "short" );
|
||||
std::string expected1( "detail-1" );
|
||||
std::string expected2( "detail-2" );
|
||||
std::string expected3( "detail-3" );
|
||||
CPPUNIT_NS::Message message( expected, expected1, expected2, expected3 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( expected, message.shortDescription() );
|
||||
CPPUNIT_ASSERT_EQUAL( 3, message.detailCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( expected1, message.detailAt(0) );
|
||||
CPPUNIT_ASSERT_EQUAL( expected2, message.detailAt(1) );
|
||||
CPPUNIT_ASSERT_EQUAL( expected3, message.detailAt(2) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testDetailsNone()
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE("012345678901234",true);
|
||||
std::string empty;
|
||||
CPPUNIT_ASSERT_EQUAL( empty, m_message->details() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testDetailsSome()
|
||||
{
|
||||
m_message->addDetail( "Expected: 1", "Actual: 7", "Info: number" );
|
||||
std::string expected( "- Expected: 1\n- Actual: 7\n- Info: number\n" );
|
||||
std::string actual = m_message->details();
|
||||
CPPUNIT_ASSERT_EQUAL( expected, actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testEqual()
|
||||
{
|
||||
CPPUNIT_ASSERT( *m_message == CPPUNIT_NS::Message() );
|
||||
|
||||
CPPUNIT_NS::Message message1( "short", "det1", "det2", "det3" );
|
||||
CPPUNIT_NS::Message message2( message1 );
|
||||
CPPUNIT_ASSERT( message1 == message2 );
|
||||
|
||||
CPPUNIT_ASSERT( !(*m_message == message1) );
|
||||
|
||||
CPPUNIT_NS::Message message3( "short" );
|
||||
CPPUNIT_ASSERT( !(message3 == message1) );
|
||||
|
||||
CPPUNIT_NS::Message message4( "long" );
|
||||
CPPUNIT_ASSERT( !(message3 == message4) );
|
||||
|
||||
CPPUNIT_NS::Message message5( "short", "det1", "det-2", "det3" );
|
||||
CPPUNIT_ASSERT( !(message1 == message5) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MessageTest::testNotEqual()
|
||||
{
|
||||
CPPUNIT_NS::Message message1( "short", "det1", "det2", "det3" );
|
||||
CPPUNIT_NS::Message message2( "short", "det1", "det-2", "det3" );
|
||||
CPPUNIT_ASSERT( message1 != message2 );
|
||||
CPPUNIT_ASSERT( !(message1 != message1) );
|
||||
}
|
76
examples/cppunittest/MessageTest.h
Normal file
76
examples/cppunittest/MessageTest.h
Normal file
@@ -0,0 +1,76 @@
|
||||
#ifndef MESSAGETEST_H
|
||||
#define MESSAGETEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/Message.h>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
/// Unit tests for MessageTest
|
||||
class MessageTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( MessageTest );
|
||||
CPPUNIT_TEST( testDefaultConstructor );
|
||||
CPPUNIT_TEST_EXCEPTION( testDetailAtThrowIfBadIndex, std::invalid_argument );
|
||||
CPPUNIT_TEST_EXCEPTION( testDetailAtThrowIfBadIndex2, std::invalid_argument );
|
||||
CPPUNIT_TEST( testAddDetail );
|
||||
CPPUNIT_TEST( testAddDetail2 );
|
||||
CPPUNIT_TEST( testAddDetail3 );
|
||||
CPPUNIT_TEST( testAddDetailEmptyMessage );
|
||||
CPPUNIT_TEST( testAddDetailMessage );
|
||||
CPPUNIT_TEST( testSetShortDescription );
|
||||
CPPUNIT_TEST( testClearDetails );
|
||||
CPPUNIT_TEST( testConstructor );
|
||||
CPPUNIT_TEST( testConstructorDetail1 );
|
||||
CPPUNIT_TEST( testConstructorDetail2 );
|
||||
CPPUNIT_TEST( testConstructorDetail3 );
|
||||
CPPUNIT_TEST( testDetailsNone );
|
||||
CPPUNIT_TEST( testDetailsSome );
|
||||
CPPUNIT_TEST( testEqual );
|
||||
CPPUNIT_TEST( testNotEqual );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
MessageTest();
|
||||
|
||||
virtual ~MessageTest();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
void testDefaultConstructor();
|
||||
void testDetailAtThrowIfBadIndex();
|
||||
void testDetailAtThrowIfBadIndex2();
|
||||
void testAddDetail();
|
||||
void testAddDetail2();
|
||||
void testAddDetail3();
|
||||
void testAddDetailEmptyMessage();
|
||||
void testAddDetailMessage();
|
||||
void testSetShortDescription();
|
||||
void testClearDetails();
|
||||
|
||||
void testConstructor();
|
||||
void testConstructorDetail1();
|
||||
void testConstructorDetail2();
|
||||
void testConstructorDetail3();
|
||||
|
||||
void testDetailsNone();
|
||||
void testDetailsSome();
|
||||
|
||||
void testEqual();
|
||||
void testNotEqual();
|
||||
|
||||
private:
|
||||
/// Prevents the use of the copy constructor.
|
||||
MessageTest( const MessageTest &other );
|
||||
|
||||
/// Prevents the use of the copy operator.
|
||||
void operator =( const MessageTest &other );
|
||||
|
||||
private:
|
||||
CPPUNIT_NS::Message *m_message;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // MESSAGETEST_H
|
90
examples/cppunittest/MockFunctor.h
Normal file
90
examples/cppunittest/MockFunctor.h
Normal file
@@ -0,0 +1,90 @@
|
||||
#ifndef MOCKFUNCTOR_H
|
||||
#define MOCKFUNCTOR_H
|
||||
|
||||
#include <cppunit/TestAssert.h>
|
||||
#include <cppunit/Protector.h>
|
||||
#include "FailureException.h"
|
||||
#include "MockProtector.h"
|
||||
|
||||
|
||||
class MockFunctor : public CPPUNIT_NS::Functor
|
||||
{
|
||||
public:
|
||||
MockFunctor()
|
||||
: m_shouldSucceed( true )
|
||||
, m_shouldThrow( false )
|
||||
, m_shouldThrowFailureException( false )
|
||||
, m_hasExpectation( false )
|
||||
, m_actualCallCount( 0 )
|
||||
, m_expectedCallCount( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool operator()() const
|
||||
{
|
||||
++CPPUNIT_CONST_CAST(MockFunctor *,this)->m_actualCallCount;
|
||||
|
||||
if ( m_shouldThrow )
|
||||
{
|
||||
if ( m_shouldThrowFailureException )
|
||||
throw FailureException();
|
||||
throw MockProtectorException();
|
||||
}
|
||||
|
||||
return m_shouldSucceed;
|
||||
}
|
||||
|
||||
void setThrowFailureException()
|
||||
{
|
||||
m_shouldThrow = true;
|
||||
m_shouldThrowFailureException = true;
|
||||
++m_expectedCallCount;
|
||||
m_hasExpectation = true;
|
||||
}
|
||||
|
||||
void setThrowMockProtectorException()
|
||||
{
|
||||
m_shouldThrow = true;
|
||||
m_shouldThrowFailureException = false;
|
||||
++m_expectedCallCount;
|
||||
m_hasExpectation = true;
|
||||
}
|
||||
|
||||
void setShouldFail()
|
||||
{
|
||||
m_shouldSucceed = false;
|
||||
}
|
||||
|
||||
void setShouldSucceed()
|
||||
{
|
||||
m_shouldSucceed = true;
|
||||
}
|
||||
|
||||
void setExpectedCallCount( int callCount =1 )
|
||||
{
|
||||
m_expectedCallCount = callCount;
|
||||
m_hasExpectation = true;
|
||||
}
|
||||
|
||||
void verify()
|
||||
{
|
||||
if ( m_hasExpectation )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( "MockFunctor: bad call count",
|
||||
m_expectedCallCount,
|
||||
m_actualCallCount );
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_shouldSucceed;
|
||||
bool m_shouldThrow;
|
||||
bool m_shouldThrowFailureException;
|
||||
bool m_hasExpectation;
|
||||
int m_actualCallCount;
|
||||
int m_expectedCallCount;
|
||||
};
|
||||
|
||||
|
||||
#endif // MOCKFUNCTOR_H
|
96
examples/cppunittest/MockProtector.h
Normal file
96
examples/cppunittest/MockProtector.h
Normal file
@@ -0,0 +1,96 @@
|
||||
#ifndef MOCKPROTECTOR_H
|
||||
#define MOCKPROTECTOR_H
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cppunit/Protector.h>
|
||||
|
||||
|
||||
class MockProtectorException : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
MockProtectorException()
|
||||
: std::runtime_error( "MockProtectorException" )
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class MockProtector : public CPPUNIT_NS::Protector
|
||||
{
|
||||
public:
|
||||
MockProtector()
|
||||
: m_wasCalled( false )
|
||||
, m_wasTrapped( false )
|
||||
, m_expectException( false )
|
||||
, m_hasExpectation( false )
|
||||
, m_shouldPropagateException( false )
|
||||
{
|
||||
}
|
||||
|
||||
bool protect( const CPPUNIT_NS::Functor &functor,
|
||||
const CPPUNIT_NS::ProtectorContext &context )
|
||||
{
|
||||
try
|
||||
{
|
||||
m_wasCalled = true;
|
||||
return functor();
|
||||
}
|
||||
catch ( MockProtectorException & )
|
||||
{
|
||||
m_wasTrapped = true;
|
||||
|
||||
if ( m_shouldPropagateException )
|
||||
throw;
|
||||
|
||||
reportError( context, CPPUNIT_NS::Message("MockProtector trap") );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void setExpectException()
|
||||
{
|
||||
m_expectException = true;
|
||||
m_hasExpectation = true;
|
||||
}
|
||||
|
||||
void setExpectNoException()
|
||||
{
|
||||
m_expectException = false;
|
||||
m_hasExpectation = true;
|
||||
}
|
||||
|
||||
void setExpectCatchAndPropagateException()
|
||||
{
|
||||
setExpectException();
|
||||
m_shouldPropagateException = true;
|
||||
}
|
||||
|
||||
void verify()
|
||||
{
|
||||
if ( m_hasExpectation )
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE( "MockProtector::protect() was not called",
|
||||
m_wasCalled );
|
||||
|
||||
std::string message;
|
||||
if ( m_expectException )
|
||||
message = "did not catch the exception.";
|
||||
else
|
||||
message = "caught an unexpected exception.";
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( "MockProtector::protect() " + message,
|
||||
m_expectException,
|
||||
m_wasTrapped );
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_wasCalled;
|
||||
bool m_wasTrapped;
|
||||
bool m_expectException;
|
||||
bool m_hasExpectation;
|
||||
bool m_shouldPropagateException;
|
||||
};
|
||||
|
||||
|
||||
#endif // MOCKPROTECTOR_H
|
190
examples/cppunittest/MockTestCase.cpp
Normal file
190
examples/cppunittest/MockTestCase.cpp
Normal file
@@ -0,0 +1,190 @@
|
||||
#include "FailureException.h"
|
||||
#include "MockTestCase.h"
|
||||
#include <cppunit/TestPath.h>
|
||||
|
||||
|
||||
MockTestCase::MockTestCase( std::string name )
|
||||
: CPPUNIT_NS::TestCase( name )
|
||||
, m_hasSetUpExpectation( false )
|
||||
, m_expectedSetUpCall( 0 )
|
||||
, m_actualSetUpCall( 0 )
|
||||
, m_hasTearDownExpectation( false )
|
||||
, m_expectedTearDownCall( 0 )
|
||||
, m_actualTearDownCall( 0 )
|
||||
, m_expectRunTestCall( false )
|
||||
, m_expectedRunTestCallCount( 0 )
|
||||
, m_actualRunTestCallCount( 0 )
|
||||
, m_expectCountTestCasesCall( false )
|
||||
, m_expectedCountTestCasesCallCount( 0 )
|
||||
, m_actualCountTestCasesCallCount( 0 )
|
||||
, m_setUpThrow( false )
|
||||
, m_tearDownThrow( false )
|
||||
, m_runTestThrow( false )
|
||||
, m_passingTest( NULL )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MockTestCase::~MockTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
MockTestCase::countTestCases() const
|
||||
{
|
||||
MockTestCase *mutableThis = CPPUNIT_CONST_CAST(MockTestCase *, this );
|
||||
++mutableThis->m_actualCountTestCasesCallCount;
|
||||
if ( m_expectCountTestCasesCall )
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE( getName() + ": unexpected MockTestCase::countTestCases() call",
|
||||
m_actualCountTestCasesCallCount <= m_expectedCountTestCasesCallCount );
|
||||
}
|
||||
|
||||
return SuperClass::countTestCases();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestCase::setUp()
|
||||
{
|
||||
if ( m_hasSetUpExpectation )
|
||||
{
|
||||
++m_actualSetUpCall;
|
||||
CPPUNIT_ASSERT_MESSAGE( getName() + ": unexpected MockTestCase::setUp() call",
|
||||
m_actualSetUpCall <= m_expectedSetUpCall );
|
||||
}
|
||||
|
||||
if ( m_setUpThrow )
|
||||
throw FailureException();
|
||||
}
|
||||
|
||||
void
|
||||
MockTestCase::tearDown()
|
||||
{
|
||||
if ( m_hasTearDownExpectation )
|
||||
{
|
||||
++m_actualTearDownCall;
|
||||
CPPUNIT_ASSERT_MESSAGE( getName() + ": unexpected MockTestCase::tearDown() call",
|
||||
m_actualTearDownCall <= m_expectedTearDownCall );
|
||||
}
|
||||
|
||||
if ( m_tearDownThrow )
|
||||
throw FailureException();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestCase::runTest()
|
||||
{
|
||||
++m_actualRunTestCallCount;
|
||||
if ( m_expectRunTestCall )
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE( getName() + ": unexpected MockTestCase::runTest() call",
|
||||
m_actualRunTestCallCount <= m_expectedRunTestCallCount );
|
||||
}
|
||||
|
||||
if ( m_runTestThrow )
|
||||
throw FailureException();
|
||||
}
|
||||
|
||||
/*
|
||||
bool
|
||||
MockTestCase::findTestPath( const CPPUNIT_NS::Test *test,
|
||||
CPPUNIT_NS::TestPath &testPath )
|
||||
{
|
||||
if ( m_passingTest == test )
|
||||
{
|
||||
testPath.add( this );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
void
|
||||
MockTestCase::setExpectedSetUpCall( int callCount )
|
||||
{
|
||||
m_hasSetUpExpectation = true;
|
||||
m_expectedSetUpCall = callCount;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestCase::setExpectedTearDownCall( int callCount )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestCase::setExpectedRunTestCall( int callCount )
|
||||
{
|
||||
m_expectRunTestCall = true;
|
||||
m_expectedRunTestCallCount = callCount ;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestCase::setExpectedCountTestCasesCall( int callCount )
|
||||
{
|
||||
m_expectCountTestCasesCall = true;
|
||||
m_expectedCountTestCasesCallCount = callCount;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestCase::makeSetUpThrow()
|
||||
{
|
||||
m_setUpThrow = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestCase::makeTearDownThrow()
|
||||
{
|
||||
m_tearDownThrow = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestCase::makeRunTestThrow()
|
||||
{
|
||||
m_runTestThrow = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestCase::verify()
|
||||
{
|
||||
if ( m_hasSetUpExpectation )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( getName() + ": bad MockTestCase::setUp() "
|
||||
"call count",
|
||||
m_expectedSetUpCall,
|
||||
m_actualSetUpCall );
|
||||
}
|
||||
|
||||
if ( m_hasTearDownExpectation )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( getName() + ": bad MockTestCase::tearDown() "
|
||||
"call count",
|
||||
m_expectedTearDownCall,
|
||||
m_actualTearDownCall );
|
||||
}
|
||||
|
||||
if ( m_expectCountTestCasesCall )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( getName() + ": bad MockTestCase::countTestCases() "
|
||||
"call count",
|
||||
m_expectedCountTestCasesCallCount,
|
||||
m_actualCountTestCasesCallCount );
|
||||
}
|
||||
if ( m_expectRunTestCall )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( getName() + ": bad MockTestCase::runTest() "
|
||||
"call count",
|
||||
m_expectedRunTestCallCount,
|
||||
m_actualRunTestCallCount );
|
||||
}
|
||||
}
|
75
examples/cppunittest/MockTestCase.h
Normal file
75
examples/cppunittest/MockTestCase.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#ifndef MOCKTESTCASE_H
|
||||
#define MOCKTESTCASE_H
|
||||
|
||||
#include <cppunit/TestCase.h>
|
||||
|
||||
|
||||
/*! \class MockTestCase
|
||||
* \brief This class represents a mock test case.
|
||||
*/
|
||||
class MockTestCase : public CPPUNIT_NS::TestCase
|
||||
{
|
||||
public:
|
||||
typedef CPPUNIT_NS::TestCase SuperClass; // work around VC++ call to super class method.
|
||||
|
||||
/*! Constructs a MockTestCase object.
|
||||
*/
|
||||
MockTestCase( std::string name );
|
||||
|
||||
/// Destructor.
|
||||
virtual ~MockTestCase();
|
||||
|
||||
void setExpectedSetUpCall( int callCount = 1 );
|
||||
void setExpectedTearDownCall( int callCount = 1 );
|
||||
void setExpectedRunTestCall( int callCount = 1 );
|
||||
void setExpectedCountTestCasesCall( int callCount = 1 );
|
||||
|
||||
void makeSetUpThrow();
|
||||
void makeTearDownThrow();
|
||||
void makeRunTestThrow();
|
||||
void makeFindTestPathPassFor( const CPPUNIT_NS::Test *testFound );
|
||||
|
||||
void verify();
|
||||
|
||||
protected:
|
||||
int countTestCases() const;
|
||||
void setUp();
|
||||
void tearDown();
|
||||
void runTest();
|
||||
// bool findTestPath( const CPPUNIT_NS::Test *test,
|
||||
// CPPUNIT_NS::TestPath &testPath );
|
||||
|
||||
private:
|
||||
/// Prevents the use of the copy constructor.
|
||||
MockTestCase( const MockTestCase © );
|
||||
|
||||
/// Prevents the use of the copy operator.
|
||||
void operator =( const MockTestCase © );
|
||||
|
||||
private:
|
||||
bool m_hasSetUpExpectation;
|
||||
int m_expectedSetUpCall;
|
||||
int m_actualSetUpCall;
|
||||
|
||||
bool m_hasTearDownExpectation;
|
||||
int m_expectedTearDownCall;
|
||||
int m_actualTearDownCall;
|
||||
|
||||
bool m_expectRunTestCall;
|
||||
int m_expectedRunTestCallCount;
|
||||
int m_actualRunTestCallCount;
|
||||
bool m_expectCountTestCasesCall;
|
||||
int m_expectedCountTestCasesCallCount;
|
||||
int m_actualCountTestCasesCallCount;
|
||||
|
||||
bool m_setUpThrow;
|
||||
bool m_tearDownThrow;
|
||||
bool m_runTestThrow;
|
||||
const CPPUNIT_NS::Test *m_passingTest;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // MOCKTESTCASE_H
|
390
examples/cppunittest/MockTestListener.cpp
Normal file
390
examples/cppunittest/MockTestListener.cpp
Normal file
@@ -0,0 +1,390 @@
|
||||
#include <cppunit/TestAssert.h>
|
||||
#include <cppunit/TestFailure.h>
|
||||
#include "MockTestListener.h"
|
||||
|
||||
|
||||
MockTestListener::MockTestListener( std::string name )
|
||||
: m_name( name )
|
||||
, m_hasExpectationForStartTest( false )
|
||||
, m_hasParametersExpectationForStartTest( false )
|
||||
, m_expectedStartTestCallCount( 0 )
|
||||
, m_startTestCall( 0 )
|
||||
, m_hasExpectationForEndTest( false )
|
||||
, m_hasParametersExpectationForEndTest( false )
|
||||
, m_expectedEndTestCallCount( 0 )
|
||||
, m_endTestCall( 0 )
|
||||
, m_hasExpectationForStartSuite( false )
|
||||
, m_hasParametersExpectationForStartSuite( false )
|
||||
, m_expectedStartSuiteCallCount( 0 )
|
||||
, m_startSuiteCall( 0 )
|
||||
, m_hasExpectationForEndSuite( false )
|
||||
, m_hasParametersExpectationForEndSuite( false )
|
||||
, m_expectedEndSuiteCallCount( 0 )
|
||||
, m_endSuiteCall( 0 )
|
||||
, m_hasExpectationForStartTestRun( false )
|
||||
, m_hasParametersExpectationForStartTestRun( false )
|
||||
, m_expectedStartTestRunCallCount( 0 )
|
||||
, m_startTestRunCall( 0 )
|
||||
, m_hasExpectationForEndTestRun( false )
|
||||
, m_hasParametersExpectationForEndTestRun( false )
|
||||
, m_expectedEndTestRunCallCount( 0 )
|
||||
, m_endTestRunCall( 0 )
|
||||
, m_hasExpectationForAddFailure( false )
|
||||
, m_hasExpectationForSomeFailure( false )
|
||||
, m_hasParametersExpectationForAddFailure( false )
|
||||
, m_expectedAddFailureCallCount( 0 )
|
||||
, m_addFailureCall( 0 )
|
||||
, m_expectedFailedTest( NULL )
|
||||
, m_expectedException( NULL )
|
||||
, m_expectedIsError( false )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectFailure( CPPUNIT_NS::Test *failedTest,
|
||||
CPPUNIT_NS::Exception *thrownException,
|
||||
bool isError )
|
||||
{
|
||||
m_hasExpectationForAddFailure = true;
|
||||
m_hasParametersExpectationForAddFailure = true;
|
||||
m_expectedAddFailureCallCount = 1;
|
||||
m_expectedFailedTest = failedTest;
|
||||
m_expectedException = thrownException;
|
||||
m_expectedIsError = isError;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectNoFailure()
|
||||
{
|
||||
m_hasExpectationForAddFailure = true;
|
||||
m_expectedAddFailureCallCount = 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectFailure()
|
||||
{
|
||||
m_hasExpectationForSomeFailure = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectedAddFailureCall( int callCount )
|
||||
{
|
||||
m_hasExpectationForAddFailure = true;
|
||||
m_expectedAddFailureCallCount = callCount;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectStartTest( CPPUNIT_NS::Test *test )
|
||||
{
|
||||
m_hasExpectationForStartTest = true;
|
||||
m_hasParametersExpectationForStartTest = true;
|
||||
m_expectedStartTestCallCount = 1;
|
||||
m_expectedStartTest = test;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectedStartTestCall( int callCount )
|
||||
{
|
||||
m_hasExpectationForStartTest = true;
|
||||
m_expectedStartTestCallCount = callCount;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectEndTest( CPPUNIT_NS::Test *test )
|
||||
{
|
||||
m_hasExpectationForEndTest = true;
|
||||
m_hasParametersExpectationForEndTest = true;
|
||||
m_expectedEndTestCallCount = 1;
|
||||
m_expectedEndTest = test;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectedEndTestCall( int callCount )
|
||||
{
|
||||
m_hasExpectationForEndTest = true;
|
||||
m_expectedEndTestCallCount = callCount;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectStartSuite( CPPUNIT_NS::Test *test )
|
||||
{
|
||||
m_hasExpectationForStartSuite = true;
|
||||
m_hasParametersExpectationForStartSuite = true;
|
||||
m_expectedStartSuiteCallCount = 1;
|
||||
m_expectedStartSuite = test;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectedStartSuiteCall( int callCount )
|
||||
{
|
||||
m_hasExpectationForStartSuite = true;
|
||||
m_expectedStartSuiteCallCount = callCount;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectEndSuite( CPPUNIT_NS::Test *test )
|
||||
{
|
||||
m_hasExpectationForEndSuite = true;
|
||||
m_hasParametersExpectationForEndSuite = true;
|
||||
m_expectedEndSuiteCallCount = 1;
|
||||
m_expectedEndSuite = test;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectedEndSuiteCall( int callCount )
|
||||
{
|
||||
m_hasExpectationForEndSuite = true;
|
||||
m_expectedEndSuiteCallCount = callCount;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectStartTestRun( CPPUNIT_NS::Test *test,
|
||||
CPPUNIT_NS::TestResult *eventManager )
|
||||
{
|
||||
m_hasExpectationForStartTestRun = true;
|
||||
m_hasParametersExpectationForStartTestRun = true;
|
||||
m_expectedStartTestRunCallCount = 1;
|
||||
m_expectedStartTestRun = test;
|
||||
m_expectedStartTestRun2 = eventManager;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectedStartTestRunCall( int callCount )
|
||||
{
|
||||
m_hasExpectationForStartTestRun = true;
|
||||
m_expectedStartTestRunCallCount = callCount;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectEndTestRun( CPPUNIT_NS::Test *test,
|
||||
CPPUNIT_NS::TestResult *eventManager )
|
||||
{
|
||||
m_hasExpectationForEndTestRun = true;
|
||||
m_hasParametersExpectationForEndTestRun = true;
|
||||
m_expectedEndTestRunCallCount = 1;
|
||||
m_expectedEndTestRun = test;
|
||||
m_expectedEndTestRun2 = eventManager;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::setExpectedEndTestRunCall( int callCount )
|
||||
{
|
||||
m_hasExpectationForEndTestRun = true;
|
||||
m_expectedEndTestRunCallCount = callCount;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::addFailure( const CPPUNIT_NS::TestFailure &failure )
|
||||
{
|
||||
if ( m_hasExpectationForAddFailure || m_hasExpectationForSomeFailure )
|
||||
++m_addFailureCall;
|
||||
|
||||
if ( m_hasExpectationForAddFailure )
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": unexpected call",
|
||||
m_addFailureCall <= m_expectedAddFailureCallCount );
|
||||
}
|
||||
|
||||
if ( m_hasParametersExpectationForAddFailure )
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": bad test",
|
||||
m_expectedFailedTest == failure.failedTest() );
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": bad thrownException",
|
||||
m_expectedException == failure.thrownException() );
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": bad isError",
|
||||
m_expectedIsError == failure.isError() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::startTest( CPPUNIT_NS::Test *test )
|
||||
{
|
||||
if ( m_hasExpectationForStartTest )
|
||||
{
|
||||
++m_startTestCall;
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": unexpected call",
|
||||
m_startTestCall <= m_expectedStartTestCallCount );
|
||||
|
||||
}
|
||||
|
||||
if ( m_hasParametersExpectationForStartTest )
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": bad test",
|
||||
m_expectedStartTest == test );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::endTest( CPPUNIT_NS::Test *test )
|
||||
{
|
||||
if ( m_hasExpectationForEndTest )
|
||||
{
|
||||
++m_endTestCall;
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": unexpected call",
|
||||
m_endTestCall <= m_expectedEndTestCallCount );
|
||||
}
|
||||
|
||||
if ( m_hasParametersExpectationForEndTest )
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": bad test",
|
||||
m_expectedEndTest == test );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::startSuite( CPPUNIT_NS::Test *test )
|
||||
{
|
||||
if ( m_hasExpectationForStartSuite )
|
||||
{
|
||||
++m_startSuiteCall;
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": unexpected call",
|
||||
m_startSuiteCall <= m_expectedStartSuiteCallCount );
|
||||
}
|
||||
|
||||
if ( m_hasParametersExpectationForStartSuite )
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": bad test",
|
||||
m_expectedStartSuite == test );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::endSuite( CPPUNIT_NS::Test *test )
|
||||
{
|
||||
if ( m_hasExpectationForEndSuite )
|
||||
{
|
||||
++m_endSuiteCall;
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": unexpected call",
|
||||
m_endSuiteCall <= m_expectedEndSuiteCallCount );
|
||||
}
|
||||
|
||||
if ( m_hasParametersExpectationForEndSuite )
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": bad test",
|
||||
m_expectedEndSuite == test );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::startTestRun( CPPUNIT_NS::Test *test,
|
||||
CPPUNIT_NS::TestResult *eventManager )
|
||||
{
|
||||
if ( m_hasExpectationForStartTestRun )
|
||||
{
|
||||
++m_startTestRunCall;
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": unexpected call",
|
||||
m_startTestRunCall <= m_expectedStartTestRunCallCount );
|
||||
}
|
||||
|
||||
if ( m_hasParametersExpectationForStartTestRun )
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": bad test",
|
||||
m_expectedStartTestRun == test );
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": bad eventManager",
|
||||
m_expectedStartTestRun2 == eventManager );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::endTestRun( CPPUNIT_NS::Test *test,
|
||||
CPPUNIT_NS::TestResult *eventManager )
|
||||
{
|
||||
if ( m_hasExpectationForEndTestRun )
|
||||
{
|
||||
++m_endTestRunCall;
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": unexpected call",
|
||||
m_endTestRunCall <= m_expectedEndTestRunCallCount );
|
||||
}
|
||||
|
||||
if ( m_hasParametersExpectationForEndTestRun )
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": bad test",
|
||||
m_expectedEndTestRun == test );
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": bad eventManager",
|
||||
m_expectedEndTestRun2 == eventManager );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MockTestListener::verify()
|
||||
{
|
||||
if ( m_hasExpectationForStartTest )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( m_name + ": missing startTest calls",
|
||||
m_expectedStartTestCallCount,
|
||||
m_startTestCall );
|
||||
}
|
||||
|
||||
if ( m_hasExpectationForEndTest )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( m_name + ": missing endTest calls",
|
||||
m_expectedEndTestCallCount,
|
||||
m_endTestCall );
|
||||
}
|
||||
|
||||
if ( m_hasExpectationForStartSuite )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( m_name + ": missing startSuite calls",
|
||||
m_expectedStartSuiteCallCount,
|
||||
m_startSuiteCall );
|
||||
}
|
||||
|
||||
if ( m_hasExpectationForEndSuite )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( m_name + ": missing endSuite calls",
|
||||
m_expectedEndSuiteCallCount,
|
||||
m_endSuiteCall );
|
||||
}
|
||||
|
||||
if ( m_hasExpectationForStartTestRun )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( m_name + ": missing startTestRun calls",
|
||||
m_expectedStartTestRunCallCount,
|
||||
m_startTestRunCall );
|
||||
}
|
||||
|
||||
if ( m_hasExpectationForEndTestRun )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( m_name + ": missing endTestRun calls",
|
||||
m_expectedEndTestRunCallCount,
|
||||
m_endTestRunCall );
|
||||
}
|
||||
|
||||
if ( m_hasExpectationForAddFailure )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE( m_name + ": missing addFailure calls",
|
||||
m_expectedAddFailureCallCount,
|
||||
m_addFailureCall );
|
||||
}
|
||||
|
||||
if ( m_hasExpectationForSomeFailure )
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE( m_name + ": there was no call to "
|
||||
"MockTestListener::addFailure()",
|
||||
m_addFailureCall > 0 );
|
||||
}
|
||||
}
|
105
examples/cppunittest/MockTestListener.h
Normal file
105
examples/cppunittest/MockTestListener.h
Normal file
@@ -0,0 +1,105 @@
|
||||
#ifndef MOCKTESTLISTENER_H
|
||||
#define MOCKTESTLISTENER_H
|
||||
|
||||
#include <cppunit/TestListener.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
class MockTestListener : public CPPUNIT_NS::TestListener
|
||||
{
|
||||
public:
|
||||
MockTestListener( std::string name );
|
||||
virtual ~MockTestListener() {}
|
||||
|
||||
void setExpectFailure( CPPUNIT_NS::Test *failedTest,
|
||||
CPPUNIT_NS::Exception *thrownException,
|
||||
bool isError );
|
||||
void setExpectNoFailure();
|
||||
void setExpectFailure();
|
||||
void setExpectedAddFailureCall( int callCount );
|
||||
void setExpectStartTest( CPPUNIT_NS::Test *test );
|
||||
void setExpectedStartTestCall( int callCount );
|
||||
void setExpectEndTest( CPPUNIT_NS::Test *test );
|
||||
void setExpectedEndTestCall( int callCount );
|
||||
void setExpectStartSuite( CPPUNIT_NS::Test *suite );
|
||||
void setExpectedStartSuiteCall( int callCount );
|
||||
void setExpectEndSuite( CPPUNIT_NS::Test *suite );
|
||||
void setExpectedEndSuiteCall( int callCount );
|
||||
void setExpectStartTestRun( CPPUNIT_NS::Test *test,
|
||||
CPPUNIT_NS::TestResult *eventManager );
|
||||
void setExpectedStartTestRunCall( int callCount );
|
||||
void setExpectEndTestRun( CPPUNIT_NS::Test *test,
|
||||
CPPUNIT_NS::TestResult *eventManager );
|
||||
void setExpectedEndTestRunCall( int callCount );
|
||||
|
||||
void addFailure( const CPPUNIT_NS::TestFailure &failure );
|
||||
void startTest( CPPUNIT_NS::Test *test );
|
||||
void endTest( CPPUNIT_NS::Test *test );
|
||||
void startSuite( CPPUNIT_NS::Test *suite );
|
||||
void endSuite( CPPUNIT_NS::Test *suite );
|
||||
void startTestRun( CPPUNIT_NS::Test *test,
|
||||
CPPUNIT_NS::TestResult *eventManager );
|
||||
void endTestRun( CPPUNIT_NS::Test *test,
|
||||
CPPUNIT_NS::TestResult *eventManager );
|
||||
|
||||
void verify();
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
|
||||
bool m_hasExpectationForStartTest;
|
||||
bool m_hasParametersExpectationForStartTest;
|
||||
int m_expectedStartTestCallCount;
|
||||
int m_startTestCall;
|
||||
CPPUNIT_NS::Test *m_expectedStartTest;
|
||||
|
||||
bool m_hasExpectationForEndTest;
|
||||
bool m_hasParametersExpectationForEndTest;
|
||||
int m_expectedEndTestCallCount;
|
||||
CPPUNIT_NS::Test *m_expectedEndTest;
|
||||
int m_endTestCall;
|
||||
|
||||
bool m_hasExpectationForStartSuite;
|
||||
bool m_hasParametersExpectationForStartSuite;
|
||||
int m_expectedStartSuiteCallCount;
|
||||
CPPUNIT_NS::Test *m_expectedStartSuite;
|
||||
int m_startSuiteCall;
|
||||
|
||||
bool m_hasExpectationForEndSuite;
|
||||
bool m_hasParametersExpectationForEndSuite;
|
||||
int m_expectedEndSuiteCallCount;
|
||||
CPPUNIT_NS::Test *m_expectedEndSuite;
|
||||
int m_endSuiteCall;
|
||||
|
||||
bool m_hasExpectationForStartTestRun;
|
||||
bool m_hasParametersExpectationForStartTestRun;
|
||||
int m_expectedStartTestRunCallCount;
|
||||
CPPUNIT_NS::Test *m_expectedStartTestRun;
|
||||
CPPUNIT_NS::TestResult *m_expectedStartTestRun2;
|
||||
int m_startTestRunCall;
|
||||
|
||||
bool m_hasExpectationForEndTestRun;
|
||||
bool m_hasParametersExpectationForEndTestRun;
|
||||
int m_expectedEndTestRunCallCount;
|
||||
CPPUNIT_NS::Test *m_expectedEndTestRun;
|
||||
CPPUNIT_NS::TestResult *m_expectedEndTestRun2;
|
||||
int m_endTestRunCall;
|
||||
|
||||
bool m_hasExpectationForAddFailure;
|
||||
bool m_hasExpectationForSomeFailure;
|
||||
bool m_hasParametersExpectationForAddFailure;
|
||||
int m_expectedAddFailureCallCount;
|
||||
int m_addFailureCall;
|
||||
CPPUNIT_NS::Test *m_expectedFailedTest;
|
||||
CPPUNIT_NS::Exception *m_expectedException;
|
||||
bool m_expectedIsError;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Inlines methods for MockTestListener:
|
||||
// -------------------------------------
|
||||
|
||||
|
||||
|
||||
#endif // MOCKTESTLISTENER_H
|
103
examples/cppunittest/OrthodoxTest.cpp
Normal file
103
examples/cppunittest/OrthodoxTest.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include "ExtensionSuite.h"
|
||||
#include "OrthodoxTest.h"
|
||||
#include <cppunit/extensions/Orthodox.h>
|
||||
#include <cppunit/TestResult.h>
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( OrthodoxTest,
|
||||
extensionSuiteName() );
|
||||
|
||||
OrthodoxTest::OrthodoxTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
OrthodoxTest::~OrthodoxTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OrthodoxTest::setUp()
|
||||
{
|
||||
m_testListener = new MockTestListener( "mock-listener" );
|
||||
m_result = new CPPUNIT_NS::TestResult();
|
||||
m_result->addListener( m_testListener );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OrthodoxTest::tearDown()
|
||||
{
|
||||
delete m_result;
|
||||
delete m_testListener;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OrthodoxTest::testValue()
|
||||
{
|
||||
CPPUNIT_NS::Orthodox<Value> test;
|
||||
m_testListener->setExpectNoFailure();
|
||||
test.run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OrthodoxTest::testValueBadConstructor()
|
||||
{
|
||||
CPPUNIT_NS::Orthodox<ValueBadConstructor> test;
|
||||
m_testListener->setExpectFailure();
|
||||
test.run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OrthodoxTest::testValueBadInvert()
|
||||
{
|
||||
CPPUNIT_NS::Orthodox<ValueBadInvert> test;
|
||||
m_testListener->setExpectFailure();
|
||||
test.run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OrthodoxTest::testValueBadEqual()
|
||||
{
|
||||
CPPUNIT_NS::Orthodox<ValueBadEqual> test;
|
||||
m_testListener->setExpectFailure();
|
||||
test.run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OrthodoxTest::testValueBadNotEqual()
|
||||
{
|
||||
CPPUNIT_NS::Orthodox<ValueBadNotEqual> test;
|
||||
m_testListener->setExpectFailure();
|
||||
test.run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OrthodoxTest::testValueBadCall()
|
||||
{
|
||||
CPPUNIT_NS::Orthodox<ValueBadCall> test;
|
||||
m_testListener->setExpectFailure();
|
||||
test.run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OrthodoxTest::testValueBadAssignment()
|
||||
{
|
||||
CPPUNIT_NS::Orthodox<ValueBadAssignment> test;
|
||||
m_testListener->setExpectFailure();
|
||||
test.run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
178
examples/cppunittest/OrthodoxTest.h
Normal file
178
examples/cppunittest/OrthodoxTest.h
Normal file
@@ -0,0 +1,178 @@
|
||||
#ifndef ORTHODOXTEST_H
|
||||
#define ORTHODOXTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include "MockTestListener.h"
|
||||
|
||||
|
||||
class OrthodoxTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( OrthodoxTest );
|
||||
CPPUNIT_TEST( testValue );
|
||||
CPPUNIT_TEST( testValueBadConstructor );
|
||||
CPPUNIT_TEST( testValueBadInvert );
|
||||
CPPUNIT_TEST( testValueBadEqual );
|
||||
CPPUNIT_TEST( testValueBadNotEqual );
|
||||
CPPUNIT_TEST( testValueBadCall );
|
||||
CPPUNIT_TEST( testValueBadAssignment );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
OrthodoxTest();
|
||||
virtual ~OrthodoxTest();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
void testValue();
|
||||
void testValueBadConstructor();
|
||||
void testValueBadInvert();
|
||||
void testValueBadEqual();
|
||||
void testValueBadNotEqual();
|
||||
void testValueBadCall();
|
||||
void testValueBadAssignment();
|
||||
|
||||
private:
|
||||
class Value
|
||||
{
|
||||
public:
|
||||
Value( int value =0 ) : m_value( value ) {}
|
||||
|
||||
Value& operator= ( const Value& v )
|
||||
{
|
||||
m_value = v.m_value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator ==( const Value &other ) const
|
||||
{
|
||||
return m_value == other.m_value;
|
||||
}
|
||||
|
||||
bool operator !=( const Value &other )
|
||||
{
|
||||
return !( *this == other );
|
||||
}
|
||||
|
||||
Value operator !()
|
||||
{
|
||||
return Value( -1 - m_value );
|
||||
}
|
||||
|
||||
protected:
|
||||
int m_value;
|
||||
};
|
||||
|
||||
|
||||
class ValueBadConstructor : public Value
|
||||
{
|
||||
public:
|
||||
ValueBadConstructor()
|
||||
{
|
||||
static int serialNumber = 0;
|
||||
m_value = ++serialNumber;
|
||||
}
|
||||
|
||||
ValueBadConstructor( int value ) : Value( value ) {}
|
||||
|
||||
ValueBadConstructor operator !()
|
||||
{
|
||||
return ValueBadConstructor( -1 - m_value );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ValueBadInvert : public Value
|
||||
{
|
||||
public:
|
||||
ValueBadInvert( int value =0 ) : Value( value ) {}
|
||||
|
||||
ValueBadInvert operator !()
|
||||
{
|
||||
return ValueBadInvert( 1 );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ValueBadEqual : public Value
|
||||
{
|
||||
public:
|
||||
ValueBadEqual( int value =0 ) : Value( value ) {}
|
||||
|
||||
ValueBadEqual operator !()
|
||||
{
|
||||
return ValueBadEqual( -1 - m_value );
|
||||
}
|
||||
|
||||
bool operator ==( const ValueBadEqual &other ) const
|
||||
{
|
||||
return m_value != other.m_value;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ValueBadNotEqual : public Value
|
||||
{
|
||||
public:
|
||||
ValueBadNotEqual( int value =0 ) : Value( value ) {}
|
||||
|
||||
ValueBadNotEqual operator !()
|
||||
{
|
||||
return ValueBadNotEqual( -1 - m_value );
|
||||
}
|
||||
|
||||
bool operator !=( const ValueBadNotEqual &other )
|
||||
{
|
||||
return m_value == other.m_value;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ValueBadCall : public Value
|
||||
{
|
||||
public:
|
||||
ValueBadCall( int value =0 ) : Value( value ) {}
|
||||
|
||||
ValueBadCall( const ValueBadCall &other )
|
||||
{
|
||||
static int serialNumber = 0;
|
||||
m_value = ++serialNumber;
|
||||
}
|
||||
|
||||
ValueBadCall operator !()
|
||||
{
|
||||
return ValueBadCall( -1 - m_value );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ValueBadAssignment: public Value
|
||||
{
|
||||
public:
|
||||
ValueBadAssignment( int value =0 ) : Value( value ) {}
|
||||
|
||||
ValueBadAssignment operator !()
|
||||
{
|
||||
return ValueBadAssignment( -1 - m_value );
|
||||
}
|
||||
|
||||
ValueBadAssignment &operator =( const ValueBadAssignment &other )
|
||||
{
|
||||
++m_value;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
OrthodoxTest( const OrthodoxTest © );
|
||||
void operator =( const OrthodoxTest © );
|
||||
|
||||
private:
|
||||
CPPUNIT_NS::TestResult *m_result;
|
||||
MockTestListener *m_testListener;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // ORTHODOXTEST_H
|
13
examples/cppunittest/OutputSuite.h
Normal file
13
examples/cppunittest/OutputSuite.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef CPPUNITTEST_OUTPUTSUITE_H
|
||||
#define CPPUNITTEST_OUTPUTSUITE_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <string>
|
||||
|
||||
inline std::string outputSuiteName()
|
||||
{
|
||||
return "Output";
|
||||
}
|
||||
|
||||
|
||||
#endif // CPPUNITTEST_OUTPUTSUITE_H
|
43
examples/cppunittest/RepeatedTestTest.cpp
Normal file
43
examples/cppunittest/RepeatedTestTest.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "ExtensionSuite.h"
|
||||
#include "RepeatedTestTest.h"
|
||||
#include <cppunit/extensions/RepeatedTest.h>
|
||||
#include <cppunit/TestResult.h>
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RepeatedTestTest,
|
||||
extensionSuiteName() );
|
||||
|
||||
|
||||
RepeatedTestTest::RepeatedTestTest() :
|
||||
m_repeatCount( 17 )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RepeatedTestTest::~RepeatedTestTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RepeatedTestTest::setUp()
|
||||
{
|
||||
m_test = new RunCountTest();
|
||||
m_repeatedTest = new CPPUNIT_NS::RepeatedTest( m_test, m_repeatCount );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RepeatedTestTest::tearDown()
|
||||
{
|
||||
delete m_repeatedTest;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RepeatedTestTest::testRun()
|
||||
{
|
||||
CPPUNIT_NS::TestResult result;
|
||||
m_repeatedTest->run( &result );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 17, m_test->m_runCount );
|
||||
}
|
47
examples/cppunittest/RepeatedTestTest.h
Normal file
47
examples/cppunittest/RepeatedTestTest.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef REPEATEDTESTTEST_H
|
||||
#define REPEATEDTESTTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
||||
class RepeatedTestTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( RepeatedTestTest );
|
||||
CPPUNIT_TEST( testRun );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
RepeatedTestTest();
|
||||
virtual ~RepeatedTestTest();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
void testRun();
|
||||
|
||||
private:
|
||||
class RunCountTest : public CPPUNIT_NS::TestCase
|
||||
{
|
||||
public:
|
||||
RunCountTest() : m_runCount( 0 ) {}
|
||||
|
||||
void runTest()
|
||||
{
|
||||
++m_runCount;
|
||||
}
|
||||
|
||||
int m_runCount;
|
||||
};
|
||||
|
||||
RepeatedTestTest( const RepeatedTestTest © );
|
||||
void operator =( const RepeatedTestTest © );
|
||||
|
||||
private:
|
||||
RunCountTest *m_test;
|
||||
CPPUNIT_NS::Test *m_repeatedTest;
|
||||
const int m_repeatCount;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // REPEATEDTESTTEST_H
|
233
examples/cppunittest/StringToolsTest.cpp
Normal file
233
examples/cppunittest/StringToolsTest.cpp
Normal file
@@ -0,0 +1,233 @@
|
||||
#include <cppunit/config/SourcePrefix.h>
|
||||
#include "StringToolsTest.h"
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( StringToolsTest );
|
||||
|
||||
|
||||
StringToolsTest::StringToolsTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
StringToolsTest::~StringToolsTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testToStringInt()
|
||||
{
|
||||
std::string expected = "123456789";
|
||||
std::string actual = CPPUNIT_NS::StringTools::toString( 123456789 );
|
||||
CPPUNIT_ASSERT_EQUAL( expected, actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testToStringDouble()
|
||||
{
|
||||
std::string expected = "1234.56";
|
||||
std::string actual = CPPUNIT_NS::StringTools::toString( 1234.56 );
|
||||
CPPUNIT_ASSERT_EQUAL( expected, actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testSplitEmptyString()
|
||||
{
|
||||
std::string text;
|
||||
CPPUNIT_NS::StringTools::Strings expected;
|
||||
CPPUNIT_NS::StringTools::Strings actual = CPPUNIT_NS::StringTools::split( text, ';' );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( expected.size(), actual.size() );
|
||||
CPPUNIT_ASSERT( expected == actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testSplitOneItem()
|
||||
{
|
||||
std::string text = "1";
|
||||
CPPUNIT_NS::StringTools::Strings expected;
|
||||
expected.push_back( "1" );
|
||||
CPPUNIT_NS::StringTools::Strings actual = CPPUNIT_NS::StringTools::split( text, ';' );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( expected.size(), actual.size() );
|
||||
CPPUNIT_ASSERT( expected == actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testSplitItemEmpty()
|
||||
{
|
||||
std::string text = "1;";
|
||||
CPPUNIT_NS::StringTools::Strings expected;
|
||||
expected.push_back( "1" );
|
||||
expected.push_back( "" );
|
||||
CPPUNIT_NS::StringTools::Strings actual = CPPUNIT_NS::StringTools::split( text, ';' );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( expected.size(), actual.size() );
|
||||
CPPUNIT_ASSERT( expected == actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testSplitTwoItem()
|
||||
{
|
||||
std::string text = "2;1";
|
||||
CPPUNIT_NS::StringTools::Strings expected;
|
||||
expected.push_back( "2" );
|
||||
expected.push_back( "1" );
|
||||
CPPUNIT_NS::StringTools::Strings actual = CPPUNIT_NS::StringTools::split( text, ';' );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( expected.size(), actual.size() );
|
||||
CPPUNIT_ASSERT( expected == actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testSplitEmptyTwoItem()
|
||||
{
|
||||
std::string text = ";1;2";
|
||||
CPPUNIT_NS::StringTools::Strings expected;
|
||||
expected.push_back( "" );
|
||||
expected.push_back( "1" );
|
||||
expected.push_back( "2" );
|
||||
CPPUNIT_NS::StringTools::Strings actual = CPPUNIT_NS::StringTools::split( text, ';' );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( expected.size(), actual.size() );
|
||||
CPPUNIT_ASSERT( expected == actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testSplitEmptyItemEmpty()
|
||||
{
|
||||
std::string text = ";1;";
|
||||
CPPUNIT_NS::StringTools::Strings expected;
|
||||
expected.push_back( "" );
|
||||
expected.push_back( "1" );
|
||||
expected.push_back( "" );
|
||||
CPPUNIT_NS::StringTools::Strings actual = CPPUNIT_NS::StringTools::split( text, ';' );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( expected.size(), actual.size() );
|
||||
CPPUNIT_ASSERT( expected == actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testSplitEmptyItemEmptyEmptyItem()
|
||||
{
|
||||
std::string text = ";1;;;2";
|
||||
CPPUNIT_NS::StringTools::Strings expected;
|
||||
expected.push_back( "" );
|
||||
expected.push_back( "1" );
|
||||
expected.push_back( "" );
|
||||
expected.push_back( "" );
|
||||
expected.push_back( "2" );
|
||||
CPPUNIT_NS::StringTools::Strings actual = CPPUNIT_NS::StringTools::split( text, ';' );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( expected.size(), actual.size() );
|
||||
CPPUNIT_ASSERT( expected == actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testWrapEmpty()
|
||||
{
|
||||
std::string text = "";
|
||||
std::string expected = "";
|
||||
|
||||
std::string actual = CPPUNIT_NS::StringTools::wrap( text, 6 );
|
||||
CPPUNIT_ASSERT_EQUAL( expected, actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testWrapNotNeeded()
|
||||
{
|
||||
std::string text = "abcd";
|
||||
std::string expected = text;
|
||||
|
||||
std::string actual = CPPUNIT_NS::StringTools::wrap( text, 6 );
|
||||
CPPUNIT_ASSERT_EQUAL( expected, actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testWrapLimitNotNeeded()
|
||||
{
|
||||
std::string text = "abcdef";
|
||||
std::string expected = text;
|
||||
|
||||
std::string actual = CPPUNIT_NS::StringTools::wrap( text, 6 );
|
||||
CPPUNIT_ASSERT_EQUAL( expected, actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testWrapOneNeeded()
|
||||
{
|
||||
std::string text = "abcdefghi";
|
||||
std::string expected = "abcdef\nghi";
|
||||
|
||||
std::string actual = CPPUNIT_NS::StringTools::wrap( text, 6 );
|
||||
CPPUNIT_ASSERT_EQUAL( expected, actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testWrapTwoNeeded()
|
||||
{
|
||||
std::string text = "abcdefghijklmnop";
|
||||
std::string expected = "abcdef\nghijkl\nmnop";
|
||||
|
||||
std::string actual = CPPUNIT_NS::StringTools::wrap( text, 6 );
|
||||
CPPUNIT_ASSERT_EQUAL( expected, actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testWrapLimitTwoNeeded()
|
||||
{
|
||||
std::string text = "abcdefghijklmnopqr";
|
||||
std::string expected = "abcdef\nghijkl\nmnopqr";
|
||||
|
||||
std::string actual = CPPUNIT_NS::StringTools::wrap( text, 6 );
|
||||
CPPUNIT_ASSERT_EQUAL( expected, actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testWrapOneNeededTwoNeeded()
|
||||
{
|
||||
std::string text = "123456789\nabcdefghijklmno";
|
||||
std::string expected = "123456\n789\nabcdef\nghijkl\nmno";
|
||||
|
||||
std::string actual = CPPUNIT_NS::StringTools::wrap( text, 6 );
|
||||
CPPUNIT_ASSERT_EQUAL( expected, actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
StringToolsTest::testWrapNotNeededEmptyLinesOneNeeded()
|
||||
{
|
||||
std::string text = "12345\n\n\n\nabcdefghi";
|
||||
std::string expected = "12345\n\n\n\nabcdef\nghi";
|
||||
|
||||
std::string actual = CPPUNIT_NS::StringTools::wrap( text, 6 );
|
||||
CPPUNIT_ASSERT_EQUAL( expected, actual );
|
||||
}
|
||||
|
74
examples/cppunittest/StringToolsTest.h
Normal file
74
examples/cppunittest/StringToolsTest.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#ifndef STRINGTOOLSTEST_H
|
||||
#define STRINGTOOLSTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/tools/StringTools.h>
|
||||
|
||||
|
||||
/// Unit tests for StringToolsTest
|
||||
class StringToolsTest : public CPPUNIT_NS::TestCase
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( StringToolsTest );
|
||||
CPPUNIT_TEST( testToStringInt );
|
||||
CPPUNIT_TEST( testToStringDouble );
|
||||
CPPUNIT_TEST( testSplitEmptyString );
|
||||
CPPUNIT_TEST( testSplitOneItem );
|
||||
CPPUNIT_TEST( testSplitItemEmpty );
|
||||
CPPUNIT_TEST( testSplitTwoItem );
|
||||
CPPUNIT_TEST( testSplitEmptyTwoItem );
|
||||
CPPUNIT_TEST( testSplitEmptyItemEmpty );
|
||||
CPPUNIT_TEST( testSplitEmptyItemEmptyEmptyItem );
|
||||
CPPUNIT_TEST( testWrapEmpty );
|
||||
CPPUNIT_TEST( testWrapNotNeeded );
|
||||
CPPUNIT_TEST( testWrapLimitNotNeeded );
|
||||
CPPUNIT_TEST( testWrapOneNeeded );
|
||||
CPPUNIT_TEST( testWrapTwoNeeded );
|
||||
CPPUNIT_TEST( testWrapLimitTwoNeeded );
|
||||
CPPUNIT_TEST( testWrapOneNeededTwoNeeded );
|
||||
CPPUNIT_TEST( testWrapNotNeededEmptyLinesOneNeeded );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
/*! Constructs a StringToolsTest object.
|
||||
*/
|
||||
StringToolsTest();
|
||||
|
||||
/// Destructor.
|
||||
virtual ~StringToolsTest();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
void testToStringInt();
|
||||
void testToStringDouble();
|
||||
|
||||
void testSplitEmptyString();
|
||||
void testSplitOneItem();
|
||||
void testSplitItemEmpty();
|
||||
void testSplitTwoItem();
|
||||
void testSplitEmptyTwoItem();
|
||||
void testSplitEmptyItemEmpty();
|
||||
void testSplitEmptyItemEmptyEmptyItem();
|
||||
|
||||
void testWrapEmpty();
|
||||
void testWrapNotNeeded();
|
||||
void testWrapLimitNotNeeded();
|
||||
void testWrapOneNeeded();
|
||||
void testWrapTwoNeeded();
|
||||
void testWrapLimitTwoNeeded();
|
||||
void testWrapOneNeededTwoNeeded();
|
||||
void testWrapNotNeededEmptyLinesOneNeeded();
|
||||
|
||||
private:
|
||||
/// Prevents the use of the copy constructor.
|
||||
StringToolsTest( const StringToolsTest &other );
|
||||
|
||||
/// Prevents the use of the copy operator.
|
||||
void operator =( const StringToolsTest &other );
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // STRINGTOOLSTEST_H
|
37
examples/cppunittest/SubclassedTestCase.cpp
Normal file
37
examples/cppunittest/SubclassedTestCase.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <cppunit/config/SourcePrefix.h>
|
||||
#include "SubclassedTestCase.h"
|
||||
|
||||
|
||||
SubclassedTestCase::SubclassedTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SubclassedTestCase::~SubclassedTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SubclassedTestCase::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SubclassedTestCase::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SubclassedTestCase::checkIt()
|
||||
{
|
||||
CPPUNIT_ASSERT( false );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SubclassedTestCase::testSubclassing()
|
||||
{
|
||||
}
|
35
examples/cppunittest/SubclassedTestCase.h
Normal file
35
examples/cppunittest/SubclassedTestCase.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef SUBCLASSEDTESTCASE_H
|
||||
#define SUBCLASSEDTESTCASE_H
|
||||
|
||||
#include "BaseTestCase.h"
|
||||
|
||||
|
||||
class SubclassedTestCase : public BaseTestCase
|
||||
{
|
||||
CPPUNIT_TEST_SUB_SUITE( SubclassedTestCase, BaseTestCase );
|
||||
CPPUNIT_TEST( testSubclassing );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
SubclassedTestCase();
|
||||
virtual ~SubclassedTestCase();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
// Another test to ensure the subclassed test case are in the suite .
|
||||
void testSubclassing();
|
||||
|
||||
protected:
|
||||
// We overload this method to ensure that the testUsingCheckIt in the
|
||||
// parent class will fail.
|
||||
virtual void checkIt();
|
||||
|
||||
private:
|
||||
SubclassedTestCase( const SubclassedTestCase © );
|
||||
void operator =( const SubclassedTestCase © );
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // SUBCLASSEDTESTCASE_H
|
55
examples/cppunittest/SynchronizedTestResult.h
Normal file
55
examples/cppunittest/SynchronizedTestResult.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef SYNCHRONIZEDTESTRESULT_H
|
||||
#define SYNCHRONIZEDTESTRESULT_H
|
||||
|
||||
#include <cppunit/TestResultCollector.h>
|
||||
|
||||
|
||||
class SynchronizedTestResult : public CPPUNIT_NS::TestResultCollector
|
||||
{
|
||||
public:
|
||||
|
||||
class SynchronizationObjectListener
|
||||
{
|
||||
public:
|
||||
virtual ~SynchronizationObjectListener() {}
|
||||
virtual void locked() {}
|
||||
virtual void unlocked() {}
|
||||
};
|
||||
|
||||
class ObservedSynchronizationObject : public CPPUNIT_NS::SynchronizedObject::SynchronizationObject
|
||||
{
|
||||
public:
|
||||
ObservedSynchronizationObject( SynchronizationObjectListener *listener ) :
|
||||
m_listener( listener )
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~ObservedSynchronizationObject()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void lock()
|
||||
{
|
||||
m_listener->locked();
|
||||
}
|
||||
|
||||
virtual void unlock()
|
||||
{
|
||||
m_listener->unlocked();
|
||||
}
|
||||
|
||||
private:
|
||||
SynchronizationObjectListener *m_listener;
|
||||
};
|
||||
|
||||
|
||||
SynchronizedTestResult( SynchronizationObjectListener *listener )
|
||||
{
|
||||
setSynchronizationObject( new ObservedSynchronizationObject( listener ) );
|
||||
}
|
||||
|
||||
virtual ~SynchronizedTestResult() {}
|
||||
|
||||
};
|
||||
|
||||
#endif // SYNCHRONIZEDTESTRESULT_H
|
269
examples/cppunittest/TestAssertTest.cpp
Normal file
269
examples/cppunittest/TestAssertTest.cpp
Normal file
@@ -0,0 +1,269 @@
|
||||
#include "CoreSuite.h"
|
||||
#include "TestAssertTest.h"
|
||||
#include <cppunit/portability/FloatingPoint.h>
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
/*
|
||||
Note:
|
||||
- tests need to be added to test asserEquals() template function and
|
||||
use of assertion traits. Some check may need to be added to check
|
||||
the message content in Exception.
|
||||
- code need to be refactored with the use of a test caller that expect
|
||||
an exception.
|
||||
*/
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestAssertTest,
|
||||
coreSuiteName() );
|
||||
|
||||
|
||||
TestAssertTest::TestAssertTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TestAssertTest::~TestAssertTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestAssertTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestAssertTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestAssertTest::testAssertThrow()
|
||||
{
|
||||
CPPUNIT_ASSERT_THROW( throw std::string(), std::string );
|
||||
|
||||
try
|
||||
{
|
||||
int x;
|
||||
CPPUNIT_ASSERT_THROW( x = 1234, std::string );
|
||||
}
|
||||
catch ( CPPUNIT_NS::Exception & )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestAssertTest::testAssertNoThrow()
|
||||
{
|
||||
int x;
|
||||
CPPUNIT_ASSERT_NO_THROW( x = 1234 );
|
||||
|
||||
try
|
||||
{
|
||||
CPPUNIT_ASSERT_NO_THROW( throw std::exception() );
|
||||
}
|
||||
catch ( CPPUNIT_NS::Exception & )
|
||||
{
|
||||
return;
|
||||
}
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestAssertTest::testAssertAssertionFail()
|
||||
{
|
||||
CPPUNIT_ASSERT_ASSERTION_FAIL( throw CPPUNIT_NS::Exception() );
|
||||
|
||||
try
|
||||
{
|
||||
int x;
|
||||
CPPUNIT_ASSERT_ASSERTION_FAIL( x = 1234 );
|
||||
}
|
||||
catch ( CPPUNIT_NS::Exception & )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestAssertTest::testAssertAssertionPass()
|
||||
{
|
||||
int x;
|
||||
CPPUNIT_ASSERT_ASSERTION_PASS( x = 1234 );
|
||||
|
||||
try
|
||||
{
|
||||
CPPUNIT_ASSERT_ASSERTION_PASS( throw CPPUNIT_NS::Exception() );
|
||||
}
|
||||
catch ( CPPUNIT_NS::Exception & )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestAssertTest::testAssert()
|
||||
{
|
||||
CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT( true ) );
|
||||
|
||||
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT( false ) );
|
||||
}
|
||||
|
||||
|
||||
static int foo() { return 1; }
|
||||
|
||||
|
||||
void
|
||||
TestAssertTest::testAssertEqual()
|
||||
{
|
||||
CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT_EQUAL( 1, 1 ) );
|
||||
CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT_EQUAL( 1, foo() ) );
|
||||
CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT_EQUAL( 12345678, 12345678 ) );
|
||||
|
||||
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_EQUAL( 1, 2 ) );
|
||||
}
|
||||
|
||||
void
|
||||
TestAssertTest::testAssertMessageTrue()
|
||||
{
|
||||
CPPUNIT_ASSERT_ASSERTION_PASS(
|
||||
CPPUNIT_ASSERT_MESSAGE( "This test should not failed", true ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestAssertTest::testAssertMessageFalse()
|
||||
{
|
||||
bool exceptionCaught = false;
|
||||
std::string message( "This test message should not be seen" );
|
||||
try
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE( message, 2==3 );
|
||||
}
|
||||
catch( CPPUNIT_NS::Exception &e )
|
||||
{
|
||||
exceptionCaught = true; // ok, we were expecting an exception.
|
||||
checkMessageContains( &e, message );
|
||||
}
|
||||
|
||||
CPPUNIT_ASSERT( exceptionCaught );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestAssertTest::testAssertDoubleEquals()
|
||||
{
|
||||
CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.1, 1.2, 0.101 ) );
|
||||
CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.2, 1.1, 0.101 ) );
|
||||
|
||||
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.1, 1.2, 0.09 ) );
|
||||
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.2, 1.1, 0.09 ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* Test that the error message from CPPUNIT_ASSERT_DOUBLES_EQUAL()
|
||||
* has more than the default 6 digits of precision.
|
||||
*/
|
||||
void
|
||||
TestAssertTest::testAssertDoubleEqualsPrecision()
|
||||
{
|
||||
std::string failure( "2.000000001" );
|
||||
try
|
||||
{
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, 2.000000001, 1 );
|
||||
}
|
||||
catch( CPPUNIT_NS::Exception &e )
|
||||
{
|
||||
checkMessageContains( &e, failure );
|
||||
return;
|
||||
}
|
||||
CPPUNIT_FAIL( "Expected assertion failure" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestAssertTest::testAssertDoubleNonFinite()
|
||||
{
|
||||
double inf = std::numeric_limits<double>::infinity();
|
||||
double nan = std::numeric_limits<double>::quiet_NaN();
|
||||
// test our portable floating-point primitives that detect NaN values
|
||||
CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsUnordered( nan ) );
|
||||
CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( inf ) );
|
||||
CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( -inf ) );
|
||||
CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( 1.0 ) );
|
||||
CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( 1.5 ) );
|
||||
CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( 2.0 ) );
|
||||
CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( 2.5 ) );
|
||||
CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( 0.0 ) );
|
||||
CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( -1.0 ) );
|
||||
CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsUnordered( -2.0 ) );
|
||||
// test our portable floating-point primitives that detect finite values
|
||||
CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsFinite( 0.0 ) );
|
||||
CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsFinite( 0.5 ) );
|
||||
CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsFinite( 1.0 ) );
|
||||
CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsFinite( 1.5 ) );
|
||||
CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsFinite( 2.0 ) );
|
||||
CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsFinite( 2.5 ) );
|
||||
CPPUNIT_ASSERT( CPPUNIT_NS::floatingPointIsFinite( -1.5 ) );
|
||||
CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsFinite( nan ) );
|
||||
CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsFinite( inf ) );
|
||||
CPPUNIT_ASSERT( !CPPUNIT_NS::floatingPointIsFinite( -inf ) );
|
||||
// Infinity tests
|
||||
CPPUNIT_ASSERT( inf == inf );
|
||||
CPPUNIT_ASSERT( -inf == -inf );
|
||||
CPPUNIT_ASSERT( -inf != inf );
|
||||
CPPUNIT_ASSERT( -inf < inf );
|
||||
CPPUNIT_ASSERT( inf > -inf );
|
||||
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( inf, 0.0, 1.0 ) );
|
||||
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, inf, 1.0 ) );
|
||||
CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT_DOUBLES_EQUAL( inf, inf, 1.0 ) );
|
||||
// NaN tests
|
||||
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, 0.0, 1.0 ) );
|
||||
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, nan, 1.0 ) );
|
||||
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( nan, inf, 1.0 ) );
|
||||
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( inf, nan, 1.0 ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestAssertTest::testFail()
|
||||
{
|
||||
bool exceptionCaught = false;
|
||||
std::string failure( "FailureMessage" );
|
||||
try
|
||||
{
|
||||
CPPUNIT_FAIL( failure );
|
||||
}
|
||||
catch( CPPUNIT_NS::Exception &e )
|
||||
{
|
||||
exceptionCaught = true;
|
||||
checkMessageContains( &e, failure );
|
||||
}
|
||||
CPPUNIT_ASSERT( exceptionCaught );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestAssertTest::checkMessageContains( CPPUNIT_NS::Exception *e,
|
||||
std::string expected )
|
||||
{
|
||||
std::string actual = e->what();
|
||||
CPPUNIT_ASSERT_MESSAGE( "Expected message not found: " + expected +
|
||||
", was: " + actual,
|
||||
std::search( actual.begin(), actual.end(),
|
||||
expected.begin(), expected.end() ) != actual.end() );
|
||||
}
|
69
examples/cppunittest/TestAssertTest.h
Normal file
69
examples/cppunittest/TestAssertTest.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#ifndef TESTASSERTTEST_H
|
||||
#define TESTASSERTTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
||||
class TestAssertTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( TestAssertTest );
|
||||
CPPUNIT_TEST( testAssertThrow );
|
||||
CPPUNIT_TEST( testAssertNoThrow );
|
||||
CPPUNIT_TEST( testAssertAssertionFail );
|
||||
CPPUNIT_TEST( testAssertAssertionPass );
|
||||
CPPUNIT_TEST( testAssert );
|
||||
CPPUNIT_TEST( testAssertEqual );
|
||||
CPPUNIT_TEST( testAssertMessageTrue );
|
||||
CPPUNIT_TEST( testAssertMessageFalse );
|
||||
CPPUNIT_TEST( testAssertDoubleEquals );
|
||||
CPPUNIT_TEST( testAssertDoubleEqualsPrecision );
|
||||
CPPUNIT_TEST( testAssertDoubleNonFinite );
|
||||
CPPUNIT_TEST( testFail );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
TestAssertTest();
|
||||
|
||||
virtual ~TestAssertTest();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
void testAssertThrow();
|
||||
void testAssertNoThrow();
|
||||
void testAssertAssertionFail();
|
||||
void testAssertAssertionPass();
|
||||
|
||||
void testBasicAssertions();
|
||||
|
||||
void testAssert();
|
||||
|
||||
void testAssertEqual();
|
||||
|
||||
void testAssertMessageTrue();
|
||||
void testAssertMessageFalse();
|
||||
|
||||
void testAssertDoubleEquals();
|
||||
void testAssertDoubleEqualsPrecision();
|
||||
void testAssertDoubleNonFinite();
|
||||
|
||||
void testAssertLongEquals();
|
||||
void testAssertLongNotEquals();
|
||||
|
||||
void testFail();
|
||||
|
||||
private:
|
||||
TestAssertTest( const TestAssertTest © );
|
||||
void operator =( const TestAssertTest © );
|
||||
|
||||
void checkDoubleNotEquals( double expected,
|
||||
double actual,
|
||||
double delta );
|
||||
|
||||
void checkMessageContains( CPPUNIT_NS::Exception *e,
|
||||
std::string expectedMessage );
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // TESTASSERTTEST_H
|
219
examples/cppunittest/TestCallerTest.cpp
Normal file
219
examples/cppunittest/TestCallerTest.cpp
Normal file
@@ -0,0 +1,219 @@
|
||||
#include "FailureException.h"
|
||||
#include "HelperSuite.h"
|
||||
#include "TestCallerTest.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestCallerTest,
|
||||
helperSuiteName() );
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::ExceptionThrower::testThrowFailureException()
|
||||
{
|
||||
throw FailureException();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::ExceptionThrower::testThrowException()
|
||||
{
|
||||
throw CPPUNIT_NS::Exception( CPPUNIT_NS::Message( "expected Exception" ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::ExceptionThrower::testThrowNothing()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
TestCallerTest::TestCallerTest() :
|
||||
m_testName( "TrackedTestCaseCaller" )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TestCallerTest::~TestCallerTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::setUp()
|
||||
{
|
||||
m_constructorCount = 0;
|
||||
m_destructorCount = 0;
|
||||
m_setUpCount = 0;
|
||||
m_tearDownCount = 0;
|
||||
m_testCount = 0;
|
||||
TrackedTestCase::setTracker( this );
|
||||
m_testListener = new MockTestListener( "listener1" );
|
||||
m_result = new CPPUNIT_NS::TestResult();
|
||||
m_result->addListener( m_testListener );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::tearDown()
|
||||
{
|
||||
TrackedTestCase::removeTracker();
|
||||
delete m_result;
|
||||
delete m_testListener;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::onConstructor()
|
||||
{
|
||||
m_constructorCount++;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::onDestructor()
|
||||
{
|
||||
m_destructorCount++;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::onSetUp()
|
||||
{
|
||||
m_setUpCount++;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::onTearDown()
|
||||
{
|
||||
m_tearDownCount++;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::onTest()
|
||||
{
|
||||
m_testCount++;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::testBasicConstructor()
|
||||
{
|
||||
{
|
||||
CPPUNIT_NS::TestCaller<TrackedTestCase> caller( m_testName,
|
||||
&TrackedTestCase::test );
|
||||
checkTestName( caller.getName() );
|
||||
checkNothingButConstructorCalled();
|
||||
|
||||
caller.run( m_result );
|
||||
|
||||
checkRunningSequenceCalled();
|
||||
} // Force destruction of the test caller.
|
||||
CPPUNIT_ASSERT_EQUAL( 1, m_destructorCount );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::testReferenceConstructor()
|
||||
{
|
||||
TrackedTestCase testCase;
|
||||
{
|
||||
CPPUNIT_NS::TestCaller<TrackedTestCase> caller( "TrackedTestCaseCaller",
|
||||
&TrackedTestCase::test,
|
||||
testCase );
|
||||
checkTestName( caller.getName() );
|
||||
checkNothingButConstructorCalled();
|
||||
|
||||
caller.run( m_result );
|
||||
|
||||
checkRunningSequenceCalled();
|
||||
} // Force destruction of the test caller.
|
||||
CPPUNIT_ASSERT_EQUAL( 0, m_destructorCount );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::testPointerConstructor()
|
||||
{
|
||||
TrackedTestCase *testCase = new TrackedTestCase();
|
||||
{
|
||||
CPPUNIT_NS::TestCaller<TrackedTestCase> caller( m_testName,
|
||||
&TrackedTestCase::test,
|
||||
testCase );
|
||||
checkTestName( caller.getName() );
|
||||
checkNothingButConstructorCalled();
|
||||
|
||||
caller.run( m_result );
|
||||
|
||||
checkRunningSequenceCalled();
|
||||
} // Force destruction of the test caller.
|
||||
CPPUNIT_ASSERT_EQUAL( 1, m_destructorCount );
|
||||
}
|
||||
|
||||
/*
|
||||
// Now done by ExceptionTestCaseDecorator
|
||||
|
||||
void
|
||||
TestCallerTest::testExpectFailureException()
|
||||
{
|
||||
CPPUNIT_NS::TestCaller<ExceptionThrower,FailureException> caller(
|
||||
m_testName,
|
||||
&ExceptionThrower::testThrowFailureException );
|
||||
m_testListener->setExpectNoFailure();
|
||||
caller.run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::testExpectException()
|
||||
{
|
||||
CPPUNIT_NS::TestCaller<ExceptionThrower,CPPUNIT_NS::Exception> caller(
|
||||
m_testName,
|
||||
&ExceptionThrower::testThrowException );
|
||||
m_testListener->setExpectNoFailure();
|
||||
caller.run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::testExpectedExceptionNotCaught()
|
||||
{
|
||||
CPPUNIT_NS::TestCaller<ExceptionThrower,FailureException> caller(
|
||||
m_testName,
|
||||
&ExceptionThrower::testThrowNothing );
|
||||
m_testListener->setExpectedAddFailureCall( 1 );
|
||||
caller.run( m_result );
|
||||
m_testListener->verify();
|
||||
}
|
||||
*/
|
||||
|
||||
void
|
||||
TestCallerTest::checkNothingButConstructorCalled()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL( 1, m_constructorCount );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, m_destructorCount );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, m_setUpCount );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, m_tearDownCount );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, m_testCount );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::checkRunningSequenceCalled()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL( 1, m_setUpCount );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, m_testCount );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, m_tearDownCount );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCallerTest::checkTestName( std::string testName )
|
||||
{
|
||||
CPPUNIT_ASSERT( testName == m_testName );
|
||||
}
|
77
examples/cppunittest/TestCallerTest.h
Normal file
77
examples/cppunittest/TestCallerTest.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef TESTCALLERTEST_H
|
||||
#define TESTCALLERTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/TestCase.h>
|
||||
#include <cppunit/TestResult.h>
|
||||
#include <cppunit/TestSuite.h>
|
||||
#include "MockTestListener.h"
|
||||
#include "TrackedTestCase.h"
|
||||
|
||||
class TestCallerTest : public CPPUNIT_NS::TestFixture,
|
||||
Tracker
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( TestCallerTest );
|
||||
CPPUNIT_TEST( testBasicConstructor );
|
||||
CPPUNIT_TEST( testReferenceConstructor );
|
||||
CPPUNIT_TEST( testPointerConstructor );
|
||||
// CPPUNIT_TEST( testExpectFailureException );
|
||||
// CPPUNIT_TEST( testExpectException );
|
||||
// CPPUNIT_TEST( testExpectedExceptionNotCaught );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
TestCallerTest();
|
||||
virtual ~TestCallerTest();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
void testBasicConstructor();
|
||||
void testReferenceConstructor();
|
||||
void testPointerConstructor();
|
||||
|
||||
// void testExpectFailureException();
|
||||
// void testExpectException();
|
||||
// void testExpectedExceptionNotCaught();
|
||||
|
||||
private:
|
||||
class ExceptionThrower : public CPPUNIT_NS::TestCase
|
||||
{
|
||||
public:
|
||||
void testThrowFailureException();
|
||||
void testThrowException();
|
||||
void testThrowNothing();
|
||||
};
|
||||
|
||||
virtual void onConstructor();
|
||||
virtual void onDestructor();
|
||||
virtual void onSetUp();
|
||||
virtual void onTearDown();
|
||||
virtual void onTest();
|
||||
|
||||
void checkNothingButConstructorCalled();
|
||||
void checkRunningSequenceCalled();
|
||||
void checkTestName( std::string testName );
|
||||
|
||||
TestCallerTest( const TestCallerTest © );
|
||||
void operator =( const TestCallerTest © );
|
||||
|
||||
private:
|
||||
int m_constructorCount;
|
||||
int m_destructorCount;
|
||||
int m_setUpCount;
|
||||
int m_tearDownCount;
|
||||
int m_testCount;
|
||||
const std::string m_testName;
|
||||
MockTestListener *m_testListener;
|
||||
CPPUNIT_NS::TestResult *m_result;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Inlines methods for TestCallerTest:
|
||||
// -----------------------------------
|
||||
|
||||
|
||||
|
||||
#endif // TESTCALLERTEST_H
|
161
examples/cppunittest/TestCaseTest.cpp
Normal file
161
examples/cppunittest/TestCaseTest.cpp
Normal file
@@ -0,0 +1,161 @@
|
||||
#include "CoreSuite.h"
|
||||
#include "FailureException.h"
|
||||
#include "MockTestCase.h"
|
||||
#include "TestCaseTest.h"
|
||||
#include <cppunit/TestResult.h>
|
||||
|
||||
/*
|
||||
- test have been done to check exception management in run(). other
|
||||
tests need to be added to check the other aspect of TestCase.
|
||||
*/
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestCaseTest,
|
||||
coreSuiteName() );
|
||||
|
||||
|
||||
TestCaseTest::TestCaseTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TestCaseTest::~TestCaseTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCaseTest::setUp()
|
||||
{
|
||||
m_testListener = new MockTestListener( "mock-testlistener" );
|
||||
m_result = new CPPUNIT_NS::TestResult();
|
||||
m_result->addListener( m_testListener );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCaseTest::tearDown()
|
||||
{
|
||||
delete m_result;
|
||||
delete m_testListener;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCaseTest::testSetUpFailure()
|
||||
{
|
||||
checkFailure( true, false, false );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCaseTest::testRunTestFailure()
|
||||
{
|
||||
checkFailure( false, true, false );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCaseTest::testTearDownFailure()
|
||||
{
|
||||
checkFailure( false, false, true );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCaseTest::testFailAll()
|
||||
{
|
||||
checkFailure( true, true, true );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCaseTest::testNoFailure()
|
||||
{
|
||||
checkFailure( false, false, false );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCaseTest::checkFailure( bool failSetUp,
|
||||
bool failRunTest,
|
||||
bool failTearDown )
|
||||
{
|
||||
try
|
||||
{
|
||||
MockTestCase testCase( "mock-test" );
|
||||
if ( failSetUp )
|
||||
testCase.makeSetUpThrow();
|
||||
if ( failRunTest )
|
||||
testCase.makeRunTestThrow();
|
||||
if ( failTearDown )
|
||||
testCase.makeTearDownThrow();
|
||||
testCase.setExpectedSetUpCall( 1 );
|
||||
testCase.setExpectedRunTestCall( failSetUp ? 0 : 1 );
|
||||
testCase.setExpectedTearDownCall( failSetUp ? 0 : 1 );
|
||||
|
||||
testCase.run( m_result );
|
||||
|
||||
testCase.verify();
|
||||
}
|
||||
catch ( FailureException & )
|
||||
{
|
||||
CPPUNIT_ASSERT_MESSAGE( "exception should have been caught", false );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCaseTest::testCountTestCases()
|
||||
{
|
||||
CPPUNIT_NS::TestCase test;
|
||||
CPPUNIT_ASSERT_EQUAL( 1, test.countTestCases() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCaseTest::testDefaultConstructor()
|
||||
{
|
||||
CPPUNIT_NS::TestCase test;
|
||||
CPPUNIT_ASSERT_EQUAL( std::string(""), test.getName() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCaseTest::testConstructorWithName()
|
||||
{
|
||||
std::string testName( "TestName" );
|
||||
CPPUNIT_NS::TestCase test( testName );
|
||||
CPPUNIT_ASSERT_EQUAL( testName, test.getName() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCaseTest::testTwoRun()
|
||||
{
|
||||
MockTestCase test1( "mocktest1" );
|
||||
test1.makeRunTestThrow();
|
||||
m_testListener->setExpectedStartTestCall( 2 );
|
||||
m_testListener->setExpectedAddFailureCall( 2 );
|
||||
m_testListener->setExpectedEndTestCall( 2 );
|
||||
|
||||
test1.run( m_result );
|
||||
test1.run( m_result );
|
||||
|
||||
m_testListener->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCaseTest::testGetChildTestCount()
|
||||
{
|
||||
CPPUNIT_NS::TestCase test( "test" );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, test.getChildTestCount() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestCaseTest::testGetChildTestAtThrow()
|
||||
{
|
||||
CPPUNIT_NS::TestCase test( "test" );
|
||||
test.getChildTestAt( 0 );
|
||||
}
|
73
examples/cppunittest/TestCaseTest.h
Normal file
73
examples/cppunittest/TestCaseTest.h
Normal file
@@ -0,0 +1,73 @@
|
||||
// //////////////////////////////////////////////////////////////////////////
|
||||
// Header file TestCaseTest.h for class TestCaseTest
|
||||
// (c)Copyright 2000, Baptiste Lepilleur.
|
||||
// Created: 2000/06/09
|
||||
// //////////////////////////////////////////////////////////////////////////
|
||||
#ifndef TESTCASETEST_H
|
||||
#define TESTCASETEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/TestResult.h>
|
||||
#include "MockTestListener.h"
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
class TestCaseTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( TestCaseTest );
|
||||
CPPUNIT_TEST( testSetUpFailure );
|
||||
CPPUNIT_TEST( testRunTestFailure );
|
||||
CPPUNIT_TEST( testTearDownFailure );
|
||||
CPPUNIT_TEST( testFailAll );
|
||||
CPPUNIT_TEST( testNoFailure );
|
||||
CPPUNIT_TEST( testTwoRun );
|
||||
CPPUNIT_TEST( testCountTestCases );
|
||||
CPPUNIT_TEST( testDefaultConstructor );
|
||||
CPPUNIT_TEST( testConstructorWithName );
|
||||
CPPUNIT_TEST( testGetChildTestCount );
|
||||
CPPUNIT_TEST_EXCEPTION( testGetChildTestAtThrow, std::out_of_range );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
TestCaseTest();
|
||||
|
||||
virtual ~TestCaseTest();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
void testSetUpFailure();
|
||||
void testRunTestFailure();
|
||||
void testTearDownFailure();
|
||||
void testFailAll();
|
||||
void testNoFailure();
|
||||
void testTwoRun();
|
||||
|
||||
void testCountTestCases();
|
||||
|
||||
void testDefaultConstructor();
|
||||
void testConstructorWithName();
|
||||
|
||||
void testGetChildTestCount();
|
||||
void testGetChildTestAtThrow();
|
||||
|
||||
private:
|
||||
TestCaseTest( const TestCaseTest © );
|
||||
void operator =( const TestCaseTest © );
|
||||
|
||||
void checkFailure( bool failSetUp,
|
||||
bool failRunTest,
|
||||
bool failTearDown );
|
||||
/*
|
||||
void checkResult( int failures,
|
||||
int errors,
|
||||
int testsRun,
|
||||
CPPUNIT_NS::TestResult *result );
|
||||
*/
|
||||
private:
|
||||
CPPUNIT_NS::TestResult *m_result;
|
||||
MockTestListener *m_testListener;
|
||||
};
|
||||
|
||||
|
||||
#endif // TESTCASETEST_H
|
61
examples/cppunittest/TestDecoratorTest.cpp
Normal file
61
examples/cppunittest/TestDecoratorTest.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "ExtensionSuite.h"
|
||||
#include "TestDecoratorTest.h"
|
||||
#include <cppunit/TestResult.h>
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestDecoratorTest,
|
||||
extensionSuiteName() );
|
||||
|
||||
|
||||
TestDecoratorTest::TestDecoratorTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TestDecoratorTest::~TestDecoratorTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestDecoratorTest::setUp()
|
||||
{
|
||||
m_test = new MockTestCase( "mocktest" );
|
||||
m_decorator = new CPPUNIT_NS::TestDecorator( m_test );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestDecoratorTest::tearDown()
|
||||
{
|
||||
delete m_decorator;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestDecoratorTest::testCountTestCases()
|
||||
{
|
||||
m_test->setExpectedCountTestCasesCall( 1 );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, m_decorator->countTestCases() );
|
||||
m_test->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestDecoratorTest::testRun()
|
||||
{
|
||||
m_test->setExpectedSetUpCall( 1 );
|
||||
m_test->setExpectedRunTestCall( 1 );
|
||||
m_test->setExpectedTearDownCall( 1 );
|
||||
CPPUNIT_NS::TestResult result;
|
||||
|
||||
m_decorator->run( &result );
|
||||
m_test->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestDecoratorTest::testGetName()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL( m_test->getName(), m_decorator->getName() );
|
||||
}
|
39
examples/cppunittest/TestDecoratorTest.h
Normal file
39
examples/cppunittest/TestDecoratorTest.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef TESTDECORATORTEST_H
|
||||
#define TESTDECORATORTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestDecorator.h>
|
||||
#include "MockTestCase.h"
|
||||
|
||||
|
||||
class TestDecoratorTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( TestDecoratorTest );
|
||||
CPPUNIT_TEST( testCountTestCases );
|
||||
CPPUNIT_TEST( testRun );
|
||||
CPPUNIT_TEST( testGetName );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
TestDecoratorTest();
|
||||
virtual ~TestDecoratorTest();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
void testCountTestCases();
|
||||
void testRun();
|
||||
void testGetName();
|
||||
|
||||
private:
|
||||
TestDecoratorTest( const TestDecoratorTest © );
|
||||
void operator =( const TestDecoratorTest © );
|
||||
|
||||
private:
|
||||
MockTestCase *m_test;
|
||||
CPPUNIT_NS::TestDecorator *m_decorator;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // TESTDECORATORTEST_H
|
70
examples/cppunittest/TestFailureTest.cpp
Normal file
70
examples/cppunittest/TestFailureTest.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "CoreSuite.h"
|
||||
#include "TestFailureTest.h"
|
||||
#include <cppunit/TestFailure.h>
|
||||
#include <cppunit/Exception.h>
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestFailureTest,
|
||||
coreSuiteName() );
|
||||
|
||||
|
||||
TestFailureTest::TestFailureTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TestFailureTest::~TestFailureTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestFailureTest::setUp()
|
||||
{
|
||||
m_exceptionDestroyed = false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestFailureTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestFailureTest::testConstructorAndGetters()
|
||||
{
|
||||
CPPUNIT_NS::TestCase test;
|
||||
CPPUNIT_NS::Exception *error = new ObservedException( this );
|
||||
checkTestFailure( &test, error, false );
|
||||
CPPUNIT_ASSERT( m_exceptionDestroyed );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestFailureTest::testConstructorAndGettersForError()
|
||||
{
|
||||
CPPUNIT_NS::TestCase test;
|
||||
CPPUNIT_NS::Exception *error = new ObservedException( this );
|
||||
checkTestFailure( &test, error, true );
|
||||
CPPUNIT_ASSERT( m_exceptionDestroyed );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestFailureTest::exceptionDestroyed()
|
||||
{
|
||||
m_exceptionDestroyed = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestFailureTest::checkTestFailure( CPPUNIT_NS::Test *test,
|
||||
CPPUNIT_NS::Exception *error,
|
||||
bool isError )
|
||||
{
|
||||
CPPUNIT_NS::TestFailure failure( test, error, isError );
|
||||
CPPUNIT_ASSERT_EQUAL( test, failure.failedTest() );
|
||||
CPPUNIT_ASSERT_EQUAL( error, failure.thrownException() );
|
||||
CPPUNIT_ASSERT_EQUAL( isError, failure.isError() );
|
||||
}
|
57
examples/cppunittest/TestFailureTest.h
Normal file
57
examples/cppunittest/TestFailureTest.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef TESTFAILURETEST_H
|
||||
#define TESTFAILURETEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
||||
class TestFailureTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( TestFailureTest );
|
||||
CPPUNIT_TEST( testConstructorAndGetters );
|
||||
CPPUNIT_TEST( testConstructorAndGettersForError );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
TestFailureTest();
|
||||
virtual ~TestFailureTest();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
void testConstructorAndGetters();
|
||||
void testConstructorAndGettersForError();
|
||||
|
||||
void exceptionDestroyed();
|
||||
|
||||
private:
|
||||
class ObservedException : public CPPUNIT_NS::Exception
|
||||
{
|
||||
public:
|
||||
ObservedException( TestFailureTest *listener ) :
|
||||
CPPUNIT_NS::Exception( CPPUNIT_NS::Message("ObservedException" ) ),
|
||||
m_listener( listener )
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~ObservedException() throw()
|
||||
{
|
||||
m_listener->exceptionDestroyed();
|
||||
}
|
||||
private:
|
||||
TestFailureTest *m_listener;
|
||||
};
|
||||
|
||||
|
||||
TestFailureTest( const TestFailureTest © );
|
||||
void operator =( const TestFailureTest © );
|
||||
void checkTestFailure( CPPUNIT_NS::Test *test,
|
||||
CPPUNIT_NS::Exception *error,
|
||||
bool isError );
|
||||
|
||||
private:
|
||||
bool m_exceptionDestroyed;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // TESTFAILURETEST_H
|
490
examples/cppunittest/TestPathTest.cpp
Normal file
490
examples/cppunittest/TestPathTest.cpp
Normal file
@@ -0,0 +1,490 @@
|
||||
#include "CoreSuite.h"
|
||||
#include "TestPathTest.h"
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestPathTest,
|
||||
coreSuiteName() );
|
||||
|
||||
|
||||
TestPathTest::TestPathTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TestPathTest::~TestPathTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::setUp()
|
||||
{
|
||||
m_path = new CPPUNIT_NS::TestPath();
|
||||
m_test1 = new CPPUNIT_NS::TestCase( "test1" );
|
||||
m_test2 = new CPPUNIT_NS::TestCase( "test2" );
|
||||
m_test3 = new CPPUNIT_NS::TestCase( "test3" );
|
||||
m_test4 = new CPPUNIT_NS::TestCase( "test4" );
|
||||
|
||||
m_suite1 = new CPPUNIT_NS::TestSuite( "All Tests" );
|
||||
m_suite2 = new CPPUNIT_NS::TestSuite( "Custom" );
|
||||
m_testSuite2a = new CPPUNIT_NS::TestCase( "MyTest::testDefaultConstructor" );
|
||||
m_testSuite2b = new CPPUNIT_NS::TestCase( "MyTest::testConstructor" );
|
||||
m_suite2->addTest( m_testSuite2a );
|
||||
m_suite2->addTest( m_testSuite2b );
|
||||
m_suite1->addTest( m_suite2 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::tearDown()
|
||||
{
|
||||
delete m_suite1;
|
||||
delete m_path;
|
||||
delete m_test4;
|
||||
delete m_test3;
|
||||
delete m_test2;
|
||||
delete m_test1;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testDefaultConstructor()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL( 0, m_path->getTestCount() );
|
||||
CPPUNIT_ASSERT( !m_path->isValid() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testAddTest()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, m_path->getTestCount() );
|
||||
CPPUNIT_ASSERT( m_path->isValid() );
|
||||
CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(0) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testGetTestAtThrow1()
|
||||
{
|
||||
m_path->getTestAt( 0 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testGetTestAtThrow2()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
m_path->getTestAt( 1 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testGetChildTest()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
CPPUNIT_ASSERT( m_test1 == m_path->getChildTest() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testGetChildTestManyTests()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
m_path->add( m_test2 );
|
||||
m_path->add( m_test3 );
|
||||
CPPUNIT_ASSERT( m_test3 == m_path->getChildTest() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testGetChildTestThrowIfNotValid()
|
||||
{
|
||||
m_path->getChildTest();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testAddPath()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path;
|
||||
path.add( m_test2 );
|
||||
path.add( m_test3 );
|
||||
|
||||
m_path->add( m_test1 );
|
||||
m_path->add( path );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 3, m_path->getTestCount() );
|
||||
CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(0) );
|
||||
CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(1) );
|
||||
CPPUNIT_ASSERT( m_test3 == m_path->getTestAt(2) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testAddInvalidPath()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path;
|
||||
m_path->add( path );
|
||||
|
||||
CPPUNIT_ASSERT( !m_path->isValid() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testRemoveTests()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
m_path->add( m_test2 );
|
||||
|
||||
m_path->removeTests();
|
||||
|
||||
CPPUNIT_ASSERT( !m_path->isValid() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testRemoveTest()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
m_path->add( m_test2 );
|
||||
|
||||
m_path->removeTest( 0 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 1, m_path->getTestCount() );
|
||||
CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(0) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testRemoveTestThrow1()
|
||||
{
|
||||
m_path->removeTest( -1 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testRemoveTestThrow2()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
|
||||
m_path->removeTest( 1 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testUp()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
|
||||
m_path->up();
|
||||
|
||||
CPPUNIT_ASSERT( !m_path->isValid() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testUpThrow()
|
||||
{
|
||||
m_path->up();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testInsert()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
|
||||
m_path->insert( m_test2, 0 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 2, m_path->getTestCount() );
|
||||
CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(0) );
|
||||
CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(1) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testInsertAtEnd()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
|
||||
m_path->insert( m_test2, 1 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 2, m_path->getTestCount() );
|
||||
CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(0) );
|
||||
CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(1) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testInsertThrow1()
|
||||
{
|
||||
m_path->insert( m_test1, -1 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testInsertThrow2()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
|
||||
m_path->insert( m_test1, 2 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testInsertPath()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path;
|
||||
path.add( m_test2 );
|
||||
path.add( m_test3 );
|
||||
|
||||
m_path->add( m_test1 );
|
||||
m_path->add( m_test4 );
|
||||
m_path->insert( path, 1 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 4, m_path->getTestCount() );
|
||||
CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(0) );
|
||||
CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(1) );
|
||||
CPPUNIT_ASSERT( m_test3 == m_path->getTestAt(2) );
|
||||
CPPUNIT_ASSERT( m_test4 == m_path->getTestAt(3) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testInsertPathThrow()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path;
|
||||
path.add( m_test2 );
|
||||
|
||||
m_path->insert( path, 1 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testInsertPathDontThrowIfInvalid()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path;
|
||||
m_path->insert( path, 1 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testRootConstructor()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path( m_test1 );
|
||||
CPPUNIT_ASSERT( path.isValid() );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() );
|
||||
CPPUNIT_ASSERT( m_test1 == path.getTestAt(0) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathSliceConstructorCopyUntilEnd()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
m_path->add( m_test2 );
|
||||
m_path->add( m_test3 );
|
||||
|
||||
CPPUNIT_NS::TestPath path( *m_path, 1 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 2, path.getTestCount() );
|
||||
CPPUNIT_ASSERT( m_test2 == path.getTestAt(0) );
|
||||
CPPUNIT_ASSERT( m_test3 == path.getTestAt(1) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathSliceConstructorCopySpecifiedCount()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
m_path->add( m_test2 );
|
||||
m_path->add( m_test3 );
|
||||
|
||||
CPPUNIT_NS::TestPath path( *m_path, 0, 1 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() );
|
||||
CPPUNIT_ASSERT( m_test1 == path.getTestAt(0) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathSliceConstructorCopyNone()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
|
||||
CPPUNIT_NS::TestPath path( *m_path, 0, 0 );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, path.getTestCount() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathSliceConstructorNegativeIndex()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
m_path->add( m_test2 );
|
||||
|
||||
CPPUNIT_NS::TestPath path( *m_path, -1, 2 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() );
|
||||
CPPUNIT_ASSERT( m_test1 == path.getTestAt(0) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathSliceConstructorAfterEndIndex()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
m_path->add( m_test2 );
|
||||
|
||||
CPPUNIT_NS::TestPath path( *m_path, 2, 5 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 0, path.getTestCount() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathSliceConstructorNegativeIndexUntilEnd()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
m_path->add( m_test2 );
|
||||
|
||||
CPPUNIT_NS::TestPath path( *m_path, -1 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 2, path.getTestCount() );
|
||||
CPPUNIT_ASSERT( m_test1 == path.getTestAt(0) );
|
||||
CPPUNIT_ASSERT( m_test2 == path.getTestAt(1) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathSliceConstructorNegativeIndexNone()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
m_path->add( m_test2 );
|
||||
|
||||
CPPUNIT_NS::TestPath path( *m_path, -2, 1 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 0, path.getTestCount() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testToStringNoTest()
|
||||
{
|
||||
std::string expected = "/";
|
||||
std::string actual = m_path->toString();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( expected, actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testToStringOneTest()
|
||||
{
|
||||
m_path->add( m_test1 );
|
||||
|
||||
std::string expected = "/test1";
|
||||
std::string actual = m_path->toString();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( expected, actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testToStringHierarchy()
|
||||
{
|
||||
m_path->add( m_suite1 );
|
||||
m_path->add( m_suite2 );
|
||||
m_path->add( m_suite2->getChildTestAt(0) );
|
||||
|
||||
std::string expected = "/All Tests/Custom/MyTest::testDefaultConstructor";
|
||||
std::string actual = m_path->toString();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( expected, actual );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathStringConstructorRoot()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path( m_suite1, "/All Tests" );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() );
|
||||
CPPUNIT_ASSERT( m_suite1 == path.getTestAt(0) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathStringConstructorEmptyIsRoot()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path( m_suite1, "" );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() );
|
||||
CPPUNIT_ASSERT( m_suite1 == path.getTestAt(0) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathStringConstructorHierarchy()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path( m_suite1, "/All Tests/Custom/MyTest::testDefaultConstructor" );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 3, path.getTestCount() );
|
||||
CPPUNIT_ASSERT( m_suite1 == path.getTestAt(0) );
|
||||
CPPUNIT_ASSERT( m_suite2 == path.getTestAt(1) );
|
||||
CPPUNIT_ASSERT( m_testSuite2a == path.getTestAt(2) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathStringConstructorBadRootThrow()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path( m_suite1, "/Custom" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathStringConstructorRelativeRoot()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path( m_suite1, "All Tests" );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() );
|
||||
CPPUNIT_ASSERT( m_suite1 == path.getTestAt(0) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathStringConstructorRelativeRoot2()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path( m_suite1, "Custom" );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() );
|
||||
CPPUNIT_ASSERT( m_suite2 == path.getTestAt(0) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathStringConstructorThrow1()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path( m_suite1, "/" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathStringConstructorRelativeHierarchy()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path( m_suite1, "Custom/MyTest::testConstructor" );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 2, path.getTestCount() );
|
||||
CPPUNIT_ASSERT( m_suite2 == path.getTestAt(0) );
|
||||
CPPUNIT_ASSERT( m_testSuite2b == path.getTestAt(1) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPathTest::testPathStringConstructorBadRelativeHierarchyThrow()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path( m_suite1, "Custom/MyBadTest::testConstructor" );
|
||||
}
|
142
examples/cppunittest/TestPathTest.h
Normal file
142
examples/cppunittest/TestPathTest.h
Normal file
@@ -0,0 +1,142 @@
|
||||
#ifndef TESTPATHTEST_H
|
||||
#define TESTPATHTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/TestPath.h>
|
||||
#include <cppunit/TestCase.h>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
/*! \class TestPathTest
|
||||
* \brief Unit tests for class TestPath.
|
||||
*/
|
||||
class TestPathTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( TestPathTest );
|
||||
CPPUNIT_TEST( testDefaultConstructor );
|
||||
CPPUNIT_TEST( testAddTest );
|
||||
CPPUNIT_TEST_EXCEPTION( testGetTestAtThrow1, std::out_of_range );
|
||||
CPPUNIT_TEST_EXCEPTION( testGetTestAtThrow2, std::out_of_range );
|
||||
CPPUNIT_TEST( testGetChildTest );
|
||||
CPPUNIT_TEST( testGetChildTestManyTests );
|
||||
CPPUNIT_TEST_EXCEPTION( testGetChildTestThrowIfNotValid, std::out_of_range );
|
||||
CPPUNIT_TEST( testAddPath );
|
||||
CPPUNIT_TEST( testAddInvalidPath );
|
||||
CPPUNIT_TEST( testRemoveTests );
|
||||
CPPUNIT_TEST( testRemoveTest );
|
||||
CPPUNIT_TEST_EXCEPTION( testRemoveTestThrow1, std::out_of_range );
|
||||
CPPUNIT_TEST_EXCEPTION( testRemoveTestThrow2, std::out_of_range );
|
||||
CPPUNIT_TEST( testUp );
|
||||
CPPUNIT_TEST_EXCEPTION( testUpThrow, std::out_of_range );
|
||||
CPPUNIT_TEST( testInsert );
|
||||
CPPUNIT_TEST( testInsertAtEnd );
|
||||
CPPUNIT_TEST_EXCEPTION( testInsertThrow1, std::out_of_range );
|
||||
CPPUNIT_TEST_EXCEPTION( testInsertThrow2, std::out_of_range );
|
||||
CPPUNIT_TEST( testInsertPath );
|
||||
CPPUNIT_TEST_EXCEPTION( testInsertPathThrow, std::out_of_range );
|
||||
CPPUNIT_TEST( testInsertPathDontThrowIfInvalid );
|
||||
CPPUNIT_TEST( testRootConstructor );
|
||||
CPPUNIT_TEST( testPathSliceConstructorCopyUntilEnd );
|
||||
CPPUNIT_TEST( testPathSliceConstructorCopySpecifiedCount );
|
||||
CPPUNIT_TEST( testPathSliceConstructorCopyNone );
|
||||
CPPUNIT_TEST( testPathSliceConstructorNegativeIndex );
|
||||
CPPUNIT_TEST( testPathSliceConstructorAfterEndIndex );
|
||||
CPPUNIT_TEST( testPathSliceConstructorNegativeIndexUntilEnd );
|
||||
CPPUNIT_TEST( testPathSliceConstructorNegativeIndexNone );
|
||||
CPPUNIT_TEST( testToStringNoTest );
|
||||
CPPUNIT_TEST( testToStringOneTest );
|
||||
CPPUNIT_TEST( testToStringHierarchy );
|
||||
CPPUNIT_TEST( testPathStringConstructorRoot );
|
||||
CPPUNIT_TEST( testPathStringConstructorEmptyIsRoot );
|
||||
CPPUNIT_TEST( testPathStringConstructorHierarchy );
|
||||
CPPUNIT_TEST_EXCEPTION( testPathStringConstructorBadRootThrow, std::invalid_argument );
|
||||
CPPUNIT_TEST( testPathStringConstructorRelativeRoot );
|
||||
CPPUNIT_TEST( testPathStringConstructorRelativeRoot2 );
|
||||
CPPUNIT_TEST_EXCEPTION( testPathStringConstructorThrow1, std::invalid_argument );
|
||||
CPPUNIT_TEST( testPathStringConstructorRelativeHierarchy );
|
||||
CPPUNIT_TEST_EXCEPTION( testPathStringConstructorBadRelativeHierarchyThrow, std::invalid_argument );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
/*! Constructs a TestPathTest object.
|
||||
*/
|
||||
TestPathTest();
|
||||
|
||||
/// Destructor.
|
||||
virtual ~TestPathTest();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
void testDefaultConstructor();
|
||||
void testAddTest();
|
||||
void testGetTestAtThrow1();
|
||||
void testGetTestAtThrow2();
|
||||
void testGetChildTest();
|
||||
void testGetChildTestManyTests();
|
||||
void testGetChildTestThrowIfNotValid();
|
||||
|
||||
void testAddPath();
|
||||
void testAddInvalidPath();
|
||||
|
||||
void testRemoveTests();
|
||||
void testRemoveTest();
|
||||
void testRemoveTestThrow1();
|
||||
void testRemoveTestThrow2();
|
||||
void testUp();
|
||||
void testUpThrow();
|
||||
|
||||
void testInsert();
|
||||
void testInsertAtEnd();
|
||||
void testInsertThrow1();
|
||||
void testInsertThrow2();
|
||||
|
||||
void testInsertPath();
|
||||
void testInsertPathThrow();
|
||||
void testInsertPathDontThrowIfInvalid();
|
||||
|
||||
void testRootConstructor();
|
||||
void testPathSliceConstructorCopyUntilEnd();
|
||||
void testPathSliceConstructorCopySpecifiedCount();
|
||||
void testPathSliceConstructorCopyNone();
|
||||
void testPathSliceConstructorNegativeIndex();
|
||||
void testPathSliceConstructorAfterEndIndex();
|
||||
void testPathSliceConstructorNegativeIndexUntilEnd();
|
||||
void testPathSliceConstructorNegativeIndexNone();
|
||||
|
||||
void testToStringNoTest();
|
||||
void testToStringOneTest();
|
||||
void testToStringHierarchy();
|
||||
|
||||
void testPathStringConstructorRoot();
|
||||
void testPathStringConstructorEmptyIsRoot();
|
||||
void testPathStringConstructorHierarchy();
|
||||
void testPathStringConstructorBadRootThrow();
|
||||
void testPathStringConstructorRelativeRoot();
|
||||
void testPathStringConstructorRelativeRoot2();
|
||||
void testPathStringConstructorThrow1();
|
||||
void testPathStringConstructorRelativeHierarchy();
|
||||
void testPathStringConstructorBadRelativeHierarchyThrow();
|
||||
|
||||
private:
|
||||
/// Prevents the use of the copy constructor.
|
||||
TestPathTest( const TestPathTest © );
|
||||
|
||||
/// Prevents the use of the copy operator.
|
||||
void operator =( const TestPathTest © );
|
||||
|
||||
private:
|
||||
CPPUNIT_NS::TestPath *m_path;
|
||||
CPPUNIT_NS::TestCase *m_test1;
|
||||
CPPUNIT_NS::TestCase *m_test2;
|
||||
CPPUNIT_NS::TestCase *m_test3;
|
||||
CPPUNIT_NS::TestCase *m_test4;
|
||||
CPPUNIT_NS::TestSuite *m_suite1;
|
||||
CPPUNIT_NS::TestSuite *m_suite2;
|
||||
CPPUNIT_NS::TestCase *m_testSuite2a;
|
||||
CPPUNIT_NS::TestCase *m_testSuite2b;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // TESTPATHTEST_H
|
297
examples/cppunittest/TestResultCollectorTest.cpp
Normal file
297
examples/cppunittest/TestResultCollectorTest.cpp
Normal file
@@ -0,0 +1,297 @@
|
||||
#include "CoreSuite.h"
|
||||
#include "TestResultCollectorTest.h"
|
||||
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestResultCollectorTest,
|
||||
coreSuiteName() );
|
||||
|
||||
|
||||
TestResultCollectorTest::TestResultCollectorTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TestResultCollectorTest::~TestResultCollectorTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::setUp()
|
||||
{
|
||||
m_lockCount = 0;
|
||||
m_unlockCount = 0;
|
||||
m_result = new CPPUNIT_NS::TestResultCollector();
|
||||
m_synchronizedResult = new SynchronizedTestResult( this );
|
||||
m_test = new CPPUNIT_NS::TestCase();
|
||||
m_test2 = new CPPUNIT_NS::TestCase();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::tearDown()
|
||||
{
|
||||
delete m_test2;
|
||||
delete m_test;
|
||||
delete m_synchronizedResult;
|
||||
delete m_result;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testConstructor()
|
||||
{
|
||||
checkResult( 0, 0, 0 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testAddTwoErrors()
|
||||
{
|
||||
CPPUNIT_NS::Message errorMessage1( "First Error" );
|
||||
CPPUNIT_NS::Message errorMessage2( "Second Error" );
|
||||
{
|
||||
CPPUNIT_NS::TestFailure failure1( m_test,
|
||||
new CPPUNIT_NS::Exception( errorMessage1 ),
|
||||
true );
|
||||
m_result->addFailure( failure1 );
|
||||
|
||||
CPPUNIT_NS::TestFailure failure2( m_test2,
|
||||
new CPPUNIT_NS::Exception( errorMessage2 ),
|
||||
true );
|
||||
m_result->addFailure( failure2 );
|
||||
} // ensure that the test result duplicate the failures.
|
||||
|
||||
checkResult( 0, 2, 0 );
|
||||
checkFailure( m_result->failures()[0],
|
||||
errorMessage1,
|
||||
m_test,
|
||||
true );
|
||||
checkFailure( m_result->failures()[1],
|
||||
errorMessage2,
|
||||
m_test2,
|
||||
true );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testAddTwoFailures()
|
||||
{
|
||||
CPPUNIT_NS::Message errorMessage1( "First Failure" );
|
||||
CPPUNIT_NS::Message errorMessage2( "Second Failure" );
|
||||
{
|
||||
CPPUNIT_NS::TestFailure failure1( m_test,
|
||||
new CPPUNIT_NS::Exception( errorMessage1 ),
|
||||
false );
|
||||
m_result->addFailure( failure1 );
|
||||
|
||||
CPPUNIT_NS::TestFailure failure2( m_test2,
|
||||
new CPPUNIT_NS::Exception( errorMessage2 ),
|
||||
false );
|
||||
m_result->addFailure( failure2 );
|
||||
} // ensure that the test result duplicate the failures.
|
||||
checkResult( 2, 0, 0 );
|
||||
checkFailure( m_result->failures()[0],
|
||||
errorMessage1,
|
||||
m_test,
|
||||
false );
|
||||
checkFailure( m_result->failures()[1],
|
||||
errorMessage2,
|
||||
m_test2,
|
||||
false );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testStartTest()
|
||||
{
|
||||
m_result->startTest( m_test );
|
||||
m_result->startTest( m_test );
|
||||
checkResult( 0, 0, 2 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testWasSuccessfulWithNoTest()
|
||||
{
|
||||
checkWasSuccessful( true );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testWasSuccessfulWithErrors()
|
||||
{
|
||||
addError( "Error1" );
|
||||
addError( "Error2" );
|
||||
checkWasSuccessful( false );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testWasSuccessfulWithFailures()
|
||||
{
|
||||
addFailure( "Failure1" );
|
||||
addFailure( "Failure2" );
|
||||
checkWasSuccessful( false );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testWasSuccessfulWithErrorsAndFailures()
|
||||
{
|
||||
addError( "Error1" );
|
||||
addFailure( "Failure2" );
|
||||
checkWasSuccessful( false );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testWasSuccessfulWithSuccessfulTest()
|
||||
{
|
||||
m_result->startTest( m_test );
|
||||
m_result->endTest( m_test );
|
||||
m_result->startTest( m_test2 );
|
||||
m_result->endTest( m_test2 );
|
||||
checkWasSuccessful( true );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testSynchronizationAddFailure()
|
||||
{
|
||||
addFailure( "Failure1", m_test, false, m_synchronizedResult );
|
||||
checkSynchronization();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testSynchronizationStartTest()
|
||||
{
|
||||
m_synchronizedResult->startTest( m_test );
|
||||
checkSynchronization();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testSynchronizationRunTests()
|
||||
{
|
||||
m_synchronizedResult->runTests();
|
||||
checkSynchronization();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testSynchronizationTestErrors()
|
||||
{
|
||||
m_synchronizedResult->testErrors();
|
||||
checkSynchronization();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testSynchronizationTestFailures()
|
||||
{
|
||||
m_synchronizedResult->testFailures();
|
||||
checkSynchronization();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testSynchronizationFailures()
|
||||
{
|
||||
m_synchronizedResult->failures();
|
||||
checkSynchronization();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::testSynchronizationWasSuccessful()
|
||||
{
|
||||
m_synchronizedResult->wasSuccessful();
|
||||
checkSynchronization();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::checkResult( int failures,
|
||||
int errors,
|
||||
int testsRun )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL( testsRun, m_result->runTests() );
|
||||
CPPUNIT_ASSERT_EQUAL( errors, m_result->testErrors() );
|
||||
CPPUNIT_ASSERT_EQUAL( failures, m_result->testFailures() );
|
||||
CPPUNIT_ASSERT_EQUAL( errors + failures,
|
||||
m_result->testFailuresTotal() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::checkFailure( CPPUNIT_NS::TestFailure *failure,
|
||||
CPPUNIT_NS::Message expectedMessage,
|
||||
CPPUNIT_NS::Test *expectedTest,
|
||||
bool expectedIsError )
|
||||
{
|
||||
CPPUNIT_NS::Message actualMessage( failure->thrownException()->message() );
|
||||
CPPUNIT_ASSERT( expectedMessage == actualMessage );
|
||||
CPPUNIT_ASSERT_EQUAL( expectedTest, failure->failedTest() );
|
||||
CPPUNIT_ASSERT_EQUAL( expectedIsError, failure->isError() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::checkWasSuccessful( bool shouldBeSuccessful )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL( shouldBeSuccessful, m_result->wasSuccessful() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::locked()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL( m_lockCount, m_unlockCount );
|
||||
++m_lockCount;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::unlocked()
|
||||
{
|
||||
++m_unlockCount;
|
||||
CPPUNIT_ASSERT_EQUAL( m_lockCount, m_unlockCount );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::checkSynchronization()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL( m_lockCount, m_unlockCount );
|
||||
CPPUNIT_ASSERT( m_lockCount > 0 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::addFailure( std::string message )
|
||||
{
|
||||
addFailure( message, m_test, false, m_result );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::addError( std::string message )
|
||||
{
|
||||
addFailure( message, m_test, true, m_result );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultCollectorTest::addFailure( std::string message,
|
||||
CPPUNIT_NS::Test *failedTest,
|
||||
bool isError,
|
||||
CPPUNIT_NS::TestResultCollector *result )
|
||||
{
|
||||
CPPUNIT_NS::TestFailure failure( failedTest,
|
||||
new CPPUNIT_NS::Exception( CPPUNIT_NS::Message( message ) ),
|
||||
isError );
|
||||
result->addFailure( failure );
|
||||
}
|
96
examples/cppunittest/TestResultCollectorTest.h
Normal file
96
examples/cppunittest/TestResultCollectorTest.h
Normal file
@@ -0,0 +1,96 @@
|
||||
#ifndef TESTCOLLECTORRESULTTEST_H
|
||||
#define TESTCOLLECTORRESULTTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/TestFailure.h>
|
||||
#include "SynchronizedTestResult.h"
|
||||
|
||||
|
||||
class TestResultCollectorTest : public CPPUNIT_NS::TestFixture,
|
||||
public SynchronizedTestResult::SynchronizationObjectListener
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( TestResultCollectorTest );
|
||||
CPPUNIT_TEST( testConstructor );
|
||||
CPPUNIT_TEST( testAddTwoErrors );
|
||||
CPPUNIT_TEST( testAddTwoFailures );
|
||||
CPPUNIT_TEST( testStartTest );
|
||||
CPPUNIT_TEST( testWasSuccessfulWithErrors );
|
||||
CPPUNIT_TEST( testWasSuccessfulWithFailures );
|
||||
CPPUNIT_TEST( testWasSuccessfulWithErrorsAndFailures );
|
||||
CPPUNIT_TEST( testWasSuccessfulWithSuccessfulTest );
|
||||
CPPUNIT_TEST( testSynchronizationAddFailure );
|
||||
CPPUNIT_TEST( testSynchronizationStartTest );
|
||||
CPPUNIT_TEST( testSynchronizationRunTests );
|
||||
CPPUNIT_TEST( testSynchronizationTestErrors );
|
||||
CPPUNIT_TEST( testSynchronizationTestFailures );
|
||||
CPPUNIT_TEST( testSynchronizationFailures );
|
||||
CPPUNIT_TEST( testSynchronizationWasSuccessful );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
TestResultCollectorTest();
|
||||
virtual ~TestResultCollectorTest();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
void testConstructor();
|
||||
|
||||
void testAddTwoErrors();
|
||||
void testAddTwoFailures();
|
||||
void testStartTest();
|
||||
|
||||
void testWasSuccessfulWithNoTest();
|
||||
void testWasSuccessfulWithErrors();
|
||||
void testWasSuccessfulWithFailures();
|
||||
void testWasSuccessfulWithErrorsAndFailures();
|
||||
void testWasSuccessfulWithSuccessfulTest();
|
||||
|
||||
void testSynchronizationAddFailure();
|
||||
void testSynchronizationStartTest();
|
||||
void testSynchronizationRunTests();
|
||||
void testSynchronizationTestErrors();
|
||||
void testSynchronizationTestFailures();
|
||||
void testSynchronizationErrors();
|
||||
void testSynchronizationFailures();
|
||||
void testSynchronizationWasSuccessful();
|
||||
|
||||
virtual void locked();
|
||||
virtual void unlocked();
|
||||
|
||||
private:
|
||||
TestResultCollectorTest( const TestResultCollectorTest © );
|
||||
void operator =( const TestResultCollectorTest © );
|
||||
|
||||
void checkResult( int failures,
|
||||
int errors,
|
||||
int testsRun );
|
||||
|
||||
void checkFailure( CPPUNIT_NS::TestFailure *failure,
|
||||
CPPUNIT_NS::Message expectedMessage,
|
||||
CPPUNIT_NS::Test *expectedTest,
|
||||
bool expectedIsError );
|
||||
|
||||
void checkWasSuccessful( bool shouldBeSuccessful );
|
||||
|
||||
void checkSynchronization();
|
||||
|
||||
void addFailure( std::string message );
|
||||
void addError( std::string message );
|
||||
void addFailure( std::string message,
|
||||
CPPUNIT_NS::Test *failedTest,
|
||||
bool isError,
|
||||
CPPUNIT_NS::TestResultCollector *result );
|
||||
|
||||
private:
|
||||
CPPUNIT_NS::TestResultCollector *m_result;
|
||||
SynchronizedTestResult *m_synchronizedResult;
|
||||
CPPUNIT_NS::Test *m_test;
|
||||
CPPUNIT_NS::Test *m_test2;
|
||||
int m_lockCount;
|
||||
int m_unlockCount;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // TESTCOLLECTORRESULTTEST_H
|
268
examples/cppunittest/TestResultTest.cpp
Normal file
268
examples/cppunittest/TestResultTest.cpp
Normal file
@@ -0,0 +1,268 @@
|
||||
#include "CoreSuite.h"
|
||||
#include "MockFunctor.h"
|
||||
#include "MockProtector.h"
|
||||
#include "MockTestCase.h"
|
||||
#include "TestResultTest.h"
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestResultTest,
|
||||
coreSuiteName() );
|
||||
|
||||
|
||||
TestResultTest::TestResultTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TestResultTest::~TestResultTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::setUp()
|
||||
{
|
||||
m_result = new CPPUNIT_NS::TestResult();
|
||||
m_listener1 = new MockTestListener( "listener1" );
|
||||
m_listener2 = new MockTestListener( "listener2" );
|
||||
m_dummyTest = new MockTestCase( "dummy-test" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::tearDown()
|
||||
{
|
||||
delete m_dummyTest;
|
||||
delete m_listener1;
|
||||
delete m_listener2;
|
||||
delete m_result;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testConstructor()
|
||||
{
|
||||
CPPUNIT_ASSERT( !m_result->shouldStop() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testStop()
|
||||
{
|
||||
m_result->stop();
|
||||
CPPUNIT_ASSERT( m_result->shouldStop() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testAddError()
|
||||
{
|
||||
CPPUNIT_NS::Exception *dummyException = new CPPUNIT_NS::Exception(
|
||||
CPPUNIT_NS::Message( "some_error" ) );
|
||||
m_listener1->setExpectFailure( m_dummyTest, dummyException, true );
|
||||
m_result->addListener( m_listener1 );
|
||||
|
||||
m_result->addError( m_dummyTest, dummyException );
|
||||
|
||||
m_listener1->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testAddFailure()
|
||||
{
|
||||
CPPUNIT_NS::Exception *dummyException = new CPPUNIT_NS::Exception(
|
||||
CPPUNIT_NS::Message("some_error" ) );
|
||||
m_listener1->setExpectFailure( m_dummyTest, dummyException, false );
|
||||
m_result->addListener( m_listener1 );
|
||||
|
||||
m_result->addFailure( m_dummyTest, dummyException );
|
||||
|
||||
m_listener1->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testStartTest()
|
||||
{
|
||||
m_listener1->setExpectStartTest( m_dummyTest );
|
||||
m_result->addListener( m_listener1 );
|
||||
|
||||
m_result->startTest( m_dummyTest );
|
||||
|
||||
m_listener1->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testEndTest()
|
||||
{
|
||||
m_listener1->setExpectEndTest( m_dummyTest );
|
||||
m_result->addListener( m_listener1 );
|
||||
|
||||
m_result->endTest( m_dummyTest );
|
||||
|
||||
m_listener1->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testStartSuite()
|
||||
{
|
||||
m_listener1->setExpectStartSuite( m_dummyTest );
|
||||
m_result->addListener( m_listener1 );
|
||||
|
||||
m_result->startSuite( m_dummyTest );
|
||||
|
||||
m_listener1->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testEndSuite()
|
||||
{
|
||||
m_listener1->setExpectEndSuite( m_dummyTest );
|
||||
m_result->addListener( m_listener1 );
|
||||
|
||||
m_result->endSuite( m_dummyTest );
|
||||
|
||||
m_listener1->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testRunTest()
|
||||
{
|
||||
m_listener1->setExpectStartTestRun( m_dummyTest, m_result );
|
||||
m_listener1->setExpectEndTestRun( m_dummyTest, m_result );
|
||||
m_result->addListener( m_listener1 );
|
||||
|
||||
m_result->runTest( m_dummyTest );
|
||||
|
||||
m_listener1->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testTwoListener()
|
||||
{
|
||||
m_listener1->setExpectStartTest( m_dummyTest );
|
||||
m_listener2->setExpectStartTest( m_dummyTest );
|
||||
CPPUNIT_NS::Exception *dummyException1 = new CPPUNIT_NS::Exception(
|
||||
CPPUNIT_NS::Message( "some_error" ) );
|
||||
m_listener1->setExpectFailure( m_dummyTest, dummyException1, true );
|
||||
m_listener2->setExpectFailure( m_dummyTest, dummyException1, true );
|
||||
m_listener1->setExpectEndTest( m_dummyTest );
|
||||
m_listener2->setExpectEndTest( m_dummyTest );
|
||||
m_result->addListener( m_listener1 );
|
||||
m_result->addListener( m_listener2 );
|
||||
|
||||
m_result->startTest( m_dummyTest );
|
||||
m_result->addError( m_dummyTest, dummyException1 );
|
||||
m_result->endTest( m_dummyTest );
|
||||
|
||||
m_listener1->verify();
|
||||
m_listener2->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testDefaultProtectSucceed()
|
||||
{
|
||||
MockFunctor functor;
|
||||
functor.setShouldSucceed();
|
||||
m_listener1->setExpectNoFailure();
|
||||
|
||||
m_result->addListener( m_listener1 );
|
||||
CPPUNIT_ASSERT( m_result->protect( functor, m_dummyTest ) );
|
||||
m_listener1->verify();
|
||||
functor.verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testDefaultProtectFail()
|
||||
{
|
||||
MockFunctor functor;
|
||||
functor.setShouldFail();
|
||||
m_listener1->setExpectNoFailure();
|
||||
|
||||
m_result->addListener( m_listener1 );
|
||||
CPPUNIT_ASSERT( !m_result->protect( functor, m_dummyTest ) );
|
||||
m_listener1->verify();
|
||||
functor.verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testDefaultProtectFailIfThrow()
|
||||
{
|
||||
MockFunctor functor;
|
||||
functor.setThrowFailureException();
|
||||
m_listener1->setExpectFailure();
|
||||
|
||||
m_result->addListener( m_listener1 );
|
||||
CPPUNIT_ASSERT( !m_result->protect( functor, m_dummyTest ) );
|
||||
m_listener1->verify();
|
||||
functor.verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testProtectChainPushOneTrap()
|
||||
{
|
||||
MockFunctor functor;
|
||||
MockProtector *protector = new MockProtector();
|
||||
functor.setThrowMockProtectorException();
|
||||
protector->setExpectException();
|
||||
m_listener1->setExpectFailure();
|
||||
|
||||
m_result->pushProtector( protector );
|
||||
m_result->addListener( m_listener1 );
|
||||
CPPUNIT_ASSERT( !m_result->protect( functor, m_dummyTest ) );
|
||||
protector->verify();
|
||||
m_listener1->verify();
|
||||
functor.verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testProtectChainPushOnePassThrough()
|
||||
{
|
||||
MockFunctor functor;
|
||||
MockProtector *protector = new MockProtector();
|
||||
functor.setThrowFailureException();
|
||||
protector->setExpectNoException();
|
||||
m_listener1->setExpectFailure();
|
||||
|
||||
m_result->pushProtector( protector );
|
||||
m_result->addListener( m_listener1 );
|
||||
CPPUNIT_ASSERT( !m_result->protect( functor, m_dummyTest ) );
|
||||
protector->verify();
|
||||
m_listener1->verify();
|
||||
functor.verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestResultTest::testProtectChainPushTwoTrap()
|
||||
{
|
||||
MockFunctor functor;
|
||||
functor.setThrowMockProtectorException();
|
||||
// protector1 catch the exception retrown by protector2
|
||||
MockProtector *protector1 = new MockProtector();
|
||||
protector1->setExpectException();
|
||||
// protector2 catch the exception and rethrow it
|
||||
MockProtector *protector2 = new MockProtector();
|
||||
protector2->setExpectCatchAndPropagateException();
|
||||
m_listener1->setExpectFailure();
|
||||
|
||||
m_result->pushProtector( protector1 );
|
||||
m_result->pushProtector( protector2 );
|
||||
m_result->addListener( m_listener1 );
|
||||
CPPUNIT_ASSERT( !m_result->protect( functor, m_dummyTest ) );
|
||||
protector1->verify();
|
||||
protector2->verify();
|
||||
m_listener1->verify();
|
||||
functor.verify();
|
||||
}
|
72
examples/cppunittest/TestResultTest.h
Normal file
72
examples/cppunittest/TestResultTest.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef TESTRESULTTEST_H
|
||||
#define TESTRESULTTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/TestResult.h>
|
||||
#include "MockTestListener.h"
|
||||
|
||||
|
||||
class TestResultTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( TestResultTest );
|
||||
CPPUNIT_TEST( testConstructor );
|
||||
CPPUNIT_TEST( testStop );
|
||||
CPPUNIT_TEST( testAddError );
|
||||
CPPUNIT_TEST( testAddFailure );
|
||||
CPPUNIT_TEST( testStartTest );
|
||||
CPPUNIT_TEST( testEndTest );
|
||||
CPPUNIT_TEST( testStartSuite );
|
||||
CPPUNIT_TEST( testEndSuite );
|
||||
CPPUNIT_TEST( testRunTest );
|
||||
CPPUNIT_TEST( testTwoListener );
|
||||
CPPUNIT_TEST( testDefaultProtectSucceed );
|
||||
CPPUNIT_TEST( testDefaultProtectFail );
|
||||
CPPUNIT_TEST( testDefaultProtectFailIfThrow );
|
||||
CPPUNIT_TEST( testProtectChainPushOneTrap );
|
||||
CPPUNIT_TEST( testProtectChainPushOnePassThrough );
|
||||
CPPUNIT_TEST( testProtectChainPushTwoTrap );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
TestResultTest();
|
||||
virtual ~TestResultTest();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
void testConstructor();
|
||||
void testStop();
|
||||
|
||||
void testAddError();
|
||||
void testAddFailure();
|
||||
void testStartTest();
|
||||
void testEndTest();
|
||||
void testStartSuite();
|
||||
void testEndSuite();
|
||||
void testRunTest();
|
||||
|
||||
void testTwoListener();
|
||||
|
||||
void testDefaultProtectSucceed();
|
||||
void testDefaultProtectFail();
|
||||
void testDefaultProtectFailIfThrow();
|
||||
|
||||
void testProtectChainPushOneTrap();
|
||||
void testProtectChainPushOnePassThrough();
|
||||
|
||||
void testProtectChainPushTwoTrap();
|
||||
|
||||
private:
|
||||
TestResultTest( const TestResultTest © );
|
||||
void operator =( const TestResultTest © );
|
||||
|
||||
private:
|
||||
CPPUNIT_NS::TestResult *m_result;
|
||||
MockTestListener *m_listener1;
|
||||
MockTestListener *m_listener2;
|
||||
CPPUNIT_NS::Test *m_dummyTest;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // TESTRESULTTEST_H
|
47
examples/cppunittest/TestSetUpTest.cpp
Normal file
47
examples/cppunittest/TestSetUpTest.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "ExtensionSuite.h"
|
||||
#include "TestSetUpTest.h"
|
||||
#include <cppunit/TestResult.h>
|
||||
#include "MockTestCase.h"
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestSetUpTest,
|
||||
extensionSuiteName() );
|
||||
|
||||
|
||||
TestSetUpTest::TestSetUpTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TestSetUpTest::~TestSetUpTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSetUpTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSetUpTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSetUpTest::testRun()
|
||||
{
|
||||
CPPUNIT_NS::TestResult result;
|
||||
MockTestCase *test = new MockTestCase( "TestSetUpTest" );
|
||||
test->setExpectedSetUpCall();
|
||||
test->setExpectedRunTestCall();
|
||||
test->setExpectedTearDownCall();
|
||||
MockSetUp setUpTest( test );
|
||||
|
||||
setUpTest.run( &result );
|
||||
|
||||
setUpTest.verify();
|
||||
test->verify();
|
||||
}
|
63
examples/cppunittest/TestSetUpTest.h
Normal file
63
examples/cppunittest/TestSetUpTest.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#ifndef TESTSETUPTEST_H
|
||||
#define TESTSETUPTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestSetUp.h>
|
||||
|
||||
|
||||
class TestSetUpTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( TestSetUpTest );
|
||||
CPPUNIT_TEST( testRun );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
TestSetUpTest();
|
||||
virtual ~TestSetUpTest();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
void testRun();
|
||||
|
||||
private:
|
||||
class MockSetUp : public CPPUNIT_NS::TestSetUp
|
||||
{
|
||||
public:
|
||||
MockSetUp( CPPUNIT_NS::Test *test )
|
||||
: CPPUNIT_NS::TestSetUp( test )
|
||||
, m_setUpCalled( false )
|
||||
, m_tearDownCalled( false )
|
||||
{
|
||||
}
|
||||
|
||||
void setUp()
|
||||
{
|
||||
m_setUpCalled = true;
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
m_tearDownCalled = true;
|
||||
}
|
||||
|
||||
void verify()
|
||||
{
|
||||
CPPUNIT_ASSERT( m_setUpCalled );
|
||||
CPPUNIT_ASSERT( m_tearDownCalled );
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_setUpCalled;
|
||||
bool m_tearDownCalled;
|
||||
};
|
||||
|
||||
TestSetUpTest( const TestSetUpTest © );
|
||||
void operator =( const TestSetUpTest © );
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // TESTSETUPTEST_H
|
179
examples/cppunittest/TestSuiteTest.cpp
Normal file
179
examples/cppunittest/TestSuiteTest.cpp
Normal file
@@ -0,0 +1,179 @@
|
||||
#include "CoreSuite.h"
|
||||
#include "TestSuiteTest.h"
|
||||
#include <cppunit/TestResult.h>
|
||||
#include "MockTestCase.h"
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestSuiteTest,
|
||||
coreSuiteName() );
|
||||
|
||||
|
||||
TestSuiteTest::TestSuiteTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TestSuiteTest::~TestSuiteTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSuiteTest::setUp()
|
||||
{
|
||||
m_suite = new CPPUNIT_NS::TestSuite();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSuiteTest::tearDown()
|
||||
{
|
||||
delete m_suite;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSuiteTest::testConstructor()
|
||||
{
|
||||
std::string name( "MySuite" );
|
||||
CPPUNIT_NS::TestSuite suite( name );
|
||||
CPPUNIT_ASSERT_EQUAL( name, suite.getName() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSuiteTest::testCountTestCasesWithNoTest()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL( 0, m_suite->countTestCases() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSuiteTest::testCountTestCasesWithTwoTests()
|
||||
{
|
||||
MockTestCase *case1 = new MockTestCase( "test1" );
|
||||
case1->setExpectedCountTestCasesCall();
|
||||
MockTestCase *case2 = new MockTestCase( "test2" );
|
||||
case2->setExpectedCountTestCasesCall();
|
||||
m_suite->addTest( case1 );
|
||||
m_suite->addTest( case2 );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 2, m_suite->countTestCases() );
|
||||
case1->verify();
|
||||
case2->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSuiteTest::testCountTestCasesWithSubSuite()
|
||||
{
|
||||
MockTestCase *case1 = new MockTestCase( "test1" );
|
||||
case1->setExpectedCountTestCasesCall();
|
||||
MockTestCase *case2 = new MockTestCase( "test2" );
|
||||
case2->setExpectedCountTestCasesCall();
|
||||
MockTestCase *case3 = new MockTestCase( "test3" );
|
||||
case3->setExpectedCountTestCasesCall();
|
||||
CPPUNIT_NS::TestSuite *subSuite = new CPPUNIT_NS::TestSuite( "SubSuite");
|
||||
subSuite->addTest( case1 );
|
||||
subSuite->addTest( case2 );
|
||||
m_suite->addTest( case3 );
|
||||
m_suite->addTest( subSuite );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 3, m_suite->countTestCases() );
|
||||
case1->verify();
|
||||
case2->verify();
|
||||
case3->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSuiteTest::testRunWithOneTest()
|
||||
{
|
||||
MockTestCase *case1 = new MockTestCase( "test1" );
|
||||
case1->setExpectedRunTestCall();
|
||||
m_suite->addTest( case1 );
|
||||
|
||||
CPPUNIT_NS::TestResult result;
|
||||
m_suite->run( &result );
|
||||
|
||||
case1->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSuiteTest::testRunWithOneTestAndSubSuite()
|
||||
{
|
||||
MockTestCase *case1 = new MockTestCase( "test1" );
|
||||
case1->setExpectedRunTestCall();
|
||||
MockTestCase *case2 = new MockTestCase( "test2" );
|
||||
case2->setExpectedRunTestCall();
|
||||
MockTestCase *case3 = new MockTestCase( "test3" );
|
||||
case3->setExpectedRunTestCall();
|
||||
CPPUNIT_NS::TestSuite *subSuite = new CPPUNIT_NS::TestSuite( "SubSuite");
|
||||
subSuite->addTest( case1 );
|
||||
subSuite->addTest( case2 );
|
||||
m_suite->addTest( case3 );
|
||||
m_suite->addTest( subSuite);
|
||||
|
||||
CPPUNIT_NS::TestResult result;
|
||||
m_suite->run( &result );
|
||||
|
||||
case1->verify();
|
||||
case2->verify();
|
||||
case3->verify();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSuiteTest::testGetTests()
|
||||
{
|
||||
m_suite->addTest( new CPPUNIT_NS::TestCase( "test1" ) );
|
||||
m_suite->addTest( new CPPUNIT_NS::TestCase( "test2" ) );
|
||||
CPPUNIT_ASSERT_EQUAL( 2, int(m_suite->getTests().size()) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSuiteTest::testDeleteContents()
|
||||
{
|
||||
m_suite->addTest( new CPPUNIT_NS::TestCase( "test2" ) );
|
||||
m_suite->deleteContents();
|
||||
CPPUNIT_ASSERT_EQUAL( 0, int(m_suite->getTests().size()) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSuiteTest::testGetChildTestCount()
|
||||
{
|
||||
m_suite->addTest( new CPPUNIT_NS::TestCase( "test1" ) );
|
||||
m_suite->addTest( new CPPUNIT_NS::TestCase( "test2" ) );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 2, m_suite->getChildTestCount() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSuiteTest::testGetChildTestAt()
|
||||
{
|
||||
CPPUNIT_NS::TestCase *test1 = new CPPUNIT_NS::TestCase( "test1" );
|
||||
CPPUNIT_NS::TestCase *test2 = new CPPUNIT_NS::TestCase( "test2" );
|
||||
m_suite->addTest( test1 );
|
||||
m_suite->addTest( test2 );
|
||||
|
||||
CPPUNIT_ASSERT( test1 == m_suite->getChildTestAt(0) );
|
||||
CPPUNIT_ASSERT( test2 == m_suite->getChildTestAt(1) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSuiteTest::testGetChildTestAtThrow1()
|
||||
{
|
||||
m_suite->getChildTestAt(-1);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestSuiteTest::testGetChildTestAtThrow2()
|
||||
{
|
||||
m_suite->getChildTestAt(0);
|
||||
}
|
60
examples/cppunittest/TestSuiteTest.h
Normal file
60
examples/cppunittest/TestSuiteTest.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#ifndef TESTSUITETEST_H
|
||||
#define TESTSUITETEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
class TestSuiteTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( TestSuiteTest );
|
||||
CPPUNIT_TEST( testConstructor );
|
||||
CPPUNIT_TEST( testCountTestCasesWithNoTest );
|
||||
CPPUNIT_TEST( testCountTestCasesWithTwoTests );
|
||||
CPPUNIT_TEST( testCountTestCasesWithSubSuite );
|
||||
CPPUNIT_TEST( testRunWithOneTest );
|
||||
CPPUNIT_TEST( testRunWithOneTestAndSubSuite );
|
||||
CPPUNIT_TEST( testGetTests );
|
||||
CPPUNIT_TEST( testDeleteContents );
|
||||
CPPUNIT_TEST( testGetChildTestCount );
|
||||
CPPUNIT_TEST( testGetChildTestAt );
|
||||
CPPUNIT_TEST_EXCEPTION( testGetChildTestAtThrow1, std::out_of_range );
|
||||
CPPUNIT_TEST_EXCEPTION( testGetChildTestAtThrow2, std::out_of_range );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
TestSuiteTest();
|
||||
virtual ~TestSuiteTest();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
void testConstructor();
|
||||
|
||||
void testCountTestCasesWithNoTest();
|
||||
void testCountTestCasesWithTwoTests();
|
||||
void testCountTestCasesWithSubSuite();
|
||||
|
||||
void testRunWithOneTest();
|
||||
void testRunWithOneTestAndSubSuite();
|
||||
|
||||
void testGetTests();
|
||||
|
||||
void testDeleteContents();
|
||||
|
||||
void testGetChildTestCount();
|
||||
void testGetChildTestAt();
|
||||
void testGetChildTestAtThrow1();
|
||||
void testGetChildTestAtThrow2();
|
||||
|
||||
private:
|
||||
TestSuiteTest( const TestSuiteTest © );
|
||||
void operator =( const TestSuiteTest © );
|
||||
|
||||
private:
|
||||
CPPUNIT_NS::TestSuite *m_suite;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // TESTSUITETEST_H
|
133
examples/cppunittest/TestTest.cpp
Normal file
133
examples/cppunittest/TestTest.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
#include "CoreSuite.h"
|
||||
#include "TestTest.h"
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestTest,
|
||||
coreSuiteName() );
|
||||
|
||||
|
||||
TestTest::TestTest() :
|
||||
CPPUNIT_NS::TestFixture()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TestTest::~TestTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestTest::setUp()
|
||||
{
|
||||
m_suite = new CPPUNIT_NS::TestSuite( "suite" );
|
||||
m_test1 = new MockTestCase( "test1" );
|
||||
m_test2 = new MockTestCase( "test2" );
|
||||
m_suite->addTest( m_test1 );
|
||||
m_suite->addTest( m_test2 );
|
||||
|
||||
m_path = new CPPUNIT_NS::TestPath();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestTest::tearDown()
|
||||
{
|
||||
delete m_suite;
|
||||
delete m_path;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestTest::testFindTestPathPointerThis()
|
||||
{
|
||||
CPPUNIT_ASSERT( m_test1->findTestPath( m_test1, *m_path ) );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, m_path->getTestCount() );
|
||||
CPPUNIT_ASSERT( m_test1 == m_path->getChildTest() );
|
||||
|
||||
m_path->removeTests();
|
||||
|
||||
CPPUNIT_ASSERT( m_suite->findTestPath( m_suite, *m_path ) );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, m_path->getTestCount() );
|
||||
CPPUNIT_ASSERT( m_suite == m_path->getChildTest() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestTest::testFindTestPathPointer()
|
||||
{
|
||||
CPPUNIT_ASSERT( m_suite->findTestPath( m_test1, *m_path ) );
|
||||
CPPUNIT_ASSERT_EQUAL( 2, m_path->getTestCount() );
|
||||
CPPUNIT_ASSERT( m_suite == m_path->getTestAt(0) );
|
||||
CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(1) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestTest::testFindTestPathPointerFail()
|
||||
{
|
||||
MockTestCase test( "test" );
|
||||
CPPUNIT_ASSERT( !m_suite->findTestPath( &test, *m_path ) );
|
||||
CPPUNIT_ASSERT( !m_path->isValid() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestTest::testFindTestPathNameThis()
|
||||
{
|
||||
CPPUNIT_ASSERT( m_test1->findTestPath( "test1", *m_path ) );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, m_path->getTestCount() );
|
||||
CPPUNIT_ASSERT( m_test1 == m_path->getChildTest() );
|
||||
|
||||
m_path->removeTests();
|
||||
|
||||
CPPUNIT_ASSERT( m_suite->findTestPath( "suite", *m_path ) );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, m_path->getTestCount() );
|
||||
CPPUNIT_ASSERT( m_suite == m_path->getChildTest() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestTest::testFindTestPathName()
|
||||
{
|
||||
CPPUNIT_ASSERT( m_suite->findTestPath( "test2", *m_path ) );
|
||||
CPPUNIT_ASSERT_EQUAL( 2, m_path->getTestCount() );
|
||||
CPPUNIT_ASSERT( m_suite == m_path->getTestAt(0) );
|
||||
CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(1) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestTest::testFindTestPathNameFail()
|
||||
{
|
||||
CPPUNIT_ASSERT( !m_suite->findTestPath( "bad-test", *m_path ) );
|
||||
CPPUNIT_ASSERT( !m_path->isValid() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestTest::testFindTest()
|
||||
{
|
||||
CPPUNIT_ASSERT( m_test1 == m_suite->findTest( "test1" ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestTest::testFindTestThrow()
|
||||
{
|
||||
m_suite->findTest( "no-name" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestTest::testResolveTestPath()
|
||||
{
|
||||
CPPUNIT_NS::TestPath path1 = m_suite->resolveTestPath( "suite");
|
||||
CPPUNIT_ASSERT_EQUAL( 1, path1.getTestCount() );
|
||||
CPPUNIT_ASSERT( m_suite == path1.getTestAt(0) );
|
||||
|
||||
CPPUNIT_NS::TestPath path2 = m_suite->resolveTestPath( "suite/test2");
|
||||
CPPUNIT_ASSERT_EQUAL( 2, path2.getTestCount() );
|
||||
CPPUNIT_ASSERT( m_suite == path2.getTestAt(0) );
|
||||
CPPUNIT_ASSERT( m_test2 == path2.getTestAt(1) );
|
||||
}
|
67
examples/cppunittest/TestTest.h
Normal file
67
examples/cppunittest/TestTest.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#ifndef TESTTEST_H
|
||||
#define TESTTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/TestSuite.h>
|
||||
#include <cppunit/TestPath.h>
|
||||
#include "MockTestCase.h"
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
/*! \class TestTest
|
||||
* \brief Unit test for class Test.
|
||||
*/
|
||||
class TestTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( TestTest );
|
||||
CPPUNIT_TEST( testFindTestPathPointerThis );
|
||||
CPPUNIT_TEST( testFindTestPathPointer );
|
||||
CPPUNIT_TEST( testFindTestPathPointerFail );
|
||||
CPPUNIT_TEST( testFindTestPathNameThis );
|
||||
CPPUNIT_TEST( testFindTestPathName );
|
||||
CPPUNIT_TEST( testFindTestPathNameFail );
|
||||
CPPUNIT_TEST( testFindTest );
|
||||
CPPUNIT_TEST_EXCEPTION( testFindTestThrow, std::invalid_argument );
|
||||
CPPUNIT_TEST( testResolveTestPath );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
/*! Constructs a TestTest object.
|
||||
*/
|
||||
TestTest();
|
||||
|
||||
/// Destructor.
|
||||
virtual ~TestTest();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
void testFindTestPathPointerThis();
|
||||
void testFindTestPathPointer();
|
||||
void testFindTestPathPointerFail();
|
||||
|
||||
void testFindTestPathNameThis();
|
||||
void testFindTestPathName();
|
||||
void testFindTestPathNameFail();
|
||||
|
||||
void testFindTest();
|
||||
void testFindTestThrow();
|
||||
|
||||
void testResolveTestPath();
|
||||
|
||||
private:
|
||||
/// Prevents the use of the copy constructor.
|
||||
TestTest( const TestTest © );
|
||||
|
||||
/// Prevents the use of the copy operator.
|
||||
void operator =( const TestTest © );
|
||||
|
||||
private:
|
||||
CPPUNIT_NS::TestSuite *m_suite;
|
||||
MockTestCase *m_test1;
|
||||
MockTestCase *m_test2;
|
||||
CPPUNIT_NS::TestPath *m_path;
|
||||
};
|
||||
|
||||
|
||||
#endif // TESTTEST_H
|
12
examples/cppunittest/ToolsSuite.h
Normal file
12
examples/cppunittest/ToolsSuite.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef CPPUNITTEST_TOOLSSUITE_H
|
||||
#define CPPUNITTEST_TOOLSSUITE_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <string>
|
||||
|
||||
inline std::string toolsSuiteName()
|
||||
{
|
||||
return "Tools";
|
||||
}
|
||||
|
||||
#endif // CPPUNITTEST_TOOLSSUITE_H
|
55
examples/cppunittest/TrackedTestCase.cpp
Normal file
55
examples/cppunittest/TrackedTestCase.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "TrackedTestCase.h"
|
||||
|
||||
Tracker *TrackedTestCase::ms_tracker = NULL;
|
||||
|
||||
TrackedTestCase::TrackedTestCase()
|
||||
: CPPUNIT_NS::TestCase( "" )
|
||||
{
|
||||
if ( ms_tracker != NULL )
|
||||
ms_tracker->onConstructor();
|
||||
}
|
||||
|
||||
|
||||
TrackedTestCase::~TrackedTestCase()
|
||||
{
|
||||
if ( ms_tracker != NULL )
|
||||
ms_tracker->onDestructor();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TrackedTestCase::setUp()
|
||||
{
|
||||
if ( ms_tracker != NULL )
|
||||
ms_tracker->onSetUp();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TrackedTestCase::tearDown()
|
||||
{
|
||||
if ( ms_tracker != NULL )
|
||||
ms_tracker->onTearDown();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TrackedTestCase::test()
|
||||
{
|
||||
if ( ms_tracker != NULL )
|
||||
ms_tracker->onTest();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TrackedTestCase::setTracker( Tracker *tracker )
|
||||
{
|
||||
ms_tracker = tracker;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TrackedTestCase::removeTracker()
|
||||
{
|
||||
ms_tracker = NULL;
|
||||
}
|
45
examples/cppunittest/TrackedTestCase.h
Normal file
45
examples/cppunittest/TrackedTestCase.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef TRACKEDTESTCASE_H
|
||||
#define TRACKEDTESTCASE_H
|
||||
|
||||
#include <cppunit/TestCase.h>
|
||||
|
||||
|
||||
class Tracker
|
||||
{
|
||||
public:
|
||||
virtual ~Tracker() {}
|
||||
|
||||
virtual void onConstructor() {}
|
||||
virtual void onDestructor() {}
|
||||
virtual void onSetUp() {}
|
||||
virtual void onTearDown() {}
|
||||
virtual void onTest() {};
|
||||
};
|
||||
|
||||
|
||||
class TrackedTestCase : public CPPUNIT_NS::TestCase
|
||||
{
|
||||
public:
|
||||
TrackedTestCase();
|
||||
|
||||
virtual ~TrackedTestCase();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
void test();
|
||||
|
||||
static void setTracker( Tracker *tracker );
|
||||
static void removeTracker();
|
||||
|
||||
private:
|
||||
TrackedTestCase( const TrackedTestCase © );
|
||||
|
||||
void operator =( const TrackedTestCase © );
|
||||
|
||||
private:
|
||||
static Tracker *ms_tracker;
|
||||
};
|
||||
|
||||
|
||||
#endif // TRACKEDTESTCASE_H
|
12
examples/cppunittest/UnitTestToolSuite.h
Normal file
12
examples/cppunittest/UnitTestToolSuite.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef CPPUNITTEST_UNITTESTTOOLSUITE_H
|
||||
#define CPPUNITTEST_UNITTESTTOOLSUITE_H
|
||||
|
||||
#include <cppunit/Portability.h>
|
||||
#include <string>
|
||||
|
||||
inline std::string unitTestToolSuiteName()
|
||||
{
|
||||
return "UnitTestTool";
|
||||
}
|
||||
|
||||
#endif // CPPUNITTEST_UNITTESTTOOLSUITE_H
|
226
examples/cppunittest/XmlElementTest.cpp
Normal file
226
examples/cppunittest/XmlElementTest.cpp
Normal file
@@ -0,0 +1,226 @@
|
||||
#include <cppunit/config/SourcePrefix.h>
|
||||
#include <cppunit/tools/XmlElement.h>
|
||||
#include "ToolsSuite.h"
|
||||
#include "XmlElementTest.h"
|
||||
#include "XmlUniformiser.h"
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( XmlElementTest,
|
||||
toolsSuiteName() );
|
||||
|
||||
|
||||
XmlElementTest::XmlElementTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
XmlElementTest::~XmlElementTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testStringContentConstructor()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement element( "aName", "someContent" );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("aName"), element.name() );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("someContent"), element.content() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testNumericContentConstructor()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement element( "numericName", 123456789 );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("numericName"), element.name() );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("123456789"), element.content() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testSetName()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement element( "aName" );
|
||||
element.setName( "anotherName" );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("anotherName"), element.name() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testSetStringContent()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement element( "aName", "someContent" );
|
||||
element.setContent( "other" );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("other"), element.content() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testSetNumericContent()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement element( "aName", "someContent" );
|
||||
element.setContent( 87654321 );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("87654321"), element.content() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testElementCount()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement node( "element", "content" );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, node.elementCount() );
|
||||
|
||||
node.addElement( new CPPUNIT_NS::XmlElement( "child1" ) );
|
||||
node.addElement( new CPPUNIT_NS::XmlElement( "child2" ) );
|
||||
CPPUNIT_ASSERT_EQUAL( 2, node.elementCount() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testElementAtNegativeIndexThrow()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement node( "element" );
|
||||
node.elementAt( -1 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testElementAtTooLargeIndexThrow()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement node( "element" );
|
||||
node.elementAt( 0 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testElementAt()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement node( "element" );
|
||||
CPPUNIT_NS::XmlElement *element1 = new CPPUNIT_NS::XmlElement( "element1" );
|
||||
CPPUNIT_NS::XmlElement *element2 = new CPPUNIT_NS::XmlElement( "element2" );
|
||||
node.addElement( element1 );
|
||||
node.addElement( element2 );
|
||||
|
||||
CPPUNIT_ASSERT( element1 == node.elementAt(0) );
|
||||
CPPUNIT_ASSERT( element2 == node.elementAt(1) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testElementForThrow()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement node( "element" );
|
||||
node.addElement( new CPPUNIT_NS::XmlElement( "element1" ) );
|
||||
node.elementFor( "name2" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testElementFor()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement node( "element" );
|
||||
CPPUNIT_NS::XmlElement *element1 = new CPPUNIT_NS::XmlElement( "element1" );
|
||||
CPPUNIT_NS::XmlElement *element2 = new CPPUNIT_NS::XmlElement( "element2" );
|
||||
node.addElement( element1 );
|
||||
node.addElement( element2 );
|
||||
|
||||
CPPUNIT_ASSERT( element2 == node.elementFor( "element2" ) );
|
||||
CPPUNIT_ASSERT( element1 == node.elementFor( "element1" ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testEmptyNodeToString()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement node( "element" );
|
||||
std::string expectedXml = "<element></element>";
|
||||
CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testElementWithAttributesToString()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement node( "element" );
|
||||
node.addAttribute( "id", 17 );
|
||||
node.addAttribute( "date-format", "iso-8901" );
|
||||
std::string expectedXml = "<element id=\"17\" "
|
||||
"date-format=\"iso-8901\">"
|
||||
"</element>";
|
||||
CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testEscapedAttributeValueToString()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement node( "element" );
|
||||
node.addAttribute( "escaped", "&<>\"'" );
|
||||
std::string expectedXml = "<element escaped=\""
|
||||
"&<>"'"
|
||||
"\"></element>";
|
||||
CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testElementToStringEscapeContent()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement node( "element", "ChessTest<class Chess>" );
|
||||
std::string expectedXml = "<element>"
|
||||
"ChessTest<class Chess>"
|
||||
"</element>";
|
||||
CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testElementWithChildrenToString()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement node( "element" );
|
||||
node.addElement( new CPPUNIT_NS::XmlElement( "child1" ) );
|
||||
node.addElement( new CPPUNIT_NS::XmlElement( "child2" ) );
|
||||
std::string expectedXml = "<element><child1></child1>"
|
||||
"<child2></child2></element>";
|
||||
CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testElementWithContentToString()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement node( "element", "content\nline2" );
|
||||
std::string expectedXml = "<element>content\nline2</element>";
|
||||
CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testElementWithNumericContentToString()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement node( "element", 123456789 );
|
||||
std::string expectedXml = "<element>123456789</element>";
|
||||
CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlElementTest::testElementWithContentAndChildToString()
|
||||
{
|
||||
CPPUNIT_NS::XmlElement node( "element", "content" );
|
||||
node.addElement( new CPPUNIT_NS::XmlElement( "child1" ) );
|
||||
std::string expectedXml = "<element><child1></child1>content</element>";
|
||||
CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, node.toString() );
|
||||
}
|
77
examples/cppunittest/XmlElementTest.h
Normal file
77
examples/cppunittest/XmlElementTest.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef CPPUNITEST_XMLELEMENTTEST_H
|
||||
#define CPPUNITEST_XMLELEMENTTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
/*! Unit tests for XmlElement.
|
||||
*/
|
||||
class XmlElementTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( XmlElementTest );
|
||||
CPPUNIT_TEST( testStringContentConstructor );
|
||||
CPPUNIT_TEST( testNumericContentConstructor );
|
||||
CPPUNIT_TEST( testSetName );
|
||||
CPPUNIT_TEST( testSetStringContent );
|
||||
CPPUNIT_TEST( testSetNumericContent );
|
||||
CPPUNIT_TEST( testElementCount );
|
||||
CPPUNIT_TEST_EXCEPTION( testElementAtNegativeIndexThrow, std::invalid_argument );
|
||||
CPPUNIT_TEST_EXCEPTION( testElementAtTooLargeIndexThrow, std::invalid_argument );
|
||||
CPPUNIT_TEST( testElementAt );
|
||||
CPPUNIT_TEST_EXCEPTION( testElementForThrow, std::invalid_argument );
|
||||
CPPUNIT_TEST( testElementFor );
|
||||
|
||||
CPPUNIT_TEST( testEmptyNodeToString );
|
||||
CPPUNIT_TEST( testElementWithAttributesToString );
|
||||
CPPUNIT_TEST( testEscapedAttributeValueToString );
|
||||
CPPUNIT_TEST( testElementToStringEscapeContent );
|
||||
CPPUNIT_TEST( testElementWithChildrenToString );
|
||||
CPPUNIT_TEST( testElementWithContentToString );
|
||||
CPPUNIT_TEST( testElementWithNumericContentToString );
|
||||
CPPUNIT_TEST( testElementWithContentAndChildToString );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
/*! Constructs a XmlElementTest object.
|
||||
*/
|
||||
XmlElementTest();
|
||||
|
||||
/// Destructor.
|
||||
virtual ~XmlElementTest();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
void testStringContentConstructor();
|
||||
void testNumericContentConstructor();
|
||||
void testSetName();
|
||||
void testSetStringContent();
|
||||
void testSetNumericContent();
|
||||
void testElementCount();
|
||||
void testElementAtNegativeIndexThrow();
|
||||
void testElementAtTooLargeIndexThrow();
|
||||
void testElementAt();
|
||||
void testElementForThrow();
|
||||
void testElementFor();
|
||||
|
||||
void testEmptyNodeToString();
|
||||
void testElementWithAttributesToString();
|
||||
void testEscapedAttributeValueToString();
|
||||
void testElementToStringEscapeContent();
|
||||
void testElementWithChildrenToString();
|
||||
void testElementWithContentToString();
|
||||
void testElementWithNumericContentToString();
|
||||
void testElementWithContentAndChildToString();
|
||||
|
||||
private:
|
||||
/// Prevents the use of the copy constructor.
|
||||
XmlElementTest( const XmlElementTest © );
|
||||
|
||||
/// Prevents the use of the copy operator.
|
||||
void operator =( const XmlElementTest © );
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // CPPUNITEST_XMLELEMENTTEST_H
|
356
examples/cppunittest/XmlOutputterTest.cpp
Normal file
356
examples/cppunittest/XmlOutputterTest.cpp
Normal file
@@ -0,0 +1,356 @@
|
||||
#include <cppunit/config/SourcePrefix.h>
|
||||
#include <cppunit/XmlOutputter.h>
|
||||
#include <cppunit/TestFailure.h>
|
||||
#include <cppunit/XmlOutputter.h>
|
||||
#include <cppunit/XmlOutputterHook.h>
|
||||
#include "OutputSuite.h"
|
||||
#include "XmlOutputterTest.h"
|
||||
#include "XmlUniformiser.h"
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( XmlOutputterTest,
|
||||
outputSuiteName() );
|
||||
|
||||
|
||||
XmlOutputterTest::XmlOutputterTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
XmlOutputterTest::~XmlOutputterTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlOutputterTest::setUp()
|
||||
{
|
||||
m_dummyTests.clear();
|
||||
m_result = new CPPUNIT_NS::TestResultCollector();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlOutputterTest::tearDown()
|
||||
{
|
||||
delete m_result;
|
||||
for ( unsigned int index =0; index < m_dummyTests.size(); ++index )
|
||||
delete m_dummyTests[index];
|
||||
m_dummyTests.clear();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlOutputterTest::testWriteXmlResultWithNoTest()
|
||||
{
|
||||
CPPUNIT_NS::OStringStream stream;
|
||||
CPPUNIT_NS::XmlOutputter outputter( m_result, stream );
|
||||
outputter.write();
|
||||
|
||||
std::string actualXml = stream.str();
|
||||
std::string expectedXml =
|
||||
"<TestRun>"
|
||||
"<FailedTests></FailedTests>"
|
||||
"<SuccessfulTests></SuccessfulTests>"
|
||||
"<Statistics>"
|
||||
"<Tests>0</Tests>"
|
||||
"<FailuresTotal>0</FailuresTotal>"
|
||||
"<Errors>0</Errors>"
|
||||
"<Failures>0</Failures>"
|
||||
"</Statistics>"
|
||||
"</TestRun>";
|
||||
CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, actualXml );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlOutputterTest::testWriteXmlResultWithOneFailure()
|
||||
{
|
||||
addTestFailure( "test1", "message failure1", CPPUNIT_NS::SourceLine( "test.cpp", 3 ) );
|
||||
|
||||
CPPUNIT_NS::OStringStream stream;
|
||||
CPPUNIT_NS::XmlOutputter outputter( m_result, stream );
|
||||
outputter.write();
|
||||
|
||||
std::string actualXml = stream.str();
|
||||
std::string expectedXml =
|
||||
"<TestRun>"
|
||||
"<FailedTests>"
|
||||
"<FailedTest id=\"1\">"
|
||||
"<Name>test1</Name>"
|
||||
"<FailureType>Assertion</FailureType>"
|
||||
"<Location>"
|
||||
"<File>test.cpp</File>"
|
||||
"<Line>3</Line>"
|
||||
"</Location>"
|
||||
"<Message>message failure1</Message>"
|
||||
"</FailedTest>"
|
||||
"</FailedTests>"
|
||||
"<SuccessfulTests></SuccessfulTests>"
|
||||
"<Statistics>"
|
||||
"<Tests>1</Tests>"
|
||||
"<FailuresTotal>1</FailuresTotal>"
|
||||
"<Errors>0</Errors>"
|
||||
"<Failures>1</Failures>"
|
||||
"</Statistics>"
|
||||
"</TestRun>";
|
||||
CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, actualXml );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlOutputterTest::testWriteXmlResultWithOneError()
|
||||
{
|
||||
addTestError( "test1", "message error1" );
|
||||
|
||||
CPPUNIT_NS::OStringStream stream;
|
||||
CPPUNIT_NS::XmlOutputter outputter( m_result, stream );
|
||||
outputter.write();
|
||||
|
||||
std::string actualXml = stream.str();
|
||||
std::string expectedXml =
|
||||
"<TestRun>"
|
||||
"<FailedTests>"
|
||||
"<FailedTest id=\"1\">"
|
||||
"<Name>test1</Name>"
|
||||
"<FailureType>Error</FailureType>"
|
||||
"<Message>message error1</Message>"
|
||||
"</FailedTest>"
|
||||
"</FailedTests>"
|
||||
"<SuccessfulTests></SuccessfulTests>"
|
||||
"<Statistics>"
|
||||
"<Tests>1</Tests>"
|
||||
"<FailuresTotal>1</FailuresTotal>"
|
||||
"<Errors>1</Errors>"
|
||||
"<Failures>0</Failures>"
|
||||
"</Statistics>"
|
||||
"</TestRun>";
|
||||
CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, actualXml );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlOutputterTest::testWriteXmlResultWithOneSuccess()
|
||||
{
|
||||
addTest( "test1" );
|
||||
|
||||
CPPUNIT_NS::OStringStream stream;
|
||||
CPPUNIT_NS::XmlOutputter outputter( m_result, stream );
|
||||
outputter.write();
|
||||
|
||||
std::string actualXml = stream.str();
|
||||
std::string expectedXml =
|
||||
"<TestRun>"
|
||||
"<FailedTests></FailedTests>"
|
||||
"<SuccessfulTests>"
|
||||
"<Test id=\"1\">"
|
||||
"<Name>test1</Name>"
|
||||
"</Test>"
|
||||
"</SuccessfulTests>"
|
||||
"<Statistics>"
|
||||
"<Tests>1</Tests>"
|
||||
"<FailuresTotal>0</FailuresTotal>"
|
||||
"<Errors>0</Errors>"
|
||||
"<Failures>0</Failures>"
|
||||
"</Statistics>"
|
||||
"</TestRun>";
|
||||
CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, actualXml );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlOutputterTest::testWriteXmlResultWithThreeFailureTwoErrorsAndTwoSuccess()
|
||||
{
|
||||
addTestFailure( "test1", "failure1" );
|
||||
addTestError( "test2", "error1" );
|
||||
addTestFailure( "test3", "failure2" );
|
||||
addTestFailure( "test4", "failure3" );
|
||||
addTest( "test5" );
|
||||
addTestError( "test6", "error2" );
|
||||
addTest( "test7" );
|
||||
|
||||
CPPUNIT_NS::OStringStream stream;
|
||||
CPPUNIT_NS::XmlOutputter outputter( m_result, stream );
|
||||
outputter.write();
|
||||
|
||||
std::string actualXml = stream.str();
|
||||
std::string expectedXml =
|
||||
"<TestRun>"
|
||||
"<FailedTests>"
|
||||
"<FailedTest id=\"1\">"
|
||||
"<Name>test1</Name>"
|
||||
"<FailureType>Assertion</FailureType>"
|
||||
"<Message>failure1</Message>"
|
||||
"</FailedTest>"
|
||||
"<FailedTest id=\"2\">"
|
||||
"<Name>test2</Name>"
|
||||
"<FailureType>Error</FailureType>"
|
||||
"<Message>error1</Message>"
|
||||
"</FailedTest>"
|
||||
"<FailedTest id=\"3\">"
|
||||
"<Name>test3</Name>"
|
||||
"<FailureType>Assertion</FailureType>"
|
||||
"<Message>failure2</Message>"
|
||||
"</FailedTest>"
|
||||
"<FailedTest id=\"4\">"
|
||||
"<Name>test4</Name>"
|
||||
"<FailureType>Assertion</FailureType>"
|
||||
"<Message>failure3</Message>"
|
||||
"</FailedTest>"
|
||||
"<FailedTest id=\"6\">"
|
||||
"<Name>test6</Name>"
|
||||
"<FailureType>Error</FailureType>"
|
||||
"<Message>error2</Message>"
|
||||
"</FailedTest>"
|
||||
"</FailedTests>"
|
||||
"<SuccessfulTests>"
|
||||
"<Test id=\"5\">"
|
||||
"<Name>test5</Name>"
|
||||
"</Test>"
|
||||
"<Test id=\"7\">"
|
||||
"<Name>test7</Name>"
|
||||
"</Test>"
|
||||
"</SuccessfulTests>"
|
||||
"<Statistics>"
|
||||
"<Tests>7</Tests>"
|
||||
"<FailuresTotal>5</FailuresTotal>"
|
||||
"<Errors>2</Errors>"
|
||||
"<Failures>3</Failures>"
|
||||
"</Statistics>"
|
||||
"</TestRun>";
|
||||
CPPUNITTEST_ASSERT_XML_EQUAL( expectedXml, actualXml );
|
||||
}
|
||||
|
||||
|
||||
class XmlOutputterTest::MockHook : public CPPUNIT_NS::XmlOutputterHook
|
||||
{
|
||||
public:
|
||||
MockHook( int &beginCalls,
|
||||
int &endCalls,
|
||||
int &statisticsCalls,
|
||||
int &successfulTestCalls,
|
||||
int &failedTestCalls )
|
||||
: m_beginCalls( beginCalls )
|
||||
, m_endCalls( endCalls )
|
||||
, m_statisticsCalls( statisticsCalls )
|
||||
, m_successfulTestCalls( successfulTestCalls )
|
||||
, m_failedTestCalls( failedTestCalls )
|
||||
{
|
||||
}
|
||||
|
||||
void beginDocument( CPPUNIT_NS::XmlDocument *document )
|
||||
{
|
||||
++m_beginCalls;
|
||||
}
|
||||
|
||||
void endDocument( CPPUNIT_NS::XmlDocument *document )
|
||||
{
|
||||
++m_endCalls;
|
||||
}
|
||||
|
||||
void failTestAdded( CPPUNIT_NS::XmlDocument *document,
|
||||
CPPUNIT_NS::XmlElement *testElement,
|
||||
CPPUNIT_NS::Test *test,
|
||||
CPPUNIT_NS::TestFailure *failure )
|
||||
{
|
||||
++m_failedTestCalls;
|
||||
}
|
||||
|
||||
void successfulTestAdded( CPPUNIT_NS::XmlDocument *document,
|
||||
CPPUNIT_NS::XmlElement *testElement,
|
||||
CPPUNIT_NS::Test *test )
|
||||
{
|
||||
++m_successfulTestCalls;
|
||||
}
|
||||
|
||||
void statisticsAdded( CPPUNIT_NS::XmlDocument *document,
|
||||
CPPUNIT_NS::XmlElement *statisticsElement )
|
||||
{
|
||||
++m_statisticsCalls;
|
||||
}
|
||||
|
||||
private:
|
||||
int &m_beginCalls;
|
||||
int &m_endCalls;
|
||||
int &m_statisticsCalls;
|
||||
int &m_successfulTestCalls;
|
||||
int &m_failedTestCalls;
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
XmlOutputterTest::testHook()
|
||||
{
|
||||
int begin =0, end =0, statistics =0, successful =0, failed =0;
|
||||
MockHook hook( begin, end, statistics, successful, failed );
|
||||
|
||||
addTest( "test1" );
|
||||
addTest( "test2" );
|
||||
addTest( "test3" );
|
||||
addTestFailure( "testfail1", "assertion failed" );
|
||||
addTestError( "testerror1", "exception" );
|
||||
|
||||
CPPUNIT_NS::OStringStream stream;
|
||||
CPPUNIT_NS::XmlOutputter outputter( m_result, stream );
|
||||
outputter.addHook( &hook );
|
||||
outputter.write();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( 1, begin );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, end );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, statistics );
|
||||
CPPUNIT_ASSERT_EQUAL( 3, successful );
|
||||
CPPUNIT_ASSERT_EQUAL( 2, failed );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlOutputterTest::addTest( std::string testName )
|
||||
{
|
||||
CPPUNIT_NS::Test *test = makeDummyTest( testName );
|
||||
m_result->startTest( test );
|
||||
m_result->endTest( test );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlOutputterTest::addTestFailure( std::string testName,
|
||||
std::string message,
|
||||
CPPUNIT_NS::SourceLine sourceLine )
|
||||
{
|
||||
addGenericTestFailure( testName, CPPUNIT_NS::Message(message), sourceLine, false );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlOutputterTest::addTestError( std::string testName,
|
||||
std::string message,
|
||||
CPPUNIT_NS::SourceLine sourceLine )
|
||||
{
|
||||
addGenericTestFailure( testName, CPPUNIT_NS::Message(message), sourceLine, true );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlOutputterTest::addGenericTestFailure( std::string testName,
|
||||
CPPUNIT_NS::Message message,
|
||||
CPPUNIT_NS::SourceLine sourceLine,
|
||||
bool isError )
|
||||
{
|
||||
CPPUNIT_NS::Test *test = makeDummyTest( testName );
|
||||
m_result->startTest( test );
|
||||
CPPUNIT_NS::TestFailure failure( test,
|
||||
new CPPUNIT_NS::Exception( message, sourceLine ),
|
||||
isError );
|
||||
m_result->addFailure( failure );
|
||||
m_result->endTest( test );
|
||||
}
|
||||
|
||||
|
||||
CPPUNIT_NS::Test *
|
||||
XmlOutputterTest::makeDummyTest( std::string testName )
|
||||
{
|
||||
CPPUNIT_NS::Test *test = new CPPUNIT_NS::TestCase( testName );
|
||||
m_dummyTests.push_back( test );
|
||||
return test;
|
||||
}
|
||||
|
78
examples/cppunittest/XmlOutputterTest.h
Normal file
78
examples/cppunittest/XmlOutputterTest.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#ifndef CPPUNITEST_XMLTESTRESULTOUTPUTTERTEST_H
|
||||
#define CPPUNITEST_XMLTESTRESULTOUTPUTTERTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/portability/CppUnitDeque.h>
|
||||
#include <cppunit/Test.h>
|
||||
#include <cppunit/TestFailure.h>
|
||||
#include <cppunit/TestResultCollector.h>
|
||||
|
||||
|
||||
/*! \class XmlOutputterTest
|
||||
* \brief Unit tests for XmlOutputter.
|
||||
*/
|
||||
class XmlOutputterTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( XmlOutputterTest );
|
||||
CPPUNIT_TEST( testWriteXmlResultWithNoTest );
|
||||
CPPUNIT_TEST( testWriteXmlResultWithOneFailure );
|
||||
CPPUNIT_TEST( testWriteXmlResultWithOneError );
|
||||
CPPUNIT_TEST( testWriteXmlResultWithOneSuccess );
|
||||
CPPUNIT_TEST( testWriteXmlResultWithThreeFailureTwoErrorsAndTwoSuccess );
|
||||
CPPUNIT_TEST( testHook );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
/*! Constructs a XmlOutputterTest object.
|
||||
*/
|
||||
XmlOutputterTest();
|
||||
|
||||
/// Destructor.
|
||||
virtual ~XmlOutputterTest();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
void testWriteXmlResultWithNoTest();
|
||||
void testWriteXmlResultWithOneFailure();
|
||||
void testWriteXmlResultWithOneError();
|
||||
void testWriteXmlResultWithOneSuccess();
|
||||
void testWriteXmlResultWithThreeFailureTwoErrorsAndTwoSuccess();
|
||||
|
||||
void testHook();
|
||||
|
||||
private:
|
||||
class MockHook;
|
||||
|
||||
/// Prevents the use of the copy constructor.
|
||||
XmlOutputterTest( const XmlOutputterTest © );
|
||||
|
||||
/// Prevents the use of the copy operator.
|
||||
void operator =( const XmlOutputterTest © );
|
||||
|
||||
std::string statistics( int tests,
|
||||
int total,
|
||||
int error,
|
||||
int failure );
|
||||
|
||||
void addTest( std::string testName );
|
||||
void addTestFailure( std::string testName,
|
||||
std::string message,
|
||||
CPPUNIT_NS::SourceLine sourceLine = CPPUNIT_NS::SourceLine() );
|
||||
void addTestError( std::string testName,
|
||||
std::string message,
|
||||
CPPUNIT_NS::SourceLine sourceLine = CPPUNIT_NS::SourceLine() );
|
||||
void addGenericTestFailure( std::string testName,
|
||||
CPPUNIT_NS::Message message,
|
||||
CPPUNIT_NS::SourceLine sourceLine,
|
||||
bool isError );
|
||||
|
||||
CPPUNIT_NS::Test *makeDummyTest( std::string testName );
|
||||
|
||||
private:
|
||||
CPPUNIT_NS::TestResultCollector *m_result;
|
||||
CppUnitDeque<CPPUNIT_NS::Test *> m_dummyTests;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // CPPUNITEST_XMLTESTRESULTOUTPUTTERTEST_H
|
236
examples/cppunittest/XmlUniformiser.cpp
Normal file
236
examples/cppunittest/XmlUniformiser.cpp
Normal file
@@ -0,0 +1,236 @@
|
||||
#include "XmlUniformiser.h"
|
||||
|
||||
|
||||
int
|
||||
notEqualIndex( std::string expectedXml,
|
||||
std::string actualXml )
|
||||
{
|
||||
unsigned int index = 0;
|
||||
while ( index < actualXml.length() &&
|
||||
index < expectedXml.length() &&
|
||||
actualXml[index] == expectedXml[index] )
|
||||
++index;
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
/// Asserts that two XML string are equivalent.
|
||||
void
|
||||
checkXmlEqual( std::string expectedXml,
|
||||
std::string actualXml,
|
||||
CPPUNIT_NS::SourceLine sourceLine )
|
||||
{
|
||||
std::string expected = XmlUniformiser( expectedXml ).stripped();
|
||||
std::string actual = XmlUniformiser( actualXml ).stripped();
|
||||
|
||||
if ( expected == actual )
|
||||
return;
|
||||
|
||||
int index = notEqualIndex( expected, actual );
|
||||
CPPUNIT_NS::OStringStream message;
|
||||
message << "differ at index: " << index << "\n"
|
||||
<< "expected: " << expected.substr(index) << "\n"
|
||||
<< "but was : " << actual.substr( index );
|
||||
CPPUNIT_NS::Asserter::failNotEqual( expected,
|
||||
actual,
|
||||
sourceLine,
|
||||
message.str() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
XmlUniformiser::XmlUniformiser( const std::string &xml ) :
|
||||
m_index( 0 ),
|
||||
m_xml( xml )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
XmlUniformiser::stripped()
|
||||
{
|
||||
while ( isValidIndex() )
|
||||
{
|
||||
skipSpaces();
|
||||
if ( startsWith( "<?" ) )
|
||||
skipProcessed();
|
||||
else if ( startsWith( "<!--" ) )
|
||||
skipComment();
|
||||
else if ( startsWith( "<" ) )
|
||||
copyElement();
|
||||
else
|
||||
copyElementContent();
|
||||
}
|
||||
return m_stripped;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiser::skipSpaces()
|
||||
{
|
||||
while ( isSpace() )
|
||||
skipNext();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
XmlUniformiser::isSpace( char c )
|
||||
{
|
||||
return c < 33;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
XmlUniformiser::isSpace()
|
||||
{
|
||||
return isValidIndex() && isSpace( m_xml[m_index] );
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
XmlUniformiser::isValidIndex()
|
||||
{
|
||||
return m_index < m_xml.length();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiser::skipNext( int count )
|
||||
{
|
||||
while ( count-- > 0 )
|
||||
++m_index;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiser::copyNext( int count )
|
||||
{
|
||||
while ( count-- > 0 && isValidIndex() )
|
||||
m_stripped += m_xml[ m_index++ ];
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
XmlUniformiser::startsWith( std::string expected )
|
||||
{
|
||||
std::string actual = m_xml.substr( m_index, expected.length() );
|
||||
return actual == expected;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiser::skipProcessed()
|
||||
{
|
||||
while ( isValidIndex() && !startsWith( "?>" ) )
|
||||
skipNext();
|
||||
if ( isValidIndex() )
|
||||
skipNext( 2 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiser::skipComment()
|
||||
{
|
||||
while ( isValidIndex() && !startsWith( "-->" ) )
|
||||
skipNext();
|
||||
if ( isValidIndex() )
|
||||
skipNext( 3 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiser::copyElement()
|
||||
{
|
||||
copyElementName();
|
||||
copyElementAttributes();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiser::copyElementName()
|
||||
{
|
||||
while ( isValidIndex() &&
|
||||
!( isSpace() || startsWith( ">" ) ) )
|
||||
copyNext();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiser::copyElementAttributes()
|
||||
{
|
||||
do
|
||||
{
|
||||
bool hadSpace = isSpace();
|
||||
skipSpaces();
|
||||
if ( startsWith( ">" ) )
|
||||
break;
|
||||
|
||||
if ( hadSpace )
|
||||
m_stripped += ' ';
|
||||
|
||||
copyAttributeName();
|
||||
skipSpaces();
|
||||
if ( startsWith( "=" ) )
|
||||
{
|
||||
copyNext();
|
||||
copyAttributeValue();
|
||||
}
|
||||
else // attribute should always be valued, ne ?
|
||||
m_stripped += ' ';
|
||||
}
|
||||
while ( isValidIndex() );
|
||||
copyNext();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiser::copyAttributeName()
|
||||
{
|
||||
while ( isValidIndex() && !isEndOfAttributeName() )
|
||||
copyNext();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
XmlUniformiser::isEndOfAttributeName()
|
||||
{
|
||||
return isSpace() || startsWith( ">" ) || startsWith( "=" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiser::copyAttributeValue()
|
||||
{
|
||||
skipSpaces();
|
||||
copyUntilDoubleQuote();
|
||||
copyUntilDoubleQuote();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiser::copyUntilDoubleQuote()
|
||||
{
|
||||
while ( isValidIndex() && !startsWith("\"") )
|
||||
copyNext();
|
||||
copyNext(); // '"'
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiser::copyElementContent()
|
||||
{
|
||||
while ( isValidIndex() && !startsWith( "<" ) )
|
||||
copyNext();
|
||||
removeTrailingSpaces();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiser::removeTrailingSpaces()
|
||||
{
|
||||
int index = m_stripped.length();
|
||||
while ( index-1 > 0 && isSpace( m_stripped[index-1] ) )
|
||||
--index;
|
||||
m_stripped.resize( index );
|
||||
}
|
63
examples/cppunittest/XmlUniformiser.h
Normal file
63
examples/cppunittest/XmlUniformiser.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#ifndef CPPUNITTEST_XMLUNIFORMISER_H
|
||||
#define CPPUNITTEST_XMLUNIFORMISER_H
|
||||
|
||||
#include <cppunit/SourceLine.h>
|
||||
#include <cppunit/TestAssert.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
/*! Uniformise an XML string.
|
||||
*
|
||||
* Strips spaces between attribut in Element.
|
||||
* \warning Attribute values must be double-quoted (att="value").
|
||||
* No support for embedded DTD declaration
|
||||
*/
|
||||
class XmlUniformiser
|
||||
{
|
||||
public:
|
||||
XmlUniformiser( const std::string &xml );
|
||||
std::string stripped();
|
||||
|
||||
private:
|
||||
void skipSpaces();
|
||||
bool isValidIndex();
|
||||
void skipNext( int count =1 );
|
||||
void copyNext( int count =1 );
|
||||
void skipProcessed();
|
||||
void skipComment();
|
||||
void copyElement();
|
||||
void copyElementContent();
|
||||
bool isSpace( char c );
|
||||
bool isSpace();
|
||||
bool startsWith( std::string expected );
|
||||
void copyElementName();
|
||||
void copyElementAttributes();
|
||||
void copyAttributeName();
|
||||
bool isEndOfAttributeName();
|
||||
void copyAttributeValue();
|
||||
void copyUntilDoubleQuote();
|
||||
void removeTrailingSpaces();
|
||||
|
||||
private:
|
||||
unsigned int m_index;
|
||||
std::string m_xml;
|
||||
std::string m_stripped;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
checkXmlEqual( std::string expectedXml,
|
||||
std::string actualXml,
|
||||
CPPUNIT_NS::SourceLine sourceLine );
|
||||
|
||||
|
||||
/// Asserts that two XML strings are equivalent.
|
||||
#define CPPUNITTEST_ASSERT_XML_EQUAL( expected, actual ) \
|
||||
::checkXmlEqual( expected, actual, \
|
||||
CPPUNIT_SOURCELINE() )
|
||||
|
||||
|
||||
|
||||
#endif // XMLUNIFORMISER_H
|
144
examples/cppunittest/XmlUniformiserTest.cpp
Normal file
144
examples/cppunittest/XmlUniformiserTest.cpp
Normal file
@@ -0,0 +1,144 @@
|
||||
#include <stdlib.h>
|
||||
#include "UnitTestToolSuite.h"
|
||||
#include "XmlUniformiserTest.h"
|
||||
#include "XmlUniformiser.h"
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( XmlUniformiserTest,
|
||||
unitTestToolSuiteName() );
|
||||
|
||||
|
||||
XmlUniformiserTest::XmlUniformiserTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
XmlUniformiserTest::~XmlUniformiserTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiserTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiserTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiserTest::testEmpty()
|
||||
{
|
||||
check( "", "" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiserTest::testSkipProcessed()
|
||||
{
|
||||
check( "<?xml version=\"1.0\" encoding='ISO-8859-1' ?>",
|
||||
"" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiserTest::testOpenElementWithoutAttributeButSomeSpaces()
|
||||
{
|
||||
check( " <Test > ",
|
||||
"<Test>" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiserTest::testOpenCloseElement()
|
||||
{
|
||||
check( " <TestName > </TestName > ",
|
||||
"<TestName></TestName>" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiserTest::testElementWithEmptyAttribute()
|
||||
{
|
||||
check( "<TestName id=\"\">",
|
||||
"<TestName id=\"\">" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiserTest::testElementWithEmptyAttributeButSomeSpaces()
|
||||
{
|
||||
check( "<TestName id = \"\" >",
|
||||
"<TestName id=\"\">" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiserTest::testElementWithOneAttribute()
|
||||
{
|
||||
check( "<FailedTest id=\"123\">",
|
||||
"<FailedTest id=\"123\">" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiserTest::testElementWithThreeAttributes()
|
||||
{
|
||||
check( "<FailedTest id = \"7\" date-format= \"iso-8901\" "
|
||||
"style =\"debug\">",
|
||||
"<FailedTest id=\"7\" date-format=\"iso-8901\" style=\"debug\">" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiserTest::testElementWithContent()
|
||||
{
|
||||
check( "<Element>\nContent\n</Element>\n",
|
||||
"<Element>Content</Element>" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiserTest::testElementsHierarchyWithContents()
|
||||
{
|
||||
check( "<TestRuns date-format=\"iso-8901\">\n"
|
||||
"<Date>2001-10-04</Date>\n"
|
||||
"<FailedTests>\n<FailedTest>\n"
|
||||
"<TestName>TokenParserTest</TestName>\n"
|
||||
"</FailedTest>\n</Failedtests>\n</TestRuns>\n",
|
||||
"<TestRuns date-format=\"iso-8901\">"
|
||||
"<Date>2001-10-04</Date>"
|
||||
"<FailedTests><FailedTest>"
|
||||
"<TestName>TokenParserTest</TestName>"
|
||||
"</FailedTest></Failedtests></TestRuns>" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiserTest::testSkipComment()
|
||||
{
|
||||
check( "<!-- skip comment-->",
|
||||
"" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiserTest::testAssertXmlEqual()
|
||||
{
|
||||
CPPUNIT_ASSERT_ASSERTION_FAIL(
|
||||
CPPUNITTEST_ASSERT_XML_EQUAL( "<Test>", "<Tes>" ) );
|
||||
CPPUNIT_ASSERT_ASSERTION_PASS(
|
||||
CPPUNITTEST_ASSERT_XML_EQUAL( "<Test>", "<Test>" ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XmlUniformiserTest::check( const std::string &xml,
|
||||
const std::string &expectedStrippedXml )
|
||||
{
|
||||
std::string actual = XmlUniformiser( xml ).stripped();
|
||||
CPPUNIT_ASSERT_EQUAL( expectedStrippedXml, actual );
|
||||
}
|
67
examples/cppunittest/XmlUniformiserTest.h
Normal file
67
examples/cppunittest/XmlUniformiserTest.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#ifndef XMLUNIFORMISERTEST_H
|
||||
#define XMLUNIFORMISERTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
||||
/*! \class XmlUniformiserTest
|
||||
* \brief Unit test for XmlUniformiser.
|
||||
*/
|
||||
class XmlUniformiserTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( XmlUniformiserTest );
|
||||
CPPUNIT_TEST( testEmpty );
|
||||
CPPUNIT_TEST( testSkipProcessed );
|
||||
CPPUNIT_TEST( testOpenElementWithoutAttributeButSomeSpaces );
|
||||
CPPUNIT_TEST( testOpenCloseElement );
|
||||
CPPUNIT_TEST( testElementWithEmptyAttribute );
|
||||
CPPUNIT_TEST( testElementWithEmptyAttributeButSomeSpaces );
|
||||
CPPUNIT_TEST( testElementWithOneAttribute );
|
||||
CPPUNIT_TEST( testElementWithThreeAttributes );
|
||||
CPPUNIT_TEST( testSkipComment );
|
||||
CPPUNIT_TEST( testElementWithContent );
|
||||
CPPUNIT_TEST( testElementsHierarchyWithContents );
|
||||
CPPUNIT_TEST( testAssertXmlEqual );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
/*! Constructs a XmlUniformiserTest object.
|
||||
*/
|
||||
XmlUniformiserTest();
|
||||
|
||||
/// Destructor.
|
||||
virtual ~XmlUniformiserTest();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
void testEmpty();
|
||||
void testSkipProcessed();
|
||||
void testOpenElementWithoutAttributeButSomeSpaces();
|
||||
void testOpenCloseElement();
|
||||
void testElementWithEmptyAttribute();
|
||||
void testElementWithEmptyAttributeButSomeSpaces();
|
||||
void testElementWithOneAttribute();
|
||||
void testElementWithThreeAttributes();
|
||||
void testSkipComment();
|
||||
void testElementWithContent();
|
||||
void testElementsHierarchyWithContents();
|
||||
|
||||
void testAssertXmlEqual();
|
||||
|
||||
private:
|
||||
void check( const std::string &xml,
|
||||
const std::string &expectedStrippedXml );
|
||||
|
||||
/// Prevents the use of the copy constructor.
|
||||
XmlUniformiserTest( const XmlUniformiserTest © );
|
||||
|
||||
/// Prevents the use of the copy operator.
|
||||
void operator =( const XmlUniformiserTest © );
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // XMLUNIFORMISERTEST_H
|
35
examples/cppunittest/assertion_traitsTest.cpp
Normal file
35
examples/cppunittest/assertion_traitsTest.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <cppunit/TestAssert.h>
|
||||
#include "CoreSuite.h"
|
||||
#include "assertion_traitsTest.h"
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( assertion_traitsTest,
|
||||
coreSuiteName() );
|
||||
|
||||
assertion_traitsTest::assertion_traitsTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
assertion_traitsTest::test_toString()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL( std::string( "abc" ),
|
||||
CPPUNIT_NS::assertion_traits<char*>::toString( "abc" ) );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( std::string( "33" ),
|
||||
CPPUNIT_NS::assertion_traits<int>::toString( 33 ) );
|
||||
|
||||
// Test that assertion_traits<double>::toString() produces
|
||||
// more than the standard 6 digits of precision.
|
||||
CPPUNIT_ASSERT_EQUAL( std::string( "33.1" ),
|
||||
CPPUNIT_NS::assertion_traits<double>::toString( 33.1 ) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string( "33.001" ),
|
||||
CPPUNIT_NS::assertion_traits<double>::toString( 33.001 ) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string( "33.00001" ),
|
||||
CPPUNIT_NS::assertion_traits<double>::toString( 33.00001 ) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string( "33.0000001" ),
|
||||
CPPUNIT_NS::assertion_traits<double>::toString( 33.0000001 ) );
|
||||
CPPUNIT_ASSERT_EQUAL( std::string( "33.0000000001" ),
|
||||
CPPUNIT_NS::assertion_traits<double>::toString( 33.0000000001 ) );
|
||||
}
|
27
examples/cppunittest/assertion_traitsTest.h
Normal file
27
examples/cppunittest/assertion_traitsTest.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef ASSERTIONTRAITSTEST_H
|
||||
#define ASSERTIONTRAITSTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
class assertion_traitsTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE( assertion_traitsTest );
|
||||
CPPUNIT_TEST( test_toString );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
|
||||
assertion_traitsTest();
|
||||
|
||||
void test_toString();
|
||||
|
||||
|
||||
private:
|
||||
assertion_traitsTest( const assertion_traitsTest © );
|
||||
void operator =( const assertion_traitsTest © );
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user