IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12384 for trunk/psLib


Ignore:
Timestamp:
Mar 9, 2007, 12:09:13 PM (19 years ago)
Author:
jhoblitt
Message:

define macros only once
add is_int() & is_long() macros

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/pstap/src/pstap.h

    r12383 r12384  
    1212# define checkMem() if(checkLeaks) mem()
    1313
    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}
    1520
    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__);
    2222
    2323// 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}
    2633
    27 // use to test the value of a double
    28 # define ok_double(VALUE,EXPECT,COMMENT, ...)\
    29 ok((fabs((VALUE)-(EXPECT)) < DBL_EPSILON), COMMENT, ## __VA_ARGS__);
    3034
    3135// 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,...)\
    3337{ \
    3438    bool status = (fabsf((VALUE) - (EXPECT)) < (TOL)); \
    35     ok(status, COMMENT, ## __VA_ARGS__); \
     39    ok(status, __VA_ARGS__); \
    3640    if (!status) { \
    3741        diag("         got: '%f'", VALUE); \
     
    4044}
    4145
    42 // use to test the value of a double within a defined tolerance
    43 # define ok_double_tol(VALUE,EXPECT,TOL,COMMENT, ...)\
     46// use to test the value of a double
     47# define ok_double(VALUE,EXPECT,...)\
    4448{ \
    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__); \
    4751    if (!status) { \
    4852        diag("         got: '%f'", VALUE); \
    49         diag("    expected: '%f' +/- %f", EXPECT, TOL); \
     53        diag("    expected: '%f'", EXPECT); \
    5054    } \
    5155}
    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 float
    82 # define ok_float(VALUE,EXPECT, ...)\
    83 ok((fabsf((VALUE)-(EXPECT)) < FLT_EPSILON), __VA_ARGS__);
    84 
    85 // use to test the value of a double
    86 # define ok_double(VALUE,EXPECT, ...)\
    87 ok((fabs((VALUE)-(EXPECT)) < DBL_EPSILON), __VA_ARGS__);
    8856
    8957// use to test the value of a float
     
    11280{ \
    11381    int cmp = (strcmp(VALUE, EXPECT) == 0); \
    114     ok(cmp, COMMENT,  __VA_ARGS__); \
     82    ok(cmp, __VA_ARGS__); \
    11583    if (!cmp) { \
    11684        diag("         got: '%s'", VALUE); \
     
    12290{ \
    12391    int cmp = (strncmp(VALUE, EXPECT, N) == 0); \
    124     ok(cmp, COMMENT,  __VA_ARGS__); \
     92    ok(cmp, __VA_ARGS__); \
    12593    if (!cmp) { \
    12694        diag("         got: '%s'", VALUE); \
     
    12997}
    13098
    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.