2009-09-21 14:23:13 -04:00
|
|
|
/* Copyright (c) 2001-2003, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2013-01-16 01:54:56 -05:00
|
|
|
* Copyright (c) 2007-2013, The Tor Project, Inc. */
|
2009-09-21 14:23:13 -04:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
2012-10-12 12:13:10 -04:00
|
|
|
#ifndef TOR_TEST_H
|
|
|
|
#define TOR_TEST_H
|
2009-09-21 14:23:13 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \file test.h
|
2009-09-22 13:06:47 -04:00
|
|
|
* \brief Macros and functions used by unit tests.
|
2009-09-21 14:23:13 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "compat.h"
|
|
|
|
#include "tinytest.h"
|
|
|
|
#define TT_EXIT_TEST_FUNCTION STMT_BEGIN goto done; STMT_END
|
|
|
|
#include "tinytest_macros.h"
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define PRETTY_FUNCTION __PRETTY_FUNCTION__
|
|
|
|
#else
|
|
|
|
#define PRETTY_FUNCTION ""
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define test_fail_msg(msg) TT_DIE((msg))
|
|
|
|
|
|
|
|
#define test_fail() test_fail_msg("Assertion failed.")
|
|
|
|
|
|
|
|
#define test_assert(expr) tt_assert(expr)
|
|
|
|
|
|
|
|
#define test_eq(expr1, expr2) tt_int_op((expr1), ==, (expr2))
|
|
|
|
#define test_eq_ptr(expr1, expr2) tt_ptr_op((expr1), ==, (expr2))
|
|
|
|
#define test_neq(expr1, expr2) tt_int_op((expr1), !=, (expr2))
|
|
|
|
#define test_neq_ptr(expr1, expr2) tt_ptr_op((expr1), !=, (expr2))
|
|
|
|
#define test_streq(expr1, expr2) tt_str_op((expr1), ==, (expr2))
|
|
|
|
#define test_strneq(expr1, expr2) tt_str_op((expr1), !=, (expr2))
|
|
|
|
|
|
|
|
#define test_mem_op(expr1, op, expr2, len) \
|
2014-03-06 18:06:08 -05:00
|
|
|
tt_mem_op((expr1), op, (expr2), (len))
|
2009-09-21 14:23:13 -04:00
|
|
|
|
|
|
|
#define test_memeq(expr1, expr2, len) test_mem_op((expr1), ==, (expr2), len)
|
|
|
|
#define test_memneq(expr1, expr2, len) test_mem_op((expr1), !=, (expr2), len)
|
|
|
|
|
2009-09-27 12:07:33 -04:00
|
|
|
/* As test_mem_op, but decodes 'hex' before comparing. There must be a
|
|
|
|
* local char* variable called mem_op_hex_tmp for this to work. */
|
2009-09-21 14:23:13 -04:00
|
|
|
#define test_mem_op_hex(expr1, op, hex) \
|
|
|
|
STMT_BEGIN \
|
|
|
|
size_t length = strlen(hex); \
|
2009-09-27 12:07:33 -04:00
|
|
|
tor_free(mem_op_hex_tmp); \
|
|
|
|
mem_op_hex_tmp = tor_malloc(length/2); \
|
2009-09-21 14:23:13 -04:00
|
|
|
tor_assert((length&1)==0); \
|
2009-09-27 12:07:33 -04:00
|
|
|
base16_decode(mem_op_hex_tmp, length/2, hex, length); \
|
|
|
|
test_mem_op(expr1, op, mem_op_hex_tmp, length/2); \
|
2009-09-21 14:23:13 -04:00
|
|
|
STMT_END
|
|
|
|
|
|
|
|
#define test_memeq_hex(expr1, hex) test_mem_op_hex(expr1, ==, hex)
|
|
|
|
|
2012-08-09 13:47:42 -04:00
|
|
|
#define tt_double_op(a,op,b) \
|
|
|
|
tt_assert_test_type(a,b,#a" "#op" "#b,double,(val1_ op val2_),"%f", \
|
|
|
|
TT_EXIT_TEST_FUNCTION)
|
|
|
|
|
2009-09-22 13:06:47 -04:00
|
|
|
const char *get_fname(const char *name);
|
2012-01-18 15:53:30 -05:00
|
|
|
crypto_pk_t *pk_generate(int idx);
|
2009-09-22 13:06:47 -04:00
|
|
|
|
|
|
|
void legacy_test_helper(void *data);
|
|
|
|
extern const struct testcase_setup_t legacy_setup;
|
|
|
|
|
2009-09-21 14:23:13 -04:00
|
|
|
#endif
|
|
|
|
|