]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/test_test.c
Update the internal siphash tests to use the framework's output.
[thirdparty/openssl.git] / test / test_test.c
CommitLineData
2fae041d
P
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/*
11 * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
12 */
13
14#include <stdio.h>
15#include <string.h>
16
17#include <openssl/opensslconf.h>
18#include <openssl/err.h>
19#include <openssl/crypto.h>
20
21#include "e_os.h"
22#include "test_main.h"
23#include "testutil.h"
24
25#define C(l, b, t) \
26 if ((t) != b) { \
27 fprintf(stderr, "FATAL : %s != %d\n", #t, b); \
28 goto l; \
29 }
30
31static int test_int(void)
32{
33 C(err, 1, TEST_int_eq(1, 1));
34 C(err, 0, TEST_int_eq(1, -1));
35 C(err, 1, TEST_int_ne(1, 2));
36 C(err, 0, TEST_int_ne(3, 3));
37 C(err, 1, TEST_int_lt(4, 9));
38 C(err, 0, TEST_int_lt(9, 4));
39 C(err, 1, TEST_int_le(4, 9));
40 C(err, 1, TEST_int_le(5, 5));
41 C(err, 0, TEST_int_le(9, 4));
42 C(err, 1, TEST_int_gt(8, 5));
43 C(err, 0, TEST_int_gt(5, 8));
44 C(err, 1, TEST_int_ge(8, 5));
45 C(err, 1, TEST_int_ge(6, 6));
46 C(err, 0, TEST_int_ge(5, 8));
47 return 1;
48
49err:
50 return 0;
51}
52
53static int test_uint(void)
54{
55 C(err, 1, TEST_uint_eq(3u, 3u));
56 C(err, 0, TEST_uint_eq(3u, 5u));
57 C(err, 1, TEST_uint_ne(4u, 2u));
58 C(err, 0, TEST_uint_ne(6u, 6u));
59 C(err, 1, TEST_uint_lt(5u, 9u));
60 C(err, 0, TEST_uint_lt(9u, 5u));
61 C(err, 1, TEST_uint_le(5u, 9u));
62 C(err, 1, TEST_uint_le(7u, 7u));
63 C(err, 0, TEST_uint_le(9u, 5u));
64 C(err, 1, TEST_uint_gt(11u, 1u));
65 C(err, 0, TEST_uint_gt(1u, 11u));
66 C(err, 1, TEST_uint_ge(11u, 1u));
67 C(err, 1, TEST_uint_ge(6u, 6u));
68 C(err, 0, TEST_uint_ge(1u, 11u));
69 return 1;
70
71err:
72 return 0;
73}
74
75static int test_char(void)
76{
77 C(err, 1, TEST_char_eq('a', 'a'));
78 C(err, 0, TEST_char_eq('a', 'A'));
79 C(err, 1, TEST_char_ne('a', 'c'));
80 C(err, 0, TEST_char_ne('e', 'e'));
81 C(err, 1, TEST_char_lt('i', 'x'));
82 C(err, 0, TEST_char_lt('x', 'i'));
83 C(err, 1, TEST_char_le('i', 'x'));
84 C(err, 1, TEST_char_le('n', 'n'));
85 C(err, 0, TEST_char_le('x', 'i'));
86 C(err, 1, TEST_char_gt('w', 'n'));
87 C(err, 0, TEST_char_gt('n', 'w'));
88 C(err, 1, TEST_char_ge('w', 'n'));
89 C(err, 1, TEST_char_ge('p', 'p'));
90 C(err, 0, TEST_char_ge('n', 'w'));
91 return 1;
92
93err:
94 return 0;
95}
96
97static int test_uchar(void)
98{
99 C(err, 1, TEST_uchar_eq(49, 49));
100 C(err, 0, TEST_uchar_eq(49, 60));
101 C(err, 1, TEST_uchar_ne(50, 2));
102 C(err, 0, TEST_uchar_ne(66, 66));
103 C(err, 1, TEST_uchar_lt(60, 80));
104 C(err, 0, TEST_uchar_lt(80, 60));
105 C(err, 1, TEST_uchar_le(60, 80));
106 C(err, 1, TEST_uchar_le(78, 78));
107 C(err, 0, TEST_uchar_le(80, 60));
108 C(err, 1, TEST_uchar_gt(88, 37));
109 C(err, 0, TEST_uchar_gt(37, 88));
110 C(err, 1, TEST_uchar_ge(88, 37));
111 C(err, 1, TEST_uchar_ge(66, 66));
112 C(err, 0, TEST_uchar_ge(37, 88));
113 return 1;
114
115err:
116 return 0;
117}
118
119static int test_long(void)
120{
121 C(err, 1, TEST_long_eq(123l, 123l));
122 C(err, 0, TEST_long_eq(123l, -123l));
123 C(err, 1, TEST_long_ne(123l, 500l));
124 C(err, 0, TEST_long_ne(1000l, 1000l));
125 C(err, 1, TEST_long_lt(-8923l, 102934563l));
126 C(err, 0, TEST_long_lt(102934563l, -8923l));
127 C(err, 1, TEST_long_le(-8923l, 102934563l));
128 C(err, 1, TEST_long_le(12345l, 12345l));
129 C(err, 0, TEST_long_le(102934563l, -8923l));
130 C(err, 1, TEST_long_gt(84325677l, 12345l));
131 C(err, 0, TEST_long_gt(12345l, 84325677l));
132 C(err, 1, TEST_long_ge(84325677l, 12345l));
133 C(err, 1, TEST_long_ge(465869l, 465869l));
134 C(err, 0, TEST_long_ge(12345l, 84325677l));
135 return 1;
136
137err:
138 return 0;
139}
140
141static int test_ulong(void)
142{
143 C(err, 1, TEST_ulong_eq(919ul, 919ul));
144 C(err, 0, TEST_ulong_eq(919ul, 10234ul));
145 C(err, 1, TEST_ulong_ne(8190ul, 66ul));
146 C(err, 0, TEST_ulong_ne(10555ul, 10555ul));
147 C(err, 1, TEST_ulong_lt(10234ul, 1000000ul));
148 C(err, 0, TEST_ulong_lt(1000000ul, 10234ul));
149 C(err, 1, TEST_ulong_le(10234ul, 1000000ul));
150 C(err, 1, TEST_ulong_le(100000ul, 100000ul));
151 C(err, 0, TEST_ulong_le(1000000ul, 10234ul));
152 C(err, 1, TEST_ulong_gt(100000000ul, 22ul));
153 C(err, 0, TEST_ulong_gt(22ul, 100000000ul));
154 C(err, 1, TEST_ulong_ge(100000000ul, 22ul));
155 C(err, 1, TEST_ulong_ge(10555ul, 10555ul));
156 C(err, 0, TEST_ulong_ge(22ul, 100000000ul));
157 return 1;
158
159err:
160 return 0;
161}
162
163static int test_size_t(void)
164{
165 C(err, 1, TEST_int_eq((size_t)10, (size_t)10));
166 C(err, 0, TEST_int_eq((size_t)10, (size_t)12));
167 C(err, 1, TEST_int_ne((size_t)10, (size_t)12));
168 C(err, 0, TEST_int_ne((size_t)24, (size_t)24));
169 C(err, 1, TEST_int_lt((size_t)30, (size_t)88));
170 C(err, 0, TEST_int_lt((size_t)88, (size_t)30));
171 C(err, 1, TEST_int_le((size_t)30, (size_t)88));
172 C(err, 1, TEST_int_le((size_t)33, (size_t)33));
173 C(err, 0, TEST_int_le((size_t)88, (size_t)30));
174 C(err, 1, TEST_int_gt((size_t)52, (size_t)33));
175 C(err, 0, TEST_int_gt((size_t)33, (size_t)52));
176 C(err, 1, TEST_int_ge((size_t)52, (size_t)33));
177 C(err, 1, TEST_int_ge((size_t)38, (size_t)38));
178 C(err, 0, TEST_int_ge((size_t)33, (size_t)52));
179 return 1;
180
181err:
182 return 0;
183}
184
185static int test_pointer(void)
186{
187 int x = 0;
188 char y = 1;
189
190 C(err, 1, TEST_ptr(&y));
191 C(err, 0, TEST_ptr(NULL));
192 C(err, 0, TEST_ptr_null(&y));
193 C(err, 1, TEST_ptr_null(NULL));
194 C(err, 1, TEST_ptr_eq(NULL, NULL));
195 C(err, 0, TEST_ptr_eq(NULL, &y));
196 C(err, 0, TEST_ptr_eq(&y, NULL));
197 C(err, 0, TEST_ptr_eq(&y, &x));
198 C(err, 1, TEST_ptr_eq(&x, &x));
199 C(err, 0, TEST_ptr_ne(NULL, NULL));
200 C(err, 1, TEST_ptr_ne(NULL, &y));
201 C(err, 1, TEST_ptr_ne(&y, NULL));
202 C(err, 1, TEST_ptr_ne(&y, &x));
203 C(err, 0, TEST_ptr_ne(&x, &x));
204 return 1;
205
206err:
207 return 0;
208}
209
210static int test_bool(void)
211{
212 C(err, 0, TEST_true(0));
213 C(err, 1, TEST_true(1));
214 C(err, 1, TEST_false(0));
215 C(err, 0, TEST_false(1));
216 return 1;
217
218err:
219 return 0;
220}
221
222static int test_string(void)
223{
224 static char buf[] = "abc";
225 C(err, 1, TEST_str_eq(NULL, NULL));
226 C(err, 1, TEST_str_eq("abc", buf));
227 C(err, 0, TEST_str_eq("abc", NULL));
228 C(err, 0, TEST_str_eq(NULL, buf));
229 C(err, 0, TEST_str_ne(NULL, NULL));
230 C(err, 0, TEST_str_ne("abc", buf));
231 C(err, 1, TEST_str_ne("abc", NULL));
232 C(err, 1, TEST_str_ne(NULL, buf));
233 return 1;
234
235err:
236 return 0;
237}
238
239static int test_memory(void)
240{
241 static char buf[] = "xyz";
242 C(err, 1, TEST_mem_eq(NULL, 0, NULL, 0));
243 C(err, 1, TEST_mem_eq(NULL, 1, NULL, 2));
244 C(err, 0, TEST_mem_eq(NULL, 0, "xyz", 3));
245 C(err, 0, TEST_mem_eq(NULL, 0, "", 0));
246 C(err, 0, TEST_mem_eq("xyz", 3, NULL, 0));
247 C(err, 0, TEST_mem_eq("xyz", 3, buf, sizeof(buf)));
248 C(err, 1, TEST_mem_eq("xyz", 4, buf, sizeof(buf)));
249 return 1;
250
251err:
252 return 0;
253}
254
255static int test_messages(void)
256{
257 TEST_info("This is an %s message.", "info");
258 TEST_error("This is an %s message.", "error");
259 return 1;
260}
261
262void register_tests(void)
263{
264 ADD_TEST(test_int);
265 ADD_TEST(test_uint);
266 ADD_TEST(test_char);
267 ADD_TEST(test_uchar);
268 ADD_TEST(test_long);
269 ADD_TEST(test_ulong);
270 ADD_TEST(test_size_t);
271 ADD_TEST(test_pointer);
272 ADD_TEST(test_bool);
273 ADD_TEST(test_string);
274 ADD_TEST(test_memory);
275 ADD_TEST(test_messages);
276}