PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
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#ifndef _CU_TESTER_H
14#define _CU_TESTER_H 1
15
16#include "liblwgeom.h"
17
18#define MAX_CUNIT_ERROR_LENGTH 512
19
20#define PG_ADD_TEST(suite, testfunc) CU_add_test(suite, #testfunc, testfunc)
21
22/* Contains the most recent error message generated by lwerror. */
23extern char cu_error_msg[];
24
25/* Resets cu_error_msg back to blank. */
26void cu_error_msg_reset(void);
27
28/* Our internal callback to register Suites with the main tester */
29typedef void (*PG_SuiteSetup)(void);
30
31#define ASSERT_DOUBLE_EQUAL(o,e) do { \
32 if ( o != e ) \
33 fprintf(stderr, "[%s:%d]\n Expected: %g\n Obtained: %g\n", __FILE__, __LINE__, (double)(e), (o)); \
34 CU_ASSERT_EQUAL(o,(double)e); \
35} while (0);
36
37#define ASSERT_INT_EQUAL(o,e) do { \
38 if ( o != e ) \
39 fprintf(stderr, "[%s:%d]\n Expected: %d\n Obtained: %d\n", __FILE__, __LINE__, (e), (o)); \
40 CU_ASSERT_EQUAL(o,e); \
41} while (0);
42
43#define ASSERT_STRING_EQUAL(o,e) do { \
44 if ( strcmp(o,e) != 0 ) \
45 fprintf(stderr, "[%s:%d]\n Expected: %s\n Obtained: %s\n", __FILE__, __LINE__, (e), (o)); \
46 CU_ASSERT_STRING_EQUAL(o,e); \
47} while (0);
48
49#define ASSERT_LWGEOM_EQUAL(o, e) do { \
50 if ( !lwgeom_same(o, e) ) { \
51 char* wkt_o = lwgeom_to_ewkt(o); \
52 char* wkt_e = lwgeom_to_ewkt(e); \
53 fprintf(stderr, "[%s:%d]\n Expected: %s\n Obtained: %s\n", __FILE__, __LINE__, (wkt_o), (wkt_e)); \
54 lwfree(wkt_o); \
55 lwfree(wkt_e); \
56 } \
57 CU_ASSERT_TRUE(lwgeom_same(o, e)); \
58} while(0);
59
60#define ASSERT_INTARRAY_EQUAL(o, e, n) do { \
61 size_t i = 0; \
62 for (i = 0; i < n; i++) { \
63 if (o[i] != e[i]) { \
64 fprintf(stderr, "[%s:%d]", __FILE__, __LINE__); \
65 fprintf(stderr, "\nExpected: ["); \
66 for (i = 0; i < n; i++) \
67 fprintf(stderr, " %d", e[i]); \
68 fprintf(stderr, " ]\nObtained: ["); \
69 for (i = 0; i < n; i++) \
70 fprintf(stderr, " %d", o[i]); \
71 fprintf(stderr, " ]\n"); \
72 CU_FAIL(); \
73 break; \
74 } \
75 } \
76 CU_PASS(); \
77} while(0);
78
79#define ASSERT_POINT2D_EQUAL(o, e, eps) do { \
80 CU_ASSERT_DOUBLE_EQUAL(o.x, e.x, eps); \
81 CU_ASSERT_DOUBLE_EQUAL(o.y, e.y, eps); \
82} while(0);
83
84#define ASSERT_POINT4D_EQUAL(o, e, eps) do { \
85 CU_ASSERT_DOUBLE_EQUAL(o.x, e.x, eps); \
86 CU_ASSERT_DOUBLE_EQUAL(o.y, e.y, eps); \
87 CU_ASSERT_DOUBLE_EQUAL(o.z, e.z, eps); \
88 CU_ASSERT_DOUBLE_EQUAL(o.m, e.m, eps); \
89} while(0);
90
91/* Utility functions */
92void do_fn_test(LWGEOM* (*transfn)(LWGEOM*), char *input_wkt, char *expected_wkt);
93
94#endif /* _CU_TESTER_H */
void(* PG_SuiteSetup)(void)
void do_fn_test(LWGEOM *(*transfn)(LWGEOM *), char *input_wkt, char *expected_wkt)
void cu_error_msg_reset(void)
char cu_error_msg[]
This library is the generic geometry handling section of PostGIS.