選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

123 行
3.5 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://www.wtfpl.net/ 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 <climits>
  18. #include "caca.h"
  19. class CanvasTest : public CppUnit::TestCase
  20. {
  21. CPPUNIT_TEST_SUITE(CanvasTest);
  22. CPPUNIT_TEST(test_creation);
  23. CPPUNIT_TEST(test_resize);
  24. CPPUNIT_TEST(test_chars);
  25. CPPUNIT_TEST(test_utf8);
  26. CPPUNIT_TEST_SUITE_END();
  27. public:
  28. CanvasTest() : CppUnit::TestCase("Canvas Test") {}
  29. void setUp() {}
  30. void tearDown() {}
  31. void test_creation()
  32. {
  33. caca_canvas_t *cv;
  34. cv = caca_create_canvas(0, 0);
  35. CPPUNIT_ASSERT(cv != NULL);
  36. caca_free_canvas(cv);
  37. }
  38. void test_resize()
  39. {
  40. caca_canvas_t *cv;
  41. cv = caca_create_canvas(0, 0);
  42. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_width(cv), 0);
  43. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_height(cv), 0);
  44. int ret = caca_set_canvas_size(cv, 1, 1);
  45. CPPUNIT_ASSERT_EQUAL(ret, 0);
  46. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_width(cv), 1);
  47. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_height(cv), 1);
  48. ret = caca_set_canvas_size(cv, 1234, 1001);
  49. CPPUNIT_ASSERT_EQUAL(ret, 0);
  50. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_width(cv), 1234);
  51. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_height(cv), 1001);
  52. ret = caca_set_canvas_size(cv, 0, 0);
  53. CPPUNIT_ASSERT_EQUAL(ret, 0);
  54. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_width(cv), 0);
  55. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_height(cv), 0);
  56. CPPUNIT_ASSERT_EQUAL(-1, caca_set_canvas_size(cv, -1, 50));
  57. CPPUNIT_ASSERT_EQUAL(-1, caca_set_canvas_size(cv, 50, -1));
  58. CPPUNIT_ASSERT_EQUAL(-1, caca_set_canvas_size(cv, -1, -1));
  59. CPPUNIT_ASSERT_EQUAL(-1, caca_set_canvas_size(cv, INT_MAX / 2, 3));
  60. CPPUNIT_ASSERT_EQUAL(-1, caca_set_canvas_size(cv, 3, INT_MAX / 2));
  61. CPPUNIT_ASSERT_EQUAL(-1, caca_set_canvas_size(cv, INT_MAX / 2, INT_MAX / 2));
  62. CPPUNIT_ASSERT_EQUAL(0, caca_set_canvas_size(cv, 0, 0));
  63. caca_free_canvas(cv);
  64. }
  65. void test_chars()
  66. {
  67. caca_canvas_t *cv;
  68. cv = caca_create_canvas(0, 0);
  69. CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == ' ');
  70. caca_put_char(cv, 0, 0, 'x');
  71. CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == ' ');
  72. caca_set_canvas_size(cv, 1, 1);
  73. CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == ' ');
  74. caca_put_char(cv, 0, 0, 'x');
  75. CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == 'x');
  76. caca_put_char(cv, 0, 0, 'y');
  77. CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == 'y');
  78. caca_set_canvas_size(cv, 1000, 1000);
  79. CPPUNIT_ASSERT(caca_get_char(cv, 999, 999) == ' ');
  80. caca_put_char(cv, 999, 999, 'z');
  81. CPPUNIT_ASSERT(caca_get_char(cv, 999, 999) == 'z');
  82. caca_free_canvas(cv);
  83. }
  84. void test_utf8()
  85. {
  86. caca_canvas_t *cv;
  87. cv = caca_create_canvas(10, 10);
  88. /* Send only one byte of a 4-byte sequence */
  89. caca_put_str(cv, 0, 0, "\xf0");
  90. }
  91. };
  92. CPPUNIT_TEST_SUITE_REGISTRATION(CanvasTest);