1 | /*
|
---|
2 | * Copyright (c) 2024 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 <errno.h>
|
---|
30 | #include <pcut/pcut.h>
|
---|
31 | #include <tbarcfg/tbarcfg.h>
|
---|
32 | #include <stdbool.h>
|
---|
33 | #include <stdio.h>
|
---|
34 |
|
---|
35 | PCUT_INIT;
|
---|
36 |
|
---|
37 | PCUT_TEST_SUITE(tbarcfg);
|
---|
38 |
|
---|
39 | typedef struct {
|
---|
40 | bool notified;
|
---|
41 | } tbarcfg_test_resp_t;
|
---|
42 |
|
---|
43 | static void test_cb(void *);
|
---|
44 |
|
---|
45 | /** Creating, opening and closing taskbar configuration */
|
---|
46 | PCUT_TEST(create_open_close)
|
---|
47 | {
|
---|
48 | errno_t rc;
|
---|
49 | tbarcfg_t *tbcfg;
|
---|
50 | char fname[L_tmpnam], *p;
|
---|
51 |
|
---|
52 | p = tmpnam(fname);
|
---|
53 | PCUT_ASSERT_NOT_NULL(p);
|
---|
54 |
|
---|
55 | /* Create new repository */
|
---|
56 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
57 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
58 |
|
---|
59 | tbarcfg_sync(tbcfg);
|
---|
60 | tbarcfg_close(tbcfg);
|
---|
61 |
|
---|
62 | /* Re-open the repository */
|
---|
63 |
|
---|
64 | rc = tbarcfg_open(fname, &tbcfg);
|
---|
65 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
66 |
|
---|
67 | tbarcfg_close(tbcfg);
|
---|
68 | remove(fname);
|
---|
69 | }
|
---|
70 |
|
---|
71 | /** Iterating over start menu entries */
|
---|
72 | PCUT_TEST(first_next)
|
---|
73 | {
|
---|
74 | errno_t rc;
|
---|
75 | tbarcfg_t *tbcfg;
|
---|
76 | char fname[L_tmpnam], *p;
|
---|
77 | smenu_entry_t *e1 = NULL, *e2 = NULL;
|
---|
78 | smenu_entry_t *e;
|
---|
79 |
|
---|
80 | p = tmpnam(fname);
|
---|
81 | PCUT_ASSERT_NOT_NULL(p);
|
---|
82 |
|
---|
83 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
84 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
85 |
|
---|
86 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
|
---|
87 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
88 | PCUT_ASSERT_NOT_NULL(e1);
|
---|
89 |
|
---|
90 | rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
|
---|
91 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
92 | PCUT_ASSERT_NOT_NULL(e2);
|
---|
93 |
|
---|
94 | /* Create entry without getting a pointer to it */
|
---|
95 | rc = smenu_entry_create(tbcfg, "C", "c", false, NULL);
|
---|
96 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
97 |
|
---|
98 | e = tbarcfg_smenu_first(tbcfg);
|
---|
99 | PCUT_ASSERT_EQUALS(e1, e);
|
---|
100 | e = tbarcfg_smenu_next(e);
|
---|
101 | PCUT_ASSERT_EQUALS(e2, e);
|
---|
102 | e = tbarcfg_smenu_next(e);
|
---|
103 | PCUT_ASSERT_NOT_NULL(e);
|
---|
104 | e = tbarcfg_smenu_next(e);
|
---|
105 | PCUT_ASSERT_NULL(e);
|
---|
106 |
|
---|
107 | tbarcfg_close(tbcfg);
|
---|
108 | remove(fname);
|
---|
109 | }
|
---|
110 |
|
---|
111 | /** Iterating over start menu entries backwards */
|
---|
112 | PCUT_TEST(last_prev)
|
---|
113 | {
|
---|
114 | errno_t rc;
|
---|
115 | tbarcfg_t *tbcfg;
|
---|
116 | char fname[L_tmpnam], *p;
|
---|
117 | smenu_entry_t *e1 = NULL, *e2 = NULL;
|
---|
118 | smenu_entry_t *e;
|
---|
119 |
|
---|
120 | p = tmpnam(fname);
|
---|
121 | PCUT_ASSERT_NOT_NULL(p);
|
---|
122 |
|
---|
123 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
124 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
125 |
|
---|
126 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
|
---|
127 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
128 | PCUT_ASSERT_NOT_NULL(e1);
|
---|
129 |
|
---|
130 | rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
|
---|
131 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
132 | PCUT_ASSERT_NOT_NULL(e2);
|
---|
133 |
|
---|
134 | e = tbarcfg_smenu_last(tbcfg);
|
---|
135 | PCUT_ASSERT_EQUALS(e2, e);
|
---|
136 | e = tbarcfg_smenu_prev(e);
|
---|
137 | PCUT_ASSERT_EQUALS(e1, e);
|
---|
138 | e = tbarcfg_smenu_prev(e);
|
---|
139 | PCUT_ASSERT_NULL(e);
|
---|
140 |
|
---|
141 | tbarcfg_close(tbcfg);
|
---|
142 | remove(fname);
|
---|
143 | }
|
---|
144 |
|
---|
145 | /** Separator entry */
|
---|
146 | PCUT_TEST(separator)
|
---|
147 | {
|
---|
148 | errno_t rc;
|
---|
149 | tbarcfg_t *tbcfg;
|
---|
150 | char fname[L_tmpnam], *p;
|
---|
151 | const char *caption;
|
---|
152 | const char *cmd;
|
---|
153 | smenu_entry_t *e1 = NULL, *e2 = NULL;
|
---|
154 | smenu_entry_t *e;
|
---|
155 |
|
---|
156 | p = tmpnam(fname);
|
---|
157 | PCUT_ASSERT_NOT_NULL(p);
|
---|
158 |
|
---|
159 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
160 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
161 |
|
---|
162 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
|
---|
163 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
164 | PCUT_ASSERT_NOT_NULL(e1);
|
---|
165 |
|
---|
166 | rc = smenu_entry_sep_create(tbcfg, &e2);
|
---|
167 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
168 | PCUT_ASSERT_NOT_NULL(e2);
|
---|
169 |
|
---|
170 | PCUT_ASSERT_FALSE(smenu_entry_get_separator(e1));
|
---|
171 | PCUT_ASSERT_TRUE(smenu_entry_get_separator(e2));
|
---|
172 |
|
---|
173 | tbarcfg_sync(tbcfg);
|
---|
174 | tbarcfg_close(tbcfg);
|
---|
175 |
|
---|
176 | /* Re-open repository */
|
---|
177 |
|
---|
178 | rc = tbarcfg_open(fname, &tbcfg);
|
---|
179 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
180 |
|
---|
181 | e = tbarcfg_smenu_first(tbcfg);
|
---|
182 | PCUT_ASSERT_NOT_NULL(e);
|
---|
183 |
|
---|
184 | /* Check that new values of properties have persisted */
|
---|
185 | PCUT_ASSERT_FALSE(smenu_entry_get_separator(e));
|
---|
186 | caption = smenu_entry_get_caption(e);
|
---|
187 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
188 | cmd = smenu_entry_get_cmd(e);
|
---|
189 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
190 |
|
---|
191 | e = tbarcfg_smenu_next(e);
|
---|
192 |
|
---|
193 | /* Check that entry is still a separator */
|
---|
194 | PCUT_ASSERT_TRUE(smenu_entry_get_separator(e));
|
---|
195 |
|
---|
196 | tbarcfg_close(tbcfg);
|
---|
197 | remove(fname);
|
---|
198 | }
|
---|
199 |
|
---|
200 | /** Getting menu entry properties */
|
---|
201 | PCUT_TEST(get_caption_cmd_term)
|
---|
202 | {
|
---|
203 | errno_t rc;
|
---|
204 | tbarcfg_t *tbcfg;
|
---|
205 | char fname[L_tmpnam], *p;
|
---|
206 | smenu_entry_t *e;
|
---|
207 | const char *caption;
|
---|
208 | const char *cmd;
|
---|
209 | bool terminal;
|
---|
210 |
|
---|
211 | p = tmpnam(fname);
|
---|
212 | PCUT_ASSERT_NOT_NULL(p);
|
---|
213 |
|
---|
214 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
215 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
216 |
|
---|
217 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
|
---|
218 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
219 |
|
---|
220 | caption = smenu_entry_get_caption(e);
|
---|
221 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
222 | cmd = smenu_entry_get_cmd(e);
|
---|
223 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
224 | terminal = smenu_entry_get_terminal(e);
|
---|
225 | PCUT_ASSERT_FALSE(terminal);
|
---|
226 |
|
---|
227 | tbarcfg_close(tbcfg);
|
---|
228 | remove(fname);
|
---|
229 | }
|
---|
230 |
|
---|
231 | /** Setting menu entry properties */
|
---|
232 | PCUT_TEST(set_caption_cmd_term)
|
---|
233 | {
|
---|
234 | errno_t rc;
|
---|
235 | tbarcfg_t *tbcfg;
|
---|
236 | char fname[L_tmpnam], *p;
|
---|
237 | smenu_entry_t *e;
|
---|
238 | const char *caption;
|
---|
239 | const char *cmd;
|
---|
240 | bool terminal;
|
---|
241 |
|
---|
242 | p = tmpnam(fname);
|
---|
243 | PCUT_ASSERT_NOT_NULL(p);
|
---|
244 |
|
---|
245 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
246 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
247 |
|
---|
248 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
|
---|
249 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
250 |
|
---|
251 | caption = smenu_entry_get_caption(e);
|
---|
252 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
253 | cmd = smenu_entry_get_cmd(e);
|
---|
254 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
255 | terminal = smenu_entry_get_terminal(e);
|
---|
256 | PCUT_ASSERT_FALSE(terminal);
|
---|
257 |
|
---|
258 | /* Set properties */
|
---|
259 | rc = smenu_entry_set_caption(e, "B");
|
---|
260 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
261 | rc = smenu_entry_set_cmd(e, "b");
|
---|
262 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
263 | smenu_entry_set_terminal(e, true);
|
---|
264 |
|
---|
265 | rc = tbarcfg_sync(tbcfg);
|
---|
266 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
267 |
|
---|
268 | /* Check that properties have been set */
|
---|
269 | caption = smenu_entry_get_caption(e);
|
---|
270 | PCUT_ASSERT_STR_EQUALS("B", caption);
|
---|
271 | cmd = smenu_entry_get_cmd(e);
|
---|
272 | PCUT_ASSERT_STR_EQUALS("b", cmd);
|
---|
273 | terminal = smenu_entry_get_terminal(e);
|
---|
274 | PCUT_ASSERT_TRUE(terminal);
|
---|
275 |
|
---|
276 | tbarcfg_sync(tbcfg);
|
---|
277 | tbarcfg_close(tbcfg);
|
---|
278 |
|
---|
279 | /* Re-open repository */
|
---|
280 |
|
---|
281 | rc = tbarcfg_open(fname, &tbcfg);
|
---|
282 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
283 |
|
---|
284 | e = tbarcfg_smenu_first(tbcfg);
|
---|
285 | PCUT_ASSERT_NOT_NULL(e);
|
---|
286 |
|
---|
287 | /* Check that new values of properties have persisted */
|
---|
288 | caption = smenu_entry_get_caption(e);
|
---|
289 | PCUT_ASSERT_STR_EQUALS("B", caption);
|
---|
290 | cmd = smenu_entry_get_cmd(e);
|
---|
291 | PCUT_ASSERT_STR_EQUALS("b", cmd);
|
---|
292 |
|
---|
293 | tbarcfg_close(tbcfg);
|
---|
294 | remove(fname);
|
---|
295 | }
|
---|
296 |
|
---|
297 | /** Create start menu entry */
|
---|
298 | PCUT_TEST(entry_create)
|
---|
299 | {
|
---|
300 | errno_t rc;
|
---|
301 | tbarcfg_t *tbcfg;
|
---|
302 | char fname[L_tmpnam], *p;
|
---|
303 | smenu_entry_t *e;
|
---|
304 | const char *caption;
|
---|
305 | const char *cmd;
|
---|
306 | bool terminal;
|
---|
307 |
|
---|
308 | p = tmpnam(fname);
|
---|
309 | PCUT_ASSERT_NOT_NULL(p);
|
---|
310 |
|
---|
311 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
312 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
313 |
|
---|
314 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
|
---|
315 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
316 | PCUT_ASSERT_NOT_NULL(e);
|
---|
317 |
|
---|
318 | caption = smenu_entry_get_caption(e);
|
---|
319 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
320 | cmd = smenu_entry_get_cmd(e);
|
---|
321 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
322 | terminal = smenu_entry_get_terminal(e);
|
---|
323 | PCUT_ASSERT_FALSE(terminal);
|
---|
324 |
|
---|
325 | smenu_entry_destroy(e);
|
---|
326 |
|
---|
327 | rc = smenu_entry_create(tbcfg, "B", "b", true, &e);
|
---|
328 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
329 | PCUT_ASSERT_NOT_NULL(e);
|
---|
330 |
|
---|
331 | caption = smenu_entry_get_caption(e);
|
---|
332 | PCUT_ASSERT_STR_EQUALS("B", caption);
|
---|
333 | cmd = smenu_entry_get_cmd(e);
|
---|
334 | PCUT_ASSERT_STR_EQUALS("b", cmd);
|
---|
335 | terminal = smenu_entry_get_terminal(e);
|
---|
336 | PCUT_ASSERT_TRUE(terminal);
|
---|
337 |
|
---|
338 | smenu_entry_destroy(e);
|
---|
339 |
|
---|
340 | tbarcfg_close(tbcfg);
|
---|
341 | remove(fname);
|
---|
342 | }
|
---|
343 |
|
---|
344 | /** Destroy start menu entry */
|
---|
345 | PCUT_TEST(entry_destroy)
|
---|
346 | {
|
---|
347 | errno_t rc;
|
---|
348 | tbarcfg_t *tbcfg;
|
---|
349 | char fname[L_tmpnam], *p;
|
---|
350 | smenu_entry_t *e, *f;
|
---|
351 |
|
---|
352 | p = tmpnam(fname);
|
---|
353 | PCUT_ASSERT_NOT_NULL(p);
|
---|
354 |
|
---|
355 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
356 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
357 |
|
---|
358 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
|
---|
359 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
360 |
|
---|
361 | f = tbarcfg_smenu_first(tbcfg);
|
---|
362 | PCUT_ASSERT_EQUALS(e, f);
|
---|
363 |
|
---|
364 | smenu_entry_destroy(e);
|
---|
365 |
|
---|
366 | f = tbarcfg_smenu_first(tbcfg);
|
---|
367 | PCUT_ASSERT_NULL(f);
|
---|
368 |
|
---|
369 | tbarcfg_close(tbcfg);
|
---|
370 | remove(fname);
|
---|
371 | }
|
---|
372 |
|
---|
373 | /** Move start menu entry up */
|
---|
374 | PCUT_TEST(entry_move_up)
|
---|
375 | {
|
---|
376 | errno_t rc;
|
---|
377 | tbarcfg_t *tbcfg;
|
---|
378 | char fname[L_tmpnam], *p;
|
---|
379 | smenu_entry_t *e1, *e2, *e3;
|
---|
380 | smenu_entry_t *f;
|
---|
381 | const char *caption;
|
---|
382 | const char *cmd;
|
---|
383 |
|
---|
384 | p = tmpnam(fname);
|
---|
385 | PCUT_ASSERT_NOT_NULL(p);
|
---|
386 |
|
---|
387 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
388 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
389 |
|
---|
390 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
|
---|
391 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
392 |
|
---|
393 | rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
|
---|
394 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
395 |
|
---|
396 | rc = smenu_entry_create(tbcfg, "C", "c", false, &e3);
|
---|
397 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
398 |
|
---|
399 | f = tbarcfg_smenu_first(tbcfg);
|
---|
400 | PCUT_ASSERT_EQUALS(e1, f);
|
---|
401 |
|
---|
402 | /* Moving the first entry up should have no effect */
|
---|
403 |
|
---|
404 | smenu_entry_move_up(e1);
|
---|
405 |
|
---|
406 | f = tbarcfg_smenu_first(tbcfg);
|
---|
407 | PCUT_ASSERT_EQUALS(e1, f);
|
---|
408 |
|
---|
409 | /* Moving the second entry up should move it to first position */
|
---|
410 |
|
---|
411 | smenu_entry_move_up(e2);
|
---|
412 |
|
---|
413 | f = tbarcfg_smenu_first(tbcfg);
|
---|
414 | PCUT_ASSERT_EQUALS(e2, f);
|
---|
415 |
|
---|
416 | /* Moving the last entry up should move it to second position */
|
---|
417 |
|
---|
418 | smenu_entry_move_up(e3);
|
---|
419 |
|
---|
420 | f = tbarcfg_smenu_first(tbcfg);
|
---|
421 | PCUT_ASSERT_EQUALS(e2, f);
|
---|
422 |
|
---|
423 | f = tbarcfg_smenu_next(f);
|
---|
424 | PCUT_ASSERT_EQUALS(e3, f);
|
---|
425 |
|
---|
426 | f = tbarcfg_smenu_next(f);
|
---|
427 | PCUT_ASSERT_EQUALS(e1, f);
|
---|
428 |
|
---|
429 | tbarcfg_sync(tbcfg);
|
---|
430 | tbarcfg_close(tbcfg);
|
---|
431 |
|
---|
432 | /* Re-open repository */
|
---|
433 |
|
---|
434 | rc = tbarcfg_open(fname, &tbcfg);
|
---|
435 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
436 |
|
---|
437 | /* Check that new order of entries persisted */
|
---|
438 |
|
---|
439 | f = tbarcfg_smenu_first(tbcfg);
|
---|
440 | PCUT_ASSERT_NOT_NULL(f);
|
---|
441 |
|
---|
442 | caption = smenu_entry_get_caption(f);
|
---|
443 | PCUT_ASSERT_STR_EQUALS("B", caption);
|
---|
444 | cmd = smenu_entry_get_cmd(f);
|
---|
445 | PCUT_ASSERT_STR_EQUALS("b", cmd);
|
---|
446 |
|
---|
447 | f = tbarcfg_smenu_next(f);
|
---|
448 | PCUT_ASSERT_NOT_NULL(f);
|
---|
449 |
|
---|
450 | caption = smenu_entry_get_caption(f);
|
---|
451 | PCUT_ASSERT_STR_EQUALS("C", caption);
|
---|
452 | cmd = smenu_entry_get_cmd(f);
|
---|
453 | PCUT_ASSERT_STR_EQUALS("c", cmd);
|
---|
454 |
|
---|
455 | f = tbarcfg_smenu_next(f);
|
---|
456 | PCUT_ASSERT_NOT_NULL(f);
|
---|
457 |
|
---|
458 | caption = smenu_entry_get_caption(f);
|
---|
459 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
460 | cmd = smenu_entry_get_cmd(f);
|
---|
461 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
462 |
|
---|
463 | tbarcfg_close(tbcfg);
|
---|
464 | remove(fname);
|
---|
465 | }
|
---|
466 |
|
---|
467 | /** Move start menu entry down */
|
---|
468 | PCUT_TEST(entry_move_down)
|
---|
469 | {
|
---|
470 | errno_t rc;
|
---|
471 | tbarcfg_t *tbcfg;
|
---|
472 | char fname[L_tmpnam], *p;
|
---|
473 | smenu_entry_t *e1, *e2, *e3;
|
---|
474 | smenu_entry_t *f;
|
---|
475 | const char *caption;
|
---|
476 | const char *cmd;
|
---|
477 |
|
---|
478 | p = tmpnam(fname);
|
---|
479 | PCUT_ASSERT_NOT_NULL(p);
|
---|
480 |
|
---|
481 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
482 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
483 |
|
---|
484 | rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
|
---|
485 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
486 |
|
---|
487 | rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
|
---|
488 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
489 |
|
---|
490 | rc = smenu_entry_create(tbcfg, "C", "c", false, &e3);
|
---|
491 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
492 |
|
---|
493 | f = tbarcfg_smenu_last(tbcfg);
|
---|
494 | PCUT_ASSERT_EQUALS(e3, f);
|
---|
495 |
|
---|
496 | /* Moving the last entry down should have no effect */
|
---|
497 |
|
---|
498 | smenu_entry_move_down(e3);
|
---|
499 |
|
---|
500 | f = tbarcfg_smenu_last(tbcfg);
|
---|
501 | PCUT_ASSERT_EQUALS(e3, f);
|
---|
502 |
|
---|
503 | /* Moving the second entry down should move it to last position */
|
---|
504 |
|
---|
505 | smenu_entry_move_down(e2);
|
---|
506 |
|
---|
507 | f = tbarcfg_smenu_last(tbcfg);
|
---|
508 | PCUT_ASSERT_EQUALS(e2, f);
|
---|
509 |
|
---|
510 | /* Moving the first entry down should move it to second position */
|
---|
511 |
|
---|
512 | smenu_entry_move_down(e1);
|
---|
513 |
|
---|
514 | f = tbarcfg_smenu_last(tbcfg);
|
---|
515 | PCUT_ASSERT_EQUALS(e2, f);
|
---|
516 |
|
---|
517 | f = tbarcfg_smenu_prev(f);
|
---|
518 | PCUT_ASSERT_EQUALS(e1, f);
|
---|
519 |
|
---|
520 | f = tbarcfg_smenu_prev(f);
|
---|
521 | PCUT_ASSERT_EQUALS(e3, f);
|
---|
522 |
|
---|
523 | tbarcfg_sync(tbcfg);
|
---|
524 | tbarcfg_close(tbcfg);
|
---|
525 |
|
---|
526 | /* Re-open repository */
|
---|
527 |
|
---|
528 | rc = tbarcfg_open(fname, &tbcfg);
|
---|
529 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
530 |
|
---|
531 | /* Check that new order of entries persisted */
|
---|
532 |
|
---|
533 | f = tbarcfg_smenu_first(tbcfg);
|
---|
534 | PCUT_ASSERT_NOT_NULL(f);
|
---|
535 |
|
---|
536 | caption = smenu_entry_get_caption(f);
|
---|
537 | PCUT_ASSERT_STR_EQUALS("C", caption);
|
---|
538 | cmd = smenu_entry_get_cmd(f);
|
---|
539 | PCUT_ASSERT_STR_EQUALS("c", cmd);
|
---|
540 |
|
---|
541 | f = tbarcfg_smenu_next(f);
|
---|
542 | PCUT_ASSERT_NOT_NULL(f);
|
---|
543 |
|
---|
544 | caption = smenu_entry_get_caption(f);
|
---|
545 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
546 | cmd = smenu_entry_get_cmd(f);
|
---|
547 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
548 |
|
---|
549 | f = tbarcfg_smenu_next(f);
|
---|
550 | PCUT_ASSERT_NOT_NULL(f);
|
---|
551 |
|
---|
552 | caption = smenu_entry_get_caption(f);
|
---|
553 | PCUT_ASSERT_STR_EQUALS("B", caption);
|
---|
554 | cmd = smenu_entry_get_cmd(f);
|
---|
555 | PCUT_ASSERT_STR_EQUALS("b", cmd);
|
---|
556 |
|
---|
557 | tbarcfg_close(tbcfg);
|
---|
558 | remove(fname);
|
---|
559 | }
|
---|
560 |
|
---|
561 | /** Notifications can be delivered from tbarcfg_notify() to a listener. */
|
---|
562 | PCUT_TEST(notify)
|
---|
563 | {
|
---|
564 | errno_t rc;
|
---|
565 | tbarcfg_listener_t *lst;
|
---|
566 | tbarcfg_test_resp_t test_resp;
|
---|
567 |
|
---|
568 | test_resp.notified = false;
|
---|
569 |
|
---|
570 | printf("create listener resp=%p\n", (void *)&test_resp);
|
---|
571 | rc = tbarcfg_listener_create(TBARCFG_NOTIFY_DEFAULT,
|
---|
572 | test_cb, &test_resp, &lst);
|
---|
573 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
574 |
|
---|
575 | rc = tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT);
|
---|
576 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
577 |
|
---|
578 | PCUT_ASSERT_TRUE(test_resp.notified);
|
---|
579 | tbarcfg_listener_destroy(lst);
|
---|
580 | }
|
---|
581 |
|
---|
582 | static void test_cb(void *arg)
|
---|
583 | {
|
---|
584 | tbarcfg_test_resp_t *resp = (tbarcfg_test_resp_t *)arg;
|
---|
585 |
|
---|
586 | printf("test_cb: executing resp=%p\n", (void *)resp);
|
---|
587 | resp->notified = true;
|
---|
588 | }
|
---|
589 |
|
---|
590 | PCUT_EXPORT(tbarcfg);
|
---|