forked from lukeroth/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress_test.go
More file actions
129 lines (106 loc) · 3.18 KB
/
Copy pathprogress_test.go
File metadata and controls
129 lines (106 loc) · 3.18 KB
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
package gdal
import (
"runtime"
"testing"
)
func createFilledMemoryRasterDataset(t *testing.T, xSize, ySize int) Dataset {
t.Helper()
ds := createMemoryRasterDataset(t, xSize, ySize, 1, Byte)
buffer := make([]uint8, xSize*ySize)
for i := range buffer {
buffer[i] = uint8(i % 251)
}
if err := ds.RasterBand(1).IO(Write, 0, 0, xSize, ySize, buffer, xSize, ySize, 0, 0); err != nil {
ds.Close()
t.Fatalf("RasterBand.IO(Write): %v", err)
}
return ds
}
func TestProgressCallbackBridgeNilHandle(t *testing.T) {
if got := callGoGDALProgressFuncProxy(0, 0.5, "ignored"); got != 1 {
t.Fatalf("callGoGDALProgressFuncProxy(nil) = %d, want 1", got)
}
}
func TestProgressCallbackBridgeDispatches(t *testing.T) {
marker := &struct{ name string }{name: "marker"}
var (
called bool
gotComplete float64
gotMessage string
gotData interface{}
)
callback := newGoGDALProgressCallback(func(complete float64, message string, progressArg interface{}) int {
called = true
gotComplete = complete
gotMessage = message
gotData = progressArg
return 7
}, marker)
defer callback.close()
runtime.GC()
if got := callGoGDALProgressFuncProxy(uintptr(callback.handle), 0.25, "stage"); got != 7 {
t.Fatalf("callGoGDALProgressFuncProxy(...) = %d, want 7", got)
}
if !called {
t.Fatal("progress callback was not called")
}
if gotComplete != 0.25 {
t.Fatalf("progress complete = %v, want 0.25", gotComplete)
}
if gotMessage != "stage" {
t.Fatalf("progress message = %q, want %q", gotMessage, "stage")
}
if gotData != marker {
t.Fatalf("progress data = %#v, want %#v", gotData, marker)
}
}
func TestCopyWholeRasterNilProgress(t *testing.T) {
src := createFilledMemoryRasterDataset(t, 512, 512)
defer src.Close()
dst := createMemoryRasterDataset(t, 512, 512, 1, Byte)
defer dst.Close()
runtime.GC()
if err := src.CopyWholeRaster(dst, nil, nil, nil); err != nil {
t.Fatalf("CopyWholeRaster(nil progress): %v", err)
}
if got, want := dst.RasterBand(1).Checksum(0, 0, 512, 512), src.RasterBand(1).Checksum(0, 0, 512, 512); got != want {
t.Fatalf("destination checksum = %d, want %d", got, want)
}
}
func TestCopyWholeRasterProgressCallback(t *testing.T) {
src := createFilledMemoryRasterDataset(t, 512, 512)
defer src.Close()
dst := createMemoryRasterDataset(t, 512, 512, 1, Byte)
defer dst.Close()
marker := &struct{ name string }{name: "copy-whole-raster"}
var (
calls int
invalidData bool
invalidAmount bool
)
runtime.GC()
if err := src.CopyWholeRaster(dst, nil, func(complete float64, message string, progressArg interface{}) int {
calls++
if progressArg != marker {
invalidData = true
}
if complete < 0 || complete > 1 {
invalidAmount = true
}
return 1
}, marker); err != nil {
t.Fatalf("CopyWholeRaster(progress): %v", err)
}
if calls == 0 {
t.Fatal("progress callback was not called")
}
if invalidData {
t.Fatal("progress callback received unexpected data")
}
if invalidAmount {
t.Fatal("progress callback received invalid completion value")
}
if got, want := dst.RasterBand(1).Checksum(0, 0, 512, 512), src.RasterBand(1).Checksum(0, 0, 512, 512); got != want {
t.Fatalf("destination checksum = %d, want %d", got, want)
}
}