#include <pslib.h>

#include "tap.h"

#define done() ok(psMemCheckLeaks(0, NULL, stdout, false) == 0, "Memory Leaks"); \
return exit_status()

       # define mem() ok(psMemCheckLeaks(psMemGetLastId(), NULL, stdout, false) == 0, "Memory Leaks")

       # define checkLeaks false

       # define checkMem() if(checkLeaks) mem()

           # ifdef __GNUC__

           // use to test the value of a float
           # define ok_float(VALUE,EXPECT,COMMENT, ...)\
           ok((fabs((VALUE)-(EXPECT)) < FLT_EPSILON), COMMENT, ## __VA_ARGS__);

// use to test the value of a double
# define ok_double(VALUE,EXPECT,COMMENT, ...)\
ok((fabsl((VALUE)-(EXPECT)) < DBL_EPSILON), COMMENT, ## __VA_ARGS__);

// use to test the value of a float within a defined tolerance
# define ok_float_tol(VALUE,EXPECT,TOL,COMMENT, ...)\
ok((fabs((VALUE)-(EXPECT)) < (TOL)), COMMENT, ## __VA_ARGS__);

// use to test the value of a double within a defined tolerance
# define ok_double_tol(VALUE,EXPECT,TOL,COMMENT, ...)\
ok((fabsl((VALUE)-(EXPECT)) < (TOL)), COMMENT, ## __VA_ARGS__);

# define ok_str(VALUE, EXPECT, COMMENT, ...) \
{ \
    int cmp = (strcmp(VALUE, EXPECT) == 0); \
    ok(cmp, COMMENT, ## __VA_ARGS__); \
    if (!cmp) { \
        diag("         got: '%s'", VALUE); \
        diag("    expected: '%s'", EXPECT); \
    } \
}

# define ok_strn(VALUE,EXPECT,N,COMMENT, ...)\
ok(strncmp(VALUE, EXPECT, N) == 0, COMMENT, ## __VA_ARGS__);

#elif __STDC_VERSION__ >= 199901L /* __GNUC__ */

// use to test the value of a float
# define ok_float(VALUE,EXPECT, ...)\
ok((fabs((VALUE)-(EXPECT)) < FLT_EPSILON), __VA_ARGS__);

// use to test the value of a double
# define ok_double(VALUE,EXPECT, ...)\
ok((fabsl((VALUE)-(EXPECT)) < DBL_EPSILON), __VA_ARGS__);

// use to test the value of a float
# define ok_float_tol(VALUE,EXPECT,TOL, ...)\
ok((fabs((VALUE)-(EXPECT)) < (TOL)), __VA_ARGS__);

// use to test the value of a double
# define ok_double_tol(VALUE,EXPECT,TOL, ...)\
ok((fabsl((VALUE)-(EXPECT)) < )(TOL)), __VA_ARGS__);

# define ok_str(VALUE, EXPECT, COMMENT, ...) \
{ \
    int cmp = (strcmp(VALUE, EXPECT) == 0); \
    ok(cmp, COMMENT,  __VA_ARGS__); \
    if (!cmp) { \
        diag("         got: '%s'", VALUE); \
        diag("    expected: '%s'", EXPECT); \
    } \
}

# define ok_strn(VALUE,EXPECT,N, ...)\
ok(strncmp(VALUE, EXPECT, N) == 0, __VA_ARGS__);

#else /* __STDC_VERSION__ */
# error "Needs gcc or C99 compiler for variadic macros."
#endif /* __STDC_VERSION__ */
