Cpp-Processing
filesystem-tests.h
1 #define CATCH_CONFIG_MAIN
2 #include <catch2/catch_test_macros.hpp>
3 #include "filesystem-utils.h"
4 #include "FileRef.h"
5 #include <string>
6 #include <algorithm>
7 #include <set>
8 #include <iostream>
9 #include "IOFileRef.h"
10 #include <boost/log/trivial.hpp>
11 #include "executable-utils.h"
12 
13 
14 const std::filesystem::path base_path = celantur::get_executable_dir()/"test-assets/core";
15 
16 TEST_CASE("Test images", "[core]") {
17  auto images = celantur::get_images_recursively(base_path/"filesystem");
18  REQUIRE(images.size() == 4);
19  std::set<std::string> expected{
20  base_path/"filesystem/img2.jpeg",
21  base_path/"filesystem/folder/img1.jpg",
22  base_path/"filesystem/folder/img3.JPG",
23  base_path/"filesystem/folder/subfolder/img4.png"
24  };
25 
26  for (const auto& image : images) {
27  BOOST_LOG_TRIVIAL(info) << image.string() ;
28  auto found = std::find(expected.begin(), expected.end(), image.string()) != expected.end();
29  REQUIRE(found);
30  }
31 }
32 
33 TEST_CASE("Test videos", "[core]") {
34  auto videos = celantur::get_videos_recursively(base_path/"filesystem");
35  REQUIRE(videos.size() == 2);
36  std::set<std::string> expected{
37  base_path/"filesystem/folder/vid.MP4",
38  base_path/"filesystem/folder/subfolder/video.avi"
39  };
40 
41  for (const auto& video : videos) {
42  BOOST_LOG_TRIVIAL(info) << video.string() ;
43  auto found = std::find(expected.begin(), expected.end(), video.string()) != expected.end();
44  REQUIRE(found);
45  }
46 }
47 
48 TEST_CASE("Test IOFileRef", "[core]") {
49  celantur::FileRef input_fr(celantur::get_executable_dir()/"test-assets/filesystem/folder/subfolder/img4.png");
50  celantur::IOFileRef io_fr(celantur::get_executable_dir()/"test-assets/filesystem", "test-assets/output", input_fr);
51  REQUIRE(io_fr.input_file_ref().string() == "test-assets/filesystem/folder/subfolder/img4.png");
52  REQUIRE(io_fr.output_file_ref().string() == "test-assets/output/folder/subfolder/img4.png");
53 }
54