Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.6 KiB

  1. /* incomplete test suite for convert functions
  2. Current functions tested:
  3. all isxxxxx functions
  4. toupper
  5. tolower
  6. atoi
  7. atol
  8. strtol
  9. strtoul
  10. swab
  11. itoa
  12. ltoa
  13. ultoa
  14. */
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <limits.h>
  18. #include <errno.h>
  19. fail(int n)
  20. {
  21. printf("Test #%d failed.\n", n);
  22. }
  23. main()
  24. {
  25. char s[512];
  26. char t[512];
  27. char *p;
  28. /* test isxxxx functions */
  29. if (!iscntrl(0x7)) fail(1);
  30. if (iscntrl('c')) fail(2);
  31. if (!isdigit('0')) fail(3);
  32. if (isdigit('A')) fail(4);
  33. if (!isgraph(';')) fail(5);
  34. if (isgraph(' ')) fail(6);
  35. if (!islower('f')) fail(7);
  36. if (islower('F')) fail(8);
  37. if (!isprint('S')) fail(9);
  38. if (isprint('\v')) fail(10);
  39. if (!ispunct('.')) fail(11);
  40. if (ispunct('A')) fail(12);
  41. if (!isspace('\v')) fail(13);
  42. if (isspace('D')) fail(14);
  43. if (!isupper('D')) fail(15);
  44. if (isupper('z')) fail(16);
  45. if (!isxdigit('D')) fail(17);
  46. if (isxdigit('G')) fail(18);
  47. if (!isalnum('7')) fail(19);
  48. if (isalnum(';')) fail(20);
  49. if (!isalpha('j')) fail(21);
  50. if (isalpha('$')) fail(22);
  51. if (!isascii(0x3)) fail(23);
  52. if (isascii(234)) fail(24);
  53. if (!iscsym('d')) fail(25);
  54. if (iscsym('$')) fail(26);
  55. if (!iscsymf('A')) fail(27);
  56. if (iscsymf('5')) fail(28);
  57. /* test toupper and tolower */
  58. if (tolower('C') != 'c') fail(29);
  59. if (tolower('d') != 'd') fail(30);
  60. if (tolower('$') != '$') fail(31);
  61. if (toupper('q') != 'Q') fail(32);
  62. if (toupper('A') != 'A') fail(33);
  63. if (toupper(';') != ';') fail(34);
  64. /* test atol/atoi */
  65. if (atol("-123") != -123) fail(35);
  66. if (atoi("32767") != 32767) fail(36);
  67. if (atoi("-32767") != -32767) fail(36);
  68. if (atol("0") != 0) fail(37);
  69. if (atol("2147483647") != 2147483647) fail(38);
  70. if (atol("-2147483647") != -2147483647) fail(39);
  71. if (atol("123456") != 123456) fail(40);
  72. if (atol("-123456") != -123456) fail(41);
  73. /* test strtol */
  74. if (strtol("-123", NULL, 10) != -123) fail(42);
  75. if (strtol(" 2147483646", NULL, 10) != 2147483646) fail(43);
  76. if (strtol("-2147483646$$", NULL, 10) != -2147483646) fail(44);
  77. if (strtol(" 2147483648x", NULL, 10) != LONG_MAX) fail(45);
  78. if (strtol(" -2147483648", NULL, 10) != LONG_MIN) fail(46);
  79. if (strtol("0", NULL, 10) != 0) fail(47);
  80. if (strtol("981235b", NULL, 10) != 981235) fail(48);
  81. if (strtol(" -1234567a", NULL, 10) != -1234567) fail(49);
  82. if (strtol("FFDE", NULL, 16) != 0xFFDE) fail(50);
  83. if (strtol("7FFFFFFE", NULL, 16) != 0x7FFFFFFE) fail(51);
  84. if (strtol("-0x45", NULL, 16) != -0x45) fail(52);
  85. if (strtol("23478", NULL, 8) != 02347) fail(53);
  86. if (strtol(" -0x123D", NULL, 0) != -0x123d) fail(54);
  87. if (strtol(" 01238", NULL, 0) != 0123) fail(55);
  88. if (strtol(" -678899", NULL, 0) != -678899) fail(56);
  89. errno = 0;
  90. strtol("2147483647", NULL, 10);
  91. if (errno != 0) fail(57);
  92. errno = 0;
  93. strtol("2147483648", NULL, 10);
  94. if (errno != ERANGE) fail(58);
  95. errno = 0;
  96. strtol("63234283743", NULL, 10);
  97. if (errno != ERANGE) fail(59);
  98. strcpy(s, " 8983");
  99. strtol(s, &p, 8);
  100. if (s != p) fail(60);
  101. strcpy(s, "12345678901234567890XX");
  102. strtol(s, &p, 0);
  103. if (p != s+20) fail(61);
  104. strcpy(s, " 111");
  105. strtol(s, &p, 1);
  106. if (p != s) fail(62);
  107. errno = 0;
  108. if (strtoul("4294967295", NULL, 10) != ULONG_MAX) fail(63);
  109. if (errno != 0) fail(64);
  110. errno = 0;
  111. strtoul("4294967296", NULL, 10);
  112. if (errno != ERANGE) fail(65);
  113. errno = 0;
  114. strtoul("63234283743", NULL, 10);
  115. if (errno != ERANGE) fail(66);
  116. /* test swab */
  117. strcpy(s, "abcdefghijklmn");
  118. swab(s, t, 14);
  119. if (strcmp(t, "badcfehgjilknm") != 0) fail(67);
  120. strcpy(t, s);
  121. swab(s, t, 7);
  122. if (strcmp(t, "badcfeghijklmn") != 0) fail(68);
  123. strcpy(t, s);
  124. swab(s, t, -5);
  125. if (strcmp(s, t) != 0) fail(69);
  126. /* test itoa/ltoa/ultoa */
  127. if (strcmp(itoa(345, s, 10), "345") != 0) fail(70);
  128. if (strcmp(itoa(-345, s, 10), "-345") != 0) fail(71);
  129. if (strcmp(itoa(33, s, 36), "x") != 0) fail(72);
  130. if (strcmp(itoa(65535U, s, 16), "ffff") != 0) fail(73);
  131. if (strcmp(ltoa(123457, s, 10), "123457") != 0) fail(74);
  132. if (strcmp(ltoa(-123457, s, 10), "-123457") != 0) fail(75);
  133. if (strcmp(ltoa(076512L, s, 8), "76512") != 0) fail(76);
  134. if (strcmp(ltoa(-1L, s, 10), "-1") != 0) fail(77);
  135. if (strcmp(ltoa(-1L, s, 16), "ffffffff") != 0) fail(78);
  136. if (strcmp(ultoa(-1L, s, 10), "4294967295") != 0) fail(79);
  137. }