File: tc_canvas.rb

package info (click to toggle)
libcaca 0.99.beta14-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 6,720 kB
  • ctags: 2,334
  • sloc: ansic: 18,652; cs: 1,171; objc: 835; cpp: 741; makefile: 446; sh: 289; python: 215; ruby: 190; asm: 93
file content (59 lines) | stat: -rw-r--r-- 1,769 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
59
require 'test/unit'
require 'cucul'

class TC_Canvas < Test::Unit::TestCase
    def setup
        @c = Cucul::Canvas.new(3, 3)
    end
    def test_create
        c = Cucul::Canvas.new(3, 3)
        assert_not_nil(c, 'Canvas creation failed')
        assert(c.width == 3 && c.height == 3, 'Wrong size for new canvas')
    end
    def test_width
        @c.width = 42
        assert_equal(42, @c.width, 'Failed to set width with =')
        @c.set_width(24)
        assert_equal(24, @c.width, 'Failed to set width')
    end
    def test_height
        @c.height = 42
        assert_equal(42, @c.height, 'Failed to set height with =')
        @c.set_height(24)
        assert_equal(24, @c.height, 'Failed to set height')
    end
    def test_size
        @c.set_size(100,100)
        assert(@c.width == 100 && @c.height == 100, 'Failed to set size')
    end
    def test_import
        @c.import_memory("foo", "")
        assert_equal("foo\r\n", @c.export_memory("irc"), "Import/Export failed")
    end
    def test_cursor
        @c.gotoxy(1,1)
        assert_equal(1, @c.cursor_x)
        assert_equal(1, @c.cursor_y)
    end
    def test_clear
        @c.put_char(1, 1, 64)
        @c.clear
        assert_equal("", @c.export_memory("irc").strip, "Failed to clear canvas")
    end
    def test_char
        @c.put_char(1, 1, 42)
        assert_equal(42, @c.get_char(1,1))
    end
    def test_render
        c = Cucul::Canvas.new(4,4)
	c.put_str(0,0,"plop")
	f = Cucul::Font.new(Cucul::Font.list[0])
	assert_not_nil(c.render(f, c.width*f.width, c.height*f.height, c.width*f.width*4))
    end
    def test_fail_render
        c = Cucul::Canvas.new(4,4)
        assert_raise(ArgumentError) {
            c.render(nil, c.width, c.height, c.width*4)
        }
    end
end