ctype.c 4.9 KB

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