]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/ctype_internal_test.c
Make sure we use the libctx when creating an EVP_PKEY_CTX in libssl
[thirdparty/openssl.git] / test / ctype_internal_test.c
CommitLineData
a1df06b3 1/*
b0edda11 2 * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
a1df06b3 3 *
909f1a2e 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
a1df06b3
P
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"
25f2138b 11#include "crypto/ctype.h"
677963e5 12#include "internal/nelem.h"
a1df06b3
P
13#include <ctype.h>
14#include <stdio.h>
15
12bd06cd
RL
16/*
17 * Even though the VMS C RTL claims to be C99 compatible, it's not entirely
ab9c0d28
AP
18 * so far (C RTL version 8.4). Same applies to OSF. For the sake of these
19 * tests, we therefore define our own.
12bd06cd 20 */
ab9c0d28 21#if (defined(__VMS) && __CRTL_VER <= 80400000) || defined(__osf__)
12bd06cd
RL
22static int isblank(int c)
23{
24 return c == ' ' || c == '\t';
25}
26#endif
27
a1df06b3
P
28static int test_ctype_chars(int n)
29{
da9b249f
P
30 if (!TEST_int_eq(isascii((unsigned char)n) != 0, ossl_isascii(n) != 0))
31 return 0;
32
33 if (!ossl_isascii(n))
34 return 1;
35
36 return TEST_int_eq(isalpha(n) != 0, ossl_isalpha(n) != 0)
37 && TEST_int_eq(isalnum(n) != 0, ossl_isalnum(n) != 0)
ab9c0d28 38#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
a1df06b3 39 && TEST_int_eq(isblank(n) != 0, ossl_isblank(n) != 0)
ab9c0d28 40#endif
a1df06b3
P
41 && TEST_int_eq(iscntrl(n) != 0, ossl_iscntrl(n) != 0)
42 && TEST_int_eq(isdigit(n) != 0, ossl_isdigit(n) != 0)
43 && TEST_int_eq(isgraph(n) != 0, ossl_isgraph(n) != 0)
44 && TEST_int_eq(islower(n) != 0, ossl_islower(n) != 0)
45 && TEST_int_eq(isprint(n) != 0, ossl_isprint(n) != 0)
46 && TEST_int_eq(ispunct(n) != 0, ossl_ispunct(n) != 0)
47 && TEST_int_eq(isspace(n) != 0, ossl_isspace(n) != 0)
48 && TEST_int_eq(isupper(n) != 0, ossl_isupper(n) != 0)
49 && TEST_int_eq(isxdigit(n) != 0, ossl_isxdigit(n) != 0);
50}
51
a1df06b3
P
52static struct {
53 int u;
54 int l;
55} case_change[] = {
56 { 'A', 'a' },
57 { 'X', 'x' },
58 { 'Z', 'z' },
59 { '0', '0' },
60 { '%', '%' },
61 { '~', '~' },
62 { 0, 0 },
196f5c4b 63 { EOF, EOF }
a1df06b3
P
64};
65
66static int test_ctype_toupper(int n)
67{
68 return TEST_int_eq(ossl_toupper(case_change[n].l), case_change[n].u)
69 && TEST_int_eq(ossl_toupper(case_change[n].u), case_change[n].u);
70}
71
72static int test_ctype_tolower(int n)
73{
74 return TEST_int_eq(ossl_tolower(case_change[n].u), case_change[n].l)
75 && TEST_int_eq(ossl_tolower(case_change[n].l), case_change[n].l);
76}
77
678c462e
P
78static int test_ctype_eof(void)
79{
80 return test_ctype_chars(EOF);
81}
82
a1df06b3
P
83int setup_tests(void)
84{
da9b249f 85 ADD_ALL_TESTS(test_ctype_chars, 256);
a1df06b3
P
86 ADD_ALL_TESTS(test_ctype_toupper, OSSL_NELEM(case_change));
87 ADD_ALL_TESTS(test_ctype_tolower, OSSL_NELEM(case_change));
678c462e 88 ADD_TEST(test_ctype_eof);
a1df06b3
P
89 return 1;
90}