project_files/hwc/rtl/tests/check_fileio.c
author Wuzzy <Wuzzy2@mail.ru>
Sat, 24 Feb 2018 14:59:35 +0100
changeset 13070 a297e06d1607
parent 10015 4feced261c68
permissions -rw-r--r--
Display score next to team bar in singleplayer challenges
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/fpcrtl.h"
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     6
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     7
typedef struct __TResourceList
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
    Integer count;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    10
    string255 files[500 + 1];
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    11
} TResourceList;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    12
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    13
string255 t = STRINIT("test");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    14
string255 Pathz[1] =
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    15
{ STRINIT("../../") };
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    16
int ptCurrTheme = 0;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    17
string255 cThemeCFGFilename = STRINIT("theme.cfg");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    18
const string255 __str79 = STRINIT("object");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    19
string255 c1 = STRINIT("=");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    20
string255 c2 = STRINIT("\x2c");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    21
string255 c3 = STRINIT("\x2f");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    22
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    23
static string255 make_string(const char* str)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    24
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    25
    string255 s;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    26
    s.len = strlen(str);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    27
    memcpy(s.str, str, s.len + 1);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    28
    return s;
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    29
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    30
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    31
TResourceList readThemeCfg_0()
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
    TResourceList readthemecfg_result;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    34
    string255 s;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    35
    string255 key;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    36
    TextFile f;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    37
    Integer i;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    38
    TResourceList res;
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    39
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    40
    s = _strconcat(_strappend(Pathz[ptCurrTheme], '\x2f'), cThemeCFGFilename);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    41
    //umisc_log(s);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    42
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    43
    fpcrtl_assign(f, s);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    44
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    45
    FileMode = 0;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    46
    fpcrtl_reset(f);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    47
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    48
    res.count = 0;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    49
    while (!(fpcrtl_eof(f)))
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    50
    {
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    51
        fpcrtl_readLnS(f, s);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    52
        if ((fpcrtl_Length(s)) == (0))
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    53
        {
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    54
            continue;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    55
        }
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    56
        if ((s.s[1]) == ('\x3b'))
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    57
        {
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    58
            continue;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    59
        }
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    60
        i = fpcrtl_pos('\x3d', s);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    61
        key = fpcrtl_trim(fpcrtl_copy(s, 1, i - 1));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    62
        fpcrtl_delete(s, 1, i);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    63
        if (_strcompare(key, __str79))
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    64
        {
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    65
            i = fpcrtl_pos('\x2c', s);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    66
            res.files[res.count] = _strconcat(
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    67
                    _strappend(Pathz[ptCurrTheme], '\x2f'),
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    68
                    fpcrtl_trim(fpcrtl_copy(s, 1, i - 1)));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    69
            ++res.count;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    70
            //umisc_log(fpcrtl_trim(fpcrtl_copy(s, 1, i - 1)));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    71
        }
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    72
    }
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    73
    fpcrtl_close(f);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    74
    readthemecfg_result = res;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    75
    return readthemecfg_result;
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    76
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    77
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    78
START_TEST(test_readthemecfg)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    79
    {
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    80
        int i;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    81
        TResourceList result;
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    82
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    83
        printf("-----Entering test readthemecfg-----\n");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    84
        result = readThemeCfg_0();
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    85
        for (i = 0; i < result.count; i++)
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    86
        {
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    87
            printf("%s\n", result.files[i].str);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    88
        }
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    89
        printf("-----Leaving test readthemecfg-----\n");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    90
    }END_TEST
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    91
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    92
Suite* fileio_suite(void)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    93
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    94
    Suite *s = suite_create("fileio");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    95
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    96
    TCase *tc_core = tcase_create("Core");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    97
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    98
    tcase_add_test(tc_core, test_readthemecfg);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    99
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   100
    suite_add_tcase(s, tc_core);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   101
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   102
    return s;
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   103
}