Merge branch 'oled/wip-main'
This commit is contained in:
@@ -4,14 +4,22 @@ set(TEST_NAME oled)
|
||||
|
||||
set(INCLUDE_DIRS
|
||||
../../oled
|
||||
../../oled/ssd1306
|
||||
../../oled/sh1106
|
||||
helpers/inc
|
||||
)
|
||||
|
||||
set(SRCS
|
||||
../../oled/oled.c
|
||||
../../oled/connection.c
|
||||
../../oled/ssd1306/ssd1306.c
|
||||
../../oled/sh1106/sh1106.c
|
||||
|
||||
helpers/src/mock_i2c.c
|
||||
oled_test.c
|
||||
)
|
||||
|
||||
add_definitions(-DTEST)
|
||||
add_executable(${TEST_NAME} ${SRCS})
|
||||
|
||||
target_include_directories(${TEST_NAME} PUBLIC ${INCLUDE_DIR})
|
||||
target_include_directories(${TEST_NAME} PUBLIC ${INCLUDE_DIRS})
|
||||
18
test/oled/helpers/inc/main.h
Normal file
18
test/oled/helpers/inc/main.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t dummy;
|
||||
}I2C_HandleTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HAL_OK = 0x00U,
|
||||
HAL_ERROR = 0x01U,
|
||||
HAL_BUSY = 0x02U,
|
||||
HAL_TIMEOUT = 0x03
|
||||
} HAL_StatusTypeDef;
|
||||
|
||||
HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout);
|
||||
14
test/oled/helpers/src/mock_i2c.c
Normal file
14
test/oled/helpers/src/mock_i2c.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "main.h"
|
||||
|
||||
|
||||
HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)
|
||||
{
|
||||
(void)hi2c;
|
||||
(void)DevAddress;
|
||||
(void)MemAddress;
|
||||
(void)MemAddSize;
|
||||
(void)pData;
|
||||
(void)Size;
|
||||
(void)Timeout;
|
||||
return HAL_OK;
|
||||
}
|
||||
50
test/oled/oled_test.c
Normal file
50
test/oled/oled_test.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#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_configWithCorecctArgs(void)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_configWithCorecctArgs);
|
||||
RUN_TEST(test_configWithoutPointerToDisplay);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user