-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontext_test.go
76 lines (70 loc) · 2.24 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
package proj
import (
"testing"
"os"
"reflect"
)
// Tests :
// TestContext creates and destroy threading-context.
func TestContext ( t *testing.T) {
pj := os.Getenv("PROJ_LIB")
os.Setenv("PROJ_LIB",os.TempDir()) // fake path to prevent retrieval of proj.db
c := NewContext()
if c.HandleIsNil() {
t.Errorf("Failed to create a new threading-context")
}
c.SetDatabasePath(os.TempDir()) // this should failed ... but PROJ keeps the previous path which is wrong too !
if c.DatabasePath() != "" {
t.Errorf("Unexpected database path %s for threading-context", c.DatabasePath())
}
if pj != "" {
os.Setenv("PROJ_LIB",pj) // back to the right path ...
}
if c.DatabasePath() == "" {
t.Errorf("Expected database path for threading-context")
}
c.DestroyContext()
if reflect.ValueOf(c.Handle()).Elem() != reflect.Zero(reflect.TypeOf(c.Handle())).Elem() {
t.Errorf("Failed to deallocate the newly created threading-context")
}
}
// TestDefaultContext checks the default context.
func TestDefaultContext ( t *testing.T) {
if ctx.HandleIsNil() {
t.Errorf("Failed to create tests context safe thread")
}
if ctx.DatabasePath() == "" {
t.Errorf("Expected database path for default context")
}
s := "EPSG"
if !ctx.IsAnAuthority(s) {
t.Errorf("Expected '%s' to be an authority", s)
}
s = "UnKnownAuthority"
if ctx.IsAnAuthority(s) {
t.Errorf("Unexpected '%s' to be an authority", s)
}
}
// TestCtxLogging checks the logging levels.
func TestCtxLogging ( t *testing.T) {
lvl := ctx.LogLevel()
if lvl != None {
t.Errorf("Expected default log level to be '%d', but got '%d'", None, lvl)
}
ctx.SetLogLevel(Error)
lvl = ctx.LogLevel()
if lvl != Error {
t.Errorf("Expected default log level to be '%d', but got '%d'", Error, lvl)
}
ctx.SetLogLevel(Debug)
lvl = ctx.LogLevel()
if lvl != Debug {
t.Errorf("Expected default log level to be '%d', but got '%d'", Debug, lvl)
}
ctx.SetLogLevel(Trace)
lvl = ctx.LogLevel()
if lvl != Trace {
t.Errorf("Expected default log level to be '%d', but got '%d'", Trace, lvl)
}
ctx.SetLogLevel(None)
}