Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * caca-test testsuite program for libcaca
  3. * Copyright (c) 2009 Pascal Terjan <pterjan@linuxfr.org>
  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 ExportTest : public CppUnit::TestCase
  19. {
  20. CPPUNIT_TEST_SUITE(ExportTest);
  21. CPPUNIT_TEST(test_export_area_caca);
  22. CPPUNIT_TEST_SUITE_END();
  23. public:
  24. ExportTest() : CppUnit::TestCase("Export/Import Test") {}
  25. void setUp() {}
  26. void tearDown() {}
  27. void test_export_area_caca()
  28. {
  29. caca_canvas_t *cv;
  30. size_t bytes, l;
  31. void *buf;
  32. cv = caca_create_canvas(WIDTH, HEIGHT);
  33. caca_put_char(cv, 7, 3, 'a');
  34. caca_put_char(cv, 10, 3, 'b');
  35. caca_put_char(cv, 5, 5, 'c');
  36. buf = caca_export_area_to_memory (cv, 0, 0, 10, 5, "caca", &bytes);
  37. CPPUNIT_ASSERT(buf != NULL);
  38. CPPUNIT_ASSERT(bytes > 0);
  39. caca_clear_canvas(cv);
  40. l = caca_import_area_from_memory(cv, 0, 0, buf, bytes, "caca");
  41. CPPUNIT_ASSERT(l == bytes);
  42. CPPUNIT_ASSERT(caca_get_char(cv, 7, 3) == 'a');
  43. CPPUNIT_ASSERT(caca_get_char(cv, 10, 3) == ' ');
  44. CPPUNIT_ASSERT(caca_get_char(cv, 5, 5) == ' ');
  45. caca_put_char(cv, 10, 3, 'b');
  46. caca_put_char(cv, 5, 5, 'c');
  47. l = caca_import_area_from_memory(cv, 0, 0, buf, bytes, "caca");
  48. CPPUNIT_ASSERT(l == bytes);
  49. CPPUNIT_ASSERT(caca_get_char(cv, 7, 3) == 'a');
  50. CPPUNIT_ASSERT(caca_get_char(cv, 10, 3) == 'b');
  51. CPPUNIT_ASSERT(caca_get_char(cv, 5, 5) == 'c');
  52. caca_free_canvas(cv);
  53. }
  54. private:
  55. static int const WIDTH = 80, HEIGHT = 50;
  56. };
  57. CPPUNIT_TEST_SUITE_REGISTRATION(ExportTest);