Wildmeshing Toolkit
test_component_import_cache.cpp
Go to the documentation of this file.
1 #include <catch2/catch_test_macros.hpp>
2 #include <nlohmann/json.hpp>
6 #include <wmtk/components/utils/Paths.hpp>
7 
8 using namespace wmtk::components::utils;
10 
11 const std::filesystem::path data_dir = WMTK_DATA_DIR;
12 
13 TEST_CASE("component_import_cache", "[components][import_cache]")
14 {
15  wmtk::io::Cache cache("wmtk_cache", ".");
16 
17  // input
18  {
19  const std::filesystem::path input_file = data_dir / "small.msh";
20  json component_json = {
21  {"name", "input_mesh"},
22  {"file", input_file.string()},
23  {"ignore_z", false},
24  {"tetrahedron_attributes", json::array()}};
25 
26 
27  CHECK_NOTHROW(wmtk::components::input(Paths(), component_json, cache));
28  }
29 
30  wmtk::io::Cache cache_dump("wmtk_dump", ".");
31 
32  // export cache
33  {
34  json o;
35  o["folder"] = cache_dump.get_cache_path() / "exported_cache";
36 
37  CHECK_NOTHROW(wmtk::components::export_cache(Paths(), o, cache));
38  }
39 
40  wmtk::io::Cache cache2("wmtk_cache_from_import", ".");
41  // import cache
42  {
43  json o;
44  o["folder"] = cache_dump.get_cache_path() / "exported_cache";
45 
46  CHECK_NOTHROW(wmtk::components::import_cache(Paths(), o, cache2));
47  }
48 
49  CHECK(cache.equals(cache2));
50 }
std::filesystem::path get_cache_path() const
Get the path of the cache folder.
Definition: Cache.cpp:146
bool equals(const Cache &o)
Compare two caches for equality.
Definition: Cache.cpp:311
void import_cache(const utils::Paths &paths, const nlohmann::json &j, io::Cache &cache)
void export_cache(const utils::Paths &paths, const nlohmann::json &j, io::Cache &cache)
TEST_CASE("component_import_cache", "[components][import_cache]")
const std::filesystem::path data_dir
nlohmann::json json
nlohmann::json json
Definition: input.cpp:9