aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pipewire/header_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-11-24 21:48:01 +0900
committerOphestra <cat@gensokyo.uk>2025-11-24 22:00:09 +0900
commit9f7b0c2f46305f8a321791d6fcedc3df7f966783 (patch)
treeb565a4a7d8e77f8f6717e46837f6b7d6ee174fc7 /internal/pipewire/header_test.go
parent3e87187c4c4eb43ed1c9dc1c0c6613e5bed1dc6c (diff)
internal/pipewire: add type constants
This change also centralises encoding testing. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pipewire/header_test.go')
-rw-r--r--internal/pipewire/header_test.go53
1 files changed, 18 insertions, 35 deletions
diff --git a/internal/pipewire/header_test.go b/internal/pipewire/header_test.go
index d933598f..8501dc19 100644
--- a/internal/pipewire/header_test.go
+++ b/internal/pipewire/header_test.go
@@ -10,11 +10,21 @@ import (
func TestHeader(t *testing.T) {
t.Parallel()
- testCases := []struct {
- name string
- data []byte
- want pipewire.Header
- }{
+ 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_SECURITY_CONTEXT_METHOD_CREATE", []byte{
// Id
3, 0, 0, 0,
@@ -27,7 +37,7 @@ func TestHeader(t *testing.T) {
// n_fds
2, 0, 0, 0,
}, pipewire.Header{ID: 3, Opcode: pipewire.PW_SECURITY_CONTEXT_METHOD_CREATE,
- Size: 0xd8, Sequence: 5, FileCount: 2}},
+ Size: 0xd8, Sequence: 5, FileCount: 2}, nil},
{"PW_SECURITY_CONTEXT_METHOD_NUM", []byte{
// Id
@@ -41,35 +51,8 @@ func TestHeader(t *testing.T) {
// n_fds
0, 0, 0, 0,
}, pipewire.Header{ID: 0, Opcode: pipewire.PW_SECURITY_CONTEXT_METHOD_NUM,
- Size: 0x28, Sequence: 6, FileCount: 0}},
- }
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- t.Parallel()
-
- t.Run("decode", func(t *testing.T) {
- t.Parallel()
-
- var got pipewire.Header
- if err := got.UnmarshalBinary(tc.data); err != nil {
- t.Fatalf("UnmarshalBinary: error = %v", err)
- }
- if got != tc.want {
- t.Fatalf("UnmarshalBinary: %#v, want %#v", got, tc.want)
- }
- })
-
- t.Run("encode", func(t *testing.T) {
- t.Parallel()
-
- if got, err := tc.want.MarshalBinary(); err != nil {
- t.Fatalf("MarshalBinary: error = %v", err)
- } else if string(got) != string(tc.data) {
- t.Fatalf("MarshalBinary: %#v, want %#v", got, tc.data)
- }
- })
- })
- }
+ Size: 0x28, Sequence: 6, FileCount: 0}, nil},
+ }.run(t)
t.Run("size range", func(t *testing.T) {
t.Parallel()