-
Notifications
You must be signed in to change notification settings - Fork 13
/
runtests.jl
56 lines (46 loc) · 2.09 KB
/
runtests.jl
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
using GDAL
using Base.Test
info(unsafe_string(GDAL.C.GDALVersionInfo("--version")))
# drivers
# before being able to use any drivers, they must be registered first
GDAL.allregister()
info(GDAL.getdrivercount(), " GDAL drivers found")
info(GDAL.ogrgetdrivercount(), " OGR drivers found")
@test GDAL.getdrivercount() > 0
@test GDAL.ogrgetdrivercount() > 0
# test if the registered error handler also handles CE_Fatal
@test_throws GDAL.GDALError GDAL.emergencyerror("we've got a problem")
GDAL.errorreset()
# throw errors on non existing files
@test_throws GDAL.GDALError GDAL.open("NonExistent", GDAL.GA_ReadOnly)
# if a driver is not found, the C API returns a null
@test GDAL.C.GDALGetDriverByName("NonExistent") == C_NULL
# whilst the rewritten API throws a GDALError
@test_throws GDAL.GDALError GDAL.getdriverbyname("NonExistent")
srs = GDAL.newspatialreference(C_NULL)
GDAL.importfromepsg(srs, 4326) # fails if GDAL_DATA is not set correctly
xmlnode_pointer = GDAL.C.CPLParseXMLString("<a><b>hi</b></a>")
@test unsafe_string(GDAL.C.CPLGetXMLValue(xmlnode_pointer, "b", "")) == "hi"
# load into Julia struct, mutate, and put back as Ref into GDAL
xmlnode = unsafe_load(xmlnode_pointer)
xmlnode.pszValue = Base.unsafe_convert(Cstring, "c") # rename "a" to "c"
@test unsafe_string(GDAL.C.CPLSerializeXMLTree(Ref(xmlnode))) == "<c>\n <b>hi</b>\n</c>\n"
GDAL.C.CPLDestroyXMLNode(xmlnode_pointer)
# ref https://github.com/JuliaGeo/GDAL.jl/pull/41#discussion_r143345433
gfld = GDAL.gfld_create("name-a", GDAL.wkbPoint)
@test gfld isa Ptr{GDAL.OGRGeomFieldDefnH}
@test GDAL.getnameref(gfld) == "name-a"
@test GDAL.gettype(gfld) == GDAL.wkbPoint
# same as above but for the lower level C API
gfld = GDAL.C.OGR_GFld_Create("name-b", GDAL.C.wkbPolygon)
@test gfld isa Ptr{Void}
@test unsafe_string(GDAL.C.OGR_GFld_GetNameRef(gfld)) == "name-b"
@test GDAL.C.OGR_GFld_GetType(gfld) == GDAL.C.wkbPolygon
cd(dirname(@__FILE__)) do
isdir("tmp") || mkpath("tmp") # ensure it exists
include("tutorial_raster.jl")
include("tutorial_vector.jl")
include("tutorial_vrt.jl")
include("gdal_utils.jl")
end
GDAL.destroydrivermanager()