Lagrange
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
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
111template <typename MeshType>
112std::unique_ptr<MeshType> load_mesh(const fs::path& relative_path)
113{
114 auto result = lagrange::io::load_mesh<MeshType>(get_data_path(relative_path));
115 REQUIRE(result);
116 return result;
117}
118extern template LA_TESTING_API std::unique_ptr<TriangleMesh3D> load_mesh(const fs::path&);
119extern template LA_TESTING_API std::unique_ptr<QuadMesh3D> load_mesh(const fs::path&);
120
133template <typename Scalar, typename Index>
134SurfaceMesh<Scalar, Index> load_surface_mesh(const fs::path& relative_path)
135{
136 auto full_path = get_data_path(relative_path);
137 REQUIRE(lagrange::fs::exists(full_path));
138 return lagrange::io::load_mesh<SurfaceMesh<Scalar, Index>>(full_path);
139}
140
150LA_TESTING_API void setup_mkl_reproducibility();
151
152} // namespace testing
153} // namespace lagrange
A general purpose polygonal mesh class.
Definition: SurfaceMesh.h:66
Main namespace for Lagrange.
Definition: AABBIGL.h:30