author | Tero Marttila <terom@fixme.fi> |
Wed, 27 May 2009 23:57:48 +0300 | |
branch | new-lib-errors |
changeset 217 | 7728d6ec3abf |
parent 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 |
/** |
|
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 | 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 | 37 |
|
38 |
/** |
|
39 |
* Assert that the given pointer value is NULL. |
|
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 | 43 |
|
44 |
/** |
|
45 |
* Assert that the given NUL-terminated string matches the given target string exactly. |
|
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 | 49 |
|
50 |
/** |
|
51 |
* Assert that the first \a n chars of the first string matches the second string exactly. |
|
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 | 55 |
|
56 |
/** |
|
57 |
* Assert that the given \a str is \a n chars long. |
|
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 | 61 |
|
62 |
/** |
|
63 |
* Assert that the given \a str is NULL. |
|
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 | 67 |
|
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 | 75 |
* Assert that the given error code is SUCCESS. |
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 | 79 |
|
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 | 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 | 85 |
|
86 |
/** |
|
87 |
* Assert that the given actual error \a is matches the expected error \a should_be |
|
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 | 91 |
|
92 |
#endif |