Back to index

tor  0.2.3.19-rc
Defines | Functions
test.h File Reference

Macros and functions used by unit tests. More...

#include "compat.h"
#include "tinytest.h"
#include "tinytest_macros.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define TT_EXIT_TEST_FUNCTION   STMT_BEGIN goto done; STMT_END
#define PRETTY_FUNCTION   ""
#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)
#define test_memeq(expr1, expr2, len)   test_mem_op((expr1), ==, (expr2), len)
#define test_memneq(expr1, expr2, len)   test_mem_op((expr1), !=, (expr2), len)
#define test_mem_op_hex(expr1, op, hex)
#define test_memeq_hex(expr1, hex)   test_mem_op_hex(expr1, ==, hex)

Functions

const char * get_fname (const char *name)
 Return a filename relative to our testing temporary directory.
crypto_pk_tpk_generate (int idx)
 Generate and return a new keypair for use in unit tests.
void legacy_test_helper (void *data)

Detailed Description

Macros and functions used by unit tests.

Definition in file test.h.


Define Documentation

#define PRETTY_FUNCTION   ""

Definition at line 22 of file test.h.

#define test_assert (   expr)    tt_assert(expr)

Definition at line 29 of file test.h.

#define test_eq (   expr1,
  expr2 
)    tt_int_op((expr1), ==, (expr2))

Definition at line 31 of file test.h.

#define test_eq_ptr (   expr1,
  expr2 
)    tt_ptr_op((expr1), ==, (expr2))

Definition at line 32 of file test.h.

#define test_fail ( )    test_fail_msg("Assertion failed.")

Definition at line 27 of file test.h.

#define test_fail_msg (   msg)    TT_DIE((msg))

Definition at line 25 of file test.h.

#define test_mem_op (   expr1,
  op,
  expr2,
  len 
)
Value:
tt_assert_test_fmt_type(expr1,expr2,#expr1" "#op" "#expr2,            \
                          const char *,                                 \
                          (memcmp(val1_, val2_, len) op 0),             \
                          char *, "%s",                                 \
                          { size_t printlen = (len)*2+1;                \
                            print_ = tor_malloc(printlen);              \
                            base16_encode(print_, printlen, value_,     \
                                          (len)); },                    \
                          { tor_free(print_); },                        \
                          TT_EXIT_TEST_FUNCTION                         \
                          );

Definition at line 38 of file test.h.

#define test_mem_op_hex (   expr1,
  op,
  hex 
)
Value:
STMT_BEGIN                                                            \
  size_t length = strlen(hex);                                          \
  tor_free(mem_op_hex_tmp);                                             \
  mem_op_hex_tmp = tor_malloc(length/2);                                \
  tor_assert((length&1)==0);                                            \
  base16_decode(mem_op_hex_tmp, length/2, hex, length);                 \
  test_mem_op(expr1, op, mem_op_hex_tmp, length/2);                     \
  STMT_END

Definition at line 56 of file test.h.

#define test_memeq (   expr1,
  expr2,
  len 
)    test_mem_op((expr1), ==, (expr2), len)

Definition at line 51 of file test.h.

#define test_memeq_hex (   expr1,
  hex 
)    test_mem_op_hex(expr1, ==, hex)

Definition at line 66 of file test.h.

#define test_memneq (   expr1,
  expr2,
  len 
)    test_mem_op((expr1), !=, (expr2), len)

Definition at line 52 of file test.h.

#define test_neq (   expr1,
  expr2 
)    tt_int_op((expr1), !=, (expr2))

Definition at line 33 of file test.h.

#define test_neq_ptr (   expr1,
  expr2 
)    tt_ptr_op((expr1), !=, (expr2))

Definition at line 34 of file test.h.

#define test_streq (   expr1,
  expr2 
)    tt_str_op((expr1), ==, (expr2))

Definition at line 35 of file test.h.

#define test_strneq (   expr1,
  expr2 
)    tt_str_op((expr1), !=, (expr2))

Definition at line 36 of file test.h.

#define TT_EXIT_TEST_FUNCTION   STMT_BEGIN goto done; STMT_END

Definition at line 16 of file test.h.


Function Documentation

const char* get_fname ( const char *  name)

Return a filename relative to our testing temporary directory.

Definition at line 115 of file test.c.

{
  static char buf[1024];
  setup_directory();
  if (!name)
    return temp_dir;
  tor_snprintf(buf,sizeof(buf),"%s/%s",temp_dir,name);
  return buf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void legacy_test_helper ( void *  data)

Definition at line 1801 of file test.c.

{
  void (*fn)(void) = data;
  fn();
}
crypto_pk_t* pk_generate ( int  idx)

Generate and return a new keypair for use in unit tests.

If we're using the key cache optimization, we might reuse keys: we only guarantee that keys made with distinct values for idx are different. The value of idx must be at least 0, and less than N_PREGEN_KEYS.

Definition at line 178 of file test.c.

{
#ifdef CACHE_GENERATED_KEYS
  tor_assert(idx < N_PREGEN_KEYS);
  if (! pregen_keys[idx]) {
    pregen_keys[idx] = crypto_pk_new();
    tor_assert(!crypto_pk_generate_key(pregen_keys[idx]));
  }
  return crypto_pk_dup_key(pregen_keys[idx]);
#else
  crypto_pk_t *result;
  (void) idx;
  result = crypto_pk_new();
  tor_assert(!crypto_pk_generate_key(result));
  return result;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function: