No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

canvas.cpp 2.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * caca-test testsuite program for libcaca
  3. * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
  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 CanvasTest : public CppUnit::TestCase
  21. {
  22. CPPUNIT_TEST_SUITE(CanvasTest);
  23. CPPUNIT_TEST(test_creation);
  24. CPPUNIT_TEST(test_resize);
  25. CPPUNIT_TEST(test_chars);
  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. caca_set_canvas_size(cv, 1, 1);
  45. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_width(cv), 1);
  46. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_height(cv), 1);
  47. caca_set_canvas_size(cv, 1234, 1001);
  48. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_width(cv), 1234);
  49. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_height(cv), 1001);
  50. caca_set_canvas_size(cv, 0, 0);
  51. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_width(cv), 0);
  52. CPPUNIT_ASSERT_EQUAL(caca_get_canvas_height(cv), 0);
  53. caca_free_canvas(cv);
  54. }
  55. void test_chars()
  56. {
  57. caca_canvas_t *cv;
  58. cv = caca_create_canvas(0, 0);
  59. CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == ' ');
  60. caca_put_char(cv, 0, 0, 'x');
  61. CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == ' ');
  62. caca_set_canvas_size(cv, 1, 1);
  63. CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == ' ');
  64. caca_put_char(cv, 0, 0, 'x');
  65. CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == 'x');
  66. caca_put_char(cv, 0, 0, 'y');
  67. CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == 'y');
  68. caca_set_canvas_size(cv, 1000, 1000);
  69. CPPUNIT_ASSERT(caca_get_char(cv, 999, 999) == ' ');
  70. caca_put_char(cv, 999, 999, 'z');
  71. CPPUNIT_ASSERT(caca_get_char(cv, 999, 999) == 'z');
  72. caca_free_canvas(cv);
  73. }
  74. };
  75. CPPUNIT_TEST_SUITE_REGISTRATION(CanvasTest);