-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
146 lines (123 loc) · 2.35 KB
/
main_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
package main
import (
"encoding/base64"
"io/ioutil"
"net/http"
"os"
"regexp"
"testing"
)
var testfile = "tears-of-steel.bif"
var f *os.File
func TestMain(m *testing.M) {
setup()
retCode := m.Run()
teardown()
os.Exit(retCode)
}
func setup() {
buf, err := os.Open(testfile)
if err != nil {
panic(err)
}
f = buf
}
func teardown() {
f.Close()
}
func Test_checkBIF(t *testing.T) {
err := checkBIF(f)
if err != nil {
t.Error()
}
}
func Test_NewBIF(t *testing.T) {
_, err := NewBIF(f)
if err != nil {
t.Error()
}
}
func Test_BIF_getVersion(t *testing.T) {
bif, err := NewBIF(f)
if err != nil {
t.Error()
}
version := bif.getVersion()
if version != 0 {
t.Error()
}
}
func Test_BIF_getFramesCount(t *testing.T) {
bif, err := NewBIF(f)
if err != nil {
t.Error()
}
framesCount := bif.getFramesCount()
if framesCount != 185 {
t.Error()
}
}
func Test_BIF_getFramewiseSeparation(t *testing.T) {
bif, err := NewBIF(f)
if err != nil {
t.Error()
}
fs := bif.getFramewiseSeparation()
if fs != 1000 {
t.Error()
}
}
func Test_BIF_readFrame(t *testing.T) {
bif, err := NewBIF(f)
if err != nil {
t.Error()
}
timestamp1, offset1 := bif.readFrame(64)
if timestamp1 != 1 || offset1 != 1552 {
t.Error()
}
timestamp2, offset2 := bif.readFrame(72)
if timestamp2 != 2 || offset2 != 2861 {
t.Error()
}
}
func Test_BIF_getFrameImage(t *testing.T) {
bif, err := NewBIF(f)
if err != nil {
t.Error()
}
// Get first frame.
frameSize := 2861 - 1552 // frameSize = nextFrameOffet - currentOffset
img := bif.getFrameImage(1552, frameSize)
// Test if valid base64 string.
match, _ := regexp.MatchString("^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$", img)
if !match {
t.Error()
}
// Test if valid jpeg image.
dec, _ := base64.StdEncoding.DecodeString(img)
contentType := http.DetectContentType(dec)
if contentType != "image/jpeg" {
t.Error()
}
}
func Test_BIF_createFrameImage(t *testing.T) {
bif, err := NewBIF(f)
if err != nil {
t.Error()
}
// Get first frame.
frameSize := 2861 - 1552 // frameSize = nextFrameOffet - currentOffset
out := "test"
// Create image.
bif.createFrameImage(0, 2861, frameSize, out)
// Test image.
dat, err := ioutil.ReadFile("test/frame_0.jpg")
if err != nil {
t.Error()
}
contentType := http.DetectContentType(dat)
if contentType != "image/jpeg" {
t.Error()
}
}