]> granicus.if.org Git - postgis/commitdiff
Add Cunit - lwerror use case handle - #420
authorOlivier Courtin <olivier.courtin@camptocamp.com>
Sat, 20 Feb 2010 16:47:12 +0000 (16:47 +0000)
committerOlivier Courtin <olivier.courtin@camptocamp.com>
Sat, 20 Feb 2010 16:47:12 +0000 (16:47 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@5264 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_tester.c
liblwgeom/cunit/cu_tester.h

index 0d1a428c66a1f101585c344106524b6354a0445e..9fd816f0ad10ff1b0e35f49bf7469f90f0dca63c 100644 (file)
 #include "cu_tester.h"
 
 
+/**
+ * CUnit error handler 
+ * Log message in a global var instead of printing in stderr
+ *
+ * CAUTION: Not stop execution on lwerror case !!!
+ */
+static void
+cu_errorreporter(const char *fmt, va_list ap)
+{
+        char *msg;
+
+        /** This is a GNU extension.
+        * Dunno how to handle errors here.
+         */
+        if (!lw_vasprintf (&msg, fmt, ap))
+        {
+                va_end (ap);
+                return;
+        }
+
+       strncpy(cu_error_msg, msg, MAX_CUNIT_ERROR_LENGTH);
+}
+
+void
+cu_error_msg_reset()
+{
+       memset(cu_error_msg, '\0', MAX_CUNIT_ERROR_LENGTH);
+}
+
 /*
 ** Set up liblwgeom to run in stand-alone mode using the
 ** usual system memory handling functions.
 */
 void lwgeom_init_allocators(void)
 {
-       /* liblwgeom callback - install default handlers */
-       lwgeom_install_default_allocators();
+        lwalloc_var = default_allocator;
+        lwrealloc_var = default_reallocator;
+        lwfree_var = default_freeor;
+        lwnotice_var = default_noticereporter;
+        lwerror_var = cu_errorreporter;
+
 }
 
 /*
index 60def6fb456190fb651822c797fcaf2ebb9eb908..8f487c08533568b29f8951896a5ff3067894ffaf 100644 (file)
@@ -1,3 +1,6 @@
+#define MAX_CUNIT_ERROR_LENGTH 512
+char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1];
+void cu_error_msg_reset();
 
 CU_pSuite register_measures_suite(void);
 CU_pSuite register_geodetic_suite(void);