From e77652bf89bf1f1e55174cd61a745cf13ca31e48 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Tue, 25 Nov 2025 08:09:10 +0900 Subject: [PATCH] internal/pipewire: move test data to files These get very big later on, and would be painful to represent as the compound literal. Signed-off-by: Ophestra --- internal/pipewire/client_test.go | 400 +----------------- internal/pipewire/core_test.go | 9 +- internal/pipewire/header_test.go | 36 +- internal/pipewire/pipewire_test.go | 17 + .../testdata/00-sendmsg00-message00-header | Bin 0 -> 16 bytes .../testdata/01-sendmsg00-message00-POD | Bin 0 -> 24 bytes .../testdata/02-sendmsg00-message01-header | Bin 0 -> 16 bytes .../testdata/03-sendmsg00-message01-POD | Bin 0 -> 1536 bytes 8 files changed, 29 insertions(+), 433 deletions(-) create mode 100644 internal/pipewire/pipewire_test.go create mode 100644 internal/pipewire/testdata/00-sendmsg00-message00-header create mode 100644 internal/pipewire/testdata/01-sendmsg00-message00-POD create mode 100644 internal/pipewire/testdata/02-sendmsg00-message01-header create mode 100644 internal/pipewire/testdata/03-sendmsg00-message01-POD diff --git a/internal/pipewire/client_test.go b/internal/pipewire/client_test.go index 744c518..d7f723e 100644 --- a/internal/pipewire/client_test.go +++ b/internal/pipewire/client_test.go @@ -8,405 +8,7 @@ import ( func TestClientUpdateProperties(t *testing.T) { encodingTestCases[pipewire.ClientUpdateProperties, *pipewire.ClientUpdateProperties]{ - {"sample", []byte{ - // ClientUpdateProperties: size - 0xf8, 5, 0, 0, - // ClientUpdateProperties: struct - 0xe, 0, 0, 0, - - // ClientUpdateProperties.Props: size - 0xf0, 5, 0, 0, - // ClientUpdateProperties.Props: struct - 0xe, 0, 0, 0, - - // ClientUpdateProperties.Props.NItems: size - 4, 0, 0, 0, - // ClientUpdateProperties.Props.NItems: int - 4, 0, 0, 0, - 0x1e, 0, 0, 0, - 0, 0, 0, 0, - - // ClientUpdateProperties.Props.Items - - 0x11, 0, 0, 0, - 8, 0, 0, 0, - 0x72, 0x65, 0x6d, 0x6f, - 0x74, 0x65, 0x2e, 0x69, - 0x6e, 0x74, 0x65, 0x6e, - 0x74, 0x69, 0x6f, 0x6e, - 0, 0, 0, 0, - 0, 0, 0, 0, - - 8, 0, 0, 0, - 8, 0, 0, 0, - 0x6d, 0x61, 0x6e, 0x61, - 0x67, 0x65, 0x72, 0, - - 0x11, 0, 0, 0, - 8, 0, 0, 0, - 0x61, 0x70, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, - 0x6e, 0x61, 0x6d, 0x65, - 0, 0, 0, 0, - 0, 0, 0, 0, - 0xd, 0, 0, 0, - 8, 0, 0, 0, - 0x70, 0x77, 0x2d, 0x63, - 0x6f, 0x6e, 0x74, 0x61, - 0x69, 0x6e, 0x65, 0x72, - 0, 0, 0, 0, - 0x1b, 0, 0, 0, - 8, 0, 0, 0, - 0x61, 0x70, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, - 0x70, 0x72, 0x6f, 0x63, - 0x65, 0x73, 0x73, 0x2e, - 0x62, 0x69, 0x6e, 0x61, - 0x72, 0x79, 0, 0, - 0, 0, 0, 0, - 0xd, 0, 0, 0, - 8, 0, 0, 0, - 0x70, 0x77, 0x2d, 0x63, - 0x6f, 0x6e, 0x74, 0x61, - 0x69, 0x6e, 0x65, 0x72, - 0, 0, 0, 0, - 0x15, 0, 0, 0, - 8, 0, 0, 0, - 0x61, 0x70, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, - 0x6c, 0x61, 0x6e, 0x67, - 0x75, 0x61, 0x67, 0x65, - 0, 0, 0, 0, - 0xc, 0, 0, 0, - 8, 0, 0, 0, - 0x65, 0x6e, 0x5f, 0x55, - 0x53, 0x2e, 0x55, 0x54, - 0x46, 0x2d, 0x38, 0, - 0, 0, 0, 0, - 0x17, 0, 0, 0, - 8, 0, 0, 0, - 0x61, 0x70, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, - 0x70, 0x72, 0x6f, 0x63, - 0x65, 0x73, 0x73, 0x2e, - 0x69, 0x64, 0, 0, - 5, 0, 0, 0, - 8, 0, 0, 0, - 0x31, 0x34, 0x34, 0x33, - 0, 0, 0, 0, - 0x19, 0, 0, 0, - 8, 0, 0, 0, - 0x61, 0x70, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, - 0x70, 0x72, 0x6f, 0x63, - 0x65, 0x73, 0x73, 0x2e, - 0x75, 0x73, 0x65, 0x72, - 0, 0, 0, 0, - 0, 0, 0, 0, - 6, 0, 0, 0, - 8, 0, 0, 0, - 0x61, 0x6c, 0x69, 0x63, - 0x65, 0, 0, 0, - 0x19, 0, 0, 0, - 8, 0, 0, 0, - 0x61, 0x70, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, - 0x70, 0x72, 0x6f, 0x63, - 0x65, 0x73, 0x73, 0x2e, - 0x68, 0x6f, 0x73, 0x74, - 0, 0, 0, 0, - 0, 0, 0, 0, - 6, 0, 0, 0, - 8, 0, 0, 0, - 0x6e, 0x69, 0x78, 0x6f, - 0x73, 0, 0, 0, - 0x1f, 0, 0, 0, - 8, 0, 0, 0, - 0x61, 0x70, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, - 0x70, 0x72, 0x6f, 0x63, - 0x65, 0x73, 0x73, 0x2e, - 0x73, 0x65, 0x73, 0x73, - 0x69, 0x6f, 0x6e, 0x2d, - 0x69, 0x64, 0, 0, - 2, 0, 0, 0, - 8, 0, 0, 0, - 0x31, 0, 0, 0, - 0, 0, 0, 0, - 0x13, 0, 0, 0, - 8, 0, 0, 0, - 0x77, 0x69, 0x6e, 0x64, - 0x6f, 0x77, 0x2e, 0x78, - 0x31, 0x31, 0x2e, 0x64, - 0x69, 0x73, 0x70, 0x6c, - 0x61, 0x79, 0, 0, - 0, 0, 0, 0, - 3, 0, 0, 0, - 8, 0, 0, 0, - 0x3a, 0x30, 0, 0, - 0, 0, 0, 0, - 0xc, 0, 0, 0, - 8, 0, 0, 0, - 0x63, 0x70, 0x75, 0x2e, - 0x76, 0x6d, 0x2e, 0x6e, - 0x61, 0x6d, 0x65, 0, - 0, 0, 0, 0, - 5, 0, 0, 0, - 8, 0, 0, 0, - 0x71, 0x65, 0x6d, 0x75, - 0, 0, 0, 0, - 0xa, 0, 0, 0, - 8, 0, 0, 0, - 0x6c, 0x6f, 0x67, 0x2e, - 0x6c, 0x65, 0x76, 0x65, - 0x6c, 0, 0, 0, - 0, 0, 0, 0, - 2, 0, 0, 0, - 8, 0, 0, 0, - 0x30, 0, 0, 0, - 0, 0, 0, 0, - 0xe, 0, 0, 0, - 8, 0, 0, 0, - 0x63, 0x70, 0x75, 0x2e, - 0x6d, 0x61, 0x78, 0x2d, - 0x61, 0x6c, 0x69, 0x67, - 0x6e, 0, 0, 0, - 3, 0, 0, 0, - 8, 0, 0, 0, - 0x33, 0x32, 0, 0, - 0, 0, 0, 0, - 0x13, 0, 0, 0, - 8, 0, 0, 0, - 0x64, 0x65, 0x66, 0x61, - 0x75, 0x6c, 0x74, 0x2e, - 0x63, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x72, 0x61, - 0x74, 0x65, 0, 0, - 0, 0, 0, 0, - 6, 0, 0, 0, - 8, 0, 0, 0, - 0x34, 0x38, 0x30, 0x30, - 0x30, 0, 0, 0, - 0x16, 0, 0, 0, - 8, 0, 0, 0, - 0x64, 0x65, 0x66, 0x61, - 0x75, 0x6c, 0x74, 0x2e, - 0x63, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x71, 0x75, - 0x61, 0x6e, 0x74, 0x75, - 0x6d, 0, 0, 0, - 5, 0, 0, 0, - 8, 0, 0, 0, - 0x31, 0x30, 0x32, 0x34, - 0, 0, 0, 0, - 0x1a, 0, 0, 0, - 8, 0, 0, 0, - 0x64, 0x65, 0x66, 0x61, - 0x75, 0x6c, 0x74, 0x2e, - 0x63, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x6d, 0x69, - 0x6e, 0x2d, 0x71, 0x75, - 0x61, 0x6e, 0x74, 0x75, - 0x6d, 0, 0, 0, - 0, 0, 0, 0, - 3, 0, 0, 0, - 8, 0, 0, 0, - 0x33, 0x32, 0, 0, - 0, 0, 0, 0, - 0x1a, 0, 0, 0, - 8, 0, 0, 0, - 0x64, 0x65, 0x66, 0x61, - 0x75, 0x6c, 0x74, 0x2e, - 0x63, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x6d, 0x61, - 0x78, 0x2d, 0x71, 0x75, - 0x61, 0x6e, 0x74, 0x75, - 0x6d, 0, 0, 0, - 0, 0, 0, 0, - 5, 0, 0, 0, - 8, 0, 0, 0, - 0x32, 0x30, 0x34, 0x38, - 0, 0, 0, 0, - 0x1c, 0, 0, 0, - 8, 0, 0, 0, - 0x64, 0x65, 0x66, 0x61, - 0x75, 0x6c, 0x74, 0x2e, - 0x63, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x71, 0x75, - 0x61, 0x6e, 0x74, 0x75, - 0x6d, 0x2d, 0x6c, 0x69, - 0x6d, 0x69, 0x74, 0, - 0, 0, 0, 0, - 5, 0, 0, 0, - 8, 0, 0, 0, - 0x38, 0x31, 0x39, 0x32, - 0, 0, 0, 0, - 0x1c, 0, 0, 0, - 8, 0, 0, 0, - 0x64, 0x65, 0x66, 0x61, - 0x75, 0x6c, 0x74, 0x2e, - 0x63, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x71, 0x75, - 0x61, 0x6e, 0x74, 0x75, - 0x6d, 0x2d, 0x66, 0x6c, - 0x6f, 0x6f, 0x72, 0, - 0, 0, 0, 0, - 2, 0, 0, 0, - 8, 0, 0, 0, - 0x34, 0, 0, 0, - 0, 0, 0, 0, - 0x14, 0, 0, 0, - 8, 0, 0, 0, - 0x64, 0x65, 0x66, 0x61, - 0x75, 0x6c, 0x74, 0x2e, - 0x76, 0x69, 0x64, 0x65, - 0x6f, 0x2e, 0x77, 0x69, - 0x64, 0x74, 0x68, 0, - 0, 0, 0, 0, - 4, 0, 0, 0, - 8, 0, 0, 0, - 0x36, 0x34, 0x30, 0, - 0, 0, 0, 0, - 0x15, 0, 0, 0, - 8, 0, 0, 0, - 0x64, 0x65, 0x66, 0x61, - 0x75, 0x6c, 0x74, 0x2e, - 0x76, 0x69, 0x64, 0x65, - 0x6f, 0x2e, 0x68, 0x65, - 0x69, 0x67, 0x68, 0x74, - 0, 0, 0, 0, - 4, 0, 0, 0, - 8, 0, 0, 0, - 0x34, 0x38, 0x30, 0, - 0, 0, 0, 0, - 0x17, 0, 0, 0, - 8, 0, 0, 0, - 0x64, 0x65, 0x66, 0x61, - 0x75, 0x6c, 0x74, 0x2e, - 0x76, 0x69, 0x64, 0x65, - 0x6f, 0x2e, 0x72, 0x61, - 0x74, 0x65, 0x2e, 0x6e, - 0x75, 0x6d, 0, 0, - 3, 0, 0, 0, - 8, 0, 0, 0, - 0x32, 0x35, 0, 0, - 0, 0, 0, 0, - 0x19, 0, 0, 0, - 8, 0, 0, 0, - 0x64, 0x65, 0x66, 0x61, - 0x75, 0x6c, 0x74, 0x2e, - 0x76, 0x69, 0x64, 0x65, - 0x6f, 0x2e, 0x72, 0x61, - 0x74, 0x65, 0x2e, 0x64, - 0x65, 0x6e, 0x6f, 0x6d, - 0, 0, 0, 0, - 0, 0, 0, 0, - 2, 0, 0, 0, - 8, 0, 0, 0, - 0x31, 0, 0, 0, - 0, 0, 0, 0, - 0x1b, 0, 0, 0, - 8, 0, 0, 0, - 0x63, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x70, 0x6f, - 0x77, 0x65, 0x72, 0x2d, - 0x6f, 0x66, 0x2d, 0x74, - 0x77, 0x6f, 0x2d, 0x71, - 0x75, 0x61, 0x6e, 0x74, - 0x75, 0x6d, 0, 0, - 0, 0, 0, 0, - 5, 0, 0, 0, - 8, 0, 0, 0, - 0x74, 0x72, 0x75, 0x65, - 0, 0, 0, 0, - 0x11, 0, 0, 0, - 8, 0, 0, 0, - 0x6c, 0x69, 0x6e, 0x6b, - 0x2e, 0x6d, 0x61, 0x78, - 0x2d, 0x62, 0x75, 0x66, - 0x66, 0x65, 0x72, 0x73, - 0, 0, 0, 0, - 0, 0, 0, 0, - 3, 0, 0, 0, - 8, 0, 0, 0, - 0x36, 0x34, 0, 0, - 0, 0, 0, 0, - 0xf, 0, 0, 0, - 8, 0, 0, 0, - 0x6d, 0x65, 0x6d, 0x2e, - 0x77, 0x61, 0x72, 0x6e, - 0x2d, 0x6d, 0x6c, 0x6f, - 0x63, 0x6b, 0, 0, - 6, 0, 0, 0, - 8, 0, 0, 0, - 0x66, 0x61, 0x6c, 0x73, - 0x65, 0, 0, 0, - 0x10, 0, 0, 0, - 8, 0, 0, 0, - 0x6d, 0x65, 0x6d, 0x2e, - 0x61, 0x6c, 0x6c, 0x6f, - 0x77, 0x2d, 0x6d, 0x6c, - 0x6f, 0x63, 0x6b, 0, - 5, 0, 0, 0, - 8, 0, 0, 0, - 0x74, 0x72, 0x75, 0x65, - 0, 0, 0, 0, - 0x17, 0, 0, 0, - 8, 0, 0, 0, - 0x73, 0x65, 0x74, 0x74, - 0x69, 0x6e, 0x67, 0x73, - 0x2e, 0x63, 0x68, 0x65, - 0x63, 0x6b, 0x2d, 0x71, - 0x75, 0x61, 0x6e, 0x74, - 0x75, 0x6d, 0, 0, - 6, 0, 0, 0, - 8, 0, 0, 0, - 0x66, 0x61, 0x6c, 0x73, - 0x65, 0, 0, 0, - 0x14, 0, 0, 0, - 8, 0, 0, 0, - 0x73, 0x65, 0x74, 0x74, - 0x69, 0x6e, 0x67, 0x73, - 0x2e, 0x63, 0x68, 0x65, - 0x63, 0x6b, 0x2d, 0x72, - 0x61, 0x74, 0x65, 0, - 0, 0, 0, 0, - 6, 0, 0, 0, - 8, 0, 0, 0, - 0x66, 0x61, 0x6c, 0x73, - 0x65, 0, 0, 0, - 0xd, 0, 0, 0, - 8, 0, 0, 0, - 0x63, 0x6f, 0x72, 0x65, - 0x2e, 0x76, 0x65, 0x72, - 0x73, 0x69, 0x6f, 0x6e, - 0, 0, 0, 0, - 6, 0, 0, 0, - 8, 0, 0, 0, - 0x31, 0x2e, 0x34, 0x2e, - 0x37, 0, 0, 0, - 0xa, 0, 0, 0, - 8, 0, 0, 0, - 0x63, 0x6f, 0x72, 0x65, - 0x2e, 0x6e, 0x61, 0x6d, - 0x65, 0, 0, 0, - 0, 0, 0, 0, - 0x14, 0, 0, 0, - 8, 0, 0, 0, - 0x70, 0x69, 0x70, 0x65, - 0x77, 0x69, 0x72, 0x65, - 0x2d, 0x61, 0x6c, 0x69, - 0x63, 0x65, 0x2d, 0x31, - 0x34, 0x34, 0x33, 0, - 0, 0, 0, 0, - }, pipewire.ClientUpdateProperties{Props: &pipewire.SPADict{NItems: 0x1e, Items: []pipewire.SPADictItem{ + {"sample", []byte(sendmsg00Message01POD), pipewire.ClientUpdateProperties{Props: &pipewire.SPADict{NItems: 0x1e, Items: []pipewire.SPADictItem{ {Key: "remote.intention", Value: "manager"}, {Key: "application.name", Value: "pw-container"}, {Key: "application.process.binary", Value: "pw-container"}, diff --git a/internal/pipewire/core_test.go b/internal/pipewire/core_test.go index c271fea..d8c7cf9 100644 --- a/internal/pipewire/core_test.go +++ b/internal/pipewire/core_test.go @@ -8,14 +8,7 @@ import ( func TestCoreHello(t *testing.T) { encodingTestCases[pipewire.CoreHello, *pipewire.CoreHello]{ - {"sample", []byte{ - 0x10, 0, 0, 0, - 0xe, 0, 0, 0, - 4, 0, 0, 0, - 4, 0, 0, 0, - 4, 0, 0, 0, - 0, 0, 0, 0, - }, pipewire.CoreHello{ + {"sample", []byte(sendmsg00Message00POD), pipewire.CoreHello{ Version: pipewire.PW_VERSION_CORE, }, nil}, }.run(t) diff --git a/internal/pipewire/header_test.go b/internal/pipewire/header_test.go index efcea71..95f6ce1 100644 --- a/internal/pipewire/header_test.go +++ b/internal/pipewire/header_test.go @@ -11,33 +11,17 @@ func TestHeader(t *testing.T) { t.Parallel() encodingTestCases[pipewire.Header, *pipewire.Header]{ - {"PW_CORE_METHOD_HELLO", []byte{ - // Id - 0, 0, 0, 0, - // size - 0x18, 0, 0, - // opcode - 1, - // seq - 0, 0, 0, 0, - // n_fds - 0, 0, 0, 0, - }, pipewire.Header{ID: pipewire.PW_ID_CORE, Opcode: pipewire.PW_CORE_METHOD_HELLO, - Size: 0x18, Sequence: 0, FileCount: 0}, nil}, + {"PW_CORE_METHOD_HELLO", []byte(sendmsg00Message00Header), pipewire.Header{ + ID: pipewire.PW_ID_CORE, + Opcode: pipewire.PW_CORE_METHOD_HELLO, + Size: 0x18, Sequence: 0, FileCount: 0, + }, nil}, - {"PW_CLIENT_METHOD_UPDATE_PROPERTIES", []byte{ - // Id - 1, 0, 0, 0, - // size - 0, 6, 0, - // opcode - 2, - // seq - 1, 0, 0, 0, - // n_fds - 0, 0, 0, 0, - }, pipewire.Header{ID: pipewire.PW_ID_CLIENT, Opcode: pipewire.PW_CLIENT_METHOD_UPDATE_PROPERTIES, - Size: 0x600, Sequence: 1, FileCount: 0}, nil}, + {"PW_CLIENT_METHOD_UPDATE_PROPERTIES", []byte(sendmsg00Message01Header), pipewire.Header{ + ID: pipewire.PW_ID_CLIENT, + Opcode: pipewire.PW_CLIENT_METHOD_UPDATE_PROPERTIES, + Size: 0x600, Sequence: 1, FileCount: 0, + }, nil}, {"PW_SECURITY_CONTEXT_METHOD_CREATE", []byte{ // Id diff --git a/internal/pipewire/pipewire_test.go b/internal/pipewire/pipewire_test.go new file mode 100644 index 0000000..49f128f --- /dev/null +++ b/internal/pipewire/pipewire_test.go @@ -0,0 +1,17 @@ +package pipewire_test + +import ( + _ "embed" +) + +var ( + //go:embed testdata/00-sendmsg00-message00-header + sendmsg00Message00Header string + //go:embed testdata/01-sendmsg00-message00-POD + sendmsg00Message00POD string + + //go:embed testdata/02-sendmsg00-message01-header + sendmsg00Message01Header string + //go:embed testdata/03-sendmsg00-message01-POD + sendmsg00Message01POD string +) diff --git a/internal/pipewire/testdata/00-sendmsg00-message00-header b/internal/pipewire/testdata/00-sendmsg00-message00-header new file mode 100644 index 0000000000000000000000000000000000000000..601b8fe6c25696c3e78f8320a69b8415a84748a8 GIT binary patch literal 16 ScmZQzU|^77U|%Ffed1FfbIQ=H{2A>SgAYq~?`m=I23VA#x!3 z+{C=Z^wc5-nEJ$mf}G6cM37Rwyu{p8n0j8Qc?IRV$@zIDiJ5t+MIbq8s5r8|f};H7 z)Z${jq|Cg;qDqh|1_oUEMX~75Nz6+xO-u*d%>$KB&5I8W)(Z`B)3pE_C=M0JW^ZN+ z0|P5m-q6Iv7^FcG%EzX@v>4(SkUBP)x}3~pkOT1P%g8S-0qFr@n7+Ksiu_^*1_pVU zIY{9N3zy>5;^NHwJYA4GnV{+nL546eFbG5W<(YXY`Q>^QhK716nZ*S;iO_IlhRRzR zKs3O@C%K?huPhf4WibC2rskG{RB}P}<>aU9<)oIS=70nl7#LvoLyZHcDNwoqnU|Yb zp_`bKnGQ-cFnf)SAR1xrOi4{kEX^s=OU}tp&ekhRECB@?0|NsrJWMPM3_xa!LG4FX zUs#%$S5lhGfD~T_MkXK|q_C>b&CJt9=mDuicNY$Qi4|!2VBuqAU;<81GFa_{+NGP5 znVSiTYM4F?LrZW-;MbRylb;XHCh%|udyavDK?Kddvdom!e7*9_l#&dPx4?NB6c1)5 zpwMGrfaMcd_(9ZXq-LgPfE@22+|APGT)FR#dG~JT&eAEDkg`O%%81FSy0GGm0RS~L9<%@e literal 0 HcmV?d00001