[c8cf261] | 1 | /*
|
---|
| 2 | * Copyright (c) 2019 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[6af4b4f] | 29 | #include <errno.h>
|
---|
| 30 | #include <pcut/pcut.h>
|
---|
| 31 | #include <stdio.h>
|
---|
| 32 | #include <str.h>
|
---|
[c8cf261] | 33 |
|
---|
[b3c185b6] | 34 | #include "../client.h"
|
---|
[6af4b4f] | 35 | #include "../display.h"
|
---|
[cf32dbd] | 36 | #include "../seat.h"
|
---|
[b2d1df3] | 37 | #include "../window.h"
|
---|
[c8cf261] | 38 |
|
---|
[6af4b4f] | 39 | PCUT_INIT;
|
---|
[c8cf261] | 40 |
|
---|
[6af4b4f] | 41 | PCUT_TEST_SUITE(display);
|
---|
[c8cf261] | 42 |
|
---|
[be15256] | 43 | static void test_ds_ev_pending(void *);
|
---|
| 44 |
|
---|
| 45 | static ds_client_cb_t test_ds_client_cb = {
|
---|
| 46 | .ev_pending = test_ds_ev_pending
|
---|
| 47 | };
|
---|
| 48 |
|
---|
| 49 | static void test_ds_ev_pending(void *arg)
|
---|
| 50 | {
|
---|
[b2d1df3] | 51 | bool *called_cb = (bool *) arg;
|
---|
[be15256] | 52 | printf("test_ds_ev_pending\n");
|
---|
[b2d1df3] | 53 | *called_cb = true;
|
---|
[be15256] | 54 |
|
---|
[b2d1df3] | 55 | }
|
---|
[be15256] | 56 |
|
---|
[6af4b4f] | 57 | /** Display creation and destruction. */
|
---|
[bef51cf] | 58 | PCUT_TEST(display_create_destroy)
|
---|
[6af4b4f] | 59 | {
|
---|
| 60 | ds_display_t *disp;
|
---|
| 61 | errno_t rc;
|
---|
[c8cf261] | 62 |
|
---|
[159776f] | 63 | rc = ds_display_create(NULL, &disp);
|
---|
[6af4b4f] | 64 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 65 |
|
---|
| 66 | ds_display_destroy(disp);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[b3c185b6] | 69 | /** Basic client operation. */
|
---|
| 70 | PCUT_TEST(display_client)
|
---|
[bef51cf] | 71 | {
|
---|
| 72 | ds_display_t *disp;
|
---|
[b3c185b6] | 73 | ds_client_t *client;
|
---|
| 74 | ds_client_t *c0, *c1;
|
---|
[bef51cf] | 75 | errno_t rc;
|
---|
| 76 |
|
---|
[159776f] | 77 | rc = ds_display_create(NULL, &disp);
|
---|
[bef51cf] | 78 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 79 |
|
---|
[be15256] | 80 | rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
|
---|
[bef51cf] | 81 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 82 |
|
---|
[b3c185b6] | 83 | c0 = ds_display_first_client(disp);
|
---|
| 84 | PCUT_ASSERT_EQUALS(c0, client);
|
---|
[bef51cf] | 85 |
|
---|
[b3c185b6] | 86 | c1 = ds_display_next_client(c0);
|
---|
| 87 | PCUT_ASSERT_NULL(c1);
|
---|
[bef51cf] | 88 |
|
---|
[b3c185b6] | 89 | ds_client_destroy(client);
|
---|
[bef51cf] | 90 | ds_display_destroy(disp);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[b2d1df3] | 93 | /** Test ds_display_find_window(). */
|
---|
| 94 | PCUT_TEST(display_find_window)
|
---|
| 95 | {
|
---|
| 96 | ds_display_t *disp;
|
---|
| 97 | ds_client_t *client;
|
---|
| 98 | ds_window_t *w0;
|
---|
| 99 | ds_window_t *w1;
|
---|
| 100 | ds_window_t *wnd;
|
---|
| 101 | errno_t rc;
|
---|
| 102 |
|
---|
| 103 | rc = ds_display_create(NULL, &disp);
|
---|
| 104 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 105 |
|
---|
| 106 | rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
|
---|
| 107 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 108 |
|
---|
| 109 | rc = ds_window_create(client, &w0);
|
---|
| 110 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 111 |
|
---|
| 112 | rc = ds_window_create(client, &w1);
|
---|
| 113 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 114 |
|
---|
| 115 | wnd = ds_display_find_window(disp, w0->id);
|
---|
| 116 | PCUT_ASSERT_EQUALS(w0, wnd);
|
---|
| 117 |
|
---|
| 118 | wnd = ds_display_find_window(disp, w1->id);
|
---|
| 119 | PCUT_ASSERT_EQUALS(w1, wnd);
|
---|
| 120 |
|
---|
| 121 | wnd = ds_display_find_window(disp, 0);
|
---|
| 122 | PCUT_ASSERT_NULL(wnd);
|
---|
| 123 |
|
---|
| 124 | wnd = ds_display_find_window(disp, w1->id + 1);
|
---|
| 125 | PCUT_ASSERT_NULL(wnd);
|
---|
| 126 |
|
---|
[648e2ac] | 127 | ds_window_destroy(w0);
|
---|
| 128 | ds_window_destroy(w1);
|
---|
[b2d1df3] | 129 | ds_client_destroy(client);
|
---|
| 130 | ds_display_destroy(disp);
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[cf32dbd] | 133 | /** Basic seat operation. */
|
---|
| 134 | PCUT_TEST(display_seat)
|
---|
| 135 | {
|
---|
| 136 | ds_display_t *disp;
|
---|
| 137 | ds_seat_t *seat;
|
---|
| 138 | ds_seat_t *s0, *s1;
|
---|
| 139 | errno_t rc;
|
---|
| 140 |
|
---|
| 141 | rc = ds_display_create(NULL, &disp);
|
---|
| 142 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 143 |
|
---|
| 144 | rc = ds_seat_create(disp, &seat);
|
---|
| 145 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 146 |
|
---|
| 147 | s0 = ds_display_first_seat(disp);
|
---|
| 148 | PCUT_ASSERT_EQUALS(s0, seat);
|
---|
| 149 |
|
---|
| 150 | s1 = ds_display_next_seat(s0);
|
---|
| 151 | PCUT_ASSERT_NULL(s1);
|
---|
| 152 |
|
---|
| 153 | ds_seat_destroy(seat);
|
---|
| 154 | ds_display_destroy(disp);
|
---|
| 155 | }
|
---|
| 156 |
|
---|
[b2d1df3] | 157 | /** Test ds_display_post_kbd_event(). */
|
---|
| 158 | PCUT_TEST(display_post_kbd_event)
|
---|
| 159 | {
|
---|
| 160 | ds_display_t *disp;
|
---|
[cf32dbd] | 161 | ds_seat_t *seat;
|
---|
[b2d1df3] | 162 | ds_client_t *client;
|
---|
| 163 | ds_window_t *wnd;
|
---|
| 164 | kbd_event_t event;
|
---|
| 165 | bool called_cb = NULL;
|
---|
| 166 | errno_t rc;
|
---|
| 167 |
|
---|
| 168 | rc = ds_display_create(NULL, &disp);
|
---|
| 169 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 170 |
|
---|
[cf32dbd] | 171 | rc = ds_seat_create(disp, &seat);
|
---|
| 172 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 173 |
|
---|
[b2d1df3] | 174 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 175 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 176 |
|
---|
| 177 | rc = ds_window_create(client, &wnd);
|
---|
| 178 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 179 |
|
---|
| 180 | event.type = KEY_PRESS;
|
---|
| 181 | event.key = KC_ENTER;
|
---|
| 182 | event.mods = 0;
|
---|
| 183 | event.c = L'\0';
|
---|
| 184 |
|
---|
| 185 | PCUT_ASSERT_FALSE(called_cb);
|
---|
| 186 |
|
---|
| 187 | rc = ds_display_post_kbd_event(disp, &event);
|
---|
| 188 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 189 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 190 |
|
---|
[648e2ac] | 191 | ds_window_destroy(wnd);
|
---|
[b2d1df3] | 192 | ds_client_destroy(client);
|
---|
[cf32dbd] | 193 | ds_seat_destroy(seat);
|
---|
[b2d1df3] | 194 | ds_display_destroy(disp);
|
---|
| 195 | }
|
---|
| 196 |
|
---|
[6af4b4f] | 197 | PCUT_EXPORT(display);
|
---|