-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera_test.go
97 lines (81 loc) · 2.7 KB
/
camera_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
package camera
import (
"fmt"
"path/filepath"
"strings"
"testing"
)
func TestInitialize(t *testing.T) {
// Test width < MIN_WIDTH
if _, err := Initialize(MIN_WIDTH-1, MAX_HEIGHT, false, false, "./"); err == nil {
t.Error("width < MIN_WIDTH: expected error but was accepted")
}
// Test width > MAX_WIDTH
if _, err := Initialize(MAX_WIDTH+1, MAX_HEIGHT, false, false, "./"); err == nil {
t.Error("width > MAX_WIDTH: expected error but was accepted")
}
// Test height < MIN_HEIGHT
if _, err := Initialize(MIN_WIDTH, MIN_HEIGHT-1, false, false, "./"); err == nil {
t.Error("height < MIN_HEIGHT: expected error but was accepted")
}
// Test height > MAX_HEIGHT
if _, err := Initialize(MIN_WIDTH, MAX_HEIGHT+1, false, false, "./"); err == nil {
t.Error("height > MAX_HEIGHT: expected error but was accepted")
}
// Test correct values
if _, err := Initialize(MIN_WIDTH, MAX_HEIGHT, false, false, "./"); err != nil {
t.Error(err)
}
}
func TestPicture(t *testing.T) {
c, err := Initialize(MAX_WIDTH, MAX_HEIGHT, true, true, "./")
if err != nil {
t.Error(err)
}
// Test taking picture
if _, err = c.Picture(); err != nil && err.Error() != "exec: \"raspistill\": executable file not found in $PATH" {
t.Error(err)
}
}
func TestVideo(t *testing.T) {
c, err := Initialize(MAX_WIDTH, MAX_HEIGHT, true, true, "./")
if err != nil {
t.Error(err)
}
// Test duration < MIN_DURATION
if _, err = c.Video(0, false); err == nil {
t.Error("Duration < MIN_DURATION: expected error but was accepted")
}
// Test correct values, no convert
if _, err = c.Video(MIN_DURATION+10, false); err != nil && err.Error() != "exec: \"raspivid\": executable file not found in $PATH" {
t.Error(err)
}
// Test correct values, convert
if _, err = c.Video(MIN_DURATION+10, true); err != nil && err.Error() != "exec: \"raspivid\": executable file not found in $PATH" {
t.Error(err)
}
}
func TestBuildArgs(t *testing.T) {
c, err := Initialize(MAX_WIDTH, MAX_HEIGHT, true, true, "./")
if err != nil {
t.Error(err)
}
// Test for Picture
args := buildArgs(c, "foo.jpg", false, 0)
ref := fmt.Sprintf("%v %v %v %v %v %v %v %v %v %v",
STILL, WIDTHF, c.width, HEIGHTF, c.height, NO_PREVIEWF, OUTF, filepath.Join(c.savePath, "foo.jpg"),
HFLIPF, VFLIPF)
res := STILL + " " + strings.Join(args, " ")
if res != ref {
t.Errorf("Expected: %v, got: %v", ref, res)
}
// Test for Video
args = buildArgs(c, "foo.jpg", true, 50)
ref = fmt.Sprintf("%v %v %v %v %v %v %v %v %v %v %v %v",
VID, WIDTHF, c.width, HEIGHTF, c.height, NO_PREVIEWF, OUTF, filepath.Join(c.savePath, "foo.jpg"),
HFLIPF, VFLIPF, TIMEF, 50*1000)
res = VID + " " + strings.Join(args, " ")
if res != ref {
t.Errorf("Expected: %v, got: %v", ref, res)
}
}