From 138e03282f418234570fc05e9cc97484b8c87044 Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Fri, 24 Oct 2025 10:51:01 -0400 Subject: [PATCH 1/9] Moved microstrain test to external repo and set to install (when install logic implemented in repo) --- test/CMakeLists.txt | 11 +- test/microstrain_test/CMakeLists.txt | 105 --- test/microstrain_test/microstrain_test.hpp | 191 ---- .../microstrain_test/doctest_wrappers.hpp | 66 -- .../microstrain_test/microstrain_test.h | 80 -- .../microstrain_test/microstrain_test.hpp | 24 - .../microstrain_test/unity_wrappers.h | 822 ------------------ .../scripts/DiscoverTests.cmake | 110 --- .../scripts/internal/InstallDoctest.cmake | 10 - .../scripts/internal/InstallUnity.cmake | 20 - .../scripts/internal/Internals.cmake | 185 ---- .../internal/test_runner_template.c.in | 27 - 12 files changed, 9 insertions(+), 1642 deletions(-) delete mode 100644 test/microstrain_test/CMakeLists.txt delete mode 100644 test/microstrain_test/microstrain_test.hpp delete mode 100644 test/microstrain_test/microstrain_test/doctest_wrappers.hpp delete mode 100644 test/microstrain_test/microstrain_test/microstrain_test.h delete mode 100644 test/microstrain_test/microstrain_test/microstrain_test.hpp delete mode 100644 test/microstrain_test/microstrain_test/unity_wrappers.h delete mode 100644 test/microstrain_test/scripts/DiscoverTests.cmake delete mode 100644 test/microstrain_test/scripts/internal/InstallDoctest.cmake delete mode 100644 test/microstrain_test/scripts/internal/InstallUnity.cmake delete mode 100644 test/microstrain_test/scripts/internal/Internals.cmake delete mode 100644 test/microstrain_test/scripts/internal/test_runner_template.c.in diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cdfeabf03..13f778393 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,10 +2,17 @@ # Dependencies # --------------------------------------------------------------- +include(FetchContent) + set(MICROSTRAIN_TEST_USE_UNITY ON CACHE BOOL "" FORCE) set(MICROSTRAIN_TEST_USE_DOCTEST ON CACHE BOOL "" FORCE) -# TODO: Will be moved to separate repo -add_subdirectory("microstrain_test") + +FetchContent_Declare(microstrain_test + GIT_REPOSITORY https://github.com/LORD-MicroStrain/microstrain_test.git + GIT_TAG v0.1.0 +) + +FetchContent_MakeAvailable(microstrain_test) # --------------------------------------------------------------- # Target templates diff --git a/test/microstrain_test/CMakeLists.txt b/test/microstrain_test/CMakeLists.txt deleted file mode 100644 index 472b57aaa..000000000 --- a/test/microstrain_test/CMakeLists.txt +++ /dev/null @@ -1,105 +0,0 @@ -# --------------------------------------------------------------- -# Project setup -# --------------------------------------------------------------- - -cmake_minimum_required(VERSION 3.19) -project(microstrain_test) - -# --------------------------------------------------------------- -# Framework backends -# --------------------------------------------------------------- - -# C -option(MICROSTRAIN_TEST_USE_UNITY "Use unity as the backend framework for C" OFF) - -# C++ -option(MICROSTRAIN_TEST_USE_DOCTEST "Use doctest as the backend framework for C++" OFF) - -# --------------------------------------------------------------- -# Library setup -# --------------------------------------------------------------- - -add_library(microstrain_test_c INTERFACE) -add_library(microstrain_test_cpp INTERFACE) - -set_target_properties(microstrain_test_c PROPERTIES - LINKER_LANGUAGE C -) -set_target_properties(microstrain_test_cpp PROPERTIES - LINKER_LANGUAGE CXX -) - -target_include_directories(microstrain_test_c INTERFACE - "${CMAKE_CURRENT_LIST_DIR}" -) -target_include_directories(microstrain_test_cpp INTERFACE - "${CMAKE_CURRENT_LIST_DIR}" -) - -target_sources(microstrain_test_c INTERFACE - "microstrain_test/microstrain_test.h" -) -target_sources(microstrain_test_cpp INTERFACE - "microstrain_test/microstrain_test.hpp" -) - -# Add namespace aliases -add_library(microstrain_test::c ALIAS microstrain_test_c) -add_library(microstrain_test::cpp ALIAS microstrain_test_cpp) - -# --------------------------------------------------------------- -# Library compile settings -# --------------------------------------------------------------- - -if(MSVC) - set(COMPILE_OPTIONS - "/W4" # Enable warnings - "/WX" # Warnings as errors - "/MP" # Multi-process compilation - ) -else() - set(COMPILE_OPTIONS - "-Wall" # Enable warnings - "-Wextra" # Enable extra warnings - "-Werror" # Warnings as errors - ) -endif() - -target_compile_options(microstrain_test_c INTERFACE - "${COMPILE_OPTIONS}" -) -target_compile_options(microstrain_test_cpp INTERFACE - "${COMPILE_OPTIONS}" -) - -# --------------------------------------------------------------- -# (C) Unity setup -# --------------------------------------------------------------- - -if(MICROSTRAIN_TEST_USE_UNITY) - include(scripts/internal/InstallUnity.cmake) - - target_compile_definitions(microstrain_test_c INTERFACE - "MICROSTRAIN_TEST_USE_UNITY" - ) - - target_link_libraries(microstrain_test_c INTERFACE - unity - ) -endif() - -# --------------------------------------------------------------- -# (C++) Doctest setup -# --------------------------------------------------------------- - -if(MICROSTRAIN_TEST_USE_DOCTEST) - include(scripts/internal/InstallDoctest.cmake) - - target_compile_definitions(microstrain_test_cpp INTERFACE - "MICROSTRAIN_TEST_USE_DOCTEST" - ) - - target_link_libraries(microstrain_test_cpp INTERFACE - doctest_with_main - ) -endif() diff --git a/test/microstrain_test/microstrain_test.hpp b/test/microstrain_test/microstrain_test.hpp deleted file mode 100644 index 0de7fafe8..000000000 --- a/test/microstrain_test/microstrain_test.hpp +++ /dev/null @@ -1,191 +0,0 @@ -/** - TODO: This should be moved to its own repository so it can be used by multiple projects - - TODO: Move documentation to markdown file(s) - - Wrapper library for C/C++ automated testing frameworks - - The goal is to provide a standardized interface for automated testing, regardless of the backend framework being - used. -*/ -#pragma once - -#ifdef MICROSTRAIN_TEST_USE_DOCTEST -#include "doctest/doctest_wrappers.hpp" -#endif - - -/** Test registration */ - -/// Registers a test in the given test suite. -/// -/// Tests are defined as: TEST(suite_name, test_name) -/// -/// Test suites are useful for grouping related behaviors. The test suite will be created automatically if it doesn't -/// exist. -#ifndef TEST -#error "TEST is not implemented for the current backend" -#endif - - -/** Logging */ - -#ifndef LOG_ON_FAIL -#error "LOG_ON_FAIL is not implemented for the current backend." -#endif - - -/** Assertions - * - * There are three levels of failure: - * - WARN_* : Outputs a warning without failing the test. - * - FAIL_* : Fails the test but allows it to continue running. - * - FATAL_*: Fails and exits the test immediately. - * - * The arguments for each call follow the order (actual, expected). The order of arguments matters, as some assertions - * make assumptions on the size or bounds of the actual argument based on the expected argument. - * - * Ex: LEVEL_ASSERTION(actual, expected) -*/ - -/// -------------------------------------------------------------------------------------------- /// -/// The following are useful if you only care about whether a condition is true. -/// -/// They might not display any values used in the expression for debugging. -/// -------------------------------------------------------------------------------------------- /// - -#ifndef WARN_IF_NOT_TRUE -#error "WARN_IF_NOT_TRUE is not implemented for the current backend." -#endif - -#ifndef FAIL_IF_NOT_TRUE -#error "FAIL_IF_NOT_TRUE is not implemented for the current backend." -#endif - -#ifndef FATAL_IF_NOT_TRUE -#error "FATAL_IF_NOT_TRUE is not implemented for the current backend." -#endif - -/// -------------------------------------------------------------------------------------------- /// -/// More specific checks for equality that print the values when debugging. -/// -------------------------------------------------------------------------------------------- /// - -#ifndef WARN_IF_NOT_EQUAL -#error "WARN_IF_NOT_EQUAL is not implemented for the current backend." -#endif - -#ifndef FAIL_IF_NOT_EQUAL -#error "FAIL_IF_NOT_EQUAL is not implemented for the current backend." -#endif - -#ifndef FATAL_IF_NOT_EQUAL -#error "FATAL_IF_NOT_EQUAL is not implemented for the current backend." -#endif - -#ifndef WARN_IF_EQUAL -#error "WARN_IF_EQUAL is not implemented for the current backend." -#endif - -#ifndef FAIL_IF_EQUAL -#error "FAIL_IF_EQUAL is not implemented for the current backend." -#endif - -#ifndef FATAL_IF_EQUAL -#error "FATAL_IF_EQUAL is not implemented for the current backend." -#endif - -/// -------------------------------------------------------------------------------------------- /// -/// Same as the equality checks, but with additional safety and debugging info for C strings. -/// -------------------------------------------------------------------------------------------- /// - -#ifndef WARN_IF_C_STRINGS_NOT_EQUAL -#error "WARN_IF_C_STRINGS_NOT_EQUAL is not implemented for the current backend." -#endif - -#ifndef FAIL_IF_C_STRINGS_NOT_EQUAL -#error "FAIL_IF_C_STRINGS_NOT_EQUAL is not implemented for the current backend." -#endif - -#ifndef FATAL_IF_C_STRINGS_NOT_EQUAL -#error "FATAL_IF_C_STRINGS_NOT_EQUAL is not implemented for the current backend." -#endif - -/// -------------------------------------------------------------------------------------------- /// -/// For individual characters. -/// -------------------------------------------------------------------------------------------- /// - -#ifndef WARN_IF_CHAR_NOT_EQUAL -#error "WARN_IF_CHAR_NOT_EQUAL is not implemented for the current backend." -#endif - -#ifndef FAIL_IF_CHAR_NOT_EQUAL -#error "FAIL_IF_CHAR_NOT_EQUAL is not implemented for the current backend." -#endif - -#ifndef FATAL_IF_CHAR_NOT_EQUAL -#error "FATAL_IF_CHAR_NOT_EQUAL is not implemented for the current backend." -#endif - -/// -------------------------------------------------------------------------------------------- /// -/// These allow you to pass custom information to display if a test assertion fails. -/// -------------------------------------------------------------------------------------------- /// - -#ifndef WARN_AND_LOG_IF_NOT_TRUE -#error "WARN_AND_LOG_IF_NOT_TRUE is not implemented for the current backend." -#endif - -#ifndef FAIL_AND_LOG_IF_NOT_TRUE -#error "FAIL_AND_LOG_IF_NOT_TRUE is not implemented for the current backend." -#endif - -#ifndef FATAL_AND_LOG_IF_NOT_TRUE -#error "FATAL_AND_LOG_IF_NOT_TRUE is not implemented for the current backend." -#endif - -#ifndef WARN_AND_LOG_IF_NOT_EQUAL -#error "WARN_AND_LOG_IF_NOT_EQUAL is not implemented for the current backend." -#endif - -#ifndef FAIL_AND_LOG_IF_NOT_EQUAL -#error "FAIL_AND_LOG_IF_NOT_EQUAL is not implemented for the current backend." -#endif - -#ifndef FATAL_AND_LOG_IF_NOT_EQUAL -#error "FATAL_AND_LOG_IF_NOT_EQUAL is not implemented for the current backend." -#endif - -#ifndef WARN_AND_LOG_IF_EQUAL -#error "WARN_AND_LOG_IF_EQUAL is not implemented for the current backend." -#endif - -#ifndef FAIL_AND_LOG_IF_EQUAL -#error "FAIL_AND_LOG_IF_EQUAL is not implemented for the current backend." -#endif - -#ifndef FATAL_AND_LOG_IF_EQUAL -#error "FATAL_AND_LOG_IF_EQUAL is not implemented for the current backend." -#endif - -#ifndef WARN_AND_LOG_IF_C_STRINGS_NOT_EQUAL -#error "WARN_AND_LOG_IF_C_STRINGS_NOT_EQUAL is not implemented for the current backend." -#endif - -#ifndef FAIL_AND_LOG_IF_C_STRINGS_NOT_EQUAL -#error "FAIL_AND_LOG_IF_C_STRINGS_NOT_EQUAL is not implemented for the current backend." -#endif - -#ifndef FATAL_AND_LOG_IF_C_STRINGS_NOT_EQUAL -#error "FATAL_AND_LOG_IF_C_STRINGS_NOT_EQUAL is not implemented for the current backend." -#endif - -#ifndef WARN_AND_LOG_IF_CHAR_NOT_EQUAL -#error "WARN_AND_LOG_IF_CHAR_NOT_EQUAL is not implemented for the current backend." -#endif - -#ifndef FAIL_AND_LOG_IF_CHAR_NOT_EQUAL -#error "FAIL_AND_LOG_IF_CHAR_NOT_EQUAL is not implemented for the current backend." -#endif - -#ifndef FATAL_AND_LOG_IF_CHAR_NOT_EQUAL -#error "FATAL_AND_LOG_IF_CHAR_NOT_EQUAL is not implemented for the current backend." -#endif diff --git a/test/microstrain_test/microstrain_test/doctest_wrappers.hpp b/test/microstrain_test/microstrain_test/doctest_wrappers.hpp deleted file mode 100644 index 011933f6e..000000000 --- a/test/microstrain_test/microstrain_test/doctest_wrappers.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -#include - -#include - -// ----------------------------------------------------------------------------------------------------------- -// Automatic test registration and discovery -// ----------------------------------------------------------------------------------------------------------- - -#define MICROSTRAIN_TEST_CASE_IMPL(suite_name, test_name) \ - TEST_CASE("[" suite_name "] " test_name) - -// ----------------------------------------------------------------------------------------------------------- -// Assertions -// ----------------------------------------------------------------------------------------------------------- - -// TODO: Can add wrapper macros for the doctest parts of this and make it framework-independent -// ---> In this case, we could rename the file common.hpp or implementation.hpp -/// @brief Internal, DON'T USE DIRECTLY! -#define CSTR_EQ_IMPL(actual, expected, level) \ - do \ - { \ - INFO("Actual: " << std::string(actual)); \ - INFO("Expected: " << std::string(expected)); \ - \ - bool terminated = actual[strlen(expected)] == '\0'; \ - if (!terminated) \ - { \ - level##_MESSAGE(terminated, "The actual string is not terminated when the expected string is."); \ - break; \ - } \ - \ - level##_EQ(strcmp(actual, expected), 0); \ - } while(0) - -/// @brief Displays a warning, but does not fail the test when the given C strings are not equal. -/// -/// This assertion is pseudo-safe if the expected string is passed as the second argument. -/// It will fail early if the actual string isn't null terminated at the same position as -/// the expected string. -/// -/// It is reasonable to assume that the expected string is null terminated, since it is -/// almost always hard-coded by a test. -#define WARN_CSTR_EQ(actual, expected) CSTR_EQ_IMPL(actual, expected, WARN) - -/// @brief Fails the test when the given C strings are not equal, but allows the test to keep running. -/// -/// This assertion is pseudo-safe if the expected string is passed as the second argument. -/// It will fail early if the actual string isn't null terminated at the same position as -/// the expected string. -/// -/// It is reasonable to assume that the expected string is null terminated, since it is -/// almost always hard-coded by a test. -#define CHECK_CSTR_EQ(actual, expected) CSTR_EQ_IMPL(actual, expected, CHECK) - -/// @brief Fails and exits the test immediately when the given C strings are not equal. -/// -/// This assertion is pseudo-safe if the expected string is passed as the second argument. -/// It will fail early if the actual string isn't null terminated at the same position as -/// the expected string. -/// -/// It is reasonable to assume that the expected string is null terminated, since it is -/// almost always hard-coded by a test. -#define REQUIRE_CSTR_EQ(actual, expected) CSTR_EQ_IMPL(actual, expected, REQUIRE) - diff --git a/test/microstrain_test/microstrain_test/microstrain_test.h b/test/microstrain_test/microstrain_test/microstrain_test.h deleted file mode 100644 index ef2fe9c3e..000000000 --- a/test/microstrain_test/microstrain_test/microstrain_test.h +++ /dev/null @@ -1,80 +0,0 @@ -/** - C framework API -*/ -#pragma once - -#ifdef MICROSTRAIN_TEST_USE_UNITY - #include "unity_wrappers.h" -#endif - -// ----------------------------------------------------------------------------------------------------------- -// Automatic test registration and discovery -// ----------------------------------------------------------------------------------------------------------- - -/// @brief Registers a test case in the given test suite. -/// -/// All tests in a test suite can be run together by passing the suite name as -/// a label to CTest. This currently only works with automatic test discovery, -/// or if you set the label for a CTest to the suite name manually. -/// -/// @param suite_name Currently needs to be a valid function identifier. -/// @param test_name Currently needs to be a valid function identifier. -/// -#define MICROSTRAIN_TEST_CASE(suite_name, test_name) \ - MICROSTRAIN_TEST_CASE_IMPL(suite_name, test_name) - -// ----------------------------------------------------------------------------------------------------------- -// Manual test registration and discovery -// ----------------------------------------------------------------------------------------------------------- - -/// @brief Completes any required setup before tests can be run. -/// -/// DON'T use this directly if using automatic test discovery. This should be called -/// near the top of the main file, before the main function definition. -/// -#define MICROSTRAIN_TEST_DEFAULT_SETUP() \ - MICROSTRAIN_TEST_DEFAULT_SETUP_IMPL() - -/// @brief Begins the test registration process. -/// -/// DON'T use this directly if using automatic test discovery. If manually discovering -/// tests, register tests after this call in the main function. When done, call the -/// END macro. -/// -#define MICROSTRAIN_TEST_BEGIN() \ - MICROSTRAIN_TEST_BEGIN_IMPL() - -/// @brief Ends the test registration process. -/// -/// DON'T use this directly if using automatic test discovery. If manually discovering -/// tests, no tests will be registered after this call in the main function. The result -/// should be returned from the main function. -/// -#define MICROSTRAIN_TEST_END() \ - MICROSTRAIN_TEST_END_IMPL() - -/// @brief Runs a MicrostrainTest-defined test case. -/// -/// DON'T use this directly if using automatic test discovery. Call this in the main -/// function for each test to run. -/// -/// @param suite_name Currently needs to be a valid function identifier. -/// @param test_name Currently needs to be a valid function identifier. -/// -#define RUN_MICROSTRAIN_TEST_CASE(suite_name, test_name) \ - RUN_MICROSTRAIN_TEST_CASE_IMPL(suite_name, test_name) - -// ----------------------------------------------------------------------------------------------------------- -// Internals -// ----------------------------------------------------------------------------------------------------------- - -/// @brief DON'T use directly! -#define INTERNAL_RUN_MICROSTRAIN_TEST_CASE(suite_name, test_name, file_path) \ - INTERNAL_RUN_MICROSTRAIN_TEST_CASE_IMPL(suite_name, test_name, file_path) - -/// @brief DON'T use directly! -#define INTERNAL_MICROSTRAIN_TEST_CASE_FILTER(test_filter, suite_name, test_name, filepath) \ - if (!test_filter || strcmp(test_filter, "[" #suite_name "] " #test_name) == 0) \ - { \ - INTERNAL_RUN_MICROSTRAIN_TEST_CASE(suite_name, test_name, filepath); \ - } diff --git a/test/microstrain_test/microstrain_test/microstrain_test.hpp b/test/microstrain_test/microstrain_test/microstrain_test.hpp deleted file mode 100644 index 791c76724..000000000 --- a/test/microstrain_test/microstrain_test/microstrain_test.hpp +++ /dev/null @@ -1,24 +0,0 @@ -/** - C++ framework API -*/ -#pragma once - -#ifdef MICROSTRAIN_TEST_USE_DOCTEST - #include "doctest_wrappers.hpp" -#endif - -// ----------------------------------------------------------------------------------------------------------- -// Automatic test registration and discovery -// ----------------------------------------------------------------------------------------------------------- - -/// @brief Registers a test case in the given test suite. -/// -/// All tests in a test suite can be run together by passing the suite name as -/// a label to CTest. This currently only works with automatic test discovery, -/// or if you set the label for a CTest to the suite name manually. -/// -/// @param suite_name A string, which may contain any characters. -/// @param test_name A string, which may contain any characters. -/// -#define MICROSTRAIN_TEST_CASE(suite_name, test_name) \ - MICROSTRAIN_TEST_CASE_IMPL(suite_name, test_name) diff --git a/test/microstrain_test/microstrain_test/unity_wrappers.h b/test/microstrain_test/microstrain_test/unity_wrappers.h deleted file mode 100644 index 4cf924534..000000000 --- a/test/microstrain_test/microstrain_test/unity_wrappers.h +++ /dev/null @@ -1,822 +0,0 @@ -#pragma once - -#include - -// ----------------------------------------------------------------------------------------------------------- -// Automatic test registration and discovery -// ----------------------------------------------------------------------------------------------------------- - -#define MICROSTRAIN_TEST_CASE_IMPL(suite_name, test_name) \ - void suite_name##_##test_name(void) - -// ----------------------------------------------------------------------------------------------------------- -// Manual test registration and discovery -// ----------------------------------------------------------------------------------------------------------- - -#define MICROSTRAIN_TEST_DEFAULT_SETUP_IMPL() \ - void setUp(void) {} \ - void tearDown(void) {} \ - -#define MICROSTRAIN_TEST_BEGIN_IMPL() \ - UNITY_BEGIN() - -#define MICROSTRAIN_TEST_END_IMPL() \ - UNITY_END() - -#define RUN_MICROSTRAIN_TEST_CASE_IMPL(suite_name, test_name) \ - RUN_TEST(suite_name##_##test_name) - -// ----------------------------------------------------------------------------------------------------------- -// Internals -// ----------------------------------------------------------------------------------------------------------- - -// NOTE: Unfortunately have to reimplement and modify Unity's internals here instead -// of using RUN_TEST/UnityDefaultTestRun since there's no other way to update -// the file path without it being overridden. -// -// Make sure this is up to date when updating Unity. Luckily, it doesn't look -// like it changes often. -#define INTERNAL_RUN_MICROSTRAIN_TEST_CASE_IMPL(suite_name, test_name, file_path) \ - do \ - { \ - Unity.CurrentTestName = "["#suite_name"] "#test_name; \ - /* Gets the line of the calling test in the generated runner file. If the */ \ - /* test passes, this will be used for the link. If the test fails, the */ \ - /* line number will be updated by the failing assertion and used for the */ \ - /* link instead. */ \ - Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)__LINE__; \ - Unity.NumberOfTests++; \ - Unity.TestFile = file_path; \ - \ - UNITY_CLR_DETAILS(); \ - UNITY_EXEC_TIME_START(); \ - UNITY_LINE_TYPE previous_failures = Unity.TestFailures; \ - \ - if (TEST_PROTECT()) { \ - setUp(); \ - suite_name##_##test_name(); \ - } \ - if (TEST_PROTECT()) { \ - tearDown(); \ - } \ - \ - UNITY_EXEC_TIME_STOP(); \ - /* If the test passes, then the line number will be for the calling test */ \ - /* in the generated runner file. We want to set it as the file in this */ \ - /* case. */ \ - if (Unity.TestFailures == previous_failures) \ - { \ - Unity.TestFile = __FILE__; \ - } \ - UnityConcludeTest(); \ - } while(0) - - -/* - * Assertion wrappers - */ - -/* The following wrapper macros flip the argument order from (expected, actual) to (actual, expected). - * - * There is no added functionality to these macros. They are simply to maintain consistency with other - * frameworks. Assertion names remains the same, minus the "TEST_" part. - */ -// TODO: Add code generation script to do the assertion argument flipping automatically - -/* - * Conditional assertions - */ - -#define ASSERT_TRUE(condition) \ - TEST_ASSERT_TRUE(condition) - -#define ASSERT_FALSE(condition) \ - TEST_ASSERT_FALSE(condition) - -/* - * Integer assertions - */ - -#define ASSERT_EQUAL(actual, expected) \ - TEST_ASSERT_EQUAL_INT((expected), (actual)) - -#define ASSERT_EQUAL_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_INT_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_INT(actual, expected) \ - TEST_ASSERT_EQUAL_INT((expected), (actual)) - -#define ASSERT_EQUAL_INT_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_INT_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_INT8(actual, expected) \ - TEST_ASSERT_EQUAL_INT8((expected), (actual)) - -#define ASSERT_EQUAL_INT8_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_INT8_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_INT16(actual, expected) \ - TEST_ASSERT_EQUAL_INT16((expected), (actual)) - -#define ASSERT_EQUAL_INT16_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_INT16_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_INT32(actual, expected) \ - TEST_ASSERT_EQUAL_INT32((expected), (actual)) - -#define ASSERT_EQUAL_INT32_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_INT32_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_INT64(actual, expected) \ - TEST_ASSERT_EQUAL_INT64((expected), (actual)) - -#define ASSERT_EQUAL_INT64_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_INT64_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_UINT(actual, expected) \ - TEST_ASSERT_EQUAL_UINT((expected), (actual)) - -#define ASSERT_EQUAL_UINT_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_UINT_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_UINT8(actual, expected) \ - TEST_ASSERT_EQUAL_UINT8((expected), (actual)) - -#define ASSERT_EQUAL_UINT8_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_UINT8_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_UINT16(actual, expected) \ - TEST_ASSERT_EQUAL_UINT16((expected), (actual)) - -#define ASSERT_EQUAL_UINT16_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_UINT16_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_UINT32(actual, expected) \ - TEST_ASSERT_EQUAL_UINT32((expected), (actual)) - -#define ASSERT_EQUAL_UINT32_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_UINT32_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_UINT64(actual, expected) \ - TEST_ASSERT_EQUAL_UINT64((expected), (actual)) - -#define ASSERT_EQUAL_UINT64_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_UINT64_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_HEX(actual, expected) \ - TEST_ASSERT_EQUAL_HEX((expected), (actual)) - -#define ASSERT_EQUAL_HEX_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_HEX_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_HEX8(actual, expected) \ - TEST_ASSERT_EQUAL_HEX8((expected), (actual)) - -#define ASSERT_EQUAL_HEX8_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_HEX8_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_HEX16(actual, expected) \ - TEST_ASSERT_EQUAL_HEX16((expected), (actual)) - -#define ASSERT_EQUAL_HEX16_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_HEX16_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_HEX32(actual, expected) \ - TEST_ASSERT_EQUAL_HEX32((expected), (actual)) - -#define ASSERT_EQUAL_HEX32_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_HEX32_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_HEX64(actual, expected) \ - TEST_ASSERT_EQUAL_HEX64((expected), (actual)) - -#define ASSERT_EQUAL_HEX64_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_HEX64_MESSAGE((expected), (actual), (message)) - -/* - * Float/double assertions - */ - -#define ASSERT_EQUAL_FLOAT(actual, expected) \ - TEST_ASSERT_EQUAL_FLOAT((expected), (actual)) - -#define ASSERT_EQUAL_FLOAT_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_FLOAT_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_DOUBLE(actual, expected) \ - TEST_ASSERT_EQUAL_DOUBLE((expected), (actual)) - -#define ASSERT_EQUAL_DOUBLE_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_DOUBLE_MESSAGE((expected), (actual), (message)) - -#define ASSERT_FLOAT_WITHIN(actual, delta, expected) \ - TEST_ASSERT_FLOAT_WITHIN((delta), (expected), (actual)) - -#define ASSERT_FLOAT_WITHIN_MESSAGE(actual, delta, expected, message) \ - TEST_ASSERT_FLOAT_WITHIN_MESSAGE((delta), (expected), (actual), (message)) - -#define ASSERT_DOUBLE_WITHIN(actual, delta, expected) \ - TEST_ASSERT_DOUBLE_WITHIN((delta), (expected), (actual)) - -#define ASSERT_DOUBLE_WITHIN_MESSAGE(actual, delta, expected, message) \ - TEST_ASSERT_DOUBLE_WITHIN_MESSAGE((delta), (expected), (actual), (message)) - -/* - * String assertions - */ - -#define ASSERT_EQUAL_STRING(actual, expected) \ - TEST_ASSERT_EQUAL_STRING((expected), (actual)) - -#define ASSERT_EQUAL_STRING_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_STRING_MESSAGE((expected), (actual), (message)) - -#define ASSERT_EQUAL_STRING_LEN(actual, expected, len) \ - TEST_ASSERT_EQUAL_STRING_LEN((expected), (actual), (len)) - -#define ASSERT_EQUAL_STRING_LEN_MESSAGE(actual, expected, len, message) \ - TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE((expected), (actual), (len), (message)) - -/* - * Memory assertions - */ - -#define ASSERT_EQUAL_MEMORY(actual, expected, len) \ - TEST_ASSERT_EQUAL_MEMORY((expected), (actual), (len)) - -#define ASSERT_EQUAL_MEMORY_MESSAGE(actual, expected, len, message) \ - TEST_ASSERT_EQUAL_MEMORY_MESSAGE((expected), (actual), (len), (message)) - -/* - * Pointer assertions - */ - -#define ASSERT_EQUAL_PTR(actual, expected) \ - TEST_ASSERT_EQUAL_PTR((expected), (actual)) - -#define ASSERT_EQUAL_PTR_MESSAGE(actual, expected, message) \ - TEST_ASSERT_EQUAL_PTR_MESSAGE((expected), (actual), (message)) - -/* - * Int array assertions - */ - -#define ASSERT_EQUAL_INT_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_INT_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_INT_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -#define ASSERT_EQUAL_INT8_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_INT8_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_INT8_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_INT8_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -#define ASSERT_EQUAL_INT16_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_INT16_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_INT16_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_INT16_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -#define ASSERT_EQUAL_INT32_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_INT32_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_INT32_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_INT32_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -#define ASSERT_EQUAL_INT64_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_INT64_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_INT64_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_INT64_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -/* - * Unsigned int array assertions - */ - -#define ASSERT_EQUAL_UINT_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_UINT_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_UINT_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -#define ASSERT_EQUAL_UINT8_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_UINT8_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -#define ASSERT_EQUAL_UINT16_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_UINT16_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_UINT16_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_UINT16_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -#define ASSERT_EQUAL_UINT32_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_UINT32_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_UINT32_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_UINT32_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -#define ASSERT_EQUAL_UINT64_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_UINT64_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_UINT64_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_UINT64_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -/* - * Hex array assertions - */ - -#define ASSERT_EQUAL_HEX_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_HEX_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_HEX_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_HEX_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -#define ASSERT_EQUAL_HEX8_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_HEX8_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -#define ASSERT_EQUAL_HEX16_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_HEX16_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_HEX16_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_HEX16_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -#define ASSERT_EQUAL_HEX32_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_HEX32_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -#define ASSERT_EQUAL_HEX64_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_HEX64_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_HEX64_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_HEX64_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -/* - * Float array assertions - */ - -#define ASSERT_EQUAL_FLOAT_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_FLOAT_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -/* - * Double array assertions - */ - -#define ASSERT_EQUAL_DOUBLE_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_DOUBLE_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_DOUBLE_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_DOUBLE_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -/* - * Pointer array assertions - */ - -#define ASSERT_EQUAL_PTR_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_PTR_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_PTR_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_PTR_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -/* CHAR array assertions (if Unity supports them) */ -#define ASSERT_EQUAL_CHAR_ARRAY(actual, expected, num_elements) \ - TEST_ASSERT_EQUAL_CHAR_ARRAY((expected), (actual), (num_elements)) - -#define ASSERT_EQUAL_CHAR_ARRAY_MESSAGE(actual, expected, num_elements, message) \ - TEST_ASSERT_EQUAL_CHAR_ARRAY_MESSAGE((expected), (actual), (num_elements), (message)) - -/* - * Generic comparison assertions - */ - -#define ASSERT_GREATER_THAN(actual, threshold) \ - TEST_ASSERT_GREATER_THAN((threshold), (actual)) - -#define ASSERT_GREATER_THAN_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN(actual, threshold) \ - TEST_ASSERT_LESS_THAN((threshold), (actual)) - -#define ASSERT_LESS_THAN_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_MESSAGE((threshold), (actual), (message)) - -/* - * Int comparison assertions - */ - -#define ASSERT_GREATER_THAN_INT(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_INT((threshold), (actual)) - -#define ASSERT_GREATER_THAN_INT_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_INT_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_INT(actual, threshold) \ - TEST_ASSERT_LESS_THAN_INT((threshold), (actual)) - -#define ASSERT_LESS_THAN_INT_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_INT_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_INT(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_INT((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_INT_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_INT_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_INT(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL_INT((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_INT_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_INT_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_THAN_INT8(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_INT8((threshold), (actual)) - -#define ASSERT_GREATER_THAN_INT8_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_INT8_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_INT8(actual, threshold) \ - TEST_ASSERT_LESS_THAN_INT8((threshold), (actual)) - -#define ASSERT_LESS_THAN_INT8_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_INT8_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_INT8(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_INT8((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_INT8_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_INT8_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_INT8(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL_INT8((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_INT8_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_INT8_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_THAN_INT16(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_INT16((threshold), (actual)) - -#define ASSERT_GREATER_THAN_INT16_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_INT16_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_INT16(actual, threshold) \ - TEST_ASSERT_LESS_THAN_INT16((threshold), (actual)) - -#define ASSERT_LESS_THAN_INT16_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_INT16_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_INT16(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_INT16((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_INT16_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_INT16_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_INT16(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL_INT16((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_INT16_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_INT16_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_THAN_INT32(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_INT32((threshold), (actual)) - -#define ASSERT_GREATER_THAN_INT32_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_INT32_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_INT32(actual, threshold) \ - TEST_ASSERT_LESS_THAN_INT32((threshold), (actual)) - -#define ASSERT_LESS_THAN_INT32_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_INT32_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_INT32(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_INT32((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_INT32_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_INT32_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_INT32(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL_INT32((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_INT32_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_INT32_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_THAN_INT64(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_INT64((threshold), (actual)) - -#define ASSERT_GREATER_THAN_INT64_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_INT64_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_INT64(actual, threshold) \ - TEST_ASSERT_LESS_THAN_INT64((threshold), (actual)) - -#define ASSERT_LESS_THAN_INT64_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_INT64_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_INT64(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_INT64((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_INT64_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_INT64_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_INT64(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL_INT64((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_INT64_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_INT64_MESSAGE((threshold), (actual), (message)) - -/* - * Unsigned int comparison assertions - */ - -#define ASSERT_GREATER_THAN_UINT(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_UINT((threshold), (actual)) - -#define ASSERT_GREATER_THAN_UINT_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_UINT_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_UINT(actual, threshold) \ - TEST_ASSERT_LESS_THAN_UINT((threshold), (actual)) - -#define ASSERT_LESS_THAN_UINT_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_UINT_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_UINT(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_UINT((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_UINT_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_UINT_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_UINT(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL_UINT((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_UINT_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_UINT_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_THAN_UINT8(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_UINT8((threshold), (actual)) - -#define ASSERT_GREATER_THAN_UINT8_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_UINT8_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_UINT8(actual, threshold) \ - TEST_ASSERT_LESS_THAN_UINT8((threshold), (actual)) - -#define ASSERT_LESS_THAN_UINT8_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_UINT8_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_UINT8(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_UINT8((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_UINT8_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_UINT8_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_UINT8(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL_UINT8((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_UINT8_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_UINT8_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_THAN_UINT16(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_UINT16((threshold), (actual)) - -#define ASSERT_GREATER_THAN_UINT16_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_UINT16_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_UINT16(actual, threshold) \ - TEST_ASSERT_LESS_THAN_UINT16((threshold), (actual)) - -#define ASSERT_LESS_THAN_UINT16_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_UINT16_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_UINT16(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_UINT16((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_UINT16_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_UINT16_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_UINT16(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL_UINT16((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_UINT16_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_UINT16_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_THAN_UINT32(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_UINT32((threshold), (actual)) - -#define ASSERT_GREATER_THAN_UINT32_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_UINT32_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_UINT32(actual, threshold) \ - TEST_ASSERT_LESS_THAN_UINT32((threshold), (actual)) - -#define ASSERT_LESS_THAN_UINT32_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_UINT32_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_UINT32(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_UINT32((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_UINT32_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_UINT32_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_UINT32(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL_UINT32((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_UINT32_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_UINT32_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_THAN_UINT64(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_UINT64((threshold), (actual)) - -#define ASSERT_GREATER_THAN_UINT64_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_UINT64_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_UINT64(actual, threshold) \ - TEST_ASSERT_LESS_THAN_UINT64((threshold), (actual)) - -#define ASSERT_LESS_THAN_UINT64_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_UINT64_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_UINT64(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_UINT64((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_UINT64_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_UINT64_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_UINT64(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL_UINT64((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_UINT64_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_UINT64_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_THAN_HEX8(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_HEX8((threshold), (actual)) - -#define ASSERT_GREATER_THAN_HEX8_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_HEX8_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_HEX8(actual, threshold) \ - TEST_ASSERT_LESS_THAN_HEX8((threshold), (actual)) - -#define ASSERT_LESS_THAN_HEX8_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_HEX8_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_HEX8(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_HEX8((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_HEX8_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_HEX8_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_HEX8(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL_HEX8((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_HEX8_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_HEX8_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_THAN_HEX16(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_HEX16((threshold), (actual)) - -#define ASSERT_GREATER_THAN_HEX16_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_HEX16_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_HEX16(actual, threshold) \ - TEST_ASSERT_LESS_THAN_HEX16((threshold), (actual)) - -#define ASSERT_LESS_THAN_HEX16_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_HEX16_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_HEX16(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_HEX16((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_HEX16_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_HEX16_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_HEX16(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL_HEX16((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_HEX16_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_HEX16_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_THAN_HEX32(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_HEX32((threshold), (actual)) - -#define ASSERT_GREATER_THAN_HEX32_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_HEX32_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_HEX32(actual, threshold) \ - TEST_ASSERT_LESS_THAN_HEX32((threshold), (actual)) - -#define ASSERT_LESS_THAN_HEX32_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_HEX32_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_HEX32(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_HEX32((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_HEX32_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_HEX32_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_HEX32_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_HEX32_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_THAN_HEX64(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_HEX64((threshold), (actual)) - -#define ASSERT_LESS_THAN_HEX64(actual, threshold) \ - TEST_ASSERT_LESS_THAN_HEX64((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_HEX64(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_HEX64((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_HEX64(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL_HEX64((threshold), (actual)) - -#define ASSERT_GREATER_THAN_HEX64_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_HEX64_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_HEX64_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_HEX64_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_HEX64_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_HEX64_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_HEX64_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_HEX64_MESSAGE((threshold), (actual), (message)) - -/* - * Float comparison assertions - */ - -#define ASSERT_GREATER_THAN_FLOAT(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_FLOAT((threshold), (actual)) - -#define ASSERT_LESS_THAN_FLOAT(actual, threshold) \ - TEST_ASSERT_LESS_THAN_FLOAT((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_FLOAT(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_FLOAT((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_FLOAT(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL_FLOAT((threshold), (actual)) - -#define ASSERT_GREATER_THAN_FLOAT_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_FLOAT_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_FLOAT_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_FLOAT_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_FLOAT_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_FLOAT_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_FLOAT_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_FLOAT_MESSAGE((threshold), (actual), (message)) - -/* - * Double comparison assertions - */ - -#define ASSERT_GREATER_THAN_DOUBLE(actual, threshold) \ - TEST_ASSERT_GREATER_THAN_DOUBLE((threshold), (actual)) - -#define ASSERT_LESS_THAN_DOUBLE(actual, threshold) \ - TEST_ASSERT_LESS_THAN_DOUBLE((threshold), (actual)) - -#define ASSERT_GREATER_OR_EQUAL_DOUBLE(actual, threshold) \ - TEST_ASSERT_GREATER_OR_EQUAL_DOUBLE((threshold), (actual)) - -#define ASSERT_LESS_OR_EQUAL_DOUBLE(actual, threshold) \ - TEST_ASSERT_LESS_OR_EQUAL_DOUBLE((threshold), (actual)) - -#define ASSERT_GREATER_THAN_DOUBLE_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_THAN_DOUBLE_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_THAN_DOUBLE_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_THAN_DOUBLE_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_GREATER_OR_EQUAL_DOUBLE_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_GREATER_OR_EQUAL_DOUBLE_MESSAGE((threshold), (actual), (message)) - -#define ASSERT_LESS_OR_EQUAL_DOUBLE_MESSAGE(actual, threshold, message) \ - TEST_ASSERT_LESS_OR_EQUAL_DOUBLE_MESSAGE((threshold), (actual), (message)) diff --git a/test/microstrain_test/scripts/DiscoverTests.cmake b/test/microstrain_test/scripts/DiscoverTests.cmake deleted file mode 100644 index a2275eb92..000000000 --- a/test/microstrain_test/scripts/DiscoverTests.cmake +++ /dev/null @@ -1,110 +0,0 @@ -include(${microstrain_test_SOURCE_DIR}/scripts/internal/Internals.cmake) - -# Automatically discovers and sets tests to run (C framework API). -# -# Arguments: -# TARGET - An executable with the source files for all tests to run linked to it. -# A main function will be generated for this executable to run the tests. -# LABELS - Additional CTest labels for the tests discovered. Example use cases: -# "unit" or "integration" to allow all tests of each type to be run. -# SEQUENTIAL - A boolean switch to run all tests discovered one at a time, instead -# of in parallel. If this isn't passed, the tests will run in parallel. -function(microstrain_discover_tests_c) - # Set policy to allow for test names with special characters - if(POLICY CMP0110) - cmake_policy(SET CMP0110 NEW) - endif() - - cmake_parse_arguments( - ARG - "SEQUENTIAL" - "TARGET" - "LABELS" - ${ARGN} - ) - - # Verify the target exists - if(NOT TARGET ${ARG_TARGET}) - message(FATAL_ERROR "Target ${ARG_TARGET} does not exist") - return() - endif() - - # Verify the target has source files set - get_target_property(TARGET_SOURCES ${ARG_TARGET} SOURCES) - if(NOT TARGET_SOURCES OR TARGET_SOURCES STREQUAL "TARGET_SOURCES-NOTFOUND") - internal_generate_test_runner_file_with_dummy_main("${ARG_TARGET}") - return() - endif() - - internal_parse_test_registrations_from_sources( - "${TARGET_SOURCES}" - DISCOVERED_SUITES - DISCOVERED_TESTS - TEST_FILEPATHS - ) - - # Exit early if no test registrations are found - if(NOT DISCOVERED_SUITES OR NOT DISCOVERED_TESTS) - internal_generate_test_runner_file_with_dummy_main("${ARG_TARGET}") - return() - endif() - - internal_generate_test_runner_file_with_main( - "${ARG_TARGET}" - "${DISCOVERED_SUITES}" - "${DISCOVERED_TESTS}" - "${TEST_FILEPATHS}" - GENERATED_MAIN - ) - - # Add generated main to existing executable - target_sources(${ARG_TARGET} PRIVATE ${GENERATED_MAIN}) - - internal_register_individual_tests_with_ctest( - "${ARG_TARGET}" - "${DISCOVERED_SUITES}" - "${DISCOVERED_TESTS}" - "${ARG_LABELS}" - "${ARG_DISABLED}" - "${ARG_SEQUENTIAL}" - ) -endfunction() - - -# Automatically discovers and sets tests to run (C++ framework API). -# -# Arguments: -# TARGET - An executable with the source files for all tests to run linked to it. -# A main function will be generated for this executable to run the tests. -# LABELS - Additional CTest labels for the tests discovered. Example use cases: -# "unit" or "integration" to allow all tests of each type to be run. -# SEQUENTIAL - A boolean switch to run all tests discovered one at a time, instead -# of in parallel. If this isn't passed, the tests will run in parallel. -function(microstrain_discover_tests_cpp) - cmake_parse_arguments( - ARG - "SEQUENTIAL" - "TARGET" - "LABELS" - ${ARGN} - ) - - if(MICROSTRAIN_TEST_USE_DOCTEST) - include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake) - - if(ARG_SEQUENTIAL) - doctest_discover_tests( - ${ARG_TARGET} - PROPERTIES - LABELS ${ARG_LABELS} - RESOURCE_LOCK ${ARG_TARGET} - ) - else() - doctest_discover_tests( - ${ARG_TARGET} - PROPERTIES - LABELS ${ARG_LABELS} - ) - endif() - endif() -endfunction() diff --git a/test/microstrain_test/scripts/internal/InstallDoctest.cmake b/test/microstrain_test/scripts/internal/InstallDoctest.cmake deleted file mode 100644 index f2b8024fc..000000000 --- a/test/microstrain_test/scripts/internal/InstallDoctest.cmake +++ /dev/null @@ -1,10 +0,0 @@ -include(FetchContent) - -set(DOCTEST_NO_INSTALL ON CACHE BOOL "" FORCE) - -FetchContent_Declare(doctest - GIT_REPOSITORY "https://github.com/doctest/doctest.git" - GIT_TAG "v2.4.12" -) - -FetchContent_MakeAvailable(doctest) diff --git a/test/microstrain_test/scripts/internal/InstallUnity.cmake b/test/microstrain_test/scripts/internal/InstallUnity.cmake deleted file mode 100644 index c8d28c4dc..000000000 --- a/test/microstrain_test/scripts/internal/InstallUnity.cmake +++ /dev/null @@ -1,20 +0,0 @@ -include(FetchContent) - -FetchContent_Declare(unity - GIT_REPOSITORY "https://github.com/ThrowTheSwitch/Unity.git" - GIT_TAG "v2.6.1" -) - -FetchContent_MakeAvailable(unity) - -# Unity doesn't have native CMake support, so we have to build it manually. -if (NOT TARGET unity) - add_library(unity STATIC ${unity_SOURCE_DIR}/src/unity.c) - target_include_directories(unity PUBLIC ${unity_SOURCE_DIR}/src) -endif() - -# Disable Spectre mitigation warnings for Unity as building with /Qspectre would add performance -# overhead without a significant security threat to justify it. -if(MSVC) - target_compile_options(unity PRIVATE /wd5045) -endif() diff --git a/test/microstrain_test/scripts/internal/Internals.cmake b/test/microstrain_test/scripts/internal/Internals.cmake deleted file mode 100644 index 4a47d0bda..000000000 --- a/test/microstrain_test/scripts/internal/Internals.cmake +++ /dev/null @@ -1,185 +0,0 @@ -# Searches through all source files linked to the target and parses test registration -# calls from them. -# -# The test suites and names are extracted from the registration calls and returned in -# lists for reference, along with the paths to the files where the calls were made. -# The paths are needed so that links point to the correct file when an assertion fails. -function(internal_parse_test_registrations_from_sources - TARGET_SOURCES - OUT_SUITES - OUT_TESTS - OUT_FILEPATHS -) - set(DISCOVERED_SUITES "") - set(DISCOVERED_TESTS "") - set(TEST_FILEPATHS "") - - foreach(SOURCE_FILE ${TARGET_SOURCES}) - get_filename_component(SOURCE_FILE_ABSOLUTE_PATH "${SOURCE_FILE}" ABSOLUTE) - - # Set CMake to reload when source changes to discover newly added tests. - set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${SOURCE_FILE_ABSOLUTE_PATH}") - - if(NOT EXISTS "${SOURCE_FILE_ABSOLUTE_PATH}") - continue() - endif() - - file(READ "${SOURCE_FILE_ABSOLUTE_PATH}" FILE_CONTENT) - - # Remove block comments /* ... */ - # This regex handles multiline block comments. It also handles complex cases such as if - # asterisks are inside the comment, etc. - string(REGEX REPLACE "/\\*([^*]|\\*+[^*/])*\\*+/" "" FILE_CONTENT "${FILE_CONTENT}") - - # Split file into lines to check for line comments. - # Replaces every ";" with "\\;" (so they aren't interpreted as the CMake list separator). - string(REGEX REPLACE ";" "\\\\;" FILE_CONTENT "${FILE_CONTENT}") - # Converts the file to a CMake list where each element is one line by replacing newlines - # with the CMake list separator. This allows the lines to be looped over. - string(REGEX REPLACE "\n" ";" FILE_LINES "${FILE_CONTENT}") - - foreach(LINE ${FILE_LINES}) - # Remove everything after // (line comments) - string(REGEX REPLACE "//.*$" "" LINE_WITHOUT_COMMENT "${LINE}") - - # Check if the line contains a test registration (after comment removal). - string(REGEX MATCH "MICROSTRAIN_TEST_CASE\\([^)]+\\)" MATCH "${LINE_WITHOUT_COMMENT}") - - if(MATCH) - # Extract the test name and test suite. - string(REGEX REPLACE "MICROSTRAIN_TEST_CASE\\(([a-zA-Z0-9_]+)[ \t]*,[ \t]*([a-zA-Z0-9_]+)\\)" "\\1" SUITE_NAME "${MATCH}") - string(REGEX REPLACE "MICROSTRAIN_TEST_CASE\\(([a-zA-Z0-9_]+)[ \t]*,[ \t]*([a-zA-Z0-9_]+)\\)" "\\2" TEST_NAME "${MATCH}") - - list(APPEND DISCOVERED_SUITES ${SUITE_NAME}) - list(APPEND DISCOVERED_TESTS ${TEST_NAME}) - list(APPEND TEST_FILEPATHS "${SOURCE_FILE_ABSOLUTE_PATH}") - endif() - endforeach() - endforeach() - - # Return results to parent scope - set(${OUT_SUITES} ${DISCOVERED_SUITES} PARENT_SCOPE) - set(${OUT_TESTS} ${DISCOVERED_TESTS} PARENT_SCOPE) - set(${OUT_FILEPATHS} ${TEST_FILEPATHS} PARENT_SCOPE) -endfunction() - - -# Creates an empty test runner file (this file should be populated later). -function(internal_create_test_runner_file TARGET_NAME OUT_GENERATED_FILEPATH) - # Create directory for the generated file - set(GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated_tests/${TARGET_NAME}") - file(MAKE_DIRECTORY "${GENERATED_DIR}") - - # Create the file - set(GENERATED_MAIN "${GENERATED_DIR}/run_tests.c") - - # Return the filepath to parent scope - set(${OUT_GENERATED_FILEPATH} "${GENERATED_MAIN}" PARENT_SCOPE) -endfunction() - - -# Generates a main runner file with a dummy main to avoid a failing build if no tests are -# discovered. -# -# This should only be used if no tests are available after discovery. Otherwise, the -# actual main generator should be used. -function(internal_generate_test_runner_file_with_dummy_main TARGET_NAME) - internal_create_test_runner_file("${TARGET_NAME}" GENERATED_MAIN) - - # Write empty main - file(WRITE "${GENERATED_MAIN}" "int main(void) { return 0; }\n") - - # Add to target - target_sources(${TARGET_NAME} PRIVATE "${GENERATED_MAIN}") -endfunction() - - -# Generates a main runner file for all tests, with a main function to handle test execution. -# -# Allows all tests to be run at once, or filtered individually through the command-line. -function(internal_generate_test_runner_file_with_main - TARGET_NAME - DISCOVERED_SUITES - DISCOVERED_TESTS - TEST_FILEPATHS - OUT_GENERATED_MAIN -) - internal_create_test_runner_file("${TARGET_NAME}" GENERATED_MAIN) - - # Generate test case declarations - set(TEST_DECLARATIONS "") - list(LENGTH DISCOVERED_TESTS TEST_COUNT) - math(EXPR LAST_INDEX "${TEST_COUNT} - 1") - foreach(INDEX RANGE ${LAST_INDEX}) - list(GET DISCOVERED_SUITES ${INDEX} SUITE_NAME) - list(GET DISCOVERED_TESTS ${INDEX} TEST_NAME) - string(APPEND TEST_DECLARATIONS "extern MICROSTRAIN_TEST_CASE(${SUITE_NAME}, ${TEST_NAME});\n") - endforeach() - - # Generate test filtering logic to allow individual tests to be run given commandline - # arguments (or run all tests at once). - set(TEST_FILTERING "") - foreach(INDEX RANGE ${LAST_INDEX}) - # We need to set the filepath explicitly (for Unity) since it points to the generated - # runner file instead. - list(GET TEST_FILEPATHS ${INDEX} TEST_FILEPATH) - list(GET DISCOVERED_SUITES ${INDEX} SUITE_NAME) - list(GET DISCOVERED_TESTS ${INDEX} TEST_NAME) - - # Escape backslashes in filepaths for C string literal - string(REPLACE "\\" "\\\\" TEST_FILEPATH_ESCAPED "${TEST_FILEPATH}") - - string(APPEND TEST_FILTERING "INTERNAL_MICROSTRAIN_TEST_CASE_FILTER(test_filter, ${SUITE_NAME}, ${TEST_NAME}, \"${TEST_FILEPATH_ESCAPED}\")\n") - endforeach() - - # Write the generated contents to the main file and return the filepath to the parent scope. - configure_file( - "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/test_runner_template.c.in" - "${GENERATED_MAIN}" - @ONLY - ) - set(${OUT_GENERATED_MAIN} "${GENERATED_MAIN}" PARENT_SCOPE) -endfunction() - - -# Registers each individual test with CTest. -function(internal_register_individual_tests_with_ctest - TARGET_NAME - DISCOVERED_SUITES - DISCOVERED_TESTS - LABELS - DISABLED - SEQUENTIAL -) - list(LENGTH DISCOVERED_TESTS TEST_COUNT) - math(EXPR LAST_INDEX "${TEST_COUNT} - 1") - - foreach(INDEX RANGE ${LAST_INDEX}) - list(GET DISCOVERED_SUITES ${INDEX} SUITE_NAME) - list(GET DISCOVERED_TESTS ${INDEX} TEST_NAME) - - # Set how the test name should be displayed in the console when running tests. - # Currently in this format: "[Example_suite] Example_test" - set(TEST_DISPLAY "[${SUITE_NAME}] ${TEST_NAME}") - - add_test(NAME ${TEST_DISPLAY} COMMAND ${TARGET_NAME} --test=${TEST_DISPLAY}) - - set_tests_properties(${TEST_DISPLAY} - PROPERTIES - TIMEOUT 30 - LABELS "${TARGET_NAME};${SUITE_NAME}" - ) - - if(LABELS) - set_tests_properties(${TEST_DISPLAY} PROPERTIES LABELS ${LABELS}) - endif() - - if(DISABLED) - set_tests_properties(${TEST_DISPLAY} PROPERTIES DISABLED TRUE) - endif() - - if(SEQUENTIAL) - set_tests_properties(${TEST_DISPLAY} PROPERTIES RESOURCE_LOCK ${TARGET_NAME}) - endif() - endforeach() -endfunction() diff --git a/test/microstrain_test/scripts/internal/test_runner_template.c.in b/test/microstrain_test/scripts/internal/test_runner_template.c.in deleted file mode 100644 index 4459bdcd3..000000000 --- a/test/microstrain_test/scripts/internal/test_runner_template.c.in +++ /dev/null @@ -1,27 +0,0 @@ -/* Template file used to generate the test runner for a test executable */ -#include - -#include - -MICROSTRAIN_TEST_DEFAULT_SETUP(); - -@TEST_DECLARATIONS@ - -int main(int argc, char** argv) { - MICROSTRAIN_TEST_BEGIN(); - - const char* test_filter = NULL; - - // Parse command line for --test=name - for (int i = 1; i < argc; ++i) { - if (strncmp(argv[i], "--test=", 7) == 0) { - test_filter = argv[i] + 7; - break; - } - } - - (void)test_filter; /* Suppress unused variable warning if only one test */ - -@TEST_FILTERING@ - return MICROSTRAIN_TEST_END(); -} From 150c6bdd070ff156aa27722e3fa6fe5e580877a9 Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Fri, 24 Oct 2025 13:53:26 -0400 Subject: [PATCH 2/9] Fixed frameworks not being set correctly --- test/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 13f778393..121ebb349 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,12 +4,12 @@ include(FetchContent) -set(MICROSTRAIN_TEST_USE_UNITY ON CACHE BOOL "" FORCE) -set(MICROSTRAIN_TEST_USE_DOCTEST ON CACHE BOOL "" FORCE) +set(MICROSTRAIN_TEST_FRAMEWORK_C "unity" CACHE STRING "" FORCE) +set(MICROSTRAIN_TEST_FRAMEWORK_CPP "doctest" CACHE STRING "" FORCE) FetchContent_Declare(microstrain_test GIT_REPOSITORY https://github.com/LORD-MicroStrain/microstrain_test.git - GIT_TAG v0.1.0 + GIT_TAG v0.2.2 ) FetchContent_MakeAvailable(microstrain_test) From 062b834ff9e800c99f68a94ed80ecc719e8a693b Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Fri, 24 Oct 2025 14:11:44 -0400 Subject: [PATCH 3/9] Updated microstrain test version --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 121ebb349..43ca96d62 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,7 +9,7 @@ set(MICROSTRAIN_TEST_FRAMEWORK_CPP "doctest" CACHE STRING "" FORCE) FetchContent_Declare(microstrain_test GIT_REPOSITORY https://github.com/LORD-MicroStrain/microstrain_test.git - GIT_TAG v0.2.2 + GIT_TAG v0.2.3 ) FetchContent_MakeAvailable(microstrain_test) From b821b64aea75b7b3b5a41675a5d0a46225e950fb Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Fri, 24 Oct 2025 14:13:29 -0400 Subject: [PATCH 4/9] Updated microstrain test version --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 43ca96d62..70722b004 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,7 +9,7 @@ set(MICROSTRAIN_TEST_FRAMEWORK_CPP "doctest" CACHE STRING "" FORCE) FetchContent_Declare(microstrain_test GIT_REPOSITORY https://github.com/LORD-MicroStrain/microstrain_test.git - GIT_TAG v0.2.3 + GIT_TAG v0.2.4 ) FetchContent_MakeAvailable(microstrain_test) From ce6917203748d6c0b3a9326fa24506dad026885d Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Fri, 24 Oct 2025 15:31:29 -0400 Subject: [PATCH 5/9] Updated microstrain test version --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 70722b004..1963f6314 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,7 +9,7 @@ set(MICROSTRAIN_TEST_FRAMEWORK_CPP "doctest" CACHE STRING "" FORCE) FetchContent_Declare(microstrain_test GIT_REPOSITORY https://github.com/LORD-MicroStrain/microstrain_test.git - GIT_TAG v0.2.4 + GIT_TAG v0.2.5 ) FetchContent_MakeAvailable(microstrain_test) From ba43902fcae1d5b9ef11158af7dcdd723b24f490 Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Fri, 24 Oct 2025 16:16:19 -0400 Subject: [PATCH 6/9] Updated microstrain test version and fixed strings unit test not using wrapper macros --- test/CMakeLists.txt | 2 +- test/c/microstrain/strings.unit.c | 172 +++++++-------- test/c/mip/test_mip_fields.c | 124 ----------- test/c/mip/test_mip_packet_builder.c | 117 ---------- test/c/mip/test_mip_random.c | 308 --------------------------- test/cpp/mip.cpp | 113 ---------- test/cpp/packet_interface.cpp | 185 ---------------- 7 files changed, 87 insertions(+), 934 deletions(-) delete mode 100644 test/c/mip/test_mip_fields.c delete mode 100644 test/c/mip/test_mip_packet_builder.c delete mode 100644 test/c/mip/test_mip_random.c delete mode 100644 test/cpp/mip.cpp delete mode 100644 test/cpp/packet_interface.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1963f6314..49e7dfc6f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,7 +9,7 @@ set(MICROSTRAIN_TEST_FRAMEWORK_CPP "doctest" CACHE STRING "" FORCE) FetchContent_Declare(microstrain_test GIT_REPOSITORY https://github.com/LORD-MicroStrain/microstrain_test.git - GIT_TAG v0.2.5 + GIT_TAG v0.2.6 ) FetchContent_MakeAvailable(microstrain_test) diff --git a/test/c/microstrain/strings.unit.c b/test/c/microstrain/strings.unit.c index f40809c32..68d9ece9d 100644 --- a/test/c/microstrain/strings.unit.c +++ b/test/c/microstrain/strings.unit.c @@ -14,10 +14,10 @@ MICROSTRAIN_TEST_CASE(C_string_concatentation, A_zero_terminated_string_can_be_c const bool ok = microstrain_string_concat(buffer, sizeof(buffer), &index, string, string_length); - TEST_ASSERT_TRUE(ok); - TEST_ASSERT_EQUAL_INT(index, string_length); - TEST_ASSERT_EQUAL_CHAR(buffer[5], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "12345\0____"); + ASSERT_TRUE(ok); + ASSERT_EQUAL_INT(index, string_length); + ASSERT_EQUAL_CHAR(buffer[5], '\0'); + ASSERT_EQUAL_STRING(buffer, "12345\0____"); } MICROSTRAIN_TEST_CASE(C_string_concatenation, String_concatenation_to_an_empty_buffer_fails_gracefully_if_buffer_too_small) @@ -31,10 +31,10 @@ MICROSTRAIN_TEST_CASE(C_string_concatenation, String_concatenation_to_an_empty_b const bool ok = microstrain_string_concat(buffer, fake_buffer_size, &index, string, string_length); - TEST_ASSERT_FALSE(ok); - TEST_ASSERT_EQUAL_INT(index, string_length); - TEST_ASSERT_EQUAL_CHAR(buffer[3], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "123\0______"); + ASSERT_FALSE(ok); + ASSERT_EQUAL_INT(index, string_length); + ASSERT_EQUAL_CHAR(buffer[3], '\0'); + ASSERT_EQUAL_STRING(buffer, "123\0______"); } MICROSTRAIN_TEST_CASE(C_string_concatenation, String_concatenation_computes_required_buffer_size_when_buffer_is_null) @@ -45,8 +45,8 @@ MICROSTRAIN_TEST_CASE(C_string_concatenation, String_concatenation_computes_requ const bool ok = microstrain_string_concat(NULL, 0, &index, string, string_length); - TEST_ASSERT_TRUE(ok); - TEST_ASSERT_EQUAL_INT(index, string_length); + ASSERT_TRUE(ok); + ASSERT_EQUAL_INT(index, string_length); } MICROSTRAIN_TEST_CASE(C_string_concatenation, A_zero_terminated_string_can_be_concatenated_to_a_non_empty_buffer) @@ -58,10 +58,10 @@ MICROSTRAIN_TEST_CASE(C_string_concatenation, A_zero_terminated_string_can_be_co const bool ok = microstrain_string_concat(buffer, sizeof(buffer), &index, "6789", 4); - TEST_ASSERT_TRUE(ok); - TEST_ASSERT_EQUAL_INT(index, 9); - TEST_ASSERT_EQUAL_CHAR(buffer[9], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "123456789\0"); + ASSERT_TRUE(ok); + ASSERT_EQUAL_INT(index, 9); + ASSERT_EQUAL_CHAR(buffer[9], '\0'); + ASSERT_EQUAL_STRING(buffer, "123456789\0"); } MICROSTRAIN_TEST_CASE(C_string_concatenation, String_concatenation_to_a_non_empty_buffer_fails_gracefully_if_buffer_too_small) @@ -73,10 +73,10 @@ MICROSTRAIN_TEST_CASE(C_string_concatenation, String_concatenation_to_a_non_empt const bool ok = microstrain_string_concat(buffer, fake_buffer_size, &index, "89ABCDEF", 8); - TEST_ASSERT_FALSE(ok); - TEST_ASSERT_EQUAL_INT(index, 16); - TEST_ASSERT_EQUAL_CHAR(buffer[9], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "012345678\0##########"); // TODO: I don't think characters after the null terminator are compared. + ASSERT_FALSE(ok); + ASSERT_EQUAL_INT(index, 16); + ASSERT_EQUAL_CHAR(buffer[9], '\0'); + ASSERT_EQUAL_STRING(buffer, "012345678\0##########"); // TODO: I don't think characters after the null terminator are compared. // Should they be? } @@ -92,10 +92,10 @@ MICROSTRAIN_TEST_CASE(C_string_concatenation, String_concatenation_to_a_non_empt const bool ok = microstrain_string_concat(buffer, fake_buffer_size, &index, msg, msg_size); - TEST_ASSERT_FALSE(ok); - TEST_ASSERT_EQUAL_INT(index, 18); - TEST_ASSERT_EQUAL_CHAR(buffer[9], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "012345678\0__________"); + ASSERT_FALSE(ok); + ASSERT_EQUAL_INT(index, 18); + ASSERT_EQUAL_CHAR(buffer[9], '\0'); + ASSERT_EQUAL_STRING(buffer, "012345678\0__________"); } MICROSTRAIN_TEST_CASE(C_string_concatenation, Multiple_string_concatenations_work) @@ -112,10 +112,10 @@ MICROSTRAIN_TEST_CASE(C_string_concatenation, Multiple_string_concatenations_wor ok &= microstrain_string_concat_l(buffer, sizeof(buffer), &index, "long "); ok &= microstrain_string_concat_l(buffer, sizeof(buffer), &index, "test..."); - TEST_ASSERT_TRUE(ok); - TEST_ASSERT_EQUAL_INT(index, 27); - TEST_ASSERT_EQUAL_CHAR(buffer[27], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "This is a very long test..."); + ASSERT_TRUE(ok); + ASSERT_EQUAL_INT(index, 27); + ASSERT_EQUAL_CHAR(buffer[27], '\0'); + ASSERT_EQUAL_STRING(buffer, "This is a very long test..."); } MICROSTRAIN_TEST_CASE(C_string_concatenation, Multiple_string_concatenations_fail_gracefully_when_buffer_too_small) @@ -133,10 +133,10 @@ MICROSTRAIN_TEST_CASE(C_string_concatenation, Multiple_string_concatenations_fai ok &= microstrain_string_concat_l(buffer, fake_buffer_size, &index, "long "); ok &= microstrain_string_concat_l(buffer, fake_buffer_size, &index, "test..."); - TEST_ASSERT_FALSE(ok); - TEST_ASSERT_EQUAL_INT(index, 27); - TEST_ASSERT_EQUAL_CHAR(buffer[9], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "This is a"); + ASSERT_FALSE(ok); + ASSERT_EQUAL_INT(index, 27); + ASSERT_EQUAL_CHAR(buffer[9], '\0'); + ASSERT_EQUAL_STRING(buffer, "This is a"); } MICROSTRAIN_TEST_CASE(C_string_formatting, A_string_can_be_formatted_and_written_to_an_empty_buffer) @@ -147,10 +147,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_string_can_be_formatted_and_written const bool ok = microstrain_string_format(buffer, sizeof(buffer), &index, "%d==0x%x", 4096, 0x1000); - TEST_ASSERT_TRUE(ok); - TEST_ASSERT_EQUAL_INT(index, 4+2+2+4); - TEST_ASSERT_EQUAL_CHAR(buffer[12], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "4096==0x1000\0_______"); + ASSERT_TRUE(ok); + ASSERT_EQUAL_INT(index, 4+2+2+4); + ASSERT_EQUAL_CHAR(buffer[12], '\0'); + ASSERT_EQUAL_STRING(buffer, "4096==0x1000\0_______"); } MICROSTRAIN_TEST_CASE(C_string_formatting, String_formatting_fails_gracefully_when_buffer_is_too_small) @@ -161,10 +161,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, String_formatting_fails_gracefully_wh const bool ok = microstrain_string_format(buffer, 10, &index, "%d==0x%x", 4096, 0x1000); - TEST_ASSERT_FALSE(ok); - TEST_ASSERT_EQUAL_INT(index, 4+2+2+4); - TEST_ASSERT_EQUAL_CHAR(buffer[9], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "4096==0x1\0__________"); + ASSERT_FALSE(ok); + ASSERT_EQUAL_INT(index, 4+2+2+4); + ASSERT_EQUAL_CHAR(buffer[9], '\0'); + ASSERT_EQUAL_STRING(buffer, "4096==0x1\0__________"); } MICROSTRAIN_TEST_CASE(C_string_formatting, String_formatting_calculates_required_buffer_size_if_buffer_is_null) @@ -173,8 +173,8 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, String_formatting_calculates_required const bool ok = microstrain_string_format(NULL, 0, &index, "%d==0x%x", 4096, 0x1000); - TEST_ASSERT_TRUE(ok); - TEST_ASSERT_EQUAL_INT(index, 4+2+2+4); + ASSERT_TRUE(ok); + ASSERT_EQUAL_INT(index, 4+2+2+4); } MICROSTRAIN_TEST_CASE(C_string_formatting, A_string_can_be_formatted_and_written_to_a_non_empty_buffer) @@ -186,10 +186,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_string_can_be_formatted_and_written const bool ok = microstrain_string_format(buffer, sizeof(buffer), &index, "%d==0x%x", 4096, 0x1000); - TEST_ASSERT_TRUE(ok); - TEST_ASSERT_EQUAL_INT(index, 6+4+2+2+4); - TEST_ASSERT_EQUAL_CHAR(buffer[18], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "Test: 4096==0x1000\0_"); + ASSERT_TRUE(ok); + ASSERT_EQUAL_INT(index, 6+4+2+2+4); + ASSERT_EQUAL_CHAR(buffer[18], '\0'); + ASSERT_EQUAL_STRING(buffer, "Test: 4096==0x1000\0_"); } MICROSTRAIN_TEST_CASE(C_string_formatting, String_formatting_to_a_non_empty_buffer_fails_gracefully_if_buffer_too_small) @@ -201,10 +201,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, String_formatting_to_a_non_empty_buff const bool ok = microstrain_string_format(buffer, 10, &index, "%d==0x%x", 4096, 0x1000); - TEST_ASSERT_FALSE(ok); - TEST_ASSERT_EQUAL_INT(index, 6+4+2+2+4); - TEST_ASSERT_EQUAL_CHAR(buffer[9], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "Test: 409\0__________"); + ASSERT_FALSE(ok); + ASSERT_EQUAL_INT(index, 6+4+2+2+4); + ASSERT_EQUAL_CHAR(buffer[9], '\0'); + ASSERT_EQUAL_STRING(buffer, "Test: 409\0__________"); } MICROSTRAIN_TEST_CASE(C_string_formatting, Multiple_string_formattings_work) @@ -220,10 +220,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, Multiple_string_formattings_work) ok &= microstrain_string_format(buffer, 50, &index, "C=%s", "abcdefg"); ok &= microstrain_string_format(buffer, 50, &index, "]"); - TEST_ASSERT_TRUE(ok); - TEST_ASSERT_EQUAL_INT(index, 9+2+5+2+4+4+2+2+7+1); - TEST_ASSERT_EQUAL_CHAR(buffer[38], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "Values: [A=54321, B=0xABCD, C=abcdefg]"); + ASSERT_TRUE(ok); + ASSERT_EQUAL_INT(index, 9+2+5+2+4+4+2+2+7+1); + ASSERT_EQUAL_CHAR(buffer[38], '\0'); + ASSERT_EQUAL_STRING(buffer, "Values: [A=54321, B=0xABCD, C=abcdefg]"); } MICROSTRAIN_TEST_CASE(C_string_formatting, Multiple_string_formattings_fail_gracefully_when_buffer_too_small) @@ -239,10 +239,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, Multiple_string_formattings_fail_grac ok &= microstrain_string_format(buffer, 25, &index, "C=%s", "abcdefg"); ok &= microstrain_string_format(buffer, 25, &index, "]"); - TEST_ASSERT_FALSE(ok); - TEST_ASSERT_EQUAL_INT(index, 9+2+5+2+4+4+2+2+7+1); - TEST_ASSERT_EQUAL_CHAR(buffer[24], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "Values: [A=54321, B=0xAB"); + ASSERT_FALSE(ok); + ASSERT_EQUAL_INT(index, 9+2+5+2+4+4+2+2+7+1); + ASSERT_EQUAL_CHAR(buffer[24], '\0'); + ASSERT_EQUAL_STRING(buffer, "Values: [A=54321, B=0xAB"); } MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadecimal_and_written_to_a_string_buffer) @@ -254,10 +254,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadec const bool ok = microstrain_string_bytes_to_hex_str(buffer, 25, &index, data, sizeof(data), 0); - TEST_ASSERT_TRUE(ok); - TEST_ASSERT_EQUAL_INT(index, 2+2+2+2); - TEST_ASSERT_EQUAL_CHAR(buffer[8], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "A1B2C3D4"); + ASSERT_TRUE(ok); + ASSERT_EQUAL_INT(index, 2+2+2+2); + ASSERT_EQUAL_CHAR(buffer[8], '\0'); + ASSERT_EQUAL_STRING(buffer, "A1B2C3D4"); } MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadecimal_with_group1_and_written_to_a_string_buffer) @@ -269,10 +269,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadec const bool ok = microstrain_string_bytes_to_hex_str(buffer, 25, &index, data, sizeof(data), 1); - TEST_ASSERT_TRUE(ok); - TEST_ASSERT_EQUAL_INT(index, 2+1+2+1+2+1+2); - TEST_ASSERT_EQUAL_CHAR(buffer[11], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "A1 B2 C3 D4"); + ASSERT_TRUE(ok); + ASSERT_EQUAL_INT(index, 2+1+2+1+2+1+2); + ASSERT_EQUAL_CHAR(buffer[11], '\0'); + ASSERT_EQUAL_STRING(buffer, "A1 B2 C3 D4"); } MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadecimal_with_group2_and_written_to_a_string_buffer) @@ -284,10 +284,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadec const bool ok = microstrain_string_bytes_to_hex_str(buffer, 25, &index, data, sizeof(data), 2); - TEST_ASSERT_TRUE(ok); - TEST_ASSERT_EQUAL_INT(index, 2+2+1+2+2); - TEST_ASSERT_EQUAL_CHAR(buffer[9], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "A1B2 C3D4"); + ASSERT_TRUE(ok); + ASSERT_EQUAL_INT(index, 2+2+1+2+2); + ASSERT_EQUAL_CHAR(buffer[9], '\0'); + ASSERT_EQUAL_STRING(buffer, "A1B2 C3D4"); } MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadecimal_with_partial_group2_and_written_to_a_string_buffer) @@ -299,10 +299,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadec const bool ok = microstrain_string_bytes_to_hex_str(buffer, 25, &index, data, sizeof(data), 2); - TEST_ASSERT_TRUE(ok); - TEST_ASSERT_EQUAL_INT(index, 2+2+1+2+2+1+2); - TEST_ASSERT_EQUAL_CHAR(buffer[12], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "A1B2 C3D4 E5"); + ASSERT_TRUE(ok); + ASSERT_EQUAL_INT(index, 2+2+1+2+2+1+2); + ASSERT_EQUAL_CHAR(buffer[12], '\0'); + ASSERT_EQUAL_STRING(buffer, "A1B2 C3D4 E5"); } MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadecimal_with_group4_and_written_to_a_string_buffer) @@ -314,10 +314,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadec const bool ok = microstrain_string_bytes_to_hex_str(buffer, 25, &index, data, sizeof(data), 4); - TEST_ASSERT_TRUE(ok); - TEST_ASSERT_EQUAL_INT(index, 2+2+2+2+1+2+2+2+2); - TEST_ASSERT_EQUAL_CHAR(buffer[17], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "A8B9CEDF 01234567"); + ASSERT_TRUE(ok); + ASSERT_EQUAL_INT(index, 2+2+2+2+1+2+2+2+2); + ASSERT_EQUAL_CHAR(buffer[17], '\0'); + ASSERT_EQUAL_STRING(buffer, "A8B9CEDF 01234567"); } MICROSTRAIN_TEST_CASE(C_string_formatting, Byte_formatting_handles_no_data_properly) @@ -328,8 +328,8 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, Byte_formatting_handles_no_data_prope const bool ok = microstrain_string_bytes_to_hex_str(buffer, 10, &index, NULL, 0, 0); - TEST_ASSERT_TRUE(ok); - TEST_ASSERT_EQUAL_INT(index, 0); + ASSERT_TRUE(ok); + ASSERT_EQUAL_INT(index, 0); } MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadecimal_and_written_to_a_non_empty_string_buffer) @@ -342,10 +342,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadec const bool ok = microstrain_string_bytes_to_hex_str(buffer, 25, &index, data, sizeof(data), 0); - TEST_ASSERT_TRUE(ok); - TEST_ASSERT_EQUAL_INT(index, 6+2+2+2+2); - TEST_ASSERT_EQUAL_CHAR(buffer[14], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "Data: A1B2C3D4"); + ASSERT_TRUE(ok); + ASSERT_EQUAL_INT(index, 6+2+2+2+2); + ASSERT_EQUAL_CHAR(buffer[14], '\0'); + ASSERT_EQUAL_STRING(buffer, "Data: A1B2C3D4"); } MICROSTRAIN_TEST_CASE(C_string_formatting, Byte_formatting_fails_gracefully_when_buffer_too_small) @@ -358,8 +358,8 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, Byte_formatting_fails_gracefully_when const bool ok = microstrain_string_bytes_to_hex_str(buffer, 10, &index, data, sizeof(data), 0); - TEST_ASSERT_FALSE(ok); - TEST_ASSERT_EQUAL_INT(index, 6+2+2+2+2); - TEST_ASSERT_EQUAL_CHAR(buffer[6], '\0'); - TEST_ASSERT_EQUAL_STRING(buffer, "Data: "); + ASSERT_FALSE(ok); + ASSERT_EQUAL_INT(index, 6+2+2+2+2); + ASSERT_EQUAL_CHAR(buffer[6], '\0'); + ASSERT_EQUAL_STRING(buffer, "Data: "); } diff --git a/test/c/mip/test_mip_fields.c b/test/c/mip/test_mip_fields.c deleted file mode 100644 index df4a87a67..000000000 --- a/test/c/mip/test_mip_fields.c +++ /dev/null @@ -1,124 +0,0 @@ - -#include -#include - -#include -#include - - -uint8_t packet_buffer[MIP_PACKET_LENGTH_MAX]; -struct mip_packet_view packet; - -struct mip_field_view fields[MIP_PACKET_PAYLOAD_LENGTH_MAX / MIP_FIELD_LENGTH_MIN]; -unsigned int num_fields = 0; - - -bool add_random_field() -{ - const uint8_t length = rand() % 10; - const uint8_t field_desc = (rand() % 255) + 1; - - uint8_t* payload; - if( !mip_packet_create_field(&packet, field_desc, length, &payload) ) - return false; - - for(unsigned int i=0; i 10 ) - { - fprintf(stderr, "***\n_too many errors, aborting.\n"); - break; - } - } - - return num_errors; -} diff --git a/test/c/mip/test_mip_packet_builder.c b/test/c/mip/test_mip_packet_builder.c deleted file mode 100644 index db4b9f013..000000000 --- a/test/c/mip/test_mip_packet_builder.c +++ /dev/null @@ -1,117 +0,0 @@ - -#include "test.h" - -#include -#include - - -#include -#include -#include - -#define EXTRA 1 -uint8_t buffer[MIP_PACKET_LENGTH_MAX+EXTRA]; - - -void test_init() -{ - struct mip_packet_view packet; - mip_packet_from_buffer(&packet, buffer, sizeof(buffer)); - - check(packet._buffer == buffer && packet._buffer_length == sizeof(buffer)-EXTRA, "mip_packet_init is broken"); -} - -void test_create() -{ - struct mip_packet_view packet; - - uint8_t descriptors[] = {0x80, 0x01, 0x0C}; - - for(unsigned int i=0; i -#include -#include - -#include -#include -#include - - -struct mip_parser parser; - -unsigned int num_errors = 0; - -unsigned int num_packets_parsed = 0; -mip_timestamp parsed_packet_timestamp = 0; -size_t parsed_packet_length = 0; -uint8_t parsed_buffer[MIP_PACKET_LENGTH_MAX]; -mip_packet_view parsed_packet = { ._buffer=parsed_buffer, ._buffer_length=0, }; - - -void print_packet(FILE* out, const struct mip_packet_view* packet) -{ - size_t size = mip_packet_total_length(packet); - const uint8_t* ptr = mip_packet_pointer(packet); - - for(size_t i=0; i> 16) & 0xFF; -} - -int main(int argc, const char* argv[]) -{ - mip_parser_init(&parser, &handle_packet, NULL, MIP_PARSER_DEFAULT_TIMEOUT_MS); - - srand(0); - - mip_timestamp start_time = rand() % 500; - - const unsigned int NUM_ITERATIONS = 100*1000*1000; - - unsigned int last_parsed = 0; - - uint8_t buffer [MIP_PACKET_LENGTH_MAX]; - uint8_t prev_buffer[MIP_PACKET_LENGTH_MAX]; - mip_packet_view packet = { ._buffer=buffer, ._buffer_length=sizeof(buffer) }; - mip_packet_view prev_packet = { ._buffer=prev_buffer, ._buffer_length=sizeof(buffer) }; - - bool prev_timeout = false; - - unsigned int i; - for(i=0; i> (rand() % 8); - - const uint8_t field_desc = (rand() % 255) + 1; // Random field descriptor. - - uint8_t* payload; - int available = mip_packet_create_field(&packet, field_desc, paylen, &payload); - - if( available < 0 ) - { - num_errors++; - fprintf(stderr, "Failed to create field of length %u\n", paylen+MIP_FIELD_HEADER_LENGTH); - fprintf(stderr, " max_len=%zu, available=%u\n", max_field_len, available); - break; - } - - // Random payload. - for(unsigned int p=0; p 0 ) - timestamp += (rand() % mip_parser_timeout(&parser)); - } - - // Final chunk - const size_t extra = 0; - - const size_t count = packet_size - sent; - - if(PRINT_DEBUG) - printf(" send %zu @ time %zu\n", count, timestamp); - mip_parser_parse(&parser, mip_packet_pointer(&packet)+sent, count, timestamp); - - sent += count; - timestamps[c] = timestamp; - offsets[c++] = sent; - - bool timedout = (timestamps[c-1] - start_time) >= mip_parser_timeout(&parser); - - // If the previous packet timed out, there could be a nested header that also needs - // to time out. Ensure that it times out and that the parser gets to the new packet. - // This is similar to how real applications should behave; continually poll the parser - // for packets even if no new data arrives. - if(prev_timeout) - { - // Try to flush the parser repeatedly in case there were multiple nested packets - // which each need to time out separately. - for(unsigned int t=0; parser._buffered_length > packet_size && t < 5; t++) - { - timestamp += mip_parser_timeout(&parser); - - if(PRINT_DEBUG) - printf(" send 0 bytes @ time %zu (forced timeout).\n", timestamp); - - mip_parser_parse(&parser, NULL, 0, timestamp); - } - } - - if( timedout ) - { - if( num_packets_parsed != last_parsed ) - { - // Don't consider this a true error since the timeout handling can't be perfect. - // The parser must not miss valid packets, but catching delayed packets is OK. - // E.g. this data and timing results in receiving packet 9 because of a nested 75 65 in packet 8. - // Packet 8 (131 bytes): - // 75 65 25 7D 0D E4 04 F4 EC 0B B9 20 BA 86 C3 3E 05 70 65 33 B7 99 50 A3 E3 14 D3 D9 34 F7 5E A0 - // F2 10 A8 F6 05 94 01 BE B4 BC 44 78 FA 49 69 E6 23 D0 1A DA 69 6A 7E 4C 7E 51 25 B3 48 84 53 3A - // 94 FB 31 99 90 32 57 44 EE 9B BC E9 E5 25 CF 08 F5 E9 E2 5E 53 60 AA D2 B2 D0 85 FA 54 D8 35 E8 - // D4 66 82 64 98 D9 A8 87 75_65_70_5A 8A 3F 62 80 29 44 DE 7C A5 89 4E 57 59 D3 51 AD AC 86 95 80 - // EC 2E 35 ^^^^^^^^^^^ nested header (92-byte length) - // send 104 @ time 1275 - // send 18 @ time 1332 - // send 3 @ time 1368 - // send 6 @ time 1382 (times out outer packet, now inner "packet" in buffer with 21+6 bytes) - // Packet 9: - // 75 65 9D 58 58 72 BB 22 FC E4 66 DA 61 0B 63 AF 62 BC 83 B4 69 2F 3A FF AF 27 16 93 AC 07 1F B8 - // 6D 11 34 2D 8D EF 4F 89 D4 B6 63 35 C1 C7 E4 24 83 67 D8 ED 96 12 EC 45 39 02 D8 E5 0A F8 9D 77 - // 09 D1 A5 96 C1 F4 1F 95 AA 82 CA 6C 49 AE 90 CD 16 68 BA AC 7A A6 F2 B4 A8 CA 99 B2 59 2A - // send 39 @ time 1382 - // send 26 @ time 1452 - // send 25 @ time 1532 (nested packet fails, start_time now 1532) - // send 4 @ time 1625 (1625-1532 < timeout so packet is received) - - //num_errors++; - //error = true; // Uncomment to log details - //fprintf(stderr, "Note: Parser produced %u packet(s) but should have timed out.\n", num_packets_parsed-last_parsed); - } - } - else if( num_packets_parsed != (last_parsed + 1) ) - { - num_errors++; - error = true; - fprintf(stderr, "Parser produced %u packet(s) but expected exactly 1.\n", num_packets_parsed-last_parsed); - } - else if( parsed_packet_length != packet_size ) - { - num_errors++; - error = true; - fprintf(stderr, "Parsed packet size is wrong (%zu bytes should be %zu)\n", parsed_packet_length, packet_size); - } - else - { - if(!prev_timeout && parsed_packet_timestamp != start_time) - { - num_errors++; - error = true; - fprintf(stderr, "Parsed packet has wrong timestamp %zu.\n", parsed_packet_timestamp); - } - if(memcmp(parsed_buffer, packet._buffer, packet_size) != 0) - { - num_errors++; - error = true; - fprintf(stderr, "Parsed packet data doesn't match.\n"); - } - } - - start_time = timestamp; - - if( error ) - { - fprintf(stderr, " packet_size=%zu, last_count=%zu, extra=%zu, start_time=%zu\n", packet_size, count, extra, start_time); - - fprintf(stderr, " Sent chunks:"); - for(unsigned int d=0; d 10) - break; - else if((i+1) % 100000 == 0) - printf("Progress: %u/%u iterations.\n", i+1, NUM_ITERATIONS); - - last_parsed = num_packets_parsed; - prev_timeout = timedout; - - // Swap packets - uint8_t* tmp = prev_packet._buffer; - prev_packet._buffer = packet._buffer; - packet._buffer = tmp; - } - - printf("Completed %u/%u iterations with %u errors.\n", i, NUM_ITERATIONS, num_errors); - - return num_errors; -} diff --git a/test/cpp/mip.cpp b/test/cpp/mip.cpp deleted file mode 100644 index d006b75d0..000000000 --- a/test/cpp/mip.cpp +++ /dev/null @@ -1,113 +0,0 @@ - -#include - -#include -#include - -#include -#include - - -using namespace mip; -using namespace mip::C; - -uint8_t packetBuffer[MIP_PACKET_LENGTH_MAX]; -uint8_t parseBuffer[1024]; - -FieldView fields[(unsigned int)mip::PacketView::PAYLOAD_LENGTH_MAX / (unsigned int)mip::FieldView::LENGTH_MIN]; -unsigned int numFields = 0; - -unsigned int numErrors = 0; - -int main(int argc, const char* argv[]) -{ - srand(0); - - auto callback = [](void*, const PacketView* parsedPacket, Timestamp timestamp) - { - (void)timestamp; - - unsigned int parsedFields = 0; - bool error = false; - for(FieldView field : *parsedPacket) - { - if( field.descriptorSet() != fields[parsedFields].descriptorSet() ) - { - error = true; - fprintf(stderr, "Descriptor set does not match.\n"); - } - if( field.fieldDescriptor() != fields[parsedFields].fieldDescriptor() ) - { - error = true; - fprintf(stderr, "Field descriptor does not match.\n"); - } - if( field.payloadLength() != fields[parsedFields].payloadLength() ) - { - error = true; - fprintf(stderr, "Payload length does not match.\n"); - } - if( std::memcmp(field.payload(), fields[parsedFields].payload(), std::min(field.payloadLength(),fields[parsedFields].payloadLength())) != 0 ) - { - error = true; - fprintf(stderr, "Payloads do not match.\n"); - } - - if( error ) - { - numErrors++; - fprintf(stderr, " From field %d/%d\n", parsedFields, numFields); - fprintf(stderr, " Descriptor set: %02X/%02X\n", field.descriptorSet(), fields[parsedFields].descriptorSet()); - fprintf(stderr, " Field Descriptor: %02X/%02X\n", field.fieldDescriptor(), fields[parsedFields].fieldDescriptor()); - fprintf(stderr, " Payload Length: %02X/%02X\n", field.payloadLength(), fields[parsedFields].payloadLength()); - fputc('\n', stderr); - } - - parsedFields++; - } - if( parsedFields != numFields ) - { - numErrors++; - fprintf(stderr, "Field count mismatch: %d != %d\n", parsedFields, numFields); - } - }; - - Parser parser(callback, nullptr, MIP_PARSER_DEFAULT_TIMEOUT_MS); - - - const unsigned int NUM_ITERATIONS = 100; - - for(unsigned int i=0; i(rand() & 0xFF); - - if(!payload.isFinished()) - { - numErrors++; - fprintf(stderr, "Field %u did not have the right size (wrote %zu, expected %u, max %zu).\n", numFields, payload.offset(), payloadLength, payload.capacity()); - } - - fields[numFields] = FieldView(packet.descriptorSet(), fieldDescriptor, payload.basePointer(), payloadLength); - } - - packet.finalize(); - - parser.parse(packet.pointer(), packet.totalLength(), 0); - - if( numErrors > 10 ) - break; - } - - return numErrors; -} diff --git a/test/cpp/packet_interface.cpp b/test/cpp/packet_interface.cpp deleted file mode 100644 index e6a63cc91..000000000 --- a/test/cpp/packet_interface.cpp +++ /dev/null @@ -1,185 +0,0 @@ - -#include "test.h" - -#include -#include - -#include -#include -#include - -// A ping command -const uint8_t PING[] = { 0x75, 0x65, 0x01, 0x02, 0x02, 0x01, 0xE0, 0xC6 }; -// Sample data field -const mip::data_sensor::ScaledAccel ACCEL_FIELD = { {1.f, 2.f, -3.f} }; -const uint8_t ACCEL_PKT[] = { 0x75, 0x65, 0x80, 0x0e, 0x0e, 0x04, 0x3f, 0x80, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0xC0, 0x40, 0x00, 0x00, 0x79, 0xed }; -//const mip::data_shared::ReferenceTimestamp REFTIME = { 1'234'567'890 }; - -void print_packet(const mip::PacketView& packet) -{ - print_buffer(stderr, packet.pointer(), packet.packetLength()); -} - -bool checkPacketView(const mip::PacketView& packet, microstrain::ConstU8ArrayView compare, const char* method) -{ - bool ok = true; - - ok &= check(packet.isSane(), "Insane packet from %s", method); - ok &= check(packet.descriptorSet() == compare[mip::PacketView::Index::DESC_SET], "Wrong descriptor set from %s", method); - ok &= check(packet.payloadLength() == compare[mip::PacketView::Index::LENGTH], "Wrong payload length from %s", method); - ok &= check(packet.packetLength() == packet.payloadLength()+mip::PacketView::LENGTH_MIN, "Wrong total length from %s", method); - ok &= check_equal(packet.payloadPointer(), packet.pointer() + mip::PacketView::Index::PAYLOAD, "Wrong payload pointer from %s", method); - ok &= check(packet.pointer() != nullptr, "PacketRef shouldn't have NULL pointer from %s", method); - ok &= check_equal(packet.bytes().data(), packet.pointer(), "bytes().data() should match pointer()"); - ok &= check_equal(packet.bytes().size(), packet.packetLength(), "bytes().size() should match totalLength()"); - ok &= check_equal(packet.payloadBytes().data(), packet.payloadPointer(), "payload().data() should match payload()"); - ok &= check_equal(packet.payloadBytes().size(), packet.payloadLength(), "payload().size() should match payloadLength()"); - ok &= check_equal(packet.remainingSpace(), packet.bufferSize()-packet.packetLength(), "remainingSpace() is wrong"); - - if(std::memcmp(packet.pointer(), compare.data(), compare.size()) != 0) - { - fprintf(stderr, "Data mismatch from %s:\n", method); - print_packet(packet); - print_buffer(stderr, compare.data(), compare.size()); - ok = false; - } - - return ok; -} - -template -bool checkPacketBuf(mip::SizedPacketBuf& packet, microstrain::ConstU8ArrayView compare, const char* method) -{ - bool ok = checkPacketView(packet, compare, method); - - ok &= check(packet.bufferPointer() != nullptr, "NULL buffer from %s", method); - ok &= check_equal(packet.bufferSize(), Size, "bufferSize() should match templated size from %s", method); - ok &= check_equal(packet.pointer(), packet.bufferPointer(), "Packet buffer/pointer mismatch from %s", method); - ok &= check(packet.pointer() != compare.data(), "PacketBuf shouldn't point to original data buffer from %s", method); - ok &= check_equal(packet.buffer().data(), packet.bufferPointer(), ".buffer().data() doesn't match .bufferPointer()"); - ok &= check(packet.buffer().size() == Size, "buffer().size() doesn't match Size"); - - return ok; -} - -bool checkPingPacketView(const mip::PacketView& packet, const char* method) -{ - return checkPacketView(packet, PING, method); -} - -template -bool checkPingPacketBuf(mip::SizedPacketBuf& packet, const char* method) -{ - return checkPacketBuf(packet, PING, method); -} - - -void testPacketView() -{ - // - // Construction - // - - uint8_t buffer[mip::PACKET_LENGTH_MAX]; - - mip::PacketView packet1(buffer, sizeof(buffer), mip::commands_base::DESCRIPTOR_SET); - checkPacketView(packet1, buffer, "PacketView initializing constructor"); - check(packet1.isEmpty(), "Packet should be empty after packetView initializing constructor"); - check_equal(packet1.bufferSize(), sizeof(buffer), "Wrong buffer size from PacketView initializing constructor"); - check_equal(packet1.remainingSpace(), mip::PacketView::PAYLOAD_LENGTH_MAX, "remainingSpace wrong after PacketView initializing constructor"); - //bool ok = packet1.addField(mip::commands_base::Ping::FIELD_DESCRIPTOR, nullptr, 0); - //check(ok, "Failed to add field to packet1"); - //check_equal(packet1.remainingSpace(), mip::PacketView::PAYLOAD_LENGTH_MAX-2, "remainingSpace wrong after adding Ping command to packet1"); - //check_equal(packet1.bufferSize(), sizeof(buffer), "Wrong buffer size after adding Ping command to packet1"); - packet1.finalize(); - if(!check(packet1.isValid(), "Packet1 not valid after finalization")) - print_packet(packet1); - - mip::PacketView packet2(PING, sizeof(PING)); - checkPingPacketView(packet2, "PacketView existing constructor"); - - mip::C::mip_packet_view packet3c; - mip::C::mip_packet_from_buffer(&packet3c, PING, sizeof(PING)); - mip::PacketView packet3(packet3c); - checkPingPacketView(packet3, "PacketView C constructor"); - - mip::PacketView packet4(buffer, mip::commands_base::DESCRIPTOR_SET); - checkPacketView(packet4, buffer, "PacketView initializing constructor (U8ArrayView version)"); - - mip::PacketView packet5(PING); - checkPingPacketView(packet5, "PacketView existing constructor (U8ArrayView version)"); - - -} - -void testPacketBuf() -{ - // - // Construction - // - - // Default constructor - mip::PacketBuf packet1; - check( !mip::isValidDescriptorSet(packet1.descriptorSet()), "PacketBuf should default-construct to invalid descriptor set"); - - // Specify descriptor set - mip::PacketBuf packet2(mip::data_sensor::DESCRIPTOR_SET); - check( packet2.descriptorSet() == mip::data_sensor::DESCRIPTOR_SET, "PacketBuf constructor with descriptor set doesn't work"); - - // Construct from raw buffer, U8ArrayView, or existing view. - mip::PacketBuf packet3(PING, sizeof(PING)); - mip::PacketBuf packet4(PING); - mip::PacketBuf packet5((mip::PacketView(packet4))); - - checkPingPacketBuf(packet3, "PacketBuf raw buffer constructor"); - checkPingPacketBuf(packet4, "PacketBuf span constructor"); - checkPingPacketBuf(packet5, "PacketBuf PacketView constructor"); - - // Regular copy constructor - mip::PacketBuf packet6(packet5); - checkPingPacketBuf(packet6, "PacketBuf copy constructor"); - check(packet6.bufferPointer() != packet5.bufferPointer(), "Packet6 shouldn't point to packet5's data buffer from copy constructor"); - - // Construct from SizedPacketBuf of differing size - mip::SizedPacketBuf<8> packet7(packet5); - checkPingPacketView(packet7, "SizedPacketBuf<8> copy constructor"); - - // Construction from PacketView - mip::PacketBuf packet8(packet5.ref()); - checkPingPacketBuf(packet8, "PacketBuf copy constructor (PacketView)"); - check(packet8.bufferPointer() != packet5.bufferPointer(), "Packet6 shouldn't point to packet5's data buffer from copy constructor"); - - // Assignment - mip::PacketBuf packet9; - packet9 = packet5; - checkPingPacketBuf(packet9, "PacketBuf operator="); - check(packet9.bufferPointer() != packet5.bufferPointer(), "Packet9 shouldn't point to packet5's data buffer from operator="); - - // Create from field - mip::PacketBuf packet10(ACCEL_FIELD); - checkPacketBuf(packet10, ACCEL_PKT, "PacketBuf field constructor"); - - // .ref() already tested - // .buffer() already tested - // .bufferSpan() already tested - // .copyFrom tested by constructors - - // Test copying to destination - uint8_t tmp[sizeof(PING)]; - packet5.copyPacketTo(tmp); - check(std::memcmp(PING, tmp, sizeof(PING))==0, "Temporary buffer doesn't match after calling packet.copyPacketTo"); - - std::memset(tmp, 0x00, sizeof(tmp)); - packet5.copyPacketTo({tmp, sizeof(tmp)}); - check(std::memcmp(PING, tmp, sizeof(PING))==0, "Temporary buffer doesn't match after calling packet.copyPacketTo (span version)"); - -} - - -int main() -{ - testPacketView(); - testPacketBuf(); - - return num_errors; -} From 10e44bc794a941b143b14266d1c639cfeaeeb7ef Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Fri, 24 Oct 2025 16:18:40 -0400 Subject: [PATCH 7/9] Added C++ precursor to all C++ test suites --- test/cpp/logging.unit.cpp | 6 +++--- test/cpp/mip.integration.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/cpp/logging.unit.cpp b/test/cpp/logging.unit.cpp index 02756b64f..40cb5bba5 100644 --- a/test/cpp/logging.unit.cpp +++ b/test/cpp/logging.unit.cpp @@ -8,7 +8,7 @@ constexpr uint8_t SET_AND_SAVE_COMM_SPEED_PACKET[] = { 0xCE, 0x80 }; -MICROSTRAIN_TEST_CASE("Formatting", "A packet can be properly formatted to bytes") +MICROSTRAIN_TEST_CASE("C++ Formatting", "A packet can be properly formatted to bytes") { char buffer[128]; size_t index = 0; @@ -20,7 +20,7 @@ MICROSTRAIN_TEST_CASE("Formatting", "A packet can be properly formatted to bytes CHECK_CSTR_EQ(buffer, "7565010C 080901010001C200 04090301 CE80"); } -MICROSTRAIN_TEST_CASE("Formatting", "A packet can be properly formatted to a human-readable string") +MICROSTRAIN_TEST_CASE("C++ Formatting", "A packet can be properly formatted to a human-readable string") { char buffer[128]; size_t index = 0; @@ -32,7 +32,7 @@ MICROSTRAIN_TEST_CASE("Formatting", "A packet can be properly formatted to a hum CHECK_CSTR_EQ(buffer, "Packet(DS=0x01){ Field(FD=0x09)[01010001C200] Field(FD=0x09)[0301] }"); } -MICROSTRAIN_TEST_CASE("Formatting", "A field can be properly formatted to a human-readable string") +MICROSTRAIN_TEST_CASE("C++ Formatting", "A field can be properly formatted to a human-readable string") { char buffer[128]; size_t index = 0; diff --git a/test/cpp/mip.integration.cpp b/test/cpp/mip.integration.cpp index 92bb9875c..6cae5dfdc 100644 --- a/test/cpp/mip.integration.cpp +++ b/test/cpp/mip.integration.cpp @@ -54,7 +54,7 @@ bool packetCallback(void*, const PacketView *parsedPacket, Timestamp timestamp) return true; } -MICROSTRAIN_TEST_CASE("Packet Builder", "Packets can be built and parsed correctly") +MICROSTRAIN_TEST_CASE("C++ Packet Builder", "Packets can be built and parsed correctly") { std::random_device random_device; std::mt19937 random_generator(random_device()); From fa8e69fd8f68dede15684fa267bab3b318e5258a Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Fri, 24 Oct 2025 16:23:42 -0400 Subject: [PATCH 8/9] Update changelog --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2726d23c..40960d4ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,6 @@ REMOVED - A function/class has been removed. Forthcoming ----------- ### New Features -* Added MicrostrainTest test wrapper framework ### Interface Changes ### Bug Fixes From cc8605962b52e88af3bd86d3cc9d0e623bc7feac Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Mon, 27 Oct 2025 11:44:38 -0400 Subject: [PATCH 9/9] Updated MicrostrainTest version --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 49e7dfc6f..e2a5455ea 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,7 +9,7 @@ set(MICROSTRAIN_TEST_FRAMEWORK_CPP "doctest" CACHE STRING "" FORCE) FetchContent_Declare(microstrain_test GIT_REPOSITORY https://github.com/LORD-MicroStrain/microstrain_test.git - GIT_TAG v0.2.6 + GIT_TAG v0.2.7 ) FetchContent_MakeAvailable(microstrain_test)