#include "RuntimeStateJson.h" #include #include #include #include #include namespace { int gFailures = 0; void ExpectContains(const std::string& text, const std::string& fragment, const std::string& message) { if (text.find(fragment) != std::string::npos) return; ++gFailures; std::cerr << "FAIL: " << message << "\n"; } std::filesystem::path MakeTestRoot() { const auto stamp = std::chrono::steady_clock::now().time_since_epoch().count(); const std::filesystem::path root = std::filesystem::temp_directory_path() / ("render-cadence-state-json-tests-" + std::to_string(stamp)); std::filesystem::create_directories(root); return root; } void WriteFile(const std::filesystem::path& path, const std::string& contents) { std::filesystem::create_directories(path.parent_path()); std::ofstream output(path, std::ios::binary); output << contents; } } int main() { RenderCadenceCompositor::AppConfig config = RenderCadenceCompositor::DefaultAppConfig(); config.outputVideoFormat = "1080p"; config.outputFrameRate = "59.94"; RenderCadenceCompositor::CadenceTelemetrySnapshot telemetry; telemetry.renderFps = 59.94; telemetry.shaderBuildsCommitted = 1; const std::filesystem::path root = MakeTestRoot(); WriteFile(root / "solid-color" / "shader.slang", "float4 shadeVideo(float2 uv) { return float4(uv, 0.0, 1.0); }\n"); WriteFile(root / "solid-color" / "shader.json", R"({ "id": "solid-color", "name": "Solid Color", "description": "A single color shader.", "category": "Generator", "entryPoint": "shadeVideo", "parameters": [ { "id": "color", "label": "Color", "description": "Output color.", "type": "color", "default": [1.0, 0.25, 0.5, 1.0], "min": [0.0, 0.0, 0.0, 0.0], "max": [1.0, 1.0, 1.0, 1.0], "step": [0.01, 0.01, 0.01, 0.01] } ] })"); RenderCadenceCompositor::SupportedShaderCatalog shaderCatalog; std::string error; ExpectContains(shaderCatalog.Load(root, 4, error) ? "loaded" : error, "loaded", "test shader catalog should load"); RenderCadenceCompositor::RuntimeLayerModel layerModel; layerModel.InitializeSingleLayer(shaderCatalog, "solid-color", error); RuntimeShaderArtifact artifact; artifact.shaderId = "solid-color"; artifact.displayName = "Solid Color"; artifact.fragmentShaderSource = "void main(){}"; artifact.message = "Runtime shader committed."; layerModel.MarkBuildReady(artifact, error); const RenderCadenceCompositor::RuntimeLayerModelSnapshot layerSnapshot = layerModel.Snapshot(); const std::string json = RenderCadenceCompositor::RuntimeStateToJson(RenderCadenceCompositor::RuntimeStateJsonInput{ config, telemetry, 8080, true, "DeckLink scheduled output running.", shaderCatalog, layerSnapshot }); ExpectContains(json, "\"shaders\":[{\"id\":\"solid-color\"", "state JSON should include supported shaders"); ExpectContains(json, "\"layerCount\":1", "state JSON should expose the display layer count"); ExpectContains(json, "\"layers\":[{\"id\":\"runtime-layer-1\"", "state JSON should expose the active display layer"); ExpectContains(json, "\"parameters\":[{\"id\":\"color\"", "state JSON should expose active shader parameters"); ExpectContains(json, "\"type\":\"color\"", "state JSON should serialize parameter types for the UI"); ExpectContains(json, "\"width\":1920", "state JSON should expose output width"); ExpectContains(json, "\"height\":1080", "state JSON should expose output height"); std::filesystem::remove_all(root); if (gFailures != 0) { std::cerr << gFailures << " RenderCadenceCompositorRuntimeStateJson test failure(s).\n"; return 1; } std::cout << "RenderCadenceCompositorRuntimeStateJson tests passed.\n"; return 0; }