diff --git a/src/test/cunit.c b/src/test/cunit.c index e1f4707..d64c05a 100644 --- a/src/test/cunit.c +++ b/src/test/cunit.c @@ -102,6 +102,8 @@ int main(void) test_parse_obj3)) || (NULL == CU_add_test(pSuite, "test4 parsing .obj", test_parse_obj4)) || + (NULL == CU_add_test(pSuite, "test5 parsing .obj", + test_parse_obj5)) || (NULL == CU_add_test(pSuite, "test1 finding center ob obj", test_find_center1)) || (NULL == CU_add_test(pSuite, "test2 finding center ob obj", diff --git a/src/test/cunit.h b/src/test/cunit.h index b5e6c28..ed77d88 100644 --- a/src/test/cunit.h +++ b/src/test/cunit.h @@ -42,6 +42,7 @@ void test_parse_obj1(void); void test_parse_obj2(void); void test_parse_obj3(void); void test_parse_obj4(void); +void test_parse_obj5(void); void test_find_center1(void); void test_find_center2(void); diff --git a/src/test/cunit_half_edge.c b/src/test/cunit_half_edge.c index f7f0cb6..e176ea5 100644 --- a/src/test/cunit_half_edge.c +++ b/src/test/cunit_half_edge.c @@ -436,6 +436,46 @@ void test_parse_obj4(void) CU_ASSERT_PTR_NULL(obj); } +/** + * Test the whole object for consistency by walking + * through all faces and checking the respective half-edges + * ans pairs. + */ +void test_parse_obj5(void) +{ + char const * const string = "" + "v 9.0 10.0 11.0\n" + "v 11.0 10.0 11.0\n" + "v 9.0 11.0 11.0\n" + "v 11.0 11.0 11.0\n" + "v 9.0 11.0 9.0\n" + "v 11.0 11.0 9.0\n" + "v 9.0 10.0 9.0\n" + "v 11.0 10.0 9.0\n" + "f 1 2 4 3\n" + "f 3 4 6 5\n" + "f 5 6 8 7\n" + "f 7 8 2 1\n" + "f 2 8 6 4\n" + "f 7 1 3 5\n"; + + HE_obj *obj = parse_obj(string); + + CU_ASSERT_PTR_NOT_NULL(obj); + + for (uint32_t i = 0; i < obj->fc; i++) { + HE_edge *start_edge = &(obj->faces[i].edge[0]), + *next_edge = start_edge->next; + while(next_edge != start_edge) { + CU_ASSERT_PTR_NOT_NULL(next_edge); + CU_ASSERT_PTR_NOT_NULL(next_edge->pair->pair); + CU_ASSERT_EQUAL(next_edge->face, &(obj->faces[i])); + CU_ASSERT_EQUAL(next_edge->pair->pair, next_edge); + next_edge = next_edge->next; + } + } +} + /** * Test finding the center of an object. */