EPICS ARCHIVER V4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups
UnitTest.h
1 // -*- c++ -*-
2 
3 // Simple Unit-Test Framework.
4 //
5 // makeUnitTestMain.pl parses current directory,
6 // creating UnitTest.cpp test suite and
7 // UnitTest.mk makefile snippet.
8 //
9 // See Tools/*Test.cpp for example test cases
10 // and Tools/Makefile for how to build and run.
11 
12 #include <stdio.h>
13 
14 typedef bool TEST_CASE;
15 
16 #define COMMENT(msg) \
17  printf(" ----- %s\n", msg);
18 
19 #define FAIL(msg) \
20  { \
21  printf(" FAIL: %s\n", msg); \
22  return false; \
23  }
24 
25 #define PASS(msg) \
26  printf(" OK : %s\n", msg);
27 
28 #define TEST(t) \
29  if (t) \
30  printf(" OK : %s\n", #t); \
31  else \
32  { \
33  printf(" FAIL: %s\n", #t); \
34  return false; \
35  }
36 
37 #define TEST_MSG(t,msg) \
38  if (t) \
39  printf(" OK : %s\n", msg); \
40  else \
41  { \
42  printf(" FAIL: %s\n", msg); \
43  return false; \
44  }
45 
46 // Deletes the given file.
47 bool test_delete_file(const char *filename);
48 
49 #define TEST_DELETE_FILE(file) \
50  if (test_delete_file(file)) \
51  printf(" OK : '%s' was removed\n", file); \
52  else \
53  { \
54  printf(" FAIL: cannot remove file '%s'\n", file); \
55  return false; \
56  }
57 
58 
59 // Runs 'diff', returns true when files match.
60 bool test_filediff(const char *filename1, const char *filename2);
61 
62 #define TEST_FILEDIFF(file1,file2) \
63  if (test_filediff(file1,file2)) \
64  printf(" OK : '%s' and '%s' match\n", file1, file2); \
65  else \
66  { \
67  printf(" FAIL: diff %s %s\n", file1, file2); \
68  return false; \
69  }
70 
71 #define TEST_OK return true
72