From 521582be95315d06f489a3dee2c48c1f96278f81 Mon Sep 17 00:00:00 2001 From: Robin Onsay Date: Tue, 10 Jun 2025 06:15:59 -0500 Subject: [PATCH 1/4] :sparkles: Add api for I2c and SPI Ref #41 --- include/juno/io/async_io_api.h | 1 + include/juno/io/i2c_io_api.h | 117 +++++++++++++++++++++++++++++++++ include/juno/io/spi_io_api.h | 55 ++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 include/juno/io/i2c_io_api.h create mode 100644 include/juno/io/spi_io_api.h diff --git a/include/juno/io/async_io_api.h b/include/juno/io/async_io_api.h index cd05e357..a2a953d8 100644 --- a/include/juno/io/async_io_api.h +++ b/include/juno/io/async_io_api.h @@ -29,6 +29,7 @@ #include "juno/status.h" #include "juno/module.h" #include "juno/time/time_api.h" +#include #ifdef __cplusplus extern "C" { diff --git a/include/juno/io/i2c_io_api.h b/include/juno/io/i2c_io_api.h new file mode 100644 index 00000000..f86fb192 --- /dev/null +++ b/include/juno/io/i2c_io_api.h @@ -0,0 +1,117 @@ +/* + MIT License + + Copyright (c) 2025 Robin A. Onsay + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. +*/ + +/** + This API has been generated by LibJuno: + https://www.robinonsay.com/libjuno/ +*/ + +/** + This header contains the io library API + @author +*/ +#ifndef JUNO_I2C_IO_API_H +#define JUNO_I2C_IO_API_H +#include "juno/status.h" +#include "juno/module.h" +#include "juno/time/time_api.h" +#include +#include +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct JUNO_I2C_IO_API_TAG JUNO_I2C_IO_API_T; +typedef struct JUNO_I2C_IO_MSG_R_TAG JUNO_I2C_IO_MSG_R_T; +typedef struct JUNO_I2C_IO_MSG_W_TAG JUNO_I2C_IO_MSG_W_T; +typedef struct JUNO_I2C_IO_MSG_HDR_TAG JUNO_I2C_IO_MSG_HDR_T; +typedef union JUNO_I2C_IO_MSG_TAG JUNO_I2C_IO_MSG_T; +JUNO_MODULE_DECLARE(JUNO_I2C_IO_T); +JUNO_MODULE_BASE_DECLARE(JUNO_I2C_IO_BASE_T); + +typedef enum JUNO_I2C_IO_MSG_TYPE_TAG +{ + JUNO_I2C_IO_MSG_TYPE_RESERVED = 0, + JUNO_I2C_IO_MSG_TYPE_W = 1, + JUNO_I2C_IO_MSG_TYPE_R = 2, +} JUNO_I2C_IO_MSG_TYPE_T; + +struct JUNO_I2C_IO_MSG_HDR_TAG +{ + JUNO_I2C_IO_MSG_TYPE_T tType; + uint8_t iAddr; +}; + +struct JUNO_I2C_IO_MSG_R_TAG +{ + JUNO_I2C_IO_MSG_HDR_T tHdr; + uint8_t *ptReadBuff; + size_t zReadBuffSize; +}; + +struct JUNO_I2C_IO_MSG_W_TAG +{ + JUNO_I2C_IO_MSG_HDR_T tHdr; + const void *ptWriteBuff; + size_t zWriteBuffSize; +}; + +union JUNO_I2C_IO_MSG_TAG +{ + JUNO_I2C_IO_MSG_HDR_T tHdr; + JUNO_I2C_IO_MSG_W_T tWrite; + JUNO_I2C_IO_MSG_R_T tRead; +}; + +inline JUNO_I2C_IO_MSG_T ReadMsg(uint8_t iAddr, uint8_t *pcBuff, size_t zReadBuffSize) +{ + return (JUNO_I2C_IO_MSG_T) + { + .tRead = (JUNO_I2C_IO_MSG_R_T) + { + .tHdr = {JUNO_I2C_IO_MSG_TYPE_R, iAddr}, + .ptReadBuff = pcBuff, + .zReadBuffSize = zReadBuffSize + } + }; +} + +inline JUNO_I2C_IO_MSG_T WriteMsg(uint8_t iAddr, const void *pvBuff, size_t zWriteBuffSize) +{ + return (JUNO_I2C_IO_MSG_T) + { + .tWrite = (JUNO_I2C_IO_MSG_W_T) + { + .tHdr = {JUNO_I2C_IO_MSG_TYPE_W, iAddr}, + .ptWriteBuff = pvBuff, + .zWriteBuffSize = zWriteBuffSize + } + }; +} + +JUNO_MODULE_BASE(JUNO_I2C_IO_BASE_T, JUNO_I2C_IO_API_T, JUNO_MODULE_EMPTY); + +struct JUNO_I2C_IO_API_TAG +{ + JUNO_STATUS_T (*Transfer)(JUNO_I2C_IO_T *ptI2c, const JUNO_I2C_IO_MSG_T *ptArrMsgs, size_t zMsgArrLen); +}; + +#ifdef __cplusplus +} +#endif +#endif // JUNO_I2C_IO_API_H diff --git a/include/juno/io/spi_io_api.h b/include/juno/io/spi_io_api.h new file mode 100644 index 00000000..63db6a58 --- /dev/null +++ b/include/juno/io/spi_io_api.h @@ -0,0 +1,55 @@ +/* + MIT License + + Copyright (c) 2025 Robin A. Onsay + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. +*/ + +/** + This API has been generated by LibJuno: + https://www.robinonsay.com/libjuno/ +*/ + +/** + This header contains the io library API + @author +*/ +#ifndef JUNO_SPI_IO_API_H +#define JUNO_SPI_IO_API_H +#include "juno/status.h" +#include "juno/module.h" +#include "juno/time/time_api.h" +#include +#include +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct JUNO_SPI_IO_API_TAG JUNO_SPI_IO_API_T; +JUNO_MODULE_DECLARE(JUNO_SPI_IO_T); +JUNO_MODULE_BASE_DECLARE(JUNO_SPI_IO_BASE_T); + +JUNO_MODULE_BASE(JUNO_SPI_IO_BASE_T, JUNO_SPI_IO_API_T, JUNO_MODULE_EMPTY); + + +struct JUNO_SPI_IO_API_TAG +{ + /// Perform an SPI transaction + JUNO_STATUS_T (*Transaction)(JUNO_SPI_IO_T *ptIo, char *pcReadBuff, size_t zReadBuffSize, const void *pvWriteBuff, size_t zWriteBuffSize); +}; + +#ifdef __cplusplus +} +#endif +#endif // JUNO_SPI_IO_API_H From 8d951bb01cfa814357edfeb9cd7f06f532662120 Mon Sep 17 00:00:00 2001 From: Robin Onsay Date: Tue, 10 Jun 2025 06:31:16 -0500 Subject: [PATCH 2/4] :sparkles: Add helper macros to i2c api Ref #41 --- include/juno/io/i2c_io_api.h | 53 +++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/include/juno/io/i2c_io_api.h b/include/juno/io/i2c_io_api.h index f86fb192..9923b8fe 100644 --- a/include/juno/io/i2c_io_api.h +++ b/include/juno/io/i2c_io_api.h @@ -78,36 +78,45 @@ union JUNO_I2C_IO_MSG_TAG JUNO_I2C_IO_MSG_R_T tRead; }; -inline JUNO_I2C_IO_MSG_T ReadMsg(uint8_t iAddr, uint8_t *pcBuff, size_t zReadBuffSize) -{ - return (JUNO_I2C_IO_MSG_T) - { - .tRead = (JUNO_I2C_IO_MSG_R_T) - { - .tHdr = {JUNO_I2C_IO_MSG_TYPE_R, iAddr}, - .ptReadBuff = pcBuff, - .zReadBuffSize = zReadBuffSize - } - }; +#define ReadMsg(iAddr, pcBuff, zBuffSize) \ +(JUNO_I2C_IO_MSG_T) \ +{ \ + .tRead = (JUNO_I2C_IO_MSG_R_T) \ + { \ + .tHdr = {JUNO_I2C_IO_MSG_TYPE_R, iAddr}, \ + .ptReadBuff = pcBuff, \ + .zReadBuffSize = zBuffSize \ + } \ } -inline JUNO_I2C_IO_MSG_T WriteMsg(uint8_t iAddr, const void *pvBuff, size_t zWriteBuffSize) -{ - return (JUNO_I2C_IO_MSG_T) - { - .tWrite = (JUNO_I2C_IO_MSG_W_T) - { - .tHdr = {JUNO_I2C_IO_MSG_TYPE_W, iAddr}, - .ptWriteBuff = pvBuff, - .zWriteBuffSize = zWriteBuffSize - } - }; +#define WriteMsg(iAddr, pvBuff, zBuffSize) \ +(JUNO_I2C_IO_MSG_T) \ +{ \ + .tWrite = (JUNO_I2C_IO_MSG_W_T) \ + { \ + .tHdr = {JUNO_I2C_IO_MSG_TYPE_W, iAddr}, \ + .ptWriteBuff = pvBuff, \ + .zWriteBuffSize = zBuffSize \ + } \ } JUNO_MODULE_BASE(JUNO_I2C_IO_BASE_T, JUNO_I2C_IO_API_T, JUNO_MODULE_EMPTY); +#define JUNO_I2C_IO_TRANSFER(...) (JUNO_I2C_IO_MSG_T[]){__VA_ARGS__} + struct JUNO_I2C_IO_API_TAG { + /** + Perform an I2C transfer. + A typical call would look like: + + ``` + ptApi->Transfer(ptI2c, JUNO_I2C_IO_TRANSFER{WriteMsg(0xFF, ptMyWriteBuff, sizeof(ptMyWriteBuff))}, 1) + // OR + JUNO_I2C_IO_MSG_T ptArrTransfer[] = JUNO_I2C_IO_TRANSFER{WriteMsg(0xFF, ptMyWriteBuff, sizeof(ptMyWriteBuff))}; + ptApi->Transfer(ptI2c, ptArrTransfer, sizeof(ptArrTransfer) / sizeof(ptArrTransfer[0])); + ``` + */ JUNO_STATUS_T (*Transfer)(JUNO_I2C_IO_T *ptI2c, const JUNO_I2C_IO_MSG_T *ptArrMsgs, size_t zMsgArrLen); }; From fd1af6d5afbaaed51d28c70b151b43a168e879c4 Mon Sep 17 00:00:00 2001 From: Robin Onsay Date: Tue, 10 Jun 2025 07:30:26 -0500 Subject: [PATCH 3/4] :sparkles: Add queue and stack impl --- include/juno/buff/buff_queue_api.h | 112 +++++++++++++++++++++++++++ include/juno/buff/buff_stack_api.h | 107 ++++++++++++++++++++++++++ tests/test_buff.c | 119 +++++++++++++++++++++++++++++ 3 files changed, 338 insertions(+) create mode 100644 include/juno/buff/buff_queue_api.h create mode 100644 include/juno/buff/buff_stack_api.h create mode 100644 tests/test_buff.c diff --git a/include/juno/buff/buff_queue_api.h b/include/juno/buff/buff_queue_api.h new file mode 100644 index 00000000..14c4011b --- /dev/null +++ b/include/juno/buff/buff_queue_api.h @@ -0,0 +1,112 @@ +/* + MIT License + + Copyright (c) 2025 Robin A. Onsay + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. +*/ + +/** + This API has been generated by LibJuno: + https://www.robinonsay.com/libjuno/ +*/ + +/** + This header contains the juno_buff_queue library API + @author +*/ +#ifndef JUNO_BUFF_QUEUE_API_H +#define JUNO_BUFF_QUEUE_API_H +#include "juno/macros.h" +#include "juno/memory/memory_api.h" +#include "juno/status.h" +#include "juno/module.h" +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct JUNO_BUFF_QUEUE_API_TAG JUNO_BUFF_QUEUE_API_T; +typedef struct JUNO_BUFF_QUEUE_TAG JUNO_BUFF_QUEUE_T; + + +struct JUNO_BUFF_QUEUE_TAG +{ + size_t iStartIndex; + size_t zLength; + size_t zCapacity; + JUNO_FAILURE_HANDLER_T JUNO_FAILURE_HANDLER; + JUNO_USER_DATA_T *JUNO_FAILURE_USER_DATA; +}; + +static inline JUNO_STATUS_T JunoBuff_QueueInit(JUNO_BUFF_QUEUE_T *ptQueue, size_t zCapacity, JUNO_FAILURE_HANDLER_T pfcnFailureHdlr, JUNO_USER_DATA_T *pvFailureUserData) +{ + ASSERT_EXISTS(ptQueue); + ptQueue->iStartIndex = 0; + ptQueue->zLength = 0; + ptQueue->zCapacity = zCapacity; + ptQueue->_pfcnFailureHandler = pfcnFailureHdlr; + ptQueue->_pvFailurUserData = pvFailureUserData; + return JUNO_STATUS_SUCCESS; +} + +static inline JUNO_STATUS_T JunoBuff_QueueEnqueue(JUNO_BUFF_QUEUE_T *ptQueue, size_t *ptRetIndex) +{ + ASSERT_EXISTS(ptQueue); + if(ptQueue->zLength < ptQueue->zCapacity) + { + ptQueue->zLength += 1; + } + else + { + FAIL(JUNO_STATUS_INVALID_SIZE_ERROR, ptQueue->_pfcnFailureHandler, ptQueue->_pvFailurUserData, "Failed to enqueue data"); + return JUNO_STATUS_INVALID_SIZE_ERROR; + } + if(ptRetIndex) + { + *ptRetIndex = ptQueue->zLength % ptQueue->zCapacity; + } + return JUNO_STATUS_SUCCESS; +} + +static inline JUNO_STATUS_T JunoBuff_QueueDequeue(JUNO_BUFF_QUEUE_T *ptQueue, size_t *ptRetIndex) +{ + ASSERT_EXISTS(ptQueue); + if(ptQueue->zLength > 0) + { + ptQueue->iStartIndex = (ptQueue->iStartIndex + 1) % ptQueue->zCapacity; + ptQueue->zLength -= 1; + if(ptRetIndex) + { + *ptRetIndex = ptQueue->iStartIndex; + } + return JUNO_STATUS_SUCCESS; + } + FAIL(JUNO_STATUS_ERR, ptQueue->_pfcnFailureHandler, ptQueue->_pvFailurUserData, "Queue is empty"); + return JUNO_STATUS_ERR; +} + +static inline JUNO_STATUS_T JunoBuff_QueueGetIndex(JUNO_BUFF_QUEUE_T *ptQueue, size_t *ptRetIndex) +{ + ASSERT_EXISTS(ptQueue); + if(*ptRetIndex) + { + *ptRetIndex = ptQueue->iStartIndex; + } + return JUNO_STATUS_SUCCESS; +} + + +#ifdef __cplusplus +} +#endif +#endif // JUNO_BUFF_QUEUE_API_H diff --git a/include/juno/buff/buff_stack_api.h b/include/juno/buff/buff_stack_api.h new file mode 100644 index 00000000..c70c5f32 --- /dev/null +++ b/include/juno/buff/buff_stack_api.h @@ -0,0 +1,107 @@ +/* + MIT License + + Copyright (c) 2025 Robin A. Onsay + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. +*/ + +/** + This API has been generated by LibJuno: + https://www.robinonsay.com/libjuno/ +*/ + +/** + This header contains the juno_buff_stack library API + @author +*/ +#ifndef JUNO_BUFF_STACK_API_H +#define JUNO_BUFF_STACK_API_H +#include "juno/macros.h" +#include "juno/memory/memory_api.h" +#include "juno/status.h" +#include "juno/module.h" +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct JUNO_BUFF_STACK_API_TAG JUNO_BUFF_STACK_API_T; +typedef struct JUNO_BUFF_STACK_TAG JUNO_BUFF_STACK_T; + +struct JUNO_BUFF_STACK_TAG +{ + size_t zLength; + size_t zCapacity; + JUNO_FAILURE_HANDLER_T JUNO_FAILURE_HANDLER; + JUNO_USER_DATA_T *JUNO_FAILURE_USER_DATA; +}; + +static inline JUNO_STATUS_T JunoBuff_StackInit(JUNO_BUFF_STACK_T *ptStack, size_t zCapacity, JUNO_FAILURE_HANDLER_T pfcnFailureHdlr, JUNO_USER_DATA_T *pvFailureUserData) +{ + ASSERT_EXISTS(ptStack); + ptStack->zLength = 0; + ptStack->zCapacity = zCapacity; + ptStack->_pfcnFailureHandler = pfcnFailureHdlr; + ptStack->_pvFailurUserData = pvFailureUserData; + return JUNO_STATUS_SUCCESS; +} + +static inline JUNO_STATUS_T JunoBuff_StackPush(JUNO_BUFF_STACK_T *ptStack, size_t *ptRetIndex) +{ + ASSERT_EXISTS(ptStack); + if(ptStack->zLength < ptStack->zCapacity) + { + if(ptRetIndex) + { + *ptRetIndex = ptStack->zLength; + } + ptStack->zLength += 1; + } + else + { + FAIL(JUNO_STATUS_INVALID_SIZE_ERROR, ptStack->_pfcnFailureHandler, ptStack->_pvFailurUserData, "Failed to enqueue data"); + return JUNO_STATUS_INVALID_SIZE_ERROR; + } + return JUNO_STATUS_SUCCESS; +} + +static inline JUNO_STATUS_T JunoBuff_StackPop(JUNO_BUFF_STACK_T *ptStack, size_t *ptRetIndex) +{ + ASSERT_EXISTS(ptStack); + if(ptStack->zLength > 0) + { + ptStack->zLength -= 1; + if(ptRetIndex) + { + *ptRetIndex = ptStack->zLength; + } + return JUNO_STATUS_SUCCESS; + } + return JUNO_STATUS_INVALID_SIZE_ERROR; +} + +static inline JUNO_STATUS_T JunoBuff_StackPeek(JUNO_BUFF_STACK_T *ptStack, size_t *ptRetIndex) +{ + ASSERT_EXISTS(ptStack); + if(*ptRetIndex) + { + *ptRetIndex = ptStack->zLength; + } + return JUNO_STATUS_SUCCESS; +} + + +#ifdef __cplusplus +} +#endif +#endif // JUNO_BUFF_STACK_API_H diff --git a/tests/test_buff.c b/tests/test_buff.c new file mode 100644 index 00000000..974562a8 --- /dev/null +++ b/tests/test_buff.c @@ -0,0 +1,119 @@ +#include "juno/status.h" +#include "unity.h" +#include "unity_internals.h" +#include "juno/buff/buff_queue_api.h" +#include "juno/buff/buff_stack_api.h" +#include +#include + + +void setUp(void) +{ + +} +void tearDown(void) +{ + +} + +static void test_queue(void) +{ + uint8_t iTestQueue[10]; + JUNO_BUFF_QUEUE_T tQueue = {}; + + JUNO_STATUS_T tStatus = JunoBuff_QueueInit(&tQueue, sizeof(iTestQueue), NULL, NULL); + TEST_ASSERT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + for(int i = 0; i < sizeof(iTestQueue); i++) + { + size_t iIndex = 0; + tStatus = JunoBuff_QueueEnqueue(&tQueue, &iIndex); + TEST_ASSERT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + iTestQueue[iIndex] = i+1; + } + size_t iIndex = 0; + tStatus = JunoBuff_QueueEnqueue(&tQueue, &iIndex); + TEST_ASSERT_NOT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + for(int i = 0; i < sizeof(iTestQueue); i++) + { + size_t iIndex = 0; + tStatus = JunoBuff_QueueDequeue(&tQueue, &iIndex); + TEST_ASSERT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + TEST_ASSERT_EQUAL(i+1, iTestQueue[iIndex]); + } + tStatus = JunoBuff_QueueDequeue(&tQueue, &iIndex); + TEST_ASSERT_NOT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + for(int i = 0; i < sizeof(iTestQueue); i++) + { + size_t iIndex = 0; + tStatus = JunoBuff_QueueEnqueue(&tQueue, &iIndex); + TEST_ASSERT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + iTestQueue[iIndex] = i+1; + } + iIndex = 0; + tStatus = JunoBuff_QueueEnqueue(&tQueue, &iIndex); + TEST_ASSERT_NOT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + for(int i = 0; i < sizeof(iTestQueue); i++) + { + size_t iIndex = 0; + tStatus = JunoBuff_QueueDequeue(&tQueue, &iIndex); + TEST_ASSERT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + TEST_ASSERT_EQUAL(i+1, iTestQueue[iIndex]); + } + tStatus = JunoBuff_QueueDequeue(&tQueue, &iIndex); + TEST_ASSERT_NOT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); +} + +static void test_stack(void) +{ + uint8_t iTestStack[10]; + JUNO_BUFF_STACK_T tStack = {}; + + JUNO_STATUS_T tStatus = JunoBuff_StackInit(&tStack, sizeof(iTestStack), NULL, NULL); + TEST_ASSERT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + for(int i = 0; i < sizeof(iTestStack); i++) + { + size_t iIndex = 0; + tStatus = JunoBuff_StackPush(&tStack, &iIndex); + TEST_ASSERT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + iTestStack[iIndex] = i+1; + } + size_t iIndex = 0; + tStatus = JunoBuff_StackPush(&tStack, &iIndex); + TEST_ASSERT_NOT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + for(int i = 0; i < sizeof(iTestStack); i++) + { + size_t iIndex = 0; + tStatus = JunoBuff_StackPop(&tStack, &iIndex); + TEST_ASSERT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + TEST_ASSERT_EQUAL(sizeof(iTestStack) - i, iTestStack[iIndex]); + } + tStatus = JunoBuff_StackPop(&tStack, &iIndex); + TEST_ASSERT_NOT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + for(int i = 0; i < sizeof(iTestStack); i++) + { + size_t iIndex = 0; + tStatus = JunoBuff_StackPush(&tStack, &iIndex); + TEST_ASSERT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + iTestStack[iIndex] = i+1; + } + iIndex = 0; + tStatus = JunoBuff_StackPush(&tStack, &iIndex); + TEST_ASSERT_NOT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + for(int i = 0; i < sizeof(iTestStack); i++) + { + size_t iIndex = 0; + tStatus = JunoBuff_StackPop(&tStack, &iIndex); + TEST_ASSERT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + TEST_ASSERT_EQUAL(sizeof(iTestStack) - i, iTestStack[iIndex]); + } + tStatus = JunoBuff_StackPop(&tStack, &iIndex); + TEST_ASSERT_NOT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); +} + +int main(void) +{ + UNITY_BEGIN(); + RUN_TEST(test_queue); + RUN_TEST(test_stack); + return UNITY_END(); +} From b7621ad8907a03d62d71b6909026bee3eef73a19 Mon Sep 17 00:00:00 2001 From: Robin Onsay Date: Tue, 10 Jun 2025 07:34:05 -0500 Subject: [PATCH 4/4] :sparkles: Add more unit tests --- tests/test_buff.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_buff.c b/tests/test_buff.c index 974562a8..9ccded04 100644 --- a/tests/test_buff.c +++ b/tests/test_buff.c @@ -61,6 +61,37 @@ static void test_queue(void) } tStatus = JunoBuff_QueueDequeue(&tQueue, &iIndex); TEST_ASSERT_NOT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + for(int i = 0; i < sizeof(iTestQueue); i++) + { + size_t iIndex = 0; + tStatus = JunoBuff_QueueEnqueue(&tQueue, &iIndex); + TEST_ASSERT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + iTestQueue[iIndex] = i+1; + tStatus = JunoBuff_QueueDequeue(&tQueue, &iIndex); + TEST_ASSERT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + TEST_ASSERT_EQUAL(i+1, iTestQueue[iIndex]); + } + tStatus = JunoBuff_QueueDequeue(&tQueue, &iIndex); + TEST_ASSERT_NOT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + for(int i = 0; i < sizeof(iTestQueue); i++) + { + size_t iIndex = 0; + tStatus = JunoBuff_QueueEnqueue(&tQueue, &iIndex); + TEST_ASSERT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + iTestQueue[iIndex] = i+1; + } + iIndex = 0; + tStatus = JunoBuff_QueueEnqueue(&tQueue, &iIndex); + TEST_ASSERT_NOT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + for(int i = 0; i < sizeof(iTestQueue); i++) + { + size_t iIndex = 0; + tStatus = JunoBuff_QueueDequeue(&tQueue, &iIndex); + TEST_ASSERT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); + TEST_ASSERT_EQUAL(i+1, iTestQueue[iIndex]); + } + tStatus = JunoBuff_QueueDequeue(&tQueue, &iIndex); + TEST_ASSERT_NOT_EQUAL(JUNO_STATUS_SUCCESS, tStatus); } static void test_stack(void)