source: trunk/IPs/systemC/processor/Morpheo/Common/include/Test.h @ 75

Last change on this file since 75 was 75, checked in by rosiere, 16 years ago

Update all component (except front_end) to :

  • new statistics model
  • no namespace std
File size: 2.6 KB
RevLine 
[2]1#ifndef TEST_H
2#define TEST_H
3
4#include <iostream>
5#include <sstream>
6#include <stdint.h>
[71]7#include "Common/include/Message.h"
[44]8#include "Common/include/ErrorMorpheo.h"
[71]9#include "Common/include/ToString.h"
[2]10
[75]11namespace morpheo {
12
[2]13//-----[ Routine de test ]---------------------------------------
14
15static uint32_t num_test;
16
[71]17inline void test_ko_error (void)
[53]18{
[75]19  std::string msg = "Test ko : error in test \""+morpheo::toString(num_test)+"\"";
[71]20  throw (morpheo::ErrorMorpheo (msg));
[53]21}
22 
[2]23template <class T>
[71]24inline void test_ko (char * file, uint32_t line, T exp1, T exp2)
[2]25{
[75]26  std::cerr << "[" << num_test << "] : Test KO"
27       << "\tline " << line                           << std::endl
28       << " * Localisation"                           << std::endl
29       << "   - File : " << file                      << std::endl
30       << "   - Line : " << line                      << std::endl
31       << " * Expression is different"                << std::endl
32       << "   - exp1 : "+morpheo::toString(exp1)               << std::endl
33       << "   - exp2 : "+morpheo::toString(exp2)               << std::endl;
[53]34
35  test_ko_error ();
[2]36};
37
[71]38inline void test_ko (char * file, uint32_t line)
[50]39{
[75]40  std::cerr << "[" << num_test << "] : Test KO"
41       << "\tline " << line                           << std::endl
42       << " * Localisation"                           << std::endl
43       << "   - File : " << file                      << std::endl
44       << "   - Line : " << line                      << std::endl;
[50]45 
[53]46  test_ko_error ();
[50]47};
48
[71]49inline void test_ok ()
[2]50{
[71]51  msg (_("[%d] : Test OK\n"), num_test);
[2]52
53  num_test ++;
54};
55
[71]56inline void test_ok (char * file, uint32_t line)
[53]57{
[71]58  msg (_("[%d] : Test OK\n"), num_test);
59  msg (_("\tline %d\n"), line);
[53]60
61  num_test ++;
62};
63
[2]64template <class T>
[71]65inline void test_ok (char * file, uint32_t line, T exp)
[2]66{
[71]67  msg (_("[%d] : Test OK\n"), num_test);
68  msg (_("\tline %d\n"), line);
69  msg (_("\tvalue %s\n"), (morpheo::toString(exp)).c_str());
[53]70
71  num_test ++;
72}
73
74template <class T>
[71]75inline void test(char * file, uint32_t line, T exp1, T exp2)
[53]76{
[2]77  if (exp1 != exp2)
[53]78    test_ko <T> (file,line,exp1,exp2);
[2]79  else
[53]80    test_ok <T> (file,line,exp1);
[2]81};
82
[75]83#define TEST(type,exp1,exp2)            do {morpheo::test<type> (__FILE__,__LINE__,exp1,exp2);} while(0)
84#define TEST_STR(type,exp1,exp2,str...) do {fprintf(stdout,str); fprintf(stdout,"\n"); morpheo::test<type> (__FILE__,__LINE__,exp1,exp2);} while(0)
85#define TEST_OK(str...)                 do {fprintf(stdout,str); fprintf(stdout,"\n"); morpheo::test_ok(__FILE__,__LINE__);} while(0)
86#define TEST_KO(str...)                 do {fprintf(stdout,str); fprintf(stdout,"\n"); morpheo::test_ko(__FILE__,__LINE__);} while(0)
[2]87
[50]88
[75]89};
[2]90#endif
Note: See TracBrowser for help on using the repository browser.