From 1b83af44e9a4427e661b8a4a335948cff143fc58 Mon Sep 17 00:00:00 2001 From: bartool Date: Sun, 27 Nov 2022 07:49:52 +0100 Subject: [PATCH] add test minor changes --- .vscode/settings.json | 14 ++++++++++++++ oled/oled.c | 11 ++++------- oled/oled.h | 6 +++++- test/oled/CMakeLists.txt | 10 +++++----- test/oled/oled_test.c | 32 ++++++++++++++++++++++++++++---- 5 files changed, 56 insertions(+), 17 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1ec3127 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "files.associations": { + "climits": "c", + "cmath": "c", + "cstdarg": "c", + "cstdint": "c", + "cstdio": "c", + "cstdlib": "c", + "type_traits": "c", + "limits": "c", + "*.tcc": "c", + "typeinfo": "c" + } +} \ No newline at end of file diff --git a/oled/oled.c b/oled/oled.c index 65e660d..4e88287 100644 --- a/oled/oled.c +++ b/oled/oled.c @@ -1,15 +1,18 @@ #include +// #include #include "oled.h" #include "ssd1306.h" #include "sh1106.h" HAL_StatusTypeDef oled_Config(OLED_HandleTypeDef *hOled, uint8_t DevAddress, uint8_t Width, uint8_t Height, OLED_DisplayType_t OledType) { + // static_assert(hOled != NULL, "brak pointera"); if (hOled == NULL || Width == 0 || Height == 0 || OledType == UNKNOWN) { return HAL_ERROR; } + hOled->hi2c = NULL; hOled->DevAddress = DevAddress; hOled->Width = Width; hOled->Height = Height; @@ -78,7 +81,7 @@ OLED_SendStatus_t oled_display_page(OLED_HandleTypeDef *hOled) { if (hOled == NULL) { - return; + return ERROR; } OLED_SendStatus_t sendStatus; switch (hOled->OledType) @@ -97,9 +100,3 @@ OLED_SendStatus_t oled_display_page(OLED_HandleTypeDef *hOled) return sendStatus; } -int main(void) -{ - - OLED_HandleTypeDef display; - oled_Config(&display, 0x3C, 128, 64, SH1106); -} \ No newline at end of file diff --git a/oled/oled.h b/oled/oled.h index 3ead40e..17fce82 100644 --- a/oled/oled.h +++ b/oled/oled.h @@ -14,6 +14,7 @@ typedef enum } OLED_DisplayType_t; typedef enum{ + ERROR, SENDPAGE, SENDALL } OLED_SendStatus_t; @@ -30,4 +31,7 @@ typedef struct } OLED_HandleTypeDef; -void oled_init(OLED_HandleTypeDef *hOled, I2C_HandleTypeDef *hi2c); \ No newline at end of file +HAL_StatusTypeDef oled_Config(OLED_HandleTypeDef *hOled, uint8_t DevAddress, uint8_t Width, uint8_t Height, OLED_DisplayType_t OledType); +void oled_init(OLED_HandleTypeDef *hOled, I2C_HandleTypeDef *hi2c); +void oled_display_all(OLED_HandleTypeDef *hOled); +OLED_SendStatus_t oled_display_page(OLED_HandleTypeDef *hOled); \ No newline at end of file diff --git a/test/oled/CMakeLists.txt b/test/oled/CMakeLists.txt index 3484c33..2e8dfd9 100644 --- a/test/oled/CMakeLists.txt +++ b/test/oled/CMakeLists.txt @@ -10,12 +10,12 @@ set(INCLUDE_DIRS ) set(SRCS - # ../../oled/oled.c - # ../../oled/connection.c - # ../../oled/ssd1306/ssd1306.c - # ../../oled/sh1106/sh1106.c + ../../oled/oled.c + ../../oled/connection.c + ../../oled/ssd1306/ssd1306.c + ../../oled/sh1106/sh1106.c - # helpers/src/mock_i2c.c + helpers/src/mock_i2c.c oled_test.c ) diff --git a/test/oled/oled_test.c b/test/oled/oled_test.c index 4ea14ca..70c6569 100644 --- a/test/oled/oled_test.c +++ b/test/oled/oled_test.c @@ -1,18 +1,41 @@ +#include "stdlib.h" #include "unity.h" +#include "oled.h" +#include "string.h" - +OLED_HandleTypeDef* display; void setUp(void) { + // uint32_t size = sizeof(OLED_HandleTypeDef); + // printf("size in B: %u\n", size); + display = (OLED_HandleTypeDef*)malloc(sizeof(OLED_HandleTypeDef)); } void tearDown(void) { + free(display); } -void test_one(void) +void test_configWithCorecctArgs(void) { - TEST_FAIL(); + HAL_StatusTypeDef status = oled_Config(display, 0x0F, 128, 64, SH1106); + + TEST_ASSERT_EQUAL(status, HAL_OK); + TEST_ASSERT_NULL(display->hi2c); + TEST_ASSERT_EQUAL(display->OledType, SH1106); + TEST_ASSERT_EQUAL_HEX8(display->DevAddress, 0x0F); + TEST_ASSERT_EQUAL(display->Width, 128); + TEST_ASSERT_EQUAL(display->Height, 64); + TEST_ASSERT_EQUAL(display->BufSize, 128*64/8); + TEST_ASSERT_NOT_NULL(display->Buffer); +} + +void test_configWithoutPointerToDisplay(void) +{ + HAL_StatusTypeDef status = oled_Config(NULL, 0x0F, 128, 64, SH1106); + + TEST_ASSERT_EQUAL(status, HAL_ERROR); } @@ -20,7 +43,8 @@ void test_one(void) int main(void) { UNITY_BEGIN(); - RUN_TEST(test_one); + RUN_TEST(test_configWithCorecctArgs); + RUN_TEST(test_configWithoutPointerToDisplay); return UNITY_END(); } \ No newline at end of file