source: libcaca/trunk/test/canvas.cpp @ 4148

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

Update my e-mail address everywhere.

File size: 2.7 KB
RevLine 
[2301]1/*
[2821]2 *  caca-test     testsuite program for libcaca
[4148]3 *  Copyright (c) 2008 Sam Hocevar <samhocevar.net>
[2301]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
[2821]22#include "caca.h"
[2301]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    {
[2821]41        caca_canvas_t *cv;
[2301]42
[2821]43        cv = caca_create_canvas(0, 0);
[2301]44        CPPUNIT_ASSERT(cv != NULL);
45
[2821]46        caca_free_canvas(cv);
[2301]47    }
48
49    void test_resize()
50    {
[2821]51        caca_canvas_t *cv;
[2301]52
[2821]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);
[2301]56
[2821]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);
[2301]60
[2821]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);
[2301]64
[2821]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);
[2301]68
[2821]69        caca_free_canvas(cv);
[2301]70    }
71
72    void test_chars()
73    {
[2821]74        caca_canvas_t *cv;
[2301]75
[2821]76        cv = caca_create_canvas(0, 0);
77        CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == ' ');
[2301]78
[2821]79        caca_put_char(cv, 0, 0, 'x');
80        CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == ' ');
[2301]81
[2821]82        caca_set_canvas_size(cv, 1, 1);
83        CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == ' ');
[2301]84
[2821]85        caca_put_char(cv, 0, 0, 'x');
86        CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == 'x');
[2301]87
[2821]88        caca_put_char(cv, 0, 0, 'y');
89        CPPUNIT_ASSERT(caca_get_char(cv, 0, 0) == 'y');
[2301]90
[2821]91        caca_set_canvas_size(cv, 1000, 1000);
92        CPPUNIT_ASSERT(caca_get_char(cv, 999, 999) == ' ');
[2301]93
[2821]94        caca_put_char(cv, 999, 999, 'z');
95        CPPUNIT_ASSERT(caca_get_char(cv, 999, 999) == 'z');
[2301]96
[2821]97        caca_free_canvas(cv);
[2301]98    }
99};
100
101CPPUNIT_TEST_SUITE_REGISTRATION(CanvasTest);
102
Note: See TracBrowser for help on using the repository browser.