Lagrange
Loading...
Searching...
No Matches
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/load_mesh.h>
23#ifdef LAGRANGE_ENABLE_LEGACY_FUNCTIONS
24 #include <lagrange/io/legacy/load_mesh.h>
25#endif
26#include <lagrange/testing/api.h>
27#include <lagrange/utils/assert.h>
28
29#include <catch2/catch_test_macros.hpp>
30
40#define LA_REQUIRE_THROWS(...) \
41 do { \
42 bool __was_enabled = lagrange::is_breakpoint_enabled(); \
43 lagrange::set_breakpoint_enabled(false); \
44 REQUIRE_THROWS(__VA_ARGS__); \
45 lagrange::set_breakpoint_enabled(__was_enabled); \
46 } while (0)
47
58#define LA_REQUIRE_THROWS_WITH(x, y) \
59 do { \
60 bool __was_enabled = lagrange::is_breakpoint_enabled(); \
61 lagrange::set_breakpoint_enabled(false); \
62 REQUIRE_THROWS_WITH(x, y); \
63 lagrange::set_breakpoint_enabled(__was_enabled); \
64 } while (0)
65
75#define LA_CHECK_THROWS(...) \
76 do { \
77 bool __was_enabled = lagrange::is_breakpoint_enabled(); \
78 lagrange::set_breakpoint_enabled(false); \
79 CHECK_THROWS(__VA_ARGS__); \
80 lagrange::set_breakpoint_enabled(__was_enabled); \
81 } while (0)
82
83
84namespace lagrange {
85namespace testing {
86
92LA_TESTING_API fs::path get_data_dir();
93
101LA_TESTING_API fs::path get_test_output_dir();
102
111LA_TESTING_API fs::path get_data_path(const fs::path& relative_path);
112
121LA_TESTING_API fs::path get_data_folder(const fs::path& relative_path);
122
131LA_TESTING_API fs::path get_test_output_path(const fs::path& relative_path);
132
142#ifdef LAGRANGE_ENABLE_LEGACY_FUNCTIONS
143template <typename MeshType>
144std::unique_ptr<MeshType> load_mesh(const fs::path& relative_path)
145{
146 auto result = lagrange::io::load_mesh<MeshType>(get_data_path(relative_path));
147 REQUIRE(result);
148 return result;
149}
150extern template LA_TESTING_API std::unique_ptr<TriangleMesh3D> load_mesh(const fs::path&);
151extern template LA_TESTING_API std::unique_ptr<QuadMesh3D> load_mesh(const fs::path&);
152#endif
153
166template <typename Scalar, typename Index>
167SurfaceMesh<Scalar, Index> load_surface_mesh(const fs::path& relative_path)
168{
169 auto full_path = get_data_path(relative_path);
170 REQUIRE(lagrange::fs::exists(full_path));
171 io::LoadOptions options;
172 options.quiet = true;
173 return lagrange::io::load_mesh<SurfaceMesh<Scalar, Index>>(full_path, options);
174}
175
185LA_TESTING_API void setup_mkl_reproducibility();
186
194LA_TESTING_API void disable_windows_error_dialogs();
195
196} // namespace testing
197} // namespace lagrange
MeshType load_mesh(std::istream &input_stream, const LoadOptions &options={})
Load a mesh from a stream.
Definition load_mesh.cpp:39
Main namespace for Lagrange.