Fix the lack of isblank() with VMS C
[openssl.git] / test / ctype_internal_test.c
1 /*
2  * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #include "testutil.h"
11 #include "internal/ctype.h"
12 #include "../e_os.h"
13 #include <ctype.h>
14 #include <stdio.h>
15
16 /*
17  * Even though the VMS C RTL claims to be C99 compatible, it's not entirely
18  * so far (C RTL version 8.4).  For the sake of these tests, we therefore
19  * define our own.
20  */
21 #if defined(__VMS) && __CRTL_VER <= 80400000
22 static int isblank(int c)
23 {
24     return c == ' ' || c == '\t';
25 }
26 #endif
27
28 static int test_ctype_chars(int n)
29 {
30     return TEST_int_eq(isalnum(n) != 0, ossl_isalnum(n) != 0)
31            && TEST_int_eq(isalpha(n) != 0, ossl_isalpha(n) != 0)
32            && TEST_int_eq(isascii(n) != 0, ossl_isascii(n) != 0)
33            && TEST_int_eq(isblank(n) != 0, ossl_isblank(n) != 0)
34            && TEST_int_eq(iscntrl(n) != 0, ossl_iscntrl(n) != 0)
35            && TEST_int_eq(isdigit(n) != 0, ossl_isdigit(n) != 0)
36            && TEST_int_eq(isgraph(n) != 0, ossl_isgraph(n) != 0)
37            && TEST_int_eq(islower(n) != 0, ossl_islower(n) != 0)
38            && TEST_int_eq(isprint(n) != 0, ossl_isprint(n) != 0)
39            && TEST_int_eq(ispunct(n) != 0, ossl_ispunct(n) != 0)
40            && TEST_int_eq(isspace(n) != 0, ossl_isspace(n) != 0)
41            && TEST_int_eq(isupper(n) != 0, ossl_isupper(n) != 0)
42            && TEST_int_eq(isxdigit(n) != 0, ossl_isxdigit(n) != 0);
43 }
44
45 static int test_ctype_negative(int n)
46 {
47     return test_ctype_chars(-n);
48 }
49
50 static struct {
51     int u;
52     int l;
53 } case_change[] = {
54     { 'A', 'a' },
55     { 'X', 'x' },
56     { 'Z', 'z' },
57     { '0', '0' },
58     { '%', '%' },
59     { '~', '~' },
60     {   0,   0 },
61     { EOF, EOF },
62     { 333, 333 },
63     { -333, -333 },
64     { -128, -128 }
65 };
66
67 static int test_ctype_toupper(int n)
68 {
69     return TEST_int_eq(ossl_toupper(case_change[n].l), case_change[n].u)
70            && TEST_int_eq(ossl_toupper(case_change[n].u), case_change[n].u);
71 }
72
73 static int test_ctype_tolower(int n)
74 {
75     return TEST_int_eq(ossl_tolower(case_change[n].u), case_change[n].l)
76            && TEST_int_eq(ossl_tolower(case_change[n].l), case_change[n].l);
77 }
78
79 int setup_tests(void)
80 {
81     ADD_ALL_TESTS(test_ctype_chars, 256);
82     ADD_ALL_TESTS(test_ctype_negative, 128);
83     ADD_ALL_TESTS(test_ctype_toupper, OSSL_NELEM(case_change));
84     ADD_ALL_TESTS(test_ctype_tolower, OSSL_NELEM(case_change));
85     return 1;
86 }