forked from gen2brain/malgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_test.go
55 lines (43 loc) · 1.61 KB
/
context_test.go
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
package malgo_test
import (
"flag"
"testing"
"github.com/gen2brain/malgo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var testWithHardware = flag.Bool("malgo.hardware", false, "run tests with expecting hardware")
func TestContextLifecycle(t *testing.T) {
config := malgo.ContextConfig{ThreadPriority: malgo.ThreadPriorityNormal}
backends := []malgo.Backend{malgo.BackendNull}
ctx, err := malgo.InitContext(backends, config, nil)
require.Nil(t, err, "No error expected initializing context")
require.NotNil(t, ctx, "Context instance expected")
assert.NotEqual(t, malgo.Context(0), ctx.Context, "Context value expected")
err = ctx.Uninit()
assert.Nil(t, err, "No error expected uninitializing")
ctx.Free()
assert.Equal(t, malgo.Context(0), ctx.Context, "Expected context value to be reset")
}
func TestContextDeviceEnumeration(t *testing.T) {
if *testWithHardware {
t.Log("Running test expecting devices\n")
}
ctx, err := malgo.InitContext(nil, malgo.ContextConfig{}, nil)
require.Nil(t, err, "No error expected initializing context")
defer func() {
err := ctx.Uninit()
assert.Nil(t, err, "No error expected uninitializing")
ctx.Free()
}()
playbackDevices, err := ctx.Devices(malgo.Playback)
assert.Nil(t, err, "No error expected querying playback devices")
if *testWithHardware {
assert.True(t, len(playbackDevices) > 0, "No playback devices found")
}
captureDevices, err := ctx.Devices(malgo.Capture)
assert.Nil(t, err, "No error expected querying capture devices")
if *testWithHardware {
assert.True(t, len(captureDevices) > 0, "No capture devices found")
}
}