source: libcaca/trunk/test/export.cpp @ 4333

Last change on this file since 4333 was 4333, checked in by Sam Hocevar, 10 years ago

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

  • 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 *  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
13#include "config.h"
14
15#include <cppunit/extensions/HelperMacros.h>
16#include <cppunit/TestCaller.h>
17#include <cppunit/TestCase.h>
18#include <cppunit/TestSuite.h>
19
20#include "caca.h"
21
22class ExportTest : public CppUnit::TestCase
23{
24    CPPUNIT_TEST_SUITE(ExportTest);
25    CPPUNIT_TEST(test_export_area_caca);
26    CPPUNIT_TEST_SUITE_END();
27
28public:
29    ExportTest() : CppUnit::TestCase("Export/Import Test") {}
30
31    void setUp() {}
32
33    void tearDown() {}
34
35    void test_export_area_caca()
36    {
37        caca_canvas_t *cv;
38        size_t bytes, l;
39        void *buf;
40
41        cv = caca_create_canvas(WIDTH, HEIGHT);
42        caca_put_char(cv, 7, 3, 'a');
43        caca_put_char(cv, 10, 3, 'b');
44        caca_put_char(cv, 5, 5, 'c');
45        buf = caca_export_area_to_memory (cv, 0, 0, 10, 5, "caca", &bytes);
46        CPPUNIT_ASSERT(buf != NULL);
47        CPPUNIT_ASSERT(bytes > 0);
48
49        caca_clear_canvas(cv);
50        l = caca_import_area_from_memory(cv, 0, 0, buf, bytes, "caca");
51        CPPUNIT_ASSERT(l == bytes);
52        CPPUNIT_ASSERT(caca_get_char(cv, 7, 3) == 'a');
53        CPPUNIT_ASSERT(caca_get_char(cv, 10, 3) == ' ');
54        CPPUNIT_ASSERT(caca_get_char(cv, 5, 5) == ' ');
55
56        caca_put_char(cv, 10, 3, 'b');
57        caca_put_char(cv, 5, 5, 'c');
58        l = caca_import_area_from_memory(cv, 0, 0, buf, bytes, "caca");
59        CPPUNIT_ASSERT(l == bytes);
60        CPPUNIT_ASSERT(caca_get_char(cv, 7, 3) == 'a');
61        CPPUNIT_ASSERT(caca_get_char(cv, 10, 3) == 'b');
62        CPPUNIT_ASSERT(caca_get_char(cv, 5, 5) == 'c');
63
64        caca_free_canvas(cv);
65    }
66
67private:
68    static int const WIDTH = 80, HEIGHT = 50;
69};
70
71CPPUNIT_TEST_SUITE_REGISTRATION(ExportTest);
72
Note: See TracBrowser for help on using the repository browser.