Changeset 425

Show
Ignore:
Timestamp:
07/22/09 14:57:26 (15 years ago)
Author:
vbarta
Message:

moved logger test to testsuite, updated logger docs (a bit)

Location:
library
Files:
3 added
4 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/base/loggers.h

    r387 r425  
    2121 
    2222/*! 
    23 * \brief Logging into matrices in data format in memory 
    24  
    25 * More?... 
    26 */ 
    27  
     23 * Logging into matrices in data format in memory, optionally persisted into a file. 
     24 */ 
    2825class memlog : public logger { 
    2926 
     
    7168        \code 
    7269        logger = { 
    73                 type = "itpplog"; 
     70                class = "memlog"; 
    7471                filename = "file_name.it"; // resulting filename with results in it format 
    7572                maxlen = 100;          // size of memory buffer 
     
    115112        void write_buffers ( int Len ); 
    116113 
    117         // TODO dokumentace - aktualizovat 
    118114        /*! \brief UI for dirfilelog (Kst file format)  
    119115        \code 
    120116        logger = { 
    121                 type = "dirfilelog"; 
    122                 dirmane = "directory_for_files"; // resulting files will be stored there 
     117                class = "dirfilelog"; 
     118                dirname = "directory_for_files"; // resulting files will be stored there 
    123119                maxlen = 100;                    // size of memory buffer, when full results are written to disk 
    124120        } 
  • library/tests/CMakeLists.txt

    r424 r425  
    99# Add executable called "helloDemo" that is built from the source files 
    1010# "demo.cxx" and "demo_b.cxx".  The extensions are automatically found. 
    11  
    12 # BASIC EXECS 
    13 EXEC(loggers_test) 
    1411 
    1512EXEC(chmat_test) 
     
    4037 
    4138# using UnitTest++ 
    42 add_executable(testsuite datalink_test.cpp rv_test.cpp testsuite.cpp test_user_info.cpp test_shared_ptr.cpp) 
     39add_executable(testsuite datalink_test.cpp loggers_test.cpp rv_test.cpp testsuite.cpp test_user_info.cpp test_util.cpp test_util.h test_shared_ptr.cpp) 
    4340target_link_libraries(testsuite bdm itpp unittest) 
    4441 
  • library/tests/loggers_test.cpp

    r386 r425  
    1  
     1#define BDMLIB // not an ideal way to prevent double registration of UI factories... 
    22#include "base/loggers.h" 
     3#include "test_util.h" 
     4#include "UnitTest++.h" 
     5#include <string> 
     6#include <sys/stat.h> 
     7#include <sys/types.h> 
    38 
    49using namespace bdm; 
    510 
    6 //These lines are needed for use of cout and endl 
    7 using std::cout; 
    8 using std::endl; 
     11TEST(test_dirfilelog) 
     12{ 
     13    RV th = RV("{alog blog }"); 
     14    RV r = RV("{r }", "2"); 
    915 
    10 int main() 
    11 { 
    12         int i; 
    13          
    14         RV th = RV ( "{a b }"); 
    15         RV r = RV ( "{r }","2"); 
     16    if (mkdir("exp", 0777)) { 
     17        remove_all("exp/dirfile"); 
     18    } 
    1619 
    17         dirfilelog L("exp/dirfile",10); 
    18          
    19         int rid; 
    20         int thid; 
    21          
    22         rid=L.add(r,""); 
    23         thid=L.add(th,"th"); 
    24          
    25         L.init(); 
     20    dirfilelog L("exp/dirfile", 10); 
    2621 
    27         for (i=0; i<150; i++){   
    28                 L.logit(rid,vec_2((double)i,(double)(i+1))); 
    29                 L.logit(thid,vec_2((double)(100-i),(double)(i-50))); 
    30                 L.step(); 
    31         } 
    32         L.finalize(); 
     22    int rid; 
     23    int thid; 
     24 
     25    rid = L.add(r, ""); 
     26    thid = L.add(th, "th"); 
     27 
     28    L.init(); 
     29 
     30    for (int i = 0; i < 150; i++) { 
     31            L.logit(rid, vec_2((double)i, (double)(i + 1))); 
     32            L.logit(thid, vec_2((double)(100 - i), (double)(i - 50))); 
     33            L.step(); 
     34    } 
     35 
     36    L.finalize(); 
     37 
     38    std::string expected(load_test_file("dirfile-format.matrix")); 
     39    std::string actual(load_test_file("exp/dirfile/format")); 
     40    CHECK_EQUAL(expected, actual); 
    3341} 
  • library/tests/test_user_info.cpp

    r418 r425  
    1 #include <fstream> 
    21#include <memory> 
    32#include <string> 
    43#include <string.h> 
    54#include "base/user_info.h" 
     5#include "test_util.h" 
    66#include "UnitTest++.h" 
    77 
     
    196196UIREGISTER(Bike); 
    197197 
    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. 
    201 string 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  
    210198TEST(test_load) 
    211199{