-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathalsa_test.go
103 lines (68 loc) · 2.26 KB
/
alsa_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
103
// Copyright 2015-2016 Cocoon Labs Ltd.
//
// See LICENSE file for terms and conditions.
package alsa
import (
"testing"
"github.com/cocoonlife/testify/assert"
)
func TestCapture(t *testing.T) {
a := assert.New(t)
c, err := NewCaptureDevice("nonexistent", 1, FormatS16LE, 44100,
BufferParams{})
a.Equal(c, (*CaptureDevice)(nil), "capture device is nil")
a.Error(err, "no device error")
c, err = NewCaptureDevice("null", 1, FormatS32LE, 0, BufferParams{})
a.Equal(c, (*CaptureDevice)(nil), "capture device is nil")
a.Error(err, "bad rate error")
c, err = NewCaptureDevice("null", 1, FormatS32LE, 44100, BufferParams{})
a.NoError(err, "created capture device")
b1 := make([]int8, 100)
samples, err := c.Read(b1)
a.Error(err, "wrong type error")
a.Equal(samples, 0, "no samples read")
b2 := make([]int16, 200)
samples, err = c.Read(b2)
a.Error(err, "wrong type error")
a.Equal(samples, 0, "no samples read")
b3 := make([]float64, 50)
samples, err = c.Read(b3)
a.Error(err, "wrong type error")
a.Equal(samples, 0, "no samples read")
b4 := make([]int32, 200)
samples, err = c.Read(b4)
a.NoError(err, "read samples ok")
a.Equal(len(b2), samples, "correct number of samples read")
c.Close()
}
func TestPlayback(t *testing.T) {
a := assert.New(t)
p, err := NewPlaybackDevice("nonexistent", 1, FormatS16LE, 44100,
BufferParams{})
a.Equal(p, (*PlaybackDevice)(nil), "playback device is nil")
a.Error(err, "no device error")
p, err = NewPlaybackDevice("null", 0, FormatS32LE, 44100,
BufferParams{})
a.Equal(p, (*PlaybackDevice)(nil), "playback device is nil")
a.Error(err, "bad channels error")
p, err = NewPlaybackDevice("null", 1, FormatS32LE, 44100,
BufferParams{})
a.NoError(err, "created playback device")
b1 := make([]int8, 100)
frames, err := p.Write(b1)
a.Error(err, "wrong type error")
a.Equal(frames, 0, "no frames written")
b2 := make([]int16, 100)
frames, err = p.Write(b2)
a.Error(err, "wrong type error")
a.Equal(frames, 0, "no frames written")
b3 := make([]float64, 100)
frames, err = p.Write(b3)
a.Error(err, "wrong type error")
a.Equal(frames, 0, "no frames written")
b4 := make([]int32, 100)
frames, err = p.Write(b4)
a.NoError(err, "buffer written ok")
a.Equal(frames, 100, "100 frames written")
p.Close()
}