File: svg_surface.lua

package info (click to toggle)
oocairo 1.4-1.2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 712 kB
  • sloc: ansic: 3,352; makefile: 59; sh: 15
file content (58 lines) | stat: -rw-r--r-- 1,682 bytes parent folder | download
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
require "test-setup"
require "lunit"
local Cairo = require "oocairo"

module("test.svg_surface", lunit.testcase, package.seeall)

teardown = clean_up_temp_files

if Cairo.HAS_SVG_SURFACE then
    function test_svg_versions ()
        local versions = Cairo.svg_get_versions()
        assert_table(versions)
        for k, v in pairs(versions) do
            assert_number(k)
            assert_string(v)
        end
    end

    local function check_svg_surface (surface)
        assert_userdata(surface)
        assert_equal("cairo surface object", surface._NAME)
        assert_equal("svg", surface:get_type())
    end

    local function check_file_contains_svg (filename)
        local fh = assert(io.open(filename, "rb"))
        local data = fh:read("*a")
        fh:close()
        assert_match("<svg", data)
    end

    function test_create ()
        local filename = tmpname()
        local surface = Cairo.svg_surface_create(filename, 300, 200)
        check_svg_surface(surface)
        draw_arbitrary_stuff(Cairo, surface)
        surface:finish()
        check_file_contains_svg(filename)
    end

    function test_create_stream ()
        local filename = tmpname()
        local fh = assert(io.open(filename, "wb"))
        local surface = Cairo.svg_surface_create(fh, 300, 200)
        check_svg_surface(surface)
        draw_arbitrary_stuff(Cairo, surface)
        surface:finish()
        fh:close()
        check_file_contains_svg(filename)
    end

    function test_create_bad ()
        assert_error("wrong type instead of file/filename",
                     function () Cairo.svg_surface_create(true, 300, 200) end)
    end
end

-- vi:ts=4 sw=4 expandtab