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.
 
 
 
 
 
 

131 lines
4.1 KiB

  1. /*
  2. * caca-test testsuite program for libcaca
  3. * Copyright (c) 2009 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This program is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. #include "config.h"
  15. #include <cppunit/extensions/HelperMacros.h>
  16. #include <cppunit/TestCaller.h>
  17. #include <cppunit/TestCase.h>
  18. #include <cppunit/TestSuite.h>
  19. #include "caca.h"
  20. class DirtyTest : public CppUnit::TestCase
  21. {
  22. CPPUNIT_TEST_SUITE(DirtyTest);
  23. CPPUNIT_TEST(test_create);
  24. CPPUNIT_TEST(test_put_char);
  25. CPPUNIT_TEST_SUITE_END();
  26. public:
  27. DirtyTest() : CppUnit::TestCase("Dirty Rectangles Test") {}
  28. void setUp() {}
  29. void tearDown() {}
  30. void test_create()
  31. {
  32. caca_canvas_t *cv;
  33. int xmin, xmax, ymin, ymax;
  34. /* Check that the dirty rectangle contains the whole canvas
  35. * upon creation. */
  36. cv = caca_create_canvas(WIDTH, HEIGHT);
  37. caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
  38. CPPUNIT_ASSERT(xmin <= 0);
  39. CPPUNIT_ASSERT(ymin <= 0);
  40. CPPUNIT_ASSERT(xmax >= caca_get_canvas_width(cv) - 1);
  41. CPPUNIT_ASSERT(ymax >= caca_get_canvas_height(cv) - 1);
  42. /* Invalidate the dirty rectangle and check that it stays so. */
  43. caca_set_dirty_rectangle(cv, -1, -1, -1, -1);
  44. caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
  45. CPPUNIT_ASSERT(xmin > xmax || ymin > ymax);
  46. caca_free_canvas(cv);
  47. }
  48. void test_put_char()
  49. {
  50. caca_canvas_t *cv;
  51. int xmin, xmax, ymin, ymax;
  52. cv = caca_create_canvas(WIDTH, HEIGHT);
  53. caca_set_dirty_rectangle(cv, -1, -1, -1, -1);
  54. caca_put_char(cv, 7, 3, 'x');
  55. caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
  56. CPPUNIT_ASSERT(xmin <= 7);
  57. CPPUNIT_ASSERT(ymin <= 3);
  58. CPPUNIT_ASSERT(xmax >= 7);
  59. CPPUNIT_ASSERT(ymax >= 3);
  60. caca_clear_canvas(cv);
  61. caca_set_dirty_rectangle(cv, -1, -1, -1, -1);
  62. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  63. caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
  64. CPPUNIT_ASSERT(xmin <= 7);
  65. CPPUNIT_ASSERT(ymin <= 3);
  66. CPPUNIT_ASSERT(xmax >= 8);
  67. CPPUNIT_ASSERT(ymax >= 3);
  68. caca_clear_canvas(cv);
  69. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  70. caca_set_dirty_rectangle(cv, -1, -1, -1, -1);
  71. caca_put_char(cv, 7, 3, 'x');
  72. caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
  73. CPPUNIT_ASSERT(xmin <= 7);
  74. CPPUNIT_ASSERT(ymin <= 3);
  75. CPPUNIT_ASSERT(xmax >= 8);
  76. CPPUNIT_ASSERT(ymax >= 3);
  77. caca_clear_canvas(cv);
  78. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  79. caca_set_dirty_rectangle(cv, -1, -1, -1, -1);
  80. caca_put_char(cv, 8, 3, 'x');
  81. caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
  82. CPPUNIT_ASSERT(xmin <= 7);
  83. CPPUNIT_ASSERT(ymin <= 3);
  84. CPPUNIT_ASSERT(xmax >= 8);
  85. CPPUNIT_ASSERT(ymax >= 3);
  86. caca_clear_canvas(cv);
  87. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  88. caca_set_dirty_rectangle(cv, -1, -1, -1, -1);
  89. caca_put_char(cv, 6, 3, 0x2f06 /* ⼆ */);
  90. caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
  91. CPPUNIT_ASSERT(xmin <= 6);
  92. CPPUNIT_ASSERT(ymin <= 3);
  93. CPPUNIT_ASSERT(xmax >= 8);
  94. CPPUNIT_ASSERT(ymax >= 3);
  95. caca_clear_canvas(cv);
  96. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  97. caca_set_dirty_rectangle(cv, -1, -1, -1, -1);
  98. caca_put_char(cv, 8, 3, 0x2f06 /* ⼆ */);
  99. caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
  100. CPPUNIT_ASSERT(xmin <= 7);
  101. CPPUNIT_ASSERT(ymin <= 3);
  102. CPPUNIT_ASSERT(xmax >= 9);
  103. CPPUNIT_ASSERT(ymax >= 3);
  104. }
  105. private:
  106. static int const WIDTH = 80, HEIGHT = 50;
  107. };
  108. CPPUNIT_TEST_SUITE_REGISTRATION(DirtyTest);