Skip to content

Commit

Permalink
do not register all drivers on loading the module
Browse files Browse the repository at this point in the history
Fixes #18

Also updates the tests, and removes some pointer()
calls which are no longer neccesary
  • Loading branch information
visr committed Mar 24, 2016
1 parent 82be083 commit 75b3967
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 2 additions & 4 deletions src/GDAL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ function __init__()
funcptr = cfunction(gdaljl_errorhandler, Ptr{Void}, (UInt32, Cint, Ptr{UInt8}))
C.CPLSetErrorHandler(funcptr)

C.GDALAllRegister()
versionstring = bytestring(C.GDALVersionInfo(pointer("RELEASE_NAME")))
# get GDAL version number
versionstring = bytestring(C.GDALVersionInfo("RELEASE_NAME"))
const GDALVERSION = convert(VersionNumber, versionstring)
if GDALVERSION < v"2.0.0"
warn("GDAL.jl is made for GDAL 2.0 and later")
# deprecated in GDAL 2.0, is covered by GDALRegisterAll
C.OGRRegisterAll()
end
end

Expand Down
20 changes: 13 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
using GDAL
using Base.Test

info(bytestring(GDAL.C.GDALVersionInfo(pointer("--version"))))
info(bytestring(GDAL.C.GDALVersionInfo("--version")))

# drivers
info(GDAL.C.GDALGetDriverCount(), " GDAL drivers found")
info(GDAL.C.OGRGetDriverCount(), " OGR drivers found")
@test GDAL.C.GDALGetDriverCount() > 0
@test GDAL.C.OGRGetDriverCount() > 0
# 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

# throw errors on non existing files
@test_throws GDAL.GDALError GDAL.C.GDALOpen(pointer("NonExistent"), GDAL.C.GA_ReadOnly)
@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(pointer("NonExistent")) == C_NULL
@test GDAL.C.GDALGetDriverByName("NonExistent") == C_NULL
# whilst the rewritten API throws a GDALError
@test_throws GDAL.GDALError GDAL.getdriverbyname("NonExistent")

cd(dirname(@__FILE__)) do
isdir("tmp") || mkpath("tmp") # ensure it exists

include("tutorial_raster.jl")
include("tutorial_vector.jl")
end

GDAL.destroydrivermanager()

0 comments on commit 75b3967

Please sign in to comment.