-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathsequentialreader_test.go
43 lines (37 loc) · 975 Bytes
/
sequentialreader_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
package shp
import (
"os"
"testing"
)
func openFile(name string, t *testing.T) *os.File {
f, err := os.Open(name)
if err != nil {
t.Fatalf("Failed to open %s: %v", name, err)
}
return f
}
func getShapesSequentially(prefix string, t *testing.T) (shapes []Shape) {
shp := openFile(prefix+".shp", t)
dbf := openFile(prefix+".dbf", t)
sr := SequentialReaderFromExt(shp, dbf)
if err := sr.Err(); err != nil {
t.Fatalf("Error when iterating over the shapefile header: %v", err)
}
for sr.Next() {
_, shape := sr.Shape()
shapes = append(shapes, shape)
}
if err := sr.Err(); err != nil {
t.Errorf("Error when iterating over the shapes: %v", err)
}
if err := sr.Close(); err != nil {
t.Errorf("Could not close sequential reader: %v", err)
}
return shapes
}
func TestSequentialReader(t *testing.T) {
for prefix := range dataForReadTests {
t.Logf("Testing sequential read for %s", prefix)
testshapeIdentity(t, prefix, getShapesSequentially)
}
}