project_files/hwc/rtl/tests/check_sysutils.c
author Wuzzy <Wuzzy2@mail.ru>
Thu, 10 Jan 2019 02:50:01 +0100
changeset 14541 181509fe1ae8
parent 10015 4feced261c68
permissions -rw-r--r--
Fix player team ignoring custom team control scheme in campaign/missions
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/sysutils.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
static int is_string_equal(string255 s1, string255 s2)
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
    return (s1.len == s2.len) && (strcmp(s1.str, s2.str) == 0);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    18
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    19
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    20
START_TEST (test_trim)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    21
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    22
    string255 t;
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_trim(make_string(""));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    25
    fail_if(strcmp(t.str, ""), "trim(\"\")");
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_trim(make_string("ab"));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    28
    fail_if(strcmp(t.str, "ab"), "trim(\"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_trim(make_string(" "));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    31
    fail_if(strcmp(t.str, ""), "trim(\" \")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    32
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    33
    t = fpcrtl_trim(make_string("   "));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    34
    fail_if(strcmp(t.str, ""), "trim(\"   \")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    35
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    36
    t = fpcrtl_trim(make_string(" ab"));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    37
    fail_if(strcmp(t.str, "ab"), "trim(\" ab\")");
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_trim(make_string("ab  "));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    40
    fail_if(strcmp(t.str, "ab"), "trim(\"ab  \")");
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_trim(make_string("  ab  "));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    43
    fail_if(strcmp(t.str, "ab"), "trim(\"  ab  \")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    44
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    45
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    46
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    47
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    48
START_TEST (test_strToInt)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    49
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    50
    fail_unless(fpcrtl_strToInt(make_string("123")) == 123, "strToInt(\"123\")");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    51
    fail_unless(fpcrtl_strToInt(make_string("0")) == 0, "strToInt(\"0\")");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    52
    fail_unless(fpcrtl_strToInt(make_string("-123")) == -123, "strToInt(\"-123\")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    53
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    54
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    55
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    56
START_TEST (test_extractFileName)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    57
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    58
    fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("abc")), make_string("abc")), "extractFileName(\"abc\")");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    59
    fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("a:abc")), make_string("abc")), "extractFileName(\"a:abc\")");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    60
    fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("/abc")), make_string("abc")), "extractFileName(\"/abc\")");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    61
    fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("\\abc")), make_string("abc")), "extractFileName(\"\\abc\")");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    62
    fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("/usr/bin/abc")), make_string("abc")), "extractFileName(\"/usr/bin/abc\")");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    63
    fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("c:\\def\\abc")), make_string("abc")), "extractFileName(\"c:\\def\\abc\")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    64
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    65
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    66
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    67
Suite* sysutils_suite(void)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    68
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    69
    Suite *s = suite_create("sysutils");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    70
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    71
    TCase *tc_core = tcase_create("Core");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    72
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    73
    tcase_add_test(tc_core, test_trim);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    74
    tcase_add_test(tc_core, test_strToInt);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    75
    tcase_add_test(tc_core, test_extractFileName);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    76
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    77
    suite_add_tcase(s, tc_core);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    78
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    79
    return s;
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    80
}