Skip to content

Commit

Permalink
Merge pull request #597 from DLR-AMR/parametrize_vtk_tests
Browse files Browse the repository at this point in the history
Parametrize vtk tests
  • Loading branch information
ililikakis authored Jun 29, 2023
2 parents a76a752 + 8a4e5fa commit e97f833
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 25 deletions.
3 changes: 2 additions & 1 deletion src/t8_vtk/t8_vtk_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
88 changes: 64 additions & 24 deletions test/t8_IO/t8_gtest_vtk_reader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +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_cmesh_vtk_reader, dummy_test)


/* *INDENT-OFF* */
class vtk_reader : public testing::TestWithParam<vtk_file_type_t>{
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);
#else
#endif
}

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);
/* All readers should construct a cmesh from a file. */
TEST_P (vtk_reader, vtk_to_cmesh_success)
{
#if T8_WITH_VTK
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
}

/* 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));

0 comments on commit e97f833

Please sign in to comment.