winprefs v0.3.2
A registry exporter for programmers.
Loading...
Searching...
No Matches
test_shell.c
1#include "io.h"
2#include "shell.h"
3
4static void test_escape_returns_null_on_null_input_or_zero_chars(void **state) {
5 (void)state;
6 assert_null(escape_for_batch(nullptr, 10));
7 assert_null(escape_for_batch(L"input", 0));
8}
9
10static void test_escape_handles_special_characters(void **state) {
11 (void)state;
12 wchar_t *out = escape_for_batch(L"%VAR%", 5);
13 assert_memory_equal(L"%%VAR%%", out, 7);
14 free(out);
15
16 out = escape_for_batch(L"\"VAR\"", 5);
17 assert_memory_equal(L"\"\"VAR\"\"", out, 7);
18 free(out);
19}
20
21static void test_escape_handles_reg_multi_sz(void **state) {
22 (void)state;
23 wchar_t input[] = {L'a', L'\0', L'b', L'\0', L'c'};
24 wchar_t *out = escape_for_batch(input, 5);
25 assert_memory_equal(L"a\\0b\\0c", out, 9);
26 free(out);
27}
28
29static void test_escape_returns_same_when_escaping_unnecessary(void **state) {
30 (void)state;
31 wchar_t *out = escape_for_batch(L"abcdef", 6);
32 assert_memory_equal(L"abcdef", out, 6);
33 free(out);
34}
35
36const struct CMUnitTest shell_tests[] = {
37 cmocka_unit_test(test_escape_handles_reg_multi_sz),
38 cmocka_unit_test(test_escape_handles_special_characters),
39 cmocka_unit_test(test_escape_returns_null_on_null_input_or_zero_chars),
40 cmocka_unit_test(test_escape_returns_same_when_escaping_unnecessary),
41};
42
43int main(int argc, char *argv[]) {
44 (void)argc;
45 (void)argv;
46 return cmocka_run_group_tests(shell_tests, nullptr, nullptr);
47}