From 0e4d85f8337f18f782c9569012418b8e3629ab8b Mon Sep 17 00:00:00 2001 From: David Knapp Date: Thu, 29 Jun 2023 08:52:58 +0200 Subject: [PATCH 1/3] Change name of test --- test/t8_IO/t8_gtest_vtk_reader.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/t8_IO/t8_gtest_vtk_reader.cxx b/test/t8_IO/t8_gtest_vtk_reader.cxx index 761207acdc..5162f1a444 100644 --- a/test/t8_IO/t8_gtest_vtk_reader.cxx +++ b/test/t8_IO/t8_gtest_vtk_reader.cxx @@ -29,7 +29,7 @@ along with t8code; if not, write to the Free Software Foundation, Inc., * test yet. * */ -TEST (t8_cmesh_vtk_reader, dummy_test) +TEST (t8__vtk_reader, vtk_to_cmesh) { #if T8_WITH_VTK t8_cmesh_t cmesh = From 5598de7d17713e813a631efe182492fde34b54cc Mon Sep 17 00:00:00 2001 From: David Knapp Date: Thu, 29 Jun 2023 09:08:35 +0200 Subject: [PATCH 2/3] Add new test for pointSets --- test/t8_IO/t8_gtest_vtk_reader.cxx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/t8_IO/t8_gtest_vtk_reader.cxx b/test/t8_IO/t8_gtest_vtk_reader.cxx index 5162f1a444..cd96e6372c 100644 --- a/test/t8_IO/t8_gtest_vtk_reader.cxx +++ b/test/t8_IO/t8_gtest_vtk_reader.cxx @@ -29,7 +29,7 @@ along with t8code; if not, write to the Free Software Foundation, Inc., * test yet. * */ -TEST (t8__vtk_reader, vtk_to_cmesh) +TEST (t8_vtk_reader, vtk_to_cmesh) { #if T8_WITH_VTK t8_cmesh_t cmesh = @@ -61,3 +61,21 @@ TEST (t8__vtk_reader, vtk_to_cmesh) #else #endif } + +TEST (t8_vtk_reader, vtk_to_pointSet) +{ +#if T8_WITH_VTK + vtkSmartPointer < vtkPointSet > points = + t8_vtk_reader_pointSet ("test/testfiles/test_vtk_tri.vtu", 0, 0, + sc_MPI_COMM_WORLD, VTK_UNSTRUCTURED_FILE); + int num_points = points->GetNumberOfPoints (); + EXPECT_EQ (num_points, 121); + + points = + t8_vtk_reader_pointSet ("test/testfiles/test_vtk_cube.vtp", 0, 0, + sc_MPI_COMM_WORLD, VTK_POLYDATA_FILE); + num_points = points->GetNumberOfPoints (); + EXPECT_EQ (num_points, 24); +#else +#endif +} From 8a4e5fa6c41ef053fe4941fad4229b6d0ec6dc9c Mon Sep 17 00:00:00 2001 From: David Knapp Date: Thu, 29 Jun 2023 09:45:58 +0200 Subject: [PATCH 3/3] Parametrize all tests --- src/t8_vtk/t8_vtk_types.h | 3 +- test/t8_IO/t8_gtest_vtk_reader.cxx | 96 ++++++++++++++++++------------ 2 files changed, 61 insertions(+), 38 deletions(-) diff --git a/src/t8_vtk/t8_vtk_types.h b/src/t8_vtk/t8_vtk_types.h index 4870d68b11..0d19196e54 100644 --- a/src/t8_vtk/t8_vtk_types.h +++ b/src/t8_vtk/t8_vtk_types.h @@ -62,7 +62,8 @@ typedef enum vtk_file_type { VTK_FILE_ERROR = -1, /*For Testing purpose. */ VTK_UNSTRUCTURED_FILE = 0, - VTK_POLYDATA_FILE = 1 + VTK_POLYDATA_FILE = 1, + VTK_NUM_TYPES } vtk_file_type_t; typedef enum vtk_read_success diff --git a/test/t8_IO/t8_gtest_vtk_reader.cxx b/test/t8_IO/t8_gtest_vtk_reader.cxx index cd96e6372c..52d144d026 100644 --- a/test/t8_IO/t8_gtest_vtk_reader.cxx +++ b/test/t8_IO/t8_gtest_vtk_reader.cxx @@ -26,56 +26,78 @@ along with t8code; if not, write to the Free Software Foundation, Inc., /** * This is currently a place-holder for a propper cmesh_vtk_reader-test. * The function is not implemented yet and therefore we do not provide a proper - * test yet. + * test yet. A proper test would compare the read files with a reference-cmesh. * */ -TEST (t8_vtk_reader, vtk_to_cmesh) + + +/* *INDENT-OFF* */ +class vtk_reader : public testing::TestWithParam{ + protected: + void SetUp() override{ + file_type = GetParam(); + file = (int)file_type + 1; + } + int file; + vtk_file_type_t file_type; + const char* failing_files[3] = { + "no_file", + "non-existing-file.vtu", + "non-existing-file.vtp" + }; + const char* test_files[3] = { + "no_file", + "test/testfiles/test_vtk_tri.vtu", + "test/testfiles/test_vtk_cube.vtp" + }; + const int num_points[3] = {0, 121, 24}; +}; +/* *INDENT-ON* */ + +/* All readers should fail properly with a non-existing file. */ +TEST_P (vtk_reader, vtk_to_cmesh_fail) { #if T8_WITH_VTK t8_cmesh_t cmesh = - t8_cmesh_vtk_reader ("non-existing-file.vtu", 0, 0, sc_MPI_COMM_WORLD, - VTK_FILE_ERROR); - EXPECT_TRUE (cmesh == NULL); - - cmesh = - t8_cmesh_vtk_reader ("non-existing-file.vtu", 0, 0, sc_MPI_COMM_WORLD, - VTK_UNSTRUCTURED_FILE); - EXPECT_TRUE (cmesh == NULL); - - cmesh = - t8_cmesh_vtk_reader ("non-existing-file.vtp", 0, 0, sc_MPI_COMM_WORLD, - VTK_POLYDATA_FILE); + t8_cmesh_vtk_reader (failing_files[file], 0, 0, sc_MPI_COMM_WORLD, + file_type); EXPECT_TRUE (cmesh == NULL); - - cmesh = - t8_cmesh_vtk_reader ("test/testfiles/test_vtk_tri.vtu", 0, 0, - sc_MPI_COMM_WORLD, VTK_UNSTRUCTURED_FILE); - EXPECT_FALSE (cmesh == NULL); - t8_cmesh_destroy (&cmesh); - cmesh = - t8_cmesh_vtk_reader ("test/testfiles/test_vtk_cube.vtp", 0, 0, - sc_MPI_COMM_WORLD, VTK_POLYDATA_FILE); - EXPECT_FALSE (cmesh == NULL); - t8_cmesh_destroy (&cmesh); - #else #endif } -TEST (t8_vtk_reader, vtk_to_pointSet) +/* All readers should construct a cmesh from a file. */ +TEST_P (vtk_reader, vtk_to_cmesh_success) { #if T8_WITH_VTK - vtkSmartPointer < vtkPointSet > points = - t8_vtk_reader_pointSet ("test/testfiles/test_vtk_tri.vtu", 0, 0, - sc_MPI_COMM_WORLD, VTK_UNSTRUCTURED_FILE); - int num_points = points->GetNumberOfPoints (); - EXPECT_EQ (num_points, 121); + t8_cmesh_t cmesh = t8_cmesh_vtk_reader (test_files[file], 0, 0, + sc_MPI_COMM_WORLD, + file_type); + if (file_type != VTK_FILE_ERROR) { + EXPECT_FALSE (cmesh == NULL); + t8_cmesh_destroy (&cmesh); + } + else { + EXPECT_TRUE (cmesh == NULL); + } +#else +#endif +} - points = - t8_vtk_reader_pointSet ("test/testfiles/test_vtk_cube.vtp", 0, 0, - sc_MPI_COMM_WORLD, VTK_POLYDATA_FILE); - num_points = points->GetNumberOfPoints (); - EXPECT_EQ (num_points, 24); +/* Read a file as a pointSet and compare the number of points with the known number of points. */ +TEST_P (vtk_reader, vtk_to_pointSet) +{ +#if T8_WITH_VTK + if (file_type != VTK_FILE_ERROR) { + vtkSmartPointer < vtkPointSet > points = + t8_vtk_reader_pointSet (test_files[file], 0, 0, + sc_MPI_COMM_WORLD, file_type); + int test_points = points->GetNumberOfPoints (); + EXPECT_EQ (num_points[file], test_points); + } #else #endif } + +INSTANTIATE_TEST_SUITE_P (t8_gtest_vtk_reader, vtk_reader, + testing::Range (VTK_FILE_ERROR, VTK_NUM_TYPES));