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

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

Change the dirty rectangle API so that it can handle several rectangles. The
inner implementation still only handles one dirty rectangle, but this way
we can prepare supporting applictions for the future.

  • Property svn:keywords set to Id
File size: 4.7 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 3470 2009-05-19 00:51:47Z 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 i, 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        i = caca_get_dirty_rectangle_count(cv);
47        CPPUNIT_ASSERT_EQUAL(i, 1);
48
49        caca_get_dirty_rectangle(cv, 0, &xmin, &ymin, &xmax, &ymax);
50        CPPUNIT_ASSERT_EQUAL(xmin, 0);
51        CPPUNIT_ASSERT_EQUAL(ymin, 0);
52        CPPUNIT_ASSERT_EQUAL(xmax, caca_get_canvas_width(cv) - 1);
53        CPPUNIT_ASSERT_EQUAL(ymax, caca_get_canvas_height(cv) - 1);
54
55        /* Invalidate the dirty rectangle and check that it stays so. */
56        caca_clear_dirty_rectangle_list(cv);
57        i = caca_get_dirty_rectangle_count(cv);
58        CPPUNIT_ASSERT_EQUAL(i, 0);
59
60        caca_free_canvas(cv);
61    }
62
63    void test_put_char()
64    {
65        caca_canvas_t *cv;
66        int i, xmin, xmax, ymin, ymax;
67
68        cv = caca_create_canvas(WIDTH, HEIGHT);
69
70        caca_clear_dirty_rectangle_list(cv);
71        caca_put_char(cv, 7, 3, 'x');
72        i = caca_get_dirty_rectangle_count(cv);
73        CPPUNIT_ASSERT_EQUAL(i, 1);
74        caca_get_dirty_rectangle(cv, 0, &xmin, &ymin, &xmax, &ymax);
75        CPPUNIT_ASSERT_EQUAL(xmin, 7);
76        CPPUNIT_ASSERT_EQUAL(ymin, 3);
77        CPPUNIT_ASSERT_EQUAL(xmax, 7);
78        CPPUNIT_ASSERT_EQUAL(ymax, 3);
79
80        caca_clear_canvas(cv);
81        caca_clear_dirty_rectangle_list(cv);
82        caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
83        i = caca_get_dirty_rectangle_count(cv);
84        CPPUNIT_ASSERT_EQUAL(i, 1);
85        caca_get_dirty_rectangle(cv, 0, &xmin, &ymin, &xmax, &ymax);
86        CPPUNIT_ASSERT_EQUAL(xmin, 7);
87        CPPUNIT_ASSERT_EQUAL(ymin, 3);
88        CPPUNIT_ASSERT_EQUAL(xmax, 8);
89        CPPUNIT_ASSERT_EQUAL(ymax, 3);
90
91        caca_clear_canvas(cv);
92        caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
93        caca_clear_dirty_rectangle_list(cv);
94        caca_put_char(cv, 7, 3, 'x');
95        i = caca_get_dirty_rectangle_count(cv);
96        CPPUNIT_ASSERT_EQUAL(i, 1);
97        caca_get_dirty_rectangle(cv, 0, &xmin, &ymin, &xmax, &ymax);
98        CPPUNIT_ASSERT_EQUAL(xmin, 7);
99        CPPUNIT_ASSERT_EQUAL(ymin, 3);
100        CPPUNIT_ASSERT_EQUAL(xmax, 8);
101        CPPUNIT_ASSERT_EQUAL(ymax, 3);
102
103        caca_clear_canvas(cv);
104        caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
105        caca_clear_dirty_rectangle_list(cv);
106        caca_put_char(cv, 8, 3, 'x');
107        i = caca_get_dirty_rectangle_count(cv);
108        CPPUNIT_ASSERT_EQUAL(i, 1);
109        caca_get_dirty_rectangle(cv, 0, &xmin, &ymin, &xmax, &ymax);
110        CPPUNIT_ASSERT_EQUAL(xmin, 7);
111        CPPUNIT_ASSERT_EQUAL(ymin, 3);
112        CPPUNIT_ASSERT_EQUAL(xmax, 8);
113        CPPUNIT_ASSERT_EQUAL(ymax, 3);
114
115        caca_clear_canvas(cv);
116        caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
117        caca_clear_dirty_rectangle_list(cv);
118        caca_put_char(cv, 6, 3, 0x2f06 /* ⼆ */);
119        i = caca_get_dirty_rectangle_count(cv);
120        CPPUNIT_ASSERT_EQUAL(i, 1);
121        caca_get_dirty_rectangle(cv, 0, &xmin, &ymin, &xmax, &ymax);
122        CPPUNIT_ASSERT_EQUAL(xmin, 6);
123        CPPUNIT_ASSERT_EQUAL(ymin, 3);
124        CPPUNIT_ASSERT_EQUAL(xmax, 8);
125        CPPUNIT_ASSERT_EQUAL(ymax, 3);
126
127        caca_clear_canvas(cv);
128        caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
129        caca_clear_dirty_rectangle_list(cv);
130        caca_put_char(cv, 8, 3, 0x2f06 /* ⼆ */);
131        i = caca_get_dirty_rectangle_count(cv);
132        CPPUNIT_ASSERT_EQUAL(i, 1);
133        caca_get_dirty_rectangle(cv, 0, &xmin, &ymin, &xmax, &ymax);
134        CPPUNIT_ASSERT_EQUAL(xmin, 7);
135        CPPUNIT_ASSERT_EQUAL(ymin, 3);
136        CPPUNIT_ASSERT_EQUAL(xmax, 9);
137        CPPUNIT_ASSERT_EQUAL(ymax, 3);
138    }
139
140private:
141    static int const WIDTH = 80, HEIGHT = 50;
142};
143
144CPPUNIT_TEST_SUITE_REGISTRATION(DirtyTest);
145
Note: See TracBrowser for help on using the repository browser.