7983
|
1 |
#include <check.h>
|
|
2 |
#include <stdlib.h>
|
|
3 |
#include <stdio.h>
|
|
4 |
#include "check_check.h"
|
|
5 |
#include "../src/sysutils.h"
|
|
6 |
|
|
7 |
static string255 make_string(const char* str)
|
|
8 |
{
|
|
9 |
string255 s;
|
|
10 |
s.len = strlen(str);
|
|
11 |
memcpy(s.str, str, s.len + 1);
|
|
12 |
return s;
|
|
13 |
}
|
|
14 |
|
|
15 |
static int is_string_equal(string255 s1, string255 s2)
|
|
16 |
{
|
|
17 |
return (s1.len == s2.len) && (strcmp(s1.str, s2.str) == 0);
|
|
18 |
}
|
|
19 |
|
|
20 |
START_TEST (test_trim)
|
|
21 |
{
|
|
22 |
string255 t;
|
|
23 |
|
|
24 |
t = fpcrtl_trim(make_string(""));
|
|
25 |
fail_if(strcmp(t.str, ""), "trim(\"\")");
|
|
26 |
|
|
27 |
t = fpcrtl_trim(make_string("ab"));
|
|
28 |
fail_if(strcmp(t.str, "ab"), "trim(\"ab\")");
|
|
29 |
|
|
30 |
t = fpcrtl_trim(make_string(" "));
|
|
31 |
fail_if(strcmp(t.str, ""), "trim(\" \")");
|
|
32 |
|
|
33 |
t = fpcrtl_trim(make_string(" "));
|
|
34 |
fail_if(strcmp(t.str, ""), "trim(\" \")");
|
|
35 |
|
|
36 |
t = fpcrtl_trim(make_string(" ab"));
|
|
37 |
fail_if(strcmp(t.str, "ab"), "trim(\" ab\")");
|
|
38 |
|
|
39 |
t = fpcrtl_trim(make_string("ab "));
|
|
40 |
fail_if(strcmp(t.str, "ab"), "trim(\"ab \")");
|
|
41 |
|
|
42 |
t = fpcrtl_trim(make_string(" ab "));
|
|
43 |
fail_if(strcmp(t.str, "ab"), "trim(\" ab \")");
|
|
44 |
|
|
45 |
}
|
|
46 |
END_TEST
|
|
47 |
|
|
48 |
START_TEST (test_strToInt)
|
|
49 |
{
|
|
50 |
fail_unless(fpcrtl_strToInt(make_string("123")) == 123, "strToInt(\"123\")");
|
|
51 |
fail_unless(fpcrtl_strToInt(make_string("0")) == 0, "strToInt(\"0\")");
|
|
52 |
fail_unless(fpcrtl_strToInt(make_string("-123")) == -123, "strToInt(\"-123\")");
|
|
53 |
}
|
|
54 |
END_TEST
|
|
55 |
|
|
56 |
START_TEST (test_extractFileName)
|
|
57 |
{
|
|
58 |
fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("abc")), make_string("abc")), "extractFileName(\"abc\")");
|
|
59 |
fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("a:abc")), make_string("abc")), "extractFileName(\"a:abc\")");
|
|
60 |
fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("/abc")), make_string("abc")), "extractFileName(\"/abc\")");
|
|
61 |
fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("\\abc")), make_string("abc")), "extractFileName(\"\\abc\")");
|
|
62 |
fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("/usr/bin/abc")), make_string("abc")), "extractFileName(\"/usr/bin/abc\")");
|
|
63 |
fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("c:\\def\\abc")), make_string("abc")), "extractFileName(\"c:\\def\\abc\")");
|
|
64 |
}
|
|
65 |
END_TEST
|
|
66 |
|
|
67 |
Suite* sysutils_suite(void)
|
|
68 |
{
|
|
69 |
Suite *s = suite_create("sysutils");
|
|
70 |
|
|
71 |
TCase *tc_core = tcase_create("Core");
|
|
72 |
|
|
73 |
tcase_add_test(tc_core, test_trim);
|
|
74 |
tcase_add_test(tc_core, test_strToInt);
|
|
75 |
tcase_add_test(tc_core, test_extractFileName);
|
|
76 |
|
|
77 |
suite_add_tcase(s, tc_core);
|
|
78 |
|
|
79 |
return s;
|
|
80 |
}
|