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

Last change on this file since 2301 was 2301, checked in by Sam Hocevar, 12 years ago
  • Use CppUnit? for C and C++ unit tests. Sorry, Jylam.
File size: 2.8 KB
RevLine 
[2301]1/*
2 *  cucul-test    testsuite program for libcucul
3 *  Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
4 *  Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
5 *                All Rights Reserved
6 *
7 *  $Id$
8 *
9 *  This program is free software. It comes without any warranty, to
10 *  the extent permitted by applicable law. You can redistribute it
11 *  and/or modify it under the terms of the Do What The Fuck You Want
12 *  To Public License, Version 2, as published by Sam Hocevar. See
13 *  http://sam.zoy.org/wtfpl/COPYING for more details.
14 */
15
16#include "config.h"
17
18#include <cppunit/extensions/HelperMacros.h>
19#include <cppunit/TestCaller.h>
20#include <cppunit/TestCase.h>
21#include <cppunit/TestSuite.h>
22
23#include "cucul.h"
24
25class CanvasTest : public CppUnit::TestCase
26{
27    CPPUNIT_TEST_SUITE(CanvasTest);
28    CPPUNIT_TEST(test_creation);
29    CPPUNIT_TEST(test_resize);
30    CPPUNIT_TEST(test_chars);
31    CPPUNIT_TEST_SUITE_END();
32
33public:
34    CanvasTest() : CppUnit::TestCase("Canvas Test") {}
35
36    void setUp() {}
37
38    void tearDown() {}
39
40    void test_creation()
41    {
42        cucul_canvas_t *cv;
43
44        cv = cucul_create_canvas(0, 0);
45        CPPUNIT_ASSERT(cv != NULL);
46
47        cucul_free_canvas(cv);
48    }
49
50    void test_resize()
51    {
52        cucul_canvas_t *cv;
53
54        cv = cucul_create_canvas(0, 0);
55        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_width(cv), 0U);
56        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_height(cv), 0U);
57
58        cucul_set_canvas_size(cv, 1, 1);
59        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_width(cv), 1U);
60        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_height(cv), 1U);
61
62        cucul_set_canvas_size(cv, 1234, 1001);
63        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_width(cv), 1234U);
64        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_height(cv), 1001U);
65
66        cucul_set_canvas_size(cv, 0, 0);
67        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_width(cv), 0U);
68        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_height(cv), 0U);
69
70        cucul_free_canvas(cv);
71    }
72
73    void test_chars()
74    {
75        cucul_canvas_t *cv;
76
77        cv = cucul_create_canvas(0, 0);
78        CPPUNIT_ASSERT(cucul_get_char(cv, 0, 0) == ' ');
79
80        cucul_put_char(cv, 0, 0, 'x');
81        CPPUNIT_ASSERT(cucul_get_char(cv, 0, 0) == ' ');
82
83        cucul_set_canvas_size(cv, 1, 1);
84        CPPUNIT_ASSERT(cucul_get_char(cv, 0, 0) == ' ');
85
86        cucul_put_char(cv, 0, 0, 'x');
87        CPPUNIT_ASSERT(cucul_get_char(cv, 0, 0) == 'x');
88
89        cucul_put_char(cv, 0, 0, 'y');
90        CPPUNIT_ASSERT(cucul_get_char(cv, 0, 0) == 'y');
91
92        cucul_set_canvas_size(cv, 1000, 1000);
93        CPPUNIT_ASSERT(cucul_get_char(cv, 999, 999) == ' ');
94
95        cucul_put_char(cv, 999, 999, 'z');
96        CPPUNIT_ASSERT(cucul_get_char(cv, 999, 999) == 'z');
97
98        cucul_free_canvas(cv);
99    }
100};
101
102CPPUNIT_TEST_SUITE_REGISTRATION(CanvasTest);
103
Note: See TracBrowser for help on using the repository browser.