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.
 
 
 
 
 
 

146 lines
4.5 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);
  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 i, dx, dy, dw, dh;
  34. /* Check that the dirty rectangle contains the whole canvas
  35. * upon creation. */
  36. cv = caca_create_canvas(WIDTH, HEIGHT);
  37. i = caca_get_dirty_rect_count(cv);
  38. CPPUNIT_ASSERT_EQUAL(i, 1);
  39. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  40. CPPUNIT_ASSERT_EQUAL(dx, 0);
  41. CPPUNIT_ASSERT_EQUAL(dy, 0);
  42. CPPUNIT_ASSERT_EQUAL(dw, caca_get_canvas_width(cv));
  43. CPPUNIT_ASSERT_EQUAL(dh, caca_get_canvas_height(cv));
  44. /* Invalidate the dirty rectangle and check that it stays so. */
  45. caca_clear_dirty_rect_list(cv);
  46. i = caca_get_dirty_rect_count(cv);
  47. CPPUNIT_ASSERT_EQUAL(i, 0);
  48. caca_free_canvas(cv);
  49. }
  50. void test_put_char()
  51. {
  52. caca_canvas_t *cv;
  53. int i, dx, dy, dw, dh;
  54. cv = caca_create_canvas(WIDTH, HEIGHT);
  55. caca_clear_dirty_rect_list(cv);
  56. caca_put_char(cv, 7, 3, 'x');
  57. i = caca_get_dirty_rect_count(cv);
  58. CPPUNIT_ASSERT_EQUAL(i, 1);
  59. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  60. CPPUNIT_ASSERT_EQUAL(dx, 7);
  61. CPPUNIT_ASSERT_EQUAL(dy, 3);
  62. CPPUNIT_ASSERT_EQUAL(dw, 1);
  63. CPPUNIT_ASSERT_EQUAL(dh, 1);
  64. caca_clear_canvas(cv);
  65. caca_clear_dirty_rect_list(cv);
  66. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  67. i = caca_get_dirty_rect_count(cv);
  68. CPPUNIT_ASSERT_EQUAL(i, 1);
  69. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  70. CPPUNIT_ASSERT_EQUAL(dx, 7);
  71. CPPUNIT_ASSERT_EQUAL(dy, 3);
  72. CPPUNIT_ASSERT_EQUAL(dw, 2);
  73. CPPUNIT_ASSERT_EQUAL(dh, 1);
  74. caca_clear_canvas(cv);
  75. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  76. caca_clear_dirty_rect_list(cv);
  77. caca_put_char(cv, 7, 3, 'x');
  78. i = caca_get_dirty_rect_count(cv);
  79. CPPUNIT_ASSERT_EQUAL(i, 1);
  80. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  81. CPPUNIT_ASSERT_EQUAL(dx, 7);
  82. CPPUNIT_ASSERT_EQUAL(dy, 3);
  83. CPPUNIT_ASSERT_EQUAL(dw, 2);
  84. CPPUNIT_ASSERT_EQUAL(dh, 1);
  85. caca_clear_canvas(cv);
  86. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  87. caca_clear_dirty_rect_list(cv);
  88. caca_put_char(cv, 8, 3, 'x');
  89. i = caca_get_dirty_rect_count(cv);
  90. CPPUNIT_ASSERT_EQUAL(i, 1);
  91. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  92. CPPUNIT_ASSERT_EQUAL(dx, 7);
  93. CPPUNIT_ASSERT_EQUAL(dy, 3);
  94. CPPUNIT_ASSERT_EQUAL(dw, 2);
  95. CPPUNIT_ASSERT_EQUAL(dh, 1);
  96. caca_clear_canvas(cv);
  97. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  98. caca_clear_dirty_rect_list(cv);
  99. caca_put_char(cv, 6, 3, 0x2f06 /* ⼆ */);
  100. i = caca_get_dirty_rect_count(cv);
  101. CPPUNIT_ASSERT_EQUAL(i, 1);
  102. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  103. CPPUNIT_ASSERT_EQUAL(dx, 6);
  104. CPPUNIT_ASSERT_EQUAL(dy, 3);
  105. CPPUNIT_ASSERT_EQUAL(dw, 3);
  106. CPPUNIT_ASSERT_EQUAL(dh, 1);
  107. caca_clear_canvas(cv);
  108. caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
  109. caca_clear_dirty_rect_list(cv);
  110. caca_put_char(cv, 8, 3, 0x2f06 /* ⼆ */);
  111. i = caca_get_dirty_rect_count(cv);
  112. CPPUNIT_ASSERT_EQUAL(i, 1);
  113. caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
  114. CPPUNIT_ASSERT_EQUAL(dx, 7);
  115. CPPUNIT_ASSERT_EQUAL(dy, 3);
  116. CPPUNIT_ASSERT_EQUAL(dw, 3);
  117. CPPUNIT_ASSERT_EQUAL(dh, 1);
  118. }
  119. private:
  120. static int const WIDTH = 80, HEIGHT = 50;
  121. };
  122. CPPUNIT_TEST_SUITE_REGISTRATION(DirtyTest);