-
Notifications
You must be signed in to change notification settings - Fork 12
/
parser_test.go
80 lines (65 loc) · 1.56 KB
/
parser_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
package main
import (
"os"
"strings"
"testing"
)
func newLocalFile(f string) ([]byte, error) {
return os.ReadFile(f)
}
func newSplit(b []byte) ([]byte, []byte) {
var header []byte
var def []byte
header = append(header, b[0:headerLength]...)
def = append(def, b[headerLength:]...)
return header, def
}
func TestParseCVD(t *testing.T) {
testFile, err := newLocalFile("filedefs/bytecode.cvd")
if err != nil {
t.Error("cannot read from cache or local disk! tests cannot run!")
t.FailNow()
}
var errs []error
_ = ParseCVD(testFile, &errs)
if len(errs) > 0 {
t.Errorf("%v", errs)
t.Fail()
}
}
func TestHeaderFields_ParseTime(t *testing.T) {
testTime := "09 Mar 2017 16-12 -0500"
testHeader := newEmptyHeader()
testHeader.ParseTime(testTime)
if len(testHeader.Problems) > 0 {
t.Error(testHeader.Problems)
t.Fail()
}
}
func TestHeaderFields_Atou(t *testing.T) {
have := "1234"
want := uint(1234)
testHeader := newEmptyHeader()
got := testHeader.Atou(have)
if want != got {
t.Logf("have: %s, want: %d, got: %d", have, want, got)
t.Fail()
}
}
func TestHeaderFields_ParseMD5(t *testing.T) {
testHeader := newEmptyHeader()
testFile, err := newLocalFile("filedefs/bytecode.cvd")
if err != nil {
t.Error(err)
t.FailNow()
}
testFileHeader, testFileBody := newSplit(testFile)
testHeadParts := strings.Split(string(testFileHeader), ":")
want := testHeadParts[5]
testHeader.ParseMD5(testHeadParts[5], testFileBody)
got := testHeader.MD5Hash
if want != got && !testHeader.MD5Valid {
t.Errorf("got md5: %s, want: %s", got, want)
t.Fail()
}
}