misc.c revision 35c4bbdf
1/**
2 * Copyright © 2011 Red Hat, Inc.
3 *
4 *  Permission is hereby granted, free of charge, to any person obtaining a
5 *  copy of this software and associated documentation files (the "Software"),
6 *  to deal in the Software without restriction, including without limitation
7 *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 *  and/or sell copies of the Software, and to permit persons to whom the
9 *  Software is furnished to do so, subject to the following conditions:
10 *
11 *  The above copyright notice and this permission notice (including the next
12 *  paragraph) shall be included in all copies or substantial portions of the
13 *  Software.
14 *
15 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 *  DEALINGS IN THE SOFTWARE.
22 */
23
24#ifdef HAVE_DIX_CONFIG_H
25#include <dix-config.h>
26#endif
27
28#include <stdint.h>
29#include "misc.h"
30#include "scrnintstr.h"
31#include "dix.h"
32#include "dixstruct.h"
33
34ScreenInfo screenInfo;
35
36static void
37dix_version_compare(void)
38{
39    int rc;
40
41    rc = version_compare(0, 0, 1, 0);
42    assert(rc < 0);
43    rc = version_compare(1, 0, 0, 0);
44    assert(rc > 0);
45    rc = version_compare(0, 0, 0, 0);
46    assert(rc == 0);
47    rc = version_compare(1, 0, 1, 0);
48    assert(rc == 0);
49    rc = version_compare(1, 0, 0, 9);
50    assert(rc > 0);
51    rc = version_compare(0, 9, 1, 0);
52    assert(rc < 0);
53    rc = version_compare(1, 0, 1, 9);
54    assert(rc < 0);
55    rc = version_compare(1, 9, 1, 0);
56    assert(rc > 0);
57    rc = version_compare(2, 0, 1, 9);
58    assert(rc > 0);
59    rc = version_compare(1, 9, 2, 0);
60    assert(rc < 0);
61}
62
63static void
64dix_update_desktop_dimensions(void)
65{
66    int i;
67    int x, y, w, h;
68    int w2, h2;
69    ScreenRec screens[MAXSCREENS];
70
71    for (i = 0; i < MAXSCREENS; i++)
72        screenInfo.screens[i] = &screens[i];
73
74    x = 0;
75    y = 0;
76    w = 10;
77    h = 5;
78    w2 = 35;
79    h2 = 25;
80
81#define assert_dimensions(_x, _y, _w, _h) \
82    update_desktop_dimensions();          \
83    assert(screenInfo.x == _x);           \
84    assert(screenInfo.y == _y);           \
85    assert(screenInfo.width == _w);       \
86    assert(screenInfo.height == _h);
87
88#define set_screen(idx, _x, _y, _w, _h)   \
89    screenInfo.screens[idx]->x = _x;      \
90    screenInfo.screens[idx]->y = _y;      \
91    screenInfo.screens[idx]->width = _w;  \
92    screenInfo.screens[idx]->height = _h; \
93
94    /* single screen */
95    screenInfo.numScreens = 1;
96    set_screen(0, x, y, w, h);
97    assert_dimensions(x, y, w, h);
98
99    /* dualhead rightof */
100    screenInfo.numScreens = 2;
101    set_screen(1, w, 0, w2, h2);
102    assert_dimensions(x, y, w + w2, h2);
103
104    /* dualhead belowof */
105    screenInfo.numScreens = 2;
106    set_screen(1, 0, h, w2, h2);
107    assert_dimensions(x, y, w2, h + h2);
108
109    /* triplehead L shape */
110    screenInfo.numScreens = 3;
111    set_screen(1, 0, h, w2, h2);
112    set_screen(2, w2, h2, w, h);
113    assert_dimensions(x, y, w + w2, h + h2);
114
115    /* quadhead 2x2 */
116    screenInfo.numScreens = 4;
117    set_screen(1, 0, h, w, h);
118    set_screen(2, w, h, w, h2);
119    set_screen(3, w, 0, w2, h);
120    assert_dimensions(x, y, w + w2, h + h2);
121
122    /* quadhead horiz line */
123    screenInfo.numScreens = 4;
124    set_screen(1, w, 0, w, h);
125    set_screen(2, 2 * w, 0, w, h);
126    set_screen(3, 3 * w, 0, w, h);
127    assert_dimensions(x, y, 4 * w, h);
128
129    /* quadhead vert line */
130    screenInfo.numScreens = 4;
131    set_screen(1, 0, h, w, h);
132    set_screen(2, 0, 2 * h, w, h);
133    set_screen(3, 0, 3 * h, w, h);
134    assert_dimensions(x, y, w, 4 * h);
135
136    /* x overlap */
137    screenInfo.numScreens = 2;
138    set_screen(0, 0, 0, w2, h2);
139    set_screen(1, w, 0, w2, h2);
140    assert_dimensions(x, y, w2 + w, h2);
141
142    /* y overlap */
143    screenInfo.numScreens = 2;
144    set_screen(0, 0, 0, w2, h2);
145    set_screen(1, 0, h, w2, h2);
146    assert_dimensions(x, y, w2, h2 + h);
147
148    /* negative origin */
149    screenInfo.numScreens = 1;
150    set_screen(0, -w2, -h2, w, h);
151    assert_dimensions(-w2, -h2, w, h);
152
153    /* dualhead negative origin, overlap */
154    screenInfo.numScreens = 2;
155    set_screen(0, -w2, -h2, w2, h2);
156    set_screen(1, -w, -h, w, h);
157    assert_dimensions(-w2, -h2, w2, h2);
158}
159
160static int
161dix_request_fixed_size_overflow(ClientRec *client)
162{
163    xReq req = { 0 };
164
165    client->req_len = req.length = 1;
166    REQUEST_FIXED_SIZE(req, SIZE_MAX);
167    return Success;
168}
169
170static int
171dix_request_fixed_size_match(ClientRec *client)
172{
173    xReq req = { 0 };
174
175    client->req_len = req.length = 9;
176    REQUEST_FIXED_SIZE(req, 30);
177    return Success;
178}
179
180static void
181dix_request_size_checks(void)
182{
183    ClientRec client = { 0 };
184    int rc;
185
186    rc = dix_request_fixed_size_overflow(&client);
187    assert(rc == BadLength);
188
189    rc = dix_request_fixed_size_match(&client);
190    assert(rc == Success);
191}
192
193
194int
195main(int argc, char **argv)
196{
197    dix_version_compare();
198    dix_update_desktop_dimensions();
199    dix_request_size_checks();
200
201    return 0;
202}
203