7983
|
1 |
#include <check.h>
|
|
2 |
#include <stdlib.h>
|
|
3 |
#include <stdio.h>
|
|
4 |
#include "check_check.h"
|
|
5 |
#include "../src/misc.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 |
START_TEST(test_strconcat)
|
|
16 |
{
|
10015
|
17 |
string255 t;
|
|
18 |
t = fpcrtl_strconcat(make_string(""), make_string(""));
|
|
19 |
fail_if(strcmp(t.str, ""), "strconcat(\"\", \"\")");
|
7983
|
20 |
|
10015
|
21 |
t = fpcrtl_strconcat(make_string(""), make_string("a"));
|
|
22 |
fail_if(strcmp(t.str, "a"), "strconcat(\"\", \"a\")");
|
7983
|
23 |
|
10015
|
24 |
t = fpcrtl_strconcat(make_string("a"), make_string(""));
|
|
25 |
fail_if(strcmp(t.str, "a"), "strconcat(\"a\", \"\")");
|
7983
|
26 |
|
10015
|
27 |
t = fpcrtl_strconcat(make_string("ab"), make_string(""));
|
|
28 |
fail_if(strcmp(t.str, "ab"), "strconcat(\"ab\", \"\")");
|
7983
|
29 |
|
10015
|
30 |
t = fpcrtl_strconcat(make_string("ab"), make_string("cd"));
|
|
31 |
fail_if(strcmp(t.str, "abcd"), "strconcat(\"ab\", \"cd\")");
|
7983
|
32 |
}
|
|
33 |
END_TEST
|
|
34 |
|
|
35 |
START_TEST (test_strappend)
|
|
36 |
{
|
10015
|
37 |
string255 t;
|
7983
|
38 |
|
10015
|
39 |
t = fpcrtl_strappend(make_string(""), 'c');
|
|
40 |
fail_if(strcmp(t.str, "c"), "strappend(\"\", 'c')");
|
7983
|
41 |
|
10015
|
42 |
t = fpcrtl_strappend(make_string("ab"), 'c');
|
|
43 |
fail_if(strcmp(t.str, "abc"), "strappend(\"ab\", 'c')");
|
7983
|
44 |
}
|
|
45 |
END_TEST
|
|
46 |
|
|
47 |
START_TEST (test_strprepend)
|
|
48 |
{
|
10015
|
49 |
string255 t;
|
7983
|
50 |
|
10015
|
51 |
t = fpcrtl_strprepend('c', make_string(""));
|
|
52 |
fail_if(strcmp(t.str, "c"), "strprepend('c', \"\")");
|
7983
|
53 |
|
10015
|
54 |
t = fpcrtl_strprepend('c', make_string("ab"));
|
|
55 |
fail_if(strcmp(t.str, "cab"), "strprepend('c', \"ab\")");
|
7983
|
56 |
}
|
|
57 |
END_TEST
|
|
58 |
|
|
59 |
START_TEST (test_strcompare)
|
|
60 |
{
|
10015
|
61 |
fail_unless(fpcrtl_strcompare(make_string(""), make_string("")), "strcompare(\"\", \"\")");
|
|
62 |
fail_unless(fpcrtl_strcompare(make_string("a"), make_string("a")), "strcompare(\"a\", \"a\"");
|
|
63 |
fail_unless(!fpcrtl_strcompare(make_string("a"), make_string("b")), "strcompare(\"a\", \"b\")");
|
|
64 |
fail_unless(!fpcrtl_strcompare(make_string("a"), make_string("ab")), "strcompare(\"a\", \"ab\")");
|
7983
|
65 |
|
10015
|
66 |
fail_unless(fpcrtl_strcomparec(make_string(" "), ' '), "strcomparec(\" \", ' ')");
|
|
67 |
fail_unless(fpcrtl_strcomparec(make_string("a"), 'a'), "strcomparec(\"a\", 'a')");
|
|
68 |
fail_unless(!fpcrtl_strcomparec(make_string(" "), ' '), "strcomparec(\" \", ' '");
|
|
69 |
fail_unless(!fpcrtl_strcomparec(make_string(""), ' '), "strcomparec(\"\", ' ')");
|
7983
|
70 |
|
|
71 |
}
|
|
72 |
END_TEST
|
|
73 |
|
|
74 |
Suite* misc_suite(void)
|
|
75 |
{
|
10015
|
76 |
Suite *s = suite_create("misc");
|
7983
|
77 |
|
10015
|
78 |
TCase *tc_core = tcase_create("Core");
|
7983
|
79 |
|
10015
|
80 |
tcase_add_test(tc_core, test_strconcat);
|
|
81 |
tcase_add_test(tc_core, test_strappend);
|
|
82 |
tcase_add_test(tc_core, test_strprepend);
|
|
83 |
tcase_add_test(tc_core, test_strcompare);
|
7983
|
84 |
|
10015
|
85 |
suite_add_tcase(s, tc_core);
|
7983
|
86 |
|
10015
|
87 |
return s;
|
7983
|
88 |
}
|