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-- |
168 | 1 |
#ifndef TEST_ASSERT_H |
2 |
#define TEST_ASSERT_H |
|
3 |
||
4 |
/** |
|
5 |
* @file |
|
6 |
* |
|
7 |
* Various general assert-condition tests used to fail tests |
|
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 | 10 |
#include "../error.h" |
11 |
||
12 |
/* |
|
13 |
* Also accept the existance of the system assert() function |
|
14 |
*/ |
|
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 | 22 |
|
23 |
/** |
|
24 |
* Assert that the given condition is true, and fail with the given error if not |
|
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 | 32 |
|
33 |
/** |
|
34 |
* Assert that the given pointer value is NULL. |
|
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 | 38 |
|
39 |
/** |
|
40 |
* Assert that the given NUL-terminated string matches the given target string exactly. |
|
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 | 44 |
|
45 |
/** |
|
46 |
* Assert that the first \a n chars of the first string matches the second string exactly. |
|
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 | 50 |
|
51 |
/** |
|
52 |
* Assert that the given \a str is \a n chars long. |
|
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 | 56 |
|
57 |
/** |
|
58 |
* Assert that the given \a str is NULL. |
|
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 | 62 |
|
63 |
/** |
|
64 |
* Assert that the given error code is SUCCESS. |
|
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 | 68 |
|
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 | 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 | 74 |
|
75 |
/** |
|
76 |
* Assert that the given actual error \a is matches the expected error \a should_be |
|
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 | 80 |
|
81 |
#endif |