src/test/assert.h
author Tero Marttila <terom@fixme.fi>
Fri, 08 May 2009 01:43:02 +0300
changeset 194 808b1b047620
parent 168 a58ad50911fc
child 196 873796250c60
permissions -rw-r--r--
add a new test/fail module, and rewrite test/assert to use it
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
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
 * Assert that the given condition is true, and fail with the given error if not
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
 */
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    26
#define assert_true(cond, ...) fail_if(cond, __VA_ARGS__)
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    27
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    28
/**
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    29
 * 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
    30
 */
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    31
#define assert_fail(...) fail(__VA_ARGS__)
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    32
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
 * Assert that the given pointer value is NULL.
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
 */
194
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_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
    37
void _assert_null (_ASSERT_FUNC_ARGS, const void *ptr);
168
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
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
 * 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
    41
 */
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    42
#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
    43
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
    44
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    45
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    46
 * 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
    47
 */
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    48
#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
    49
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
    50
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
 * 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
    53
 */
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    54
#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
    55
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
    56
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    57
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    58
 * Assert that the given \a str is NULL.
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    59
 */
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    60
#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
    61
void _assert_strnull (_ASSERT_FUNC_ARGS, const char *str);
168
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
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    64
 * Assert that the given error code is SUCCESS.
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    65
 */
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    66
#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
    67
void _assert_success (_ASSERT_FUNC_ARGS, err_t err);
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    68
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    69
/**
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    70
 * 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
    71
 */
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    72
#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
    73
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
    74
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    75
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    76
 * 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
    77
 */ 
194
808b1b047620 add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents: 168
diff changeset
    78
#define assert_error(is, should_be) _ASSERT_FUNC_CALL(_assert_error, 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
    79
void _assert_error (_ASSERT_FUNC_ARGS, error_t *is, error_t *should_be);
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    80
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    81
#endif