Compare commits
No commits in common. "d315aa778051492cbb8232610f92d1ecac1cada1" and "a7f51ff472c125bab07febaf1c8ac7928de68051" have entirely different histories.
d315aa7780
...
a7f51ff472
37 changed files with 84 additions and 839 deletions
24
.gitignore
vendored
24
.gitignore
vendored
|
|
@ -1,12 +1,12 @@
|
||||||
.cache/
|
build/CMakeFiles
|
||||||
*.core
|
build/Testing/Temporary
|
||||||
tags
|
build/cpputest
|
||||||
|
build/src
|
||||||
# Keep the build directory itself.
|
build/tests
|
||||||
build/*
|
build/CMakeCache.txt
|
||||||
|
build/CTestTestfile.cmake
|
||||||
# Generated Documentation shouldn't be included.
|
build/Makefile
|
||||||
docs/generated_docs/latex
|
build/cmake_install.cmake
|
||||||
docs/generated_docs/html
|
build/compile_commands.json
|
||||||
|
.cache/clangd/index
|
||||||
|
build/.cache/clangd/index
|
||||||
|
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
# 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}
|
|
||||||
)
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
#include "module_name.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
/**
|
|
||||||
* @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,42 +1,7 @@
|
||||||
# File: src/module_name/CMakeLists.txt
|
|
||||||
add_library(module_name STATIC
|
add_library(module_name STATIC
|
||||||
module_name.c
|
module_name.c
|
||||||
)
|
)
|
||||||
|
|
||||||
# Current list dir: The directory where the cmake config file is.
|
target_include_directories(module_name PUBLIC
|
||||||
# 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_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,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#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)
|
||||||
|
|
|
||||||
16
.template_files/modules/module_name.cpp
Normal file
16
.template_files/modules/module_name.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* 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,31 +1,14 @@
|
||||||
/**
|
/*
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#pragma once
|
#ifndef module_name
|
||||||
#ifndef module_name_H
|
#define module_name
|
||||||
#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(FirstTestGroup)
|
TEST_GROUP(test_module_name)
|
||||||
{
|
{
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
@ -24,12 +24,12 @@ TEST_GROUP(FirstTestGroup)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST(FirstTestGroup, FirstTest)
|
TEST(test_module_name, FirstTest)
|
||||||
{
|
{
|
||||||
FAIL("Fail me!");
|
FAIL("Fail me!");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FirstTestGroup, SecondTest)
|
TEST(test_module_name, SecondTest)
|
||||||
{
|
{
|
||||||
STRCMP_EQUAL("hello", "world");
|
STRCMP_EQUAL("hello", "world");
|
||||||
LONGS_EQUAL(1, 2);
|
LONGS_EQUAL(1, 2);
|
||||||
|
|
|
||||||
|
|
@ -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(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 0.1.0
|
VERSION 1.0
|
||||||
DESCRIPTION "template for cmake + cpputest"
|
DESCRIPTION "template for cmake + cpputest"
|
||||||
LANGUAGES C CXX
|
LANGUAGES C CXX
|
||||||
)
|
)
|
||||||
|
|
@ -53,14 +53,14 @@ if (UNIT_TESTING)
|
||||||
message(STATUS "Found CppUTest version ${CPPUTEST_VERSION}")
|
message(STATUS "Found CppUTest version ${CPPUTEST_VERSION}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Diagnostic Messages for Multi-Platform testing.
|
include_directories(
|
||||||
message(STATUS "CPPUTEST_LIBRARY_DIRS: ${CPPUTEST_LIBRARY_DIRS}")
|
${CPPUTEST_INCLUDE_DIRS}
|
||||||
message(STATUS "CPPUTEST_INCLUDE_DIRS: ${CPPUTEST_INCLUDE_DIRS}" )
|
./inc
|
||||||
message(STATUS "CPPUTEST_LIBRARIES: ${CPPUTEST_LIBRARIES}" )
|
./mocks
|
||||||
|
)
|
||||||
include_directories(${CPPUTEST_INCLUDE_DIRS})
|
link_directories(${CPPUTEST_LIBRARIES})
|
||||||
link_directories(${CPPUTEST_LIBRARY_DIRS})
|
|
||||||
|
|
||||||
|
add_subdirectory(mocks)
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
1
compile_commands.json
Symbolic link
1
compile_commands.json
Symbolic link
|
|
@ -0,0 +1 @@
|
||||||
|
./build/compile_commands.json
|
||||||
|
|
@ -1,70 +1,37 @@
|
||||||
#!/usr/bin/env bash
|
#!/bin/sh
|
||||||
|
|
||||||
# Author: Jake Goodwin
|
# Author: Jake Goodwin
|
||||||
# Date: 2026
|
# Date: 2024
|
||||||
# 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"
|
|
||||||
|
|
||||||
PROJECT_NAME="template"
|
IS_FREEBSD=0
|
||||||
|
is_freebsd () {
|
||||||
run_uc_tags() {
|
UNAME="$(uname)"
|
||||||
uctags --recurse=yes \
|
if [ $UNAME == "FreeBSD" ]; then
|
||||||
--languages=C,C++,Asm \
|
IS_FREEBSD=1
|
||||||
--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
|
||||||
echo "Skipping tags generation."
|
IS_FREEBSD=0
|
||||||
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 ./tests/shared -name '*.c')
|
source_c_files=$(find ./src -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 ./tests -name '*.h')
|
source_h_files=$(find ./src -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!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,10 +50,6 @@ 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"
|
||||||
|
|
@ -98,27 +61,15 @@ 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 () {
|
||||||
|
|
@ -127,7 +78,6 @@ 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 () {
|
||||||
|
|
@ -174,9 +124,6 @@ git_remove_module () {
|
||||||
git rm -r ./tests/CMakeLists.txt
|
git rm -r ./tests/CMakeLists.txt
|
||||||
}
|
}
|
||||||
|
|
||||||
add_mock_module() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
add_new_module () {
|
add_new_module () {
|
||||||
|
|
||||||
|
|
@ -190,7 +137,13 @@ add_new_module () {
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
is_freebsd
|
||||||
|
if [ IS_FREEBSD -eq 0]; then
|
||||||
modname_cap=$(echo $modname | sed 's/[a-z]/\U&/g')
|
modname_cap=$(echo $modname | sed 's/[a-z]/\U&/g')
|
||||||
|
else
|
||||||
|
modname_cap=$( echo $modname | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/')
|
||||||
|
fi
|
||||||
|
|
||||||
modsrc_dir="./src/${modname}"
|
modsrc_dir="./src/${modname}"
|
||||||
modtest_dir="./tests/${modname}"
|
modtest_dir="./tests/${modname}"
|
||||||
|
|
||||||
|
|
@ -229,16 +182,16 @@ add_new_module () {
|
||||||
|
|
||||||
add_c_mdoule () {
|
add_c_mdoule () {
|
||||||
|
|
||||||
sed -e "s/module_name/${modname}/" $MODULE_DIR/module_name.c > $modsrc_dir/${modname}.c
|
sed "s/module_name/${modname}/" $MODULE_DIR/module_name.c > $modsrc_dir/${modname}.c
|
||||||
sed -i'' -e "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.c
|
sed -i'' "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.c
|
||||||
|
|
||||||
sed -e "s/module_name/${modname_cap}/" $MODULE_DIR/module_name.h > $modsrc_dir/${modname}.h
|
sed "s/module_name/${modname_cap}/" $MODULE_DIR/module_name.h > $modsrc_dir/${modname}.h
|
||||||
sed -i'' -e "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.h
|
sed -i'' "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.h
|
||||||
|
|
||||||
sed -e "s/module_name/${modname}/" $MODULE_DIR/CMakeLists.txt > $modsrc_dir/CMakeLists.txt
|
sed "s/module_name/${modname}/" $MODULE_DIR/CMakeLists.txt > $modsrc_dir/CMakeLists.txt
|
||||||
|
|
||||||
sed -e "s/module_name/${modname}/" $MODULE_DIR/test_module_name.cpp > $modtest_dir/test_${modname}.cpp
|
sed "s/module_name/${modname}/" $MODULE_DIR/test_module_name.cpp > $modtest_dir/test_${modname}.cpp
|
||||||
sed -e "s/module_name/${modname}/" $MODULE_DIR/TestCMakeLists.txt > $modtest_dir/CMakeLists.txt
|
sed "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}"
|
||||||
|
|
@ -269,10 +222,6 @@ add_cpp_module () {
|
||||||
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}"
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
del_module () {
|
del_module () {
|
||||||
|
|
@ -301,35 +250,14 @@ 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"
|
||||||
|
|
@ -349,11 +277,6 @@ 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,8 +1,6 @@
|
||||||
project(Tests)
|
project(Tests)
|
||||||
|
|
||||||
# TEST_DIRS
|
# TEST_DIRS
|
||||||
|
|
||||||
add_subdirectory(shared)
|
|
||||||
add_subdirectory(simple_test)
|
add_subdirectory(simple_test)
|
||||||
|
|
||||||
# TEST_RUNNER
|
# TEST_RUNNER
|
||||||
|
|
@ -11,7 +9,8 @@ add_executable(AllTests
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(AllTests
|
target_link_libraries(AllTests
|
||||||
${CPPUTEST_LIBRARIES}
|
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||||
|
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||||
# TEST_LINKS
|
# TEST_LINKS
|
||||||
simple_test
|
simple_test
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
#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
|
|
||||||
|
|
@ -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,79 +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,29 +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 <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
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
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}
|
|
||||||
)
|
|
||||||
|
|
@ -1,217 +0,0 @@
|
||||||
/*
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
/**
|
|
||||||
* @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
|
|
||||||
|
|
@ -1,55 +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,30 +0,0 @@
|
||||||
/*
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,25 +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
|
target_link_libraries(simple_test
|
||||||
${CPPUTEST_LIBRARIES}
|
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||||
|
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue