source: libcaca/trunk/tests/dirty.cpp @ 3449

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

Start writing unit tests for the dirty rectangle handling.

  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1/*
2 *  caca-test     testsuite program for libcaca
3 *  Copyright (c) 2009 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: dirty.cpp 3449 2009-05-14 00:18:30Z sam $
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 DirtyTest : public CppUnit::TestCase
25{
26    CPPUNIT_TEST_SUITE(DirtyTest);
27    CPPUNIT_TEST(test_create);
28    CPPUNIT_TEST(test_put_char);
29    CPPUNIT_TEST_SUITE_END();
30
31public:
32    DirtyTest() : CppUnit::TestCase("Dirty Rectangles Test") {}
33
34    void setUp() {}
35
36    void tearDown() {}
37
38    void test_create()
39    {
40        caca_canvas_t *cv;
41        int xmin, xmax, ymin, ymax;
42
43        /* Check that the dirty rectangle contains the whole canvas
44         * upon creation. */
45        cv = caca_create_canvas(WIDTH, HEIGHT);
46        caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
47        CPPUNIT_ASSERT(xmin <= 0);
48        CPPUNIT_ASSERT(ymin <= 0);
49        CPPUNIT_ASSERT(xmax >= caca_get_canvas_width(cv) - 1);
50        CPPUNIT_ASSERT(ymax >= caca_get_canvas_height(cv) - 1);
51
52        /* Invalidate the dirty rectangle and check that it stays so. */
53        caca_set_dirty_rectangle(cv, -1, -1, -1, -1);
54        caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
55        CPPUNIT_ASSERT(xmin > xmax || ymin > ymax);
56
57        caca_free_canvas(cv);
58    }
59
60    void test_put_char()
61    {
62        caca_canvas_t *cv;
63        int xmin, xmax, ymin, ymax;
64
65        cv = caca_create_canvas(WIDTH, HEIGHT);
66
67        caca_set_dirty_rectangle(cv, -1, -1, -1, -1);
68        caca_put_char(cv, 7, 3, 'x');
69        caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
70        CPPUNIT_ASSERT(xmin <= 7);
71        CPPUNIT_ASSERT(ymin <= 3);
72        CPPUNIT_ASSERT(xmax >= 7);
73        CPPUNIT_ASSERT(ymax >= 3);
74
75        caca_clear_canvas(cv);
76        caca_set_dirty_rectangle(cv, -1, -1, -1, -1);
77        caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
78        caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
79        CPPUNIT_ASSERT(xmin <= 7);
80        CPPUNIT_ASSERT(ymin <= 3);
81        CPPUNIT_ASSERT(xmax >= 8);
82        CPPUNIT_ASSERT(ymax >= 3);
83
84        caca_clear_canvas(cv);
85        caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
86        caca_set_dirty_rectangle(cv, -1, -1, -1, -1);
87        caca_put_char(cv, 7, 3, 'x');
88        caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
89        CPPUNIT_ASSERT(xmin <= 7);
90        CPPUNIT_ASSERT(ymin <= 3);
91        CPPUNIT_ASSERT(xmax >= 8);
92        CPPUNIT_ASSERT(ymax >= 3);
93
94        caca_clear_canvas(cv);
95        caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
96        caca_set_dirty_rectangle(cv, -1, -1, -1, -1);
97        caca_put_char(cv, 8, 3, 'x');
98        caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
99        CPPUNIT_ASSERT(xmin <= 7);
100        CPPUNIT_ASSERT(ymin <= 3);
101        CPPUNIT_ASSERT(xmax >= 8);
102        CPPUNIT_ASSERT(ymax >= 3);
103
104        caca_clear_canvas(cv);
105        caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
106        caca_set_dirty_rectangle(cv, -1, -1, -1, -1);
107        caca_put_char(cv, 6, 3, 0x2f06 /* ⼆ */);
108        caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
109        CPPUNIT_ASSERT(xmin <= 6);
110        CPPUNIT_ASSERT(ymin <= 3);
111        CPPUNIT_ASSERT(xmax >= 8);
112        CPPUNIT_ASSERT(ymax >= 3);
113
114        caca_clear_canvas(cv);
115        caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
116        caca_set_dirty_rectangle(cv, -1, -1, -1, -1);
117        caca_put_char(cv, 8, 3, 0x2f06 /* ⼆ */);
118        caca_get_dirty_rectangle(cv, &xmin, &ymin, &xmax, &ymax);
119        CPPUNIT_ASSERT(xmin <= 7);
120        CPPUNIT_ASSERT(ymin <= 3);
121        CPPUNIT_ASSERT(xmax >= 9);
122        CPPUNIT_ASSERT(ymax >= 3);
123    }
124
125private:
126    static int const WIDTH = 80, HEIGHT = 50;
127};
128
129CPPUNIT_TEST_SUITE_REGISTRATION(DirtyTest);
130
Note: See TracBrowser for help on using the repository browser.