1 | /*
|
---|
2 | * Copyright (c) 2023 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 "../cfgclient.h"
|
---|
36 |
|
---|
37 | PCUT_INIT;
|
---|
38 |
|
---|
39 | PCUT_TEST_SUITE(cfgclient);
|
---|
40 |
|
---|
41 | static void test_ds_dcev_pending(void *);
|
---|
42 |
|
---|
43 | static ds_cfgclient_cb_t test_ds_cfgclient_cb = {
|
---|
44 | .ev_pending = test_ds_dcev_pending
|
---|
45 | };
|
---|
46 |
|
---|
47 | static void test_ds_dcev_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_cfgclient_t *cfgclient;
|
---|
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_cfgclient_create(disp, &test_ds_cfgclient_cb, NULL, &cfgclient);
|
---|
64 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
65 |
|
---|
66 | ds_cfgclient_destroy(cfgclient);
|
---|
67 | ds_display_destroy(disp);
|
---|
68 | }
|
---|
69 |
|
---|
70 | /** Test ds_cfgclient_get_event(), ds_cfgclient_post_seat_added_event(). */
|
---|
71 | PCUT_TEST(client_get_post_seat_added_event)
|
---|
72 | {
|
---|
73 | ds_display_t *disp;
|
---|
74 | ds_cfgclient_t *cfgclient;
|
---|
75 | dispcfg_ev_t revent;
|
---|
76 | bool called_cb = NULL;
|
---|
77 | sysarg_t seat_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_cfgclient_create(disp, &test_ds_cfgclient_cb, &called_cb,
|
---|
84 | &cfgclient);
|
---|
85 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
86 |
|
---|
87 | called_cb = false;
|
---|
88 | seat_id = 42;
|
---|
89 |
|
---|
90 | rc = ds_cfgclient_get_event(cfgclient, &revent);
|
---|
91 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
92 |
|
---|
93 | rc = ds_cfgclient_post_seat_added_event(cfgclient, seat_id);
|
---|
94 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
95 | PCUT_ASSERT_TRUE(called_cb);
|
---|
96 |
|
---|
97 | rc = ds_cfgclient_get_event(cfgclient, &revent);
|
---|
98 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
99 | PCUT_ASSERT_EQUALS(seat_id, revent.seat_id);
|
---|
100 | PCUT_ASSERT_EQUALS(dcev_seat_added, revent.etype);
|
---|
101 |
|
---|
102 | rc = ds_cfgclient_get_event(cfgclient, &revent);
|
---|
103 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
104 |
|
---|
105 | ds_cfgclient_destroy(cfgclient);
|
---|
106 | ds_display_destroy(disp);
|
---|
107 | }
|
---|
108 |
|
---|
109 | /** Test ds_cfgclient_get_event(), ds_cfgclient_post_seat_removed_event(). */
|
---|
110 | PCUT_TEST(client_get_post_seat_removed_event)
|
---|
111 | {
|
---|
112 | ds_display_t *disp;
|
---|
113 | ds_cfgclient_t *cfgclient;
|
---|
114 | dispcfg_ev_t revent;
|
---|
115 | bool called_cb = NULL;
|
---|
116 | sysarg_t seat_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_cfgclient_create(disp, &test_ds_cfgclient_cb, &called_cb,
|
---|
123 | &cfgclient);
|
---|
124 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
125 |
|
---|
126 | called_cb = false;
|
---|
127 | seat_id = 42;
|
---|
128 |
|
---|
129 | rc = ds_cfgclient_get_event(cfgclient, &revent);
|
---|
130 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
131 |
|
---|
132 | rc = ds_cfgclient_post_seat_removed_event(cfgclient, seat_id);
|
---|
133 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
134 | PCUT_ASSERT_TRUE(called_cb);
|
---|
135 |
|
---|
136 | rc = ds_cfgclient_get_event(cfgclient, &revent);
|
---|
137 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
138 | PCUT_ASSERT_EQUALS(seat_id, revent.seat_id);
|
---|
139 | PCUT_ASSERT_EQUALS(dcev_seat_removed, revent.etype);
|
---|
140 |
|
---|
141 | rc = ds_cfgclient_get_event(cfgclient, &revent);
|
---|
142 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
143 |
|
---|
144 | ds_cfgclient_destroy(cfgclient);
|
---|
145 | ds_display_destroy(disp);
|
---|
146 | }
|
---|
147 |
|
---|
148 | /** Test ds_cfgclient_purge_events() */
|
---|
149 | PCUT_TEST(purge_events)
|
---|
150 | {
|
---|
151 | ds_display_t *disp;
|
---|
152 | ds_cfgclient_t *cfgclient;
|
---|
153 | dispcfg_ev_t revent;
|
---|
154 | bool called_cb = NULL;
|
---|
155 | sysarg_t seat_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_cfgclient_create(disp, &test_ds_cfgclient_cb, &called_cb,
|
---|
162 | &cfgclient);
|
---|
163 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
164 |
|
---|
165 | /* Post window added event */
|
---|
166 | seat_id = 42;
|
---|
167 | rc = ds_cfgclient_post_seat_added_event(cfgclient, seat_id);
|
---|
168 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
169 |
|
---|
170 | /* Purge it */
|
---|
171 | ds_cfgclient_purge_events(cfgclient);
|
---|
172 |
|
---|
173 | /* The queue should be empty now */
|
---|
174 | rc = ds_cfgclient_get_event(cfgclient, &revent);
|
---|
175 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
176 |
|
---|
177 | ds_cfgclient_destroy(cfgclient);
|
---|
178 | ds_display_destroy(disp);
|
---|
179 | }
|
---|
180 |
|
---|
181 | PCUT_EXPORT(cfgclient);
|
---|