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 const gboolean ok = parse_csi (NULL, &s, end);
57
58 ck_assert_msg (ok, "failed to parse CSI");
59 ck_assert_str_eq (s, "Rest");
60 }
61 END_TEST
62
63
64
65 START_TEST (test_strip_ctrl_codes)
66 {
67
68 char *s = g_strdup (ESC_STR "]0;~\a" ESC_STR "[30m" ESC_STR "(B" ESC_STR "[m"
69 ESC_STR "]133;A;special_key=1\a$ " ESC_STR "[K" ESC_STR "[?2004h"
70 ESC_STR "[>4;1m" ESC_STR "[=5u" ESC_STR "=" ESC_STR "[?2004l"
71 ESC_STR "[>4;0m" ESC_STR "[=0u" ESC_STR ">" ESC_STR "[?2004h"
72 ESC_STR "[>4;1m" ESC_STR "[=5u" ESC_STR "=" ESC_STR "[?2004l"
73 ESC_STR "[>4;0m" ESC_STR "[=0u" ESC_STR ">" ESC_STR "[?2004h"
74 ESC_STR "[>4;1m" ESC_STR "[=5u" ESC_STR "=");
75
76 char *actual = strip_ctrl_codes (s);
77 const char *expected = "$ ";
78
79 ck_assert_str_eq (actual, expected);
80 g_free (s);
81 }
82 END_TEST
83
84
85
86 int
87 main (void)
88 {
89 TCase *tc_core;
90
91 tc_core = tcase_create ("Core");
92
93 tcase_add_checked_fixture (tc_core, setup, teardown);
94
95
96 tcase_add_test (tc_core, test_parse_csi);
97 tcase_add_test (tc_core, test_strip_ctrl_codes);
98
99
100 return mctest_run_all (tc_core);
101 }
102
103