-
Notifications
You must be signed in to change notification settings - Fork 2
/
scanner_test.go
113 lines (102 loc) · 2.9 KB
/
scanner_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
package matroska
import (
"fmt"
"os"
"path/filepath"
"testing"
)
func TestScanner(t *testing.T) {
tests := []struct {
name string
filename string
source string
wantErr bool
wantClusterLen int // Result of `mkvinfo -o matroska/test8.mkv | grep '|+ Cluster' | wc -l`
}{
{
name: "Basic file",
filename: "test1.mkv",
source: "https://github.com/Matroska-Org/matroska-test-files/blob/master/test_files/test1.mkv?raw=true",
wantClusterLen: 11,
},
{
name: "Non default timecodescale & aspect ratio",
filename: "test2.mkv",
source: "https://github.com/Matroska-Org/matroska-test-files/blob/master/test_files/test2.mkv?raw=true",
wantClusterLen: 47,
},
{
name: "Header stripping & standard block",
filename: "test3.mkv",
source: "https://github.com/Matroska-Org/matroska-test-files/blob/master/test_files/test3.mkv?raw=true",
wantClusterLen: 47,
},
{
name: "Live stream recording",
filename: "test4.mkv",
source: "https://github.com/Matroska-Org/matroska-test-files/blob/master/test_files/test4.mkv?raw=true",
wantClusterLen: 36,
},
{
name: "Multiple audio/subtitles",
filename: "test5.mkv",
source: "https://github.com/Matroska-Org/matroska-test-files/blob/master/test_files/test5.mkv?raw=true",
wantClusterLen: 25,
},
{
name: "Different EBML head sizes & cue-less seeking",
filename: "test6.mkv",
source: "https://github.com/Matroska-Org/matroska-test-files/blob/master/test_files/test6.mkv?raw=true",
wantClusterLen: 11,
},
{
name: "Extra unknown/junk elements & damaged",
filename: "test7.mkv",
source: "https://github.com/Matroska-Org/matroska-test-files/blob/master/test_files/test7.mkv?raw=true",
wantErr: true,
wantClusterLen: 37,
},
{
name: "Audio gap",
filename: "test8.mkv",
source: "https://github.com/Matroska-Org/matroska-test-files/blob/master/test_files/test8.mkv?raw=true",
wantClusterLen: 47,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f, err := os.Open(filepath.Join(".", tt.filename))
if err != nil {
if !os.IsNotExist(err) {
t.Fatal(err)
}
if err := downloadTestFile(tt.filename, tt.source); err != nil {
t.Fatal(err)
}
if f, err = os.Open(filepath.Join(".", tt.filename)); err != nil {
t.Fatal(err)
}
}
defer f.Close()
s, err := NewScanner(f)
if err != nil {
t.Fatal(err)
}
fmt.Printf("%+v\n", s.Info())
fmt.Printf("%+v\n", s.Tracks())
seekHead, ok := s.SeekHead()
fmt.Printf("%+v, %+v\n", ok, seekHead)
var cluster []Cluster
for s.Next() {
cluster = append(cluster, s.Cluster())
}
if tt.wantErr != (s.Err() != nil) {
t.Error(s.Err())
}
if got := len(cluster); got != tt.wantClusterLen {
t.Errorf("len(Cluster) got = %v, want %v", got, tt.wantClusterLen)
}
//fmt.Printf("%+v\n", len(b.Cluster))
})
}
}