| 1 | require 'caca' |
|---|
| 2 | |
|---|
| 3 | class TC_Canvas < Test::Unit::TestCase |
|---|
| 4 | def setup |
|---|
| 5 | @c = Caca::Canvas.new(3, 3) |
|---|
| 6 | end |
|---|
| 7 | def test_create |
|---|
| 8 | c = Caca::Canvas.new(3, 3) |
|---|
| 9 | assert_not_nil(c, 'Canvas creation failed') |
|---|
| 10 | assert(c.width == 3 && c.height == 3, 'Wrong size for new canvas') |
|---|
| 11 | end |
|---|
| 12 | def test_width |
|---|
| 13 | @c.width = 42 |
|---|
| 14 | assert_equal(42, @c.width, 'Failed to set width with =') |
|---|
| 15 | @c.set_width(24) |
|---|
| 16 | assert_equal(24, @c.width, 'Failed to set width') |
|---|
| 17 | end |
|---|
| 18 | def test_height |
|---|
| 19 | @c.height = 42 |
|---|
| 20 | assert_equal(42, @c.height, 'Failed to set height with =') |
|---|
| 21 | @c.set_height(24) |
|---|
| 22 | assert_equal(24, @c.height, 'Failed to set height') |
|---|
| 23 | end |
|---|
| 24 | def test_size |
|---|
| 25 | @c.set_size(100,100) |
|---|
| 26 | assert(@c.width == 100 && @c.height == 100, 'Failed to set size') |
|---|
| 27 | end |
|---|
| 28 | def test_import |
|---|
| 29 | @c.import_memory("foo", "") |
|---|
| 30 | assert_equal("foo\r\n", @c.export_memory("irc"), "Import/Export failed") |
|---|
| 31 | end |
|---|
| 32 | def test_cursor |
|---|
| 33 | @c.gotoxy(1,1) |
|---|
| 34 | assert_equal(1, @c.cursor_x) |
|---|
| 35 | assert_equal(1, @c.cursor_y) |
|---|
| 36 | end |
|---|
| 37 | def test_clear |
|---|
| 38 | @c.put_char(1, 1, 64) |
|---|
| 39 | @c.clear |
|---|
| 40 | assert_equal("", @c.export_memory("irc").strip, "Failed to clear canvas") |
|---|
| 41 | end |
|---|
| 42 | def test_char |
|---|
| 43 | @c.put_char(1, 1, 42) |
|---|
| 44 | assert_equal(42, @c.get_char(1,1)) |
|---|
| 45 | end |
|---|
| 46 | def test_render |
|---|
| 47 | c = Caca::Canvas.new(4,4) |
|---|
| 48 | c.put_str(0,0,"plop") |
|---|
| 49 | f = Caca::Font.new(Caca::Font.list[0]) |
|---|
| 50 | assert_not_nil(c.render(f, c.width*f.width, c.height*f.height, c.width*f.width*4)) |
|---|
| 51 | end |
|---|
| 52 | def test_fail_render |
|---|
| 53 | c = Caca::Canvas.new(4,4) |
|---|
| 54 | assert_raise(ArgumentError) { |
|---|
| 55 | c.render(nil, c.width, c.height, c.width*4) |
|---|
| 56 | } |
|---|
| 57 | end |
|---|
| 58 | end |
|---|