[B]asic module for [unit] program testing:
|
00001 // test1.cpp (C) 2007 adolfo@di-mare.com 00002 00003 /** \file test1.cpp 00004 \brief Muestra de uso de \c assertTrue_Msg(). 00005 00006 \author Adolfo Di Mare <adolfo@di-mare.com> 00007 \date 2007 00008 */ 00009 00010 #include "BUnit.h" // 1. Agregrar #include "BUnit.h" 00011 00012 /// Muestra de uso de \c assertTrue_Msg(). 00013 class test1 : public TestCase { // #2. Derivar de TestCase 00014 enum { N = 2 }; 00015 int m_Matrix[N][N]; 00016 public: 00017 void setUp() { 00018 for ( int i=0; i<N; ++i ) { 00019 for ( int j=0; j<N; ++j ) { 00020 m_Matrix[i][j] = 0; 00021 } 00022 } 00023 } 00024 bool run() { 00025 for ( int i=0; i<N; ++i ) { 00026 for ( int j=0; j<N; ++j ) { 00027 std::string fail = "m_Matrix"; 00028 fail += '[' + TestCase::toString(i) + ']'; 00029 fail += '[' + TestCase::toString(j) + ']'; 00030 fail += " == 0"; // #3 Invocar assertTrue() 00031 assertTrue_Msg( fail , m_Matrix[i][j] == 0 ); 00032 } 00033 } 00034 return wasSuccessful(); 00035 } 00036 }; 00037 00038 #include <iostream> // cout 00039 00040 /// Programa principal que ejecuta la prueba. 00041 int main() { 00042 test1 tester; 00043 tester.run(); // #4 run(): Ejecutar las pruebas 00044 if ( ! tester.wasSuccessful() ) { 00045 std::cout << tester.report(); 00046 } 00047 00048 tester.reset(); 00049 tester.runBare(); 00050 std::cout << tester.summary(); 00051 return 0; 00052 } 00053 00054 /* 00055 TestCase [class test1] (OK: 0) (FAIL: 4) 00056 =\_fail: m_Matrix[0][0] == 0 00057 =/ (31) X:\DIR\SubDir\test1.cpp 00058 =\_fail: m_Matrix[0][1] == 0 00059 =/ (31) X:\DIR\SubDir\test1.cpp 00060 =\_fail: m_Matrix[1][0] == 0 00061 =/ (31) X:\DIR\SubDir\test1.cpp 00062 =\_fail: m_Matrix[1][1] == 0 00063 =/ (31) X:\DIR\SubDir\test1.cpp 00064 TestCase [class test1] (OK: 4) (FAIL: 0) 00065 */ 00066 00067 // EOF: test1.cpp