ACMX 2.139.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().time_since_epoch().count();
17 path = fs::temp_directory_path() / ("acmxvk-output-paths-" + std::to_string(suffix));
18 fs::create_directories(path);
19 }
20
22 std::error_code error;
23 fs::remove_all(path, error);
24 }
25
28
29 fs::path path;
30 };
31
32 void expect(bool condition, const std::string &message) {
33 if (!condition) {
34 throw std::runtime_error(message);
35 }
36 }
37
38 void expect_suffix(const fs::path &path, std::string_view suffix, const std::string &message) { expect(path.filename().string().ends_with(suffix), message); }
39} // namespace
40
41int main() {
42 try {
43 TemporaryDirectory temporary;
44 expect(acmxvk::output_frame_directory("movie.mp4", "png") == fs::path(".") / "video_file-movie.mp4-png", "relative output directory is incorrect");
45 expect(acmxvk::output_frame_directory((temporary.path / "movie.mp4").string(), "generate") == temporary.path / "video_file-movie.mp4-generate", "parent output directory was not retained");
46
47 const fs::path output_directory = temporary.path / "nested/frames";
48 acmxvk::create_output_directory(output_directory);
49 expect(fs::is_directory(output_directory), "output directory was not created");
50 expect(acmxvk::frame_path(output_directory, 42) == output_directory / "frame-00000042.png", "numbered PNG frame path is incorrect");
51
52 expect(acmxvk::snapshot_extension(acmxvk::SnapshotFormat::Png) == ".png", "PNG snapshot extension is incorrect");
53 expect(acmxvk::snapshot_extension(acmxvk::SnapshotFormat::WebP) == ".webp", "WebP snapshot extension is incorrect");
54 expect(acmxvk::snapshot_extension(acmxvk::SnapshotFormat::Tiff) == ".tiff", "TIFF snapshot extension is incorrect");
55 expect(acmxvk::snapshot_extension(acmxvk::SnapshotFormat::Raw) == ".raw", "raw snapshot extension is incorrect");
56
57 std::uint64_t counter = 7;
58 const auto timestamp = std::chrono::system_clock::from_time_t(0);
59 const fs::path first = acmxvk::snapshot_path(temporary.path, 1920, 1080, counter, acmxvk::SnapshotFormat::Png, timestamp);
60 expect_suffix(first, "-1920x1080-7.png", "snapshot dimensions or counter are incorrect");
61 std::ofstream(first) << "collision";
62 const fs::path second = acmxvk::snapshot_path(temporary.path, 1920, 1080, counter, acmxvk::SnapshotFormat::Png, timestamp);
63 expect(counter == 8, "snapshot collision did not advance the counter");
64 expect_suffix(second, "-1920x1080-8.png", "collision-safe snapshot path is incorrect");
65
66 const fs::path regular_file = temporary.path / "not-a-directory";
67 std::ofstream(regular_file) << "file";
68 bool rejected_file = false;
69 try {
71 } catch (const std::runtime_error &) {
72 rejected_file = true;
73 }
74 expect(rejected_file, "regular file was accepted as an output directory");
75 } catch (const std::exception &error) {
76 std::cerr << "output path test failed: " << error.what() << '\n';
77 return 1;
78 }
79 return 0;
80}
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)