This source file includes following definitions.
- setup
- teardown
- START_TEST
- START_TEST
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #define TEST_SUITE_NAME "/lib/terminal"
27
28 #include "tests/mctest.h"
29
30 #include <string.h>
31
32 #include "lib/global.h"
33 #include "lib/terminal.h"
34 #include "lib/strutil.h"
35
36
37
38 static void
39 setup (void)
40 {
41 str_init_strings (NULL);
42 }
43
44 static void
45 teardown (void)
46 {
47 str_uninit_strings ();
48 }
49
50
51
52 START_TEST (test_parse_csi)
53 {
54 const char *s = &"\x1b[=5uRest"[2];
55 const char *end = s + strlen (s);
56 gboolean ok = parse_csi (NULL, &s, end);
57 ck_assert_msg (ok, "failed to parse CSI");
58 ck_assert_str_eq (s, "Rest");
59 }
60 END_TEST
61
62
63
64 START_TEST (test_strip_ctrl_codes)
65 {
66 char *s = strdup (
67 "\033]0;~\a\033[30m\033(B\033[m\033]133;A;special_key=1\a$ "
68 "\033[K\033[?2004h\033[>4;1m\033[=5u\033=\033[?2004l\033[>4;0m\033[=0u\033>\033[?2004h"
69 "\033[>4;1m\033[=5u\033=\033[?2004l\033[>4;0m\033[=0u\033>\033[?2004h\033[>4;1m\033[=5u"
70 "\033=");
71 char *actual = strip_ctrl_codes (s);
72 const char *expected = "$ ";
73 ck_assert_str_eq (actual, expected);
74 free (s);
75 }
76 END_TEST
77
78
79
80 int
81 main (void)
82 {
83 TCase *tc_core;
84
85 tc_core = tcase_create ("Core");
86
87 tcase_add_checked_fixture (tc_core, setup, teardown);
88
89
90 tcase_add_test (tc_core, test_parse_csi);
91 tcase_add_test (tc_core, test_strip_ctrl_codes);
92
93
94 return mctest_run_all (tc_core);
95 }
96
97