[B]asic module for [unit] program testing:
|
[B]asic module for [unit] program testing. More...
#include <list>
#include <string>
#include <sstream>
#include <cstring>
#include <typeinfo>
#include <algorithm>
#include <math.h>
Go to the source code of this file.
Classes | |
class | TestCaseFailure |
Private class to hold test cases that didn´t succeed. More... | |
class | TestCase |
Every test case is an instance derived from this abstract class. More... | |
class | TestSuite< TestCase > |
Test collection. More... | |
Namespaces | |
namespace | std |
Defined by the C++ estándar library. | |
namespace | ECCI |
Escuela de Ciencias de la Computación e Informática. | |
Defines | |
#define | English_dox "Doxygen English documentation" |
Doxygen English documentation. | |
#define | BUnit_h |
#define | English_dox "Doxygen English documentation" |
Doxygen English documentation. | |
#define | TEST_BUnit() |
[BUnit] ==> BUnit.h | |
#define | BUnit_TEST(cond) testThis( cond, #cond, __FILE__, __LINE__ ) |
[BUnit] Executes test "cond and records its result. | |
#define | BUnit_TEST_Msg(msg, cond) testThis( cond, msg, __FILE__, __LINE__ ) |
[BUnit] Macro similar to BUnit_TEST() that uses mesaje "msg" . | |
#define | BUnit_FAILURE(msg) recordFailure( msg, __FILE__, __LINE__ ) |
[BUnit] Records as "failure" the result of a test. | |
#define | BUnit_SUCCESS() recordSuccess() |
[BUnit] Records as "successful" the result of a test. | |
#define | BUnit_EQUAL(expected, actual) testThis( (expected) == (actual), #expected " == " #actual, __FILE__, __LINE__ ) |
[BUnit] Executes the test to determine if (expected == actual) . | |
#define | BUnit_EQUAL_Msg(MSG, expected, actual) testThis( (expected) == (actual), MSG, __FILE__, __LINE__ ) |
[BUnit] Executes the test to determine if (expected == actual) . | |
#define | BUnit_DEFINE_check_ok |
If this macro exist functions for check_ok() will be defined for the basic types. | |
#define | CPPUNIT_BUnit() |
[CppUnit] Macros propios de CppUnit http://cppunit.sourceforge.net/doc/lastest | |
#define | CPPUNIT_ASSERT(condition) BUnit_TEST(condition) |
[CppUnit] Assertions that a condition is true. | |
#define | CPPUNIT_ASSERT_MESSAGE(message, condition) assertTrue_Msg(message,condition) |
[CppUnit] Assertion with a user specified message. | |
#define | CPPUNIT_FAIL(message) BUnit_FAILURE(message) |
[CppUnit] Fails with the specified message. | |
#define | CPPUNIT_ASSERT_EQUAL(expected, actual) BUnit_EQUAL(expected, actual) |
[CppUnit] Asserts that two values are equals. | |
#define | CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expected, actual) BUnit_EQUAL_Msg(message, expected, actual) |
[CppUnit] Asserts that two values are equals, provides additional messafe on failure. | |
#define | CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, delta) assertEquals_Delta(expected, actual, delta) |
[CppUnit] Macro for primitive value comparisons. | |
#define | CPPUNIT_ASSERT_THROW(expression, ExceptionType) |
[CppUnit] Asserts that the given expression throws an exception of the specified type. | |
#define | CPPUNIT_ASSERT_NO_THROW(expression) |
[CppUnit] Asserts that the given expression does not throw any exceptions. | |
#define | CPPUNIT_ASSERT_ASSERTION_FAIL(assertion) CPPUNIT_ASSERT_THROW( assertion, CPPUNIT_NS::Exception ) |
[CppUnit] Asserts that an assertion fail. | |
#define | CPPUNIT_ASSERT_ASSERTION_PASS(assertion) CPPUNIT_ASSERT_NO_THROW( assertion ) |
[CppUnit] Asserts that an assertion pass. | |
#define | JUnit_BUnit() |
#define | assertEquals(EXPECTED, ACTUAL) BUnit_EQUAL(EXPECTED, ACTUAL) |
[JUnit] Macros propios de JUnit http://junit.sourceforge.net/javadoc/junit/framework/Assert.html Asserts that two objects are equal. | |
#define | assertEquals_Msg(MSG, EXPECTED, ACTUAL) BUnit_EQUAL_Msg(MSG, EXPECTED, ACTUAL) |
Asserts that two objects are equal (with message). | |
#define | assertTrue(CONDITION) testThis( CONDITION, #CONDITION, __FILE__, __LINE__ ) |
[JUnit] Asserts that a condition is true. | |
#define | assertTrue_Msg(MSG,CONDITION) testThis( CONDITION, MSG, __FILE__, __LINE__ ) |
[JUnit] Asserts that a condition is true (with message). | |
#define | assertFalse(CONDITION) testThis( !(CONDITION), "!(" #CONDITION ")", __FILE__, __LINE__ ) |
[JUnit] Asserts that a condition is false. | |
#define | assertFalse_Msg(MSG, CONDITION) testThis( !(CONDITION), MSG, __FILE__, __LINE__ ) |
[JUnit] Asserts that a condition is false (with message). | |
#define | assertEquals_Delta(EXPECTED, ACTUAL, DELTA) |
[JUnit] Asserts that two doubles are equal concerning a delta. | |
#define | assertEquals_Delta_Msg(MSG, EXPECTED, ACTUAL, DELTA) |
[JUnit] Asserts that two doubles are equal concerning a delta (with message). | |
#define | assertNull(OBJECT) testThis( 0==&(OBJECT), "assertNull(" #OBJECT ")", __FILE__, __LINE__ ) |
[JUnit] Asserts that an object is null. | |
#define | assertNotNull(OBJECT) testThis( 0!=&(OBJECT), "assertNotNull(" #OBJECT ")", __FILE__, __LINE__ ) |
[JUnit] Asserts that an object isn't null. | |
#define | assertSame(THIS, THAT) |
[JUnit] Asserts that two objects refer to the same object. | |
#define | assertNotSame(THIS, THAT) |
Asserts that two objects do not refer to the same object. | |
#define | fail_Msg(MSG) BUnit_FAILURE(MSG) |
[JUnit] Fails a test with the given message. | |
Typedefs | |
typedef TestCase | TestCase_is_base_for_TestSuite |
Synonym for TestCase . | |
typedef TestCase | TestFixture |
Sets the environment for the test run. | |
Functions | |
template<class TestCase > | |
void | do_toString (const TestCase *tc, std::basic_ostringstream< char > &ost) |
Adds to ost the string of al unsuccessful test from *tc . | |
template<class TestCase > | |
void | do_toXML (const TestCase *tc, std::basic_ostringstream< char > &ost) |
Adds to ost the string of al unsuccessful test from *tc in XML format. |
#define English_dox "Doxygen English documentation" |
#define English_dox "Doxygen English documentation" |
#define TEST_BUnit | ( | ) |
#define BUnit_TEST | ( | cond | ) | testThis( cond, #cond, __FILE__, __LINE__ ) |
[BUnit] Executes test "cond
and records its result.
assertTrue()
for the same purpose."cond"
is successful method TestCase::recordSuccess()
is invoked."cond"
is not successful, methodTestCase::recordFailure()
is invoked. {{ // test::BUnit_macro() class MyTest : public TestCase { public: bool run() { testThis( 2 == 2, "2 == 2", __FILE__, __LINE__ ); // sucess BUnit_TEST( 2 == 2 ); // same thing using macro BUnit_TEST() testThis( 1 == 2, "1 == 2", __FILE__, __LINE__ ); // failure #1 assertTrue( 1 == 2 ); // same thing using BUnit_TEST() // failure #2 { // con macros std::vector<int> V; // "V[]" is empty ==> there is no "V[2]" try { int i = V.at(2); // "V[2]" does not exits BUnit_FAILURE("V.at(2)"); // failure: "at()" didn´t rise the exception } catch (std::logic_error&) { BUnit_SUCCESS(); // correct: "V.at(2)" throws "logic_error" } // because "V[]" is empty } { // no macros std::vector<int> V; try { int i = V.at(2); recordFailure("V.at(2)" , __FILE__ , __LINE__ ); } catch (std::logic_error&) { recordSuccess(); } } return wasSuccessful(); // Returns "false" } }; // MyTest MyTest thisTest; assertTrue( thisTest.wasSuccessful() ); // run() has not been executed thisTest.run(); // 2 failures assertTrue( thisTest.failureCount() == 2 ); assertTrue( thisTest.toXML() != "" ); assertTrue( ! thisTest.wasSuccessful() ); }}
#define BUnit_TEST_Msg | ( | msg, | |
cond | |||
) | testThis( cond, msg, __FILE__, __LINE__ ) |
[BUnit] Macro similar to BUnit_TEST()
that uses mesaje "msg"
.
"msg"
must be a literal (char*) string or and object that can be converted into a (const char *)
. #define BUnit_FAILURE | ( | msg | ) | recordFailure( msg, __FILE__, __LINE__ ) |
[BUnit] Records as "failure" the result of a test.
TestCase::recordFailure()
. if (22==33) { BUnit_FAILURE("! (22==33)"); // records failure }
#define BUnit_SUCCESS | ( | ) | recordSuccess() |
[BUnit] Records as "successful" the result of a test.
TestCase::recordSuccess()
. #define BUnit_EQUAL | ( | expected, | |
actual | |||
) | testThis( (expected) == (actual), #expected " == " #actual, __FILE__, __LINE__ ) |
[BUnit] Executes the test to determine if (expected == actual)
.
TestCase::recordSuccess()
.TestCase::recordFailure()
.TestCase::testThis()
. #define BUnit_EQUAL_Msg | ( | MSG, | |
expected, | |||
actual | |||
) | testThis( (expected) == (actual), MSG, __FILE__, __LINE__ ) |
[BUnit] Executes the test to determine if (expected == actual)
.
TestCase::recordSuccess()
.TestCase::recordFailure()
.TestCase::testThis()
."MSG"
if the test is not successful. #define BUnit_DEFINE_check_ok |
If this macro exist functions for check_ok()
will be defined for the basic types.
#define CPPUNIT_BUnit | ( | ) |
[CppUnit] Macros propios de CppUnit
http://cppunit.sourceforge.net/doc/lastest
#define CPPUNIT_ASSERT | ( | condition | ) | BUnit_TEST(condition) |
[CppUnit] Assertions that a condition is true.
#define CPPUNIT_ASSERT_MESSAGE | ( | message, | |
condition | |||
) | assertTrue_Msg(message,condition) |
[CppUnit] Assertion with a user specified message.
#define CPPUNIT_FAIL | ( | message | ) | BUnit_FAILURE(message) |
[CppUnit] Fails with the specified message.
#define CPPUNIT_ASSERT_EQUAL | ( | expected, | |
actual | |||
) | BUnit_EQUAL(expected, actual) |
[CppUnit] Asserts that two values are equals.
#define CPPUNIT_ASSERT_EQUAL_MESSAGE | ( | message, | |
expected, | |||
actual | |||
) | BUnit_EQUAL_Msg(message, expected, actual) |
[CppUnit] Asserts that two values are equals, provides additional messafe on failure.
#define CPPUNIT_ASSERT_DOUBLES_EQUAL | ( | expected, | |
actual, | |||
delta | |||
) | assertEquals_Delta(expected, actual, delta) |
[CppUnit] Macro for primitive value comparisons.
#define CPPUNIT_ASSERT_THROW | ( | expression, | |
ExceptionType | |||
) |
do { \ bool cpputExceptionThrown_ = false; \ try { \ expression; \ } catch ( const ExceptionType & ) { \ cpputExceptionThrown_ = true; \ } \ \ if ( cpputExceptionThrown_ ) { \ break; \ } \ BUnit_FAILURE( \ "Expected exception: " #ExceptionType ) \ } while ( false )
[CppUnit] Asserts that the given expression throws an exception of the specified type.
#define CPPUNIT_ASSERT_NO_THROW | ( | expression | ) |
do { \ try { \ expression; \ } catch ( ... ) { \ BUnit_FAILURE("Unexpected exception caught"); \ } \ } while ( false )
[CppUnit] Asserts that the given expression does not throw any exceptions.
#define CPPUNIT_ASSERT_ASSERTION_FAIL | ( | assertion | ) | CPPUNIT_ASSERT_THROW( assertion, CPPUNIT_NS::Exception ) |
[CppUnit] Asserts that an assertion fail.
#define CPPUNIT_ASSERT_ASSERTION_PASS | ( | assertion | ) | CPPUNIT_ASSERT_NO_THROW( assertion ) |
[CppUnit] Asserts that an assertion pass.
#define JUnit_BUnit | ( | ) |
#define assertEquals | ( | EXPECTED, | |
ACTUAL | |||
) | BUnit_EQUAL(EXPECTED, ACTUAL) |
[JUnit] Macros propios de JUnit
http://junit.sourceforge.net/javadoc/junit/framework/Assert.html Asserts that two objects are equal.
#define assertEquals_Msg | ( | MSG, | |
EXPECTED, | |||
ACTUAL | |||
) | BUnit_EQUAL_Msg(MSG, EXPECTED, ACTUAL) |
Asserts that two objects are equal (with message).
#define assertTrue | ( | CONDITION | ) | testThis( CONDITION, #CONDITION, __FILE__, __LINE__ ) |
[JUnit] Asserts that a condition is true.
#define assertTrue_Msg | ( | MSG, | |
CONDITION | |||
) | testThis( CONDITION, MSG, __FILE__, __LINE__ ) |
[JUnit] Asserts that a condition is true (with message).
#define assertFalse | ( | CONDITION | ) | testThis( !(CONDITION), "!(" #CONDITION ")", __FILE__, __LINE__ ) |
[JUnit] Asserts that a condition is false.
#define assertFalse_Msg | ( | MSG, | |
CONDITION | |||
) | testThis( !(CONDITION), MSG, __FILE__, __LINE__ ) |
[JUnit] Asserts that a condition is false (with message).
#define assertEquals_Delta | ( | EXPECTED, | |
ACTUAL, | |||
DELTA | |||
) |
testThis( fabs( double(EXPECTED) - double(ACTUAL) ) < double(DELTA), \ "|" #EXPECTED "-" #ACTUAL "| < " #DELTA, __FILE__, __LINE__ )
[JUnit] Asserts that two doubles are equal concerning a delta.
#define assertEquals_Delta_Msg | ( | MSG, | |
EXPECTED, | |||
ACTUAL, | |||
DELTA | |||
) |
testThis( fabs( double(EXPECTED) - double(ACTUAL) ) < double(DELTA), \ MSG, __FILE__, __LINE__ )
[JUnit] Asserts that two doubles are equal concerning a delta (with message).
#define assertNull | ( | OBJECT | ) | testThis( 0==&(OBJECT), "assertNull(" #OBJECT ")", __FILE__, __LINE__ ) |
[JUnit] Asserts that an object is null.
#define assertNotNull | ( | OBJECT | ) | testThis( 0!=&(OBJECT), "assertNotNull(" #OBJECT ")", __FILE__, __LINE__ ) |
[JUnit] Asserts that an object isn't null.
#define assertSame | ( | THIS, | |
THAT | |||
) |
testThis( &(THIS)==&(THAT), \ "assertSame(" #THIS ", " #THAT ")", __FILE__, __LINE__ )
[JUnit] Asserts that two objects refer to the same object.
#define assertNotSame | ( | THIS, | |
THAT | |||
) |
testThis( &(THIS)!=&(THAT), \ "assertNotSame(" #THIS ", " #THAT ")", __FILE__, __LINE__ )
Asserts that two objects do not refer to the same object.
#define fail_Msg | ( | MSG | ) | BUnit_FAILURE(MSG) |
[JUnit] Fails a test with the given message.
typedef TestCase TestFixture |
Sets the environment for the test run.
This clase exists to improve compatibility with JUnit.
void do_toString | ( | const TestCase * | tc, |
std::basic_ostringstream< char > & | ost | ||
) |