Modulo [B]asico para prueba [unit]aria de programas:
|
Módulo [B]ásico para prueba [unit]aria de programas. Más...
#include <list>
#include <string>
#include <sstream>
#include <cstring>
#include <typeinfo>
#include <algorithm>
#include <math.h>
Ir al código fuente de este archivo.
Clases | |
class | TestCaseFailure |
Clase privada que contiene los datos de cada prueba no exitosa. Más... | |
class | TestCase |
Cada caso de prueba es una instancia derivada de esta clase abstracta. Más... | |
class | TestSuite< TestCase > |
Colección de pruebas. Más... | |
Namespaces | |
namespace | std |
Definido por la biblioteca C++ estándar. | |
namespace | ECCI |
Escuela de Ciencias de la Computación e Informática. | |
'defines' | |
#define | Spanish_dox "Documentación en español" |
Documentación en español. | |
#define | BUnit_h |
#define | Spanish_dox "Documentación en español" |
Documentación en español. | |
#define | TEST_BUnit() |
[BUnit] ==> BUnit.h | |
#define | BUnit_TEST(cond) testThis( cond, #cond, __FILE__, __LINE__ ) |
[BUnit] Efectúa la prueba "cond y registra el resultado. | |
#define | BUnit_TEST_Msg(msg, cond) testThis( cond, msg, __FILE__, __LINE__ ) |
[BUnit] Macro similar a BUnit_TEST() que usa el mensaje "msg" . | |
#define | BUnit_FAILURE(msg) recordFailure( msg, __FILE__, __LINE__ ) |
[BUnit] Registra como "falla" el resultado de una prueba. | |
#define | BUnit_SUCCESS() recordSuccess() |
[BUnit] Registra como "exitoso" el resultado de una prueba. | |
#define | BUnit_EQUAL(expected, actual) testThis( (expected) == (actual), #expected " == " #actual, __FILE__, __LINE__ ) |
[BUnit] Efectúa la prueba para determinar si (expected == actual) . | |
#define | BUnit_EQUAL_Msg(MSG, expected, actual) testThis( (expected) == (actual), MSG, __FILE__, __LINE__ ) |
[BUnit] Efectúa la prueba para determinar si expected == actual . | |
#define | BUnit_DEFINE_check_ok |
Si esta macro existe las funciones check_ok() quedan definidas para los tipos básicos. | |
#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 |
Sinónimo de TestCase . | |
typedef TestCase | TestFixture |
Establece el ambiente para la ejecución de la prueba. | |
Funciones | |
template<class TestCase > | |
void | do_toString (const TestCase *tc, std::basic_ostringstream< char > &ost) |
Le agrega a ost la hilera de todas las pruebas no exitosas de *tc . | |
template<class TestCase > | |
void | do_toXML (const TestCase *tc, std::basic_ostringstream< char > &ost) |
Le agrega a ost la hilera de todas las pruebas no exitosas de *tc en formato XML. |
#define Spanish_dox "Documentación en español" |
#define Spanish_dox "Documentación en español" |
#define TEST_BUnit | ( | ) |
#define BUnit_TEST | ( | cond | ) | testThis( cond, #cond, __FILE__, __LINE__ ) |
[BUnit] Efectúa la prueba "cond
y registra el resultado.
assertTrue()
que hace lo mismo."cond"
tiene éxito invoca el método TestCase::recordSuccess()
."cond"
no tiene éxito invoca el método TestCase::recordFailure()
. {{ // 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 a BUnit_TEST()
que usa el mensaje "msg"
.
"msg"
debe ser una hilera (char*) literal o un objeto que pueda convertirse en (const char *)
. #define BUnit_FAILURE | ( | msg | ) | recordFailure( msg, __FILE__, __LINE__ ) |
[BUnit] Registra como "falla" el resultado de una prueba.
TestCase::recordFailure()
. if (22==33) { BUnit_FAILURE("! (22==33)"); // records failure }
#define BUnit_SUCCESS | ( | ) | recordSuccess() |
[BUnit] Registra como "exitoso" el resultado de una prueba.
TestCase::recordSuccess()
. #define BUnit_EQUAL | ( | expected, | |
actual | |||
) | testThis( (expected) == (actual), #expected " == " #actual, __FILE__, __LINE__ ) |
[BUnit] Efectúa la prueba para determinar si (expected == actual)
.
TestCase::recordSuccess()
.TestCase::recordFailure()
.TestCase::testThis()
. #define BUnit_EQUAL_Msg | ( | MSG, | |
expected, | |||
actual | |||
) | testThis( (expected) == (actual), MSG, __FILE__, __LINE__ ) |
[BUnit] Efectúa la prueba para determinar si expected == actual
.
TestCase::recordSuccess()
.TestCase::recordFailure()
.TestCase::testThis()
."MSG"
si la prueba no tiene éxito. #define BUnit_DEFINE_check_ok |
Si esta macro existe las funciones check_ok()
quedan definidas para los tipos básicos.
#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 |
Establece el ambiente para la ejecución de la prueba.
Esta clase existe para mejorar la compatibilidad con JUnit.
void do_toString | ( | const TestCase * | tc, |
std::basic_ostringstream< char > & | ost | ||
) |