Add a changelog entry for fixing bug 1237.
[tor.git] / debian / src-test-test.h
blobed0eb316ad05ea0ec1090c789c646580c838d98e
1 /* Copyright (c) 2001-2003, Roger Dingledine.
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2009, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
6 #ifndef _TOR_TEST_H
7 #define _TOR_TEST_H
9 /**
10 * \file test.h
11 * \brief Macros and functions used by unit tests.
14 #include "compat.h"
15 #include "tinytest.h"
16 #define TT_EXIT_TEST_FUNCTION STMT_BEGIN goto done; STMT_END
17 #include "tinytest_macros.h"
19 #ifdef __GNUC__
20 #define PRETTY_FUNCTION __PRETTY_FUNCTION__
21 #else
22 #define PRETTY_FUNCTION ""
23 #endif
25 #define test_fail_msg(msg) TT_DIE((msg))
27 #define test_fail() test_fail_msg("Assertion failed.")
29 #define test_assert(expr) tt_assert(expr)
31 #define test_eq(expr1, expr2) tt_int_op((expr1), ==, (expr2))
32 #define test_eq_ptr(expr1, expr2) tt_ptr_op((expr1), ==, (expr2))
33 #define test_neq(expr1, expr2) tt_int_op((expr1), !=, (expr2))
34 #define test_neq_ptr(expr1, expr2) tt_ptr_op((expr1), !=, (expr2))
35 #define test_streq(expr1, expr2) tt_str_op((expr1), ==, (expr2))
36 #define test_strneq(expr1, expr2) tt_str_op((expr1), !=, (expr2))
37 #define test_streq(expr1, expr2) tt_str_op((expr1), ==, (expr2))
39 #define test_mem_op(expr1, op, expr2, len) \
40 tt_assert_test_fmt_type(expr1,expr2,#expr1" "#op" "#expr2, \
41 const char *, \
42 (memcmp(_val1, _val2, len) op 0), \
43 char *, "%s", \
44 { size_t printlen = (len)*2+1; \
45 _print = tor_malloc(printlen); \
46 base16_encode(_print, printlen, _value, \
47 (len)); }, \
48 { tor_free(_print); } \
51 #define test_memeq(expr1, expr2, len) test_mem_op((expr1), ==, (expr2), len)
52 #define test_memneq(expr1, expr2, len) test_mem_op((expr1), !=, (expr2), len)
54 /* As test_mem_op, but decodes 'hex' before comparing. There must be a
55 * local char* variable called mem_op_hex_tmp for this to work. */
56 #define test_mem_op_hex(expr1, op, hex) \
57 STMT_BEGIN \
58 size_t length = strlen(hex); \
59 tor_free(mem_op_hex_tmp); \
60 mem_op_hex_tmp = tor_malloc(length/2); \
61 tor_assert((length&1)==0); \
62 base16_decode(mem_op_hex_tmp, length/2, hex, length); \
63 test_mem_op(expr1, op, mem_op_hex_tmp, length/2); \
64 STMT_END
66 #define test_memeq_hex(expr1, hex) test_mem_op_hex(expr1, ==, hex)
68 const char *get_fname(const char *name);
69 crypto_pk_env_t *pk_generate(int idx);
71 void legacy_test_helper(void *data);
72 extern const struct testcase_setup_t legacy_setup;
74 #endif