ctype.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. Written by Erik Andersen
  6. * <andersen@lineo.com>, <andersee@debian.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU Library General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  16. * for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public License
  19. * along with this program; if not, write to the Free Software Foundation,
  20. * 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 1
  29. int main( int argc, char **argv)
  30. {
  31. int i, c;
  32. init_testsuite("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( isalnum(c)==TRUE);
  39. }
  40. }
  41. {
  42. int buffer[]={ 2, 128, 254, '\n', -1};
  43. for(i=0; buffer[i]!=-1; i++) {
  44. c = buffer[i];
  45. TEST( isalnum(c)!=TRUE);
  46. }
  47. }
  48. /* isalpha() */
  49. {
  50. int buffer[]={ 'a', 'z', 'A', 'Z', -1};
  51. for(i=0; buffer[i]!=-1; i++) {
  52. c = buffer[i];
  53. TEST( isalpha(c)==TRUE);
  54. }
  55. }
  56. {
  57. int buffer[]={ 2, 63, 128, 254, '\n', -1};
  58. for(i=0; buffer[i]!=-1; i++) {
  59. c = buffer[i];
  60. TEST( isalpha(c)!=TRUE);
  61. }
  62. }
  63. /* isascii() */
  64. {
  65. int buffer[]={ 'a', 'z', 'A', 'Z', '\n', -1};
  66. for(i=0; buffer[i]!=-1; i++) {
  67. c = buffer[i];
  68. TEST( isascii(c)==TRUE);
  69. }
  70. }
  71. {
  72. int buffer[]={ 128, 254, -1};
  73. for(i=0; buffer[i]!=-1; i++) {
  74. c = buffer[i];
  75. TEST( isascii(c)!=TRUE);
  76. }
  77. }
  78. /* iscntrl() */
  79. {
  80. int buffer[]={ 0x7F, 6, '\t', '\n', 0x7F, -1};
  81. for(i=0; buffer[i]!=-1; i++) {
  82. c = buffer[i];
  83. TEST( iscntrl(c)==TRUE);
  84. }
  85. }
  86. {
  87. int buffer[]={ 63, 128, 254, -1};
  88. for(i=0; buffer[i]!=-1; i++) {
  89. c = buffer[i];
  90. TEST( iscntrl(c)!=TRUE);
  91. }
  92. }
  93. /* isdigit() */
  94. {
  95. int buffer[]={ '1', '5', '7', '9', -1};
  96. for(i=0; buffer[i]!=-1; i++) {
  97. c = buffer[i];
  98. TEST( isdigit(c)==TRUE);
  99. }
  100. }
  101. {
  102. int buffer[]={ 2, 'a', 'z', 'A', 'Z', 63, 128, 254, '\n', -1};
  103. for(i=0; buffer[i]!=-1; i++) {
  104. c = buffer[i];
  105. TEST( isdigit(c)!=TRUE);
  106. }
  107. }
  108. /* isgraph() */
  109. {
  110. int buffer[]={ ')', '~', '9', -1};
  111. for(i=0; buffer[i]!=-1; i++) {
  112. c = buffer[i];
  113. TEST( isgraph(c)==TRUE);
  114. }
  115. }
  116. {
  117. int buffer[]={ 9, ' ', '\t', '\n', 200, 0x7F, -1};
  118. for(i=0; buffer[i]!=-1; i++) {
  119. c = buffer[i];
  120. TEST( isgraph(c)!=TRUE);
  121. }
  122. }
  123. /* islower() */
  124. {
  125. int buffer[]={ 'a', 'g', 'z', -1};
  126. for(i=0; buffer[i]!=-1; i++) {
  127. c = buffer[i];
  128. TEST( islower(c)==TRUE);
  129. }
  130. }
  131. {
  132. int buffer[]={ 9, 'A', 'Z', 128, 254, ' ', '\t', '\n', 0x7F, -1};
  133. for(i=0; buffer[i]!=-1; i++) {
  134. c = buffer[i];
  135. TEST( islower(c)!=TRUE);
  136. }
  137. }
  138. /* isprint() */
  139. {
  140. int buffer[]={ ' ', ')', '~', '9', -1};
  141. for(i=0; buffer[i]!=-1; i++) {
  142. c = buffer[i];
  143. TEST( isprint(c)==TRUE);
  144. }
  145. }
  146. {
  147. int buffer[]={ '\b', '\t', '\n', 9, 128, 254, 200, 0x7F, -1};
  148. for(i=0; buffer[i]!=-1; i++) {
  149. c = buffer[i];
  150. TEST( isprint(c)!=TRUE);
  151. }
  152. }
  153. /* ispunct() */
  154. {
  155. int buffer[]={ '.', '#', '@', ';', -1};
  156. for(i=0; buffer[i]!=-1; i++) {
  157. c = buffer[i];
  158. TEST( ispunct(c)==TRUE);
  159. }
  160. }
  161. {
  162. int buffer[]={ 2, 'a', 'Z', '1', 128, 254, '\n', -1};
  163. for(i=0; buffer[i]!=-1; i++) {
  164. c = buffer[i];
  165. TEST( ispunct(c)!=TRUE);
  166. }
  167. }
  168. /* isspace() */
  169. {
  170. int buffer[]={ ' ', '\t', '\r', '\v', '\n', -1};
  171. for(i=0; buffer[i]!=-1; i++) {
  172. c = buffer[i];
  173. TEST( isspace(c)==TRUE);
  174. }
  175. }
  176. {
  177. int buffer[]={ 2, 'a', 'Z', '1', 128, 254, -1};
  178. for(i=0; buffer[i]!=-1; i++) {
  179. c = buffer[i];
  180. TEST( isspace(c)!=TRUE);
  181. }
  182. }
  183. /* isupper() */
  184. {
  185. int buffer[]={ 'A', 'G', 'Z', -1};
  186. for(i=0; buffer[i]!=-1; i++) {
  187. c = buffer[i];
  188. TEST( isupper(c)==TRUE);
  189. }
  190. }
  191. {
  192. int buffer[]={ 2, 'a', 'z', '1', 128, 254, -1};
  193. for(i=0; buffer[i]!=-1; i++) {
  194. c = buffer[i];
  195. TEST( isupper(c)!=TRUE);
  196. }
  197. }
  198. /* isxdigit() */
  199. {
  200. int buffer[]={ 'f', 'A', '1', '8', -1};
  201. for(i=0; buffer[i]!=-1; i++) {
  202. c = buffer[i];
  203. TEST( isxdigit(c)==TRUE);
  204. }
  205. }
  206. {
  207. int buffer[]={ 2, 'g', 'G', 'x', '\n', -1};
  208. for(i=0; buffer[i]!=-1; i++) {
  209. c = buffer[i];
  210. TEST( isxdigit(c)!=TRUE);
  211. }
  212. }
  213. /* tolower() */
  214. c='A';
  215. TEST_NUMERIC( tolower(c), 'a');
  216. c='a';
  217. TEST_NUMERIC( tolower(c), 'a');
  218. c='#';
  219. TEST_NUMERIC( tolower(c), c);
  220. /* toupper() */
  221. c='a';
  222. TEST_NUMERIC( toupper(c), 'A');
  223. c='A';
  224. TEST_NUMERIC( toupper(c), 'A');
  225. c='#';
  226. TEST_NUMERIC( toupper(c), c);
  227. exit(0);
  228. }