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 |
{
|
|
9 |
string255 s;
|
|
10 |
s.len = strlen(str);
|
|
11 |
memcpy(s.str, str, s.len + 1);
|
|
12 |
return s;
|
|
13 |
}
|
|
14 |
|
|
15 |
START_TEST(test_strconcat)
|
|
16 |
{
|
|
17 |
string255 t;
|
|
18 |
t = fpcrtl_strconcat(make_string(""), make_string(""));
|
|
19 |
fail_if(strcmp(t.str, ""), "strconcat(\"\", \"\")");
|
|
20 |
|
|
21 |
t = fpcrtl_strconcat(make_string(""), make_string("a"));
|
|
22 |
fail_if(strcmp(t.str, "a"), "strconcat(\"\", \"a\")");
|
|
23 |
|
|
24 |
t = fpcrtl_strconcat(make_string("a"), make_string(""));
|
|
25 |
fail_if(strcmp(t.str, "a"), "strconcat(\"a\", \"\")");
|
|
26 |
|
|
27 |
t = fpcrtl_strconcat(make_string("ab"), make_string(""));
|
|
28 |
fail_if(strcmp(t.str, "ab"), "strconcat(\"ab\", \"\")");
|
|
29 |
|
|
30 |
t = fpcrtl_strconcat(make_string("ab"), make_string("cd"));
|
|
31 |
fail_if(strcmp(t.str, "abcd"), "strconcat(\"ab\", \"cd\")");
|
|
32 |
}
|
|
33 |
END_TEST
|
|
34 |
|
|
35 |
START_TEST (test_strappend)
|
|
36 |
{
|
|
37 |
string255 t;
|
|
38 |
|
|
39 |
t = fpcrtl_strappend(make_string(""), 'c');
|
|
40 |
fail_if(strcmp(t.str, "c"), "strappend(\"\", 'c')");
|
|
41 |
|
|
42 |
t = fpcrtl_strappend(make_string("ab"), 'c');
|
|
43 |
fail_if(strcmp(t.str, "abc"), "strappend(\"ab\", 'c')");
|
|
44 |
}
|
|
45 |
END_TEST
|
|
46 |
|
|
47 |
START_TEST (test_strprepend)
|
|
48 |
{
|
|
49 |
string255 t;
|
|
50 |
|
|
51 |
t = fpcrtl_strprepend('c', make_string(""));
|
|
52 |
fail_if(strcmp(t.str, "c"), "strprepend('c', \"\")");
|
|
53 |
|
|
54 |
t = fpcrtl_strprepend('c', make_string("ab"));
|
|
55 |
fail_if(strcmp(t.str, "cab"), "strprepend('c', \"ab\")");
|
|
56 |
}
|
|
57 |
END_TEST
|
|
58 |
|
|
59 |
START_TEST (test_strcompare)
|
|
60 |
{
|
|
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\")");
|
|
65 |
|
|
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(\"\", ' ')");
|
|
70 |
|
|
71 |
}
|
|
72 |
END_TEST
|
|
73 |
|
|
74 |
Suite* misc_suite(void)
|
|
75 |
{
|
|
76 |
Suite *s = suite_create("misc");
|
|
77 |
|
|
78 |
TCase *tc_core = tcase_create("Core");
|
|
79 |
|
|
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);
|
|
84 |
|
|
85 |
suite_add_tcase(s, tc_core);
|
|
86 |
|
|
87 |
return s;
|
|
88 |
}
|