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

Last change on this file since 2309 was 2309, checked in by Sam Hocevar, 12 years ago
  • Started libcaca unit tests.
File size: 2.7 KB
Line 
1/*
2 *  cucul-test    testsuite program for libcucul
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 "cucul.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        cucul_canvas_t *cv;
42
43        cv = cucul_create_canvas(0, 0);
44        CPPUNIT_ASSERT(cv != NULL);
45
46        cucul_free_canvas(cv);
47    }
48
49    void test_resize()
50    {
51        cucul_canvas_t *cv;
52
53        cv = cucul_create_canvas(0, 0);
54        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_width(cv), 0);
55        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_height(cv), 0);
56
57        cucul_set_canvas_size(cv, 1, 1);
58        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_width(cv), 1);
59        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_height(cv), 1);
60
61        cucul_set_canvas_size(cv, 1234, 1001);
62        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_width(cv), 1234);
63        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_height(cv), 1001);
64
65        cucul_set_canvas_size(cv, 0, 0);
66        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_width(cv), 0);
67        CPPUNIT_ASSERT_EQUAL(cucul_get_canvas_height(cv), 0);
68
69        cucul_free_canvas(cv);
70    }
71
72    void test_chars()
73    {
74        cucul_canvas_t *cv;
75
76        cv = cucul_create_canvas(0, 0);
77        CPPUNIT_ASSERT(cucul_get_char(cv, 0, 0) == ' ');
78
79        cucul_put_char(cv, 0, 0, 'x');
80        CPPUNIT_ASSERT(cucul_get_char(cv, 0, 0) == ' ');
81
82        cucul_set_canvas_size(cv, 1, 1);
83        CPPUNIT_ASSERT(cucul_get_char(cv, 0, 0) == ' ');
84
85        cucul_put_char(cv, 0, 0, 'x');
86        CPPUNIT_ASSERT(cucul_get_char(cv, 0, 0) == 'x');
87
88        cucul_put_char(cv, 0, 0, 'y');
89        CPPUNIT_ASSERT(cucul_get_char(cv, 0, 0) == 'y');
90
91        cucul_set_canvas_size(cv, 1000, 1000);
92        CPPUNIT_ASSERT(cucul_get_char(cv, 999, 999) == ' ');
93
94        cucul_put_char(cv, 999, 999, 'z');
95        CPPUNIT_ASSERT(cucul_get_char(cv, 999, 999) == 'z');
96
97        cucul_free_canvas(cv);
98    }
99};
100
101CPPUNIT_TEST_SUITE_REGISTRATION(CanvasTest);
102
Note: See TracBrowser for help on using the repository browser.