forked from sensorbee/opencv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
capture_from_device_test.go
139 lines (131 loc) · 3.89 KB
/
capture_from_device_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
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
package opencv
import (
"fmt"
. "github.com/smartystreets/goconvey/convey"
"gopkg.in/sensorbee/sensorbee.v0/bql"
"gopkg.in/sensorbee/sensorbee.v0/core"
"gopkg.in/sensorbee/sensorbee.v0/data"
"testing"
)
func TestGenerateStreamDeviceError(t *testing.T) {
ctx := &core.Context{}
sc := FromDeviceCreator{}
ioParams := &bql.IOParams{}
Convey("Given a CaptureFromDevice source with invalid device ID", t, func() {
params := data.Map{
"device_id": data.Int(999999), // invalid device ID
}
capture, err := sc.CreateSource(ctx, ioParams, params)
So(err, ShouldBeNil)
So(capture, ShouldNotBeNil)
Convey("When generate stream", func() {
Convey("Then error has occurred", func() {
err := capture.GenerateStream(ctx, &dummyWriter{})
So(err, ShouldNotBeNil)
So(err.Error(), ShouldStartWith, "error")
})
})
})
}
func TestGetDeviceSourceCreator(t *testing.T) {
ctx := &core.Context{}
ioParams := &bql.IOParams{}
Convey("Given a CaptureFromDevice creator", t, func() {
sc := FromDeviceCreator{}
Convey("When create source with full parameters", func() {
params := data.Map{
"device_id": data.Int(0),
"format": data.String("cvmat"),
"width": data.Int(500),
"height": data.Int(600),
"fps": data.Int(25),
}
Convey("Then creator should initialize capture source", func() {
s, err := sc.createCaptureFromDevice(ctx, ioParams, params)
So(err, ShouldBeNil)
capture, ok := s.(*captureFromDevice)
So(ok, ShouldBeTrue)
So(capture.deviceID, ShouldEqual, 0)
So(capture.width, ShouldEqual, 500)
So(capture.height, ShouldEqual, 600)
So(capture.fps, ShouldEqual, 25)
})
})
Convey("When create source with empty device ID", func() {
params := data.Map{
"width": data.Int(500),
"height": data.Int(600),
"fps": data.Int(25),
}
Convey("Then creator should occur an error", func() {
s, err := sc.CreateSource(ctx, ioParams, params)
So(err, ShouldNotBeNil)
So(s, ShouldBeNil)
})
})
Convey("When create source with only device ID", func() {
params := data.Map{
"device_id": data.Int(0),
}
Convey("Then capture should set default values", func() {
s, err := sc.createCaptureFromDevice(ctx, ioParams, params)
So(err, ShouldBeNil)
capture, ok := s.(*captureFromDevice)
So(ok, ShouldBeTrue)
So(capture.deviceID, ShouldEqual, 0)
So(capture.width, ShouldEqual, 0)
So(capture.height, ShouldEqual, 0)
So(capture.fps, ShouldEqual, 0)
})
})
Convey("When create source with invalid device ID", func() {
params := data.Map{
"device_id": data.String("a"),
}
Convey("Then creator should occur parse errors", func() {
s, err := sc.CreateSource(ctx, ioParams, params)
So(err, ShouldNotBeNil)
So(s, ShouldBeNil)
})
})
Convey("When create source with invalid option parameters", func() {
params := data.Map{
"device_id": data.Int(0),
}
testMap := data.Map{
"format": data.False,
"width": data.String("a"),
"height": data.String("b"),
"fps": data.String("@"),
}
for k, v := range testMap {
v := v
msg := fmt.Sprintf("with %v error", k)
Convey("Then creator should occur a parse error on option parameters "+msg,
func() {
params[k] = v
s, err := sc.CreateSource(ctx, ioParams, params)
So(err, ShouldNotBeNil)
So(s, ShouldBeNil)
})
}
})
})
}
func TestGetDeviceSourceCreatorWithRawMode(t *testing.T) {
ctx := &core.Context{}
ioParams := &bql.IOParams{}
Convey("Given a raw mode enabled capture source creator", t, func() {
sc := FromDeviceCreator{}
Convey("When create source with not supported format", func() {
params := data.Map{
"device_id": data.Int(0),
"format": data.String("4k"),
}
_, err := sc.createCaptureFromDevice(ctx, ioParams, params)
Convey("Then capture should return an error", func() {
So(err, ShouldNotBeNil)
})
})
})
}