project_files/hwc/rtl/tests/check_system.c
author Wuzzy <Wuzzy2@mail.ru>
Fri, 09 Nov 2018 16:28:23 +0100
changeset 14206 801dc57371c3
parent 10015 4feced261c68
permissions -rw-r--r--
Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
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/system.h"
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     6
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     7
void check_string(string255 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
    fail_unless(strlen(str.str) == str.len, "String internal inconsistency error");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    10
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    11
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    12
static string255 make_string(const char* str)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    13
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    14
    string255 s;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    15
    s.len = strlen(str);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    16
    memcpy(s.str, str, s.len + 1);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    17
    return s;
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_copy)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    21
    {
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    22
        string255 s = STRINIT("1234567");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    23
        string255 t;
7983
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
        t = fpcrtl_copy(s, 1, 1);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    26
        fail_if(strcmp(t.str, "1"), "Test copy fail 1");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    27
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    28
        t = fpcrtl_copy(s, 7, 1);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    29
        fail_if(strcmp(t.str, "7"), "Test copy fail 2");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    30
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    31
        t = fpcrtl_copy(s, 8, 1);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    32
        fail_if(t.len != 0, "Test copy fail 3");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    33
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    34
        t = fpcrtl_copy(s, 8, 100);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    35
        fail_if(t.len != 0, "Test copy fail 4");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    36
        check_string(t);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    37
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    38
        t = fpcrtl_copy(s, 0, 100);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    39
        fail_if(strcmp(t.str, "1234567"), "Test copy fail 5");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    40
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    41
        t = fpcrtl_copy(s, 0, 5);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    42
        fail_if(strcmp(t.str, "12345"), "Test copy fail 6");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    43
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    44
        t = fpcrtl_copy(s, 4, 100);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    45
        fail_if(strcmp(t.str, "4567"), "Test copy fail 7");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    46
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    47
        t = fpcrtl_copy(s, 4, 2);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    48
        fail_if(strcmp(t.str, "45"), "Test copy fail 8");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    49
    }END_TEST
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    50
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    51
START_TEST (test_delete)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    52
    {
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    53
        string255 s = STRINIT("1234567");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    54
        string255 s2 = STRINIT("1234567");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    55
        string255 s3 = STRINIT("1234567");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    56
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    57
        fpcrtl_delete(s, 0, 10);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    58
        fail_if(strcmp(s.str, "1234567"), "delete(\"1234567\", 0, 10)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    59
        check_string(s);
7983
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
        fpcrtl_delete(s, 1, 1);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    62
        fail_if(strcmp(s.str, "234567"), "delete(\"1234567\", 1, 1)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    63
        check_string(s);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    64
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    65
        fpcrtl_delete(s, 1, 100);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    66
        fail_if(strcmp(s.str, ""), "delete(\"234567\", 1, 100)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    67
        check_string(s);
7983
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
        fpcrtl_delete(s2, 3, 2);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    70
        fail_if(strcmp(s2.str, "12567"), "delete(\"1234567\", 3, 2)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    71
        check_string(s2);
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
        fpcrtl_delete(s3, 3, 100);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    74
        fail_if(strcmp(s3.str, "12"), "delete(\"1234567\", 3, 100)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    75
        check_string(s3);
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
    }
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    78
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    79
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    80
START_TEST (test_FloatToStr)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    81
    {
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    82
        double s = 1.2345;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    83
        string255 t = fpcrtl_floatToStr(s);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    84
        printf("-----Entering test floatToStr-----\n");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    85
        printf("FloatToStr(%f) = %s\n", s, t.str);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    86
        printf("-----Leaving test floatToStr-----\n");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    87
    }
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    88
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    89
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    90
START_TEST (test_random)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    91
    {
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    92
        fpcrtl_randomize();
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    93
        printf("-----Entering test random-----\n");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    94
        printf("random(5000) = %d\n", fpcrtl_random(5000));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    95
        printf("random(1) = %d\n", fpcrtl_random(1));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    96
        printf("random(2) = %d\n", fpcrtl_random(2));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    97
        printf("-----Leaving test random-----\n");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    98
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
    99
    }
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   100
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   101
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   102
START_TEST (test_posS)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   103
    {
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   104
        string255 substr1 = STRINIT("123");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   105
        string255 str1 = STRINIT("12345");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   106
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   107
        string255 substr2 = STRINIT("45");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   108
        string255 str2 = STRINIT("12345");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   109
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   110
        string255 substr3 = STRINIT("");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   111
        string255 str3 = STRINIT("12345");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   112
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   113
        string255 substr4 = STRINIT("123");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   114
        string255 str4 = STRINIT("");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   115
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   116
        string255 substr5 = STRINIT("123");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   117
        string255 str5 = STRINIT("456");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   118
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   119
        fail_unless(fpcrtl_posS(substr1, str1) == 1, "pos(123, 12345)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   120
        fail_unless(fpcrtl_posS(substr2, str2) == 4, "pos(45, 12345)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   121
        fail_unless(fpcrtl_posS(substr3, str3) == 0, "pos(, 12345)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   122
        fail_unless(fpcrtl_posS(substr4, str4) == 0, "pos(123, )");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   123
        fail_unless(fpcrtl_posS(substr5, str5) == 0, "pos(123, 456)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   124
    }
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   125
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   126
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   127
START_TEST (test_trunc)
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   128
    {
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   129
          fail_unless(fpcrtl_trunc(123.456) == 123, "trunc(123.456)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   130
          fail_unless(fpcrtl_trunc(-123.456) == -123, "trunc(-123.456)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   131
          fail_unless(fpcrtl_trunc(12.3456) == 12, "trunc(12.3456)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   132
          fail_unless(fpcrtl_trunc(-12.3456) == -12, "trunc(-12.3456)");
14206
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   133
          fail_unless(fpcrtl_trunc(0.3) == 0, "trunc(0.3)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   134
          fail_unless(fpcrtl_trunc(0.5) == 0, "trunc(0.5)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   135
          fail_unless(fpcrtl_trunc(99.9999999) == 99, "trunc(99.9999999)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   136
          fail_unless(fpcrtl_trunc(0x01000000.0) == 0x01000000, "trunc(0x01000000.0)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   137
          fail_unless(fpcrtl_trunc(0x01000001.0) == 0x01000001, "trunc(0x01000001.0)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   138
          fail_unless(fpcrtl_trunc(0x02000000.0) == 0x02000000, "trunc(0x02000000.0)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   139
          fail_unless(fpcrtl_trunc(0x04000000.0) == 0x04000000, "trunc(0x04000000.0)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   140
          fail_unless(fpcrtl_trunc(0x08000000.0) == 0x08000000, "trunc(0x08000000.0)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   141
          fail_unless(fpcrtl_trunc(0x10000000.0) == 0x10000000, "trunc(0x10000000.0)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   142
          fail_unless(fpcrtl_trunc(0x10000001.0) == 0x10000001, "trunc(0x10000001.0)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   143
          fail_unless(fpcrtl_trunc(0x20000000.0) == 0x20000000, "trunc(0x20000000.0)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   144
          fail_unless(fpcrtl_trunc(0x40000000.0) == 0x40000000, "trunc(0x40000000.0)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   145
          fail_unless(fpcrtl_trunc(0x80000000.0) == 0x80000000, "trunc(0x80000000.0)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   146
          fail_unless(fpcrtl_trunc(0xF0000000.0) == 0xF0000000, "trunc(0xF0000000.0)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   147
          fail_unless(fpcrtl_trunc(0xF0000001.0) == 0xF0000001, "trunc(0xF0000001.0)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   148
          fail_unless(fpcrtl_trunc(0x01010101.0) == 0x01010101, "trunc(0x01010101.0)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   149
          fail_unless(fpcrtl_trunc(0xFFFFFFFF.0) == 0xFFFFFFFF, "trunc(0xFFFFFFFF.0)");
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 10015
diff changeset
   150
          fail_unless(fpcrtl_trunc(0x8943FE39.0) == 0x8943FE39, "trunc(0x01000000.0)");
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   151
    }
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   152
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   153
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   154
START_TEST (test_odd)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   155
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   156
    fail_unless(fpcrtl_odd(123) != 0, "odd(123)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   157
    fail_unless(fpcrtl_odd(124) == 0, "odd(124)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   158
    fail_unless(fpcrtl_odd(0) == 0, "odd(0)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   159
    fail_unless(fpcrtl_odd(-1) != 0, "odd(-1)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   160
    fail_unless(fpcrtl_odd(-2) == 0, "odd(-2)");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   161
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   162
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   163
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   164
START_TEST (test_sqr)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   165
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   166
    fail_unless(fpcrtl_sqr(0) == 0, "sqr(0)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   167
    fail_unless(fpcrtl_sqr(5) == 25, "sqr(5)");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   168
    fail_unless(fpcrtl_sqr(-5) == 25, "sqr(-5)");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   169
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   170
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   171
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   172
START_TEST (test_lowercase)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   173
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   174
    string255 s1 = STRINIT("");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   175
    string255 s2 = STRINIT("a");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   176
    string255 s3 = STRINIT("abc");
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   177
    string255 t;
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   178
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   179
    t = fpcrtl_lowerCase(make_string(""));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   180
    fail_if(strcmp(t.str, s1.str), "lowerCase(\"\")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   181
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   182
    t = fpcrtl_lowerCase(make_string("a"));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   183
    fail_if(strcmp(t.str, s2.str), "lowerCase(\"a\")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   184
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   185
    t = fpcrtl_lowerCase(make_string("A"));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   186
    fail_if(strcmp(t.str, s2.str), "lowerCase(\"A\")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   187
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   188
    t = fpcrtl_lowerCase(make_string("AbC"));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   189
    fail_if(strcmp(t.str, s3.str), "lowerCase(\"AbC\")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   190
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   191
    t = fpcrtl_lowerCase(make_string("abc"));
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   192
    fail_if(strcmp(t.str, s3.str), "lowerCase(\"abc\")");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   193
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   194
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   195
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   196
START_TEST (test_str)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   197
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   198
    int8_t a1 = -8;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   199
    uint8_t a2 = 8;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   200
    int16_t a3 = -13;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   201
    uint16_t a4 = 13;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   202
    int32_t a5 = -19;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   203
    uint32_t a6 = 22;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   204
    int64_t a7 = -199999999999999;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   205
    uint64_t a8 = 200000000000000;
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   206
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   207
    float a9 = 12345.6789;
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   208
    double a10 = -9876.54321;
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   209
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   210
    string255 s;
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   211
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   212
    printf("-----Entering test str-----\n");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   213
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   214
    fpcrtl_str(a1, s);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   215
    printf("%d == %s\n", a1, s.str);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   216
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   217
    fpcrtl_str(a2, s);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   218
    printf("%u == %s\n", a2, s.str);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   219
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   220
    fpcrtl_str(a3, s);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   221
    printf("%d == %s\n", a3, s.str);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   222
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   223
    fpcrtl_str(a4, s);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   224
    printf("%u == %s\n", a4, s.str);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   225
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   226
    fpcrtl_str(a5, s);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   227
    printf("%d == %s\n", a5, s.str);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   228
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   229
    fpcrtl_str(a6, s);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   230
    printf("%u == %s\n", a6, s.str);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   231
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   232
    fpcrtl_str(a7, s);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   233
    printf("%lld == %s\n", a7, s.str);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   234
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   235
    fpcrtl_str(a8, s);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   236
    printf("%llu == %s\n", a8, s.str);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   237
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   238
    fpcrtl_str(a9, s);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   239
    printf("%f == %s\n", a9, s.str);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   240
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   241
    fpcrtl_str(a10, s);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   242
    printf("%f == %s\n", a10, s.str);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   243
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   244
    printf("-----Leaving test str------\n");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   245
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   246
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   247
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   248
Suite* system_suite(void)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   249
{
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   250
    Suite *s = suite_create("system");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   251
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   252
    TCase *tc_core = tcase_create("Core");
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   253
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   254
    tcase_add_test(tc_core, test_copy);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   255
    tcase_add_test(tc_core, test_FloatToStr);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   256
    tcase_add_test(tc_core, test_random);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   257
    tcase_add_test(tc_core, test_posS);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   258
    tcase_add_test(tc_core, test_trunc);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   259
    tcase_add_test(tc_core, test_delete);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   260
    tcase_add_test(tc_core, test_odd);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   261
    tcase_add_test(tc_core, test_sqr);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   262
    tcase_add_test(tc_core, test_lowercase);
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   263
    tcase_add_test(tc_core, test_str);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   264
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   265
    suite_add_tcase(s, tc_core);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   266
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 7983
diff changeset
   267
    return s;
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   268
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   269