Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include "test.h"
  4.  
  5. #define N(s, c) { \
  6.         char *p = s; \
  7.         char *q = strchr(p, c); \
  8.         if (q) \
  9.                 t_error("strchr(%s,%s) returned str+%d, wanted 0\n", #s, #c, q-p); \
  10. }
  11.  
  12. #define T(s, c, n) { \
  13.         char *p = s; \
  14.         char *q = strchr(p, c); \
  15.         if (q == 0) \
  16.                 t_error("strchr(%s,%s) returned 0, wanted str+%d\n", #s, #c, n); \
  17.         else if (q - p != n) \
  18.                 t_error("strchr(%s,%s) returned str+%d, wanted str+%d\n", #s, #c, q-p, n); \
  19. }
  20.  
  21. int main(void)
  22. {
  23.         int i;
  24.         char a[128];
  25.         char s[256];
  26.  
  27.         for (i = 0; i < 128; i++)
  28.                 a[i] = (i+1) & 127;
  29.         for (i = 0; i < 256; i++)
  30.                 *((unsigned char*)s+i) = i+1;
  31.  
  32.         N("", 'a')
  33.         N("a", 'b')
  34.         N("abc abc", 'x')
  35.         N(a, 128)
  36.         N(a, 255)
  37.  
  38.         T("", 0, 0)
  39.         T("a", 'a', 0)
  40.         T("a", 'a'+256, 0)
  41.         T("a", 0, 1)
  42.         T("ab", 'b', 1)
  43.         T("aab", 'b', 2)
  44.         T("aaab", 'b', 3)
  45.         T("aaaab", 'b', 4)
  46.         T("aaaaab", 'b', 5)
  47.         T("aaaaaab", 'b', 6)
  48.         T("abc abc", 'c', 2)
  49.         T(s, 1, 0)
  50.         T(s, 2, 1)
  51.         T(s, 10, 9)
  52.         T(s, 11, 10)
  53.         T(s, 127, 126)
  54.         T(s, 128, 127)
  55.         T(s, 255, 254)
  56.         T(s, 0, 255)
  57.  
  58.         printf("%s finished\n", __FILE__);
  59.         return t_status;
  60. }
  61.