source: libcaca/trunk/tests/export.cpp @ 3907

Last change on this file since 3907 was 3514, checked in by Pascal Terjan, 14 years ago

Add unit test for memory export/import with caca format

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1/*
2 *  caca-test     testsuite program for libcaca
3 *  Copyright (c) 2009 Pascal Terjan <pterjan@linuxfr.org>
4 *                All Rights Reserved
5 *
6 *  $Id: export.cpp 3514 2009-05-22 13:51:44Z pterjan $
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
15#include "config.h"
16
17#include <cppunit/extensions/HelperMacros.h>
18#include <cppunit/TestCaller.h>
19#include <cppunit/TestCase.h>
20#include <cppunit/TestSuite.h>
21
22#include "caca.h"
23
24class ExportTest : public CppUnit::TestCase
25{
26    CPPUNIT_TEST_SUITE(ExportTest);
27    CPPUNIT_TEST(test_export_area_caca);
28    CPPUNIT_TEST_SUITE_END();
29
30public:
31    ExportTest() : CppUnit::TestCase("Export/Import Test") {}
32
33    void setUp() {}
34
35    void tearDown() {}
36
37    void test_export_area_caca()
38    {
39        caca_canvas_t *cv;
40        size_t bytes, l;
41        void *buf;
42
43        cv = caca_create_canvas(WIDTH, HEIGHT);
44        caca_put_char(cv, 7, 3, 'a');
45        caca_put_char(cv, 10, 3, 'b');
46        caca_put_char(cv, 5, 5, 'c');
47        buf = caca_export_area_to_memory (cv, 0, 0, 10, 5, "caca", &bytes);
48        CPPUNIT_ASSERT(buf != NULL);
49        CPPUNIT_ASSERT(bytes > 0);
50
51        caca_clear_canvas(cv);
52        l = caca_import_area_from_memory(cv, 0, 0, buf, bytes, "caca");
53        CPPUNIT_ASSERT(l == bytes);
54        CPPUNIT_ASSERT(caca_get_char(cv, 7, 3) == 'a');
55        CPPUNIT_ASSERT(caca_get_char(cv, 10, 3) == ' ');
56        CPPUNIT_ASSERT(caca_get_char(cv, 5, 5) == ' ');
57
58        caca_put_char(cv, 10, 3, 'b');
59        caca_put_char(cv, 5, 5, 'c');
60        l = caca_import_area_from_memory(cv, 0, 0, buf, bytes, "caca");
61        CPPUNIT_ASSERT(l == bytes);
62        CPPUNIT_ASSERT(caca_get_char(cv, 7, 3) == 'a');
63        CPPUNIT_ASSERT(caca_get_char(cv, 10, 3) == 'b');
64        CPPUNIT_ASSERT(caca_get_char(cv, 5, 5) == 'c');
65
66        caca_free_canvas(cv);
67    }
68
69private:
70    static int const WIDTH = 80, HEIGHT = 50;
71};
72
73CPPUNIT_TEST_SUITE_REGISTRATION(ExportTest);
74
Note: See TracBrowser for help on using the repository browser.