source: libcaca/trunk/ruby/t/tc_canvas.rb @ 2297

Last change on this file since 2297 was 2004, checked in by Pascal Terjan, 13 years ago
  • Improve type checking of arguments
File size: 1.7 KB
Line 
1require 'test/unit'
2require 'cucul'
3
4class TC_Canvas < Test::Unit::TestCase
5    def setup
6        @c = Cucul::Canvas.new(3, 3)
7    end
8    def test_create
9        c = Cucul::Canvas.new(3, 3)
10        assert_not_nil(c, 'Canvas creation failed')
11        assert(c.width == 3 && c.height == 3, 'Wrong size for new canvas')
12    end
13    def test_width
14        @c.width = 42
15        assert_equal(42, @c.width, 'Failed to set width with =')
16        @c.set_width(24)
17        assert_equal(24, @c.width, 'Failed to set width')
18    end
19    def test_height
20        @c.height = 42
21        assert_equal(42, @c.height, 'Failed to set height with =')
22        @c.set_height(24)
23        assert_equal(24, @c.height, 'Failed to set height')
24    end
25    def test_size
26        @c.set_size(100,100)
27        assert(@c.width == 100 && @c.height == 100, 'Failed to set size')
28    end
29    def test_import
30        @c.import_memory("foo", "")
31        assert_equal("foo\r\n", @c.export_memory("irc"), "Import/Export failed")
32    end
33    def test_cursor
34        @c.gotoxy(1,1)
35        assert_equal(1, @c.cursor_x)
36        assert_equal(1, @c.cursor_y)
37    end
38    def test_clear
39        @c.put_char(1, 1, 64)
40        @c.clear
41        assert_equal("", @c.export_memory("irc").strip, "Failed to clear canvas")
42    end
43    def test_char
44        @c.put_char(1, 1, 42)
45        assert_equal(42, @c.get_char(1,1))
46    end
47    def test_render
48        c = Cucul::Canvas.new(4,4)
49        c.put_str(0,0,"plop")
50        f = Cucul::Font.new(Cucul::Font.list[0])
51        assert_not_nil(c.render(f, c.width*f.width, c.height*f.height, c.width*f.width*4))
52    end
53    def test_fail_render
54        c = Cucul::Canvas.new(4,4)
55        assert_raise(ArgumentError) {
56            c.render(nil, c.width, c.height, c.width*4)
57        }
58    end
59end
Note: See TracBrowser for help on using the repository browser.