Refrain from doing exhaustive iteration over all values of integers
[tor.git] / src / test / test_ptr_slow.c
blob632a304177bde96bea463770e19863f9ba48a4e5
1 /* Copyright (c) 2001-2004, Roger Dingledine.
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2019, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
6 #include "orconfig.h"
7 #include "core/or/or.h"
8 #include "test/test.h"
10 #include <stdint.h>
11 #include <limits.h>
13 /** Assert that <b>a</b> can be cast to void * and back. */
14 static void
15 assert_int_voidptr_roundtrip(int a)
17 intptr_t ap = (intptr_t)a;
18 void *b = (void *)ap;
19 intptr_t c = (intptr_t)b;
20 void *d = (void *)c;
22 tt_assert(ap == c);
23 tt_assert(b == d);
25 done:
26 return;
29 static void
30 test_int_voidstar_interop(void *arg)
32 int a;
33 (void)arg;
35 for (a = 0; a <= 1024; a++) {
36 assert_int_voidptr_roundtrip(a);
39 for (a = INT_MAX-1024; a < INT_MAX; a++) {
40 assert_int_voidptr_roundtrip(a);
44 static void
45 assert_uint_voidptr_roundtrip(unsigned int a)
47 intptr_t ap = (intptr_t)a;
48 void *b = (void *)ap;
49 intptr_t c = (intptr_t)b;
50 void *d = (void *)c;
52 tt_assert(ap == c);
53 tt_assert(b == d);
55 done:
56 return;
59 static void
60 test_uint_voidstar_interop(void *arg)
62 unsigned int a;
63 (void)arg;
65 for (a = 0; a <= 1024; a++) {
66 assert_uint_voidptr_roundtrip(a);
69 for (a = UINT_MAX-1024; a < UINT_MAX; a++) {
70 assert_uint_voidptr_roundtrip(a);
74 struct testcase_t slow_ptr_tests[] = {
75 { .name = "int_voidstar_interop",
76 .fn = test_int_voidstar_interop,
77 .flags = 0,
78 .setup = NULL,
79 .setup_data = NULL },
80 { .name = "uint_voidstar_interop",
81 .fn = test_uint_voidstar_interop,
82 .flags = 0,
83 .setup = NULL,
84 .setup_data = NULL },
85 END_OF_TESTCASES