summaryrefslogtreecommitdiff
path: root/lily-test.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-04-04 16:42:05 -0500
committersanine <sanine.not@pm.me>2022-04-04 16:42:05 -0500
commitf133f0a424db19dd3263794e8fa71ea920ef3ea9 (patch)
tree178d3fc672acd38ff7c26aa2238a0e7507b81f0e /lily-test.c
parent2cef2d4e0bb490f8e5002e47368bac8e89dbeb88 (diff)
add lily_mock_t basic functionality
Diffstat (limited to 'lily-test.c')
-rw-r--r--lily-test.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/lily-test.c b/lily-test.c
index 0581263..1e7e5f4 100644
--- a/lily-test.c
+++ b/lily-test.c
@@ -242,3 +242,45 @@ void _lily_dequeue(lily_queue_t *q, size_t size, uint8_t *ptr)
memcpy(ptr, q->front, size);
q->front += size;
}
+
+
+lily_mock_t * lily_mock_create()
+{
+ lily_mock_t *m = malloc(sizeof(lily_mock_t));
+ m->n_calls = 0;
+ m->arguments = lily_queue_create();
+ m->values = lily_queue_create();
+ return m;
+}
+
+void lily_mock_destroy(lily_mock_t *m)
+{
+ lily_queue_destroy(m->arguments);
+ lily_queue_destroy(m->values);
+ free(m);
+}
+
+void _lily_mock_call(lily_mock_t *m, struct lily_mock_arg_t *args, size_t n_args)
+{
+ m->n_calls += 1;
+
+ for (int i=0; i<n_args; i++) {
+ _lily_enqueue(m->arguments, args[i].size, args[i].var);
+ }
+}
+
+void _lily_get_call(lily_mock_t *m,
+ struct lily_mock_arg_t *args,
+ size_t n_args,
+ unsigned int call_num)
+{
+ size_t stride = 0;
+ for (int i=0; i<n_args; i++) {
+ stride += args[i].size;
+ }
+
+ m->arguments->front = m->arguments->buf + (call_num * stride);
+ for (int i=0; i<n_args; i++) {
+ _lily_dequeue(m->arguments, args[i].size, args[i].var);
+ }
+}