-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathmix_test.go
More file actions
168 lines (145 loc) · 3.59 KB
/
mix_test.go
File metadata and controls
168 lines (145 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Sequence-based Go-native audio mixer for music apps
package mix
import (
"bytes"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/go-mix/mix/bind/spec"
"github.com/go-mix/mix/lib/mix"
)
func TestDebug(t *testing.T) {
// Test turning debug on
Debug(true)
// Since debug package is internal, we test indirectly that it doesn't panic
assert.NotPanics(t, func() {
Debug(true)
Debug(false)
})
}
func TestConfigure(t *testing.T) {
// Test valid configuration
assert.NotPanics(t, func() {
Configure(spec.AudioSpec{
Freq: 44100,
Format: spec.AudioF32,
Channels: 2,
})
})
}
func TestConfigure_FailureFreqNotGreaterThanZero(t *testing.T) {
defer func() {
msg := recover()
assert.IsType(t, "", msg)
assert.Equal(t, "Must specify a mixing frequency greater than zero.", msg)
}()
Configure(spec.AudioSpec{
Freq: -100,
Format: spec.AudioS16,
Channels: 2,
})
}
func TestTeardown(t *testing.T) {
testAPISetup()
Teardown()
}
func TestSpec(t *testing.T) {
testAPISetup()
assert.Equal(t, &spec.AudioSpec{
Freq: 44100,
Format: spec.AudioF32,
Channels: 1,
}, Spec())
Teardown()
}
func TestSetFire(t *testing.T) {
testAPISetup()
fire := SetFire("lib/source/testdata/Signed16bitLittleEndian44100HzMono.wav", time.Duration(0), 0, 1.0, 0, 0, 0, 1.0, 0)
assert.NotNil(t, fire)
}
func TestFireCount(t *testing.T) {
testAPISetup()
assert.Equal(t, 0, FireCount())
SetFire("lib/source/testdata/Float32bitLittleEndian48000HzEstéreo.wav", time.Duration(0), 0, 1.0, 0, 0, 0, 1.0, 0)
assert.Equal(t, 1, FireCount())
SetFire("lib/source/testdata/Signed16bitLittleEndian44100HzMono.wav", time.Duration(0), 0, 1.0, 0, 0, 0, 1.0, 0)
assert.Equal(t, 2, FireCount())
// TODO: assert count drains during back to 0 as a result of playback
}
func TestClearAllFires(t *testing.T) {
testAPISetup()
SetFire("lib/source/testdata/Signed16bitLittleEndian44100HzMono.wav", time.Duration(0), 0, 1.0, 0, 0, 0, 1.0, 0)
ClearAllFires()
assert.Equal(t, 0, FireCount())
}
func TestSetSoundsPath(t *testing.T) {
// Test setting sounds path doesn't panic
assert.NotPanics(t, func() {
SetSoundsPath("test/path/")
SetSoundsPath("")
})
}
func TestSetGetMixCycleDuration(t *testing.T) {
testAPISetup()
SetMixCycleDuration(2 * time.Second)
assert.Equal(t, spec.Tz(88200), mix.GetCycleDurationTz())
}
func TestStart(t *testing.T) {
Start()
}
func TestStartAt(t *testing.T) {
StartAt(time.Now().Add(1 * time.Second))
}
func TestGetStartTime(t *testing.T) {
startExpect := time.Now().Add(1 * time.Second)
StartAt(startExpect)
startActual := GetStartTime()
assert.Equal(t, startExpect, startActual)
}
func TestGetNowAt(t *testing.T) {
testAPISetup()
Start()
// Give it a moment to start
time.Sleep(10 * time.Millisecond)
now := GetNowAt()
// Should be a positive duration after start
assert.True(t, now >= 0)
}
func TestOutputStart(t *testing.T) {
testAPISetup()
// Create a buffer to write to
var buf bytes.Buffer
assert.NotPanics(t, func() {
OutputStart(1*time.Second, &buf)
})
}
func TestOutputContinueTo(t *testing.T) {
testAPISetup()
assert.NotPanics(t, func() {
OutputContinueTo(100 * time.Millisecond)
})
}
func TestOutputClose(t *testing.T) {
testAPISetup()
assert.NotPanics(t, func() {
OutputClose()
})
}
func TestAudioCallback(t *testing.T) {
// Test that the audio system can be configured
// This is tested indirectly through Configure
testAPISetup()
assert.NotNil(t, Spec())
}
//
// Test Components
//
func testAPISetup() {
Teardown()
ClearAllFires()
Configure(spec.AudioSpec{
Freq: 44100,
Format: spec.AudioF32,
Channels: 1,
})
}