video config construction refactoring

This commit is contained in:
Dmitry Sergeev
2026-09-16 21:31:12 +03:00
parent 765aa8d3e1
commit c9bdfec3b0
7 changed files with 406 additions and 199 deletions
+63
View File
@@ -2,8 +2,12 @@ package main
import (
"bytes"
"encoding/json"
"os"
"strings"
"testing"
"mxl-pattern-generator/internal/flowdef"
)
func TestParseArgsHelpStopsBeforeValidation(t *testing.T) {
@@ -99,3 +103,62 @@ func TestListPatternsIsSorted(t *testing.T) {
t.Fatalf("patterns are not sorted: %q", text)
}
}
func TestBuildVideoConfigFromArgs(t *testing.T) {
args := appArgs{
videoUUID: "5fbec3b1-1b0f-417d-9059-8b94a47197ed",
videoWidth: 1920,
videoHeight: 1080,
videoFPS: "29.97",
pattern: "ebu75",
}
cfg, err := buildVideoConfig(args)
if err != nil {
t.Fatalf("buildVideoConfig: %v", err)
}
if cfg.Width() != 1920 || cfg.Height() != 1080 {
t.Fatalf("dimensions = %dx%d, want 1920x1080", cfg.Width(), cfg.Height())
}
if cfg.Rate().Num != 30000 || cfg.Rate().Den != 1001 {
t.Fatalf("rate = %d/%d, want 30000/1001", cfg.Rate().Num, cfg.Rate().Den)
}
}
func TestBuildVideoConfigFromFile(t *testing.T) {
definition, err := flowdef.NewV210Video(
"5fbec3b1-1b0f-417d-9059-8b94a47197ed",
3840,
2160,
flowdef.Rational{Numerator: 60000, Denominator: 1001},
)
if err != nil {
t.Fatalf("NewV210Video: %v", err)
}
data, err := json.Marshal(definition)
if err != nil {
t.Fatalf("json.Marshal: %v", err)
}
path := t.TempDir() + "/video.json"
if err := os.WriteFile(path, data, 0o600); err != nil {
t.Fatalf("os.WriteFile: %v", err)
}
cfg, err := buildVideoConfig(appArgs{
videoFlowDefFile: path,
pattern: "smpte",
// These values must be ignored when a definition file is supplied.
videoWidth: 1920,
videoHeight: 1080,
videoFPS: "25",
})
if err != nil {
t.Fatalf("buildVideoConfig: %v", err)
}
if cfg.Width() != 3840 || cfg.Height() != 2160 {
t.Fatalf("dimensions = %dx%d, want file values 3840x2160", cfg.Width(), cfg.Height())
}
if cfg.Rate().Num != 60000 || cfg.Rate().Den != 1001 {
t.Fatalf("rate = %d/%d, want file value 60000/1001", cfg.Rate().Num, cfg.Rate().Den)
}
}