PostGIS  2.4.9dev-r@@SVN_REVISION@@
liblwgeom/cunit/cu_tester.h
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * Copyright (C) 2009 Paul Ramsey <pramsey@cleverelephant.ca>
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU General Public Licence. See the COPYING file.
10  *
11  **********************************************************************/
12 
13 #include "liblwgeom.h"
14 
15 #define MAX_CUNIT_ERROR_LENGTH 512
16 
17 #define PG_ADD_TEST(suite, testfunc) CU_add_test(suite, #testfunc, testfunc)
18 
19 /* Contains the most recent error message generated by lwerror. */
21 
22 /* Resets cu_error_msg back to blank. */
23 void cu_error_msg_reset(void);
24 
25 /* Our internal callback to register Suites with the main tester */
26 typedef void (*PG_SuiteSetup)(void);
27 
28 #define ASSERT_DOUBLE_EQUAL(o,e) do { \
29  if ( o != e ) \
30  fprintf(stderr, "[%s:%d]\n Expected: %g\n Obtained: %g\n", __FILE__, __LINE__, (double)(e), (o)); \
31  CU_ASSERT_EQUAL(o,(double)e); \
32 } while (0);
33 
34 #define ASSERT_INT_EQUAL(o,e) do { \
35  if ( o != e ) \
36  fprintf(stderr, "[%s:%d]\n Expected: %d\n Obtained: %d\n", __FILE__, __LINE__, (e), (o)); \
37  CU_ASSERT_EQUAL(o,e); \
38 } while (0);
39 
40 #define ASSERT_STRING_EQUAL(o,e) do { \
41  if ( strcmp(o,e) != 0 ) \
42  fprintf(stderr, "[%s:%d]\n Expected: %s\n Obtained: %s\n", __FILE__, __LINE__, (e), (o)); \
43  CU_ASSERT_STRING_EQUAL(o,e); \
44 } while (0);
45 
46 #define ASSERT_LWGEOM_EQUAL(o, e) do { \
47  if ( !lwgeom_same(o, e) ) { \
48  char* wkt_o = lwgeom_to_ewkt(o); \
49  char* wkt_e = lwgeom_to_ewkt(e); \
50  fprintf(stderr, "[%s:%d]\n Expected: %s\n Obtained: %s\n", __FILE__, __LINE__, (wkt_o), (wkt_e)); \
51  lwfree(wkt_o); \
52  lwfree(wkt_e); \
53  } \
54  CU_ASSERT_TRUE(lwgeom_same(o, e)); \
55 } while(0);
56 
57 #define ASSERT_INTARRAY_EQUAL(o, e, n) do { \
58  size_t i = 0; \
59  for (i = 0; i < n; i++) { \
60  if (o[i] != e[i]) { \
61  fprintf(stderr, "[%s:%d]", __FILE__, __LINE__); \
62  fprintf(stderr, "\nExpected: ["); \
63  for (i = 0; i < n; i++) \
64  fprintf(stderr, " %d", e[i]); \
65  fprintf(stderr, " ]\nObtained: ["); \
66  for (i = 0; i < n; i++) \
67  fprintf(stderr, " %d", o[i]); \
68  fprintf(stderr, " ]\n"); \
69  CU_FAIL(); \
70  break; \
71  } \
72  } \
73  CU_PASS(); \
74 } while(0);
75 
76 /* Utility functions */
77 void do_fn_test(LWGEOM* (*transfn)(LWGEOM*), char *input_wkt, char *expected_wkt);
void cu_error_msg_reset(void)
void(* PG_SuiteSetup)(void)
void do_fn_test(LWGEOM *(*transfn)(LWGEOM *), char *input_wkt, char *expected_wkt)
#define MAX_CUNIT_ERROR_LENGTH
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
This library is the generic geometry handling section of PostGIS.