2009-09-21 20:23:13 +02:00
|
|
|
/* Copyright (c) 2001-2003, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2012-06-05 02:58:17 +02:00
|
|
|
* Copyright (c) 2007-2012, The Tor Project, Inc. */
|
2009-09-21 20:23:13 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
2012-10-12 18:13:10 +02:00
|
|
|
#ifndef TOR_TEST_H
|
|
|
|
#define TOR_TEST_H
|
2009-09-21 20:23:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \file test.h
|
2009-09-22 19:06:47 +02:00
|
|
|
* \brief Macros and functions used by unit tests.
|
2009-09-21 20:23:13 +02: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) \
|
|
|
|
tt_assert_test_fmt_type(expr1,expr2,#expr1" "#op" "#expr2, \
|
|
|
|
const char *, \
|
2012-02-13 23:45:15 +01:00
|
|
|
(memcmp(val1_, val2_, len) op 0), \
|
2009-09-21 20:23:13 +02:00
|
|
|
char *, "%s", \
|
|
|
|
{ size_t printlen = (len)*2+1; \
|
2012-02-13 23:45:15 +01:00
|
|
|
print_ = tor_malloc(printlen); \
|
|
|
|
base16_encode(print_, printlen, value_, \
|
2009-09-21 20:23:13 +02:00
|
|
|
(len)); }, \
|
2012-02-13 23:45:15 +01:00
|
|
|
{ tor_free(print_); }, \
|
2011-06-09 23:30:09 +02:00
|
|
|
TT_EXIT_TEST_FUNCTION \
|
2009-09-21 20:23:13 +02: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 18:07:33 +02: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 20:23:13 +02:00
|
|
|
#define test_mem_op_hex(expr1, op, hex) \
|
|
|
|
STMT_BEGIN \
|
|
|
|
size_t length = strlen(hex); \
|
2009-09-27 18:07:33 +02:00
|
|
|
tor_free(mem_op_hex_tmp); \
|
|
|
|
mem_op_hex_tmp = tor_malloc(length/2); \
|
2009-09-21 20:23:13 +02:00
|
|
|
tor_assert((length&1)==0); \
|
2009-09-27 18:07:33 +02: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 20:23:13 +02:00
|
|
|
STMT_END
|
|
|
|
|
|
|
|
#define test_memeq_hex(expr1, hex) test_mem_op_hex(expr1, ==, hex)
|
|
|
|
|
2012-08-09 19:47:42 +02: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 19:06:47 +02:00
|
|
|
const char *get_fname(const char *name);
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_pk_t *pk_generate(int idx);
|
2009-09-22 19:06:47 +02:00
|
|
|
|
|
|
|
void legacy_test_helper(void *data);
|
|
|
|
extern const struct testcase_setup_t legacy_setup;
|
|
|
|
|
2009-09-21 20:23:13 +02:00
|
|
|
#endif
|
|
|
|
|