File: cu_tester.h

package info (click to toggle)
postgis 2.5.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 75,792 kB
  • sloc: ansic: 139,314; sql: 136,281; xml: 48,954; sh: 4,906; perl: 4,509; makefile: 2,897; python: 1,198; yacc: 441; cpp: 305; lex: 132
file content (89 lines) | stat: -rw-r--r-- 2,762 bytes parent folder | download
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
/**********************************************************************
 *
 * PostGIS - Spatial Types for PostgreSQL
 * http://postgis.net
 *
 * Copyright (C) 2009 Paul Ramsey <pramsey@cleverelephant.ca>
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the GNU General Public Licence. See the COPYING file.
 *
 **********************************************************************/

#include "liblwgeom.h"

#define MAX_CUNIT_ERROR_LENGTH 512

#define PG_ADD_TEST(suite, testfunc) CU_add_test(suite, #testfunc, testfunc)

/* Contains the most recent error message generated by lwerror. */
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1];

/* Resets cu_error_msg back to blank. */
void cu_error_msg_reset(void);

/* Our internal callback to register Suites with the main tester */
typedef void (*PG_SuiteSetup)(void);

#define ASSERT_DOUBLE_EQUAL(o,e) do { \
  if ( o != e ) \
    fprintf(stderr, "[%s:%d]\n Expected: %g\n Obtained: %g\n", __FILE__, __LINE__, (double)(e), (o)); \
  CU_ASSERT_EQUAL(o,(double)e); \
} while (0);

#define ASSERT_INT_EQUAL(o,e) do { \
  if ( o != e ) \
    fprintf(stderr, "[%s:%d]\n Expected: %d\n Obtained: %d\n", __FILE__, __LINE__, (e), (o)); \
  CU_ASSERT_EQUAL(o,e); \
} while (0);

#define ASSERT_STRING_EQUAL(o,e) do { \
  if ( strcmp(o,e) != 0 ) \
    fprintf(stderr, "[%s:%d]\n Expected: %s\n Obtained: %s\n", __FILE__, __LINE__, (e), (o)); \
  CU_ASSERT_STRING_EQUAL(o,e); \
} while (0);

#define ASSERT_LWGEOM_EQUAL(o, e) do { \
	if ( !lwgeom_same(o, e) ) { \
		char* wkt_o = lwgeom_to_ewkt(o); \
		char* wkt_e = lwgeom_to_ewkt(e); \
		fprintf(stderr, "[%s:%d]\n Expected: %s\n Obtained: %s\n", __FILE__, __LINE__, (wkt_o), (wkt_e)); \
		lwfree(wkt_o); \
		lwfree(wkt_e); \
	} \
	CU_ASSERT_TRUE(lwgeom_same(o, e)); \
} while(0);

#define ASSERT_INTARRAY_EQUAL(o, e, n) do { \
	size_t i = 0; \
	for (i = 0; i < n; i++) { \
		if (o[i] != e[i]) { \
			fprintf(stderr, "[%s:%d]", __FILE__, __LINE__); \
			fprintf(stderr, "\nExpected: ["); \
			for (i = 0; i < n; i++) \
				fprintf(stderr, " %d", e[i]); \
			fprintf(stderr, " ]\nObtained: ["); \
			for (i = 0; i < n; i++) \
				fprintf(stderr, " %d", o[i]); \
			fprintf(stderr, " ]\n"); \
			CU_FAIL(); \
			break; \
		} \
	} \
	CU_PASS(); \
} while(0);

#define ASSERT_POINT2D_EQUAL(o, e, eps) do { \
	CU_ASSERT_DOUBLE_EQUAL(o.x, e.x, eps); \
	CU_ASSERT_DOUBLE_EQUAL(o.y, e.y, eps); \
} while(0);

#define ASSERT_POINT4D_EQUAL(o, e, eps) do { \
	CU_ASSERT_DOUBLE_EQUAL(o.x, e.x, eps); \
	CU_ASSERT_DOUBLE_EQUAL(o.y, e.y, eps); \
	CU_ASSERT_DOUBLE_EQUAL(o.z, e.z, eps); \
	CU_ASSERT_DOUBLE_EQUAL(o.m, e.m, eps); \
} while(0);

/* Utility functions */
void do_fn_test(LWGEOM* (*transfn)(LWGEOM*), char *input_wkt, char *expected_wkt);