Editor needs to hide cursor when menu bar is activated
[helenos.git] / uspace / lib / ui / test / accel.c
blob650c1394ad2ff51ede6151343781b25136bfe87b
1 /*
2 * Copyright (c) 2022 Jiri Svoboda
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
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 INTvvhhzccgggrERRUPTION) 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.
29 #include <pcut/pcut.h>
30 #include <stdlib.h>
31 #include <str.h>
32 #include <uchar.h>
33 #include <ui/accel.h>
35 PCUT_INIT;
37 PCUT_TEST_SUITE(accel);
39 /** ui_accel_process() */
40 PCUT_TEST(process)
42 errno_t rc;
43 char *buf;
44 char *endptr;
45 char *bp1;
46 char *bp2;
48 /* Cases where one string is produced */
50 rc = ui_accel_process("", &buf, &endptr);
51 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
52 PCUT_ASSERT_STR_EQUALS("", buf);
53 PCUT_ASSERT_EQUALS(buf + 1, endptr);
54 free(buf);
56 rc = ui_accel_process("Hello", &buf, &endptr);
57 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
58 PCUT_ASSERT_STR_EQUALS("Hello", buf);
59 PCUT_ASSERT_EQUALS(buf + str_size("Hello") + 1, endptr);
60 free(buf);
62 rc = ui_accel_process("~~Hello~~", &buf, &endptr);
63 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
64 PCUT_ASSERT_STR_EQUALS("~Hello~", buf);
65 PCUT_ASSERT_EQUALS(buf + str_size("~Hello~") + 1, endptr);
66 free(buf);
68 /* Three strings are produced (the first is empty) */
70 rc = ui_accel_process("~H~ello", &buf, &endptr);
71 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
72 PCUT_ASSERT_STR_EQUALS("", buf);
74 bp1 = buf + str_size(buf) + 1;
75 PCUT_ASSERT_STR_EQUALS("H", bp1);
77 bp2 = bp1 + str_size(bp1) + 1;
78 PCUT_ASSERT_STR_EQUALS("ello", bp2);
80 PCUT_ASSERT_EQUALS(bp2 + str_size("ello") + 1, endptr);
81 free(buf);
84 /** ui_accel_get() */
85 PCUT_TEST(get)
87 char32_t a;
89 a = ui_accel_get("");
90 PCUT_ASSERT_EQUALS('\0', a);
92 a = ui_accel_get("Hello");
93 PCUT_ASSERT_EQUALS('\0', a);
95 a = ui_accel_get("~~");
96 PCUT_ASSERT_EQUALS('\0', a);
98 a = ui_accel_get("~~Hello~~");
99 PCUT_ASSERT_EQUALS('\0', a);
101 a = ui_accel_get("~H~ello");
102 PCUT_ASSERT_EQUALS('h', a);
104 a = ui_accel_get("H~e~llo");
105 PCUT_ASSERT_EQUALS('e', a);
108 PCUT_EXPORT(accel);