From 8a6d8815f41cd90302878c1b6ddebd9eeb37c7ba Mon Sep 17 00:00:00 2001 From: waqar-ukaea Date: Wed, 15 Oct 2025 13:35:27 +0100 Subject: [PATCH] Fixed test_no_geom to still compile when XDG compiled without libmesh support --- tests/test_no_geom.cpp | 44 +++++++++++++++++++----------------------- tests/util.h | 44 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/tests/test_no_geom.cpp b/tests/test_no_geom.cpp index efa2de6a..01408fb2 100644 --- a/tests/test_no_geom.cpp +++ b/tests/test_no_geom.cpp @@ -1,39 +1,35 @@ // testing includes #include #include +#include // xdg includes -#include "xdg/moab/mesh_manager.h" -#include "xdg/libmesh/mesh_manager.h" +#include "util.h" using namespace xdg; -TEST_CASE("Test MOAB Mesh Without Geometry") -{ - std::unique_ptr mesh_manager = std::make_unique(); - - mesh_manager->load_file("cube-mesh-no-geom.h5m"); - mesh_manager->init(); - // there will be two volumes: one for the cube and one for the implicit complement - REQUIRE(mesh_manager->num_volumes() == 2); - // one surface (the boundary of the mesh) separates the two volumes - REQUIRE(mesh_manager->num_surfaces() == 1); +TEST_CASE("Test Mesh Without Geometry") +{ + auto mesh_backend = GENERATE(MeshLibrary::MOAB, MeshLibrary::LIBMESH); - REQUIRE(mesh_manager->num_volume_elements() == 8814); -} + DYNAMIC_SECTION(fmt::format("Backend = {}", mesh_backend)) + { + check_mesh_library_supported(mesh_backend); // skip if backend not enabled at configuration time + auto mesh_manager = create_mesh_manager(mesh_backend); + REQUIRE(mesh_manager); -TEST_CASE("Test libMesh Mesh Without Geometry") -{ - std::unique_ptr mesh_manager = std::make_unique(); + const std::string file = std::string("cube-mesh-no-geom.") + + (mesh_backend == MeshLibrary::MOAB ? "h5m" : "exo"); - mesh_manager->load_file("cube-mesh-no-geom.exo"); - mesh_manager->init(); + mesh_manager->load_file(file); + mesh_manager->init(); - // there will be two volumes: one for the cube and one for the implicit complement - REQUIRE(mesh_manager->num_volumes() == 2); - // one surface (the boundary of the mesh) separates the two volumes - REQUIRE(mesh_manager->num_surfaces() == 1); + // there will be two volumes: one for the cube and one for the implicit complement + REQUIRE(mesh_manager->num_volumes() == 2); + // one surface (the boundary of the mesh) separates the two volumes + REQUIRE(mesh_manager->num_surfaces() == 1); - REQUIRE(mesh_manager->num_volume_elements() == 8814); + REQUIRE(mesh_manager->num_volume_elements() == 8814); + } } \ No newline at end of file diff --git a/tests/util.h b/tests/util.h index 2d5f6bc0..02205799 100644 --- a/tests/util.h +++ b/tests/util.h @@ -4,6 +4,7 @@ #include "xdg/constants.h" #include "xdg/ray_tracers.h" +#include "xdg/mesh_managers.h" #include "vulkan_probe.h" static std::random_device rd; @@ -15,6 +16,8 @@ inline double rand_double(double min, double max) return dis(gen); } +// Library availability checks + inline void check_ray_tracer_supported(xdg::RTLibrary rt) { #ifndef XDG_ENABLE_EMBREE if (rt == xdg::RTLibrary::EMBREE) { @@ -33,15 +36,44 @@ inline void check_ray_tracer_supported(xdg::RTLibrary rt) { #endif } -// Factory function to create ray tracer based on which library selected -inline std::shared_ptr create_raytracer(xdg::RTLibrary rt) { +inline void check_mesh_library_supported(xdg::MeshLibrary mesh) { + #ifndef XDG_ENABLE_MOAB + if (mesh == xdg::MeshLibrary::MOAB) { + SKIP("MOAB backend not built; skipping."); + } + #endif + + #ifndef XDG_ENABLE_LIBMESH + if (mesh == xdg::MeshLibrary::LIBMESH) { + SKIP("LibMesh backend not built; skipping."); + } + #endif +} + +// Factories + +inline std::unique_ptr +create_mesh_manager(xdg::MeshLibrary mesh) { + #ifdef XDG_ENABLE_MOAB + if (mesh == xdg::MeshLibrary::MOAB) + return std::make_unique(); + #endif + + #ifdef XDG_ENABLE_LIBMESH + if (mesh == xdg::MeshLibrary::LIBMESH) + return std::make_unique(); + #endif +} + +inline std::shared_ptr +create_raytracer(xdg::RTLibrary rt) { #ifdef XDG_ENABLE_EMBREE - if (rt == xdg::RTLibrary::EMBREE) + if (rt == xdg::RTLibrary::EMBREE) return std::make_shared(); #endif - + #ifdef XDG_ENABLE_GPRT - if (rt == xdg::RTLibrary::GPRT) + if (rt == xdg::RTLibrary::GPRT) return std::make_shared(); #endif -} \ No newline at end of file +}