-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcapture_from_uri_test.go
170 lines (158 loc) · 4.82 KB
/
capture_from_uri_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
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
169
170
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 TestGenerateStreamURIError(t *testing.T) {
ctx := &core.Context{}
sc := FromURICreator{}
ioParams := &bql.IOParams{}
Convey("Given a CaptureFromURI source with invalid URI", t, func() {
params := data.Map{
"uri": data.String("error uri"),
}
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")
})
})
})
}
type dummyWriter struct{}
func (w *dummyWriter) Write(ctx *core.Context, t *core.Tuple) error {
return nil
}
func TestGetURISourceCreatorWithRawMode(t *testing.T) {
ctx := &core.Context{}
ioParams := &bql.IOParams{}
Convey("Given a raw mode enabled capture source creator", t, func() {
sc := FromURICreator{}
Convey("When create source with not supported format", func() {
params := data.Map{
"uri": data.String("/data/file.avi"),
"format": data.String("4k"),
}
_, err := sc.createCaptureFromURI(ctx, ioParams, params)
Convey("Then capture should return an error", func() {
So(err, ShouldNotBeNil)
})
})
})
}
func TestGetURISourceCreator(t *testing.T) {
cc := &core.ContextConfig{}
ctx := core.NewContext(cc)
ioParams := &bql.IOParams{}
Convey("Given a CaptureFromURI creator", t, func() {
sc := FromURICreator{}
Convey("When create source with full parameters", func() {
params := data.Map{
"uri": data.String("/data/file.avi"),
"format": data.String("cvmat"),
"frame_skip": data.Int(5),
"next_frame_error": data.False,
}
Convey("Then creator should initialize capture source", func() {
s, err := sc.createCaptureFromURI(ctx, ioParams, params)
So(err, ShouldBeNil)
capture, ok := s.(*captureFromURI)
So(ok, ShouldBeTrue)
So(capture.uri, ShouldEqual, "/data/file.avi")
So(capture.frameSkip, ShouldEqual, 5)
So(capture.endErrFlag, ShouldBeFalse)
})
})
Convey("When create source with empty uri", func() {
params := data.Map{
"frame_skip": data.Int(5),
"next_frame_error": data.False,
}
Convey("Then creator should occur an error", func() {
s, err := sc.createCaptureFromURI(ctx, ioParams, params)
So(err, ShouldNotBeNil)
So(s, ShouldBeNil)
})
})
Convey("When create source with only uri", func() {
params := data.Map{
"uri": data.String("/data/file.avi"),
}
Convey("Then capture should set default values", func() {
s, err := sc.createCaptureFromURI(ctx, ioParams, params)
So(err, ShouldBeNil)
capture, ok := s.(*captureFromURI)
So(ok, ShouldBeTrue)
So(capture.uri, ShouldEqual, "/data/file.avi")
So(capture.frameSkip, ShouldEqual, 0)
So(capture.endErrFlag, ShouldBeTrue)
})
})
Convey("When create source with invalid uri", func() {
params := data.Map{
"uri": data.Null{},
}
Convey("Then create should occur an error", func() {
s, err := sc.createCaptureFromURI(ctx, ioParams, params)
So(err, ShouldNotBeNil)
So(s, ShouldBeNil)
})
})
Convey("When create source with invalid option parameters", func() {
params := data.Map{
"uri": data.String("/data/file.avi"),
}
testMap := data.Map{
"format": data.True,
"frame_skip": data.String("@"),
"next_frame_error": data.String("True"),
}
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.createCaptureFromURI(ctx, ioParams, params)
So(err, ShouldNotBeNil)
So(s, ShouldBeNil)
})
}
})
Convey("When create source with only uri and rewindable", func() {
params := data.Map{
"uri": data.String("/data/file.avi"),
"rewindable": data.True,
}
Convey("Then rewindable capture should be created", func() {
c := FromURICreator{}
s, err := c.CreateSource(ctx, ioParams, params)
So(err, ShouldBeNil)
So(s, ShouldNotBeNil)
_, ok := s.(core.RewindableSource)
So(ok, ShouldBeTrue)
})
})
Convey("When create source with only uri and deprecated rewind param name", func() {
params := data.Map{
"uri": data.String("/data/file.avi"),
"rewind": data.True,
}
Convey("Then rewindable capture should be created", func() {
c := FromURICreator{}
s, err := c.CreateSource(ctx, ioParams, params)
So(err, ShouldBeNil)
So(s, ShouldNotBeNil)
_, ok := s.(core.RewindableSource)
So(ok, ShouldBeTrue)
})
})
})
}