25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

194 satır
5.9 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_SUITE_END();
  28. public:
  29. DirtyTest() : CppUnit::TestCase("Dirty Rectangles Test") {}
  30. void setUp() {}
  31. void tearDown() {}
  32. void test_create()
  33. {
  34. caca_canvas_t *cv;
  35. int i, dx, dy, dw, dh;
  36. /* Check that the dirty rectangle contains the whole canvas
  37. * upon creation. */
  38. cv = caca_create_canvas(WIDTH, HEIGHT);
  39. i = caca_get_dirty_rect_count(cv);
  40. CPPUNIT_ASSERT_EQUAL(i, 1);
  41. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  42. CPPUNIT_ASSERT_EQUAL(dx, 0);
  43. CPPUNIT_ASSERT_EQUAL(dy, 0);
  44. CPPUNIT_ASSERT_EQUAL(dw, caca_get_canvas_width(cv));
  45. CPPUNIT_ASSERT_EQUAL(dh, caca_get_canvas_height(cv));
  46. /* Invalidate the dirty rectangle and check that it stays so. */
  47. caca_clear_dirty_rect_list(cv);
  48. i = caca_get_dirty_rect_count(cv);
  49. CPPUNIT_ASSERT_EQUAL(i, 0);
  50. caca_free_canvas(cv);
  51. }
  52. void test_put_char_dirty()
  53. {
  54. caca_canvas_t *cv;
  55. int i, dx, dy, dw, dh;
  56. cv = caca_create_canvas(WIDTH, HEIGHT);
  57. caca_clear_dirty_rect_list(cv);
  58. caca_put_char(cv, 7, 3, 'x');
  59. i = caca_get_dirty_rect_count(cv);
  60. CPPUNIT_ASSERT_EQUAL(i, 1);
  61. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  62. CPPUNIT_ASSERT_EQUAL(dx, 7);
  63. CPPUNIT_ASSERT_EQUAL(dy, 3);
  64. CPPUNIT_ASSERT_EQUAL(dw, 1);
  65. CPPUNIT_ASSERT_EQUAL(dh, 1);
  66. caca_clear_canvas(cv);
  67. caca_clear_dirty_rect_list(cv);
  68. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  69. i = caca_get_dirty_rect_count(cv);
  70. CPPUNIT_ASSERT_EQUAL(i, 1);
  71. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  72. CPPUNIT_ASSERT_EQUAL(dx, 7);
  73. CPPUNIT_ASSERT_EQUAL(dy, 3);
  74. CPPUNIT_ASSERT_EQUAL(dw, 2);
  75. CPPUNIT_ASSERT_EQUAL(dh, 1);
  76. caca_clear_canvas(cv);
  77. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  78. caca_clear_dirty_rect_list(cv);
  79. caca_put_char(cv, 7, 3, 'x');
  80. i = caca_get_dirty_rect_count(cv);
  81. CPPUNIT_ASSERT_EQUAL(i, 1);
  82. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  83. CPPUNIT_ASSERT_EQUAL(dx, 7);
  84. CPPUNIT_ASSERT_EQUAL(dy, 3);
  85. CPPUNIT_ASSERT_EQUAL(dw, 2);
  86. CPPUNIT_ASSERT_EQUAL(dh, 1);
  87. caca_clear_canvas(cv);
  88. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  89. caca_clear_dirty_rect_list(cv);
  90. caca_put_char(cv, 8, 3, 'x');
  91. i = caca_get_dirty_rect_count(cv);
  92. CPPUNIT_ASSERT_EQUAL(i, 1);
  93. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  94. CPPUNIT_ASSERT_EQUAL(dx, 7);
  95. CPPUNIT_ASSERT_EQUAL(dy, 3);
  96. CPPUNIT_ASSERT_EQUAL(dw, 2);
  97. CPPUNIT_ASSERT_EQUAL(dh, 1);
  98. caca_clear_canvas(cv);
  99. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  100. caca_clear_dirty_rect_list(cv);
  101. caca_put_char(cv, 6, 3, 0x2f06 /* ⼆ */);
  102. i = caca_get_dirty_rect_count(cv);
  103. CPPUNIT_ASSERT_EQUAL(i, 1);
  104. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  105. CPPUNIT_ASSERT_EQUAL(dx, 6);
  106. CPPUNIT_ASSERT_EQUAL(dy, 3);
  107. CPPUNIT_ASSERT_EQUAL(dw, 3);
  108. CPPUNIT_ASSERT_EQUAL(dh, 1);
  109. caca_clear_canvas(cv);
  110. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  111. caca_clear_dirty_rect_list(cv);
  112. caca_put_char(cv, 8, 3, 0x2f06 /* ⼆ */);
  113. i = caca_get_dirty_rect_count(cv);
  114. CPPUNIT_ASSERT_EQUAL(i, 1);
  115. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  116. CPPUNIT_ASSERT_EQUAL(dx, 7);
  117. CPPUNIT_ASSERT_EQUAL(dy, 3);
  118. CPPUNIT_ASSERT_EQUAL(dw, 3);
  119. CPPUNIT_ASSERT_EQUAL(dh, 1);
  120. }
  121. void test_put_char_not_dirty()
  122. {
  123. caca_canvas_t *cv;
  124. int i;
  125. cv = caca_create_canvas(WIDTH, HEIGHT);
  126. /* Check that pasting the same character does not cause
  127. * a dirty rectangle to be created. */
  128. caca_put_char(cv, 7, 3, 'x');
  129. caca_clear_dirty_rect_list(cv);
  130. caca_put_char(cv, 7, 3, 'x');
  131. i = caca_get_dirty_rect_count(cv);
  132. CPPUNIT_ASSERT_EQUAL(i, 0);
  133. caca_clear_canvas(cv);
  134. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  135. caca_clear_dirty_rect_list(cv);
  136. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  137. i = caca_get_dirty_rect_count(cv);
  138. CPPUNIT_ASSERT_EQUAL(i, 0);
  139. }
  140. void test_box()
  141. {
  142. caca_canvas_t *cv;
  143. int i, dx, dy, dw, dh;
  144. cv = caca_create_canvas(WIDTH, HEIGHT);
  145. caca_clear_dirty_rect_list(cv);
  146. caca_fill_box(cv, 7, 3, 14, 9, 'x');
  147. i = caca_get_dirty_rect_count(cv);
  148. CPPUNIT_ASSERT_EQUAL(i, 1);
  149. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  150. CPPUNIT_ASSERT_EQUAL(dx, 7);
  151. CPPUNIT_ASSERT_EQUAL(dy, 3);
  152. CPPUNIT_ASSERT_EQUAL(dw, 14);
  153. CPPUNIT_ASSERT_EQUAL(dh, 9);
  154. caca_clear_dirty_rect_list(cv);
  155. caca_fill_box(cv, 7, 3, 14, 9, 'x');
  156. i = caca_get_dirty_rect_count(cv);
  157. CPPUNIT_ASSERT_EQUAL(i, 0);
  158. }
  159. private:
  160. static int const WIDTH = 80, HEIGHT = 50;
  161. };
  162. CPPUNIT_TEST_SUITE_REGISTRATION(DirtyTest);