Back to index

tor  0.2.3.18-rc
test.h
Go to the documentation of this file.
00001 /* Copyright (c) 2001-2003, Roger Dingledine.
00002  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
00003  * Copyright (c) 2007-2012, The Tor Project, Inc. */
00004 /* See LICENSE for licensing information */
00005 
00006 #ifndef _TOR_TEST_H
00007 #define _TOR_TEST_H
00008 
00014 #include "compat.h"
00015 #include "tinytest.h"
00016 #define TT_EXIT_TEST_FUNCTION STMT_BEGIN goto done; STMT_END
00017 #include "tinytest_macros.h"
00018 
00019 #ifdef __GNUC__
00020 #define PRETTY_FUNCTION __PRETTY_FUNCTION__
00021 #else
00022 #define PRETTY_FUNCTION ""
00023 #endif
00024 
00025 #define test_fail_msg(msg) TT_DIE((msg))
00026 
00027 #define test_fail() test_fail_msg("Assertion failed.")
00028 
00029 #define test_assert(expr) tt_assert(expr)
00030 
00031 #define test_eq(expr1, expr2) tt_int_op((expr1), ==, (expr2))
00032 #define test_eq_ptr(expr1, expr2) tt_ptr_op((expr1), ==, (expr2))
00033 #define test_neq(expr1, expr2) tt_int_op((expr1), !=, (expr2))
00034 #define test_neq_ptr(expr1, expr2) tt_ptr_op((expr1), !=, (expr2))
00035 #define test_streq(expr1, expr2) tt_str_op((expr1), ==, (expr2))
00036 #define test_strneq(expr1, expr2) tt_str_op((expr1), !=, (expr2))
00037 
00038 #define test_mem_op(expr1, op, expr2, len)                              \
00039   tt_assert_test_fmt_type(expr1,expr2,#expr1" "#op" "#expr2,            \
00040                           const char *,                                 \
00041                           (memcmp(val1_, val2_, len) op 0),             \
00042                           char *, "%s",                                 \
00043                           { size_t printlen = (len)*2+1;                \
00044                             print_ = tor_malloc(printlen);              \
00045                             base16_encode(print_, printlen, value_,     \
00046                                           (len)); },                    \
00047                           { tor_free(print_); },                        \
00048                           TT_EXIT_TEST_FUNCTION                         \
00049                           );
00050 
00051 #define test_memeq(expr1, expr2, len) test_mem_op((expr1), ==, (expr2), len)
00052 #define test_memneq(expr1, expr2, len) test_mem_op((expr1), !=, (expr2), len)
00053 
00054 /* As test_mem_op, but decodes 'hex' before comparing.  There must be a
00055  * local char* variable called mem_op_hex_tmp for this to work. */
00056 #define test_mem_op_hex(expr1, op, hex)                                 \
00057   STMT_BEGIN                                                            \
00058   size_t length = strlen(hex);                                          \
00059   tor_free(mem_op_hex_tmp);                                             \
00060   mem_op_hex_tmp = tor_malloc(length/2);                                \
00061   tor_assert((length&1)==0);                                            \
00062   base16_decode(mem_op_hex_tmp, length/2, hex, length);                 \
00063   test_mem_op(expr1, op, mem_op_hex_tmp, length/2);                     \
00064   STMT_END
00065 
00066 #define test_memeq_hex(expr1, hex) test_mem_op_hex(expr1, ==, hex)
00067 
00068 const char *get_fname(const char *name);
00069 crypto_pk_t *pk_generate(int idx);
00070 
00071 void legacy_test_helper(void *data);
00072 extern const struct testcase_setup_t legacy_setup;
00073 
00074 #endif
00075