source: libcaca/trunk/tests/canvas.cpp @ 2821

Last change on this file since 2821 was 2821, checked in by Sam Hocevar, 11 years ago

Starting refactoring to get rid of libcucul. The initial reason for the
split is rendered moot by the plugin system: when enabled, binaries do
not link directly with libX11 or libGL. I hope this is a step towards
more consisteny and clarity.

File size: 2.7 KB
Line 
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
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 CanvasTest : public CppUnit::TestCase
25{
26    CPPUNIT_TEST_SUITE(CanvasTest);
27    CPPUNIT_TEST(test_creation);
28    CPPUNIT_TEST(test_resize);
29    CPPUNIT_TEST(test_chars);
30    CPPUNIT_TEST_SUITE_END();
31
32public:
33    CanvasTest() : CppUnit::TestCase("Canvas Test") {}
34
35    void setUp() {}
36
37    void tearDown() {}
38
39    void test_creation()
40    {
41        caca_canvas_t *cv;
42
43        cv = caca_create_canvas(0, 0);
44        CPPUNIT_ASSERT(cv != NULL);
45
46        caca_free_canvas(cv);
47    }
48
49    void test_resize()
50    {
51        caca_canvas_t *cv;
52
53        cv = caca_create_canvas(0, 0);
54        CPPUNIT_ASSERT_EQUAL(caca_get_canvas_width(cv), 0);
55        CPPUNIT_ASSERT_EQUAL(caca_get_canvas_height(cv), 0);
56
57        caca_set_canvas_size(cv, 1, 1);
58        CPPUNIT_ASSERT_EQUAL(caca_get_canvas_width(cv), 1);
59        CPPUNIT_ASSERT_EQUAL(caca_get_canvas_height(cv), 1);
60
61        caca_set_canvas_size(cv, 1234, 1001);
62        CPPUNIT_ASSERT_EQUAL(caca_get_canvas_width(cv), 1234);
63        CPPUNIT_ASSERT_EQUAL(caca_get_canvas_height(cv), 1001);
64
65        caca_set_canvas_size(cv, 0, 0);
66        CPPUNIT_ASSERT_EQUAL(caca_get_canvas_width(cv), 0);
67        CPPUNIT_ASSERT_EQUAL(caca_get_canvas_height(cv), 0);
68
69        caca_free_canvas(cv);
70    }
71
72    void test_chars()
73    {
74        caca_canvas_t *cv;
75
76        cv = caca_create_canvas(0, 0);
77        CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == ' ');
78
79        caca_put_char(cv, 0, 0, 'x');
80        CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == ' ');
81
82        caca_set_canvas_size(cv, 1, 1);
83        CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == ' ');
84
85        caca_put_char(cv, 0, 0, 'x');
86        CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == 'x');
87
88        caca_put_char(cv, 0, 0, 'y');
89        CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == 'y');
90
91        caca_set_canvas_size(cv, 1000, 1000);
92        CPPUNIT_ASSERT(caca_get_char(cv, 999, 999) == ' ');
93
94        caca_put_char(cv, 999, 999, 'z');
95        CPPUNIT_ASSERT(caca_get_char(cv, 999, 999) == 'z');
96
97        caca_free_canvas(cv);
98    }
99};
100
101CPPUNIT_TEST_SUITE_REGISTRATION(CanvasTest);
102
Note: See TracBrowser for help on using the repository browser.