| 1 |
require 'caca' |
| 2 |
|
| 3 |
class TC_Canvas < MiniTest::Test |
| 4 |
def setup |
| 5 |
@c = Caca::Canvas.new(3, 3) |
| 6 |
end |
| 7 |
def test_create |
| 8 |
c = Caca::Canvas.new(3, 3) |
| 9 |
refute_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_from_memory("foo", "") |
| 30 |
assert_equal("foo\r\n", @c.export_to_memory("irc"), "Import/Export failed") |
| 31 |
@c.import_area_from_memory(0, 0, "p", "") |
| 32 |
assert_equal("poo\r\n", @c.export_area_to_memory(0, 0, 3, 1, "irc"), "Import/Export of area failed") |
| 33 |
end |
| 34 |
def test_cursor |
| 35 |
@c.gotoxy(1,1) |
| 36 |
assert_equal(1, @c.wherex) |
| 37 |
assert_equal(1, @c.wherey) |
| 38 |
end |
| 39 |
def test_clear |
| 40 |
@c.put_char(1, 1, 64) |
| 41 |
@c.clear |
| 42 |
assert_equal("", @c.export_to_memory("irc").strip, "Failed to clear canvas") |
| 43 |
end |
| 44 |
def test_char |
| 45 |
@c.put_char(1, 1, 42) |
| 46 |
assert_equal(42, @c.get_char(1,1)) |
| 47 |
end |
| 48 |
def test_render |
| 49 |
c = Caca::Canvas.new(4,4) |
| 50 |
c.put_str(0,0,"plop") |
| 51 |
f = Caca::Font.new(Caca::Font.list[0]) |
| 52 |
refute_nil(c.render(f, c.width*f.width, c.height*f.height, c.width*f.width*4)) |
| 53 |
end |
| 54 |
def test_fail_render |
| 55 |
c = Caca::Canvas.new(4,4) |
| 56 |
assert_raises(ArgumentError) { |
| 57 |
c.render(nil, c.width, c.height, c.width*4) |
| 58 |
} |
| 59 |
end |
| 60 |
end |