From 9ca128acbdd6cbf0ab29e04439a32e8f4563131b Mon Sep 17 00:00:00 2001 From: turbocat Date: Wed, 3 Nov 2021 18:52:54 +0000 Subject: [PATCH] Added libc_test.c for testing libc.obj (by "navichok26") git-svn-id: svn://kolibrios.org@9242 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../ktcc/trunk/libc.obj/samples/Makefile | 3 +- .../ktcc/trunk/libc.obj/samples/build_all.sh | 39 ++++----- .../ktcc/trunk/libc.obj/samples/libc_test.c | 84 +++++++++++++++++++ 3 files changed, 106 insertions(+), 20 deletions(-) create mode 100644 programs/develop/ktcc/trunk/libc.obj/samples/libc_test.c diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/Makefile b/programs/develop/ktcc/trunk/libc.obj/samples/Makefile index 2e72c0d2ac..3bbd6bf93b 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/Makefile +++ b/programs/develop/ktcc/trunk/libc.obj/samples/Makefile @@ -22,7 +22,8 @@ clayer/msgbox.kex \ clayer/boxlib.kex \ thread_work.kex \ sdltest.kex \ -shell_test.kex +shell_test.kex \ +libc_test.kex LIBS= -lSDL -lshell -ltcc -lsound -ldialog -lrasterworks -limg -lbox -lmsgbox -lnetwork -lc.obj diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh b/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh index 108d7dae5b..592f17afc4 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh +++ b/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh @@ -1,21 +1,22 @@ #SHS mkdir /tmp0/1/tcc_samples -/kolibrios/develop/tcc/tcc file_io.c -o /tmp0/1/tcc_samples/file_io -lc.obj -/kolibrios/develop/tcc/tcc whois.c -o /tmp0/1/tcc_samples/whois -ltcc -lnetwork -lc.obj -/kolibrios/develop/tcc/tcc stdio_test.c -o /tmp0/1/tcc_samples/stdio_test -lc.obj -/kolibrios/develop/tcc/tcc basic_gui.c -o /tmp0/1/tcc_samples/basic_gui -ltcc -lc.obj -/kolibrios/develop/tcc/tcc consoleio.c -o /tmp0/1/tcc_samples/consoleio -lc.obj -/kolibrios/develop/tcc/tcc dir_example.c -o /tmp0/1/tcc_samples/ls_dir -lc.obj -/kolibrios/develop/tcc/tcc http_tcp_demo.c -o /tmp0/1/tcc_samples/http_tcp_demo -ltcc -lnetwork -lc.obj -/kolibrios/develop/tcc/tcc math_test.c -o /tmp0/1/tcc_samples/math_test -ltcc -lc.obj -/kolibrios/develop/tcc/tcc string_test.c -o /tmp0/1/tcc_samples/string_test -ltcc -lc.obj -/kolibrios/develop/tcc/tcc tmpdisk_work.c -o /tmp0/1/tcc_samples/tmpdisk_work -ltcc -lc.obj -/kolibrios/develop/tcc/tcc clayer/boxlib.c -o /tmp0/1/tcc_samples/boxlib -ltcc -lbox -lc.obj -/kolibrios/develop/tcc/tcc clayer/dialog.c -o /tmp0/1/tcc_samples/dialog -ltcc -ldialog -lc.obj -cp /kolibrios/develop/tcc/samples/clayer/logo.png /tmp0/1/tcc_samples/logo.png -/kolibrios/develop/tcc/tcc clayer/libimg.c -o /tmp0/1/tcc_samples/libimg -ltcc -limg -lc.obj -/kolibrios/develop/tcc/tcc clayer/msgbox.c -o /tmp0/1/tcc_samples/msgbox -ltcc -lmsgbox -lc.obj -/kolibrios/develop/tcc/tcc clayer/rasterworks.c -o /tmp0/1/tcc_samples/rasterworks -ltcc -lrasterworks -lc.obj -/kolibrios/develop/tcc/tcc thread_work.c -o /tmp0/1/tcc_samples/thread_work -ltcc -lc.obj -/kolibrios/develop/tcc/tcc -I/kolibrios/develop/tcc/include/SDL sdltest.c -o /tmp0/1/tcc_samples/sdltest -lSDL -lsound -ltcc -lc.obj -/kolibrios/develop/tcc/tcc shell_test.c -o /tmp0/1/tcc_samples/shell_test -lshell -ltcc -lc.obj +../tcc file_io.c -o /tmp0/1/tcc_samples/file_io -lc.obj +../tcc whois.c -o /tmp0/1/tcc_samples/whois -ltcc -lnetwork -lc.obj +../tcc stdio_test.c -o /tmp0/1/tcc_samples/stdio_test -lc.obj +../tcc basic_gui.c -o /tmp0/1/tcc_samples/basic_gui -ltcc -lc.obj +../tcc consoleio.c -o /tmp0/1/tcc_samples/consoleio -lc.obj +../tcc dir_example.c -o /tmp0/1/tcc_samples/ls_dir -lc.obj +../tcc http_tcp_demo.c -o /tmp0/1/tcc_samples/http_tcp_demo -ltcc -lnetwork -lc.obj +../tcc math_test.c -o /tmp0/1/tcc_samples/math_test -ltcc -lc.obj +../tcc string_test.c -o /tmp0/1/tcc_samples/string_test -ltcc -lc.obj +../tcc tmpdisk_work.c -o /tmp0/1/tcc_samples/tmpdisk_work -ltcc -lc.obj +../tcc clayer/boxlib.c -o /tmp0/1/tcc_samples/boxlib -ltcc -lbox -lc.obj +../tcc clayer/dialog.c -o /tmp0/1/tcc_samples/dialog -ltcc -ldialog -lc.obj +cp clayer/logo.png /tmp0/1/tcc_samples/logo.png +../tcc clayer/libimg.c -o /tmp0/1/tcc_samples/libimg -ltcc -limg -lc.obj +../tcc clayer/msgbox.c -o /tmp0/1/tcc_samples/msgbox -ltcc -lmsgbox -lc.obj +../tcc clayer/rasterworks.c -o /tmp0/1/tcc_samples/rasterworks -ltcc -lrasterworks -lc.obj +../tcc thread_work.c -o /tmp0/1/tcc_samples/thread_work -ltcc -lc.obj +../tcc -I../include/SDL sdltest.c -o /tmp0/1/tcc_samples/sdltest -lSDL -lsound -ltcc -lc.obj +../tcc shell_test.c -o /tmp0/1/tcc_samples/shell_test -lshell -ltcc -lc.obj +../tcc libc_test.c -o /tmp0/1/tcc_samples/libc_test -ltcc -lc.obj diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/libc_test.c b/programs/develop/ktcc/trunk/libc.obj/samples/libc_test.c new file mode 100644 index 0000000000..f961a0a23e --- /dev/null +++ b/programs/develop/ktcc/trunk/libc.obj/samples/libc_test.c @@ -0,0 +1,84 @@ +#include +#include +#include +#include + +int comp(void *a, void *b) { + return *(int*)a - *(int*)b; +} + +int main(){ + puts("Start testing."); + assert(NULL == ((void*)0)); + assert(RAND_MAX == 65535); + assert(min(3, 10) == 3); + assert(max(3, 10) == 10); + assert(atof("12.4") == 12.4); + assert(atoi("-123") == -123); + assert(atol("-2146483647") == -2146483647L); + assert(atoll("-9223372036854775806") == -9223372036854775806LL); + assert(!strcmp("123", "123")); + + char st1[32]; + itoa(-2341, st1); + assert(!strcmp(st1, "-2341")); + + assert(strlen("12345") == 5); + assert(abs(4) == 4); + assert(abs(-4) == 4); + assert(labs(1000000000) == 1000000000); + assert(labs(-1000000000) == 1000000000); + assert(llabs(100000000000) == 100000000000); + assert(llabs(-100000000000) == 100000000000); + + div_t output1 = div(27, 4); + assert(output1.quot == 6); + assert(output1.rem == 3); + + ldiv_t output2 = ldiv(27, 4); + assert(output2.quot == 6); + assert(output2.rem == 3); + + lldiv_t output3 = lldiv(27, 4); + assert(output3.quot == 6); + assert(output3.rem == 3); + + char *st2 = malloc(sizeof(char)*2); + assert(st2 != NULL); + st2[0] = 'H'; + st2[1] = 'i'; + st2 = realloc(st2, sizeof(char)*3); + st2[2] = '!'; + assert(!strcmp(st2, "Hi!")); + free(st2); + + st2 = calloc(2, sizeof(char)); + assert(st2 != NULL); + st2[0] = 'H'; + st2[1] = 'i'; + assert(!strcmp(st2, "Hi")); + free(st2); + + char *start = "100.00 Rub"; + char *end; + assert(strtol(start, &end, 10) == 100L); + assert(!strcmp(end, ".00 Rub")); + + end = NULL; + assert(strtod(start, &end) == 100.0); + assert(!strcmp(end, " Rub")); + + // rand и srand проверены вручную :3 + + char *st3 = "21.3e3Hello World!"; + assert(atof(st3) == 21300.0); + + int nums[10] = {5, 3, 9, 1, 8, 4, 2, 0, 7, 6}; + qsort(nums, 10, sizeof(int), (int(*) (const void *, const void *))comp); + for (int i = 0; i < 10; i++) { + assert(nums[i] == i); + } + + puts("End testing."); + exit(0); +} \ No newline at end of file