Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
12 changes: 8 additions & 4 deletions test/t8_IO/t8_gtest_vtk_reader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <gtest/gtest.h>
#include <test/t8_gtest_macros.hxx>
#include <src/t8_vtk/t8_with_vtk/t8_vtk_reader.hxx>
#include "t8_test_data_dir.h"
#include <string>

#define T8_VTK_TEST_NUM_PROCS 2

Expand Down Expand Up @@ -66,8 +68,8 @@ struct vtk_reader: public testing::TestWithParam<std::tuple<int, int, int>>
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 };
};
Expand All @@ -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);
Expand Down Expand Up @@ -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<vtkPointSet> 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. */
Expand Down
14 changes: 8 additions & 6 deletions test/t8_cmesh/t8_gtest_cmesh_readmshfile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <t8_cmesh/t8_cmesh.h>
#include <t8_cmesh/t8_cmesh_io/t8_cmesh_readmshfile.h>
#include <t8_cmesh/t8_cmesh_internal/t8_cmesh_trees.h>
#include "t8_test_data_dir.h"
#include <string>

/* In this file we test the msh file (gmsh) reader of the cmesh.
* Currently, we support version 2 and 4 ascii.
Expand All @@ -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. */
Expand All @@ -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");
Expand Down
10 changes: 6 additions & 4 deletions test/t8_cmesh/t8_gtest_cmesh_set_join_by_vertices.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "test/t8_cmesh_generator/t8_cmesh_example_sets.hxx"
#include <t8_geometry/t8_geometry_implementations/t8_geometry_linear.hxx>
#include <test/t8_gtest_macros.hxx>
#include "t8_test_data_dir.h"
#include <string>

#include <p8est_geometry.h>

Expand Down Expand Up @@ -277,17 +279,17 @@ 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);
t8_cmesh_destroy (&cmesh);
}

{
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);
Expand Down
25 changes: 25 additions & 0 deletions test/t8_test_data_dir.h.in
Original file line number Diff line number Diff line change
@@ -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@"