-
Notifications
You must be signed in to change notification settings - Fork 33
/
h5g_group_test.go
154 lines (131 loc) · 3.26 KB
/
h5g_group_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
147
148
149
150
151
152
153
154
// Copyright ©2017 The Gonum 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 hdf5
import (
"os"
"testing"
)
func TestGroup(t *testing.T) {
f, err := CreateFile(fname, F_ACC_TRUNC)
if err != nil {
t.Fatalf("CreateFile failed: %s", err)
}
defer os.Remove(fname)
defer f.Close()
if f.LinkExists("/foo") {
t.Error("unexpected /foo link present")
}
g1, err := f.CreateGroup("foo")
if err != nil {
t.Fatalf("couldn't create group: %s", err)
}
g1f := g1.File()
defer g1f.Close()
if *g1f != *f {
t.Fatal("wrong file for group")
}
if g1.Name() != "/foo" {
t.Errorf(`wrong name for group: want:"/foo", got:%q`, g1.Name())
}
if !f.LinkExists("/foo") {
t.Error(`unexpected "/foo" group link not present`)
}
if g1.LinkExists("bar") {
t.Error(`unexpected "bar" child link for "/foo" group`)
}
g2, err := g1.CreateGroup("bar")
if err != nil {
t.Fatalf("couldn't create group: %s", err)
}
g2f := g2.File()
defer g2f.Close()
if *g2f != *f {
t.Fatal("wrong file for group")
}
if g2.Name() != "/foo/bar" {
t.Errorf("wrong Name for group: want %q, got %q", "/foo/bar", g1.Name())
}
if !g1.LinkExists("bar") {
t.Error(`expected "bar" child link for "/foo" group not present`)
}
g3, err := g2.CreateGroup("baz")
if err != nil {
t.Fatalf("couldn't create group: %s", err)
}
g3f := g3.File()
defer g3f.Close()
if *g3f != *f {
t.Fatal("wrong file for group")
}
if g3.Name() != "/foo/bar/baz" {
t.Errorf("wrong Name for group: want %q, got %q", "/foo/bar/bar", g1.Name())
}
if nObjs, err := g2.NumObjects(); err != nil {
t.Fatal(err)
} else if nObjs != 1 {
t.Errorf("wrong number of objects in group: want 1, got %d", nObjs)
}
if name, err := g2.ObjectNameByIndex(0); err != nil {
t.Fatalf("could not retrieve object name idx=%d: %+v", 0, err)
} else if got, want := name, "baz"; got != want {
t.Errorf("invalid name for object idx=%d: got=%q, want=%q", 0, got, want)
}
if typ, err := g2.ObjectTypeByIndex(0); err != nil {
t.Fatalf("could not retrieve object type idx=%d: %+v", 0, err)
} else if got, want := typ, H5G_GROUP; got != want {
t.Errorf("invalid type for object idx=%d: got=%v, want=%v", 0, got, want)
}
err = g1.Close()
if err != nil {
t.Error(err)
}
err = g2.Close()
if err != nil {
t.Error(err)
}
err = g3.Close()
if err != nil {
t.Error(err)
}
g2, err = f.OpenGroup("/foo/bar")
if err != nil {
t.Fatal(err)
}
defer g2.Close()
g3, err = g2.OpenGroup("baz")
if err != nil {
t.Fatal(err)
}
defer g3.Close()
_, err = g3.OpenGroup("bs")
if err == nil {
t.Fatal("expected error on opening invalid group")
}
data := 5
dtype, err := NewDatatypeFromValue(data)
if err != nil {
t.Fatal(err)
}
defer dtype.Close()
dims := []uint{1}
dspace, err := CreateSimpleDataspace(dims, dims)
if err != nil {
t.Fatal(err)
}
defer dspace.Close()
dset, err := g3.CreateDataset("dset", dtype, dspace)
if err != nil {
t.Fatal(err)
}
defer dset.Close()
dset2, err := g3.OpenDataset("dset")
if dset.Name() != dset2.Name() {
t.Error("expected dataset names to be equal")
}
defer dset2.Close()
dset2, err = g3.OpenDataset("bs")
if err == nil {
t.Errorf("opened dataset that was never created: %v", dset2)
}
}