src/test/assert.h
author Tero Marttila <terom@fixme.fi>
Wed, 27 May 2009 23:57:48 +0300
branchnew-lib-errors
changeset 217 7728d6ec3abf
parent 196 873796250c60
permissions -rw-r--r--
nexus.c compiles
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#ifndef TEST_ASSERT_H
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#define TEST_ASSERT_H
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
 * @file
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
 *
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
 * Various general assert-condition tests used to fail tests
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
 */
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
     9
#include "fail.h"
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
#include "../error.h"
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
/*
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
 * Also accept the existance of the system assert() function
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
 */
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
#include <assert.h>
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    16
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    17
/*
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    18
 * Internal shorthand macros for passing func/file/line args
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    19
 */
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    20
#define _ASSERT_FUNC_ARGS const char *func, const char *file, int line
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    21
#define _ASSERT_FUNC_CALL(func, ...) func(__func__, __FILE__, __LINE__, __VA_ARGS__)
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
/**
196
873796250c60 implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents: 194
diff changeset
    24
 * Assert that the given condition is true
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
 */
196
873796250c60 implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents: 194
diff changeset
    26
#define assert_true(cond) fail_if(!(cond), "assert_true(%s)", #cond)
873796250c60 implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents: 194
diff changeset
    27
873796250c60 implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents: 194
diff changeset
    28
/**
873796250c60 implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents: 194
diff changeset
    29
 * Assert that the given condition is not true
873796250c60 implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents: 194
diff changeset
    30
 */
873796250c60 implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents: 194
diff changeset
    31
#define assert_false(cond) fail_if(cond, "assert_false(%s)", #cond)
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    32
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    33
/**
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    34
 * Assert failure unconditionally
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    35
 */
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    36
#define assert_fail(...) fail(__VA_ARGS__)
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    38
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    39
 * Assert that the given pointer value is NULL.
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
 */
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    41
#define assert_null(ptr) _ASSERT_FUNC_CALL(_assert_null, ptr)
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    42
void _assert_null (_ASSERT_FUNC_ARGS, const void *ptr);
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    43
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    44
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    45
 * Assert that the given NUL-terminated string matches the given target string exactly.
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    46
 */
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    47
#define assert_strcmp(is, should_be) _ASSERT_FUNC_CALL(_assert_strcmp, is, should_be)
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    48
void _assert_strcmp (_ASSERT_FUNC_ARGS, const char *is, const char *should_be);
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    50
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
 * Assert that the first \a n chars of the first string matches the second string exactly.
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
 */
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    53
#define assert_strncmp(is, should_be, n) _ASSERT_FUNC_CALL(_assert_strncmp, is, should_be, n)
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    54
void _assert_strncmp (_ASSERT_FUNC_ARGS, const char *is, const char *should_be, size_t n);
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    55
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    56
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    57
 * Assert that the given \a str is \a n chars long.
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    58
 */
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    59
#define assert_strlen(str, n) _ASSERT_FUNC_CALL(_assert_strlen, str, n)
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    60
void _assert_strlen (_ASSERT_FUNC_ARGS, const char *str, size_t n);
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    61
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    62
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    63
 * Assert that the given \a str is NULL.
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    64
 */
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    65
#define assert_strnull(str) _ASSERT_FUNC_CALL(_assert_strnull, str)
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    66
void _assert_strnull (_ASSERT_FUNC_ARGS, const char *str);
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    68
/**
196
873796250c60 implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents: 194
diff changeset
    69
 * Assert that the two given buffers contain the same data using memcmp().
873796250c60 implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents: 194
diff changeset
    70
 */
873796250c60 implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents: 194
diff changeset
    71
#define assert_memcmp(is, should_be, len) _ASSERT_FUNC_CALL(_assert_memcmp, is, should_be, len)
873796250c60 implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents: 194
diff changeset
    72
void _assert_memcmp(_ASSERT_FUNC_ARGS, const char *is, const char *should_be, size_t len);
873796250c60 implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents: 194
diff changeset
    73
873796250c60 implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents: 194
diff changeset
    74
/**
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    75
 * Assert that the given error code is SUCCESS.
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    76
 */
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    77
#define assert_success(err) _ASSERT_FUNC_CALL(_assert_success, err)
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    78
void _assert_success (_ASSERT_FUNC_ARGS, err_t err);
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    79
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    80
/**
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    81
 * Assert that the given actual error code \a err matches the expected error code \a should_be.
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    82
 */
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    83
#define assert_err(is, should_be) _ASSERT_FUNC_CALL(_assert_err, is, should_be)
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    84
void _assert_err (_ASSERT_FUNC_ARGS, err_t is, err_t should_be);
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    85
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    86
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    87
 * Assert that the given actual error \a is matches the expected error \a should_be
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    88
 */ 
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    89
#define assert_error(is, should_be) _ASSERT_FUNC_CALL(_assert_error, is, should_be)
196
873796250c60 implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents: 194
diff changeset
    90
void _assert_error (_ASSERT_FUNC_ARGS, const error_t *is, const error_t *should_be);
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    91
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    92
#endif