Skip to content

Commit

Permalink
Return status_t from write_to_png
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Dec 8, 2019
1 parent 6114ec4 commit e560e96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Cairo.jl
Expand Up @@ -415,12 +415,12 @@ end

function write_to_png(surface::CairoSurface, stream::T) where {T<:IO}
callback = get_stream_callback(T)
ccall((:cairo_surface_write_to_png_stream,libcairo), Nothing,
ccall((:cairo_surface_write_to_png_stream,libcairo), status_t,
(Ptr{UInt8},Ptr{Nothing},Any), surface.ptr, callback, stream)
end

function write_to_png(surface::CairoSurface, filename::AbstractString)
ccall((:cairo_surface_write_to_png,libcairo), Nothing,
ccall((:cairo_surface_write_to_png,libcairo), status_t,
(Ptr{UInt8},Ptr{UInt8}), surface.ptr, String(filename))
end

Expand Down
10 changes: 10 additions & 0 deletions test/test_stream.jl
Expand Up @@ -20,3 +20,13 @@ include("shape_functions.jl")

@test length(str_data) > 200
end

@testset "Test that writing images to a temp file works" begin
c = CairoRGBSurface(256,256)
cr = CairoContext(c)
ddots4(cr,256,246,1.0,3000)
fn = tempname()*".png"
@test write_to_png(c,fn) == Cairo.STATUS_SUCCESS
@test isfile(fn)
rm(fn) # clean up
end

0 comments on commit e560e96

Please sign in to comment.