project_files/hwc/rtl/tests/check_misc.c
author antonc27 <antonc27@mail.ru>
Thu, 10 Sep 2015 01:31:52 +0200
branchios-revival
changeset 11147 f9c460720e02
parent 10015 4feced261c68
permissions -rw-r--r--
- First attempt to fix crashes on loading 'Styles'
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     1
#include <check.h>
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     2
#include <stdlib.h>
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     3
#include <stdio.h>
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     4
#include "check_check.h"
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     5
#include "../src/misc.h"
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     6
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     7
static string255 make_string(const char* str)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     8
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
     9
    string255 s;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    10
    s.len = strlen(str);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    11
    memcpy(s.str, str, s.len + 1);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    12
    return s;
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    13
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    14
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    15
START_TEST(test_strconcat)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    16
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    17
    string255 t;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    18
    t = fpcrtl_strconcat(make_string(""), make_string(""));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    19
    fail_if(strcmp(t.str, ""), "strconcat(\"\", \"\")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    20
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    21
    t = fpcrtl_strconcat(make_string(""), make_string("a"));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    22
    fail_if(strcmp(t.str, "a"), "strconcat(\"\", \"a\")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    23
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    24
    t = fpcrtl_strconcat(make_string("a"), make_string(""));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    25
    fail_if(strcmp(t.str, "a"), "strconcat(\"a\", \"\")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    26
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    27
    t = fpcrtl_strconcat(make_string("ab"), make_string(""));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    28
    fail_if(strcmp(t.str, "ab"), "strconcat(\"ab\", \"\")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    29
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    30
    t = fpcrtl_strconcat(make_string("ab"), make_string("cd"));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    31
    fail_if(strcmp(t.str, "abcd"), "strconcat(\"ab\", \"cd\")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    32
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    33
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    34
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    35
START_TEST (test_strappend)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    36
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    37
    string255 t;
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    38
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    39
    t = fpcrtl_strappend(make_string(""), 'c');
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    40
    fail_if(strcmp(t.str, "c"), "strappend(\"\", 'c')");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    41
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    42
    t = fpcrtl_strappend(make_string("ab"), 'c');
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    43
    fail_if(strcmp(t.str, "abc"), "strappend(\"ab\", 'c')");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    44
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    45
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    46
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    47
START_TEST (test_strprepend)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    48
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    49
    string255 t;
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    50
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    51
    t = fpcrtl_strprepend('c', make_string(""));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    52
    fail_if(strcmp(t.str, "c"), "strprepend('c', \"\")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    53
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    54
    t = fpcrtl_strprepend('c', make_string("ab"));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    55
    fail_if(strcmp(t.str, "cab"), "strprepend('c', \"ab\")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    56
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    57
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    58
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    59
START_TEST (test_strcompare)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    60
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    61
    fail_unless(fpcrtl_strcompare(make_string(""), make_string("")), "strcompare(\"\", \"\")");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    62
    fail_unless(fpcrtl_strcompare(make_string("a"), make_string("a")), "strcompare(\"a\", \"a\"");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    63
    fail_unless(!fpcrtl_strcompare(make_string("a"), make_string("b")), "strcompare(\"a\", \"b\")");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    64
    fail_unless(!fpcrtl_strcompare(make_string("a"), make_string("ab")), "strcompare(\"a\", \"ab\")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    65
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    66
    fail_unless(fpcrtl_strcomparec(make_string(" "), ' '), "strcomparec(\" \", ' ')");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    67
    fail_unless(fpcrtl_strcomparec(make_string("a"), 'a'), "strcomparec(\"a\", 'a')");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    68
    fail_unless(!fpcrtl_strcomparec(make_string("  "), ' '), "strcomparec(\"  \", ' '");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    69
    fail_unless(!fpcrtl_strcomparec(make_string(""), ' '), "strcomparec(\"\", ' ')");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    70
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    71
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    72
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    73
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    74
Suite* misc_suite(void)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    75
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    76
    Suite *s = suite_create("misc");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    77
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    78
    TCase *tc_core = tcase_create("Core");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    79
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    80
    tcase_add_test(tc_core, test_strconcat);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    81
    tcase_add_test(tc_core, test_strappend);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    82
    tcase_add_test(tc_core, test_strprepend);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    83
    tcase_add_test(tc_core, test_strcompare);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    84
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    85
    suite_add_tcase(s, tc_core);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    86
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    87
    return s;
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    88
}