This source file includes following definitions.
- 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 #define TEST_SUITE_NAME "/src/file_history"
24
25 #include "tests/mctest.h"
26
27 #include "src/file_history.c"
28
29
30
31 START_TEST (test_file_history_parse_entry)
32 {
33 GList *file_list = NULL;
34
35 const char *mock_entries[] = {
36 "/home/codespace/tmp/foo\n", "\n", "bar quux 2;0;5\n", "ba\\nz 1;0;5\n", "",
37 };
38 const size_t entries_count = G_N_ELEMENTS (mock_entries);
39
40 for (size_t i = 0; i < entries_count; i++)
41 file_history_parse_entry (mock_entries[i], &file_list);
42
43 ck_assert_uint_eq (g_list_length (file_list), 2);
44
45 const file_history_data_t *e1 = g_list_nth_data (file_list, 0);
46 const file_history_data_t *e2 = g_list_nth_data (file_list, 1);
47
48 ck_assert_str_eq (e1->file_name, "ba\nz");
49 ck_assert_str_eq (e2->file_name, "bar quux");
50
51 g_list_free_full (file_list, file_history_free_item);
52 }
53 END_TEST
54
55
56
57 START_TEST (test_file_history_write_entry)
58 {
59 const file_history_data_t fhd = {
60 .file_name = g_strdup ("ba\nz"),
61 .file_pos = g_strdup ("1;0;5"),
62 };
63
64 GString *s = g_string_new ("");
65 file_history_write_entry (&fhd, s);
66
67 ck_assert_str_eq (s->str, "ba\\nz 1;0;5");
68
69 g_string_free (s, TRUE);
70 }
71 END_TEST
72
73
74 int
75 main (void)
76 {
77 TCase *tc_core;
78
79 tc_core = tcase_create ("Core");
80
81
82 tcase_add_test (tc_core, test_file_history_parse_entry);
83 tcase_add_test (tc_core, test_file_history_write_entry);
84
85
86 return mctest_run_all (tc_core);
87 }
88
89