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

75 行
2.1 KiB

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