2012-08-18 16:07:05 +00:00
|
|
|
/* Note VERBOSE needs to be (un)defined before including this file */
|
|
|
|
|
|
|
|
#ifndef LIBTRANSMISSION_TEST_H
|
|
|
|
#define LIBTRANSMISSION_TEST_H 1
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
#include "utils.h" /* tr_strcmp0 () */
|
2012-08-18 16:07:05 +00:00
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
extern int current_test;
|
2012-10-14 17:59:24 +00:00
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
extern bool verbose;
|
2012-10-14 17:59:24 +00:00
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
bool should_print (bool pass);
|
2012-10-14 17:59:24 +00:00
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
bool check_condition_impl (const char * file, int line, bool condition);
|
|
|
|
bool check_int_eq_impl (const char * file, int line, int64_t expected, int64_t actual);
|
|
|
|
bool check_ptr_eq_impl (const char * file, int line, const void * expected, const void * actual);
|
|
|
|
bool check_streq_impl (const char * file, int line, const char * expected, const char * actual);
|
2012-12-10 01:24:50 +00:00
|
|
|
|
2012-10-14 17:59:24 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
#define check(condition) \
|
|
|
|
do { \
|
|
|
|
++current_test; \
|
|
|
|
if (!check_condition_impl (__FILE__, __LINE__, (condition))) \
|
|
|
|
return current_test; \
|
2012-12-05 17:29:46 +00:00
|
|
|
} while (0)
|
2012-10-14 17:59:24 +00:00
|
|
|
|
|
|
|
#define check_streq(expected, actual) \
|
|
|
|
do { \
|
|
|
|
++current_test; \
|
|
|
|
if (!check_streq_impl (__FILE__, __LINE__, (expected), (actual))) \
|
|
|
|
return current_test; \
|
2012-12-05 17:29:46 +00:00
|
|
|
} while (0)
|
2012-10-14 17:59:24 +00:00
|
|
|
|
|
|
|
#define check_int_eq(expected, actual) \
|
|
|
|
do { \
|
|
|
|
++current_test; \
|
2012-12-10 01:24:50 +00:00
|
|
|
if (!check_int_eq_impl (__FILE__, __LINE__, (expected), (actual))) \
|
|
|
|
return current_test; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define check_ptr_eq(expected, actual) \
|
|
|
|
do { \
|
|
|
|
++current_test; \
|
|
|
|
if (!check_ptr_eq_impl (__FILE__, __LINE__, (expected), (actual))) \
|
2012-10-14 17:59:24 +00:00
|
|
|
return current_test; \
|
|
|
|
} while (0)
|
2012-08-18 16:07:05 +00:00
|
|
|
|
2012-10-14 17:59:24 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
2012-08-18 16:07:05 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
typedef int (*testFunc)(void);
|
|
|
|
#define NUM_TESTS(tarray)((int)(sizeof (tarray)/sizeof (tarray[0])))
|
2012-08-18 16:07:05 +00:00
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
int runTests (const testFunc * const tests, int numTests);
|
2012-08-18 16:07:05 +00:00
|
|
|
|
2012-10-14 17:59:24 +00:00
|
|
|
#define MAIN_SINGLE_TEST(test) \
|
2012-12-05 17:29:46 +00:00
|
|
|
int main (void) { \
|
2012-10-14 17:59:24 +00:00
|
|
|
const testFunc tests[] = { test }; \
|
2012-12-05 17:29:46 +00:00
|
|
|
return runTests (tests, 1); \
|
2012-08-18 16:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !LIBTRANSMISSION_TEST_H */
|