Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

ADH_test.h File Reference

Módulo para prueba unitaria de programas. More...

#include <string>
#include <sstream>
#include <typeinfo.h>
#include <math.h>

Go to the source code of this file.

Namespaces

namespace  std
namespace  ECCI

Defines

#define ADH_test_h
 Evita la inclusión múltiple.
#define TEST_ADH_test()
 [ADH_test] Macros propios de ADH_test.h
#define TEST_THIS(cond)   testThis( cond, #cond, __FILE__, __LINE__ )
#define TEST_THIS_Msg(msg, cond)   testThis( cond, msg, __FILE__, __LINE__ )
#define TEST_ERROR(str)   recordError( str, __FILE__, __LINE__ )
#define TEST_SUCCESS()   recordSuccess()
#define TEST_EQUAL(expected, actual)   testThis( (expected) == (actual), #expected " == " #actual, __FILE__, __LINE__ )
#define TEST_EQUAL_Msg(MSG, expected, actual)   testThis( (expected) == (actual), MSG, __FILE__, __LINE__ )
#define CPPUNIT_ADH_test()
 [CppUnit] Macros propios de CppUnit http://cppunit.sourceforge.net/doc/lastest
#define CPPUNIT_ASSERT(condition)   TEST_THIS(condition)
#define CPPUNIT_ASSERT_MESSAGE(message, condition)   CPPUNIT_ASSERT(condition)
#define CPPUNIT_FAIL(message)   TEST_ERROR(message)
#define CPPUNIT_ASSERT_EQUAL(expected, actual)   TEST_EQUAL(expected, actual)
#define CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expected, actual)   TEST_EQUAL_Msg(message, expected, actual)
#define CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, delta)   assertEquals_Delta(expected, actual, delta)
#define CPPUNIT_ASSERT_THROW(expression, ExceptionType)
#define CPPUNIT_ASSERT_NO_THROW(expression)
#define CPPUNIT_ASSERT_ASSERTION_FAIL(assertion)   CPPUNIT_ASSERT_THROW( assertion, CPPUNIT_NS::Exception )
#define CPPUNIT_ASSERT_ASSERTION_PASS(assertion)   CPPUNIT_ASSERT_NO_THROW( assertion )
#define JUnit_ADH_test()
#define assertEquals(EXPECTED, ACTUAL)   TEST_EQUAL(EXPECTED, ACTUAL)
#define assertEquals_Msg(MSG, EXPECTED, ACTUAL)   TEST_EQUAL_Msg(MSG, EXPECTED, ACTUAL)
#define assertTrue(CONDITION)   testThis( CONDITION, #CONDITION, __FILE__, __LINE__ )
#define assertTrue_Msg(MSG,CONDITION)   testThis( CONDITION, MSG, __FILE__, __LINE__ )
#define assertFalse(CONDITION)   testThis( !(CONDITION), "!(" #CONDITION ")", __FILE__, __LINE__ )
#define assertFalse_Msg(MSG, CONDITION)   testThis( !(CONDITION), MSG, __FILE__, __LINE__ )
#define assertEquals_Delta(EXPECTED, ACTUAL, DELTA)
#define assertEquals_Delta_Msg(MSG, EXPECTED, ACTUAL, DELTA)
#define assertNull(OBJECT)   testThis( 0==&(OBJECT), "assertNull(" #OBJECT ")", __FILE__, __LINE__ )
#define assertNotNull(OBJECT)   testThis( 0!=&(OBJECT), "assertNotNull(" #OBJECT ")", __FILE__, __LINE__ )
#define assertSame(THIS, THAT)   testThis( &(THIS)==&(THAT), "assertSame(" #THIS ", " #THAT ")", __FILE__, __LINE__ )
#define assertNotSame(THIS, THAT)   testThis( &(THIS)!=&(THAT), "assertNotSame(" #THIS ", " #THAT ")", __FILE__, __LINE__ )
#define fail()   TEST_ERROR("ERROR")
#define fail_Msg(MSG)   TEST_ERROR(MSG)

Functions

std::ostream & operator<< (std::ostream &COUT, const TestCase &test)
long Report (std::ostream &COUT, const TestCase &test)
template<class T>
bool check_ok (const T &)
 Declaración genérica para check_ok().
bool check_ok (const signed char &)
 check_ok<>()==true por defecto (por si el programador no lo ha implementado)
bool check_ok (const unsigned char &)
 check_ok<>()==true por defecto (por si el programador no lo ha implementado)
bool check_ok (const signed int &)
 check_ok<>()==true por defecto (por si el programador no lo ha implementado)
bool check_ok (const unsigned int &)
 check_ok<>()==true por defecto (por si el programador no lo ha implementado)
bool check_ok (const signed long &)
 check_ok<>()==true por defecto (por si el programador no lo ha implementado)
bool check_ok (const unsigned long &)
 check_ok<>()==true por defecto (por si el programador no lo ha implementado)
bool check_ok (const float &)
 check_ok<>()==true por defecto (por si el programador no lo ha implementado)
bool check_ok (const double &)
 check_ok<>()==true por defecto (por si el programador no lo ha implementado)
bool check_ok (const long double &)
 check_ok<>()==true por defecto (por si el programador no lo ha implementado)
template<class T>
std::string toString (const T &val)


Detailed Description

Módulo para prueba unitaria de programas.

Author:
Adolfo Di Mare <[email protected]>
Date:
2006

Define Documentation

#define assertEquals EXPECTED,
ACTUAL   )     TEST_EQUAL(EXPECTED, ACTUAL)
 

[JUnit] Macros propios de JUnit http://junit.sourceforge.net/javadoc/junit/framework/Assert.html Asserts that two objects are equal.

See also:
http://junit.sourceforge.net/javadoc/junit/framework/Assert.html#assertEquals(java.lang.Object,%20java.lang.Object)

#define assertEquals_Delta EXPECTED,
ACTUAL,
DELTA   ) 
 

Value:

testThis( fabs( double(EXPECTED) -  double(ACTUAL) ) < double(DELTA), \
        "|"  #EXPECTED "-" #ACTUAL "| < " #DELTA,  __FILE__, __LINE__ )
[JUnit] Asserts that two doubles are equal concerning a delta.
See also:
http://junit.sourceforge.net/javadoc/junit/framework/Assert.html#assertEquals(double,%20double,%20double)

#define assertEquals_Delta_Msg MSG,
EXPECTED,
ACTUAL,
DELTA   ) 
 

Value:

testThis( fabs( double(EXPECTED) -  double(ACTUAL) ) < double(DELTA), \
        MSG, __FILE__, __LINE__ )
[JUnit] Asserts that two doubles are equal concerning a delta (with message).
See also:
http://junit.sourceforge.net/javadoc/junit/framework/Assert.html#assertEquals(java.lang.String,%20double,%20double,%20double)

#define assertEquals_Msg MSG,
EXPECTED,
ACTUAL   )     TEST_EQUAL_Msg(MSG, EXPECTED, ACTUAL)
 

Asserts that two objects are equal (with message).

See also:
http://junit.sourceforge.net/javadoc/junit/framework/Assert.html#assertEquals(java.lang.String,%20java.lang.Object,%20java.lang.Object)

#define assertFalse CONDITION   )     testThis( !(CONDITION), "!(" #CONDITION ")", __FILE__, __LINE__ )
 

[JUnit] Asserts that a condition is false.

See also:
http://junit.sourceforge.net/javadoc/junit/framework/Assert.html#assertFalse(boolean)

#define assertFalse_Msg MSG,
CONDITION   )     testThis( !(CONDITION), MSG, __FILE__, __LINE__ )
 

[JUnit] Asserts that a condition is false (with message).

See also:
http://junit.sourceforge.net/javadoc/junit/framework/Assert.html#assertFalse(java.lang.String,%20boolean)

#define assertNotNull OBJECT   )     testThis( 0!=&(OBJECT), "assertNotNull(" #OBJECT ")", __FILE__, __LINE__ )
 

[JUnit] Asserts that an object isn't null.

See also:
http://junit.sourceforge.net/javadoc/junit/framework/Assert.html#assertNotNull(java.lang.Object)

#define assertNotSame THIS,
THAT   )     testThis( &(THIS)!=&(THAT), "assertNotSame(" #THIS ", " #THAT ")", __FILE__, __LINE__ )
 

Asserts that two objects do not refer to the same object.

See also:
http://junit.sourceforge.net/javadoc/junit/framework/Assert.html#assertNotSame(java.lang.Object,%20java.lang.Object)

#define assertNull OBJECT   )     testThis( 0==&(OBJECT), "assertNull(" #OBJECT ")", __FILE__, __LINE__ )
 

[JUnit] Asserts that an object is null.

See also:
http://junit.sourceforge.net/javadoc/junit/framework/Assert.html#assertNull(java.lang.Object)

#define assertSame THIS,
THAT   )     testThis( &(THIS)==&(THAT), "assertSame(" #THIS ", " #THAT ")", __FILE__, __LINE__ )
 

[JUnit] Asserts that two objects refer to the same object.

See also:
http://junit.sourceforge.net/javadoc/junit/framework/Assert.html#assertSame(java.lang.Object,%20java.lang.Object)

#define assertTrue CONDITION   )     testThis( CONDITION, #CONDITION, __FILE__, __LINE__ )
 

[JUnit] Asserts that a condition is true.

See also:
http://junit.sourceforge.net/javadoc/junit/framework/Assert.html#assertTrue(boolean)

#define assertTrue_Msg MSG,
CONDITION   )     testThis( CONDITION, MSG, __FILE__, __LINE__ )
 

[JUnit] Asserts that a condition is true (with message).

See also:
http://junit.sourceforge.net/javadoc/junit/framework/Assert.html#assertTrue(java.lang.String,%20boolean)

#define CPPUNIT_ASSERT condition   )     TEST_THIS(condition)
 

[CppUnit] Assertions that a condition is true.

See also:
http://cppunit.sourceforge.net/doc/lastest/group___assertions.html#ga0

#define CPPUNIT_ASSERT_ASSERTION_FAIL assertion   )     CPPUNIT_ASSERT_THROW( assertion, CPPUNIT_NS::Exception )
 

[CppUnit] Asserts that an assertion fail.

See also:
http://cppunit.sourceforge.net/doc/lastest/group___assertions.html#ga8

#define CPPUNIT_ASSERT_ASSERTION_PASS assertion   )     CPPUNIT_ASSERT_NO_THROW( assertion )
 

[CppUnit] Asserts that an assertion pass.

See also:
http://cppunit.sourceforge.net/doc/lastest/group___assertions.html#ga9

#define CPPUNIT_ASSERT_DOUBLES_EQUAL expected,
actual,
delta   )     assertEquals_Delta(expected, actual, delta)
 

[CppUnit] Macro for primitive value comparisons.

See also:
http://cppunit.sourceforge.net/doc/lastest/group___assertions.html#ga5

#define CPPUNIT_ASSERT_EQUAL expected,
actual   )     TEST_EQUAL(expected, actual)
 

[CppUnit] Asserts that two values are equals.

See also:
http://cppunit.sourceforge.net/doc/lastest/group___assertions.html#ga3

#define CPPUNIT_ASSERT_EQUAL_MESSAGE message,
expected,
actual   )     TEST_EQUAL_Msg(message, expected, actual)
 

[CppUnit] Asserts that two values are equals, provides additional messafe on failure.

See also:
http://cppunit.sourceforge.net/doc/lastest/group___assertions.html#ga4

#define CPPUNIT_ASSERT_MESSAGE message,
condition   )     CPPUNIT_ASSERT(condition)
 

[CppUnit] Assertion with a user specified message.

See also:
http://cppunit.sourceforge.net/doc/lastest/group___assertions.html#ga1

#define CPPUNIT_ASSERT_NO_THROW expression   ) 
 

Value:

do {                                                 \
            try {                                            \
                expression;                                  \
            } catch ( ... ) {                                \
                TEST_ERROR("Unexpected exception caught");   \
            }                                                \
        } while ( false )
[CppUnit] Asserts that the given expression does not throw any exceptions.
See also:
http://cppunit.sourceforge.net/doc/lastest/group___assertions.html#ga7

#define CPPUNIT_ASSERT_THROW expression,
ExceptionType   ) 
 

Value:

do {                                             \
            bool cpputExceptionThrown_ = false;          \
            try {                                        \
                expression;                              \
            } catch ( const ExceptionType & ) {          \
                cpputExceptionThrown_ = true;            \
            }                                            \
                                                         \
            if ( cpputExceptionThrown_ ) {               \
                break;                                   \
            }                                            \
            TEST_ERROR(                                  \
                "Expected exception: " #ExceptionType )  \
        } while ( false )
[CppUnit] Asserts that the given expression throws an exception of the specified type.
See also:
http://cppunit.sourceforge.net/doc/lastest/group___assertions.html#ga6

#define CPPUNIT_FAIL message   )     TEST_ERROR(message)
 

[CppUnit] Fails with the specified message.

See also:
http://cppunit.sourceforge.net/doc/lastest/group___assertions.html#ga2

 
#define fail  )     TEST_ERROR("ERROR")
 

[JUnit] Fails a test with no message.

See also:
http://junit.sourceforge.net/javadoc/junit/framework/Assert.html#fail()

#define fail_Msg MSG   )     TEST_ERROR(MSG)
 

[JUnit] Fails a test with the given message.

See also:
http://junit.sourceforge.net/javadoc/junit/framework/Assert.html#fail(java.lang.String)

#define TEST_EQUAL expected,
actual   )     testThis( (expected) == (actual), #expected " == " #actual, __FILE__, __LINE__ )
 

[ADH_test] Efectúa la prueba para determinar si expected == actual.

#define TEST_EQUAL_Msg MSG,
expected,
actual   )     testThis( (expected) == (actual), MSG, __FILE__, __LINE__ )
 

[ADH_test] Efectúa la prueba para determinar si expected == actual.

  • Si la prueba tiene éxito invoca el método TestCase::recordSuccess()
  • Si la prueba falla invoca el método TestCase::recordFail()
  • Esta es una una macro que invoca el método TestCase::testThis()
  • Registra el mensaje MSG si la prueba falla.

#define TEST_ERROR str   )     recordError( str, __FILE__, __LINE__ )
 

[ADH_test] Registra como "error" el resultado de una prueba.

  • El programador cliente es quien determinó que la prueba falló y por eso quiere registrar ese hecho.
  • Está implementado comun una macro que invoca el método TestCase::recordError()

      if (22==33) {
          TEST_ERROR("22 != 33"); // Registra que la prueba falló
      }

 
#define TEST_SUCCESS  )     recordSuccess()
 

[ADH_test] Registra como "exitoso" el resultado de una prueba.

  • El programador cliente es quien determinó que la prueba fue exitosa y por eso quiere registrar ese hecho.
  • Generalmente se usa después de atrapar una excepción que se supone debió ser lanzada como resultado de la prueba.
  • Está implementado comun una macro que invoca el método TestCase::recordSuccess()

      queue<T> Q(SIZE); // la cola "Q" está vacía ==> no tiene "front()"
      try {
          Q.front();  // Es incorrecto usar un valor de la cola si la cola está vacía
          TEST_ERROR("Q.front();"); // Fallaría si "front()" no levanta la excepción
       }
       catch (std::logic_error&) {
          TEST_SUCCESS(); // Esto es lo correcto pues "front()" levanta "logic_error" para unca cola vacía
      }

#define TEST_THIS cond   )     testThis( cond, #cond, __FILE__, __LINE__ )
 

[ADH_test] Efectúa la prueba cond y registra el resultado.

  • Si la prueba cond tiene éxito invoca el método TestCase::recordSuccess()
  • Si la prueba cond falla invoca el método TestCase::recordFail()
  • Esta es una una macro que invoca el método TestCase::testThis()
          TEST_THIS("0 != 1"); // Siempre tiene éxito
          testThis(0 != 1, "0 != 1", __FILE__, __LINE__ ); // Siempre tiene éxito
    

#define TEST_THIS_Msg msg,
cond   )     testThis( cond, msg, __FILE__, __LINE__ )
 

[ADH_test] Macro similar a TEST_THIS() que usa el mensaje msg en caso de falla.

  • El mensaje msg debe ser una hilera literal o un objeto que pueda convertirse en const char *


Function Documentation

std::ostream& operator<< std::ostream &  COUT,
const TestCase test
 

Operación de grabado que permite reportar el resultado de la prueba test.

  • Graba en COUT el nombre, cantidad de éxitos y cantidad de errores.

long Report std::ostream &  COUT,
const TestCase test
[inline]
 

Graba en "COUT" el resultado de la prueba test.

  • Retorna la cantidad total de errores test.nError().
  • Además, graba la cantidad de pruebas exitosas y erróneas.
  • Si hubo pruebas no exitosas, graba los mensajes de error correspondientes.

template<class T>
std::string toString const T &  val  ) 
 

Retorna una hilera que contiene el valor de val.


Generated on Tue Aug 21 16:47:52 2007 by  doxygen 1.4.1
Hosted by www.Geocities.ws

1