Remove all PipeWire/wpctl system calls (SetDefaultSinkVolume, listSinkIDs, listSinks, SetAllSinkVolumes, parseSinks, parseSinkLine, Sink struct). Volume is now managed entirely through SDL_mixer's VolumeMusic(), making audio fully system-agnostic. Changes: - mixer.go: delete ~170 lines of wpctl code; add SetVolume() public API using mix.VolumeMusic(math.Round(level * MAX_VOLUME)) - Init/Play/SwitchDevice set volume inline (they already hold the mutex) - Play() now uses stored currentVolume instead of hardcoded MAX_VOLUME - AudioOptions: SetAllSinkVolumes -> SetVolume - mixer_test.go: add TestSetVolume (validation + error path coverage)
72 lines
1.5 KiB
Go
72 lines
1.5 KiB
Go
package mixer_test
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
|
|
"rhemawavetech.com/rhemawave/internal/mixer"
|
|
)
|
|
|
|
func TestSetVolume(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
level float64
|
|
wantErr bool
|
|
}{
|
|
{"zero volume", 0.0, false},
|
|
{"half volume", 0.5, false},
|
|
{"max volume", 1.0, false},
|
|
{"above range", 1.5, true},
|
|
{"negative", -0.1, true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := mixer.SetVolume(tt.level)
|
|
if tt.wantErr {
|
|
if err == nil {
|
|
t.Errorf("SetVolume(%v) = nil, want error", tt.level)
|
|
}
|
|
return
|
|
}
|
|
if err != nil {
|
|
// For valid input, failure is expected when SDL isn't initialized
|
|
// (that's fine — we're testing validation, not SDL integration)
|
|
if err.Error() != "audio mixer not initialized" {
|
|
t.Errorf("SetVolume(%v) = %v, want 'audio mixer not initialized' or nil", tt.level, err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestConvertVolume(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input int
|
|
expected float64
|
|
}{
|
|
{"0 percent", 0, 0.0},
|
|
{"25 percent", 25, 0.25},
|
|
{"33 percent", 33, 0.33},
|
|
{"50 percent", 50, 0.50},
|
|
{"90 percent", 90, 0.90},
|
|
{"100 percent", 100, 1.0},
|
|
{"1 percent", 1, 0.01},
|
|
{"99 percent", 99, 0.99},
|
|
{"negative 10", -10, -0.10},
|
|
{"over 100", 150, 1.50},
|
|
}
|
|
|
|
const epsilon = 1e-9
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := mixer.ConvertVolume(tt.input)
|
|
if math.Abs(got-tt.expected) > epsilon {
|
|
t.Errorf("ConvertVolume(%d) = %v, want %v", tt.input, got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|