diff options
author | sanine <sanine.not@pm.me> | 2022-04-04 16:04:17 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-04-04 16:04:17 -0500 |
commit | 2cef2d4e0bb490f8e5002e47368bac8e89dbeb88 (patch) | |
tree | f057ad4af920bc06f68c4df7a1da68af90b6be3e | |
parent | 5e3d8e950d97a222b15d41de1ae17ccf51621471 (diff) |
add LILY_NARGS()
-rw-r--r-- | lily-test.h | 23 | ||||
-rw-r--r-- | tests/main.c | 1 | ||||
-rw-r--r-- | tests/mock_queue.c | 17 | ||||
-rw-r--r-- | tests/tests.h | 1 |
4 files changed, 38 insertions, 4 deletions
diff --git a/lily-test.h b/lily-test.h index 1e604fe..51b440f 100644 --- a/lily-test.h +++ b/lily-test.h @@ -114,6 +114,7 @@ void _lily_assert_memory_not_equal(const char *name_a, const char *name_b, * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + typedef struct lily_queue_t { size_t buf_size; uint8_t *buf; @@ -124,10 +125,10 @@ typedef struct lily_queue_t { lily_queue_t* lily_queue_create(); void lily_queue_destroy(lily_queue_t *q); -#define lily_enqueue(q, type, value) \ - do { \ - type _var = value; \ - _lily_enqueue(q, sizeof(type), (uint8_t*)(&_var)); \ +#define lily_enqueue(q, type, value) \ + do { \ + type _var = value; \ + _lily_enqueue(q, sizeof(type), (uint8_t*)(&_var)); \ } while(0) void _lily_enqueue(lily_queue_t *q, size_t size, uint8_t *data); @@ -136,4 +137,18 @@ void _lily_enqueue(lily_queue_t *q, size_t size, uint8_t *data); _lily_dequeue(q, sizeof(type), (uint8_t*) ptr) void _lily_dequeue(lily_queue_t *q, size_t size, uint8_t *ptr); + +struct lily_mock_arg_t { + size_t size; + void *var; +}; + +#define LILY_NARGS(args) (sizeof(args)/sizeof(struct lily_mock_arg_t)) + +typedef struct lily_mock_t { + unsigned int n_calls; + lily_queue_t *arguments; + lily_queue_t *values; +} lily_mock_t; + #endif diff --git a/tests/main.c b/tests/main.c index 062e5f8..f4e634c 100644 --- a/tests/main.c +++ b/tests/main.c @@ -23,6 +23,7 @@ int main() run_test(test_mock_enqueue_dequeue_int); run_test(test_mock_enqueue_dequeue_heterogenous); + run_test(test_LILY_NARGS); return 0; } diff --git a/tests/mock_queue.c b/tests/mock_queue.c index bc00325..4015c68 100644 --- a/tests/mock_queue.c +++ b/tests/mock_queue.c @@ -59,3 +59,20 @@ const char* test_mock_enqueue_dequeue_heterogenous() return 0; } + + +const char* test_LILY_NARGS() +{ + int n = 5; + const char *str = "hello, world!"; + lily_queue_t *q; + + struct lily_mock_arg_t args[] = + { { sizeof(int), &n }, + { sizeof(const char *), &str }, + { sizeof(lily_queue_t *), &q }, + }; + if (LILY_NARGS(args) != 3) return "incorrect argument count!"; + + return 0; +} diff --git a/tests/tests.h b/tests/tests.h index 266cc04..39ad153 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -20,5 +20,6 @@ const char* test_assert_int_not_equal(); const char* test_mock_enqueue_dequeue_int(); const char* test_mock_enqueue_dequeue_heterogenous(); +const char* test_LILY_NARGS(); #endif |