-
Notifications
You must be signed in to change notification settings - Fork 35
/
file_test.go
119 lines (106 loc) · 2.47 KB
/
file_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
// Copyright 2017 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rootio
import (
"testing"
)
func TestFileDirectory(t *testing.T) {
f, err := Open("testdata/small-flat-tree.root")
if err != nil {
t.Fatal(err.Error())
}
defer f.Close()
for _, table := range []struct {
test string
value string
want string
}{
{"Name", f.Name(), "test-small.root"}, // name when created
{"Title", f.Title(), "small event file"},
{"Class", f.Class(), "TFile"},
} {
if table.value != table.want {
t.Fatalf("%v: got=%q, want=%q", table.test, table.value, table.want)
}
}
for _, table := range []struct {
name string
want bool
}{
{"tree", true},
{"tree;0", false},
{"tree;1", true},
{"tree;9999", true},
{"tree_nope", false},
{"tree_nope;0", false},
{"tree_nope;1", false},
{"tree_nope;9999", false},
} {
_, err := f.Get(table.name)
if (err == nil) != table.want {
t.Fatalf("%s: got key (err=%v). want=%v", table.name, err, table.want)
}
}
for _, table := range []struct {
name string
want string
}{
{"tree", "TTree"},
{"tree;1", "TTree"},
} {
k, err := f.Get(table.name)
if err != nil {
t.Fatalf("%s: expected key to exist! (got %v)", table.name, err)
}
if k.Class() != table.want {
t.Fatalf("%s: got key with class=%s (want=%s)", table.name, k.Class(), table.want)
}
}
for _, table := range []struct {
name string
want string
}{
{"tree", "tree"},
{"tree;1", "tree"},
} {
o, err := f.Get(table.name)
if err != nil {
t.Fatalf("%s: expected key to exist! (got %v)", table.name, err)
}
k := o.(Named)
if k.Name() != table.want {
t.Fatalf("%s: got key with name=%s (want=%v)", table.name, k.Name(), table.want)
}
}
for _, table := range []struct {
name string
want string
}{
{"tree", "my tree title"},
{"tree;1", "my tree title"},
} {
o, err := f.Get(table.name)
if err != nil {
t.Fatalf("%s: expected key to exist! (got %v)", table.name, err)
}
k := o.(Named)
if k.Title() != table.want {
t.Fatalf("%s: got key with title=%s (want=%v)", table.name, k.Title(), table.want)
}
}
}
func TestFileOpenStreamerInfo(t *testing.T) {
for _, fname := range []string{
"testdata/small-flat-tree.root",
"testdata/simple.root",
} {
f, err := Open(fname)
if err != nil {
t.Errorf("error opening %q: %v\n", fname, err)
continue
}
defer f.Close()
_ = f.StreamerInfo()
}
}