Lagrange
common.h
1/*
2 * Copyright 2020 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14// An alternative to injecting asset locations as command line macros,
15// is using a generated header.
16#ifdef LA_TESTING_USE_CONFIG
17 #include <lagrange/testing/public_config.h>
18#endif
19
20#include <lagrange/SurfaceMesh.h>
21#include <lagrange/fs/filesystem.h>
22#include <lagrange/io/legacy/load_mesh.h>
23#include <lagrange/io/load_mesh.h>
24#include <lagrange/testing/api.h>
25#include <lagrange/utils/assert.h>
26
27#include <catch2/catch_test_macros.hpp>
28
38#define LA_REQUIRE_THROWS(...) \
39 do { \
40 bool __was_enabled = lagrange::is_breakpoint_enabled(); \
41 lagrange::set_breakpoint_enabled(false); \
42 REQUIRE_THROWS(__VA_ARGS__); \
43 lagrange::set_breakpoint_enabled(__was_enabled); \
44 } while (0)
45
56#define LA_REQUIRE_THROWS_WITH(x, y) \
57 do { \
58 bool __was_enabled = lagrange::is_breakpoint_enabled(); \
59 lagrange::set_breakpoint_enabled(false); \
60 REQUIRE_THROWS_WITH(x, y); \
61 lagrange::set_breakpoint_enabled(__was_enabled); \
62 } while (0)
63
73#define LA_CHECK_THROWS(...) \
74 do { \
75 bool __was_enabled = lagrange::is_breakpoint_enabled(); \
76 lagrange::set_breakpoint_enabled(false); \
77 CHECK_THROWS(__VA_ARGS__); \
78 lagrange::set_breakpoint_enabled(__was_enabled); \
79 } while (0)
80
81
82namespace lagrange {
83namespace testing {
84
90LA_TESTING_API fs::path get_data_dir();
91
100LA_TESTING_API fs::path get_data_path(const fs::path& relative_path);
101
110LA_TESTING_API fs::path get_data_folder(const fs::path& relative_path);
111
121template <typename MeshType>
122std::unique_ptr<MeshType> load_mesh(const fs::path& relative_path)
123{
124 auto result = lagrange::io::load_mesh<MeshType>(get_data_path(relative_path));
125 REQUIRE(result);
126 return result;
127}
128extern template LA_TESTING_API std::unique_ptr<TriangleMesh3D> load_mesh(const fs::path&);
129extern template LA_TESTING_API std::unique_ptr<QuadMesh3D> load_mesh(const fs::path&);
130
143template <typename Scalar, typename Index>
144SurfaceMesh<Scalar, Index> load_surface_mesh(const fs::path& relative_path)
145{
146 auto full_path = get_data_path(relative_path);
147 REQUIRE(lagrange::fs::exists(full_path));
148 return lagrange::io::load_mesh<SurfaceMesh<Scalar, Index>>(full_path);
149}
150
160LA_TESTING_API void setup_mkl_reproducibility();
161
162} // namespace testing
163} // namespace lagrange
A general purpose polygonal mesh class.
Definition: SurfaceMesh.h:66
Main namespace for Lagrange.
Definition: AABBIGL.h:30