[Bf-blender-cvs] [c5c134b] gtest-testing: replace polyfill macros with functions

Campbell Barton noreply at git.blender.org
Tue May 27 15:52:32 CEST 2014


Commit: c5c134b8e51302e4a454502fdc6b9e96b5d977c3
Author: Campbell Barton
Date:   Tue May 27 23:51:17 2014 +1000
https://developer.blender.org/rBc5c134b8e51302e4a454502fdc6b9e96b5d977c3

replace polyfill macros with functions

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

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 8faaf04..73f98ac 100644
--- a/source/tests/blenlib_tests/polyfill2d_test.cc
+++ b/source/tests/blenlib_tests/polyfill2d_test.cc
@@ -30,97 +30,105 @@ static void test_valid_polyfill_prepare(unsigned int tris[][3], unsigned int tri
  * - all tris set.
  * - all verts used at least once.
  */
-#define TEST_POLYFILL_SIMPLE(poly, poly_tot, tri, tri_tot) \
-{ \
-	unsigned int i; \
-	int *tot_used = (int *)MEM_callocN(poly_tot * sizeof(int), __func__); \
-	for (i = 0; i < tri_tot; i++) { \
-		unsigned int j; \
-		for (j = 0; j < 3; j++) { \
-			EXPECT_NE(TRI_ERROR_VALUE, tri[i][j]); \
-			tot_used[tri[i][j]] += 1; \
-		} \
-		EXPECT_NE(tri[i][0], tri[i][1]); \
-		EXPECT_NE(tri[i][1], tri[i][2]); \
-		EXPECT_NE(tri[i][2], tri[i][0]); \
-	} \
-	for (i = 0; i < poly_tot; i++) { \
-		EXPECT_NE(0, tot_used[i]); \
-	} \
-	MEM_freeN(tot_used); \
-} (void)0
+static void test_polyfill_simple(
+        const float poly[][2], const unsigned int poly_tot,
+        const unsigned int tri[][3], const unsigned int tri_tot)
+{
+	unsigned int i;
+	int *tot_used = (int *)MEM_callocN(poly_tot * sizeof(int), __func__);
+	for (i = 0; i < tri_tot; i++) {
+		unsigned int j;
+		for (j = 0; j < 3; j++) {
+			EXPECT_NE(TRI_ERROR_VALUE, tri[i][j]);
+			tot_used[tri[i][j]] += 1;
+		}
+		EXPECT_NE(tri[i][0], tri[i][1]);
+		EXPECT_NE(tri[i][1], tri[i][2]);
+		EXPECT_NE(tri[i][2], tri[i][0]);
+	}
+	for (i = 0; i < poly_tot; i++) {
+		EXPECT_NE(0, tot_used[i]);
+	}
+	MEM_freeN(tot_used);
+}
 
-#define TEST_POLYFILL_TOPOLOGY(poly, poly_tot, tri, tri_tot) \
-{ \
-	EdgeHash *edgehash = BLI_edgehash_new(__func__); \
-	EdgeHashIterator *ehi; \
-	unsigned int i; \
-	for (i = 0; i < tri_tot; i++) { \
-		unsigned int j; \
-		for (j = 0; j < 3; j++) { \
-			const unsigned int v1 = tri[i][j]; \
-			const unsigned int v2 = tri[i][(j + 1) % 3]; \
-			void **p = BLI_edgehash_lookup_p(edgehash, v1, v2); \
-			if (p) { \
-				*p = (void *)((intptr_t)*p + (intptr_t)1); \
-			} \
-			else { \
-				BLI_edgehash_insert(edgehash, v1, v2, (void *)(intptr_t)1); \
-			} \
-		} \
-	} \
-	EXPECT_EQ(poly_tot + (poly_tot - 3), BLI_edgehash_size(edgehash)); \
-	\
-	for (i = 0; i < poly_tot; i++) { \
-		const unsigned int v1 = i; \
-		const unsigned int v2 = (i + 1) % poly_tot; \
-		void **p = BLI_edgehash_lookup_p(edgehash, v1, v2); \
-		EXPECT_EQ(1, (void *)p != NULL); \
-		EXPECT_EQ(1, (intptr_t)*p); \
-	} \
-	\
-	for (ehi = BLI_edgehashIterator_new(edgehash), i = 0; \
-	     BLI_edgehashIterator_isDone(ehi) == false; \
-	     BLI_edgehashIterator_step(ehi), i++) \
-	{ \
-		void **p = BLI_edgehashIterator_getValue_p(ehi); \
-		EXPECT_EQ(true, ELEM((intptr_t)*p, 1, 2)); \
-	} \
-	\
-	BLI_edgehash_free(edgehash, NULL); \
-} (void)0
+static void  test_polyfill_topology(
+        const float poly[][2], const unsigned int poly_tot,
+        const unsigned int tri[][3], const unsigned int tri_tot)
+{
+	EdgeHash *edgehash = BLI_edgehash_new(__func__);
+	EdgeHashIterator *ehi;
+	unsigned int i;
+	for (i = 0; i < tri_tot; i++) {
+		unsigned int j;
+		for (j = 0; j < 3; j++) {
+			const unsigned int v1 = tri[i][j];
+			const unsigned int v2 = tri[i][(j + 1) % 3];
+			void **p = BLI_edgehash_lookup_p(edgehash, v1, v2);
+			if (p) {
+				*p = (void *)((intptr_t)*p + (intptr_t)1);
+			}
+			else {
+				BLI_edgehash_insert(edgehash, v1, v2, (void *)(intptr_t)1);
+			}
+		}
+	}
+	EXPECT_EQ(poly_tot + (poly_tot - 3), BLI_edgehash_size(edgehash));
+
+	for (i = 0; i < poly_tot; i++) {
+		const unsigned int v1 = i;
+		const unsigned int v2 = (i + 1) % poly_tot;
+		void **p = BLI_edgehash_lookup_p(edgehash, v1, v2);
+		EXPECT_EQ(1, (void *)p != NULL);
+		EXPECT_EQ(1, (intptr_t)*p);
+	}
+
+	for (ehi = BLI_edgehashIterator_new(edgehash), i = 0;
+	     BLI_edgehashIterator_isDone(ehi) == false;
+	     BLI_edgehashIterator_step(ehi), i++)
+	{
+		void **p = BLI_edgehashIterator_getValue_p(ehi);
+		EXPECT_EQ(true, ELEM((intptr_t)*p, 1, 2));
+	}
+
+	BLI_edgehash_free(edgehash, NULL);
+}
 
 /**
  * Check all faces are flipped the same way
  */
-#define TEST_POLYFILL_WINDING(poly, poly_tot, tri, tri_tot) \
-{ \
-	unsigned int i; \
-	unsigned int count[2] = {0, 0}; \
-	for (i = 0; i < tri_tot; i++) { \
-		float winding_test = cross_tri_v2(poly[tri[i][0]], poly[tri[i][1]], poly[tri[i][2]]); \
-		if (fabsf(winding_test) > FLT_EPSILON) { \
-			count[winding_test < 0.0f] += 1; \
-		} \
-	} \
-	EXPECT_EQ(true, ELEM(0, count[0], count[1])); \
-} (void)0
+static void  test_polyfill_winding(
+        const float poly[][2], const unsigned int poly_tot,
+        const unsigned int tri[][3], const unsigned int tri_tot)
+{
+	unsigned int i;
+	unsigned int count[2] = {0, 0};
+	for (i = 0; i < tri_tot; i++) {
+		float winding_test = cross_tri_v2(poly[tri[i][0]], poly[tri[i][1]], poly[tri[i][2]]);
+		if (fabsf(winding_test) > FLT_EPSILON) {
+			count[winding_test < 0.0f] += 1;
+		}
+	}
+	EXPECT_EQ(true, ELEM(0, count[0], count[1]));
+}
 
 /**
  * Check the accumulated triangle area is close to the original area.
  */
-#define TEST_POLYFILL_AREA(poly, poly_tot, tri, tri_tot) \
-{ \
-	unsigned int i; \
-	const float area_tot = area_poly_v2(poly, poly_tot); \
-	float       area_tot_tri = 0.0f; \
-	const float eps_abs = 0.00001f; \
-	const float eps = area_tot > 1.0f ? (area_tot * eps_abs) : eps_abs; \
-	for (i = 0; i < tri_tot; i++) { \
-		area_tot_tri += area_tri_v2(poly[tri[i][0]], poly[tri[i][1]], poly[tri[i][2]]); \
-	} \
-	EXPECT_NEAR(area_tot, area_tot_tri, eps); \
-} (void)0
+static void test_polyfill_area(
+        const float poly[][2], const unsigned int poly_tot,
+        const unsigned int tri[][3], const unsigned int tri_tot)
+{
+	unsigned int i;
+	const float area_tot = area_poly_v2(poly, poly_tot);
+	float       area_tot_tri = 0.0f;
+	const float eps_abs = 0.00001f;
+	const float eps = area_tot > 1.0f ? (area_tot * eps_abs) : eps_abs;
+	for (i = 0; i < tri_tot; i++) {
+		area_tot_tri += area_tri_v2(poly[tri[i][0]], poly[tri[i][1]], poly[tri[i][2]]);
+	}
+	EXPECT_NEAR(area_tot, area_tot_tri, eps);
+}
 
 /**
  * Main template for polyfill testing.
@@ -129,16 +137,17 @@ static void test_valid_polyfill_prepare(unsigned int tris[][3], unsigned int tri
 { \
 	unsigned int tris[POLY_TRI_COUNT(ARRAY_SIZE(poly))][3]; \
 	const unsigned int poly_tot = ARRAY_SIZE(poly); \
-	test_valid_polyfill_prepare(tris, ARRAY_SIZE(tris)); \
+	const unsigned int tris_tot = ARRAY_SIZE(tris); \
+	test_valid_polyfill_prepare(tris, tris_tot); \
 	\
 	BLI_polyfill_calc(poly, poly_tot, tris); \
 	\
-	TEST_POLYFILL_SIMPLE(poly, ARRAY_SIZE(poly), tris, ARRAY_SIZE(tris)); \
-	TEST_POLYFILL_TOPOLOGY(poly, ARRAY_SIZE(poly), tris, ARRAY_SIZE(tris)); \
+	test_polyfill_simple(poly, poly_tot, (const unsigned int (*)[3])tris, tris_tot); \
+	test_polyfill_topology(poly, poly_tot, (const unsigned int (*)[3])tris, tris_tot); \
 	if (!is_degenerate) { \
-		TEST_POLYFILL_WINDING(poly, ARRAY_SIZE(poly), tris, ARRAY_SIZE(tris)); \
+		test_polyfill_winding(poly, poly_tot, (const unsigned int (*)[3])tris, tris_tot); \
 		\
-		TEST_POLYFILL_AREA(poly, ARRAY_SIZE(poly), tris, ARRAY_SIZE(tris)); \
+		test_polyfill_area(poly, poly_tot, (const unsigned int (*)[3])tris, tris_tot); \
 	} \
 } (void)0




More information about the Bf-blender-cvs mailing list