37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package sound
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"log/slog"
|
|
"testing"
|
|
)
|
|
|
|
func TestIndentationToneIsBoundedAndHonorsSoundPolicy(t *testing.T) {
|
|
service := New(slog.New(slog.DiscardHandler), nil, "default", .5)
|
|
for _, frequency := range []int{100, 200, 2750} {
|
|
name := IndentationCueName(frequency)
|
|
data, err := soundData("default", name)
|
|
if err != nil || len(data) != 44+3307*2 || binary.LittleEndian.Uint32(data[24:]) != 22050 {
|
|
t.Fatalf("indentation WAV: bytes %d, error %v", len(data), err)
|
|
}
|
|
if !service.cue_available(name) || !generated_tone(name) {
|
|
t.Fatal("generated indentation unavailable")
|
|
}
|
|
}
|
|
if _, err := soundData("default", IndentationCueName(2751)); err == nil {
|
|
t.Fatal("unbounded pitch accepted")
|
|
}
|
|
service.Configure(Configuration{Enabled: false, Theme: "default", Volume: .5})
|
|
if service.cue_available(IndentationCueName(200)) {
|
|
t.Fatal("disabled sound played indentation")
|
|
}
|
|
service.Configure(Configuration{Enabled: true, Theme: "none", Volume: .5})
|
|
if service.cue_available(IndentationCueName(200)) {
|
|
t.Fatal("None theme played indentation")
|
|
}
|
|
}
|