1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#ifndef TESTTOOL_H_INCLUDED
#define TESTTOOL_H_INCLUDED
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#ifdef _WIN32
# include <winsock2.h>
# include <ws2tcpip.h>
#else
#include <netinet/in.h>
#endif
#include "xmlrpc-c/util.h"
#include "xmlrpc-c/util_int.h"
extern int total_tests;
extern int total_failures;
void
test_failure(const char * const file,
unsigned int const line,
const char * const label,
const char * const statement);
void
test_fault(xmlrpc_env * const envP,
int const expectedCode,
const char * const fileName,
unsigned int const lineNumber);
void
test_null_string(const char * const string,
const char * const fileName,
unsigned int const lineNumber);
#define TEST(statement) \
do { \
++total_tests; \
if ((statement)) { \
printf("."); \
} else { \
test_failure(__FILE__, __LINE__, "expected", #statement); \
} \
} while (0)
#define TEST_NO_FAULT(env) \
do { \
++total_tests; \
if (!(env)->fault_occurred) { \
printf("."); \
} else { \
test_failure(__FILE__, __LINE__, "fault occurred", \
(env)->fault_string); \
} \
} while (0)
#define TEST_EPSILON 1E-5
#define FORCENONZERO(x) (MAX(fabs(x), TEST_EPSILON))
#define FLOATEQUAL(comparand, comparator) \
((fabs((comparand)-(comparator)))/FORCENONZERO(comparand) < TEST_EPSILON)
#define TESTFLOATEQUAL(comparand, comparator) \
TEST(FLOATEQUAL(comparand, comparator))
#define TEST_FAULT(envP, code) \
do { test_fault(envP, code, __FILE__, __LINE__); } while(0)
;
#define TEST_NULL_STRING(string) \
do { test_null_string(string, __FILE__, __LINE__); } while(0)
;
#define TEST_ERROR(reason) \
do { \
printf("Unable to test at %s/%u. %s", __FILE__, __LINE__, reason); \
abort(); \
} while (0)
;
struct in_addr
test_ipAddrFromDecimal(unsigned int const byte0,
unsigned int const byte1,
unsigned int const byte2,
unsigned int const byte3);
#endif
|