-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcontext_test.go
156 lines (137 loc) · 3.42 KB
/
context_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
155
156
package proj_test
import (
"runtime"
"strconv"
"testing"
"github.com/alecthomas/assert/v2"
"github.com/twpayne/go-proj/v11"
)
func TestContext_NewCRSToCRS(t *testing.T) {
defer runtime.GC()
context := proj.NewContext()
assert.NotZero(t, context)
for _, tc := range []struct {
name string
sourceCRS string
targetCRS string
expectedErr map[int]string
}{
{
name: "EPSG:4326_to_EPSG;3857",
sourceCRS: "EPSG:4326",
targetCRS: "EPSG:3857",
},
{
name: "EPSG:4326_to_invalid",
sourceCRS: "EPSG:4326",
targetCRS: "invalid",
expectedErr: map[int]string{
6: "generic error of unknown origin",
8: "Unknown error (code 4096)",
9: "Invalid PROJ string syntax",
},
},
} {
t.Run(tc.name, func(t *testing.T) {
pj, err := context.NewCRSToCRS(tc.sourceCRS, tc.targetCRS, nil)
if tc.expectedErr != nil {
assert.EqualError(t, err, tc.expectedErr[proj.VersionMajor])
assert.Zero(t, pj)
} else {
assert.NoError(t, err)
assert.NotZero(t, pj)
}
})
}
}
func TestContext_NewCRSToCRSFromPJ(t *testing.T) {
defer runtime.GC()
sourceCRS, err := proj.New("epsg:4326")
assert.NoError(t, err)
assert.True(t, sourceCRS.IsCRS())
targetCRS, err := proj.New("epsg:3857")
assert.NoError(t, err)
assert.True(t, targetCRS.IsCRS())
pj, err := proj.NewCRSToCRSFromPJ(sourceCRS, targetCRS, nil, "")
assert.NoError(t, err)
assert.NotZero(t, pj)
}
func TestContext_New(t *testing.T) {
defer runtime.GC()
context := proj.NewContext()
assert.NotZero(t, context)
for _, tc := range []struct {
definition string
expectedErr map[int]string
}{
{
definition: "epsg:4326",
},
{
definition: "+proj=etmerc +lat_0=38 +lon_0=125 +ellps=bessel",
},
{
definition: "invalid",
expectedErr: map[int]string{
6: "generic error of unknown origin",
8: "Unknown error (code 4096)",
9: "Invalid PROJ string syntax",
},
},
} {
t.Run(tc.definition, func(t *testing.T) {
pj, err := context.New(tc.definition)
if tc.expectedErr != nil {
assert.EqualError(t, err, tc.expectedErr[proj.VersionMajor])
assert.Zero(t, pj)
} else {
assert.NoError(t, err)
assert.NotZero(t, pj)
}
})
}
}
func TestContext_NewFromArgs(t *testing.T) {
defer runtime.GC()
context := proj.NewContext()
assert.NotZero(t, context)
for i, tc := range []struct {
args []string
expectedErr map[int]string
}{
{
args: []string{"proj=utm", "zone=32", "ellps=GRS80"},
},
{
args: []string{"proj=utm", "zone=0", "ellps=GRS80"},
expectedErr: map[int]string{
6: "invalid UTM zone number",
8: "Invalid value for an argument",
9: "Invalid value for an argument",
},
},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
pj, err := context.NewFromArgs(tc.args...)
if tc.expectedErr != nil {
assert.EqualError(t, err, tc.expectedErr[proj.VersionMajor])
assert.Zero(t, pj)
} else {
assert.NoError(t, err)
assert.NotZero(t, pj)
}
})
}
}
func TestContext_SetSearchPaths(t *testing.T) {
defer runtime.GC()
context := proj.NewContext()
assert.NotZero(t, context)
// The C function does not return any error so we only validate
// that executing the SetSearchPaths function call
// does not panic considering various boundary conditions
context.SetSearchPaths(nil)
context.SetSearchPaths([]string{})
context.SetSearchPaths([]string{"/tmp/data"})
context.SetSearchPaths([]string{"/tmp/data", "/tmp/data2"})
}