[Bf-blender-cvs] [d696c92] gtest-testing: add optional OBJ output for polyfill tests

Campbell Barton noreply at git.blender.org
Tue May 27 16:37:51 CEST 2014


Commit: d696c92cab7f2b698596be5a8301290cc57688e8
Author: Campbell Barton
Date:   Wed May 28 00:30:50 2014 +1000
https://developer.blender.org/rBd696c92cab7f2b698596be5a8301290cc57688e8

add optional OBJ output for polyfill tests

===================================================================

M	source/tests/blenlib_tests/polyfill2d_test.cc

===================================================================

diff --git a/source/tests/blenlib_tests/polyfill2d_test.cc b/source/tests/blenlib_tests/polyfill2d_test.cc
index 73f98ac..343be66 100644
--- a/source/tests/blenlib_tests/polyfill2d_test.cc
+++ b/source/tests/blenlib_tests/polyfill2d_test.cc
@@ -1,14 +1,21 @@
 #include "testing/testing.h"
 
+/* Use to write out OBJ files, handy for checking output */
+// #define USE_OBJ_PREVIEW
+
 extern "C" {
 #include "BLI_polyfill2d.h"
 #include "BLI_math.h"
 #include "BLI_edgehash.h"
 #include "MEM_guardedalloc.h"
+
+#ifdef USE_OBJ_PREVIEW
+#  include "BLI_string.h"
+#endif
 }
 
 /* -------------------------------------------------------------------- */
-/* tests */
+/* test utility functions */
 
 #define TRI_ERROR_VALUE (unsigned int)-1
 
@@ -149,8 +156,54 @@ static void test_polyfill_area(
 		\
 		test_polyfill_area(poly, poly_tot, (const unsigned int (*)[3])tris, tris_tot); \
 	} \
+	polyfill_to_obj(typeid(*this).name(), poly, poly_tot, (const unsigned int (*)[3])tris, tris_tot); \
 } (void)0
 
+/* -------------------------------------------------------------------- */
+/* visualisation functions (not needed for testing) */
+
+#ifdef USE_OBJ_PREVIEW
+static void polyfill_to_obj(
+        const char *id,
+        const float poly[][2], const unsigned int poly_tot,
+        const unsigned int tri[][3], const unsigned int tri_tot)
+{
+	char path[1024];
+	FILE *f;
+	unsigned int i;
+
+	BLI_snprintf(path, sizeof(path), "%s.obj", id);
+
+	f = fopen(path, "w");
+	if (!f) {
+		return;
+	}
+
+	for (i = 0; i < poly_tot; i++) {
+		fprintf(f, "v %f %f 0.0\n", UNPACK2(poly[i]));
+	}
+
+	for (i = 0; i < tri_tot; i++) {
+		fprintf(f, "f %u %u %u\n", UNPACK3OP(1 +, tri[i]));
+	}
+
+	fclose(f);
+}
+#else
+static void polyfill_to_obj(
+        const char *id,
+        const float poly[][2], const unsigned int poly_tot,
+        const unsigned int tri[][3], const unsigned int tri_tot)
+{
+	(void)id;
+	(void)poly, (void)poly_tot;
+	(void)tri, (void)tri_tot;
+}
+#endif  /* USE_OBJ_PREVIEW */
+
+
+/* -------------------------------------------------------------------- */
+/* tests */
 
 #define POLY_TRI_COUNT(len) ((len) - 2)
 /* BLI_cleanup_path */




More information about the Bf-blender-cvs mailing list