You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 17 година
пре 17 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. require 'caca'
  2. class TC_Canvas < MiniTest::Test
  3. def setup
  4. @c = Caca::Canvas.new(3, 3)
  5. end
  6. def test_create
  7. c = Caca::Canvas.new(3, 3)
  8. refute_nil(c, 'Canvas creation failed')
  9. assert(c.width == 3 && c.height == 3, 'Wrong size for new canvas')
  10. end
  11. def test_width
  12. @c.width = 42
  13. assert_equal(42, @c.width, 'Failed to set width with =')
  14. @c.set_width(24)
  15. assert_equal(24, @c.width, 'Failed to set width')
  16. end
  17. def test_height
  18. @c.height = 42
  19. assert_equal(42, @c.height, 'Failed to set height with =')
  20. @c.set_height(24)
  21. assert_equal(24, @c.height, 'Failed to set height')
  22. end
  23. def test_size
  24. @c.set_size(100,100)
  25. assert(@c.width == 100 && @c.height == 100, 'Failed to set size')
  26. end
  27. def test_import
  28. @c.import_from_memory("foo", "")
  29. assert_equal("foo\r\n", @c.export_to_memory("irc"), "Import/Export failed")
  30. @c.import_area_from_memory(0, 0, "p", "")
  31. assert_equal("poo\r\n", @c.export_area_to_memory(0, 0, 3, 1, "irc"), "Import/Export of area failed")
  32. end
  33. def test_cursor
  34. @c.gotoxy(1,1)
  35. assert_equal(1, @c.wherex)
  36. assert_equal(1, @c.wherey)
  37. end
  38. def test_clear
  39. @c.put_char(1, 1, 64)
  40. @c.clear
  41. assert_equal("", @c.export_to_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 = Caca::Canvas.new(4,4)
  49. c.put_str(0,0,"plop")
  50. f = Caca::Font.new(Caca::Font.list[0])
  51. refute_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 = Caca::Canvas.new(4,4)
  55. assert_raises(ArgumentError) {
  56. c.render(nil, c.width, c.height, c.width*4)
  57. }
  58. end
  59. end