summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-04-04 13:40:20 -0500
committersanine <sanine.not@pm.me>2022-04-04 13:40:20 -0500
commit5e3d8e950d97a222b15d41de1ae17ccf51621471 (patch)
treecbf807e36097d498d40b7acd196de22834e882b3
parent29179fc15a1d085299601267fe0bc9c6be5dfa1c (diff)
refactor: rename lily_mock_queue_t -> lily_queue_t
-rw-r--r--lily-test.c10
-rw-r--r--lily-test.h13
-rw-r--r--tests/mock_queue.c10
3 files changed, 16 insertions, 17 deletions
diff --git a/lily-test.c b/lily-test.c
index 17959ca..0581263 100644
--- a/lily-test.c
+++ b/lily-test.c
@@ -187,11 +187,11 @@ void _lily_assert_memory_not_equal(const char *name_a, const char *name_b,
}
-lily_mock_queue_t* lily_queue_create()
+lily_queue_t* lily_queue_create()
{
const size_t size = 256 * sizeof(uint8_t);
- lily_mock_queue_t *q = malloc(sizeof(lily_mock_queue_t));
+ lily_queue_t *q = malloc(sizeof(lily_queue_t));
q->buf_size = size;
q->buf = malloc(size);
q->front = q->buf;
@@ -201,14 +201,14 @@ lily_mock_queue_t* lily_queue_create()
}
-void lily_queue_destroy(lily_mock_queue_t *q)
+void lily_queue_destroy(lily_queue_t *q)
{
free(q->buf);
free(q);
}
-void _lily_enqueue(lily_mock_queue_t *q, size_t size, uint8_t *data)
+void _lily_enqueue(lily_queue_t *q, size_t size, uint8_t *data)
{
size_t used = q->back - q->buf;
size_t remaining = q->buf_size - used;
@@ -230,7 +230,7 @@ void _lily_enqueue(lily_mock_queue_t *q, size_t size, uint8_t *data)
}
-void _lily_dequeue(lily_mock_queue_t *q, size_t size, uint8_t *ptr)
+void _lily_dequeue(lily_queue_t *q, size_t size, uint8_t *ptr)
{
size_t dist = q->back - q->front;
if (dist < size) {
diff --git a/lily-test.h b/lily-test.h
index 783e134..1e604fe 100644
--- a/lily-test.h
+++ b/lily-test.h
@@ -114,27 +114,26 @@ void _lily_assert_memory_not_equal(const char *name_a, const char *name_b,
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
-typedef struct lily_mock_queue_t {
+typedef struct lily_queue_t {
size_t buf_size;
uint8_t *buf;
uint8_t *front, *back;
-} lily_mock_queue_t;
+} lily_queue_t;
-lily_mock_queue_t* lily_queue_create();
-void lily_queue_destroy(lily_mock_queue_t *q);
+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)); \
} while(0)
-void _lily_enqueue(lily_mock_queue_t *q, size_t size, uint8_t *data);
+void _lily_enqueue(lily_queue_t *q, size_t size, uint8_t *data);
#define lily_dequeue(q, type, ptr) \
_lily_dequeue(q, sizeof(type), (uint8_t*) ptr)
-void _lily_dequeue(lily_mock_queue_t *q, size_t size, uint8_t *ptr);
-
+void _lily_dequeue(lily_queue_t *q, size_t size, uint8_t *ptr);
#endif
diff --git a/tests/mock_queue.c b/tests/mock_queue.c
index 269d462..bc00325 100644
--- a/tests/mock_queue.c
+++ b/tests/mock_queue.c
@@ -6,7 +6,7 @@
const char* test_mock_enqueue_dequeue_int() {
- lily_mock_queue_t *q = lily_queue_create();
+ lily_queue_t *q = lily_queue_create();
/* enqueue A259482, for no particular reason */
lily_enqueue(q, int, 2);
@@ -39,17 +39,17 @@ const char* test_mock_enqueue_dequeue_int() {
const char* test_mock_enqueue_dequeue_heterogenous()
{
- lily_mock_queue_t *q = lily_queue_create();
+ lily_queue_t *q = lily_queue_create();
lily_enqueue(q, int, 2);
- lily_enqueue(q, lily_mock_queue_t *, q);
+ lily_enqueue(q, lily_queue_t *, q);
lily_enqueue(q, const char *, "hello, world!");
int n;
lily_dequeue(q, int, &n);
if (n != 2) return "dequeued incorrect int value";
- lily_mock_queue_t *p;
- lily_dequeue(q, lily_mock_queue_t *, &p);
+ lily_queue_t *p;
+ lily_dequeue(q, lily_queue_t *, &p);
if (p != q) return "dequeued incorrect pointer value";
const char *str;
lily_dequeue(q, const char *, &str);