Files
radiantwave-legacy/internal/mixer/mixer_internal_test.go
T

72 lines
2.3 KiB
Go

package mixer
import "testing"
func TestHumanizeDeviceName(t *testing.T) {
tests := []struct {
name string
raw string
want string
}{
{"hdmi description", "Built-in Audio Digital Stereo (HDMI)", "HDMI | Monitor | TV"},
{"hdmi alsa name", "alsa_output.pci-0000_00_1f.3.hdmi-stereo-extra1", "HDMI | Monitor | TV"},
{"monitor", "Monitor", "HDMI | Monitor | TV"},
{"tv", "TV", "HDMI | Monitor | TV"},
{"uppercase hdmi", "HDMI", "HDMI | Monitor | TV"},
{"headset", "Headset", "Headset"},
{"headphones", "WH-1000XM4 Headphones", "Headset"},
{"bluetooth headset name", "bluez_output.00_11_22_33_44_55.headset-head-unit", "Headset"},
{"usb description", "USB Audio", "USB"},
{"usb alsa name", "alsa_output.usb-046d_0825-00.analog-stereo", "USB"},
{"internal analog description", "Built-in Audio Analog Stereo", "Internal Speakers"},
{"internal alsa name", "alsa_output.pci-0000_00_1f.3.analog-stereo", "Internal Speakers"},
{"internal speakers label", "Internal Speakers", "Internal Speakers"},
{"virtual speaker", "Virtual Speaker", "Internal Speakers"},
{"no match fallback", "Custom Node 42", "Custom Node 42"},
{"empty fallback", "", ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := HumanizeDeviceName(tt.raw); got != tt.want {
t.Errorf("HumanizeDeviceName(%q) = %q, want %q", tt.raw, got, tt.want)
}
})
}
}
func TestMatchDeviceName(t *testing.T) {
names := []string{
"Built-in Audio Analog Stereo",
"Built-in Audio Digital Stereo (HDMI)",
"USB Audio",
"Headset",
}
tests := []struct {
name string
preferred string
want string
wantOK bool
}{
{"empty preferred", "", "", false},
{"exact match", "USB Audio", "USB Audio", true},
{"substring match", "hdmi", "Built-in Audio Digital Stereo (HDMI)", true},
{"suffix tolerance", "Built-in Audio Digital Stereo", "Built-in Audio Digital Stereo (HDMI)", true},
{"case insensitive", "usb audio", "USB Audio", true},
{"no match", "Bluetooth Dongle", "", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, ok := matchDevice(names, tt.preferred)
if ok != tt.wantOK {
t.Fatalf("matchDevice(%q) ok = %v, want %v", tt.preferred, ok, tt.wantOK)
}
if ok && got != tt.want {
t.Errorf("matchDevice(%q) = %q, want %q", tt.preferred, got, tt.want)
}
})
}
}