-
Notifications
You must be signed in to change notification settings - Fork 53
/
context_test.go
102 lines (86 loc) · 2.39 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
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
package malgo_test
import (
"flag"
"fmt"
"testing"
"github.com/gen2brain/malgo"
)
var testWithHardware = flag.Bool("malgo.hardware", false, "run tests with expecting hardware")
func TestContextLifecycle(t *testing.T) {
config := malgo.ContextConfig{ThreadPriority: malgo.ThreadPriorityNormal}
ctx, err := malgo.InitContext(nil, config, nil)
assertNil(t, err, "No error expected initializing context")
assertNotNil(t, ctx, "Context instance expected")
assertNotEqual(t, malgo.Context{}, ctx.Context, "Context value expected")
err = ctx.Uninit()
assertNil(t, err, "No error expected uninitializing")
ctx.Free()
assertEqual(t, malgo.Context{}, 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)
assertNil(t, err, "No error expected initializing context")
defer func() {
err := ctx.Uninit()
assertNil(t, err, "No error expected uninitializing")
ctx.Free()
}()
playbackDevices, err := ctx.Devices(malgo.Playback)
assertNil(t, err, "No error expected querying playback devices")
if *testWithHardware {
assertTrue(t, len(playbackDevices) > 0, "No playback devices found")
}
captureDevices, err := ctx.Devices(malgo.Capture)
assertNil(t, err, "No error expected querying capture devices")
if *testWithHardware {
assertTrue(t, len(captureDevices) > 0, "No capture devices found")
}
}
func assertEqual(t *testing.T, a interface{}, b interface{}, message string) {
if a == b {
return
}
if len(message) == 0 {
message = fmt.Sprintf("%v != %v", a, b)
}
t.Fatal(message)
}
func assertNotEqual(t *testing.T, a interface{}, b interface{}, message string) {
if a != b {
return
}
if len(message) == 0 {
message = fmt.Sprintf("%v == %v", a, b)
}
t.Fatal(message)
}
func assertNil(t *testing.T, v interface{}, message string) {
if v == nil {
return
}
if len(message) == 0 {
message = fmt.Sprintf("expected nil, got %#v", v)
}
t.Fatal(message)
}
func assertNotNil(t *testing.T, v interface{}, message string) {
if v != nil {
return
}
if len(message) == 0 {
message = fmt.Sprintf("expected value not to be nil")
}
t.Fatal(message)
}
func assertTrue(t *testing.T, v bool, message string) {
if v {
return
}
if len(message) == 0 {
message = fmt.Sprintf("should be true")
}
t.Fatal(message)
}