| 1 | /*
|
|---|
| 2 | * Copyright (c) 2022 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 |
|
|---|
| 29 | #include <disp_srv.h>
|
|---|
| 30 | #include <errno.h>
|
|---|
| 31 | #include <pcut/pcut.h>
|
|---|
| 32 | #include <str.h>
|
|---|
| 33 |
|
|---|
| 34 | #include "../display.h"
|
|---|
| 35 | #include "../wmclient.h"
|
|---|
| 36 |
|
|---|
| 37 | PCUT_INIT;
|
|---|
| 38 |
|
|---|
| 39 | PCUT_TEST_SUITE(wmclient);
|
|---|
| 40 |
|
|---|
| 41 | static void test_ds_wmev_pending(void *);
|
|---|
| 42 |
|
|---|
| 43 | static ds_wmclient_cb_t test_ds_wmclient_cb = {
|
|---|
| 44 | .ev_pending = test_ds_wmev_pending
|
|---|
| 45 | };
|
|---|
| 46 |
|
|---|
| 47 | static void test_ds_wmev_pending(void *arg)
|
|---|
| 48 | {
|
|---|
| 49 | bool *called_cb = (bool *) arg;
|
|---|
| 50 | *called_cb = true;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | /** WM client creation and destruction. */
|
|---|
| 54 | PCUT_TEST(create_destroy)
|
|---|
| 55 | {
|
|---|
| 56 | ds_display_t *disp;
|
|---|
| 57 | ds_wmclient_t *wmclient;
|
|---|
| 58 | errno_t rc;
|
|---|
| 59 |
|
|---|
| 60 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 61 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 62 |
|
|---|
| 63 | rc = ds_wmclient_create(disp, &test_ds_wmclient_cb, NULL, &wmclient);
|
|---|
| 64 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 65 |
|
|---|
| 66 | ds_wmclient_destroy(wmclient);
|
|---|
| 67 | ds_display_destroy(disp);
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | /** Test ds_wmclient_get_event(), ds_wmclient_post_wnd_added_event(). */
|
|---|
| 71 | PCUT_TEST(client_get_post_wnd_added_event)
|
|---|
| 72 | {
|
|---|
| 73 | ds_display_t *disp;
|
|---|
| 74 | ds_wmclient_t *wmclient;
|
|---|
| 75 | wndmgt_ev_t revent;
|
|---|
| 76 | bool called_cb = NULL;
|
|---|
| 77 | sysarg_t wnd_id;
|
|---|
| 78 | errno_t rc;
|
|---|
| 79 |
|
|---|
| 80 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 81 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 82 |
|
|---|
| 83 | rc = ds_wmclient_create(disp, &test_ds_wmclient_cb, &called_cb,
|
|---|
| 84 | &wmclient);
|
|---|
| 85 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 86 |
|
|---|
| 87 | called_cb = false;
|
|---|
| 88 | wnd_id = 42;
|
|---|
| 89 |
|
|---|
| 90 | rc = ds_wmclient_get_event(wmclient, &revent);
|
|---|
| 91 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
|---|
| 92 |
|
|---|
| 93 | rc = ds_wmclient_post_wnd_added_event(wmclient, wnd_id);
|
|---|
| 94 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 95 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 96 |
|
|---|
| 97 | rc = ds_wmclient_get_event(wmclient, &revent);
|
|---|
| 98 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 99 | PCUT_ASSERT_EQUALS(wnd_id, revent.wnd_id);
|
|---|
| 100 | PCUT_ASSERT_EQUALS(wmev_window_added, revent.etype);
|
|---|
| 101 |
|
|---|
| 102 | rc = ds_wmclient_get_event(wmclient, &revent);
|
|---|
| 103 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
|---|
| 104 |
|
|---|
| 105 | ds_wmclient_destroy(wmclient);
|
|---|
| 106 | ds_display_destroy(disp);
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | /** Test ds_wmclient_get_event(), ds_wmclient_post_wnd_removed_event(). */
|
|---|
| 110 | PCUT_TEST(client_get_post_wnd_removed_event)
|
|---|
| 111 | {
|
|---|
| 112 | ds_display_t *disp;
|
|---|
| 113 | ds_wmclient_t *wmclient;
|
|---|
| 114 | wndmgt_ev_t revent;
|
|---|
| 115 | bool called_cb = NULL;
|
|---|
| 116 | sysarg_t wnd_id;
|
|---|
| 117 | errno_t rc;
|
|---|
| 118 |
|
|---|
| 119 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 120 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 121 |
|
|---|
| 122 | rc = ds_wmclient_create(disp, &test_ds_wmclient_cb, &called_cb,
|
|---|
| 123 | &wmclient);
|
|---|
| 124 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 125 |
|
|---|
| 126 | called_cb = false;
|
|---|
| 127 | wnd_id = 42;
|
|---|
| 128 |
|
|---|
| 129 | rc = ds_wmclient_get_event(wmclient, &revent);
|
|---|
| 130 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
|---|
| 131 |
|
|---|
| 132 | rc = ds_wmclient_post_wnd_removed_event(wmclient, wnd_id);
|
|---|
| 133 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 134 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 135 |
|
|---|
| 136 | rc = ds_wmclient_get_event(wmclient, &revent);
|
|---|
| 137 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 138 | PCUT_ASSERT_EQUALS(wnd_id, revent.wnd_id);
|
|---|
| 139 | PCUT_ASSERT_EQUALS(wmev_window_removed, revent.etype);
|
|---|
| 140 |
|
|---|
| 141 | rc = ds_wmclient_get_event(wmclient, &revent);
|
|---|
| 142 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
|---|
| 143 |
|
|---|
| 144 | ds_wmclient_destroy(wmclient);
|
|---|
| 145 | ds_display_destroy(disp);
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | /** Test ds_wmclient_get_event(), ds_wmclient_post_wnd_changed_event(). */
|
|---|
| 149 | PCUT_TEST(client_get_post_wnd_changed_event)
|
|---|
| 150 | {
|
|---|
| 151 | ds_display_t *disp;
|
|---|
| 152 | ds_wmclient_t *wmclient;
|
|---|
| 153 | wndmgt_ev_t revent;
|
|---|
| 154 | bool called_cb = NULL;
|
|---|
| 155 | sysarg_t wnd_id;
|
|---|
| 156 | errno_t rc;
|
|---|
| 157 |
|
|---|
| 158 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 159 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 160 |
|
|---|
| 161 | rc = ds_wmclient_create(disp, &test_ds_wmclient_cb, &called_cb,
|
|---|
| 162 | &wmclient);
|
|---|
| 163 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 164 |
|
|---|
| 165 | called_cb = false;
|
|---|
| 166 | wnd_id = 42;
|
|---|
| 167 |
|
|---|
| 168 | rc = ds_wmclient_get_event(wmclient, &revent);
|
|---|
| 169 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
|---|
| 170 |
|
|---|
| 171 | rc = ds_wmclient_post_wnd_changed_event(wmclient, wnd_id);
|
|---|
| 172 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 173 | PCUT_ASSERT_TRUE(called_cb);
|
|---|
| 174 |
|
|---|
| 175 | rc = ds_wmclient_get_event(wmclient, &revent);
|
|---|
| 176 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 177 | PCUT_ASSERT_EQUALS(wnd_id, revent.wnd_id);
|
|---|
| 178 | PCUT_ASSERT_EQUALS(wmev_window_changed, revent.etype);
|
|---|
| 179 |
|
|---|
| 180 | rc = ds_wmclient_get_event(wmclient, &revent);
|
|---|
| 181 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
|---|
| 182 |
|
|---|
| 183 | ds_wmclient_destroy(wmclient);
|
|---|
| 184 | ds_display_destroy(disp);
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | /** Test ds_wmclient_purge_events() */
|
|---|
| 188 | PCUT_TEST(purge_events)
|
|---|
| 189 | {
|
|---|
| 190 | ds_display_t *disp;
|
|---|
| 191 | ds_wmclient_t *wmclient;
|
|---|
| 192 | wndmgt_ev_t revent;
|
|---|
| 193 | bool called_cb = NULL;
|
|---|
| 194 | sysarg_t wnd_id;
|
|---|
| 195 | errno_t rc;
|
|---|
| 196 |
|
|---|
| 197 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 198 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 199 |
|
|---|
| 200 | rc = ds_wmclient_create(disp, &test_ds_wmclient_cb, &called_cb,
|
|---|
| 201 | &wmclient);
|
|---|
| 202 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 203 |
|
|---|
| 204 | /* Post window added event */
|
|---|
| 205 | wnd_id = 42;
|
|---|
| 206 | rc = ds_wmclient_post_wnd_added_event(wmclient, wnd_id);
|
|---|
| 207 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 208 |
|
|---|
| 209 | /* Purge it */
|
|---|
| 210 | ds_wmclient_purge_events(wmclient);
|
|---|
| 211 |
|
|---|
| 212 | /* The queue should be empty now */
|
|---|
| 213 | rc = ds_wmclient_get_event(wmclient, &revent);
|
|---|
| 214 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
|---|
| 215 |
|
|---|
| 216 | ds_wmclient_destroy(wmclient);
|
|---|
| 217 | ds_display_destroy(disp);
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | PCUT_EXPORT(wmclient);
|
|---|