14 #define _CU_TESTER_H 1
19 #define MAX_CUNIT_ERROR_LENGTH 512
21 #define PG_ADD_TEST(suite, testfunc) CU_add_test(suite, #testfunc, testfunc)
32 #define ASSERT_DOUBLE_EQUAL(o,e) do { \
34 fprintf(stderr, "[%s:%d]\n Expected: %g\n Obtained: %g\n", __FILE__, __LINE__, (double)(e), (o)); \
35 CU_ASSERT_EQUAL(o,(double)e); \
38 #define ASSERT_DOUBLE_EQUAL_TOLERANCE(o,e,t) do { \
39 if ( fabs(o-e) > t ) \
40 fprintf(stderr, "[%s:%d]\n Expected: %g\n Obtained: %g\n Difference: %.15g\n Tolerated: %.15g\n", __FILE__, __LINE__, (double)(e), (o), fabs((o)-(e)), (t)); \
41 CU_ASSERT_DOUBLE_EQUAL(o,e,t); \
44 #define ASSERT_INT_EQUAL(o,e) do { \
46 fprintf(stderr, "[%s:%d]\n Expected: %d\n Obtained: %d\n", __FILE__, __LINE__, (e), (o)); \
47 CU_ASSERT_EQUAL(o,e); \
50 #define ASSERT_NORMALIZED_GEOM_SAME(gobt, gexp) \
54 LWGEOM *ngobt, *ngexp; \
55 ngobt = lwgeom_normalize(gobt); \
56 ngexp = lwgeom_normalize(gexp); \
57 if (!lwgeom_same((ngobt), (ngexp))) \
59 obt = lwgeom_to_wkt((ngobt), WKT_ISO, 8, NULL); \
60 exp = lwgeom_to_wkt((ngexp), WKT_ISO, 8, NULL); \
61 fprintf(stderr, "[%s:%d]\n Expected: %s\n Obtained: %s\n", __FILE__, __LINE__, exp, obt); \
79 CU_BOOL error = (!obtained && expected) || (obtained && !expected) || (strcmp(obtained, expected) != 0);
83 msg =
lwalloc(60 + (obtained ? strlen(obtained) : 4) + (expected ? strlen(expected) : 4));
85 "ASSERT_STRING_EQUAL\n\t* Expected: %s\n\t* Obtained: %s",
86 expected ? expected :
"NULL",
87 obtained ? obtained :
"NULL");
89 CU_assertImplementation(!error, line, msg, file, NULL, CU_FALSE);
94 #define ASSERT_STRING_EQUAL(o, e) assert_string_equal_impl(o, e, __FILE__, __LINE__)
96 #define ASSERT_VARLENA_EQUAL(v, s) \
99 if (strncmp(v->data, s, LWSIZE_GET(v->size) - LWVARHDRSZ) != 0) \
102 stderr, "[%s:%d]\n Expected: %s\n Obtained: %s\n", __FILE__, __LINE__, (s), (v->data)); \
109 #define ASSERT_LWGEOM_EQUAL(o, e) do { \
110 if ( !lwgeom_same(o, e) ) { \
111 char* wkt_o = lwgeom_to_ewkt(o); \
112 char* wkt_e = lwgeom_to_ewkt(e); \
113 fprintf(stderr, "[%s:%d]\n Expected: %s\n Obtained: %s\n", __FILE__, __LINE__, (wkt_o), (wkt_e)); \
117 CU_ASSERT_TRUE(lwgeom_same(o, e)); \
120 #define ASSERT_INTARRAY_EQUAL(o, e, n) do { \
122 for (i = 0; i < n; i++) { \
123 if (o[i] != e[i]) { \
124 fprintf(stderr, "[%s:%d]", __FILE__, __LINE__); \
125 fprintf(stderr, "\nExpected: ["); \
126 for (i = 0; i < n; i++) \
127 fprintf(stderr, " %d", e[i]); \
128 fprintf(stderr, " ]\nObtained: ["); \
129 for (i = 0; i < n; i++) \
130 fprintf(stderr, " %d", o[i]); \
131 fprintf(stderr, " ]\n"); \
139 #define ASSERT_POINT2D_EQUAL(o, e, eps) do { \
140 CU_ASSERT_DOUBLE_EQUAL(o.x, e.x, eps); \
141 CU_ASSERT_DOUBLE_EQUAL(o.y, e.y, eps); \
144 #define ASSERT_POINT4D_EQUAL(o, e, eps) do { \
145 CU_ASSERT_DOUBLE_EQUAL(o.x, e.x, eps); \
146 CU_ASSERT_DOUBLE_EQUAL(o.y, e.y, eps); \
147 CU_ASSERT_DOUBLE_EQUAL(o.z, e.z, eps); \
148 CU_ASSERT_DOUBLE_EQUAL(o.m, e.m, eps); \
void(* PG_SuiteSetup)(void)
void do_fn_test(LWGEOM *(*transfn)(LWGEOM *), char *input_wkt, char *expected_wkt)
static void assert_string_equal_impl(const char *obtained, const char *expected, const char *file, int line)
void cu_error_msg_reset(void)
void * lwalloc(size_t size)
This library is the generic geometry handling section of PostGIS.