2 * Copyright (c) 2022 Jiri Svoboda
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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>
37 PCUT_TEST_SUITE(accel
);
39 /** ui_accel_process() */
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
);
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
);
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
);
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
);
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
);