File tests/misc/marks.c changed (mode: 100644) (index 22e6c1b43..accd1a538) |
3 |
3 |
#include <stddef.h> /* NULL */ |
#include <stddef.h> /* NULL */ |
4 |
4 |
#include <string.h> /* strlen() */ |
#include <string.h> /* strlen() */ |
5 |
5 |
|
|
|
6 |
|
#include <test-utils.h> |
|
7 |
|
|
6 |
8 |
#include "../../src/cfg/config.h" |
#include "../../src/cfg/config.h" |
|
9 |
|
#include "../../src/compat/os.h" |
7 |
10 |
#include "../../src/ui/ui.h" |
#include "../../src/ui/ui.h" |
8 |
11 |
#include "../../src/marks.h" |
#include "../../src/marks.h" |
9 |
12 |
|
|
|
13 |
|
static void suggest_cb_no_call(const wchar_t text[], const wchar_t value[], |
|
14 |
|
const char descr[]); |
|
15 |
|
static void suggest_cb_a_lpath(const wchar_t text[], const wchar_t value[], |
|
16 |
|
const char descr[]); |
|
17 |
|
static void suggest_cb_a_testdir(const wchar_t text[], const wchar_t value[], |
|
18 |
|
const char descr[]); |
|
19 |
|
static void suggest_cb_a_testdir_slash(const wchar_t text[], |
|
20 |
|
const wchar_t value[], const char descr[]); |
|
21 |
|
|
|
22 |
|
static int calls; |
|
23 |
|
|
10 |
24 |
SETUP() |
SETUP() |
11 |
25 |
{ |
{ |
12 |
26 |
cfg.slow_fs_list = strdup(""); |
cfg.slow_fs_list = strdup(""); |
|
... |
... |
SETUP() |
14 |
28 |
lwin.column_count = 1; |
lwin.column_count = 1; |
15 |
29 |
rwin.list_pos = 0; |
rwin.list_pos = 0; |
16 |
30 |
rwin.column_count = 1; |
rwin.column_count = 1; |
|
31 |
|
|
|
32 |
|
calls = 0; |
17 |
33 |
} |
} |
18 |
34 |
|
|
19 |
35 |
TEARDOWN() |
TEARDOWN() |
20 |
36 |
{ |
{ |
21 |
37 |
free(cfg.slow_fs_list); |
free(cfg.slow_fs_list); |
22 |
38 |
cfg.slow_fs_list = NULL; |
cfg.slow_fs_list = NULL; |
|
39 |
|
|
|
40 |
|
marks_clear_all(); |
23 |
41 |
} |
} |
24 |
42 |
|
|
25 |
43 |
TEST(unexistent_mark) |
TEST(unexistent_mark) |
|
... |
... |
TEST(sel_marks_are_local) |
82 |
100 |
assert_string_equal("rfile>", mark->file); |
assert_string_equal("rfile>", mark->file); |
83 |
101 |
} |
} |
84 |
102 |
|
|
|
103 |
|
TEST(marks_are_suggested) |
|
104 |
|
{ |
|
105 |
|
view_setup(&lwin); |
|
106 |
|
|
|
107 |
|
/* No marks to suggest. */ |
|
108 |
|
marks_suggest(&lwin, &suggest_cb_no_call, /*local_only=*/0); |
|
109 |
|
assert_int_equal(0, calls); |
|
110 |
|
|
|
111 |
|
/* Adding one mark. */ |
|
112 |
|
marks_set_user(&lwin, 'a', "lpath", "lfile"); |
|
113 |
|
|
|
114 |
|
/* Nothing will be suggested because the only mark isn't local. */ |
|
115 |
|
marks_suggest(&lwin, &suggest_cb_a_lpath, /*local_only=*/1); |
|
116 |
|
assert_int_equal(0, calls); |
|
117 |
|
|
|
118 |
|
/* All marks are suggested and there is only one. */ |
|
119 |
|
marks_suggest(&lwin, &suggest_cb_a_lpath, /*local_only=*/0); |
|
120 |
|
assert_int_equal(1, calls); |
|
121 |
|
|
|
122 |
|
/* Make the mark local. */ |
|
123 |
|
strcpy(lwin.curr_dir, "lpath"); |
|
124 |
|
append_view_entry(&lwin, "lfile"); |
|
125 |
|
|
|
126 |
|
/* Now the mark is suggested as local. */ |
|
127 |
|
marks_suggest(&lwin, &suggest_cb_a_lpath, /*local_only=*/1); |
|
128 |
|
assert_int_equal(2, calls); |
|
129 |
|
|
|
130 |
|
/* And among all marks as well. */ |
|
131 |
|
marks_suggest(&lwin, &suggest_cb_a_lpath, /*local_only=*/0); |
|
132 |
|
assert_int_equal(3, calls); |
|
133 |
|
|
|
134 |
|
view_teardown(&lwin); |
|
135 |
|
} |
|
136 |
|
|
|
137 |
|
TEST(marks_are_suggested_with_trailing_slash) |
|
138 |
|
{ |
|
139 |
|
assert_success(os_chdir(SANDBOX_PATH)); |
|
140 |
|
create_dir("testdir"); |
|
141 |
|
|
|
142 |
|
marks_set_user(&lwin, 'a', "testdir", "somefile"); |
|
143 |
|
marks_suggest(&lwin, &suggest_cb_a_testdir, /*local_only=*/0); |
|
144 |
|
assert_int_equal(1, calls); |
|
145 |
|
|
|
146 |
|
marks_set_user(&lwin, 'a', "testdir", ".."); |
|
147 |
|
marks_suggest(&lwin, &suggest_cb_a_testdir_slash, /*local_only=*/0); |
|
148 |
|
assert_int_equal(2, calls); |
|
149 |
|
|
|
150 |
|
remove_dir("testdir"); |
|
151 |
|
} |
|
152 |
|
|
|
153 |
|
static void |
|
154 |
|
suggest_cb_no_call(const wchar_t text[], const wchar_t value[], |
|
155 |
|
const char descr[]) |
|
156 |
|
{ |
|
157 |
|
assert_fail("Unexpected invocation of marks' callback."); |
|
158 |
|
++calls; |
|
159 |
|
} |
|
160 |
|
|
|
161 |
|
static void |
|
162 |
|
suggest_cb_a_lpath(const wchar_t text[], const wchar_t value[], |
|
163 |
|
const char descr[]) |
|
164 |
|
{ |
|
165 |
|
assert_wstring_equal(L"mark: a", text); |
|
166 |
|
assert_wstring_equal(L"", value); |
|
167 |
|
assert_string_equal("lpath", descr); |
|
168 |
|
++calls; |
|
169 |
|
} |
|
170 |
|
|
|
171 |
|
static void |
|
172 |
|
suggest_cb_a_testdir(const wchar_t text[], const wchar_t value[], |
|
173 |
|
const char descr[]) |
|
174 |
|
{ |
|
175 |
|
assert_wstring_equal(L"mark: a", text); |
|
176 |
|
assert_wstring_equal(L"", value); |
|
177 |
|
assert_string_equal("testdir/somefile", descr); |
|
178 |
|
++calls; |
|
179 |
|
} |
|
180 |
|
|
|
181 |
|
static void |
|
182 |
|
suggest_cb_a_testdir_slash(const wchar_t text[], const wchar_t value[], |
|
183 |
|
const char descr[]) |
|
184 |
|
{ |
|
185 |
|
assert_wstring_equal(L"mark: a", text); |
|
186 |
|
assert_wstring_equal(L"", value); |
|
187 |
|
assert_string_equal("testdir/", descr); |
|
188 |
|
++calls; |
|
189 |
|
} |
|
190 |
|
|
85 |
191 |
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ |
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ |
86 |
192 |
/* vim: set cinoptions+=t0 filetype=c : */ |
/* vim: set cinoptions+=t0 filetype=c : */ |