ctype.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Test application for functions defined in ctype.h
  4. *
  5. * Copyright (C) 2000 by Lineo, inc.
  6. * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <stdarg.h>
  26. #include <ctype.h>
  27. #include "../testsuite.h"
  28. #define TRUE 0
  29. int main( int argc, char **argv)
  30. {
  31. int i, c;
  32. printf( "Testing functions defined in ctype.h\n");
  33. /* isalnum() */
  34. {
  35. int buffer[]={ '1', '4', 'a', 'z', 'A', 'Z', '5', -1};
  36. for(i=0; buffer[i]!=-1; i++) {
  37. c = buffer[i];
  38. TEST_SUCCESS( isalnum(c)==TRUE,
  39. "isalnum(%c)", c);
  40. }
  41. }
  42. {
  43. int buffer[]={ 2, 128, 254, '\n', -1};
  44. for(i=0; buffer[i]!=-1; i++) {
  45. c = buffer[i];
  46. TEST_SUCCESS( isalnum(c)!=TRUE,
  47. "!isalnum(%d)", c);
  48. }
  49. }
  50. /* isalpha() */
  51. {
  52. int buffer[]={ 'a', 'z', 'A', 'Z', -1};
  53. for(i=0; buffer[i]!=-1; i++) {
  54. c = buffer[i];
  55. TEST_SUCCESS( isalpha(c)==TRUE,
  56. "isalpha(%c)", c);
  57. }
  58. }
  59. {
  60. int buffer[]={ 2, 63, 128, 254, '\n', -1};
  61. for(i=0; buffer[i]!=-1; i++) {
  62. c = buffer[i];
  63. TEST_SUCCESS( isalpha(c)!=TRUE,
  64. "!isalpha(%d)", c);
  65. }
  66. }
  67. /* isascii() */
  68. {
  69. int buffer[]={ 'a', 'z', 'A', 'Z', '\n', -1};
  70. for(i=0; buffer[i]!=-1; i++) {
  71. c = buffer[i];
  72. TEST_SUCCESS( isascii(c)==TRUE,
  73. "isascii(%d)", c);
  74. }
  75. }
  76. {
  77. int buffer[]={ 128, 254, -1};
  78. for(i=0; buffer[i]!=-1; i++) {
  79. c = buffer[i];
  80. TEST_SUCCESS( isascii(c)!=TRUE,
  81. "!isascii(%d)", c);
  82. }
  83. }
  84. /* iscntrl() */
  85. {
  86. int buffer[]={ 0x7F, 6, '\t', '\n', 0x7F, -1};
  87. for(i=0; buffer[i]!=-1; i++) {
  88. c = buffer[i];
  89. TEST_SUCCESS( iscntrl(c)==TRUE,
  90. "iscntrl(%d)", c);
  91. }
  92. }
  93. {
  94. int buffer[]={ 63, 128, 254, -1};
  95. for(i=0; buffer[i]!=-1; i++) {
  96. c = buffer[i];
  97. TEST_SUCCESS( iscntrl(c)!=TRUE,
  98. "!iscntrl(%d)", c);
  99. }
  100. }
  101. /* isdigit() */
  102. {
  103. int buffer[]={ '1', '5', '7', '9', -1};
  104. for(i=0; buffer[i]!=-1; i++) {
  105. c = buffer[i];
  106. TEST_SUCCESS( isdigit(c)==TRUE,
  107. "isdigit(%c)", c);
  108. }
  109. }
  110. {
  111. int buffer[]={ 2, 'a', 'z', 'A', 'Z', 63, 128, 254, '\n', -1};
  112. for(i=0; buffer[i]!=-1; i++) {
  113. c = buffer[i];
  114. TEST_SUCCESS( isdigit(c)!=TRUE,
  115. "!isdigit(%d)", c);
  116. }
  117. }
  118. /* isgraph() */
  119. {
  120. int buffer[]={ ')', '~', '9', -1};
  121. for(i=0; buffer[i]!=-1; i++) {
  122. c = buffer[i];
  123. TEST_SUCCESS( isgraph(c)==TRUE,
  124. "isgraph(%d)", c);
  125. }
  126. }
  127. {
  128. int buffer[]={ 9, ' ', '\t', '\n', 200, 0x7F, -1};
  129. for(i=0; buffer[i]!=-1; i++) {
  130. c = buffer[i];
  131. TEST_SUCCESS( isgraph(c)!=TRUE,
  132. "!isgraph(%d)", c);
  133. }
  134. }
  135. /* islower() */
  136. {
  137. int buffer[]={ 'a', 'g', 'z', -1};
  138. for(i=0; buffer[i]!=-1; i++) {
  139. c = buffer[i];
  140. TEST_SUCCESS( islower(c)==TRUE,
  141. "islower(%c)", c);
  142. }
  143. }
  144. {
  145. int buffer[]={ 9, 'A', 'Z', 128, 254, ' ', '\t', '\n', 0x7F, -1};
  146. for(i=0; buffer[i]!=-1; i++) {
  147. c = buffer[i];
  148. TEST_SUCCESS( islower(c)!=TRUE,
  149. "!islower(%d)", c);
  150. }
  151. }
  152. /* isprint() */
  153. {
  154. int buffer[]={ ' ', ')', '~', '9', -1};
  155. for(i=0; buffer[i]!=-1; i++) {
  156. c = buffer[i];
  157. TEST_SUCCESS( isprint(c)==TRUE,
  158. "isprint(%c)", c);
  159. }
  160. }
  161. {
  162. int buffer[]={ '\b', '\t', '\n', 9, 128, 254, 200, 0x7F, -1};
  163. for(i=0; buffer[i]!=-1; i++) {
  164. c = buffer[i];
  165. TEST_SUCCESS( isprint(c)!=TRUE,
  166. "!isprint(%d)", c);
  167. }
  168. }
  169. /* ispunct() */
  170. {
  171. int buffer[]={ '.', '#', '@', ';', -1};
  172. for(i=0; buffer[i]!=-1; i++) {
  173. c = buffer[i];
  174. TEST_SUCCESS( ispunct(c)==TRUE,
  175. "ispunct(%c)", c);
  176. }
  177. }
  178. {
  179. int buffer[]={ 2, 'a', 'Z', '1', 128, 254, '\n', -1};
  180. for(i=0; buffer[i]!=-1; i++) {
  181. c = buffer[i];
  182. TEST_SUCCESS( ispunct(c)!=TRUE,
  183. "!ispunct(%d)", c);
  184. }
  185. }
  186. /* isspace() */
  187. {
  188. int buffer[]={ ' ', '\t', '\r', '\v', '\n', -1};
  189. for(i=0; buffer[i]!=-1; i++) {
  190. c = buffer[i];
  191. TEST_SUCCESS( isspace(c)==TRUE,
  192. "isspace(%d)", c);
  193. }
  194. }
  195. {
  196. int buffer[]={ 2, 'a', 'Z', '1', 128, 254, -1};
  197. for(i=0; buffer[i]!=-1; i++) {
  198. c = buffer[i];
  199. TEST_SUCCESS( isspace(c)!=TRUE,
  200. "!isspace(%d)", c);
  201. }
  202. }
  203. /* isupper() */
  204. {
  205. int buffer[]={ 'A', 'G', 'Z', -1};
  206. for(i=0; buffer[i]!=-1; i++) {
  207. c = buffer[i];
  208. TEST_SUCCESS( isupper(c)==TRUE,
  209. "isupper(%c)", c);
  210. }
  211. }
  212. {
  213. int buffer[]={ 2, 'a', 'z', '1', 128, 254, -1};
  214. for(i=0; buffer[i]!=-1; i++) {
  215. c = buffer[i];
  216. TEST_SUCCESS( isupper(c)!=TRUE,
  217. "!isupper(%d)", c);
  218. }
  219. }
  220. /* isxdigit() */
  221. {
  222. int buffer[]={ 'f', 'A', '1', '8', -1};
  223. for(i=0; buffer[i]!=-1; i++) {
  224. c = buffer[i];
  225. TEST_SUCCESS( isxdigit(c)==TRUE,
  226. "isxdigit(%c)", c);
  227. }
  228. }
  229. {
  230. int buffer[]={ 2, 'g', 'G', 'x', '\n', -1};
  231. for(i=0; buffer[i]!=-1; i++) {
  232. c = buffer[i];
  233. TEST_SUCCESS( isxdigit(c)!=TRUE,
  234. "!isxdigit(%d)", c);
  235. }
  236. }
  237. /* tolower() */
  238. c='A';
  239. TEST_NUMERIC_OUTPUT( tolower(c), 'a', "tolower(%c)=%c", c, tolower(c));
  240. c='a';
  241. TEST_NUMERIC_OUTPUT( tolower(c), 'a', "tolower(%c)=%c", c, tolower(c));
  242. c='#';
  243. TEST_NUMERIC_OUTPUT( tolower(c), c, "tolower(%c)=%c", c, tolower(c));
  244. /* toupper() */
  245. c='a';
  246. TEST_NUMERIC_OUTPUT( toupper(c), 'A', "toupper(%c)=%c", c, toupper(c));
  247. c='A';
  248. TEST_NUMERIC_OUTPUT( toupper(c), 'A', "toupper(%c)=%c", c, toupper(c));
  249. c='#';
  250. TEST_NUMERIC_OUTPUT( toupper(c), c, "toupper(%c)=%c", c, toupper(c));
  251. printf( "Finished testing ctype.h\n");
  252. stop_testing();
  253. }