ACMX 2.136.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
playlist_tests.cpp
Go to the documentation of this file.
1#include "app/playlist.hpp"
2
3#include <chrono>
4#include <fstream>
5#include <iostream>
6#include <sstream>
7#include <stdexcept>
8#include <string>
9#include <system_error>
10
11namespace {
12 namespace fs = std::filesystem;
13
15 public:
17 const auto suffix = std::chrono::steady_clock::now()
18 .time_since_epoch()
19 .count();
20 path = fs::temp_directory_path() /
21 ("acmxvk-playlist-" + std::to_string(suffix));
22 fs::create_directories(path);
23 }
24
26 std::error_code error;
27 fs::remove_all(path, error);
28 }
29
32
33 fs::path path;
34 };
35
36 void write_text(const fs::path &path, const std::string &text) {
37 std::ofstream output(path);
38 if (!output) {
39 throw std::runtime_error("could not create playlist test file");
40 }
41 output << text;
42 }
43
44 void expect(bool condition, const std::string &message) {
45 if (!condition) {
46 throw std::runtime_error(message);
47 }
48 }
49} // namespace
50
51int main() {
52 try {
53 TemporaryDirectory temporary;
54 const fs::path library = temporary.path / "library";
55 const std::vector<fs::path> shaders{
56 library / "orphan.frag.spv", library / "one.frag.spv",
57 library / "compute/two.comp.spv"};
58
59 expect(acmxvk::find_shader_path(shaders, library, " one.frag ") ==
60 shaders[1],
61 "fragment shader name was not resolved");
62 expect(acmxvk::find_shader_path(shaders, library,
63 "compute/two.comp") == shaders[2],
64 "relative compute shader path was not resolved");
65
66 const fs::path playlist_path = temporary.path / "test.playlist.txt";
67 write_text(playlist_path,
68 "orphan.frag\n"
69 "[Warm]\n"
70 "one.frag\n"
71 "missing.frag\n"
72 "[Compute]\n"
73 "compute/two.comp\n"
74 "[Empty]\n"
75 "missing-again.frag\n");
76 std::ostringstream warnings;
77 const std::vector<acmxvk::PlaylistNode> playlist =
78 acmxvk::load_playlist(playlist_path, shaders, library, warnings);
79 expect(playlist.size() == 3, "empty playlist node was not removed");
80 expect(playlist[0].name == "Default" &&
81 playlist[0].shaders ==
82 std::vector<fs::path>{shaders[0]},
83 "default playlist entries were not retained");
84 expect(playlist[1].name == "Warm" &&
85 playlist[1].shaders ==
86 std::vector<fs::path>{shaders[1]},
87 "named fragment node was parsed incorrectly");
88 expect(playlist[2].name == "Compute" &&
89 playlist[2].shaders ==
90 std::vector<fs::path>{shaders[2]},
91 "named compute node was parsed incorrectly");
93 "playlist shader count is incorrect");
94 expect(warnings.str().find("missing.frag") != std::string::npos,
95 "missing shader warning was not emitted");
96
97 const fs::path malformed_path = temporary.path / "malformed.txt";
98 write_text(malformed_path, "[Broken\none.frag\n");
99 bool rejected_malformed = false;
100 try {
101 static_cast<void>(acmxvk::load_playlist(
102 malformed_path, shaders, library, warnings));
103 } catch (const std::runtime_error &) {
104 rejected_malformed = true;
105 }
106 expect(rejected_malformed, "malformed playlist node was accepted");
107 } catch (const std::exception &error) {
108 std::cerr << "playlist test failed: " << error.what() << '\n';
109 return 1;
110 }
111 return 0;
112}
int main(int argc, char **argv)
Application entry point.
TemporaryDirectory & operator=(const TemporaryDirectory &)=delete
TemporaryDirectory(const TemporaryDirectory &)=delete
std::vector< PlaylistNode > load_playlist(const fs::path &playlist_path, const std::vector< fs::path > &available_shaders, const fs::path &library_directory, std::ostream &warning_output)
std::size_t playlist_shader_count(const std::vector< PlaylistNode > &playlist) noexcept
fs::path find_shader_path(const std::vector< fs::path > &available_shaders, const fs::path &library_directory, std::string name)
void write_text(const fs::path &path, const std::string &text)
void expect(bool condition, const std::string &message)