Subversion Repositories Kolibri OS

Rev

Rev 9262 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <sys/ksys.h>
  6. #include <time.h>
  7.  
  8. int comp(void* a, void* b)
  9. {
  10.     return *(int*)a - *(int*)b;
  11. }
  12.  
  13. int main()
  14. {
  15.     puts("Start testing.");
  16.     assert(NULL == ((void*)0));
  17.     assert(RAND_MAX == 65535);
  18.     assert(min(3, 10) == 3);
  19.     assert(max(3, 10) == 10);
  20.     assert(atof("12.4") == 12.4);
  21.     assert(atoi("-123") == -123);
  22.     assert(atol("-2146483647") == -2146483647L);
  23.     assert(atoll("-9223372036854775806") == -9223372036854775806LL);
  24.     assert(!strcmp("123", "123"));
  25.  
  26.     char st1[32];
  27.     itoa(-2341, st1);
  28.     assert(!strcmp(st1, "-2341"));
  29.  
  30.     assert(strlen("12345") == 5);
  31.     assert(abs(4) == 4);
  32.     assert(abs(-4) == 4);
  33.     assert(labs(1000000000) == 1000000000);
  34.     assert(labs(-1000000000) == 1000000000);
  35.     assert(llabs(100000000000) == 100000000000);
  36.     assert(llabs(-100000000000) == 100000000000);
  37.  
  38.     div_t output1 = div(27, 4);
  39.     assert(output1.quot == 6);
  40.     assert(output1.rem == 3);
  41.  
  42.     ldiv_t output2 = ldiv(27, 4);
  43.     assert(output2.quot == 6);
  44.     assert(output2.rem == 3);
  45.  
  46.     lldiv_t output3 = lldiv(27, 4);
  47.     assert(output3.quot == 6);
  48.     assert(output3.rem == 3);
  49.  
  50.     char* st2 = malloc(sizeof(char) * 2);
  51.     assert(st2 != NULL);
  52.     st2[0] = 'H';
  53.     st2[1] = 'i';
  54.     st2 = realloc(st2, sizeof(char) * 3);
  55.     st2[2] = '!';
  56.     assert(!strcmp(st2, "Hi!"));
  57.     free(st2);
  58.  
  59.     st2 = calloc(2, sizeof(char));
  60.     assert(st2 != NULL);
  61.     st2[0] = 'H';
  62.     st2[1] = 'i';
  63.     assert(!strcmp(st2, "Hi"));
  64.     free(st2);
  65.  
  66.     char* start = "100.00 Rub";
  67.     char* end;
  68.     assert(strtol(start, &end, 10) == 100L);
  69.     assert(!strcmp(end, ".00 Rub"));
  70.  
  71.     end = NULL;
  72.     assert(strtod(start, &end) == 100.0);
  73.     assert(!strcmp(end, " Rub"));
  74.  
  75.     char* st3 = "21.3e3Hello World!";
  76.     assert(atof(st3) == 21300.0);
  77.  
  78.     int nums[10] = { 5, 3, 9, 1, 8, 4, 2, 0, 7, 6 };
  79.     qsort(nums, 10, sizeof(int), (int (*)(const void*, const void*))comp);
  80.     for (int i = 0; i < 10; i++) {
  81.         assert(nums[i] == i);
  82.     }
  83.  
  84.     time_t libc_time = time(NULL);
  85.     struct tm* libc_tm = localtime(&libc_time);
  86.     printf(asctime(libc_tm));
  87.  
  88.     puts("End testing.");
  89.     exit(0);
  90. }
  91.