commit 578749db237b7d4e186be0d9267ffde33a46e080
parent b5d777e24d900661857614bfae7096190a26ef88
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Fri, 3 May 2024 16:20:01 +0800
test: add macos native golden output
There appears to be significant differences in output between the
uncompressed data from CoreAudio vs Windows MediaFoundation. To keep the
test passing, we can supply a golden output that was computed from
CoreAudio instead.
Diffstat:
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/internal/test/audio_test.go b/internal/test/audio_test.go
@@ -18,10 +18,23 @@ var (
compressed []byte
//go:embed uncompressed.s16le.pcm
uncompressed []byte
+ //go:embed uncompressed.s16le.macos.pcm
+ uncompressed_macos []byte
//go:embed corrupt.m4a
corrupt []byte
)
+// getUncompressed returns the uncompressed result produced on the
+// current platform.
+func getUncompressed() []byte {
+ switch runtime.GOOS {
+ case "darwin":
+ return uncompressed_macos
+ default:
+ return uncompressed
+ }
+}
+
// TestLoad ensures that output from the native decoders are close to
// the output of ffmpeg.
func TestLoad(t *testing.T) {
@@ -41,10 +54,10 @@ func TestLoad(t *testing.T) {
t.Fatalf("unexpected channel count: want 2, got %d", f.Channels)
}
// Test passes on exact match, otherwise do a tolerance test.
- if bytes.Equal(by, uncompressed) {
+ if bytes.Equal(by, getUncompressed()) {
return
}
- if !equal(t, by, uncompressed) {
+ if !equal(t, by, getUncompressed()) {
t.Fatalf("native output does not match ffmpeg output")
}
}
@@ -68,10 +81,10 @@ func TestDecode(t *testing.T) {
t.Fatalf("unexpected channel count: want 2, got %d", f.Channels)
}
// Test passes on exact match, otherwise do a tolerance test.
- if bytes.Equal(by, uncompressed) {
+ if bytes.Equal(by, getUncompressed()) {
return
}
- if !equal(t, by, uncompressed) {
+ if !equal(t, by, getUncompressed()) {
t.Fatalf("native output does not match ffmpeg output")
}
}
@@ -124,7 +137,6 @@ func TestMemoryLeak(t *testing.T) {
t.Errorf("un-freed data: %s -> %d\n", f.Name(), p.InUseBytes())
}
-
}
// equal decodes the PCM samples and tests if they are "close enough"
diff --git a/internal/test/uncompressed.s16le.macos.pcm b/internal/test/uncompressed.s16le.macos.pcm
Binary files differ.