package spa import ( "encoding/binary" "encoding/hex" "errors" "testing" ) // Golden vectors are the bytes produced by the SPA reference builder // (spa/pod/builder.h, libspa 0.2 / PipeWire 1.6.9) for the same parameters // via spa_pod_builder_add_object / SPA_POD_CHOICE_* on amd64. const ( goldenEnumFormatSingle = "b80000000f00000003000400030000000100000000000000040000000300000002000000000000000200000000000000040000000300000001000000000000000100020000000000040000000300000008000000000000000300020000000000080000000a00000040010000f00000000400020000000000080000000b0000000000000001000000050002000000000028000000130000000100000000000000080000000b0000003c0000000100000001000000010000003c00000001000000" goldenEnumFormatMulti = "d00000000f000000030004000300000001000000000000000400000003000000020000000000000002000000000000000400000003000000010000000000000001000200000000001c000000130000000300000000000000040000000300000008000000080000000c000000000000000300020000000000080000000a00000080070000380400000400020000000000080000000b0000000000000001000000050002000000000028000000130000000100000000000000080000000b000000900000000100000001000000010000009000000001000000" goldenBuffers = "c00000000f000000040004000500000001000000000000001c0000001300000001000000000000000400000004000000080000000200000010000000000000000200000000000000040000000400000001000000000000000300000000000000040000000400000000b004000000000004000000000000000400000004000000000500000000000005000000000000000400000004000000100000000000000006000000000000001400000013000000040000000000000004000000040000000400000000000000" goldenMetaHeader = "380000000f0000000500040006000000010000000000000004000000030000000100000000000000020000000000000004000000040000002000000000000000" ) func mustHex(t testing.TB, s string) []byte { t.Helper() b, err := hex.DecodeString(s) if err != nil { t.Fatal(err) } return b } func TestVideoEnumFormatGoldenSingle(t *testing.T) { var dst [512]byte got, err := VideoEnumFormat(dst[:], 320, 240, 60, VideoFormatBGRx) if err != nil { t.Fatal(err) } if want := mustHex(t, goldenEnumFormatSingle); hex.EncodeToString(got) != hex.EncodeToString(want) { t.Fatalf("got %x\nwant %x", got, want) } } func TestVideoEnumFormatGoldenMulti(t *testing.T) { var dst [512]byte got, err := VideoEnumFormat(dst[:], 1920, 1080, 144, VideoFormatBGRx, VideoFormatBGRA) if err != nil { t.Fatal(err) } if want := mustHex(t, goldenEnumFormatMulti); hex.EncodeToString(got) != hex.EncodeToString(want) { t.Fatalf("got %x\nwant %x", got, want) } } func TestVideoBuffersGolden(t *testing.T) { var dst [512]byte got, err := VideoBuffers(dst[:], 320*240*4, 320*4, 2, 8, 16, 1<