25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

256 lines
8.1 KiB

  1. /*
  2. * caca-test testsuite program for libcaca
  3. * Copyright (c) 2009 Sam Hocevar <sam@hocevar.net>
  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_dirty);
  25. CPPUNIT_TEST(test_put_char_not_dirty);
  26. CPPUNIT_TEST(test_box);
  27. CPPUNIT_TEST(test_blit);
  28. CPPUNIT_TEST_SUITE_END();
  29. public:
  30. DirtyTest() : CppUnit::TestCase("Dirty Rectangles Test") {}
  31. void setUp() {}
  32. void tearDown() {}
  33. void test_create()
  34. {
  35. caca_canvas_t *cv;
  36. int dx, dy, dw, dh;
  37. /* Check that we only have one dirty rectangle upon creation. */
  38. cv = caca_create_canvas(WIDTH, HEIGHT);
  39. CPPUNIT_ASSERT_EQUAL(1, caca_get_dirty_rect_count(cv));
  40. /* Check that our only rectangle contains the whole canvas. */
  41. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  42. CPPUNIT_ASSERT_EQUAL(0, dx);
  43. CPPUNIT_ASSERT_EQUAL(0, dy);
  44. CPPUNIT_ASSERT_EQUAL(WIDTH, dw);
  45. CPPUNIT_ASSERT_EQUAL(HEIGHT, dh);
  46. /* Invalidate the dirty rectangle and check that it stays so. */
  47. caca_clear_dirty_rect_list(cv);
  48. CPPUNIT_ASSERT_EQUAL(0, caca_get_dirty_rect_count(cv));
  49. caca_free_canvas(cv);
  50. }
  51. void test_put_char_dirty()
  52. {
  53. caca_canvas_t *cv;
  54. int dx, dy, dw, dh;
  55. cv = caca_create_canvas(WIDTH, HEIGHT);
  56. /* Check that one character creates a 1x1 dirty rect. */
  57. caca_clear_dirty_rect_list(cv);
  58. caca_put_char(cv, 7, 3, 'x');
  59. CPPUNIT_ASSERT_EQUAL(1, caca_get_dirty_rect_count(cv));
  60. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  61. CPPUNIT_ASSERT_EQUAL(7, dx);
  62. CPPUNIT_ASSERT_EQUAL(3, dy);
  63. CPPUNIT_ASSERT_EQUAL(1, dw);
  64. CPPUNIT_ASSERT_EQUAL(1, dh);
  65. /* Check that a fullwidth character creates a 2x1 dirty rect. */
  66. caca_clear_canvas(cv);
  67. caca_clear_dirty_rect_list(cv);
  68. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  69. CPPUNIT_ASSERT_EQUAL(1, caca_get_dirty_rect_count(cv));
  70. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  71. CPPUNIT_ASSERT_EQUAL(7, dx);
  72. CPPUNIT_ASSERT_EQUAL(3, dy);
  73. CPPUNIT_ASSERT_EQUAL(2, dw);
  74. CPPUNIT_ASSERT_EQUAL(1, dh);
  75. /* Check that a character over a fullwidth character creates a
  76. * 2x1 dirty rect because of clobbering on the left side. */
  77. caca_clear_canvas(cv);
  78. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  79. caca_clear_dirty_rect_list(cv);
  80. caca_put_char(cv, 7, 3, 'x');
  81. CPPUNIT_ASSERT_EQUAL(1, caca_get_dirty_rect_count(cv));
  82. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  83. CPPUNIT_ASSERT_EQUAL(7, dx);
  84. CPPUNIT_ASSERT_EQUAL(3, dy);
  85. CPPUNIT_ASSERT_EQUAL(2, dw);
  86. CPPUNIT_ASSERT_EQUAL(1, dh);
  87. /* Check that a character over a fullwidth character creates a
  88. * 2x1 dirty rect because of clobbering on the right side. */
  89. caca_clear_canvas(cv);
  90. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  91. caca_clear_dirty_rect_list(cv);
  92. caca_put_char(cv, 8, 3, 'x');
  93. CPPUNIT_ASSERT_EQUAL(1, caca_get_dirty_rect_count(cv));
  94. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  95. CPPUNIT_ASSERT_EQUAL(7, dx);
  96. CPPUNIT_ASSERT_EQUAL(3, dy);
  97. CPPUNIT_ASSERT_EQUAL(2, dw);
  98. CPPUNIT_ASSERT_EQUAL(1, dh);
  99. /* Check that a fullwidth character over a fullwidth character creates
  100. * a 3x1 dirty rect because of clobbering on the left side. */
  101. caca_clear_canvas(cv);
  102. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  103. caca_clear_dirty_rect_list(cv);
  104. caca_put_char(cv, 6, 3, 0x2f06 /* ⼆ */);
  105. CPPUNIT_ASSERT_EQUAL(1, caca_get_dirty_rect_count(cv));
  106. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  107. CPPUNIT_ASSERT_EQUAL(6, dx);
  108. CPPUNIT_ASSERT_EQUAL(3, dy);
  109. CPPUNIT_ASSERT_EQUAL(3, dw);
  110. CPPUNIT_ASSERT_EQUAL(1, dh);
  111. /* Check that a fullwidth character over a fullwidth character creates
  112. * a 3x1 dirty rect because of clobbering on the right side. */
  113. caca_clear_canvas(cv);
  114. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  115. caca_clear_dirty_rect_list(cv);
  116. caca_put_char(cv, 8, 3, 0x2f06 /* ⼆ */);
  117. CPPUNIT_ASSERT_EQUAL(1, caca_get_dirty_rect_count(cv));
  118. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  119. CPPUNIT_ASSERT_EQUAL(7, dx);
  120. CPPUNIT_ASSERT_EQUAL(3, dy);
  121. CPPUNIT_ASSERT_EQUAL(3, dw);
  122. CPPUNIT_ASSERT_EQUAL(1, dh);
  123. }
  124. void test_put_char_not_dirty()
  125. {
  126. caca_canvas_t *cv;
  127. cv = caca_create_canvas(WIDTH, HEIGHT);
  128. /* Check that pasting the same character does not cause a dirty
  129. * rectangle to be created. */
  130. caca_put_char(cv, 7, 3, 'x');
  131. caca_clear_dirty_rect_list(cv);
  132. caca_put_char(cv, 7, 3, 'x');
  133. CPPUNIT_ASSERT_EQUAL(0, caca_get_dirty_rect_count(cv));
  134. /* Check that pasting the same fullwidth character does not cause
  135. * a dirty rectangle to be created. */
  136. caca_clear_canvas(cv);
  137. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  138. caca_clear_dirty_rect_list(cv);
  139. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  140. CPPUNIT_ASSERT_EQUAL(0, caca_get_dirty_rect_count(cv));
  141. }
  142. void test_box()
  143. {
  144. caca_canvas_t *cv;
  145. int dx, dy, dw, dh;
  146. cv = caca_create_canvas(WIDTH, HEIGHT);
  147. caca_clear_dirty_rect_list(cv);
  148. /* Check that a filled box creates one dirty rectangle of the same
  149. * size. */
  150. caca_fill_box(cv, 7, 3, 14, 9, 'x');
  151. CPPUNIT_ASSERT_EQUAL(1, caca_get_dirty_rect_count(cv));
  152. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  153. CPPUNIT_ASSERT_EQUAL(7, dx);
  154. CPPUNIT_ASSERT_EQUAL(3, dy);
  155. CPPUNIT_ASSERT_EQUAL(14, dw);
  156. CPPUNIT_ASSERT_EQUAL(9, dh);
  157. /* Check that the same filled box does not create a new dirty
  158. * rectangle. */
  159. caca_clear_dirty_rect_list(cv);
  160. caca_fill_box(cv, 7, 3, 14, 9, 'x');
  161. CPPUNIT_ASSERT_EQUAL(0, caca_get_dirty_rect_count(cv));
  162. }
  163. void test_blit()
  164. {
  165. caca_canvas_t *cv, *cv2;
  166. int i, dx, dy, dw, dh;
  167. cv = caca_create_canvas(WIDTH, HEIGHT);
  168. caca_clear_dirty_rect_list(cv);
  169. cv2 = caca_create_canvas(2, 2);
  170. caca_fill_box(cv2, 0, 0, 2, 1, 'x');
  171. /* Check that blitting a canvas make a dirty rectangle
  172. * only for modified lines */
  173. /* FIXME: check this test's validity */
  174. caca_blit(cv, 1, 1, cv2, NULL);
  175. i = caca_get_dirty_rect_count(cv);
  176. CPPUNIT_ASSERT_EQUAL(1, i);
  177. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  178. CPPUNIT_ASSERT(1 == dx);
  179. CPPUNIT_ASSERT(1 == dy);
  180. CPPUNIT_ASSERT(2 <= dw);
  181. CPPUNIT_ASSERT(1 == dh);
  182. caca_clear_canvas(cv);
  183. caca_clear_dirty_rect_list(cv);
  184. /* Check that blitting a canvas make a dirty rectangle
  185. * only for modified chars when we have a mask */
  186. /* FIXME: check this test's validity */
  187. caca_blit(cv, 1, 1, cv2, cv2);
  188. i = caca_get_dirty_rect_count(cv);
  189. CPPUNIT_ASSERT_EQUAL(1, i);
  190. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  191. CPPUNIT_ASSERT(1 == dx);
  192. CPPUNIT_ASSERT(1 == dy);
  193. CPPUNIT_ASSERT(2 == dw);
  194. CPPUNIT_ASSERT(1 == dh);
  195. CPPUNIT_ASSERT(' ' == caca_get_char(cv, 0, 0));
  196. }
  197. private:
  198. static int const WIDTH, HEIGHT;
  199. };
  200. int const DirtyTest::WIDTH = 80;
  201. int const DirtyTest::HEIGHT = 50;
  202. CPPUNIT_TEST_SUITE_REGISTRATION(DirtyTest);