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

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

Change the dirty rectangle API once again so that calling applications get
a more natural (x,y,w,h) 4-tuple to handle.

  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1/*
2 *  caca-test     testsuite program for libcaca
3 *  Copyright (c) 2009 Sam Hocevar <sam@hocevar.net>
4 *                All Rights Reserved
5 *
6 *  $Id: dirty.cpp 3494 2009-05-21 20:55:13Z 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, dx, dy, dw, dh;
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_rect_count(cv);
47        CPPUNIT_ASSERT_EQUAL(i, 1);
48
49        caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
50        CPPUNIT_ASSERT_EQUAL(dx, 0);
51        CPPUNIT_ASSERT_EQUAL(dy, 0);
52        CPPUNIT_ASSERT_EQUAL(dw, caca_get_canvas_width(cv));
53        CPPUNIT_ASSERT_EQUAL(dh, caca_get_canvas_height(cv));
54
55        /* Invalidate the dirty rectangle and check that it stays so. */
56        caca_clear_dirty_rect_list(cv);
57        i = caca_get_dirty_rect_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, dx, dy, dw, dh;
67
68        cv = caca_create_canvas(WIDTH, HEIGHT);
69
70        caca_clear_dirty_rect_list(cv);
71        caca_put_char(cv, 7, 3, 'x');
72        i = caca_get_dirty_rect_count(cv);
73        CPPUNIT_ASSERT_EQUAL(i, 1);
74        caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
75        CPPUNIT_ASSERT_EQUAL(dx, 7);
76        CPPUNIT_ASSERT_EQUAL(dy, 3);
77        CPPUNIT_ASSERT_EQUAL(dw, 1);
78        CPPUNIT_ASSERT_EQUAL(dh, 1);
79
80        caca_clear_canvas(cv);
81        caca_clear_dirty_rect_list(cv);
82        caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
83        i = caca_get_dirty_rect_count(cv);
84        CPPUNIT_ASSERT_EQUAL(i, 1);
85        caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
86        CPPUNIT_ASSERT_EQUAL(dx, 7);
87        CPPUNIT_ASSERT_EQUAL(dy, 3);
88        CPPUNIT_ASSERT_EQUAL(dw, 2);
89        CPPUNIT_ASSERT_EQUAL(dh, 1);
90
91        caca_clear_canvas(cv);
92        caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
93        caca_clear_dirty_rect_list(cv);
94        caca_put_char(cv, 7, 3, 'x');
95        i = caca_get_dirty_rect_count(cv);
96        CPPUNIT_ASSERT_EQUAL(i, 1);
97        caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
98        CPPUNIT_ASSERT_EQUAL(dx, 7);
99        CPPUNIT_ASSERT_EQUAL(dy, 3);
100        CPPUNIT_ASSERT_EQUAL(dw, 2);
101        CPPUNIT_ASSERT_EQUAL(dh, 1);
102
103        caca_clear_canvas(cv);
104        caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
105        caca_clear_dirty_rect_list(cv);
106        caca_put_char(cv, 8, 3, 'x');
107        i = caca_get_dirty_rect_count(cv);
108        CPPUNIT_ASSERT_EQUAL(i, 1);
109        caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
110        CPPUNIT_ASSERT_EQUAL(dx, 7);
111        CPPUNIT_ASSERT_EQUAL(dy, 3);
112        CPPUNIT_ASSERT_EQUAL(dw, 2);
113        CPPUNIT_ASSERT_EQUAL(dh, 1);
114
115        caca_clear_canvas(cv);
116        caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
117        caca_clear_dirty_rect_list(cv);
118        caca_put_char(cv, 6, 3, 0x2f06 /* ⼆ */);
119        i = caca_get_dirty_rect_count(cv);
120        CPPUNIT_ASSERT_EQUAL(i, 1);
121        caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
122        CPPUNIT_ASSERT_EQUAL(dx, 6);
123        CPPUNIT_ASSERT_EQUAL(dy, 3);
124        CPPUNIT_ASSERT_EQUAL(dw, 3);
125        CPPUNIT_ASSERT_EQUAL(dh, 1);
126
127        caca_clear_canvas(cv);
128        caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
129        caca_clear_dirty_rect_list(cv);
130        caca_put_char(cv, 8, 3, 0x2f06 /* ⼆ */);
131        i = caca_get_dirty_rect_count(cv);
132        CPPUNIT_ASSERT_EQUAL(i, 1);
133        caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
134        CPPUNIT_ASSERT_EQUAL(dx, 7);
135        CPPUNIT_ASSERT_EQUAL(dy, 3);
136        CPPUNIT_ASSERT_EQUAL(dw, 3);
137        CPPUNIT_ASSERT_EQUAL(dh, 1);
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.