Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

111 řádky
2.9 KiB

  1. /*
  2. * caca-test testsuite program for libcaca
  3. * Copyright (c) 2008 Sam Hocevar <samhocevar.net>
  4. * All Rights Reserved
  5. *
  6. * This program is free software. It comes without any warranty, to
  7. * the extent permitted by applicable law. You can redistribute it
  8. * and/or modify it under the terms of the Do What The Fuck You Want
  9. * To Public License, Version 2, as published by Sam Hocevar. See
  10. * http://sam.zoy.org/wtfpl/COPYING for more details.
  11. */
  12. #include "config.h"
  13. #include <cppunit/extensions/HelperMacros.h>
  14. #include <cppunit/TestCaller.h>
  15. #include <cppunit/TestCase.h>
  16. #include <cppunit/TestSuite.h>
  17. #include "caca.h"
  18. class CanvasTest : public CppUnit::TestCase
  19. {
  20. CPPUNIT_TEST_SUITE(CanvasTest);
  21. CPPUNIT_TEST(test_creation);
  22. CPPUNIT_TEST(test_resize);
  23. CPPUNIT_TEST(test_chars);
  24. CPPUNIT_TEST(test_utf8);
  25. CPPUNIT_TEST_SUITE_END();
  26. public:
  27. CanvasTest() : CppUnit::TestCase("Canvas Test") {}
  28. void setUp() {}
  29. void tearDown() {}
  30. void test_creation()
  31. {
  32. caca_canvas_t *cv;
  33. cv = caca_create_canvas(0, 0);
  34. CPPUNIT_ASSERT(cv != NULL);
  35. caca_free_canvas(cv);
  36. }
  37. void test_resize()
  38. {
  39. caca_canvas_t *cv;
  40. cv = caca_create_canvas(0, 0);
  41. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_width(cv), 0);
  42. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_height(cv), 0);
  43. caca_set_canvas_size(cv, 1, 1);
  44. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_width(cv), 1);
  45. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_height(cv), 1);
  46. caca_set_canvas_size(cv, 1234, 1001);
  47. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_width(cv), 1234);
  48. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_height(cv), 1001);
  49. caca_set_canvas_size(cv, 0, 0);
  50. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_width(cv), 0);
  51. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_height(cv), 0);
  52. caca_free_canvas(cv);
  53. }
  54. void test_chars()
  55. {
  56. caca_canvas_t *cv;
  57. cv = caca_create_canvas(0, 0);
  58. CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == ' ');
  59. caca_put_char(cv, 0, 0, 'x');
  60. CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == ' ');
  61. caca_set_canvas_size(cv, 1, 1);
  62. CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == ' ');
  63. caca_put_char(cv, 0, 0, 'x');
  64. CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == 'x');
  65. caca_put_char(cv, 0, 0, 'y');
  66. CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == 'y');
  67. caca_set_canvas_size(cv, 1000, 1000);
  68. CPPUNIT_ASSERT(caca_get_char(cv, 999, 999) == ' ');
  69. caca_put_char(cv, 999, 999, 'z');
  70. CPPUNIT_ASSERT(caca_get_char(cv, 999, 999) == 'z');
  71. caca_free_canvas(cv);
  72. }
  73. void test_utf8()
  74. {
  75. caca_canvas_t *cv;
  76. cv = caca_create_canvas(10, 10);
  77. /* Send only one byte of a 4-byte sequence */
  78. caca_put_str(cv, 0, 0, "\xf0");
  79. }
  80. };
  81. CPPUNIT_TEST_SUITE_REGISTRATION(CanvasTest);