From be20834b7620ca448217d8dfc3c0a1b2e1d5b3da Mon Sep 17 00:00:00 2001
From: Alon Zakai <alonzakai@gmail.com>
Date: Tue, 18 Oct 2011 16:07:01 -0700
Subject: [PATCH] fix test_ctype for newlib

---
 tests/ctype/output.txt | 104 +++++++++++++++++++++++
 tests/ctype/src.c      | 187 ++++++++++++++++++++---------------------
 2 files changed, 196 insertions(+), 95 deletions(-)

diff --git a/tests/ctype/output.txt b/tests/ctype/output.txt
index 43775583e..5212c40ab 100644
--- a/tests/ctype/output.txt
+++ b/tests/ctype/output.txt
@@ -125,3 +125,107 @@ isascii('A'): 1
 isascii('5'): 1
 isascii('.'): 1
 isascii(183): 0
+
+islower(-45): 0
+islower( 10): 0
+islower('a'): 1
+islower('A'): 0
+islower('5'): 0
+islower('.'): 0
+islower(183): 0
+
+isupper(-45): 0
+isupper( 10): 0
+isupper('a'): 0
+isupper('A'): 1
+isupper('5'): 0
+isupper('.'): 0
+isupper(183): 0
+
+isupper(-45): 0
+isupper( 10): 0
+isupper('a'): 0
+isupper('A'): 1
+isupper('5'): 0
+isupper('.'): 0
+isupper(183): 0
+
+isalpha(-45): 0
+isalpha( 10): 0
+isalpha('a'): 1
+isalpha('A'): 1
+isalpha('5'): 0
+isalpha('.'): 0
+isalpha(183): 0
+
+isdigit(-45): 0
+isdigit( 10): 0
+isdigit('a'): 0
+isdigit('A'): 0
+isdigit('5'): 1
+isdigit('.'): 0
+isdigit(183): 0
+
+isxdigit(-45): 0
+isxdigit( 10): 0
+isxdigit('a'): 1
+isxdigit('A'): 1
+isxdigit('5'): 1
+isxdigit('.'): 0
+isxdigit(183): 0
+
+isalnum(-45): 0
+isalnum( 10): 0
+isalnum('a'): 1
+isalnum('A'): 1
+isalnum('5'): 1
+isalnum('.'): 0
+isalnum(183): 0
+
+ispunct(-45): 0
+ispunct( 10): 0
+ispunct('a'): 0
+ispunct('A'): 0
+ispunct('5'): 0
+ispunct('.'): 1
+ispunct(183): 0
+
+isspace(-45): 0
+isspace( 10): 1
+isspace('a'): 0
+isspace('A'): 0
+isspace('5'): 0
+isspace('.'): 0
+isspace(183): 0
+
+isblank(-45): 0
+isblank( 10): 0
+isblank('a'): 0
+isblank('A'): 0
+isblank('5'): 0
+isblank('.'): 0
+isblank(183): 0
+
+iscntrl(-45): 0
+iscntrl( 10): 1
+iscntrl('a'): 0
+iscntrl('A'): 0
+iscntrl('5'): 0
+iscntrl('.'): 0
+iscntrl(183): 0
+
+isprint(-45): 0
+isprint( 10): 0
+isprint('a'): 1
+isprint('A'): 1
+isprint('5'): 1
+isprint('.'): 1
+isprint(183): 0
+
+isgraph(-45): 0
+isgraph( 10): 0
+isgraph('a'): 1
+isgraph('A'): 1
+isgraph('5'): 1
+isgraph('.'): 1
+isgraph(183): 0
diff --git a/tests/ctype/src.c b/tests/ctype/src.c
index 34436c3b4..3fe99b256 100644
--- a/tests/ctype/src.c
+++ b/tests/ctype/src.c
@@ -73,127 +73,124 @@ int main() {
   printf("isascii('.'): %d\n", isascii('.') != 0);
   printf("isascii(183): %d\n", isascii(183) != 0);
 
-  /* These appear to require glibc headers and fail with newlib
-
   // These are manually preprocessed to use __ctype_b_loc. The flags combination
   // that the test runner uses seems to cause the macro to be ignored.
   printf("\n");
-  printf("islower(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISlower) != 0);
-  printf("islower( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISlower) != 0);
-  printf("islower('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISlower) != 0);
-  printf("islower('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISlower) != 0);
-  printf("islower('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISlower) != 0);
-  printf("islower('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISlower) != 0);
-  printf("islower(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISlower) != 0);
+  printf("islower(-45): %d\n", islower(-45));
+  printf("islower( 10): %d\n", islower(10));
+  printf("islower('a'): %d\n", islower('a'));
+  printf("islower('A'): %d\n", islower('A'));
+  printf("islower('5'): %d\n", islower('5'));
+  printf("islower('.'): %d\n", islower('.'));
+  printf("islower(183): %d\n", islower(183));
 
   printf("\n");
-  printf("isupper(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISupper) != 0);
-  printf("isupper( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISupper) != 0);
-  printf("isupper('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISupper) != 0);
-  printf("isupper('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISupper) != 0);
-  printf("isupper('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISupper) != 0);
-  printf("isupper('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISupper) != 0);
-  printf("isupper(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISupper) != 0);
+  printf("isupper(-45): %d\n", isupper(-45));
+  printf("isupper( 10): %d\n", isupper(10));
+  printf("isupper('a'): %d\n", isupper('a'));
+  printf("isupper('A'): %d\n", isupper('A'));
+  printf("isupper('5'): %d\n", isupper('5'));
+  printf("isupper('.'): %d\n", isupper('.'));
+  printf("isupper(183): %d\n", isupper(183));
 
   printf("\n");
-  printf("isupper(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISupper) != 0);
-  printf("isupper( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISupper) != 0);
-  printf("isupper('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISupper) != 0);
-  printf("isupper('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISupper) != 0);
-  printf("isupper('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISupper) != 0);
-  printf("isupper('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISupper) != 0);
-  printf("isupper(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISupper) != 0);
+  printf("isupper(-45): %d\n", isupper(-45));
+  printf("isupper( 10): %d\n", isupper(10));
+  printf("isupper('a'): %d\n", isupper('a'));
+  printf("isupper('A'): %d\n", isupper('A'));
+  printf("isupper('5'): %d\n", isupper('5'));
+  printf("isupper('.'): %d\n", isupper('.'));
+  printf("isupper(183): %d\n", isupper(183));
 
   printf("\n");
-  printf("isalpha(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISalpha) != 0);
-  printf("isalpha( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISalpha) != 0);
-  printf("isalpha('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISalpha) != 0);
-  printf("isalpha('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISalpha) != 0);
-  printf("isalpha('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISalpha) != 0);
-  printf("isalpha('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISalpha) != 0);
-  printf("isalpha(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISalpha) != 0);
+  printf("isalpha(-45): %d\n", isalpha(-45));
+  printf("isalpha( 10): %d\n", isalpha(10));
+  printf("isalpha('a'): %d\n", isalpha('a'));
+  printf("isalpha('A'): %d\n", isalpha('A'));
+  printf("isalpha('5'): %d\n", isalpha('5'));
+  printf("isalpha('.'): %d\n", isalpha('.'));
+  printf("isalpha(183): %d\n", isalpha(183));
 
   printf("\n");
-  printf("isdigit(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISdigit) != 0);
-  printf("isdigit( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISdigit) != 0);
-  printf("isdigit('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISdigit) != 0);
-  printf("isdigit('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISdigit) != 0);
-  printf("isdigit('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISdigit) != 0);
-  printf("isdigit('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISdigit) != 0);
-  printf("isdigit(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISdigit) != 0);
+  printf("isdigit(-45): %d\n", isdigit(-45));
+  printf("isdigit( 10): %d\n", isdigit(10));
+  printf("isdigit('a'): %d\n", isdigit('a'));
+  printf("isdigit('A'): %d\n", isdigit('A'));
+  printf("isdigit('5'): %d\n", isdigit('5'));
+  printf("isdigit('.'): %d\n", isdigit('.'));
+  printf("isdigit(183): %d\n", isdigit(183));
 
   printf("\n");
-  printf("isxdigit(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISxdigit) != 0);
-  printf("isxdigit( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISxdigit) != 0);
-  printf("isxdigit('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISxdigit) != 0);
-  printf("isxdigit('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISxdigit) != 0);
-  printf("isxdigit('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISxdigit) != 0);
-  printf("isxdigit('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISxdigit) != 0);
-  printf("isxdigit(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISxdigit) != 0);
+  printf("isxdigit(-45): %d\n", isxdigit(-45));
+  printf("isxdigit( 10): %d\n", isxdigit(10));
+  printf("isxdigit('a'): %d\n", isxdigit('a'));
+  printf("isxdigit('A'): %d\n", isxdigit('A'));
+  printf("isxdigit('5'): %d\n", isxdigit('5'));
+  printf("isxdigit('.'): %d\n", isxdigit('.'));
+  printf("isxdigit(183): %d\n", isxdigit(183));
 
   printf("\n");
-  printf("isalnum(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISalnum) != 0);
-  printf("isalnum( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISalnum) != 0);
-  printf("isalnum('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISalnum) != 0);
-  printf("isalnum('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISalnum) != 0);
-  printf("isalnum('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISalnum) != 0);
-  printf("isalnum('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISalnum) != 0);
-  printf("isalnum(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISalnum) != 0);
+  printf("isalnum(-45): %d\n", isalnum(-45));
+  printf("isalnum( 10): %d\n", isalnum(10));
+  printf("isalnum('a'): %d\n", isalnum('a'));
+  printf("isalnum('A'): %d\n", isalnum('A'));
+  printf("isalnum('5'): %d\n", isalnum('5'));
+  printf("isalnum('.'): %d\n", isalnum('.'));
+  printf("isalnum(183): %d\n", isalnum(183));
 
   printf("\n");
-  printf("ispunct(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISpunct) != 0);
-  printf("ispunct( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISpunct) != 0);
-  printf("ispunct('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISpunct) != 0);
-  printf("ispunct('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISpunct) != 0);
-  printf("ispunct('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISpunct) != 0);
-  printf("ispunct('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISpunct) != 0);
-  printf("ispunct(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISpunct) != 0);
+  printf("ispunct(-45): %d\n", ispunct(-45));
+  printf("ispunct( 10): %d\n", ispunct(10));
+  printf("ispunct('a'): %d\n", ispunct('a'));
+  printf("ispunct('A'): %d\n", ispunct('A'));
+  printf("ispunct('5'): %d\n", ispunct('5'));
+  printf("ispunct('.'): %d\n", ispunct('.'));
+  printf("ispunct(183): %d\n", ispunct(183));
 
   printf("\n");
-  printf("isspace(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISspace) != 0);
-  printf("isspace( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISspace) != 0);
-  printf("isspace('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISspace) != 0);
-  printf("isspace('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISspace) != 0);
-  printf("isspace('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISspace) != 0);
-  printf("isspace('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISspace) != 0);
-  printf("isspace(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISspace) != 0);
+  printf("isspace(-45): %d\n", isspace(-45));
+  printf("isspace( 10): %d\n", isspace(10));
+  printf("isspace('a'): %d\n", isspace('a'));
+  printf("isspace('A'): %d\n", isspace('A'));
+  printf("isspace('5'): %d\n", isspace('5'));
+  printf("isspace('.'): %d\n", isspace('.'));
+  printf("isspace(183): %d\n", isspace(183));
 
   printf("\n");
-  printf("isblank(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISblank) != 0);
-  printf("isblank( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISblank) != 0);
-  printf("isblank('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISblank) != 0);
-  printf("isblank('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISblank) != 0);
-  printf("isblank('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISblank) != 0);
-  printf("isblank('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISblank) != 0);
-  printf("isblank(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISblank) != 0);
+  printf("isblank(-45): %d\n", isblank(-45));
+  printf("isblank( 10): %d\n", isblank(10));
+  printf("isblank('a'): %d\n", isblank('a'));
+  printf("isblank('A'): %d\n", isblank('A'));
+  printf("isblank('5'): %d\n", isblank('5'));
+  printf("isblank('.'): %d\n", isblank('.'));
+  printf("isblank(183): %d\n", isblank(183));
 
   printf("\n");
-  printf("iscntrl(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _IScntrl) != 0);
-  printf("iscntrl( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _IScntrl) != 0);
-  printf("iscntrl('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _IScntrl) != 0);
-  printf("iscntrl('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _IScntrl) != 0);
-  printf("iscntrl('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _IScntrl) != 0);
-  printf("iscntrl('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _IScntrl) != 0);
-  printf("iscntrl(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _IScntrl) != 0);
+  printf("iscntrl(-45): %d\n", iscntrl(-45));
+  printf("iscntrl( 10): %d\n", iscntrl(10));
+  printf("iscntrl('a'): %d\n", iscntrl('a'));
+  printf("iscntrl('A'): %d\n", iscntrl('A'));
+  printf("iscntrl('5'): %d\n", iscntrl('5'));
+  printf("iscntrl('.'): %d\n", iscntrl('.'));
+  printf("iscntrl(183): %d\n", iscntrl(183));
 
   printf("\n");
-  printf("isprint(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISprint) != 0);
-  printf("isprint( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISprint) != 0);
-  printf("isprint('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISprint) != 0);
-  printf("isprint('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISprint) != 0);
-  printf("isprint('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISprint) != 0);
-  printf("isprint('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISprint) != 0);
-  printf("isprint(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISprint) != 0);
+  printf("isprint(-45): %d\n", isprint(-45));
+  printf("isprint( 10): %d\n", isprint(10));
+  printf("isprint('a'): %d\n", isprint('a'));
+  printf("isprint('A'): %d\n", isprint('A'));
+  printf("isprint('5'): %d\n", isprint('5'));
+  printf("isprint('.'): %d\n", isprint('.'));
+  printf("isprint(183): %d\n", isprint(183));
 
   printf("\n");
-  printf("isgraph(-45): %d\n", ((*__ctype_b_loc ())[(int) ((-45))] & (unsigned short int) _ISgraph) != 0);
-  printf("isgraph( 10): %d\n", ((*__ctype_b_loc ())[(int) ((10))] & (unsigned short int) _ISgraph) != 0);
-  printf("isgraph('a'): %d\n", ((*__ctype_b_loc ())[(int) (('a'))] & (unsigned short int) _ISgraph) != 0);
-  printf("isgraph('A'): %d\n", ((*__ctype_b_loc ())[(int) (('A'))] & (unsigned short int) _ISgraph) != 0);
-  printf("isgraph('5'): %d\n", ((*__ctype_b_loc ())[(int) (('5'))] & (unsigned short int) _ISgraph) != 0);
-  printf("isgraph('.'): %d\n", ((*__ctype_b_loc ())[(int) (('.'))] & (unsigned short int) _ISgraph) != 0);
-  printf("isgraph(183): %d\n", ((*__ctype_b_loc ())[(int) ((183))] & (unsigned short int) _ISgraph) != 0);
-  */
-
+  printf("isgraph(-45): %d\n", isgraph(-45));
+  printf("isgraph( 10): %d\n", isgraph(10));
+  printf("isgraph('a'): %d\n", isgraph('a'));
+  printf("isgraph('A'): %d\n", isgraph('A'));
+  printf("isgraph('5'): %d\n", isgraph('5'));
+  printf("isgraph('.'): %d\n", isgraph('.'));
+  printf("isgraph(183): %d\n", isgraph(183));
+ 
   return 0;
 }