Changeset 418

Show
Ignore:
Timestamp:
07/16/09 16:06:48 (15 years ago)
Author:
vbarta
Message:

#27: added UnitTest?++ to bdm sources, changed test_user_data to use it

Location:
library/tests
Files:
53 added
2 modified

Legend:

Unmodified
Added
Removed
  • library/tests/CMakeLists.txt

    r394 r418  
    11# Make sure the compiler can find include files from our Bdm library. 
    22include_directories (${BDM_SOURCE_DIR}/bdm) 
     3include_directories (./unittest-cpp) 
    34 
    45# Make sure the linker can find the Hello library once it is built. 
    56link_directories (${BDM_BINARY_DIR}/bdm) 
     7link_directories (./unittest-cpp) 
    68 
    79# Add executable called "helloDemo" that is built from the source files 
     
    1214EXEC(datalink_test) 
    1315EXEC(loggers_test) 
    14 EXEC(test_user_info) 
    1516 
    1617EXEC(chmat_test) 
     
    4041EXEC(blas_test) 
    4142 
     43# using UnitTest++ 
     44add_executable(testsuite testsuite.cpp test_user_info.cpp) 
     45target_link_libraries(testsuite bdm itpp unittest) 
     46 
    4247add_subdirectory(tutorial) 
     48add_subdirectory(unittest-cpp) 
  • library/tests/test_user_info.cpp

    r394 r418  
    1  
     1#include <fstream> 
     2#include <memory> 
    23#include <string> 
     4#include <string.h> 
    35#include "base/user_info.h" 
    4  
    5 using std::string; 
     6#include "UnitTest++.h" 
     7 
    68using namespace std; 
    79using namespace bdm; 
     
    194196UIREGISTER(Bike); 
    195197 
    196 int main() 
    197 { 
    198   //////////////////////////////////// LOADING //////////////////////////////// 
     198// Non-general but simple file load - handles only files of limited 
     199// size which do not contain '\0' characters, but for testing that 
     200// should be enough. 
     201string load_test_file(const char *fname) 
     202{ 
     203    char buffer[8192]; 
     204    memset(buffer, 0, sizeof(buffer)); 
     205    ifstream src(fname, ios_base::binary); 
     206    src.read(buffer, sizeof(buffer) - 1); 
     207    return string(buffer); 
     208} 
     209 
     210TEST(test_load) 
     211{ 
    199212  UIFile in("test_user_info_input.cfg"); 
    200   Transport *pepikovo = UI::build<Transport>(in, "pepikovo"); 
    201   cout << "pepikovo: " << pepikovo->to_string() << endl; 
    202   Transport *jardovo = UI::build<Transport>(in, "jardovo"); 
    203   cout << "jardovo: " << jardovo->to_string() << endl; 
    204   Transport *ondrejovo = UI::build<Transport>(in, "ondrejovo"); 
    205   cout << "ondrejovo: " << ondrejovo->to_string() << endl; 
    206   Transport *elisky = UI::build<Transport>(in, "elisky"); 
    207   cout << "elisky: " << elisky->to_string() << endl; 
    208   Transport *kati = UI::build<Transport>(in, "kati"); 
    209   cout << "kati: " << kati->to_string() << endl; 
    210   cout << endl << "press any key to continue..." << endl; 
    211   getchar(); 
    212  
    213   /////////////////////////////////// SAVING ////////////////////////// 
     213  auto_ptr<Transport> pepikovo(UI::build<Transport>(in, "pepikovo")); 
     214  CHECK_EQUAL(string("A car made in 1998 by audi, having 25000 kilometers on the clock.The names of passengers are as follows: Karlos Novak -1_CygWin_Matlab_Aimsun Karlosik Novacek "), pepikovo->to_string()); 
     215 
     216  auto_ptr<Transport> jardovo(UI::build<Transport>(in, "jardovo")); 
     217  CHECK_EQUAL(string("A car made in 1992 by liaz, having 1555000 kilometers on the clock."), jardovo->to_string()); 
     218 
     219  auto_ptr<Transport> ondrejovo(UI::build<Transport>(in, "ondrejovo")); 
     220  CHECK_EQUAL(string("a bike made in 1996 by author with electric lights included"), ondrejovo->to_string()); 
     221 
     222  auto_ptr<Transport> elisky(UI::build<Transport>(in, "elisky")); 
     223  CHECK_EQUAL(string("A car made in 1992 by liaz, having 1555000 kilometers on the clock."), elisky->to_string()); 
     224 
     225  auto_ptr<Transport> kati(UI::build<Transport>(in, "kati")); 
     226  CHECK_EQUAL(string("A car made in 1980 by vecernicek, having 250000 kilometers on the clock."), kati->to_string()); 
     227} 
     228 
     229TEST(test_save) 
     230{ 
     231  UIFile in("test_user_info_input.cfg"); 
     232  auto_ptr<Transport> pepikovo(UI::build<Transport>(in, "pepikovo")); 
    214233 
    215234  Car audi(1968, "zyl", 200); 
     
    221240  UI::save(&liaz, out, "bohousovo"); 
    222241  UI::save(&author, out, "karlovo"); 
    223   UI::save(pepikovo, out, "pepikovo"); 
     242  UI::save(pepikovo.get(), out, "pepikovo"); 
    224243  out.save("testUI_out.cfg"); 
    225244 
    226   cout << "all the transport means were saved correctly" << endl; 
    227   cout << endl << "press any key to end the program" << endl; 
    228   getchar(); 
    229   return 0; 
     245  string expected(load_test_file("testUI_out.matrix")); 
     246  string actual(load_test_file("testUI_out.cfg")); 
     247  CHECK_EQUAL(expected, actual); 
    230248}