xserver

xserver with xephyr scale patch
git clone https://git.neptards.moe/u3shit/xserver.git
Log | Files | Refs | README | LICENSE

misc.c (6128B)


      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 /* Test relies on assert() */
     25 #undef NDEBUG
     26 
     27 #ifdef HAVE_DIX_CONFIG_H
     28 #include <dix-config.h>
     29 #endif
     30 
     31 #include <stdint.h>
     32 #include "misc.h"
     33 #include "scrnintstr.h"
     34 #include "dix.h"
     35 #include "dixstruct.h"
     36 
     37 #include "tests-common.h"
     38 
     39 static void
     40 dix_version_compare(void)
     41 {
     42     int rc;
     43 
     44     rc = version_compare(0, 0, 1, 0);
     45     assert(rc < 0);
     46     rc = version_compare(1, 0, 0, 0);
     47     assert(rc > 0);
     48     rc = version_compare(0, 0, 0, 0);
     49     assert(rc == 0);
     50     rc = version_compare(1, 0, 1, 0);
     51     assert(rc == 0);
     52     rc = version_compare(1, 0, 0, 9);
     53     assert(rc > 0);
     54     rc = version_compare(0, 9, 1, 0);
     55     assert(rc < 0);
     56     rc = version_compare(1, 0, 1, 9);
     57     assert(rc < 0);
     58     rc = version_compare(1, 9, 1, 0);
     59     assert(rc > 0);
     60     rc = version_compare(2, 0, 1, 9);
     61     assert(rc > 0);
     62     rc = version_compare(1, 9, 2, 0);
     63     assert(rc < 0);
     64 }
     65 
     66 static void
     67 dix_update_desktop_dimensions(void)
     68 {
     69     int i;
     70     int x, y, w, h;
     71     int w2, h2;
     72     ScreenRec screens[MAXSCREENS];
     73 
     74     for (i = 0; i < MAXSCREENS; i++)
     75         screenInfo.screens[i] = &screens[i];
     76 
     77     x = 0;
     78     y = 0;
     79     w = 10;
     80     h = 5;
     81     w2 = 35;
     82     h2 = 25;
     83 
     84 #define assert_dimensions(_x, _y, _w, _h) \
     85     update_desktop_dimensions();          \
     86     assert(screenInfo.x == _x);           \
     87     assert(screenInfo.y == _y);           \
     88     assert(screenInfo.width == _w);       \
     89     assert(screenInfo.height == _h);
     90 
     91 #define set_screen(idx, _x, _y, _w, _h)   \
     92     screenInfo.screens[idx]->x = _x;      \
     93     screenInfo.screens[idx]->y = _y;      \
     94     screenInfo.screens[idx]->width = _w;  \
     95     screenInfo.screens[idx]->height = _h; \
     96 
     97     /* single screen */
     98     screenInfo.numScreens = 1;
     99     set_screen(0, x, y, w, h);
    100     assert_dimensions(x, y, w, h);
    101 
    102     /* dualhead rightof */
    103     screenInfo.numScreens = 2;
    104     set_screen(1, w, 0, w2, h2);
    105     assert_dimensions(x, y, w + w2, h2);
    106 
    107     /* dualhead belowof */
    108     screenInfo.numScreens = 2;
    109     set_screen(1, 0, h, w2, h2);
    110     assert_dimensions(x, y, w2, h + h2);
    111 
    112     /* triplehead L shape */
    113     screenInfo.numScreens = 3;
    114     set_screen(1, 0, h, w2, h2);
    115     set_screen(2, w2, h2, w, h);
    116     assert_dimensions(x, y, w + w2, h + h2);
    117 
    118     /* quadhead 2x2 */
    119     screenInfo.numScreens = 4;
    120     set_screen(1, 0, h, w, h);
    121     set_screen(2, w, h, w, h2);
    122     set_screen(3, w, 0, w2, h);
    123     assert_dimensions(x, y, w + w2, h + h2);
    124 
    125     /* quadhead horiz line */
    126     screenInfo.numScreens = 4;
    127     set_screen(1, w, 0, w, h);
    128     set_screen(2, 2 * w, 0, w, h);
    129     set_screen(3, 3 * w, 0, w, h);
    130     assert_dimensions(x, y, 4 * w, h);
    131 
    132     /* quadhead vert line */
    133     screenInfo.numScreens = 4;
    134     set_screen(1, 0, h, w, h);
    135     set_screen(2, 0, 2 * h, w, h);
    136     set_screen(3, 0, 3 * h, w, h);
    137     assert_dimensions(x, y, w, 4 * h);
    138 
    139     /* x overlap */
    140     screenInfo.numScreens = 2;
    141     set_screen(0, 0, 0, w2, h2);
    142     set_screen(1, w, 0, w2, h2);
    143     assert_dimensions(x, y, w2 + w, h2);
    144 
    145     /* y overlap */
    146     screenInfo.numScreens = 2;
    147     set_screen(0, 0, 0, w2, h2);
    148     set_screen(1, 0, h, w2, h2);
    149     assert_dimensions(x, y, w2, h2 + h);
    150 
    151     /* negative origin */
    152     screenInfo.numScreens = 1;
    153     set_screen(0, -w2, -h2, w, h);
    154     assert_dimensions(-w2, -h2, w, h);
    155 
    156     /* dualhead negative origin, overlap */
    157     screenInfo.numScreens = 2;
    158     set_screen(0, -w2, -h2, w2, h2);
    159     set_screen(1, -w, -h, w, h);
    160     assert_dimensions(-w2, -h2, w2, h2);
    161 }
    162 
    163 static int
    164 dix_request_fixed_size_overflow(ClientRec *client)
    165 {
    166     xReq req = { 0 };
    167 
    168     client->req_len = req.length = 1;
    169     REQUEST_FIXED_SIZE(req, SIZE_MAX);
    170     return Success;
    171 }
    172 
    173 static int
    174 dix_request_fixed_size_match(ClientRec *client)
    175 {
    176     xReq req = { 0 };
    177 
    178     client->req_len = req.length = 9;
    179     REQUEST_FIXED_SIZE(req, 30);
    180     return Success;
    181 }
    182 
    183 static void
    184 dix_request_size_checks(void)
    185 {
    186     ClientRec client = { 0 };
    187     int rc;
    188 
    189     rc = dix_request_fixed_size_overflow(&client);
    190     assert(rc == BadLength);
    191 
    192     rc = dix_request_fixed_size_match(&client);
    193     assert(rc == Success);
    194 }
    195 
    196 static void
    197 bswap_test(void)
    198 {
    199     const uint16_t test_16 = 0xaabb;
    200     const uint16_t expect_16 = 0xbbaa;
    201     const uint32_t test_32 = 0xaabbccdd;
    202     const uint32_t expect_32 = 0xddccbbaa;
    203     const uint64_t test_64 = 0x11223344aabbccddull;
    204     const uint64_t expect_64 = 0xddccbbaa44332211ull;
    205     uint16_t result_16;
    206     uint32_t result_32;
    207     uint64_t result_64;
    208 
    209     assert(bswap_16(test_16) == expect_16);
    210     assert(bswap_32(test_32) == expect_32);
    211     assert(bswap_64(test_64) == expect_64);
    212 
    213     result_16 = test_16;
    214     swaps(&result_16);
    215     assert(result_16 == expect_16);
    216 
    217     result_32 = test_32;
    218     swapl(&result_32);
    219     assert(result_32 == expect_32);
    220 
    221     result_64 = test_64;
    222     swapll(&result_64);
    223     assert(result_64 == expect_64);
    224 }
    225 
    226 int
    227 misc_test(void)
    228 {
    229     dix_version_compare();
    230     dix_update_desktop_dimensions();
    231     dix_request_size_checks();
    232     bswap_test();
    233 
    234     return 0;
    235 }