aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_ptr_slow.c
diff options
context:
space:
mode:
authorrl1987 <rl1987@sdf.lonestar.org>2019-02-25 19:07:47 +0200
committerrl1987 <rl1987@sdf.lonestar.org>2019-02-25 20:04:02 +0200
commitd731ab45831cfc2104b17b3a623e0c89c3174145 (patch)
tree20cac7ef2f3107a20d4d86ce276a8e3077080234 /src/test/test_ptr_slow.c
parent69238ca2da923c8a50d5c1007f3e702eea163b50 (diff)
downloadtor-d731ab45831cfc2104b17b3a623e0c89c3174145.tar.gz
tor-d731ab45831cfc2104b17b3a623e0c89c3174145.zip
Check that all valid values of int and unsigned int can be put into void pointer
Diffstat (limited to 'src/test/test_ptr_slow.c')
-rw-r--r--src/test/test_ptr_slow.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/test/test_ptr_slow.c b/src/test/test_ptr_slow.c
new file mode 100644
index 0000000000..a5914c9120
--- /dev/null
+++ b/src/test/test_ptr_slow.c
@@ -0,0 +1,67 @@
+/* Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2019, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#include "orconfig.h"
+#include "core/or/or.h"
+#include "test/test.h"
+
+#include <stdint.h>
+#include <limits.h>
+
+/** Check that all values of int can be cast to void * and back. */
+static void
+test_int_voidstar_interop(void *arg)
+{
+ int a;
+ (void)arg;
+
+ for (a = INT_MIN; a < INT_MAX; a++) {
+ intptr_t ap = (intptr_t)a;
+ void *b = (void *)ap;
+ intptr_t c = (intptr_t)b;
+ void *d = (void *)c;
+
+ tt_assert(ap == c);
+ tt_assert(b == d);
+ }
+
+ done:
+ return;
+}
+
+/** Check that all values of unsigned int can be cast to void * and back. */
+static void
+test_uint_voidstar_interop(void *arg)
+{
+ unsigned int a;
+ (void)arg;
+
+ for (a = 0; a < UINT_MAX; a++) {
+ intptr_t ap = (intptr_t)a;
+ void *b = (void *)ap;
+ intptr_t c = (intptr_t)b;
+ void *d = (void *)c;
+
+ tt_assert(ap == c);
+ tt_assert(b == d);
+ }
+
+ done:
+ return;
+}
+
+struct testcase_t slow_ptr_tests[] = {
+ { .name = "int_voidstar_interop",
+ .fn = test_int_voidstar_interop,
+ .flags = 0,
+ .setup = NULL,
+ .setup_data = NULL },
+ { .name = "uint_voidstar_interop",
+ .fn = test_uint_voidstar_interop,
+ .flags = 0,
+ .setup = NULL,
+ .setup_data = NULL },
+ END_OF_TESTCASES
+};