src/Assertion.hpp File Reference


Detailed Description

Assertions methods, classes and marcos for unit testing.

Author:
Jean Lazarou
Date:
2005/10/11

Definition in file Assertion.hpp.

#include <list>
#include <string>
#include <vector>
#include <sstream>

Go to the source code of this file.

Namespaces

namespace  unittest
namespace  std

Classes

class  unittest::Throwable
 An exception class that can be used as a base class for specific exceptions, ut4cpp catches this exception and is able to output a meaningful message. More...
class  unittest::AssertionException
 ut4cpp raises a AssertionException exception when an assertion fails. More...
class  unittest::Test
 The actual tests must implement this Test interface. More...
class  unittest::TestReport
 A TestReport object is used to record the test results. More...
class  unittest::TestSet
 A TestSet contains all the tests to run. More...
class  unittest::TestSet::Chain
 All the TestSet objects are chained using Chain objects. More...

Defines

#define TESTCASE(name)
 The TESTCASE macro starts a test case, with the given name.
#define TEST(name, body)   GEN_TEST(name, body, false, false)
 The TEST macro delcares a test, with the given name.
#define MUTE(name, body)   GEN_TEST(name, body, true, false)
 The MUTE macro delcares a test that should not be run, with the given name.
#define SOLO(name, body)   GEN_TEST(name, body, false, true)
 The SOLO macro delcares a test that is the only that must be run, with the given name.
#define GEN_TEST(name, body, setMuted, setSolo)
 Generates code for TEST, MUTE and SOLO macros.
#define GLOBAL_SETUP(body)
 When some initialization is needed for all the tests that belong to the same test case, use this marco.
#define GLOBAL_TEARDOWN(body)
 When some cleanup is needed for all the tests that belong to the same test case, use this marco.
#define END_TESTCASE
 Ends the current test case defintion.
#define USE_TESTCASE(name)   namespace name {TestSet* suite();}
 Declares the given test case so that it can be use at some place.

Typedefs

typedef Test *(* unittest::TestFactory )()
 Method signature for test factory methods.
typedef void(* unittest::SetupMethod )()
 Method signature for setup methods.
typedef void(* unittest::TeardownMethod )()
 Method signature for tear down methods.

Functions

void unittest::fail (string msg)
 Raises a AssertionException setting the given message as the cause the failure.
template<typename T>
void unittest::assertEquals (string msg, const T &expected, const T &actual)
 Compares the expected and actual values, if they are not equal, raises a AssertionException.
template<typename T>
void unittest::assertEquals (const T &expected, const T &actual)
 Compares the expected and actual values, if they are not equal, raises a AssertionException.
template<typename T>
void unittest::assertNotEquals (string msg, const T &expected, const T &actual)
 Compares the expected and actual values, if they are equal, raises a AssertionException.
template<typename T>
void unittest::assertNotEquals (const T &expected, const T &actual)
 Compares the expected and actual values, if they are equal, raises a AssertionException.
void unittest::assertTrue (string msg, bool assertion)
 Raises a AssertionException if the given assertion is not true.
void unittest::assertTrue (bool assertion)
 Raises a AssertionException if the given assertion is not true.
void unittest::assertFalse (bool assertion)
 Raises a AssertionException if the given assertion is true.
void unittest::assertFalse (string msg, bool assertion)
 Raises a AssertionException if the given assertion is true.
void unittest::assertEquals (const char *expected, const char *actual)
 Compares two C strings (char*), if they are not equal, raises a AssertionException.
void unittest::assertEquals (const char *expected, string actual)
 Compares a C string (char*) with a string object, if they are not equal, raises a AssertionException.
void unittest::assertEquals (string expected, const char *actual)
 Compares a string object with a C string (char*) , if they are not equal, raises a AssertionException.
void unittest::assertNotEquals (const char *expected, const char *actual)
 Compares two C strings (char*), if they are equal, raises a AssertionException.
void unittest::assertNotEquals (const char *expected, string actual)
 Compares a C string (char*) with a string object, if they are equal, raises a AssertionException.
void unittest::assertNotEquals (string expected, const char *actual)
 Compares a string object with a C string (char*) , if they are equal, raises a AssertionException.


Define Documentation

#define GLOBAL_SETUP body   ) 
 

Value:

\
    class GlobalSetup { \
        public:\
            static void setUp() {\
                body\
            }\
    };\
    \
    res->globalSetUp = GlobalSetup::setUp;\
When some initialization is needed for all the tests that belong to the same test case, use this marco.

Parameters:
body the C++ code that sets up the global context

Definition at line 559 of file Assertion.hpp.

#define GLOBAL_TEARDOWN body   ) 
 

Value:

\
    class GlobalTearDown {\
        public:\
            static void tearDown() {\
                body\
            }\
    };\
    \
    res->globalTearDown = GlobalTearDown::tearDown;\
When some cleanup is needed for all the tests that belong to the same test case, use this marco.

Parameters:
body the C++ code that cleans up the global context

Definition at line 575 of file Assertion.hpp.

#define MUTE name,
body   )     GEN_TEST(name, body, true, false)
 

The MUTE macro delcares a test that should not be run, with the given name.

Parameters:
name this test's name
body the C++ code that implements the code

Definition at line 520 of file Assertion.hpp.

#define SOLO name,
body   )     GEN_TEST(name, body, false, true)
 

The SOLO macro delcares a test that is the only that must be run, with the given name.

Parameters:
name this test's name
body the C++ code that implements the code

Definition at line 527 of file Assertion.hpp.

#define TEST name,
body   )     GEN_TEST(name, body, false, false)
 

The TEST macro delcares a test, with the given name.

Parameters:
name this test's name
body the C++ code that implements the code
Examples:
TestAssertion.cpp.

Definition at line 513 of file Assertion.hpp.

#define TESTCASE name   ) 
 

Value:

namespace name {\
\
TestSet* suite() {\
\
    TestSet *res = new TestSet(#name);\
\
typedef name##Fixture LocalFixture;
The TESTCASE macro starts a test case, with the given name.

Parameters:
name this test case's name
Examples:
TestAssertion.cpp.

Definition at line 499 of file Assertion.hpp.

#define USE_TESTCASE name   )     namespace name {TestSet* suite();}
 

Declares the given test case so that it can be use at some place.

..

Definition at line 601 of file Assertion.hpp.


Generated on Mon Jun 5 22:05:27 2006 for ut4cpp by  doxygen 1.4.6-NO