Compare commits
No commits in common. "1ebd68346e72cd45ca3c9a4782ab744e228598be" and "5dc658b6201bf22e982e953f054e94c87335f13a" have entirely different histories.
1ebd68346e
...
5dc658b620
38 changed files with 52 additions and 604 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
|
@ -0,0 +1,3 @@
|
|||
[submodule "cpputest"]
|
||||
path = cpputest
|
||||
url = https://github.com/cpputest/cpputest.git
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
# 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/
|
||||
)
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* 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(WCH_Template
|
||||
project(main
|
||||
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 -Werror -Wpedantic")
|
||||
set(CMAKE_C_FLAGS "-Wall -Wpedantic")
|
||||
|
||||
# SETUP THE CXX flags for .cpp
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
|
|
@ -39,30 +39,27 @@ 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_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)
|
||||
set(CPPUTEST_LIBRARIES $ENV{CPPUTEST_HOME}/lib)
|
||||
set(CPPUTEST_LDFLAGS CppUTest CppUTestExt)
|
||||
else()
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_search_module(CPPUTEST REQUIRED cpputest>=3.8)
|
||||
message(STATUS "Found CppUTest version ${CPPUTEST_VERSION}")
|
||||
endif()
|
||||
|
||||
# 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})
|
||||
|
||||
include_directories(
|
||||
${CPPUTEST_INCLUDE_DIRS}
|
||||
#/usr/include/c++/11/
|
||||
./inc
|
||||
./mocks
|
||||
)
|
||||
link_directories(${CPPUTEST_LIBRARIES})
|
||||
|
||||
add_subdirectory(mocks)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
|
|
|
|||
1
cpputest
Submodule
1
cpputest
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit c3625dc668b4be4a1639e7e81f681e7d709a7b93
|
||||
0
extern/.git_dir
vendored
0
extern/.git_dir
vendored
|
|
@ -1,29 +1,11 @@
|
|||
/**
|
||||
* @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 //_FUNCONFIG_H
|
||||
#endif
|
||||
|
|
|
|||
24
otto.sh
24
otto.sh
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
# Author: Jake Goodwin
|
||||
# Date: 2025
|
||||
# Date: 2024
|
||||
# Filename: otto.sh
|
||||
|
||||
WCH_TC="$(pwd)/riscv32-toolchain.cmake"
|
||||
|
|
@ -10,37 +10,20 @@ 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 ./tests -name '*.c')
|
||||
source_c_files=$(find ./src -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 ./tests -name '*.h')
|
||||
source_h_files=$(find ./src -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!"
|
||||
}
|
||||
|
||||
|
|
@ -287,7 +270,6 @@ flash_microcontroller () {
|
|||
}
|
||||
|
||||
run_c_tests () {
|
||||
generate_tags_file()
|
||||
format_source_code
|
||||
clear_cmake_cache
|
||||
cmake -DUNIT_TESTING=ON -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE} ../
|
||||
|
|
|
|||
|
|
@ -1,33 +1,17 @@
|
|||
# File: srcs/ADC/CMakeLists.txt
|
||||
add_library(ADC STATIC
|
||||
ADC.c
|
||||
)
|
||||
target_include_directories(ADC PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
if(NOT UNIT_TESTING)
|
||||
target_include_directories(ADC PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_SOURCE_DIR}/inc/
|
||||
)
|
||||
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.
|
||||
if(UNIT_TESTING)
|
||||
target_link_libraries(ADC
|
||||
MockRegEdit
|
||||
)
|
||||
endif()
|
||||
|
||||
else()
|
||||
target_link_libraries(ADC
|
||||
RegEdit
|
||||
)
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -5,32 +5,3 @@ 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,28 +1,17 @@
|
|||
# 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}
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
ADC
|
||||
MockRegEdit
|
||||
)
|
||||
|
||||
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
|
||||
#Needed for the tests to function
|
||||
include_directories(
|
||||
/usr/local/avr/include/avr
|
||||
#/usr/lib/avr/include/avr
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ add_subdirectory(simple_test)
|
|||
add_subdirectory(ADC)
|
||||
add_subdirectory(MockADC)
|
||||
|
||||
add_subdirectory(shared)
|
||||
|
||||
|
||||
|
||||
# TEST_RUNNER
|
||||
|
|
@ -17,7 +17,8 @@ add_executable(AllTests
|
|||
)
|
||||
|
||||
target_link_libraries(AllTests
|
||||
${CPPUTEST_LIBRARIES}
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
# TEST_LINKS
|
||||
test_blink
|
||||
test_ADC
|
||||
|
|
@ -30,7 +31,8 @@ add_executable(Mock_Tests
|
|||
)
|
||||
|
||||
target_link_libraries(Mock_Tests
|
||||
${CPPUTEST_LIBRARIES}
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
test_MockRegEdit
|
||||
test_MockADC
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ add_library(test_MockADC
|
|||
)
|
||||
|
||||
target_link_libraries(test_MockADC
|
||||
${CPPUTEST_LIBRARIES}
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
MockADC
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@ add_library(test_MockRegEdit
|
|||
)
|
||||
|
||||
target_link_libraries(test_MockRegEdit
|
||||
${CPPUTEST_LIBRARIES}
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
MockRegEdit
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ add_library(test_RegEdit
|
|||
)
|
||||
|
||||
target_link_libraries(test_RegEdit
|
||||
${CPPUTEST_LIBRARIES}
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
RegEdit
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ add_library(test_blink
|
|||
)
|
||||
|
||||
target_link_libraries(test_blink
|
||||
${CPPUTEST_LIBRARIES}
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
blink
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
# File: tests/shared/CMakeLists.txt
|
||||
|
||||
add_subdirectory(mocks)
|
||||
add_subdirectory(fakes)
|
||||
add_subdirectory(stubs)
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
add_subdirectory(MockRegEdit)
|
||||
add_subdirectory(MockADC)
|
||||
add_subdirectory(TimerMock)
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
add_library(MockADC STATIC
|
||||
MockADC.c
|
||||
)
|
||||
|
||||
target_include_directories(MockADC PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(MockADC
|
||||
${CPPUTEST_LIBRARIES}
|
||||
)
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/**
|
||||
* @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
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
add_library(MockRegEdit STATIC
|
||||
MockRegEdit.c
|
||||
)
|
||||
|
||||
target_include_directories(MockRegEdit PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(MockRegEdit
|
||||
${CPPUTEST_LIBRARIES}
|
||||
)
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/**
|
||||
* @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
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
#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);
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
#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
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
add_library(TimerMock STATIC
|
||||
TimerMock.c
|
||||
)
|
||||
|
||||
target_include_directories(TimerMock PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(TimerMock
|
||||
${CPPUTEST_LIBRARIES}
|
||||
)
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
/**
|
||||
* @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
|
||||
|
|
@ -5,6 +5,7 @@ add_library(simple_test
|
|||
)
|
||||
|
||||
target_link_libraries(simple_test
|
||||
${CPPUTEST_LIBRARIES}
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue