diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 70ec3c3a37..d622eaf5a7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -38,6 +38,8 @@ function( add_t8_test ) # Link base libraries. target_include_directories( ${ADD_T8_TEST_NAME} PRIVATE ${CMAKE_SOURCE_DIR} ) + # Include binary dir to find generated headers like t8_test_data_dir.h. + target_include_directories( ${ADD_T8_TEST_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ) target_link_libraries( ${ADD_T8_TEST_NAME} PRIVATE GTest::gtest_main T8 pthread ) @@ -99,10 +101,16 @@ function ( add_t8_cpp_test) add_t8_test( NAME ${ADD_T8_CPP_TEST_NAME} SOURCES ${ADD_T8_CPP_TEST_SOURCES} ) endfunction() -# Copy test files to build folder so that the t8_test programs can find them. -function( copy_test_file TEST_FILE_NAME ) - configure_file(${CMAKE_CURRENT_LIST_DIR}/testfiles/${TEST_FILE_NAME} ${CMAKE_CURRENT_BINARY_DIR}/testfiles/${TEST_FILE_NAME} COPYONLY) -endfunction() +# Set absolute path to test data in the source tree +file( TO_CMAKE_PATH + "${CMAKE_CURRENT_LIST_DIR}/testfiles" + T8_TEST_DATA_DIR +) +configure_file( + ${CMAKE_CURRENT_LIST_DIR}/t8_test_data_dir.h.in + ${CMAKE_CURRENT_BINARY_DIR}/t8_test_data_dir.h + @ONLY +) add_t8_cpp_test( NAME t8_gtest_cmesh_bcast_parallel SOURCES t8_cmesh/t8_gtest_bcast.cxx ) add_t8_cpp_test( NAME t8_gtest_eclass_serial SOURCES t8_gtest_eclass.cxx ) @@ -215,16 +223,3 @@ if( T8CODE_BUILD_MESH_HANDLE ) add_t8_cpp_test( NAME t8_gtest_cache_competence_serial SOURCES mesh_handle/t8_gtest_cache_competence.cxx ) add_t8_cpp_test( NAME t8_gtest_handle_data_parallel SOURCES mesh_handle/t8_gtest_handle_data.cxx ) endif() - -copy_test_file( test_cube_unstructured_1.inp ) -copy_test_file( test_cube_unstructured_2.inp ) -copy_test_file( test_vtk_tri.vtu ) -copy_test_file( test_vtk_cube.vtp ) -copy_test_file( test_parallel_file.pvtu ) -copy_test_file( test_parallel_file_0.vtu ) -copy_test_file( test_parallel_file_1.vtu ) -copy_test_file( test_polydata.pvtp ) -copy_test_file( test_polydata_0.vtp ) -copy_test_file( test_polydata_1.vtp ) -copy_test_file( test_msh_file_vers4_ascii.msh ) -copy_test_file( test_msh_file_vers4_bin.msh ) diff --git a/test/t8_IO/t8_gtest_vtk_reader.cxx b/test/t8_IO/t8_gtest_vtk_reader.cxx index f0c067d46a..749f561e87 100644 --- a/test/t8_IO/t8_gtest_vtk_reader.cxx +++ b/test/t8_IO/t8_gtest_vtk_reader.cxx @@ -23,6 +23,8 @@ #include #include #include +#include "t8_test_data_dir.h" +#include #define T8_VTK_TEST_NUM_PROCS 2 @@ -66,8 +68,8 @@ struct vtk_reader: public testing::TestWithParam> int mpirank; const char* failing_files[5] = { "no_file", "non-existing-file.vtu", "non-existing-file.vtp", "non-existing-file.pvtu", "non-existing-file.pvtp" }; - const char* test_files[5] = { "no_file", "test/testfiles/test_vtk_tri.vtu", "test/testfiles/test_vtk_cube.vtp", - "test/testfiles/test_parallel_file.pvtu", "test/testfiles/test_polydata.pvtp" }; + const char* test_files[5] + = { "no_file", "/test_vtk_tri.vtu", "/test_vtk_cube.vtp", "/test_parallel_file.pvtu", "/test_polydata.pvtp" }; const int num_points[5] = { 0, 121, 24, 6144, 900 }; const int num_trees[5] = { 0, 200, 12, 1024, 1680 }; }; @@ -86,7 +88,8 @@ TEST_P (vtk_reader, vtk_to_cmesh_success) int mpirank; int mpiret = sc_MPI_Comm_rank (sc_MPI_COMM_WORLD, &mpirank); SC_CHECK_MPI (mpiret); - t8_cmesh_t cmesh = t8_vtk_reader_cmesh (test_files[file], partition, main_proc, sc_MPI_COMM_WORLD, file_type, + std::string testfile = std::string (T8_TEST_DATA_DIR) + test_files[file]; + t8_cmesh_t cmesh = t8_vtk_reader_cmesh (testfile.c_str (), partition, main_proc, sc_MPI_COMM_WORLD, file_type, t8_testsuite_get_package_id (), 0); if (file_type != VTK_FILE_ERROR) { EXPECT_FALSE (cmesh == NULL); @@ -116,8 +119,9 @@ TEST_P (vtk_reader, vtk_to_cmesh_success) TEST_P (vtk_reader, vtk_to_pointSet) { if (file_type != VTK_FILE_ERROR) { + std::string testfile = std::string (T8_TEST_DATA_DIR) + test_files[file]; vtkSmartPointer points - = t8_vtk_reader_pointSet (test_files[file], partition, main_proc, sc_MPI_COMM_WORLD, file_type); + = t8_vtk_reader_pointSet (testfile.c_str (), partition, main_proc, sc_MPI_COMM_WORLD, file_type); int test_points = points->GetNumberOfPoints (); if (distributed) { /* The points should be distributed equally in this case. */ diff --git a/test/t8_cmesh/t8_gtest_cmesh_readmshfile.cxx b/test/t8_cmesh/t8_gtest_cmesh_readmshfile.cxx index 0d14982baa..dca27767df 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_readmshfile.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_readmshfile.cxx @@ -27,6 +27,8 @@ #include #include #include +#include "t8_test_data_dir.h" +#include /* In this file we test the msh file (gmsh) reader of the cmesh. * Currently, we support version 2 and 4 ascii. @@ -38,15 +40,15 @@ TEST (t8_cmesh_readmshfile, test_msh_file_vers4_ascii) { - const char fileprefix[BUFSIZ - 4] = "testfiles/test_msh_file_vers4_ascii"; + std::string fileprefix = std::string (T8_TEST_DATA_DIR) + "/test_msh_file_vers4_ascii"; char filename[BUFSIZ]; - snprintf (filename, BUFSIZ, "%s.msh", fileprefix); + snprintf (filename, BUFSIZ, "%s.msh", fileprefix.c_str ()); t8_debugf ("Checking msh file version 4 ascii...\n"); ASSERT_FALSE (access (filename, R_OK)) << "Could not open file " << filename; - t8_cmesh_t cmesh = t8_cmesh_from_msh_file (fileprefix, 1, sc_MPI_COMM_WORLD, 2, 0, 0); + t8_cmesh_t cmesh = t8_cmesh_from_msh_file (fileprefix.c_str (), 1, sc_MPI_COMM_WORLD, 2, 0, 0); ASSERT_TRUE (cmesh != NULL) << "Could not read cmesh from ascii version 4, but should be able to."; /* The cmesh was read successfully and we need to destroy it. */ @@ -56,15 +58,15 @@ TEST (t8_cmesh_readmshfile, test_msh_file_vers4_ascii) TEST (t8_cmesh_readmshfile, test_msh_file_vers4_bin) { - const char fileprefix[BUFSIZ - 4] = "testfiles/test_msh_file_vers4_bin"; + std::string fileprefix = std::string (T8_TEST_DATA_DIR) + "/test_msh_file_vers4_bin"; char filename[BUFSIZ]; - snprintf (filename, BUFSIZ, "%s.msh", fileprefix); + snprintf (filename, BUFSIZ, "%s.msh", fileprefix.c_str ()); t8_debugf ("Checking msh file version 4 binary...\n"); ASSERT_FALSE (access (filename, R_OK)) << "Could not open file " << filename; - t8_cmesh_t cmesh = t8_cmesh_from_msh_file (fileprefix, 1, sc_MPI_COMM_WORLD, 2, 0, 0); + t8_cmesh_t cmesh = t8_cmesh_from_msh_file (fileprefix.c_str (), 1, sc_MPI_COMM_WORLD, 2, 0, 0); ASSERT_TRUE (cmesh == NULL) << "Expected fail of reading binary msh file v.4, but did not fail."; t8_debugf ("Error handling successful.\n"); diff --git a/test/t8_cmesh/t8_gtest_cmesh_set_join_by_vertices.cxx b/test/t8_cmesh/t8_gtest_cmesh_set_join_by_vertices.cxx index eeeae6e902..a7d95bf0e6 100644 --- a/test/t8_cmesh/t8_gtest_cmesh_set_join_by_vertices.cxx +++ b/test/t8_cmesh/t8_gtest_cmesh_set_join_by_vertices.cxx @@ -30,6 +30,8 @@ #include "test/t8_cmesh_generator/t8_cmesh_example_sets.hxx" #include #include +#include "t8_test_data_dir.h" +#include #include @@ -277,8 +279,8 @@ TEST (t8_cmesh_set_join_by_vertices, test_cmesh_set_join_by_vertices) } { - const char *filename = "testfiles/test_cube_unstructured_1.inp"; - p8est_connectivity_t *p8_conn = p8est_connectivity_read_inp (filename); + std::string filename = std::string (T8_TEST_DATA_DIR) + "/test_cube_unstructured_1.inp"; + p8est_connectivity_t *p8_conn = p8est_connectivity_read_inp (filename.c_str ()); t8_cmesh_t cmesh = t8_cmesh_new_from_p8est (p8_conn, comm, do_partition); test_with_cmesh (cmesh); p8est_connectivity_destroy (p8_conn); @@ -286,8 +288,8 @@ TEST (t8_cmesh_set_join_by_vertices, test_cmesh_set_join_by_vertices) } { - const char *filename = "testfiles/test_cube_unstructured_2.inp"; - p8est_connectivity_t *p8_conn = p8est_connectivity_read_inp (filename); + std::string filename = std::string (T8_TEST_DATA_DIR) + "/test_cube_unstructured_2.inp"; + p8est_connectivity_t *p8_conn = p8est_connectivity_read_inp (filename.c_str ()); t8_cmesh_t cmesh = t8_cmesh_new_from_p8est (p8_conn, comm, do_partition); test_with_cmesh (cmesh); p8est_connectivity_destroy (p8_conn); diff --git a/test/t8_test_data_dir.h.in b/test/t8_test_data_dir.h.in new file mode 100644 index 0000000000..d380b70844 --- /dev/null +++ b/test/t8_test_data_dir.h.in @@ -0,0 +1,25 @@ +/* + This file is part of t8code. + t8code is a C library to manage a collection (a forest) of multiple + connected adaptive space-trees of general element classes in parallel. + + Copyright (C) 2026 the developers + + t8code is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + t8code is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with t8code; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#pragma once + +#define T8_TEST_DATA_DIR "@T8_TEST_DATA_DIR@" \ No newline at end of file