BRL-CAD
bu_str_isprint.c
Go to the documentation of this file.
1 /* T E S T _ C T Y P E . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2007-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 
22 #include "common.h"
23 
24 #include <string.h>
25 #include <ctype.h>
26 
27 #include "bu.h"
28 
29 
30 int
31 test_str_isprint(const char *inp , int exp)
32 {
33  int res;
34  res = bu_str_isprint(inp);
35  if (res == exp) {
36 
37  if (res)
38  printf("Testing with string : %10s is printable->PASSED!\n", inp);
39  else
40  printf("Given string not printable->PASSED!\n");
41 
42  return 1;
43  }
44  printf("Failed\n");
45  return 0;
46 }
47 
48 
49 int
50 main(int argc, char **argv)
51 {
52  int test_num = 0;
53 
54  if (argc < 2) {
55  fprintf(stderr,"Usage: %s test_num\n", argv[0]);
56  return 1;
57  }
58 
59  sscanf(argv[1], "%d", &test_num);
60 
61  switch (test_num) {
62  case 1:
63  return !test_str_isprint("abc", 1);
64  case 2:
65  return !test_str_isprint("abc123\n", 0); /* \n is end of line -not printable */
66  case 3:
67  return !test_str_isprint("abc123\\n1!", 1);
68  case 4:
69  return !test_str_isprint("123\txyz", 0); /* \t is horizontal tab - not printable */
70  case 5:
71  return !test_str_isprint("#$ ab12", 1);
72  case 6:
73  return !test_str_isprint("#$%\n 748", 0); /* \n is end of line -not printable */
74  case 7:
75  return !test_str_isprint("#$^\ry", 0); /* \r is carriage return - not printable */
76  }
77 
78  return 1;
79 }
80 
81 
82 /*
83  * Local Variables:
84  * mode: C
85  * tab-width: 8
86  * indent-tabs-mode: t
87  * c-file-style: "stroustrup"
88  * End:
89  * ex: shiftwidth=4 tabstop=8
90  */
Header file for the BRL-CAD common definitions.
int main(int argc, char **argv)
int bu_str_isprint(const char *cp)
Definition: ctype.c:28
int test_str_isprint(const char *inp, int exp)