ACMX 2.136.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
output_paths_tests.cpp
Go to the documentation of this file.
2
3#include <chrono>
4#include <fstream>
5#include <iostream>
6#include <stdexcept>
7#include <string>
8#include <system_error>
9
10namespace {
11 namespace fs = std::filesystem;
12
14 public:
16 const auto suffix = std::chrono::steady_clock::now()
17 .time_since_epoch()
18 .count();
19 path = fs::temp_directory_path() /
20 ("acmxvk-output-paths-" + std::to_string(suffix));
21 fs::create_directories(path);
22 }
23
25 std::error_code error;
26 fs::remove_all(path, error);
27 }
28
31
32 fs::path path;
33 };
34
35 void expect(bool condition, const std::string &message) {
36 if (!condition) {
37 throw std::runtime_error(message);
38 }
39 }
40
41 void expect_suffix(const fs::path &path, std::string_view suffix,
42 const std::string &message) {
43 expect(path.filename().string().ends_with(suffix), message);
44 }
45} // namespace
46
47int main() {
48 try {
49 TemporaryDirectory temporary;
50 expect(acmxvk::output_frame_directory("movie.mp4", "png") ==
51 fs::path(".") / "video_file-movie.mp4-png",
52 "relative output directory is incorrect");
54 (temporary.path / "movie.mp4").string(), "generate") ==
55 temporary.path / "video_file-movie.mp4-generate",
56 "parent output directory was not retained");
57
58 const fs::path output_directory = temporary.path / "nested/frames";
59 acmxvk::create_output_directory(output_directory);
60 expect(fs::is_directory(output_directory),
61 "output directory was not created");
62 expect(acmxvk::frame_path(output_directory, 42) ==
63 output_directory / "frame-00000042.png",
64 "numbered PNG frame path is incorrect");
65
67 ".png",
68 "PNG snapshot extension is incorrect");
70 ".webp",
71 "WebP snapshot extension is incorrect");
73 ".tiff",
74 "TIFF snapshot extension is incorrect");
76 ".raw",
77 "raw snapshot extension is incorrect");
78
79 std::uint64_t counter = 7;
80 const auto timestamp = std::chrono::system_clock::from_time_t(0);
81 const fs::path first = acmxvk::snapshot_path(
82 temporary.path, 1920, 1080, counter,
84 expect_suffix(first, "-1920x1080-7.png",
85 "snapshot dimensions or counter are incorrect");
86 std::ofstream(first) << "collision";
87 const fs::path second = acmxvk::snapshot_path(
88 temporary.path, 1920, 1080, counter,
90 expect(counter == 8, "snapshot collision did not advance the counter");
91 expect_suffix(second, "-1920x1080-8.png",
92 "collision-safe snapshot path is incorrect");
93
94 const fs::path regular_file = temporary.path / "not-a-directory";
95 std::ofstream(regular_file) << "file";
96 bool rejected_file = false;
97 try {
99 } catch (const std::runtime_error &) {
100 rejected_file = true;
101 }
102 expect(rejected_file, "regular file was accepted as an output directory");
103 } catch (const std::exception &error) {
104 std::cerr << "output path test failed: " << error.what() << '\n';
105 return 1;
106 }
107 return 0;
108}
int main(int argc, char **argv)
Application entry point.
TemporaryDirectory & operator=(const TemporaryDirectory &)=delete
fs::path snapshot_path(const fs::path &directory, std::uint32_t width, std::uint32_t height, std::uint64_t &counter, SnapshotFormat format, std::chrono::system_clock::time_point timestamp)
fs::path output_frame_directory(const std::string &filename, std::string_view suffix)
fs::path frame_path(const fs::path &directory, std::uint64_t index)
void create_output_directory(const fs::path &directory)
std::string_view snapshot_extension(SnapshotFormat format) noexcept
void expect(bool condition, const std::string &message)
void expect_suffix(const fs::path &path, std::string_view suffix, const std::string &message)