Changeset 12384
- Timestamp:
- Mar 9, 2007, 12:09:13 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/pstap/src/pstap.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/pstap/src/pstap.h
r12383 r12384 12 12 # define checkMem() if(checkLeaks) mem() 13 13 14 # ifdef __GNUC__ 14 // write a comment which is counted as a test (and swallowed by prove) 15 # define note(...)\ 16 { \ 17 fprintf(stdout, __VA_ARGS__); \ 18 fprintf(stdout, "\n[%s:%d in %s]\n", __FILE__, __LINE__, __func__); \ 19 } 15 20 16 // write a comment which is counted as a test (and swallowed by prove) 17 # define note(A, ...){ \ 18 fprintf(stdout, A, ## __VA_ARGS__); \ 19 fprintf(stdout, "\n[%s:%d in %s]\n", __FILE__, __LINE__, __func__); } 20 // write a comment which is counted as a test (and swallowed by prove) 21 # define noted(A, ...) _gen_result(1, __func__, __FILE__, __LINE__, A, ## __VA_ARGS__); 21 # define noted(...) _gen_result(1, __func__, __FILE__, __LINE__, __VA_ARGS__); 22 22 23 23 // use to test the value of a float 24 # define ok_float(VALUE,EXPECT,COMMENT, ...)\ 25 ok((fabsf((VALUE)-(EXPECT)) < FLT_EPSILON), COMMENT, ## __VA_ARGS__); 24 # define ok_float(VALUE, EXPECT, ...)\ 25 { \ 26 bool status = (fabsf(VALUE - EXPECT) < FLT_EPSILON); \ 27 ok(status, __VA_ARGS__); \ 28 if (!status) { \ 29 diag(" got: '%f'", VALUE); \ 30 diag(" expected: '%f'", EXPECT); \ 31 } \ 32 } 26 33 27 // use to test the value of a double28 # define ok_double(VALUE,EXPECT,COMMENT, ...)\29 ok((fabs((VALUE)-(EXPECT)) < DBL_EPSILON), COMMENT, ## __VA_ARGS__);30 34 31 35 // use to test the value of a float within a defined tolerance 32 # define ok_float_tol(VALUE,EXPECT,TOL, COMMENT,...)\36 # define ok_float_tol(VALUE,EXPECT,TOL,...)\ 33 37 { \ 34 38 bool status = (fabsf((VALUE) - (EXPECT)) < (TOL)); \ 35 ok(status, COMMENT, ##__VA_ARGS__); \39 ok(status, __VA_ARGS__); \ 36 40 if (!status) { \ 37 41 diag(" got: '%f'", VALUE); \ … … 40 44 } 41 45 42 // use to test the value of a double within a defined tolerance43 # define ok_double _tol(VALUE,EXPECT,TOL,COMMENT,...)\46 // use to test the value of a double 47 # define ok_double(VALUE,EXPECT,...)\ 44 48 { \ 45 bool status = (fabs( (VALUE) - (EXPECT)) < (TOL)); \46 ok(status, COMMENT, ##__VA_ARGS__); \49 bool status = (fabs(VALUE - EXPECT) < DBL_EPSILON); \ 50 ok(status, __VA_ARGS__); \ 47 51 if (!status) { \ 48 52 diag(" got: '%f'", VALUE); \ 49 diag(" expected: '%f' +/- %f", EXPECT, TOL); \53 diag(" expected: '%f'", EXPECT); \ 50 54 } \ 51 55 } 52 53 # define ok_str(VALUE, EXPECT, COMMENT, ...) \54 { \55 int cmp = (strcmp(VALUE, EXPECT) == 0); \56 ok(cmp, COMMENT, ## __VA_ARGS__); \57 if (!cmp) { \58 diag(" got: '%s'", VALUE); \59 diag(" expected: '%s'", EXPECT); \60 } \61 }62 63 # define ok_strn(VALUE, EXPECT, N, COMMENT, ...)\64 { \65 int cmp = (strncmp(VALUE, EXPECT, N) == 0); \66 ok(cmp, COMMENT, ## __VA_ARGS__); \67 if (!cmp) { \68 diag(" got: '%s'", VALUE); \69 diag(" expected: '%s'", EXPECT); \70 } \71 }72 73 #elif __STDC_VERSION__ >= 199901L /* __GNUC__ */74 75 // write a comment which is counted as a test (and swallowed by prove)76 // write a comment which is counted as a test (and swallowed by prove)77 # define note(A, ...){ \78 fprintf(stdout, A, ...); \79 fprintf(stdout, "\n[%s:%d in %s]\n", __FILE__, __LINE__, __func__); }80 81 // use to test the value of a float82 # define ok_float(VALUE,EXPECT, ...)\83 ok((fabsf((VALUE)-(EXPECT)) < FLT_EPSILON), __VA_ARGS__);84 85 // use to test the value of a double86 # define ok_double(VALUE,EXPECT, ...)\87 ok((fabs((VALUE)-(EXPECT)) < DBL_EPSILON), __VA_ARGS__);88 56 89 57 // use to test the value of a float … … 112 80 { \ 113 81 int cmp = (strcmp(VALUE, EXPECT) == 0); \ 114 ok(cmp, COMMENT,__VA_ARGS__); \82 ok(cmp, __VA_ARGS__); \ 115 83 if (!cmp) { \ 116 84 diag(" got: '%s'", VALUE); \ … … 122 90 { \ 123 91 int cmp = (strncmp(VALUE, EXPECT, N) == 0); \ 124 ok(cmp, COMMENT,__VA_ARGS__); \92 ok(cmp, __VA_ARGS__); \ 125 93 if (!cmp) { \ 126 94 diag(" got: '%s'", VALUE); \ … … 129 97 } 130 98 131 #else /* __STDC_VERSION__ */ 132 # error "Needs gcc or C99 compiler for variadic macros." 133 #endif /* __STDC_VERSION__ */ 99 # define is_int(VALUE, EXPECT, ...)\ 100 { \ 101 int cmp = (VALUE == EXPECT); \ 102 ok(cmp, __VA_ARGS__); \ 103 if (!cmp) { \ 104 diag(" got: '%d'", VALUE); \ 105 diag(" expected: '%d'", EXPECT); \ 106 } \ 107 } 108 109 # define is_long(VALUE, EXPECT, ...)\ 110 { \ 111 int cmp = (VALUE == EXPECT); \ 112 ok(cmp, __VA_ARGS__); \ 113 if (!cmp) { \ 114 diag(" got: '%ld'", VALUE); \ 115 diag(" expected: '%ld'", EXPECT); \ 116 } \ 117 }
Note:
See TracChangeset
for help on using the changeset viewer.
