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 |
{
|
10015
|
9 |
string255 s;
|
|
10 |
s.len = strlen(str);
|
|
11 |
memcpy(s.str, str, s.len + 1);
|
|
12 |
return s;
|
7983
|
13 |
}
|
|
14 |
|
|
15 |
static int is_string_equal(string255 s1, string255 s2)
|
|
16 |
{
|
10015
|
17 |
return (s1.len == s2.len) && (strcmp(s1.str, s2.str) == 0);
|
7983
|
18 |
}
|
|
19 |
|
|
20 |
START_TEST (test_trim)
|
|
21 |
{
|
10015
|
22 |
string255 t;
|
7983
|
23 |
|
10015
|
24 |
t = fpcrtl_trim(make_string(""));
|
|
25 |
fail_if(strcmp(t.str, ""), "trim(\"\")");
|
7983
|
26 |
|
10015
|
27 |
t = fpcrtl_trim(make_string("ab"));
|
|
28 |
fail_if(strcmp(t.str, "ab"), "trim(\"ab\")");
|
7983
|
29 |
|
10015
|
30 |
t = fpcrtl_trim(make_string(" "));
|
|
31 |
fail_if(strcmp(t.str, ""), "trim(\" \")");
|
7983
|
32 |
|
10015
|
33 |
t = fpcrtl_trim(make_string(" "));
|
|
34 |
fail_if(strcmp(t.str, ""), "trim(\" \")");
|
7983
|
35 |
|
10015
|
36 |
t = fpcrtl_trim(make_string(" ab"));
|
|
37 |
fail_if(strcmp(t.str, "ab"), "trim(\" ab\")");
|
7983
|
38 |
|
10015
|
39 |
t = fpcrtl_trim(make_string("ab "));
|
|
40 |
fail_if(strcmp(t.str, "ab"), "trim(\"ab \")");
|
7983
|
41 |
|
10015
|
42 |
t = fpcrtl_trim(make_string(" ab "));
|
|
43 |
fail_if(strcmp(t.str, "ab"), "trim(\" ab \")");
|
7983
|
44 |
|
|
45 |
}
|
|
46 |
END_TEST
|
|
47 |
|
|
48 |
START_TEST (test_strToInt)
|
|
49 |
{
|
10015
|
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\")");
|
7983
|
53 |
}
|
|
54 |
END_TEST
|
|
55 |
|
|
56 |
START_TEST (test_extractFileName)
|
|
57 |
{
|
10015
|
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\")");
|
7983
|
64 |
}
|
|
65 |
END_TEST
|
|
66 |
|
|
67 |
Suite* sysutils_suite(void)
|
|
68 |
{
|
10015
|
69 |
Suite *s = suite_create("sysutils");
|
7983
|
70 |
|
10015
|
71 |
TCase *tc_core = tcase_create("Core");
|
7983
|
72 |
|
10015
|
73 |
tcase_add_test(tc_core, test_trim);
|
|
74 |
tcase_add_test(tc_core, test_strToInt);
|
|
75 |
tcase_add_test(tc_core, test_extractFileName);
|
7983
|
76 |
|
10015
|
77 |
suite_add_tcase(s, tc_core);
|
7983
|
78 |
|
10015
|
79 |
return s;
|
7983
|
80 |
}
|