forked from lc-soft/LCUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_string.c
69 lines (66 loc) · 2.28 KB
/
test_string.c
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <LCUI_Build.h>
#include <LCUI/LCUI.h>
#include "test.h"
#include "libtest.h"
static void test_cmdsplit(void)
{
char **argv;
int argc = 0;
const char *cmd = "\"C:\\Program Files\\WindowsApps\\Test\\app.exe\" "
"--print \"Hello, Wolrd !\"";
const char *results[3] = {
"\"C:\\Program Files\\WindowsApps\\Test\\app.exe\"", "--print",
"\"Hello, Wolrd !\""
};
it_i("executable in command only", cmdsplit(" test.exe ", NULL), 1);
it_i("command with two parameters", cmdsplit(cmd, NULL), 3);
argc = cmdsplit(cmd, &argv);
char messageBuffer[1024];
while (argc-- > 0) {
snprintf(messageBuffer, sizeof(messageBuffer),
"check argv[%d]: check [%s] == [%s]", argc, argv[argc],
results[argc]);
it_s(messageBuffer, argv[argc], results[argc]);
free(argv[argc]);
}
free(argv);
}
void test_strs(void)
{
char **strs = NULL;
strlist_add(&strs, "first-child");
strlist_add(&strs, "last-child");
strlist_add(&strs, "one two");
it_b("check first-child is in the list",
strlist_has(strs, "first-child"), TRUE);
it_b("check last-child is in the list", strlist_has(strs, "last-child"),
TRUE);
it_b("check one is in the list", strlist_has(strs, "one"), TRUE);
it_b("check two is in the list", strlist_has(strs, "two"), TRUE);
it_b("check remove(last_child)", strlist_remove(&strs, "last-child"),
TRUE);
it_b("check remove(first-child", strlist_remove(&strs, "first-child"),
TRUE);
it_b("check remove(one)", strlist_remove(&strs, "one"), TRUE);
it_b("check first-child is removed", strlist_has(strs, "first-child"),
FALSE);
it_b("check one is removed", strlist_has(strs, "one"), FALSE);
it_b("check two is still in the list", strlist_has(strs, "two"), TRUE);
it_i("check strhash(123, \"123\") is consistent", strhash(123, "123"),
strhash(123, "123"));
it_b("check strhash(123, \"123\") != strhash(123, \"312\")",
strhash(123, "123") == strhash(123, "312"), FALSE);
it_b("check strhash(100, \"123\") != strhash(123, \"123\")",
strhash(100, "123") == strhash(123, "123"), FALSE);
it_b("check adding first-child", strlist_add(&strs, "first-child"),
TRUE);
strlist_free(strs);
}
void test_string(void)
{
describe("test cmdsplit", test_cmdsplit);
describe("test strs", test_strs);
}