[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"
|
---|
[b2d1df3] | 36 | #include "../window.h"
|
---|
[c8cf261] | 37 |
|
---|
[6af4b4f] | 38 | PCUT_INIT;
|
---|
[c8cf261] | 39 |
|
---|
[6af4b4f] | 40 | PCUT_TEST_SUITE(display);
|
---|
[c8cf261] | 41 |
|
---|
[be15256] | 42 | static void test_ds_ev_pending(void *);
|
---|
| 43 |
|
---|
| 44 | static ds_client_cb_t test_ds_client_cb = {
|
---|
| 45 | .ev_pending = test_ds_ev_pending
|
---|
| 46 | };
|
---|
| 47 |
|
---|
| 48 | static void test_ds_ev_pending(void *arg)
|
---|
| 49 | {
|
---|
[b2d1df3] | 50 | bool *called_cb = (bool *) arg;
|
---|
[be15256] | 51 | printf("test_ds_ev_pending\n");
|
---|
[b2d1df3] | 52 | *called_cb = true;
|
---|
[be15256] | 53 |
|
---|
[b2d1df3] | 54 | }
|
---|
[be15256] | 55 |
|
---|
[6af4b4f] | 56 | /** Display creation and destruction. */
|
---|
[bef51cf] | 57 | PCUT_TEST(display_create_destroy)
|
---|
[6af4b4f] | 58 | {
|
---|
| 59 | ds_display_t *disp;
|
---|
| 60 | errno_t rc;
|
---|
[c8cf261] | 61 |
|
---|
[159776f] | 62 | rc = ds_display_create(NULL, &disp);
|
---|
[6af4b4f] | 63 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 64 |
|
---|
| 65 | ds_display_destroy(disp);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[b3c185b6] | 68 | /** Basic client operation. */
|
---|
| 69 | PCUT_TEST(display_client)
|
---|
[bef51cf] | 70 | {
|
---|
| 71 | ds_display_t *disp;
|
---|
[b3c185b6] | 72 | ds_client_t *client;
|
---|
| 73 | ds_client_t *c0, *c1;
|
---|
[bef51cf] | 74 | errno_t rc;
|
---|
| 75 |
|
---|
[159776f] | 76 | rc = ds_display_create(NULL, &disp);
|
---|
[bef51cf] | 77 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 78 |
|
---|
[be15256] | 79 | rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
|
---|
[bef51cf] | 80 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 81 |
|
---|
[b3c185b6] | 82 | c0 = ds_display_first_client(disp);
|
---|
| 83 | PCUT_ASSERT_EQUALS(c0, client);
|
---|
[bef51cf] | 84 |
|
---|
[b3c185b6] | 85 | c1 = ds_display_next_client(c0);
|
---|
| 86 | PCUT_ASSERT_NULL(c1);
|
---|
[bef51cf] | 87 |
|
---|
[b3c185b6] | 88 | ds_client_destroy(client);
|
---|
[bef51cf] | 89 | ds_display_destroy(disp);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[b2d1df3] | 92 | /** Test ds_display_find_window(). */
|
---|
| 93 | PCUT_TEST(display_find_window)
|
---|
| 94 | {
|
---|
| 95 | ds_display_t *disp;
|
---|
| 96 | ds_client_t *client;
|
---|
| 97 | ds_window_t *w0;
|
---|
| 98 | ds_window_t *w1;
|
---|
| 99 | ds_window_t *wnd;
|
---|
| 100 | errno_t rc;
|
---|
| 101 |
|
---|
| 102 | rc = ds_display_create(NULL, &disp);
|
---|
| 103 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 104 |
|
---|
| 105 | rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
|
---|
| 106 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 107 |
|
---|
| 108 | rc = ds_window_create(client, &w0);
|
---|
| 109 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 110 |
|
---|
| 111 | rc = ds_window_create(client, &w1);
|
---|
| 112 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 113 |
|
---|
| 114 | wnd = ds_display_find_window(disp, w0->id);
|
---|
| 115 | PCUT_ASSERT_EQUALS(w0, wnd);
|
---|
| 116 |
|
---|
| 117 | wnd = ds_display_find_window(disp, w1->id);
|
---|
| 118 | PCUT_ASSERT_EQUALS(w1, wnd);
|
---|
| 119 |
|
---|
| 120 | wnd = ds_display_find_window(disp, 0);
|
---|
| 121 | PCUT_ASSERT_NULL(wnd);
|
---|
| 122 |
|
---|
| 123 | wnd = ds_display_find_window(disp, w1->id + 1);
|
---|
| 124 | PCUT_ASSERT_NULL(wnd);
|
---|
| 125 |
|
---|
[648e2ac] | 126 | ds_window_destroy(w0);
|
---|
| 127 | ds_window_destroy(w1);
|
---|
[b2d1df3] | 128 | ds_client_destroy(client);
|
---|
| 129 | ds_display_destroy(disp);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | /** Test ds_display_post_kbd_event(). */
|
---|
| 133 | PCUT_TEST(display_post_kbd_event)
|
---|
| 134 | {
|
---|
| 135 | ds_display_t *disp;
|
---|
| 136 | ds_client_t *client;
|
---|
| 137 | ds_window_t *wnd;
|
---|
| 138 | kbd_event_t event;
|
---|
| 139 | bool called_cb = NULL;
|
---|
| 140 | errno_t rc;
|
---|
| 141 |
|
---|
| 142 | rc = ds_display_create(NULL, &disp);
|
---|
| 143 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 144 |
|
---|
| 145 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
| 146 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 147 |
|
---|
| 148 | rc = ds_window_create(client, &wnd);
|
---|
| 149 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 150 |
|
---|
| 151 | event.type = KEY_PRESS;
|
---|
| 152 | event.key = KC_ENTER;
|
---|
| 153 | event.mods = 0;
|
---|
| 154 | event.c = L'\0';
|
---|
| 155 |
|
---|
| 156 | PCUT_ASSERT_FALSE(called_cb);
|
---|
| 157 |
|
---|
| 158 | rc = ds_display_post_kbd_event(disp, &event);
|
---|
| 159 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 160 | PCUT_ASSERT_TRUE(called_cb);
|
---|
| 161 |
|
---|
[648e2ac] | 162 | ds_window_destroy(wnd);
|
---|
[b2d1df3] | 163 | ds_client_destroy(client);
|
---|
| 164 | ds_display_destroy(disp);
|
---|
| 165 | }
|
---|
| 166 |
|
---|
[6af4b4f] | 167 | PCUT_EXPORT(display);
|
---|