author | Tero Marttila <terom@fixme.fi> |
Wed, 20 May 2009 22:53:05 +0300 | |
branch | lua-threads |
changeset 203 | ffdf53fd0337 |
parent 196 | 873796250c60 |
permissions | -rw-r--r-- |
168 | 1 |
#include "assert.h" |
2 |
#include "util.h" |
|
3 |
||
4 |
#include <string.h> |
|
5 |
||
6 |
||
194
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
7 |
#define _ASSERT_FUNC_FAIL(...) test_fail(func, file, line, 1, __VA_ARGS__) |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
8 |
|
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
9 |
void _assert_null (_ASSERT_FUNC_ARGS, const void *ptr) |
168 | 10 |
{ |
194
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
11 |
if (ptr) |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
12 |
_ASSERT_FUNC_FAIL("%p != NULL", ptr); |
168 | 13 |
} |
14 |
||
194
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
15 |
void _assert_strcmp (_ASSERT_FUNC_ARGS, const char *is, const char *should_be) |
168 | 16 |
{ |
189
f351facab1f0
add a test/backtrace module and have ASSERT_FAIL dump out a backtrace, also, fix assert_str[n]cmp to handle should_be == NULL
Tero Marttila <terom@fixme.fi>
parents:
168
diff
changeset
|
17 |
if (!should_be && !is) |
f351facab1f0
add a test/backtrace module and have ASSERT_FAIL dump out a backtrace, also, fix assert_str[n]cmp to handle should_be == NULL
Tero Marttila <terom@fixme.fi>
parents:
168
diff
changeset
|
18 |
return; |
194
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
19 |
|
168 | 20 |
if (!is || strcmp(is, should_be)) |
194
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
21 |
_ASSERT_FUNC_FAIL("%s != %s", dump_str(is), dump_str(should_be)); |
168 | 22 |
} |
23 |
||
194
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
24 |
void _assert_strncmp (_ASSERT_FUNC_ARGS, const char *is, const char *should_be, size_t n) |
168 | 25 |
{ |
194
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
26 |
if (!should_be && !is) |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
27 |
return; |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
28 |
|
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
29 |
if (!is || 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:
189
diff
changeset
|
30 |
_ASSERT_FUNC_FAIL("%s:%u != %s", dump_strn(is, n), (unsigned) n, dump_strn(should_be, n)); |
168 | 31 |
} |
32 |
||
194
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
33 |
void _assert_strlen (_ASSERT_FUNC_ARGS, const char *str, size_t n) |
168 | 34 |
{ |
194
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
35 |
if (!str || strlen(str) != n) |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
36 |
_ASSERT_FUNC_FAIL("strlen(%s) != %u", dump_str(str), (unsigned) n); |
168 | 37 |
} |
38 |
||
194
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
39 |
void _assert_strnull (_ASSERT_FUNC_ARGS, const char *str) |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
40 |
{ |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
41 |
if (str) |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
42 |
_ASSERT_FUNC_FAIL("%s != NULL", dump_str(str)); |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
43 |
} |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
44 |
|
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
|
45 |
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
|
46 |
{ |
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
|
47 |
if (!should_be && !is) |
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
|
48 |
return; |
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
|
49 |
|
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
|
50 |
if (!is || 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
|
51 |
_ASSERT_FUNC_FAIL("%s:%zu != %s", dump_strn(is, len), len, dump_strn(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
|
52 |
} |
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
|
53 |
|
194
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
54 |
void _assert_success (_ASSERT_FUNC_ARGS, err_t err) |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
55 |
{ |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
56 |
if (err) |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
57 |
_ASSERT_FUNC_FAIL("err: %s", dump_str(error_name(err))); |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
58 |
} |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
59 |
|
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
60 |
void _assert_err (_ASSERT_FUNC_ARGS, err_t is, err_t should_be) |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
61 |
{ |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
62 |
if (is != should_be) |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
63 |
_ASSERT_FUNC_FAIL("err: %s != %s", dump_str(error_name(is)), dump_str(error_name(should_be))); |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
64 |
} |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
65 |
|
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
|
66 |
void _assert_error (_ASSERT_FUNC_ARGS, const error_t *is, const error_t *should_be) |
168 | 67 |
{ |
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
|
68 |
if (!error_cmp_eq(is, should_be)) |
194
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
69 |
_ASSERT_FUNC_FAIL("error: %s != %s", dump_str(error_msg(is)), dump_str(error_msg(should_be))); |
808b1b047620
add a new test/fail module, and rewrite test/assert to use it
Tero Marttila <terom@fixme.fi>
parents:
189
diff
changeset
|
70 |
|
168 | 71 |
} |