video config construction refactoring
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package flowdef
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const testVideoID = "5fbec3b1-1b0f-417d-9059-8b94a47197ed"
|
||||
|
||||
func TestNewV210Video(t *testing.T) {
|
||||
definition, err := NewV210Video(testVideoID, 1920, 1080, Rational{Numerator: 30000, Denominator: 1001})
|
||||
if err != nil {
|
||||
t.Fatalf("NewV210Video: %v", err)
|
||||
}
|
||||
if definition.ID != testVideoID {
|
||||
t.Fatalf("ID = %q, want %q", definition.ID, testVideoID)
|
||||
}
|
||||
if definition.Format != FormatVideo || definition.MediaType != MediaTypeV210 {
|
||||
t.Fatalf("format/media type = %q/%q", definition.Format, definition.MediaType)
|
||||
}
|
||||
if len(definition.Components) != 3 {
|
||||
t.Fatalf("component count = %d, want 3", len(definition.Components))
|
||||
}
|
||||
if definition.Parents == nil {
|
||||
t.Fatal("Parents is nil; want an empty JSON array")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewV210VideoRejectsInvalidWidth(t *testing.T) {
|
||||
_, err := NewV210Video(testVideoID, 1919, 1080, Rational{Numerator: 25, Denominator: 1})
|
||||
if err == nil || !strings.Contains(err.Error(), "divisible by 6") {
|
||||
t.Fatalf("error = %v, want width divisibility error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseV210Video(t *testing.T) {
|
||||
want, err := NewV210Video(testVideoID, 1920, 1080, Rational{Numerator: 25, Denominator: 1})
|
||||
if err != nil {
|
||||
t.Fatalf("NewV210Video: %v", err)
|
||||
}
|
||||
data, err := json.Marshal(want)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal: %v", err)
|
||||
}
|
||||
|
||||
got, err := ParseV210Video(data)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseV210Video: %v", err)
|
||||
}
|
||||
if got.ID != want.ID || got.FrameWidth != want.FrameWidth || got.GrainRate != want.GrainRate {
|
||||
t.Fatalf("parsed definition = %+v, want %+v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseV210VideoRejectsAudio(t *testing.T) {
|
||||
data := []byte(`{
|
||||
"id":"5fbec3b1-1b0f-417d-9059-8b94a47197ed",
|
||||
"format":"urn:x-nmos:format:audio",
|
||||
"media_type":"audio/float32"
|
||||
}`)
|
||||
|
||||
_, err := ParseV210Video(data)
|
||||
if err == nil || !strings.Contains(err.Error(), "format must be") {
|
||||
t.Fatalf("error = %v, want video format error", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user