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

Last change on this file since 44 was 44, checked in by rosiere, 17 years ago

Modification des classes d'encapsulation des interfaces.
Stable sur tous les composants actuels

File size: 1.1 KB
Line 
1#ifndef TEST_H
2#define TEST_H
3
4#include <iostream>
5#include <sstream>
6#include <stdint.h>
7#include "Common/include/ErrorMorpheo.h"
8using namespace std;
9
10//-----[ Routine de test ]---------------------------------------
11
12static uint32_t num_test;
13
14template <class T>
15void test_ko (T exp1, T exp2, char * file, uint32_t line)
16{
17  string msg = ("<"+toString(num_test)+"> : Test KO\n" +
18                " * Localisation\n"                    +
19                "   - File : "+file+"\n"               +
20                "   - Line : "+toString(line)+"\n"     +
21                " * Expression is different\n"         +
22                "   - exp1 : "+toString(exp1)+"\n"     +
23                "   - exp2 : "+toString(exp2)+"\n");
24 
25  throw (ErrorMorpheo (msg));
26};
27
28void test_ok ()
29{
30  cout << "{" << num_test << "} : Test OK" << endl;
31
32  num_test ++;
33};
34
35template <class T>
36void test(T exp1, T exp2, char * file, uint32_t line)
37{
38  if (exp1 != exp2)
39    test_ko <T> (exp1,exp2,file,line);
40  else
41    test_ok     ();
42};
43
44#define TEST(type,exp1,exp2)            do {                      test<type> (exp1,exp2,__FILE__,__LINE__);} while(0)
45#define TEST_STR(type,exp1,exp2,str...) do { fprintf(stdout,str); test<type> (exp1,exp2,__FILE__,__LINE__);} while(0)
46
47#endif
Note: See TracBrowser for help on using the repository browser.