summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lily-test.c6
-rw-r--r--lily-test.h9
-rw-r--r--tests/main.c1
-rw-r--r--tests/mock_queue.c14
-rw-r--r--tests/tests.h1
5 files changed, 30 insertions, 1 deletions
diff --git a/lily-test.c b/lily-test.c
index ec0a1f7..2f43a28 100644
--- a/lily-test.c
+++ b/lily-test.c
@@ -333,6 +333,12 @@ void lily_mock_destroy(lily_mock_t *m)
free(m);
}
+void lily_mock_use(lily_mock_t **m)
+{
+ if (*m != NULL) lily_mock_destroy(*m);
+ *m = lily_mock_create();
+}
+
void _lily_mock_call(lily_mock_t *m, struct lily_mock_arg_t *args, size_t n_args)
{
m->n_calls += 1;
diff --git a/lily-test.h b/lily-test.h
index bf896a6..b5f380c 100644
--- a/lily-test.h
+++ b/lily-test.h
@@ -231,14 +231,21 @@ typedef struct lily_mock_t {
lily_mock_t * lily_mock_create();
/** tear down mock function storage */
void lily_mock_destroy(lily_mock_t *m);
-
+/** automatically re-create mock function storage */
+void lily_mock_use(lily_mock_t **m);
/** store a call to a mock function */
+#define lily_mock_store_call(m, args) \
+ _lily_mock_call(m, args, LILY_NARGS(args))
+/* lily_mock_call is deprecated!! do not use it in new programs */
#define lily_mock_call(m, args) \
_lily_mock_call(m, args, LILY_NARGS(args))
void _lily_mock_call(lily_mock_t *m, struct lily_mock_arg_t *args, size_t n_args);
/** retrieve a call to a mock function */
+#define lily_mock_get_call(m, args, call_num) \
+ _lily_get_call(m, args, LILY_NARGS(args), call_num)
+/* lily_get_call is deprecated!! do not use it in new programs */
#define lily_get_call(m, args, call_num) \
_lily_get_call(m, args, LILY_NARGS(args), call_num)
void _lily_get_call(lily_mock_t *m,
diff --git a/tests/main.c b/tests/main.c
index f3f1f06..44dd6a4 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -23,6 +23,7 @@ int main()
run_test(test_mock_enqueue_dequeue_heterogenous);
run_test(test_LILY_NARGS);
run_test(test_lily_mock_call);
+ run_test(test_lily_mock_use);
return 0;
}
diff --git a/tests/mock_queue.c b/tests/mock_queue.c
index 493d397..07a5379 100644
--- a/tests/mock_queue.c
+++ b/tests/mock_queue.c
@@ -118,3 +118,17 @@ const char* test_lily_mock_call()
lily_mock_destroy(m);
return 0;
}
+
+
+const char * test_lily_mock_use()
+{
+ lily_mock_t *m = NULL;
+ lily_mock_use(&m);
+ if (m == NULL) return "m was still null!";
+ m->n_calls = 5;
+ lily_mock_use(&m);
+ if (m == NULL) return "m was later null!";
+ if (m->n_calls != 0) return "m was not re-allocated!";
+ lily_mock_destroy(m);
+ return 0;
+}
diff --git a/tests/tests.h b/tests/tests.h
index 9584cac..cbee06e 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -22,5 +22,6 @@ const char* test_mock_enqueue_dequeue_int();
const char* test_mock_enqueue_dequeue_heterogenous();
const char* test_LILY_NARGS();
const char* test_lily_mock_call();
+const char* test_lily_mock_use();
#endif