Compare commits
8 commits
5dc658b620
...
1ebd68346e
| Author | SHA1 | Date | |
|---|---|---|---|
| 1ebd68346e | |||
| 4e6be91ac3 | |||
| 8e00f7406a | |||
| 9e2358f9bf | |||
| 89b22f27de | |||
| 79e8629823 | |||
| 2587bb2aba | |||
| 36bd327bc3 |
38 changed files with 604 additions and 52 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
|
@ -1,3 +0,0 @@
|
|||
[submodule "cpputest"]
|
||||
path = cpputest
|
||||
url = https://github.com/cpputest/cpputest.git
|
||||
23
.template_files/test_module/CMakeLists.txt
Normal file
23
.template_files/test_module/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# File: tests/module_name/CMakeLists.txt
|
||||
|
||||
add_subdirectory(mocks)
|
||||
add_subdirectory(fakes)
|
||||
add_subdirectory(stubs)
|
||||
|
||||
# TEST_RUNNER
|
||||
add_library(test_module_name
|
||||
test_module_name.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(test_module_name
|
||||
${CPPUTEST_LIBRARIES}
|
||||
module_name
|
||||
)
|
||||
|
||||
target_include_directories(test_module_name PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
#Next comes the shared and non-module specific test depencencies.
|
||||
${CMAKE_SOURCE_DIR}/tests/shared/mocks/
|
||||
${CMAKE_SOURCE_DIR}/tests/shared/fakes/
|
||||
${CMAKE_SOURCE_DIR}/tests/shared/stubs/
|
||||
)
|
||||
0
.template_files/test_module/fakes/CMakeLists.txt
Normal file
0
.template_files/test_module/fakes/CMakeLists.txt
Normal file
0
.template_files/test_module/mocks/CMakeLists.txt
Normal file
0
.template_files/test_module/mocks/CMakeLists.txt
Normal file
0
.template_files/test_module/stubs/CMakeLists.txt
Normal file
0
.template_files/test_module/stubs/CMakeLists.txt
Normal file
38
.template_files/test_module/test_module_name.cpp
Normal file
38
.template_files/test_module/test_module_name.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Author: username
|
||||
* Date: todays_date
|
||||
* filename: test_module_name.c
|
||||
* description: module_purpose
|
||||
*/
|
||||
|
||||
#include "CppUTest/CommandLineTestRunner.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "module_name.h"
|
||||
}
|
||||
|
||||
TEST_GROUP(FirstTestGroup)
|
||||
{
|
||||
void setup()
|
||||
{
|
||||
|
||||
}
|
||||
void teardown()
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
TEST(FirstTestGroup, FirstTest)
|
||||
{
|
||||
FAIL("Fail me!");
|
||||
}
|
||||
|
||||
TEST(FirstTestGroup, SecondTest)
|
||||
{
|
||||
STRCMP_EQUAL("hello", "world");
|
||||
LONGS_EQUAL(1, 2);
|
||||
CHECK(false);
|
||||
}
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
# Use the fancy version substitution
|
||||
project(main
|
||||
project(WCH_Template
|
||||
VERSION 0.1.0
|
||||
DESCRIPTION "template for cmake + cpputest"
|
||||
LANGUAGES C CXX
|
||||
|
|
@ -24,7 +24,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|||
# Request C standard features
|
||||
set(CMAKE_C_STANDARD 23)
|
||||
set(CMAKE_C_STANDARD_REQUIRED True)
|
||||
set(CMAKE_C_FLAGS "-Wall -Wpedantic")
|
||||
set(CMAKE_C_FLAGS "-Wall -Werror -Wpedantic")
|
||||
|
||||
# SETUP THE CXX flags for .cpp
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
|
|
@ -39,27 +39,30 @@ set(CMAKE_CXX_FLAGS "-Wall -Werror -Wpedantic")
|
|||
|
||||
|
||||
if (UNIT_TESTING)
|
||||
|
||||
#Allows usage of preprossor stuff in your files.
|
||||
add_compile_definitions(UNIT_TESTING=1)
|
||||
if(DEFINED ENV{CPPUTEST_HOME})
|
||||
message(STATUS "Using CppUTest home: $ENV{CPPUTEST_HOME}")
|
||||
set(CPPUTEST_INCLUDE_DIRS $ENV{CPPUTEST_HOME}/include)
|
||||
set(CPPUTEST_LIBRARIES $ENV{CPPUTEST_HOME}/lib)
|
||||
set(CPPUTEST_LDFLAGS CppUTest CppUTestExt)
|
||||
set(CPPUTEST_LIBRARY_DIRS $ENV{CPPUTEST_HOME}/lib)
|
||||
#set(CPPUTEST_LIBRARIES $ENV{CPPUTEST_HOME}/lib)
|
||||
#set(CPPUTEST_LIBRARIES CppUTest CppUTestExt)
|
||||
#set(CPPUTEST_LDFLAGS CppUTest CppUTestExt)
|
||||
set(CPPUTEST_LIBRARIES CppUTest CppUTestExt)
|
||||
else()
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_search_module(CPPUTEST REQUIRED cpputest>=3.8)
|
||||
message(STATUS "Found CppUTest version ${CPPUTEST_VERSION}")
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
${CPPUTEST_INCLUDE_DIRS}
|
||||
#/usr/include/c++/11/
|
||||
./inc
|
||||
./mocks
|
||||
)
|
||||
link_directories(${CPPUTEST_LIBRARIES})
|
||||
# Diagnostic Messages for Multi-Platform testing.
|
||||
message(STATUS "CPPUTEST_LIBRARY_DIRS: ${CPPUTEST_LIBRARY_DIRS}")
|
||||
message(STATUS "CPPUTEST_INCLUDE_DIRS: ${CPPUTEST_INCLUDE_DIRS}" )
|
||||
message(STATUS "CPPUTEST_LIBRARIES: ${CPPUTEST_LIBRARIES}" )
|
||||
|
||||
include_directories(${CPPUTEST_INCLUDE_DIRS})
|
||||
link_directories(${CPPUTEST_LIBRARY_DIRS})
|
||||
|
||||
add_subdirectory(mocks)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
|
|
|
|||
1
cpputest
1
cpputest
|
|
@ -1 +0,0 @@
|
|||
Subproject commit c3625dc668b4be4a1639e7e81f681e7d709a7b93
|
||||
0
extern/.git_dir
vendored
Normal file
0
extern/.git_dir
vendored
Normal file
|
|
@ -1,11 +1,29 @@
|
|||
/**
|
||||
* @brief CH32VFUN configuration header.
|
||||
* @details This file is a ch32fun configuration file.
|
||||
* @author Jake G
|
||||
* @date TODAYS_YEAR
|
||||
* @copyright None
|
||||
* @file funconfig.h
|
||||
*/
|
||||
|
||||
//Standard C header guard.
|
||||
#ifndef _FUNCONFIG_H
|
||||
#define _FUNCONFIG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define CH32V003 1
|
||||
#define FUNCONF_USE_DEBUGPRINTF 0
|
||||
#define FUNCONF_USE_UARTPRINTF 1
|
||||
#define FUNCONF_UART_PRINTF_BAUD 115200
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
#endif //_FUNCONFIG_H
|
||||
|
|
|
|||
24
otto.sh
24
otto.sh
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
# Author: Jake Goodwin
|
||||
# Date: 2024
|
||||
# Date: 2025
|
||||
# Filename: otto.sh
|
||||
|
||||
WCH_TC="$(pwd)/riscv32-toolchain.cmake"
|
||||
|
|
@ -10,20 +10,37 @@ TEMPLATE_FILES=".template_files"
|
|||
MODULE_DIR="${TEMPLATE_FILES}/modules"
|
||||
CHIP="ch32v003"
|
||||
|
||||
generate_tags_file () {
|
||||
uctags --recurse=yes \
|
||||
--languages=C,C++,Asm \
|
||||
--extras=+q \
|
||||
--fields=+iaS \
|
||||
--exclude=extern \
|
||||
--exclude=build \
|
||||
--exclude=.git \
|
||||
--exclude=.template_files \
|
||||
.
|
||||
}
|
||||
|
||||
format_source_code () {
|
||||
#Get a list of all C files
|
||||
source_c_files=$(find ./src -name '*.c')
|
||||
source_c_files=$(find ./src ./tests -name '*.c')
|
||||
for f in $source_c_files; do
|
||||
clang-format -i -style=file $f
|
||||
done
|
||||
|
||||
#Get a list of all H files
|
||||
source_h_files=$(find ./src -name '*.h')
|
||||
source_h_files=$(find ./src ./tests -name '*.h')
|
||||
for f in $source_h_files; do
|
||||
clang-format -i -style=file $f
|
||||
done
|
||||
|
||||
#Get a list of all Cpp files.
|
||||
source_cpp_files=$(find ./src ./tests -name '*.cpp')
|
||||
for f in $source_cpp_files; do
|
||||
clang-format -i -style=file $f
|
||||
done
|
||||
|
||||
echo "Applying Formating standard!"
|
||||
}
|
||||
|
||||
|
|
@ -270,6 +287,7 @@ flash_microcontroller () {
|
|||
}
|
||||
|
||||
run_c_tests () {
|
||||
generate_tags_file()
|
||||
format_source_code
|
||||
clear_cmake_cache
|
||||
cmake -DUNIT_TESTING=ON -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE} ../
|
||||
|
|
|
|||
|
|
@ -1,17 +1,33 @@
|
|||
# File: srcs/ADC/CMakeLists.txt
|
||||
add_library(ADC STATIC
|
||||
ADC.c
|
||||
)
|
||||
target_include_directories(ADC PUBLIC
|
||||
|
||||
if(NOT UNIT_TESTING)
|
||||
target_include_directories(ADC PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
if(UNIT_TESTING)
|
||||
target_link_libraries(ADC
|
||||
MockRegEdit
|
||||
${CMAKE_SOURCE_DIR}/inc/
|
||||
)
|
||||
|
||||
else()
|
||||
target_link_libraries(ADC
|
||||
RegEdit
|
||||
)
|
||||
else()
|
||||
target_include_directories(ADC PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
#First we include any module specific test dependencies.
|
||||
${CMAKE_SOURCE_DIR}/tests/ADC/mocks/
|
||||
${CMAKE_SOURCE_DIR}/tests/ADC/fakes/
|
||||
${CMAKE_SOURCE_DIR}/tests/ADC/stubs/
|
||||
#Next comes the shared and non-module specific test depencencies.
|
||||
${CMAKE_SOURCE_DIR}/tests/shared/mocks/
|
||||
${CMAKE_SOURCE_DIR}/tests/shared/fakes/
|
||||
${CMAKE_SOURCE_DIR}/tests/shared/stubs/
|
||||
#Finally we include the local stuff, which has likely been overridden.
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
#Place Mocked/Regular dependencies here for unit testing.
|
||||
target_link_libraries(ADC
|
||||
MockRegEdit
|
||||
)
|
||||
endif()
|
||||
|
||||
|
|
|
|||
|
|
@ -5,3 +5,32 @@ add_library(RegEdit STATIC
|
|||
target_include_directories(RegEdit PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
|
||||
if(NOT UNIT_TESTING)
|
||||
target_include_directories(RegEdit PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_SOURCE_DIR}/inc/
|
||||
)
|
||||
#target_link_libraries(RegEdit
|
||||
#
|
||||
#)
|
||||
else()
|
||||
target_include_directories(RegEdit PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
#First we include any module specific test dependencies.
|
||||
${CMAKE_SOURCE_DIR}/tests/RegEdit/mocks/
|
||||
${CMAKE_SOURCE_DIR}/tests/RegEdit/fakes/
|
||||
${CMAKE_SOURCE_DIR}/tests/RegEdit/stubs/
|
||||
#Next comes the shared and non-module specific test depencencies.
|
||||
${CMAKE_SOURCE_DIR}/tests/shared/mocks/
|
||||
${CMAKE_SOURCE_DIR}/tests/shared/fakes/
|
||||
${CMAKE_SOURCE_DIR}/tests/shared/stubs/
|
||||
#Finally we include the local stuff, which has likely been overridden.
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
#Place Mocked/Regular dependencies here for unit testing.
|
||||
#target_link_libraries(RegEdit
|
||||
#
|
||||
#)
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -1,17 +1,28 @@
|
|||
# File: tests/ADC/CMakeLists.txt
|
||||
|
||||
add_subdirectory(mocks)
|
||||
add_subdirectory(fakes)
|
||||
add_subdirectory(stubs)
|
||||
|
||||
# TEST_RUNNER
|
||||
add_library(test_ADC
|
||||
test_ADC.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(test_ADC
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
ADC
|
||||
MockRegEdit
|
||||
)
|
||||
|
||||
#Needed for the tests to function
|
||||
include_directories(
|
||||
/usr/local/avr/include/avr
|
||||
#/usr/lib/avr/include/avr
|
||||
target_include_directories(test_ADC PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
#Next comes the shared and non-module specific test depencencies.
|
||||
${CMAKE_SOURCE_DIR}/tests/shared/mocks/
|
||||
${CMAKE_SOURCE_DIR}/tests/shared/fakes/
|
||||
${CMAKE_SOURCE_DIR}/tests/shared/stubs/
|
||||
|
||||
${CMAKE_SOURCE_DIR}/inc
|
||||
)
|
||||
|
|
|
|||
0
tests/ADC/fakes/CMakeLists.txt
Normal file
0
tests/ADC/fakes/CMakeLists.txt
Normal file
0
tests/ADC/mocks/CMakeLists.txt
Normal file
0
tests/ADC/mocks/CMakeLists.txt
Normal file
0
tests/ADC/stubs/CMakeLists.txt
Normal file
0
tests/ADC/stubs/CMakeLists.txt
Normal file
|
|
@ -8,7 +8,7 @@ add_subdirectory(simple_test)
|
|||
add_subdirectory(ADC)
|
||||
add_subdirectory(MockADC)
|
||||
|
||||
|
||||
add_subdirectory(shared)
|
||||
|
||||
|
||||
# TEST_RUNNER
|
||||
|
|
@ -17,8 +17,7 @@ add_executable(AllTests
|
|||
)
|
||||
|
||||
target_link_libraries(AllTests
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
# TEST_LINKS
|
||||
test_blink
|
||||
test_ADC
|
||||
|
|
@ -31,8 +30,7 @@ add_executable(Mock_Tests
|
|||
)
|
||||
|
||||
target_link_libraries(Mock_Tests
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
test_MockRegEdit
|
||||
test_MockADC
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ add_library(test_MockADC
|
|||
)
|
||||
|
||||
target_link_libraries(test_MockADC
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
MockADC
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ add_library(test_MockRegEdit
|
|||
)
|
||||
|
||||
target_link_libraries(test_MockRegEdit
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
MockRegEdit
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ add_library(test_RegEdit
|
|||
)
|
||||
|
||||
target_link_libraries(test_RegEdit
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
RegEdit
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ add_library(test_blink
|
|||
)
|
||||
|
||||
target_link_libraries(test_blink
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
blink
|
||||
)
|
||||
|
|
|
|||
5
tests/shared/CMakeLists.txt
Normal file
5
tests/shared/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# File: tests/shared/CMakeLists.txt
|
||||
|
||||
add_subdirectory(mocks)
|
||||
add_subdirectory(fakes)
|
||||
add_subdirectory(stubs)
|
||||
0
tests/shared/fakes/CMakeLists.txt
Normal file
0
tests/shared/fakes/CMakeLists.txt
Normal file
6
tests/shared/mocks/CMakeLists.txt
Normal file
6
tests/shared/mocks/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
add_subdirectory(MockRegEdit)
|
||||
add_subdirectory(MockADC)
|
||||
add_subdirectory(TimerMock)
|
||||
|
||||
|
||||
|
||||
11
tests/shared/mocks/MockADC/CMakeLists.txt
Normal file
11
tests/shared/mocks/MockADC/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
add_library(MockADC STATIC
|
||||
MockADC.c
|
||||
)
|
||||
|
||||
target_include_directories(MockADC PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(MockADC
|
||||
${CPPUTEST_LIBRARIES}
|
||||
)
|
||||
84
tests/shared/mocks/MockADC/MockADC.c
Normal file
84
tests/shared/mocks/MockADC/MockADC.c
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Author: username
|
||||
* Date: 2024
|
||||
* filename: MockADC.c
|
||||
* description: module_purpose
|
||||
*/
|
||||
|
||||
#include "MockADC.h"
|
||||
#include "CppUTestExt/MockSupport_c.h"
|
||||
|
||||
#define FAKESIZE 256
|
||||
|
||||
uint16_t fake_data[FAKESIZE];
|
||||
int fake_index = 0;
|
||||
|
||||
static bool is_setup = false;
|
||||
|
||||
|
||||
|
||||
void ADC_SetPin(uint8_t pin_num)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void ADC_Setup(void)
|
||||
{
|
||||
is_setup = true;
|
||||
return;
|
||||
}
|
||||
|
||||
void ADC_Init(uint8_t pin_num)
|
||||
{
|
||||
mock_c()->actualCall("ADC_Init")
|
||||
->withUnsignedIntParameters("pin_num", pin_num);
|
||||
}
|
||||
|
||||
void ADC_Enable(void)
|
||||
{
|
||||
mock_c()->actualCall("ADC_Enable");
|
||||
}
|
||||
|
||||
void ADC_Disable(void)
|
||||
{
|
||||
mock_c()->actualCall("ADC_Disable");
|
||||
}
|
||||
|
||||
uint16_t ADC_ReadValue_Impl(uint8_t pin_num)
|
||||
{
|
||||
mock_c()->actualCall("ADC_ReadValue_Impl")
|
||||
->withUnsignedIntParameters("pin_num", pin_num);
|
||||
|
||||
if(fake_index == 0){
|
||||
return 0;
|
||||
}
|
||||
return fake_data[--fake_index];
|
||||
}
|
||||
|
||||
uint16_t (*ADC_ReadValue)(uint8_t pin_num) = ADC_ReadValue_Impl;
|
||||
|
||||
|
||||
void MockADC_PushValue(uint16_t value){
|
||||
if(fake_index >= FAKESIZE - 1){
|
||||
return;
|
||||
}
|
||||
fake_data[fake_index++] = value;
|
||||
}
|
||||
|
||||
|
||||
void MockADC_ZeroIndex(void)
|
||||
{
|
||||
fake_index = 0;
|
||||
}
|
||||
|
||||
|
||||
int MockADC_GetIndex(void)
|
||||
{
|
||||
return fake_index;
|
||||
}
|
||||
|
||||
|
||||
bool MockADC_IsSetup(void)
|
||||
{
|
||||
return is_setup;
|
||||
}
|
||||
30
tests/shared/mocks/MockADC/MockADC.h
Normal file
30
tests/shared/mocks/MockADC/MockADC.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* @brief PUT_TEXT_HERE
|
||||
* @details This file is...
|
||||
* @author username
|
||||
* @date todays_date
|
||||
* @copyright None
|
||||
* @file MOCKADC.h
|
||||
*/
|
||||
|
||||
#ifndef MOCKADC_H
|
||||
#define MOCKADC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
void ADC_Setup(void);
|
||||
void ADC_SetPin(uint8_t pin_num);
|
||||
void ADC_Init(uint8_t pin_num);
|
||||
void ADC_Enable(void);
|
||||
void ADC_Disable(void);
|
||||
|
||||
extern uint16_t (*ADC_ReadValue)(uint8_t pin_num);
|
||||
|
||||
void MockADC_PushValue(uint16_t value);
|
||||
void MockADC_ZeroIndex(void);
|
||||
int MockADC_GetIndex(void);
|
||||
bool MockADC_IsSetup(void);
|
||||
|
||||
#endif //MOCKADC_H
|
||||
11
tests/shared/mocks/MockRegEdit/CMakeLists.txt
Normal file
11
tests/shared/mocks/MockRegEdit/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
add_library(MockRegEdit STATIC
|
||||
MockRegEdit.c
|
||||
)
|
||||
|
||||
target_include_directories(MockRegEdit PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(MockRegEdit
|
||||
${CPPUTEST_LIBRARIES}
|
||||
)
|
||||
85
tests/shared/mocks/MockRegEdit/MockRegEdit.c
Normal file
85
tests/shared/mocks/MockRegEdit/MockRegEdit.c
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Author: username
|
||||
* Date: 2024
|
||||
* filename: MockRegEdit.c
|
||||
* description: module_purpose
|
||||
*/
|
||||
|
||||
#include "MockRegEdit.h"
|
||||
#include "CppUTestExt/MockSupport_c.h"
|
||||
|
||||
|
||||
void RegEdit_SetRegister(void *reg)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_SetRegister")
|
||||
->withPointerParameters("reg", reg);
|
||||
}
|
||||
|
||||
void RegEdit_ClearRegister(void *reg)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_ClearRegister")
|
||||
->withPointerParameters("reg", reg);
|
||||
}
|
||||
|
||||
|
||||
void RegEdit_SetBit(void *reg, uint8_t bit_num)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_SetBit")
|
||||
->withPointerParameters("reg", reg)
|
||||
->withUnsignedIntParameters("bit_num", bit_num);
|
||||
}
|
||||
|
||||
|
||||
void RegEdit_ClearBit(void *reg, uint8_t bit_num)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_ClearBit")
|
||||
->withPointerParameters("reg", reg)
|
||||
->withUnsignedIntParameters("bit_num", bit_num);
|
||||
}
|
||||
|
||||
|
||||
bool RegEdit_IsBitSet(void *reg, uint8_t bit_num)
|
||||
{
|
||||
|
||||
return mock_c()->actualCall("RegEdit_IsBitSet")
|
||||
->withPointerParameters("reg", reg)
|
||||
->withUnsignedIntParameters("bit_num", bit_num)
|
||||
->returnBoolValueOrDefault(true);
|
||||
//return mock_c()->returnBoolValueOrDefault(true);
|
||||
}
|
||||
|
||||
void RegEdit_OR_Num(void *reg, uint32_t num)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_OR_Num")
|
||||
->withPointerParameters("reg", reg)
|
||||
->withUnsignedIntParameters("num", num);
|
||||
}
|
||||
|
||||
|
||||
void RegEdit_AND_Num(void *reg, uint32_t num)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_AND_Num")
|
||||
->withPointerParameters("reg", reg)
|
||||
->withUnsignedIntParameters("num", num);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RegEdit_SetNum(void *reg, uint32_t num)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_SetNum")
|
||||
->withPointerParameters("reg", reg)
|
||||
->withUnsignedIntParameters("num", num);
|
||||
}
|
||||
|
||||
|
||||
uint8_t RegEdit_ReadReg(void *reg)
|
||||
{
|
||||
uint8_t value = *(uint8_t *)reg;
|
||||
|
||||
mock_c()->actualCall("RegEdit_ReadReg")
|
||||
->withPointerParameters("reg", reg)
|
||||
->returnUnsignedIntValueOrDefault(value);
|
||||
|
||||
return value;
|
||||
}
|
||||
30
tests/shared/mocks/MockRegEdit/MockRegEdit.h
Normal file
30
tests/shared/mocks/MockRegEdit/MockRegEdit.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* @brief PUT_TEXT_HERE
|
||||
* @details This file is...
|
||||
* @author username
|
||||
* @date todays_date
|
||||
* @copyright None
|
||||
* @file MockRegEdit.h
|
||||
*/
|
||||
|
||||
#ifndef MOCKREGEDIT_H
|
||||
#define MOCKREGEDIT_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void RegEdit_SetRegister(void *reg);
|
||||
void RegEdit_ClearRegister(void *reg);
|
||||
void RegEdit_SetBit(void *reg, uint8_t bit_num);
|
||||
void RegEdit_ClearBit(void *reg, uint8_t bit_num);
|
||||
bool RegEdit_IsBitSet(void *reg, uint8_t bit_num);
|
||||
|
||||
void RegEdit_OR_Num(void *reg, uint32_t num);
|
||||
void RegEdit_AND_Num(void *reg, uint32_t num);
|
||||
|
||||
void RegEdit_SetNum(void *reg, uint32_t num);
|
||||
|
||||
uint8_t RegEdit_ReadReg(void *reg);
|
||||
|
||||
#endif //MOCKREGEDIT_H
|
||||
51
tests/shared/mocks/MockRegEdit/u8_comparator.cpp
Normal file
51
tests/shared/mocks/MockRegEdit/u8_comparator.cpp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#include "u8_comparator.hpp"
|
||||
#include "CppUTest/SimpleString.h"
|
||||
|
||||
/*
|
||||
class MyTypeComparator : public MockNamedValueComparator
|
||||
{
|
||||
public:
|
||||
virtual bool isEqual(const void* object1, const void* object2)
|
||||
{
|
||||
return object1 == object2;
|
||||
}
|
||||
virtual SimpleString valueToString(const void* object)
|
||||
{
|
||||
return StringFrom(object);
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
bool UInt8PointerComparator::isEqual(const void* object1, const void* object2) {
|
||||
const uint8_t* ptr1 = reinterpret_cast<const uint8_t*>(object1);
|
||||
const uint8_t* ptr2 = reinterpret_cast<const uint8_t*>(object2);
|
||||
return std::memcmp(ptr1, ptr2, sizeof(uint8_t)) == 0;
|
||||
}
|
||||
|
||||
SimpleString UInt8PointerComparator::valueToString(const void* object) {
|
||||
const uint8_t* ptr = reinterpret_cast<const uint8_t*>(object);
|
||||
return StringFromFormat("0x%02x", *ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
bool UInt8PointerComparator::isEqual(const void* object1, const void* object2) const {
|
||||
const uint8_t* ptr1 = static_cast<const uint8_t*>(object1);
|
||||
const uint8_t* ptr2 = static_cast<const uint8_t*>(object2);
|
||||
return std::memcmp(ptr1, ptr2, sizeof(uint8_t)) == 0;
|
||||
}
|
||||
|
||||
SimpleString UInt8PointerComparator::valueToString(const void* object) const {
|
||||
const uint8_t* ptr = static_cast<const uint8_t*>(object);
|
||||
return StringFromFormat("0x%02x", *ptr);
|
||||
}
|
||||
*/
|
||||
|
||||
bool UInt8Comparator::isEqual(const void* object1, const void* object2) {
|
||||
return (uint8_t*)object1 == (uint8_t *)object2;
|
||||
}
|
||||
|
||||
SimpleString UInt8Comparator::valueToString(const void* object) {
|
||||
//uint8_t value = reinterpret_cast<uint8_t>(object);
|
||||
const uint8_t *ptr = reinterpret_cast<const uint8_t*>(object);
|
||||
return StringFromFormat("0x%02x", *ptr);
|
||||
}
|
||||
20
tests/shared/mocks/MockRegEdit/u8_comparator.hpp
Normal file
20
tests/shared/mocks/MockRegEdit/u8_comparator.hpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef U8_COMPARATOR_H
|
||||
#define U8_COMPARATOR_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <CppUTestExt/MockSupport.h>
|
||||
|
||||
class UInt8PointerComparator : public MockNamedValueComparator {
|
||||
public:
|
||||
virtual bool isEqual(const void* object1, const void* object2) override;
|
||||
SimpleString valueToString(const void* object) override;
|
||||
};
|
||||
|
||||
class UInt8Comparator : public MockNamedValueComparator {
|
||||
public:
|
||||
virtual bool isEqual(const void* object1, const void* object2) override;
|
||||
SimpleString valueToString(const void* object) override;
|
||||
};
|
||||
|
||||
#endif //U8_COMPARATOR_H
|
||||
11
tests/shared/mocks/TimerMock/CMakeLists.txt
Normal file
11
tests/shared/mocks/TimerMock/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
add_library(TimerMock STATIC
|
||||
TimerMock.c
|
||||
)
|
||||
|
||||
target_include_directories(TimerMock PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(TimerMock
|
||||
${CPPUTEST_LIBRARIES}
|
||||
)
|
||||
31
tests/shared/mocks/TimerMock/TimerMock.c
Normal file
31
tests/shared/mocks/TimerMock/TimerMock.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Author: Jake G
|
||||
* Date: 2024-09-02
|
||||
* filename: TimerMock.c
|
||||
* description: mocks timers
|
||||
*/
|
||||
|
||||
#include "TimerMock.h"
|
||||
#include <stdbool.h>
|
||||
#include "CppUTestExt/MockSupport_c.h"
|
||||
|
||||
static bool timer_started = false;
|
||||
|
||||
void Timer_Start(void)
|
||||
{
|
||||
mock_c()->actualCall("Timer_Start");
|
||||
timer_started = true;
|
||||
}
|
||||
|
||||
void Timer_Stop(void)
|
||||
{
|
||||
mock_c()->actualCall("Timer_Stop");
|
||||
timer_started = false;
|
||||
}
|
||||
|
||||
uint16_t Timer_GetOverflowCount(void)
|
||||
{
|
||||
uint16_t time = 0xAAAA;
|
||||
return mock_c()->actualCall("Timer_GetOverflowCount")
|
||||
->returnUnsignedIntValueOrDefault(time);
|
||||
}
|
||||
26
tests/shared/mocks/TimerMock/TimerMock.h
Normal file
26
tests/shared/mocks/TimerMock/TimerMock.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* @brief A Mock of the timer module.
|
||||
* @details This file is only used for testing.
|
||||
* @author Jake G
|
||||
* @date 2024-09-02
|
||||
* @copyright None
|
||||
* @file TimerMock.h
|
||||
*/
|
||||
|
||||
#ifndef TIMER_MOCK_H
|
||||
#define TIMER_MOCK_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* A function
|
||||
* @param a The first argument
|
||||
*/
|
||||
void Timer_Start(void);
|
||||
|
||||
void Timer_Stop(void);
|
||||
|
||||
uint16_t Timer_GetOverflowCount(void);
|
||||
|
||||
|
||||
#endif //TIMER_MOCK_H
|
||||
0
tests/shared/stubs/CMakeLists.txt
Normal file
0
tests/shared/stubs/CMakeLists.txt
Normal file
|
|
@ -5,7 +5,6 @@ add_library(simple_test
|
|||
)
|
||||
|
||||
target_link_libraries(simple_test
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue