home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / test / memory.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-17  |  4.3 KB  |  148 lines

  1. /* memory.c (emx+gcc) */
  2.  
  3. #include <stdio.h>
  4. #include <strings.h>
  5.  
  6. int main (void)
  7. {
  8.   char buf1[] = "this is a test string";
  9.   char buf2[sizeof (buf1)];
  10.   char *p;
  11.   int i, n;
  12.  
  13.   n = strlen (buf1);
  14.   if (n != sizeof (buf1) - 1)
  15.     puts ("strlen error 1");
  16.   if (strcmp ("a", "a") != 0)
  17.     puts ("strcmp error 1");
  18.   if (strcmp ("a", "b") >= 0)
  19.     puts ("strcmp error 2");
  20.   if (strcmp ("b", "a") <= 0)
  21.     puts ("strcmp error 3");
  22.   if (strcmp ("ab", "ac") >= 0)
  23.     puts ("strcmp error 4");
  24.   if (strcmp ("xc", "xb") <= 0)
  25.     puts ("strcmp error 5");
  26.   if (strcmp ("xx", "xxa") >= 0)
  27.     puts ("strcmp error 6");
  28.   if (strcmp ("xxa", "xx") <= 0)
  29.     puts ("strcmp error 7");
  30.   p = memchr (buf1, 'x', n);
  31.   if (p != NULL)
  32.     puts ("memchr error 1");
  33.   p = memchr (buf1, ' ', 0);
  34.   if (p != NULL)
  35.     puts ("memchr error 2");
  36.   p = memchr (buf1, 't', n);
  37.   if (p != buf1)
  38.     puts ("memchr error 3");
  39.   p = memchr (buf1, 't', 0);
  40.   if (p != NULL)
  41.     puts ("memchr error 4");
  42.   p = memchr (buf1, 'g', n);
  43.   if (p != buf1+n-1)
  44.     puts ("memchr error 5");
  45.   p = memchr (buf1, 's', 3);
  46.   if (p != NULL)
  47.     puts ("memchr error 6");
  48.   p = memchr (buf1, 's', 4);
  49.   if (p != buf1+3)
  50.     puts ("memchr error 7");
  51.   if (strcpy (buf2, buf1) != buf2)
  52.     puts ("strcpy error 1");
  53.   if (memmove (buf1+0, buf1+1, n) != buf1+0)
  54.     puts ("memmove error 1");
  55.   if (memcmp (buf1, buf2+1, n) != 0)
  56.     puts ("memcmp error 1");
  57.   if (memmove (buf1+1, buf1+0, n) != buf1+1)
  58.     puts ("memmove error 2");
  59.   buf1[0] = buf2[0];
  60.   if (memcmp (buf1, buf2, n+1) != 0)
  61.     puts ("memcmp error 2");
  62.   if (_memcount (buf1, 't', strlen (buf1)) != 4)
  63.     puts ("_memcount error 1");
  64.   if (memicmp (buf1, "ThIs", 4) != 0)
  65.     puts ("memicmp error 1");
  66.   if (memicmp (buf1, "ThIT", 4) >= 0)
  67.     puts ("memicmp error 2");
  68.   if (memicmp (buf1, "ThIr", 4) <= 0)
  69.     puts ("memicmp error 3");
  70.   if (strchr (buf1, 'X') != NULL)
  71.     puts ("strchr error 1");
  72.   if (strchr (buf1, 0) != buf1 + n)
  73.     puts ("strchr error 2");
  74.   if (strchr (buf1, 't') != buf1 + 0)
  75.     puts ("strchr error 3");
  76.   if (strchr (buf1, 'a') != buf1 + 8)
  77.     puts ("strchr error 4");
  78.   buf1[7] = 0;
  79.   if (strchr (buf1, 'a') != NULL)
  80.     puts ("strchr error 5");
  81.   buf1[7] = ' ';
  82.   if (strrchr (buf1, 'X') != NULL)
  83.     puts ("strrchr error 1");
  84.   if (strrchr (buf1, 0) != buf1 + n)
  85.     puts ("strrchr error 2");
  86.   if (strrchr (buf1, 'g') != buf1 + n - 1)
  87.     puts ("strrchr error 3");
  88.   if (strrchr (buf1, 'a') != buf1 + 8)
  89.     puts ("strrchr error 4");
  90.   buf1[7] = 0;
  91.   if (strrchr (buf1, 'a') != NULL)
  92.     puts ("strrchr error 5");
  93.   buf1[7] = ' ';
  94.   if (strrchr (buf1, 't') != buf1 + 16)
  95.     puts ("strrchr error 6");
  96.   buf1[0] = 'X';
  97.   if (strrchr (buf1, 'X') != buf1)
  98.     puts ("strrchr error 7");
  99.   if (strrchr (buf1+1, 'X') != NULL)
  100.     puts ("strrchr error 8");
  101.   buf1[0] = 't';
  102.   if (strstr (buf1, "") != buf1)
  103.     puts ("strstr error 1");
  104.   if (strstr (buf1, "x") != NULL)
  105.     puts ("strstr error 2");
  106.   if (strstr (buf1, buf1) != buf1)
  107.     puts ("strstr error 3");
  108.   if (strstr (buf1, "t") != buf1)
  109.     puts ("strstr error 4");
  110.   if (strstr (buf1, "te") != buf1+10)
  111.     puts ("strstr error 5");
  112.   if (strstr (buf1, "ti") != NULL)
  113.     puts ("strstr error 6");
  114.   if (strstr (buf1, "g") != buf1+n-1)
  115.     puts ("strstr error 7");
  116.   strset (buf2, '*');
  117.   _memswap (buf2, buf1, n+1);
  118.   if (strcmp (buf2, "this is a test string") != 0)
  119.     puts ("_memswap error 1");
  120.   _memswap (buf2, buf1, n+1);
  121.   memset (buf1, '*', n);
  122.   if (strcmp (buf1, buf2) != 0)
  123.     puts ("memset/strset error 1");
  124.   if (memcmp ("a", "b", 1) >= 0)
  125.     puts ("memcmp error 3");
  126.   if (memcmp ("b", "a", 1) <= 0)
  127.     puts ("memcmp error 4");
  128.   if (ffs (0) != 0)
  129.     puts ("ffs error 1");
  130.   if (ffs (-1) != 1)
  131.     puts ("ffs error 2");
  132.   for (i = 0; i < 32; ++i)
  133.     if (ffs (1 << i) != i + 1)
  134.       printf ("ffs error 3, i=%d\n", i);
  135.   if (ffs (6) != 2)
  136.     puts ("ffs error 4");
  137.   if (_memdif ("a", "b", 0) != _MEMDIF_EQ)
  138.     puts ("_memdif error 1\n");
  139.   if (_memdif ("ab", "xx", 2) != 0)
  140.     puts ("_memdif error 2\n");
  141.   if (_memdif ("ab", "ac", 2) != 1)
  142.     puts ("_memdif error 3\n");
  143.   if (_memdif ("ab", "ab", 2) != _MEMDIF_EQ)
  144.     puts ("_memdif error 4\n");
  145.   puts ("done");
  146.   return (0);
  147. }
  148.