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 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.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include <pcut/pcut.h>
|
---|
30 | #include <stdlib.h>
|
---|
31 | #include <str.h>
|
---|
32 | #include <uchar.h>
|
---|
33 | #include <ui/accel.h>
|
---|
34 |
|
---|
35 | PCUT_INIT;
|
---|
36 |
|
---|
37 | PCUT_TEST_SUITE(accel);
|
---|
38 |
|
---|
39 | /** ui_accel_process() */
|
---|
40 | PCUT_TEST(process)
|
---|
41 | {
|
---|
42 | errno_t rc;
|
---|
43 | char *buf;
|
---|
44 | char *endptr;
|
---|
45 | char *bp1;
|
---|
46 | char *bp2;
|
---|
47 |
|
---|
48 | /* Cases where one string is produced */
|
---|
49 |
|
---|
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);
|
---|
55 |
|
---|
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);
|
---|
61 |
|
---|
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);
|
---|
67 |
|
---|
68 | /* Three strings are produced (the first is empty) */
|
---|
69 |
|
---|
70 | rc = ui_accel_process("~H~ello", &buf, &endptr);
|
---|
71 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
72 | PCUT_ASSERT_STR_EQUALS("", buf);
|
---|
73 |
|
---|
74 | bp1 = buf + str_size(buf) + 1;
|
---|
75 | PCUT_ASSERT_STR_EQUALS("H", bp1);
|
---|
76 |
|
---|
77 | bp2 = bp1 + str_size(bp1) + 1;
|
---|
78 | PCUT_ASSERT_STR_EQUALS("ello", bp2);
|
---|
79 |
|
---|
80 | PCUT_ASSERT_EQUALS(bp2 + str_size("ello") + 1, endptr);
|
---|
81 | free(buf);
|
---|
82 | }
|
---|
83 |
|
---|
84 | /** ui_accel_get() */
|
---|
85 | PCUT_TEST(get)
|
---|
86 | {
|
---|
87 | char32_t a;
|
---|
88 |
|
---|
89 | a = ui_accel_get("");
|
---|
90 | PCUT_ASSERT_EQUALS('\0', a);
|
---|
91 |
|
---|
92 | a = ui_accel_get("Hello");
|
---|
93 | PCUT_ASSERT_EQUALS('\0', a);
|
---|
94 |
|
---|
95 | a = ui_accel_get("~~");
|
---|
96 | PCUT_ASSERT_EQUALS('\0', a);
|
---|
97 |
|
---|
98 | a = ui_accel_get("~~Hello~~");
|
---|
99 | PCUT_ASSERT_EQUALS('\0', a);
|
---|
100 |
|
---|
101 | a = ui_accel_get("~H~ello");
|
---|
102 | PCUT_ASSERT_EQUALS('h', a);
|
---|
103 |
|
---|
104 | a = ui_accel_get("H~e~llo");
|
---|
105 | PCUT_ASSERT_EQUALS('e', a);
|
---|
106 | }
|
---|
107 |
|
---|
108 | PCUT_EXPORT(accel);
|
---|