Compare commits
11 commits
a7f51ff472
...
d315aa7780
| Author | SHA1 | Date | |
|---|---|---|---|
| d315aa7780 | |||
| bca83430f7 | |||
| 5d31d1e97f | |||
| c5e573f835 | |||
| d39e011b8c | |||
| 28454182d9 | |||
| e34b4f47bd | |||
| 491b35c00d | |||
| 194669a737 | |||
| 04a0abd72d | |||
| bd81219d70 |
37 changed files with 839 additions and 84 deletions
24
.gitignore
vendored
24
.gitignore
vendored
|
|
@ -1,12 +1,12 @@
|
||||||
build/CMakeFiles
|
.cache/
|
||||||
build/Testing/Temporary
|
*.core
|
||||||
build/cpputest
|
tags
|
||||||
build/src
|
|
||||||
build/tests
|
# Keep the build directory itself.
|
||||||
build/CMakeCache.txt
|
build/*
|
||||||
build/CTestTestfile.cmake
|
|
||||||
build/Makefile
|
# Generated Documentation shouldn't be included.
|
||||||
build/cmake_install.cmake
|
docs/generated_docs/latex
|
||||||
build/compile_commands.json
|
docs/generated_docs/html
|
||||||
.cache/clangd/index
|
|
||||||
build/.cache/clangd/index
|
|
||||||
|
|
|
||||||
18
.template_files/mock_module/CMakeLists.txt
Normal file
18
.template_files/mock_module/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# File: tests/shared/mocks/module_name/CMakeLists.txt
|
||||||
|
|
||||||
|
# TEST_RUNNER
|
||||||
|
add_library(module_name STATIC
|
||||||
|
module_name.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(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/
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(module_name
|
||||||
|
${CPPUTEST_LIBRARIES}
|
||||||
|
)
|
||||||
3
.template_files/mock_module/module_name.c
Normal file
3
.template_files/mock_module/module_name.c
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#include "module_name.h"
|
||||||
|
|
||||||
|
|
||||||
29
.template_files/mock_module/module_name.h
Normal file
29
.template_files/mock_module/module_name.h
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
* @brief Module description
|
||||||
|
* @details This file is an <Purpose here>
|
||||||
|
* @author Jake G
|
||||||
|
* @date todays_date
|
||||||
|
* @copyright None
|
||||||
|
* @file module_name.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
//#pragma once
|
||||||
|
#ifndef module_name
|
||||||
|
#define module_name
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#endif //module_name
|
||||||
|
|
@ -1,7 +1,42 @@
|
||||||
|
# File: src/module_name/CMakeLists.txt
|
||||||
add_library(module_name STATIC
|
add_library(module_name STATIC
|
||||||
module_name.c
|
module_name.c
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(module_name PUBLIC
|
# Current list dir: The directory where the cmake config file is.
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
# Source Dir: The dir where the root/main cmake config file is.
|
||||||
)
|
|
||||||
|
if(NOT UNIT_TESTING)
|
||||||
|
target_include_directories(module_name PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
${CMAKE_SOURCE_DIR}/inc/
|
||||||
|
)
|
||||||
|
target_link_libraries(module_name
|
||||||
|
RegEdit
|
||||||
|
)
|
||||||
|
|
||||||
|
#These get defined in the toolchain files.
|
||||||
|
target_compile_options(module_name PUBLIC
|
||||||
|
${OBJECT_GEN_FLAGS}
|
||||||
|
${C_FLAGS_ARCH}
|
||||||
|
)
|
||||||
|
|
||||||
|
else()
|
||||||
|
target_include_directories(module_name PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
#First we include any module specific test dependencies.
|
||||||
|
${CMAKE_SOURCE_DIR}/tests/module_name/mocks/
|
||||||
|
${CMAKE_SOURCE_DIR}/tests/module_name/fakes/
|
||||||
|
${CMAKE_SOURCE_DIR}/tests/module_name/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(module_name
|
||||||
|
MockRegEdit
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "module_name.h"
|
#include "module_name.h"
|
||||||
|
#include "RegEdit.h"
|
||||||
|
|
||||||
// dumb test function
|
// dumb test function
|
||||||
int add_two(int a)
|
int add_two(int a)
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
/*
|
|
||||||
* Author: username
|
|
||||||
* Date: todays_date
|
|
||||||
* filename: module_name.cpp
|
|
||||||
* description: module_purpose
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "module_name.h"
|
|
||||||
|
|
||||||
// dumb test function
|
|
||||||
int add_two(int a)
|
|
||||||
{
|
|
||||||
int b = a;
|
|
||||||
b += 2;
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +1,31 @@
|
||||||
/*
|
/**
|
||||||
|
* @brief Module description
|
||||||
|
* @details This file is an <Purpose here>
|
||||||
|
* @author Jake G
|
||||||
|
* @date todays_date
|
||||||
|
* @copyright None
|
||||||
* @file module_name.h
|
* @file module_name.h
|
||||||
* @Author Jake Goodwin
|
|
||||||
* @Date todays_date
|
|
||||||
* @brief module_purpose
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef module_name
|
//#pragma once
|
||||||
#define module_name
|
#ifndef module_name_H
|
||||||
|
#define module_name_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
int add_two(int a);
|
int add_two(int a);
|
||||||
|
|
||||||
#endif //module_name
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#endif //module_name_H
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ extern "C"
|
||||||
#include "module_name.h"
|
#include "module_name.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_GROUP(test_module_name)
|
TEST_GROUP(FirstTestGroup)
|
||||||
{
|
{
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
@ -24,12 +24,12 @@ TEST_GROUP(test_module_name)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST(test_module_name, FirstTest)
|
TEST(FirstTestGroup, FirstTest)
|
||||||
{
|
{
|
||||||
FAIL("Fail me!");
|
FAIL("Fail me!");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_module_name, SecondTest)
|
TEST(FirstTestGroup, SecondTest)
|
||||||
{
|
{
|
||||||
STRCMP_EQUAL("hello", "world");
|
STRCMP_EQUAL("hello", "world");
|
||||||
LONGS_EQUAL(1, 2);
|
LONGS_EQUAL(1, 2);
|
||||||
|
|
|
||||||
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(tg_module_name)
|
||||||
|
{
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
void teardown()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(tg_module_name, FirstTest)
|
||||||
|
{
|
||||||
|
FAIL("Fail me!");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(tg_module_name, SecondTest)
|
||||||
|
{
|
||||||
|
STRCMP_EQUAL("hello", "world");
|
||||||
|
LONGS_EQUAL(1, 2);
|
||||||
|
CHECK(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
# Use the fancy version substitution
|
# Use the fancy version substitution
|
||||||
project(cmake-cpputest-template
|
project(cmake-cpputest-template
|
||||||
VERSION 1.0
|
VERSION 0.1.0
|
||||||
DESCRIPTION "template for cmake + cpputest"
|
DESCRIPTION "template for cmake + cpputest"
|
||||||
LANGUAGES C CXX
|
LANGUAGES C CXX
|
||||||
)
|
)
|
||||||
|
|
@ -52,15 +52,15 @@ if (UNIT_TESTING)
|
||||||
pkg_search_module(CPPUTEST REQUIRED cpputest>=3.8)
|
pkg_search_module(CPPUTEST REQUIRED cpputest>=3.8)
|
||||||
message(STATUS "Found CppUTest version ${CPPUTEST_VERSION}")
|
message(STATUS "Found CppUTest version ${CPPUTEST_VERSION}")
|
||||||
endif()
|
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}
|
|
||||||
./inc
|
|
||||||
./mocks
|
|
||||||
)
|
|
||||||
link_directories(${CPPUTEST_LIBRARIES})
|
|
||||||
|
|
||||||
add_subdirectory(mocks)
|
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
./build/compile_commands.json
|
|
||||||
0
docs/generated_docs/.git_dir
Normal file
0
docs/generated_docs/.git_dir
Normal file
|
|
@ -1,37 +1,70 @@
|
||||||
#!/bin/sh
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Author: Jake Goodwin
|
# Author: Jake Goodwin
|
||||||
# Date: 2024
|
# Date: 2026
|
||||||
# Filename: otto.sh
|
# Filename: otto.sh
|
||||||
|
# Description: Automates the TDD process.
|
||||||
|
|
||||||
CROSS_TC_WIN="$(pwd)/i686-w64-mingw32_toolchain.cmake"
|
CROSS_TC_WIN="$(pwd)/i686-w64-mingw32_toolchain.cmake"
|
||||||
CMAKE_VERBOSE="ON"
|
CMAKE_VERBOSE="ON"
|
||||||
CROSS_COMPILE=1
|
CROSS_COMPILE=1
|
||||||
TEMPLATE_FILES=".template_files"
|
TEMPLATE_FILES=".template_files"
|
||||||
MODULE_DIR="${TEMPLATE_FILES}/modules"
|
MODULE_DIR="${TEMPLATE_FILES}/modules"
|
||||||
|
TEST_MODULE_DIR="${TEMPLATE_FILES}/test_module"
|
||||||
|
|
||||||
IS_FREEBSD=0
|
PROJECT_NAME="template"
|
||||||
is_freebsd () {
|
|
||||||
UNAME="$(uname)"
|
run_uc_tags() {
|
||||||
if [ $UNAME == "FreeBSD" ]; then
|
uctags --recurse=yes \
|
||||||
IS_FREEBSD=1
|
--languages=C,C++,Asm \
|
||||||
|
--extras=+q \
|
||||||
|
--fields=+iaS \
|
||||||
|
--exclude=extern \
|
||||||
|
--exclude=build \
|
||||||
|
--exclude=.git \
|
||||||
|
--exclude=.template_files \
|
||||||
|
--exclude=*.txt \
|
||||||
|
--exclude=*.md \
|
||||||
|
--exclude=*.S \
|
||||||
|
--exclude=*.json \
|
||||||
|
./
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_tags_file () {
|
||||||
|
echo "generate_tags_file()"
|
||||||
|
|
||||||
|
if find "tags" -mmin +30 | grep -q .; then
|
||||||
|
echo "generating tags."
|
||||||
|
run_uc_tags
|
||||||
|
elif [ ! -e tags ]; then
|
||||||
|
echo "no tags file found runnning tags."
|
||||||
|
run_uc_tags
|
||||||
else
|
else
|
||||||
IS_FREEBSD=0
|
echo "Skipping tags generation."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
format_source_code () {
|
format_source_code () {
|
||||||
#Get a list of all C files
|
#Get a list of all C files
|
||||||
source_c_files=$(find ./src -name '*.c')
|
source_c_files=$(find ./src ./tests/shared -name '*.c')
|
||||||
for f in $source_c_files; do
|
for f in $source_c_files; do
|
||||||
clang-format -i -style=file $f
|
clang-format -i -style=file $f
|
||||||
done
|
done
|
||||||
|
|
||||||
#Get a list of all H files
|
#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
|
for f in $source_h_files; do
|
||||||
clang-format -i -style=file $f
|
clang-format -i -style=file $f
|
||||||
done
|
done
|
||||||
|
|
||||||
|
#Get a list of all Cpp files.
|
||||||
|
source_cpp_files=$(find ./src ./tests/shared -name '*.cpp')
|
||||||
|
for f in $source_cpp_files; do
|
||||||
|
clang-format -i -style=file $f
|
||||||
|
done
|
||||||
|
|
||||||
echo "Applying Formating standard!"
|
echo "Applying Formating standard!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,6 +83,10 @@ clear_cmake_cache () {
|
||||||
rm -rf CMakeCache.txt CMakeFiles/
|
rm -rf CMakeCache.txt CMakeFiles/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clean_build_directory() {
|
||||||
|
rm -r ./build/*
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
does_module_exist () {
|
does_module_exist () {
|
||||||
local basename="$1"
|
local basename="$1"
|
||||||
|
|
@ -61,15 +98,27 @@ does_module_exist () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
does_mock_exist () {
|
||||||
|
local basename="$1"
|
||||||
|
|
||||||
|
if [ -d "mocks/${basename}" ]; then
|
||||||
|
echo "1"
|
||||||
|
else
|
||||||
|
echo "0"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
add_module_to_cmakes () {
|
add_module_to_cmakes () {
|
||||||
local basename="$1"
|
local basename="$1"
|
||||||
|
echo "add_module_to_cmakes()"
|
||||||
echo "add_subdirectory(${basename})" >> ./src/CMakeLists.txt
|
echo "add_subdirectory(${basename})" >> ./src/CMakeLists.txt
|
||||||
|
|
||||||
# Tests cmake file needs to be edited in place.
|
# Tests cmake file needs to be edited in place.
|
||||||
sed -i'' "s/# TEST_DIRS.*$/# TEST_DIRS\r\nadd_subdirectory(${basename})/g" ./tests/CMakeLists.txt
|
# sed -i'' "s/# TEST_DIRS.*$/# TEST_DIRS\r\nadd_subdirectory(${basename})/g" ./tests/CMakeLists.txt
|
||||||
sed -i'' "s/# TEST_LINKS.*$/# TEST_LINKS\r\n\t${basename}/g" ./tests/CMakeLists.txt
|
# sed -i'' "s/# TEST_LINKS.*$/# TEST_LINKS\r\n\t${basename}/g" ./tests/CMakeLists.txt
|
||||||
|
sed -i '' -e "s|# TEST_DIRS.*$|# TEST_DIRS\nadd_subdirectory(${basename})|" ./tests/CMakeLists.txt
|
||||||
|
sed -i '' -e "s|# TEST_LINKS.*$|# TEST_LINKS\ntest_${basename}|" ./tests/CMakeLists.txt
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_module_from_cmakes () {
|
remove_module_from_cmakes () {
|
||||||
|
|
@ -78,6 +127,7 @@ remove_module_from_cmakes () {
|
||||||
sed -i'' "s/^.*add_subdirectory(${basename}).*$//g" ./src/CMakeLists.txt
|
sed -i'' "s/^.*add_subdirectory(${basename}).*$//g" ./src/CMakeLists.txt
|
||||||
sed -i'' "s/^.*add_subdirectory(${basename}).*$//g" ./tests/CMakeLists.txt
|
sed -i'' "s/^.*add_subdirectory(${basename}).*$//g" ./tests/CMakeLists.txt
|
||||||
sed -i'' "s/^.*${basename}.*$//g" ./tests/CMakeLists.txt
|
sed -i'' "s/^.*${basename}.*$//g" ./tests/CMakeLists.txt
|
||||||
|
# sed -i'' "s/^.*test_${basename}.*$//g" ./tests/CMakeLists.txt
|
||||||
}
|
}
|
||||||
|
|
||||||
git_add_module () {
|
git_add_module () {
|
||||||
|
|
@ -124,6 +174,9 @@ git_remove_module () {
|
||||||
git rm -r ./tests/CMakeLists.txt
|
git rm -r ./tests/CMakeLists.txt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
add_mock_module() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
add_new_module () {
|
add_new_module () {
|
||||||
|
|
||||||
|
|
@ -136,14 +189,8 @@ add_new_module () {
|
||||||
echo "Exiting without changing anything"
|
echo "Exiting without changing anything"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
is_freebsd
|
|
||||||
if [ IS_FREEBSD -eq 0]; then
|
|
||||||
modname_cap=$(echo $modname | sed 's/[a-z]/\U&/g')
|
|
||||||
else
|
|
||||||
modname_cap=$( echo $modname | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/')
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
modname_cap=$(echo $modname | sed 's/[a-z]/\U&/g')
|
||||||
modsrc_dir="./src/${modname}"
|
modsrc_dir="./src/${modname}"
|
||||||
modtest_dir="./tests/${modname}"
|
modtest_dir="./tests/${modname}"
|
||||||
|
|
||||||
|
|
@ -182,16 +229,16 @@ add_new_module () {
|
||||||
|
|
||||||
add_c_mdoule () {
|
add_c_mdoule () {
|
||||||
|
|
||||||
sed "s/module_name/${modname}/" $MODULE_DIR/module_name.c > $modsrc_dir/${modname}.c
|
sed -e "s/module_name/${modname}/" $MODULE_DIR/module_name.c > $modsrc_dir/${modname}.c
|
||||||
sed -i'' "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.c
|
sed -i'' -e "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.c
|
||||||
|
|
||||||
sed "s/module_name/${modname_cap}/" $MODULE_DIR/module_name.h > $modsrc_dir/${modname}.h
|
sed -e "s/module_name/${modname_cap}/" $MODULE_DIR/module_name.h > $modsrc_dir/${modname}.h
|
||||||
sed -i'' "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.h
|
sed -i'' -e "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.h
|
||||||
|
|
||||||
sed "s/module_name/${modname}/" $MODULE_DIR/CMakeLists.txt > $modsrc_dir/CMakeLists.txt
|
sed -e "s/module_name/${modname}/" $MODULE_DIR/CMakeLists.txt > $modsrc_dir/CMakeLists.txt
|
||||||
|
|
||||||
sed "s/module_name/${modname}/" $MODULE_DIR/test_module_name.cpp > $modtest_dir/test_${modname}.cpp
|
sed -e "s/module_name/${modname}/" $MODULE_DIR/test_module_name.cpp > $modtest_dir/test_${modname}.cpp
|
||||||
sed "s/module_name/${modname}/" $MODULE_DIR/TestCMakeLists.txt > $modtest_dir/CMakeLists.txt
|
sed -e "s/module_name/${modname}/" $MODULE_DIR/TestCMakeLists.txt > $modtest_dir/CMakeLists.txt
|
||||||
|
|
||||||
# Add the module to the cmake lists files.
|
# Add the module to the cmake lists files.
|
||||||
add_module_to_cmakes "${modname}"
|
add_module_to_cmakes "${modname}"
|
||||||
|
|
@ -221,6 +268,10 @@ add_cpp_module () {
|
||||||
echo "Resulting files/dirs:"
|
echo "Resulting files/dirs:"
|
||||||
tree -L 2 $modsrc_dir
|
tree -L 2 $modsrc_dir
|
||||||
tree -L 2 $modtest_dir
|
tree -L 2 $modtest_dir
|
||||||
|
|
||||||
|
# Now we add the new files to the git tracked files
|
||||||
|
git_add_module "${modname}"
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -250,14 +301,35 @@ build_main () {
|
||||||
}
|
}
|
||||||
|
|
||||||
run_c_tests () {
|
run_c_tests () {
|
||||||
|
generate_tags_file
|
||||||
format_source_code
|
format_source_code
|
||||||
clear_cmake_cache
|
clear_cmake_cache
|
||||||
cmake -DUNIT_TESTING=ON -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE} ../
|
cmake -DUNIT_TESTING=ON -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE} ../
|
||||||
make AllTests && ./tests/AllTests -v -c
|
|
||||||
|
if make AllTests; then
|
||||||
|
echo "Running: AllTests -c -v"
|
||||||
|
./tests/AllTests -v -c
|
||||||
|
else
|
||||||
|
echo "Failed to build AllTests."
|
||||||
|
echo "Press anykey to exit:"
|
||||||
|
read input
|
||||||
|
fi
|
||||||
|
|
||||||
|
read -p "Press anykey to continue:" input
|
||||||
|
|
||||||
|
if make Mock_Tests; then
|
||||||
|
tests/Mock_Tests -v -c
|
||||||
|
else
|
||||||
|
echo "Failed to build Mock_Tests."
|
||||||
|
echo "Press anykey to exit:"
|
||||||
|
read input
|
||||||
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print_menu () {
|
print_menu () {
|
||||||
echo "BUILD MENU:"
|
echo "BUILD MENU:"
|
||||||
|
echo "0. Add Mock Module"
|
||||||
echo "1. Run Tests"
|
echo "1. Run Tests"
|
||||||
echo "2. Build Project"
|
echo "2. Build Project"
|
||||||
echo "3. Build for release"
|
echo "3. Build for release"
|
||||||
|
|
@ -277,6 +349,11 @@ main() {
|
||||||
read -p "Enter your choice: " choice
|
read -p "Enter your choice: " choice
|
||||||
|
|
||||||
case $choice in
|
case $choice in
|
||||||
|
0)
|
||||||
|
echo "You selected Option 0"
|
||||||
|
valid_choice=true
|
||||||
|
add_mock_module
|
||||||
|
;;
|
||||||
1)
|
1)
|
||||||
echo "You selected Option 1"
|
echo "You selected Option 1"
|
||||||
valid_choice=true
|
valid_choice=true
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
project(Tests)
|
project(Tests)
|
||||||
|
|
||||||
# TEST_DIRS
|
# TEST_DIRS
|
||||||
|
|
||||||
|
add_subdirectory(shared)
|
||||||
add_subdirectory(simple_test)
|
add_subdirectory(simple_test)
|
||||||
|
|
||||||
# TEST_RUNNER
|
# TEST_RUNNER
|
||||||
|
|
@ -9,8 +11,7 @@ add_executable(AllTests
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(AllTests
|
target_link_libraries(AllTests
|
||||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
${CPPUTEST_LIBRARIES}
|
||||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
|
||||||
# TEST_LINKS
|
# TEST_LINKS
|
||||||
simple_test
|
simple_test
|
||||||
)
|
)
|
||||||
|
|
|
||||||
12
tests/MockTests.cpp
Normal file
12
tests/MockTests.cpp
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
#include "CppUTest/CommandLineTestRunner.h"
|
||||||
|
|
||||||
|
// ImportTestGroups
|
||||||
|
IMPORT_TEST_GROUP(test_MockRegEdit);
|
||||||
|
IMPORT_TEST_GROUP(test_MockADC);
|
||||||
|
|
||||||
|
// START: main
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
return RUN_ALL_TESTS(argc, argv);
|
||||||
|
}
|
||||||
|
// END: main
|
||||||
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}
|
||||||
|
)
|
||||||
79
tests/shared/mocks/MockADC/MockADC.c
Normal file
79
tests/shared/mocks/MockADC/MockADC.c
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
29
tests/shared/mocks/MockADC/MockADC.h
Normal file
29
tests/shared/mocks/MockADC/MockADC.h
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
* @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 <stdbool.h>
|
||||||
|
#include <stdint.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
|
||||||
12
tests/shared/mocks/MockRegEdit/CMakeLists.txt
Normal file
12
tests/shared/mocks/MockRegEdit/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
add_library(MockRegEdit STATIC
|
||||||
|
MockRegEdit.c
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(MockRegEdit PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
${CMAKE_SOURCE_DIR}/src/RegEdit/
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(MockRegEdit
|
||||||
|
${CPPUTEST_LIBRARIES}
|
||||||
|
)
|
||||||
217
tests/shared/mocks/MockRegEdit/MockRegEdit.c
Normal file
217
tests/shared/mocks/MockRegEdit/MockRegEdit.c
Normal file
|
|
@ -0,0 +1,217 @@
|
||||||
|
/*
|
||||||
|
* Author: username
|
||||||
|
* Date: 2024
|
||||||
|
* filename: MockRegEdit.c
|
||||||
|
* description: module_purpose
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "MockRegEdit.h"
|
||||||
|
#include "CppUTestExt/MockSupport_c.h"
|
||||||
|
|
||||||
|
// For 64-Bit systems and register access.
|
||||||
|
|
||||||
|
void RegEdit_u64_SetRegister(void *reg)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u64_SetRegister")->withPointerParameters("reg", reg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u64_ClearRegister(void *reg)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u64_ClearRegister")->withPointerParameters("reg", reg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u64_SetBit(void *reg, uint8_t bit_num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u64_SetBit")->withPointerParameters("reg", reg)->withUnsignedIntParameters("bit_num", bit_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u64_ClearBit(void *reg, uint8_t bit_num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u64_ClearBit")->withPointerParameters("reg", reg)->withUnsignedIntParameters("bit_num", bit_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RegEdit_u64_IsBitSet(void *reg, uint8_t bit_num)
|
||||||
|
{
|
||||||
|
return mock_c()->actualCall("RegEdit_u64_IsBitSet")->withPointerParameters("reg", reg)->withUnsignedIntParameters("bit_num", bit_num)->returnBoolValueOrDefault(true);
|
||||||
|
// return mock_c()->returnBoolValueOrDefault(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u64_OR_Num(void *reg, uint64_t num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u64_OR_Num")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u64_AND_Num(void *reg, uint64_t num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u64_AND_Num")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u64_SetNum(void *reg, uint64_t num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u64_SetNum")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t RegEdit_u64_ReadReg(void *reg)
|
||||||
|
{
|
||||||
|
uint64_t value = *(uint64_t *)reg;
|
||||||
|
|
||||||
|
mock_c()->actualCall("RegEdit_u64_ReadReg")->withPointerParameters("reg", reg)->returnUnsignedIntValueOrDefault(value);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For 32-Bit systems and register access.
|
||||||
|
|
||||||
|
void RegEdit_u32_SetRegister(void *reg)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u32_SetRegister")->withPointerParameters("reg", reg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u32_ClearRegister(void *reg)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u32_ClearRegister")->withPointerParameters("reg", reg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u32_SetBit(void *reg, uint8_t bit_num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u32_SetBit")->withPointerParameters("reg", reg)->withUnsignedIntParameters("bit_num", bit_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u32_ClearBit(void *reg, uint8_t bit_num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u32_ClearBit")->withPointerParameters("reg", reg)->withUnsignedIntParameters("bit_num", bit_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RegEdit_u32_IsBitSet(void *reg, uint8_t bit_num)
|
||||||
|
{
|
||||||
|
return mock_c()->actualCall("RegEdit_u32_IsBitSet")->withPointerParameters("reg", reg)->withUnsignedIntParameters("bit_num", bit_num)->returnBoolValueOrDefault(true);
|
||||||
|
// return mock_c()->returnBoolValueOrDefault(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u32_OR_Num(void *reg, uint32_t num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u32_OR_Num")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u32_AND_Num(void *reg, uint32_t num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u32_AND_Num")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u32_SetNum(void *reg, uint32_t num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u32_SetNum")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t RegEdit_u32_ReadReg(void *reg)
|
||||||
|
{
|
||||||
|
uint32_t value = *(uint32_t *)reg;
|
||||||
|
|
||||||
|
mock_c()->actualCall("RegEdit_u32_ReadReg")->withPointerParameters("reg", reg)->returnUnsignedIntValueOrDefault(value);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For 16-Bit systems and register access.
|
||||||
|
|
||||||
|
void RegEdit_u16_SetRegister(void *reg)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u16_SetRegister")->withPointerParameters("reg", reg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u16_ClearRegister(void *reg)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u16_ClearRegister")->withPointerParameters("reg", reg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u16_SetBit(void *reg, uint8_t bit_num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u16_SetBit")->withPointerParameters("reg", reg)->withUnsignedIntParameters("bit_num", bit_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u16_ClearBit(void *reg, uint8_t bit_num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u16_ClearBit")->withPointerParameters("reg", reg)->withUnsignedIntParameters("bit_num", bit_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RegEdit_u16_IsBitSet(void *reg, uint8_t bit_num)
|
||||||
|
{
|
||||||
|
return mock_c()->actualCall("RegEdit_u16_IsBitSet")->withPointerParameters("reg", reg)->withUnsignedIntParameters("bit_num", bit_num)->returnBoolValueOrDefault(true);
|
||||||
|
// return mock_c()->returnBoolValueOrDefault(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u16_OR_Num(void *reg, uint16_t num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u16_OR_Num")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u16_AND_Num(void *reg, uint16_t num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u16_AND_Num")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u16_SetNum(void *reg, uint16_t num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u16_SetNum")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t RegEdit_u16_ReadReg(void *reg)
|
||||||
|
{
|
||||||
|
uint16_t value = *(uint16_t *)reg;
|
||||||
|
|
||||||
|
mock_c()->actualCall("RegEdit_u16_ReadReg")->withPointerParameters("reg", reg)->returnUnsignedIntValueOrDefault(value);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For 8-Bit systems and register access.
|
||||||
|
|
||||||
|
void RegEdit_u8_SetRegister(void *reg)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u8_SetRegister")->withPointerParameters("reg", reg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u8_ClearRegister(void *reg)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u8_ClearRegister")->withPointerParameters("reg", reg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u8_SetBit(void *reg, uint8_t bit_num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u8_SetBit")->withPointerParameters("reg", reg)->withUnsignedIntParameters("bit_num", bit_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u8_ClearBit(void *reg, uint8_t bit_num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u8_ClearBit")->withPointerParameters("reg", reg)->withUnsignedIntParameters("bit_num", bit_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RegEdit_u8_IsBitSet(void *reg, uint8_t bit_num)
|
||||||
|
{
|
||||||
|
return mock_c()->actualCall("RegEdit_u8_IsBitSet")->withPointerParameters("reg", reg)->withUnsignedIntParameters("bit_num", bit_num)->returnBoolValueOrDefault(true);
|
||||||
|
// return mock_c()->returnBoolValueOrDefault(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u8_OR_Num(void *reg, uint8_t num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u8_OR_Num")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u8_AND_Num(void *reg, uint8_t num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u8_AND_Num")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegEdit_u8_SetNum(void *reg, uint8_t num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_u8_SetNum")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t RegEdit_u8_ReadReg(void *reg)
|
||||||
|
{
|
||||||
|
uint8_t value = *(uint8_t *)reg;
|
||||||
|
|
||||||
|
mock_c()->actualCall("RegEdit_u8_ReadReg")->withPointerParameters("reg", reg)->returnUnsignedIntValueOrDefault(value);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
19
tests/shared/mocks/MockRegEdit/MockRegEdit.h
Normal file
19
tests/shared/mocks/MockRegEdit/MockRegEdit.h
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/**
|
||||||
|
* @brief Mock of the RegEdit module.
|
||||||
|
* @details This file is just re-exports the RegEdit functions plus extras.
|
||||||
|
* @author Jake G
|
||||||
|
* @date 2025-12-21
|
||||||
|
* @copyright None
|
||||||
|
* @file MockRegEdit.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MOCKREGEDIT_H
|
||||||
|
#define MOCKREGEDIT_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "RegEdit.h"
|
||||||
|
|
||||||
|
#endif // MOCKREGEDIT_H
|
||||||
55
tests/shared/mocks/MockRegEdit/u8_comparator.cpp
Normal file
55
tests/shared/mocks/MockRegEdit/u8_comparator.cpp
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
#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}
|
||||||
|
)
|
||||||
30
tests/shared/mocks/TimerMock/TimerMock.c
Normal file
30
tests/shared/mocks/TimerMock/TimerMock.c
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Author: Jake G
|
||||||
|
* Date: 2024-09-02
|
||||||
|
* filename: TimerMock.c
|
||||||
|
* description: mocks timers
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "TimerMock.h"
|
||||||
|
#include "CppUTestExt/MockSupport_c.h"
|
||||||
|
#include <stdbool.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);
|
||||||
|
}
|
||||||
25
tests/shared/mocks/TimerMock/TimerMock.h
Normal file
25
tests/shared/mocks/TimerMock/TimerMock.h
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
/**
|
||||||
|
* @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
|
target_link_libraries(simple_test
|
||||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
${CPPUTEST_LIBRARIES}
|
||||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue