From 489fcbdd7e6b1776ce57a24ae77794e89c8ef63a Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Sat, 2 Nov 2024 10:11:31 -0500 Subject: [PATCH 01/40] bump patch version --- README.md | 2 +- meson.build | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6ccfc250..902506f4 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Before getting started, make sure you have the following installed: # ====================== [wrap-git] url = https://github.com/fossillogic/fossil-test.git - revision = v1.0.6 + revision = v1.0.7 [provide] fossil-test = fossil_test_dep diff --git a/meson.build b/meson.build index 66f836ec..711e856a 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,7 @@ project('Fossil Test', 'c', 'cpp', meson_version: '>=1.3.0', license: 'MPL-2.0', - version: '1.0.6', + version: '1.0.7', default_options: ['c_std=c18', 'cpp_std=c++20']) subdir('code') From b8cb54f6c1c624752aa5996a04d6c950e62e4288 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Sat, 2 Nov 2024 12:08:30 -0500 Subject: [PATCH 02/40] strip away old source --- code/logic/fossil/unittest/assert.h | 868 ------------------------- code/logic/fossil/unittest/commands.h | 60 -- code/logic/fossil/unittest/console.h | 52 -- code/logic/fossil/unittest/expect.h | 868 ------------------------- code/logic/fossil/unittest/framework.h | 61 +- code/logic/fossil/unittest/internal.h | 251 ------- code/logic/unittest/old-unittest.c | 749 +++++++++++++++++++++ 7 files changed, 751 insertions(+), 2158 deletions(-) delete mode 100644 code/logic/fossil/unittest/assert.h delete mode 100644 code/logic/fossil/unittest/commands.h delete mode 100644 code/logic/fossil/unittest/console.h delete mode 100644 code/logic/fossil/unittest/expect.h delete mode 100644 code/logic/fossil/unittest/internal.h create mode 100644 code/logic/unittest/old-unittest.c diff --git a/code/logic/fossil/unittest/assert.h b/code/logic/fossil/unittest/assert.h deleted file mode 100644 index 1b0e67db..00000000 --- a/code/logic/fossil/unittest/assert.h +++ /dev/null @@ -1,868 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#ifndef FOSSIL_TEST_ASSERT_TYPE_H -#define FOSSIL_TEST_ASSERT_TYPE_H - -#include // using assurt rules from Fossil Test - -#include -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// ************************************************** -// -// Boolean assertions -// -// ************************************************** - -// Boolean ITS assertions -#define ASSERT_ITS_TRUE(actual) \ - TEST_ASSERT((actual), "Expected " #actual " to be true") - -#define ASSERT_ITS_FALSE(actual) \ - TEST_ASSERT(!(actual), "Expected " #actual " to be false") - -// Boolean NOT assertions -#define ASSERT_NOT_TRUE(actual) \ - TEST_ASSERT(!(actual), "Expected " #actual " to not be true") - -#define ASSERT_NOT_FALSE(actual) \ - TEST_ASSERT((actual), "Expected " #actual " to not be false") - -// ************************************************** -// -// Floating point assertions -// -// ************************************************** - -// Double equality check with tolerance -#define ASSERT_ITS_EQUAL_F64(actual, expected, tol) \ - TEST_ASSERT(fabs((actual) - (expected)) <= (tol), "Expected " #actual " to be equal to " #expected " within tolerance " #tol) - -#define ASSERT_ITS_LESS_THAN_F64(actual, expected) \ - TEST_ASSERT((actual) < (expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_F64(actual, expected) \ - TEST_ASSERT((actual) > (expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_F64(actual, expected) \ - TEST_ASSERT((actual) <= (expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_F64(actual, expected) \ - TEST_ASSERT((actual) >= (expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_F64(actual, expected, tol) \ - TEST_ASSERT(fabs((actual) - (expected)) > (tol), "Expected " #actual " to not be equal to " #expected " within tolerance " #tol) - -#define ASSERT_NOT_LESS_THAN_F64(actual, expected) \ - TEST_ASSERT((actual) >= (expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_F64(actual, expected) \ - TEST_ASSERT((actual) <= (expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_F64(actual, expected) \ - TEST_ASSERT((actual) > (expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_F64(actual, expected) \ - TEST_ASSERT((actual) < (expected), "Expected " #actual " to not be more than or equal to " #expected) - -// Float equality check with tolerance -#define ASSERT_ITS_EQUAL_F32(actual, expected, tol) \ - TEST_ASSERT(fabsf((actual) - (expected)) <= (tol), "Expected " #actual " to be equal to " #expected " within tolerance " #tol) - -#define ASSERT_ITS_LESS_THAN_F32(actual, expected) \ - TEST_ASSERT((actual) < (expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_F32(actual, expected) \ - TEST_ASSERT((actual) > (expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_F32(actual, expected) \ - TEST_ASSERT((actual) <= (expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_F32(actual, expected) \ - TEST_ASSERT((actual) >= (expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_F32(actual, expected, tol) \ - TEST_ASSERT(fabsf((actual) - (expected)) > (tol), "Expected " #actual " to not be equal to " #expected " within tolerance " #tol) - -#define ASSERT_NOT_LESS_THAN_F32(actual, expected) \ - TEST_ASSERT((actual) >= (expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_F32(actual, expected) \ - TEST_ASSERT((actual) <= (expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_F32(actual, expected) \ - TEST_ASSERT((actual) > (expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_F32(actual, expected) \ - TEST_ASSERT((actual) < (expected), "Expected " #actual " to not be more than or equal to " #expected) - -// Float NaN and Infinity checks -#define ASSERT_ITS_NAN_F32(actual) \ - TEST_ASSERT(isnan(actual), "Expected " #actual " to be NaN") - -#define ASSERT_ITS_INF_F32(actual) \ - TEST_ASSERT(isinf(actual), "Expected " #actual " to be infinity") - -// Double NaN and Infinity checks -#define ASSERT_ITS_NAN_F64(actual) \ - TEST_ASSERT(isnan(actual), "Expected " #actual " to be NaN") - -#define ASSERT_ITS_INF_F64(actual) \ - TEST_ASSERT(isinf(actual), "Expected " #actual " to be infinity") - -// ************************************************** -// -// Numaric assertions -// -// ************************************************** - -// Octal assertions - -// O8 Assertions -#define ASSERT_ITS_EQUAL_O8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) == (uint8_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_O8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_O8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_O8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_O8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_O8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) != (uint8_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_O8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_O8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_O8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_O8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// O16 Assertions -#define ASSERT_ITS_EQUAL_O16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) == (uint16_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_O16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_O16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_O16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_O16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_O16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) != (uint16_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_O16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_O16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_O16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_O16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// O32 Assertions -#define ASSERT_ITS_EQUAL_O32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) == (uint32_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_O32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_O32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_O32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_O32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_O32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) != (uint32_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_O32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_O32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_O32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_O32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// OI64 Assertions -#define ASSERT_ITS_EQUAL_O64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) == (uint64_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_O64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_O64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_O64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_O64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_O64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) != (uint64_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_O64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_O64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_O64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_O64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// Hexadecimal assertions - -// H8 Assertions -#define ASSERT_ITS_EQUAL_H8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) == (uint8_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_H8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_H8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_H8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_H8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_H8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) != (uint8_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_H8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_H8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_H8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_H8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// H16 Assertions -#define ASSERT_ITS_EQUAL_H16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) == (uint16_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_H16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_H16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_H16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_H16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_H16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) != (uint16_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_H16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_H16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_H16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_H16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// H32 Assertions -#define ASSERT_ITS_EQUAL_H32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) == (uint32_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_H32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_H32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_H32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_H32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_H32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) != (uint32_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_H32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_H32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_H32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_H32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// H64 Assertions -#define ASSERT_ITS_EQUAL_H64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) == (uint64_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_H64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_H64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_H64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_H64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_H64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) != (uint64_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_H64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_H64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_H64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_H64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// I8 Assertions -#define ASSERT_ITS_EQUAL_I8(actual, expected) \ - TEST_ASSERT((int8_t)(actual) == (int8_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_I8(actual, expected) \ - TEST_ASSERT((int8_t)(actual) < (int8_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_I8(actual, expected) \ - TEST_ASSERT((int8_t)(actual) > (int8_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_I8(actual, expected) \ - TEST_ASSERT((int8_t)(actual) <= (int8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_I8(actual, expected) \ - TEST_ASSERT((int8_t)(actual) >= (int8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_I8(actual, expected) \ - TEST_ASSERT((int8_t)(actual) != (int8_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_I8(actual, expected) \ - TEST_ASSERT((int8_t)(actual) >= (int8_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_I8(actual, expected) \ - TEST_ASSERT((int8_t)(actual) <= (int8_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_I8(actual, expected) \ - TEST_ASSERT((int8_t)(actual) > (int8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_I8(actual, expected) \ - TEST_ASSERT((int8_t)(actual) < (int8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// I16 Assertions -#define ASSERT_ITS_EQUAL_I16(actual, expected) \ - TEST_ASSERT((int16_t)(actual) == (int16_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_I16(actual, expected) \ - TEST_ASSERT((int16_t)(actual) < (int16_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_I16(actual, expected) \ - TEST_ASSERT((int16_t)(actual) > (int16_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_I16(actual, expected) \ - TEST_ASSERT((int16_t)(actual) <= (int16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_I16(actual, expected) \ - TEST_ASSERT((int16_t)(actual) >= (int16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_I16(actual, expected) \ - TEST_ASSERT((int16_t)(actual) != (int16_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_I16(actual, expected) \ - TEST_ASSERT((int16_t)(actual) >= (int16_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_I16(actual, expected) \ - TEST_ASSERT((int16_t)(actual) <= (int16_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_I16(actual, expected) \ - TEST_ASSERT((int16_t)(actual) > (int16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_I16(actual, expected) \ - TEST_ASSERT((int16_t)(actual) < (int16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// I32 Assertions -#define ASSERT_ITS_EQUAL_I32(actual, expected) \ - TEST_ASSERT((int32_t)(actual) == (int32_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_I32(actual, expected) \ - TEST_ASSERT((int32_t)(actual) < (int32_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_I32(actual, expected) \ - TEST_ASSERT((int32_t)(actual) > (int32_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_I32(actual, expected) \ - TEST_ASSERT((int32_t)(actual) <= (int32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_I32(actual, expected) \ - TEST_ASSERT((int32_t)(actual) >= (int32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_I32(actual, expected) \ - TEST_ASSERT((int32_t)(actual) != (int32_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_I32(actual, expected) \ - TEST_ASSERT((int32_t)(actual) >= (int32_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_I32(actual, expected) \ - TEST_ASSERT((int32_t)(actual) <= (int32_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_I32(actual, expected) \ - TEST_ASSERT((int32_t)(actual) > (int32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_I32(actual, expected) \ - TEST_ASSERT((int32_t)(actual) < (int32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// I64 Assertions -#define ASSERT_ITS_EQUAL_I64(actual, expected) \ - TEST_ASSERT((int64_t)(actual) == (int64_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_I64(actual, expected) \ - TEST_ASSERT((int64_t)(actual) < (int64_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_I64(actual, expected) \ - TEST_ASSERT((int64_t)(actual) > (int64_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_I64(actual, expected) \ - TEST_ASSERT((int64_t)(actual) <= (int64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_I64(actual, expected) \ - TEST_ASSERT((int64_t)(actual) >= (int64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_I64(actual, expected) \ - TEST_ASSERT((int64_t)(actual) != (int64_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_I64(actual, expected) \ - TEST_ASSERT((int64_t)(actual) >= (int64_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_I64(actual, expected) \ - TEST_ASSERT((int64_t)(actual) <= (int64_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_I64(actual, expected) \ - TEST_ASSERT((int64_t)(actual) > (int64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_I64(actual, expected) \ - TEST_ASSERT((int64_t)(actual) < (int64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// U8 Assertions -#define ASSERT_ITS_EQUAL_U8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) == (uint8_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_U8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_U8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_U8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_U8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_U8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) != (uint8_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_U8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_U8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_U8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_U8(actual, expected) \ - TEST_ASSERT((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// U16 Assertions -#define ASSERT_ITS_EQUAL_U16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) == (uint16_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_U16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_U16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_U16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_U16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_U16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) != (uint16_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_U16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_U16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_U16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_U16(actual, expected) \ - TEST_ASSERT((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// U32 Assertions -#define ASSERT_ITS_EQUAL_U32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) == (uint32_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_U32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_U32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_U32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_U32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_U32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) != (uint32_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_U32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_U32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_U32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_U32(actual, expected) \ - TEST_ASSERT((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// U64 Assertions -#define ASSERT_ITS_EQUAL_U64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) == (uint64_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSERT_ITS_LESS_THAN_U64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSERT_ITS_MORE_THAN_U64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSERT_ITS_LESS_OR_EQUAL_U64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSERT_ITS_MORE_OR_EQUAL_U64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSERT_NOT_EQUAL_U64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) != (uint64_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSERT_NOT_LESS_THAN_U64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSERT_NOT_MORE_THAN_U64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSERT_NOT_LESS_OR_EQUAL_U64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSERT_NOT_MORE_OR_EQUAL_U64(actual, expected) \ - TEST_ASSERT((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// ************************************************** -// -// Null pointer assertions (_CNULL) -// -// ************************************************** - -// ITS set -#define ASSERT_ITS_CNULL(actual) \ - TEST_ASSERT((actual) == xnull, "Expected " #actual " to be xnull") - -#define ASSERT_NOT_CNULL(actual) \ - TEST_ASSERT((actual) != xnull, "Expected " #actual " to not be xnull") - -// General pointer assertions (_PTR) - -// ITS set -#define ASSERT_ITS_EQUAL_PTR(actual, expected) \ - TEST_ASSERT((actual) == (expected), "Expected pointer " #actual " to be equal to pointer " #expected " ") - -#define ASSERT_NOT_EQUAL_PTR(actual, expected) \ - TEST_ASSERT((actual) != (expected), "Expected pointer " #actual " to not be equal to pointer " #expected " ") - -// Size_t assertions - -// Equal -#define ASSERT_ITS_EQUAL_SIZE(actual, expected) \ - TEST_ASSERT((size_t)(actual) == (size_t)(expected), "Expected " #actual " to be equal to " #expected) - -// Less than -#define ASSERT_ITS_LESS_THAN_SIZE(actual, expected) \ - TEST_ASSERT((size_t)(actual) < (size_t)(expected), "Expected " #actual " to be less than " #expected) - -// More than -#define ASSERT_ITS_MORE_THAN_SIZE(actual, expected) \ - TEST_ASSERT((size_t)(actual) > (size_t)(expected), "Expected " #actual " to be more than " #expected) - -// Less or equal -#define ASSERT_ITS_LESS_OR_EQUAL_SIZE(actual, expected) \ - TEST_ASSERT((size_t)(actual) <= (size_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -// More or equal -#define ASSERT_ITS_MORE_OR_EQUAL_SIZE(actual, expected) \ - TEST_ASSERT((size_t)(actual) >= (size_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -// Not equal -#define ASSERT_NOT_EQUAL_SIZE(actual, expected) \ - TEST_ASSERT((size_t)(actual) != (size_t)(expected), "Expected " #actual " to not be equal to " #expected) - -// ************************************************** -// -// Range assertions -// -// ************************************************** - -// Assertion for checking if a value is within a specified range -#define ASSERT_ITS_WITHIN_RANGE(value, min, max) \ - TEST_ASSERT((value) >= (min) && (value) <= (max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSERT_NOT_WITHIN_RANGE(value, min, max) \ - TEST_ASSERT((value) < (min) || (value) > (max), "Value " #value " is within range [" #min ", " #max "]") - -// Unsigned integer type assertions - -#define ASSERT_ITS_WITHIN_RANGE_U8(value, min, max) \ - TEST_ASSERT((uint8_t)(value) >= (uint8_t)(min) && (uint8_t)(value) <= (uint8_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSERT_NOT_WITHIN_RANGE_U8(value, min, max) \ - TEST_ASSERT((uint8_t)(value) < (uint8_t)(min) || (uint8_t)(value) > (uint8_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define ASSERT_ITS_WITHIN_RANGE_U16(value, min, max) \ - TEST_ASSERT((uint16_t)(value) >= (uint16_t)(min) && (uint16_t)(value) <= (uint16_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSERT_NOT_WITHIN_RANGE_U16(value, min, max) \ - TEST_ASSERT((uint16_t)(value) < (uint16_t)(min) || (uint16_t)(value) > (uint16_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define ASSERT_ITS_WITHIN_RANGE_U32(value, min, max) \ - TEST_ASSERT((uint32_t)(value) >= (uint32_t)(min) && (uint32_t)(value) <= (uint32_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSERT_NOT_WITHIN_RANGE_U32(value, min, max) \ - TEST_ASSERT((uint32_t)(value) < (uint32_t)(min) || (uint32_t)(value) > (uint32_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define ASSERT_ITS_WITHIN_RANGE_U64(value, min, max) \ - TEST_ASSERT((uint64_t)(value) >= (uint64_t)(min) && (uint64_t)(value) <= (uint64_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSERT_NOT_WITHIN_RANGE_U64(value, min, max) \ - TEST_ASSERT((uint64_t)(value) < (uint64_t)(min) || (uint64_t)(value) > (uint64_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -// Signed integer type assertions - -#define ASSERT_ITS_WITHIN_RANGE_I8(value, min, max) \ - TEST_ASSERT((int8_t)(value) >= (int8_t)(min) && (int8_t)(value) <= (int8_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSERT_NOT_WITHIN_RANGE_I8(value, min, max) \ - TEST_ASSERT((int8_t)(value) < (int8_t)(min) || (int8_t)(value) > (int8_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define ASSERT_ITS_WITHIN_RANGE_I16(value, min, max) \ - TEST_ASSERT((int16_t)(value) >= (int16_t)(min) && (int16_t)(value) <= (int16_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSERT_NOT_WITHIN_RANGE_I16(value, min, max) \ - TEST_ASSERT((int16_t)(value) < (int16_t)(min) || (int16_t)(value) > (int16_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define ASSERT_ITS_WITHIN_RANGE_I32(value, min, max) \ - TEST_ASSERT((int32_t)(value) >= (int32_t)(min) && (int32_t)(value) <= (int32_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSERT_NOT_WITHIN_RANGE_I32(value, min, max) \ - TEST_ASSERT((int32_t)(value) < (int32_t)(min) || (int32_t)(value) > (int32_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define ASSERT_ITS_WITHIN_RANGE_I64(value, min, max) \ - TEST_ASSERT((int64_t)(value) >= (int64_t)(min) && (int64_t)(value) <= (int64_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSERT_NOT_WITHIN_RANGE_I64(value, min, max) \ - TEST_ASSERT((int64_t)(value) < (int64_t)(min) || (int64_t)(value) > (int64_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -// Floating point type assertions - -#define ASSERT_ITS_WITHIN_RANGE_F32(value, min, max) \ - TEST_ASSERT((value) >= (min) && (value) <= (max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSERT_NOT_WITHIN_RANGE_F32(value, min, max) \ - TEST_ASSERT((value) < (min) || (value) > (max), "Value " #value " is within range [" #min ", " #max "]") - -#define ASSERT_ITS_WITHIN_RANGE_F64(value, min, max) \ - TEST_ASSERT((value) >= (min) && (value) <= (max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSERT_NOT_WITHIN_RANGE_F64(value, min, max) \ - TEST_ASSERT((value) < (min) || (value) > (max), "Value " #value " is within range [" #min ", " #max "]") - -// Byte char type assertions (uint8_t) - -#define ASSERT_ITS_WITHIN_RANGE_BCHAR(value, min, max) \ - TEST_ASSERT((uint8_t)(value) >= (uint8_t)(min) && (uint8_t)(value) <= (uint8_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSERT_NOT_WITHIN_RANGE_BCHAR(value, min, max) \ - TEST_ASSERT((uint8_t)(value) < (uint8_t)(min) || (uint8_t)(value) > (uint8_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -// Char type assertions (char) - -#define ASSERT_ITS_WITHIN_RANGE_CCHAR(value, min, max) \ - TEST_ASSERT((char)(value) >= (char)(min) && (char)(value) <= (char)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSERT_NOT_WITHIN_RANGE_CCHAR(value, min, max) \ - TEST_ASSERT((char)(value) < (char)(min) || (char)(value) > (char)(max), "Value " #value " is within range [" #min ", " #max "]") - -// Wide char type assertions (wchar_t) - -#define ASSERT_ITS_WITHIN_RANGE_WCHAR(value, min, max) \ - TEST_ASSERT((wchar_t)(value) >= (wchar_t)(min) && (wchar_t)(value) <= (wchar_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSERT_NOT_WITHIN_RANGE_WCHAR(value, min, max) \ - TEST_ASSERT((wchar_t)(value) < (wchar_t)(min) || (wchar_t)(value) > (wchar_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -// ************************************************** -// -// String assertions -// -// ************************************************** - -// Wide char string equality check -#define ASSERT_ITS_EQUAL_WSTR(actual, expected) \ - TEST_ASSERT(wcscmp((actual), (expected)) == 0, "Expected wide string " #actual " to be equal to " #expected) - -#define ASSERT_NOT_EQUAL_WSTR(actual, expected) \ - TEST_ASSERT(wcscmp((actual), (expected)) != 0, "Expected wide string " #actual " to not be equal to " #expected) - -// For length comparison -#define ASSERT_ITS_LENGTH_EQUAL_WSTR(actual, expected_len) \ - TEST_ASSERT(wcslen((actual)) == (expected_len), "Expected length of wide string " #actual " to be equal to " #expected_len) - -// Byte string equality check -#define ASSERT_ITS_EQUAL_BSTR(actual, expected) \ - TEST_ASSERT(strcmp((const char*)(actual), (const char*)(expected)) == 0, "Expected byte string " #actual " to be equal to " #expected) - -#define ASSERT_NOT_EQUAL_BSTR(actual, expected) \ - TEST_ASSERT(strcmp((const char*)(actual), (const char*)(expected)) != 0, "Expected byte string " #actual " to not be equal to " #expected) - -// For length comparison -#define ASSERT_ITS_LENGTH_EQUAL_BSTR(actual, expected_len) \ - TEST_ASSERT(strlen((const char*)(actual)) == (expected_len), "Expected length of byte string " #actual " to be equal to " #expected_len) - -// Classic C string equality check -#define ASSERT_ITS_EQUAL_CSTR(actual, expected) \ - TEST_ASSERT(strcmp((actual), (expected)) == 0, "Expected C string " #actual " to be equal to " #expected) - -#define ASSERT_NOT_EQUAL_CSTR(actual, expected) \ - TEST_ASSERT(strcmp((actual), (expected)) != 0, "Expected C string " #actual " to not be equal to " #expected) - -// For length comparison -#define ASSERT_ITS_LENGTH_EQUAL_CSTR(actual, expected_len) \ - TEST_ASSERT(strlen((actual)) == (expected_len), "Expected length of C string " #actual " to be equal to " #expected_len) - -// ************************************************** -// -// Array assertions -// -// ************************************************** - -// Array equality check -#define ASSERT_ITS_EQUAL_ARRAY(actual, expected, length) \ - for (size_t i = 0; i < (length); i++) { \ - TEST_ASSERT((actual)[i] == (expected)[i], "Expected array element " #actual " to be equal to " #expected); \ - } - -// Array inequality check -#define ASSERT_NOT_EQUAL_ARRAY(actual, expected, length) \ - for (size_t i = 0; i < (length); i++) { \ - TEST_ASSERT((actual)[i] != (expected)[i], "Expected array element " #actual " to not be equal to " #expected); \ - } - -// Array length check -#define ASSERT_ITS_LENGTH_EQUAL_ARRAY(actual_length, expected_length) \ - TEST_ASSERT((actual_length) == (expected_length), "Expected array length " #actual_length " to be equal to " #expected_length) - -// Array element within range check -#define ASSERT_ITS_WITHIN_RANGE_ARRAY(array, min, max, length) \ - for (size_t i = 0; i < (length); i++) { \ - TEST_ASSERT((array)[i] >= (min) && (array)[i] <= (max), "Expected array element " #array " to be within range [" #min ", " #max "]"); \ - } - -// Array element not within range check -#define ASSERT_NOT_WITHIN_RANGE_ARRAY(array, min, max, length) \ - for (size_t i = 0; i < (length); i++) { \ - TEST_ASSERT((array)[i] < (min) || (array)[i] > (max), "Expected array element " #array " to not be within range [" #min ", " #max "]"); \ - } - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/code/logic/fossil/unittest/commands.h b/code/logic/fossil/unittest/commands.h deleted file mode 100644 index c4a5d828..00000000 --- a/code/logic/fossil/unittest/commands.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#ifndef FOSSIL_TEST_COMMANDS_H -#define FOSSIL_TEST_COMMANDS_H - -#include "fossil/_common/common.h" -#include "internal.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -// Define the structure to hold parsed options -typedef struct { - bool show_version; - bool show_help; - bool show_tip; - bool show_info; - bool show_author; - bool only_tags; - char only_tags_value[256]; - bool reverse; - bool repeat_enabled; - int repeat_count; - bool shuffle_enabled; - bool verbose_enabled; - int verbose_level; // 0 for cutback, 1 for normal, 2 for verbose - bool list_tests; - bool summary_enabled; - bool color_enabled; - bool sanity_enabled; -} fossil_options_t; - -extern fossil_options_t _CLI; - -/** - * Function to initialize the options structure. - * - * @return The options structure - */ -fossil_options_t fossil_options_parse(int argc, char **argv); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/code/logic/fossil/unittest/console.h b/code/logic/fossil/unittest/console.h deleted file mode 100644 index 1fdd630a..00000000 --- a/code/logic/fossil/unittest/console.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#ifndef FOSSIL_TEST_CONSOLE_H -#define FOSSIL_TEST_CONSOLE_H - -#include "fossil/_common/common.h" -#include "internal.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -/** - * Function to print a message to the console with a specific color. - * - * @param color_name The name of the color - * @param format The format string - * @param ... The arguments to format - */ -void fossil_test_cout(const char* color_name, const char* format, ...); - -void fossil_test_io_information(void); -void fossil_test_io_sanity_load(fossil_test_t *test); -void fossil_test_io_unittest_given(char *description); -void fossil_test_io_unittest_when(char *description); -void fossil_test_io_unittest_then(char *description); - -void fossil_test_io_unittest_start(fossil_test_t *test); -void fossil_test_io_unittest_step(xassert_info *assume); -void fossil_test_io_unittest_ended(fossil_test_t *test); -void fossil_test_io_asserted(xassert_info *assume); -void fossil_test_io_summary_start(void); -void fossil_test_io_summary_ended(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/code/logic/fossil/unittest/expect.h b/code/logic/fossil/unittest/expect.h deleted file mode 100644 index baee353b..00000000 --- a/code/logic/fossil/unittest/expect.h +++ /dev/null @@ -1,868 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#ifndef FOSSIL_TEST_EXPECT_TYPE_H -#define FOSSIL_TEST_EXPECT_TYPE_H - -#include // using assurt rules from Fossil Test - -#include -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// ************************************************** -// -// Boolean EXPECTions -// -// ************************************************** - -// Boolean ITS EXPECTions -#define EXPECT_ITS_TRUE(actual) \ - TEST_EXPECT((actual), "Expected " #actual " to be true") - -#define EXPECT_ITS_FALSE(actual) \ - TEST_EXPECT(!(actual), "Expected " #actual " to be false") - -// Boolean NOT EXPECTions -#define EXPECT_NOT_TRUE(actual) \ - TEST_EXPECT(!(actual), "Expected " #actual " to not be true") - -#define EXPECT_NOT_FALSE(actual) \ - TEST_EXPECT((actual), "Expected " #actual " to not be false") - -// ************************************************** -// -// Floating point EXPECTions -// -// ************************************************** - -// Double equality check with tolerance -#define EXPECT_ITS_EQUAL_F64(actual, expected, tol) \ - TEST_EXPECT(fabs((actual) - (expected)) <= (tol), "Expected " #actual " to be equal to " #expected " within tolerance " #tol) - -#define EXPECT_ITS_LESS_THAN_F64(actual, expected) \ - TEST_EXPECT((actual) < (expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_F64(actual, expected) \ - TEST_EXPECT((actual) > (expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_F64(actual, expected) \ - TEST_EXPECT((actual) <= (expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_F64(actual, expected) \ - TEST_EXPECT((actual) >= (expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_F64(actual, expected, tol) \ - TEST_EXPECT(fabs((actual) - (expected)) > (tol), "Expected " #actual " to not be equal to " #expected " within tolerance " #tol) - -#define EXPECT_NOT_LESS_THAN_F64(actual, expected) \ - TEST_EXPECT((actual) >= (expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_F64(actual, expected) \ - TEST_EXPECT((actual) <= (expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_F64(actual, expected) \ - TEST_EXPECT((actual) > (expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_F64(actual, expected) \ - TEST_EXPECT((actual) < (expected), "Expected " #actual " to not be more than or equal to " #expected) - -// Float equality check with tolerance -#define EXPECT_ITS_EQUAL_F32(actual, expected, tol) \ - TEST_EXPECT(fabsf((actual) - (expected)) <= (tol), "Expected " #actual " to be equal to " #expected " within tolerance " #tol) - -#define EXPECT_ITS_LESS_THAN_F32(actual, expected) \ - TEST_EXPECT((actual) < (expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_F32(actual, expected) \ - TEST_EXPECT((actual) > (expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_F32(actual, expected) \ - TEST_EXPECT((actual) <= (expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_F32(actual, expected) \ - TEST_EXPECT((actual) >= (expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_F32(actual, expected, tol) \ - TEST_EXPECT(fabsf((actual) - (expected)) > (tol), "Expected " #actual " to not be equal to " #expected " within tolerance " #tol) - -#define EXPECT_NOT_LESS_THAN_F32(actual, expected) \ - TEST_EXPECT((actual) >= (expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_F32(actual, expected) \ - TEST_EXPECT((actual) <= (expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_F32(actual, expected) \ - TEST_EXPECT((actual) > (expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_F32(actual, expected) \ - TEST_EXPECT((actual) < (expected), "Expected " #actual " to not be more than or equal to " #expected) - -// Float NaN and Infinity checks -#define EXPECT_ITS_NAN_F32(actual) \ - TEST_EXPECT(isnan(actual), "Expected " #actual " to be NaN") - -#define EXPECT_ITS_INF_F32(actual) \ - TEST_EXPECT(isinf(actual), "Expected " #actual " to be infinity") - -// Double NaN and Infinity checks -#define EXPECT_ITS_NAN_F64(actual) \ - TEST_EXPECT(isnan(actual), "Expected " #actual " to be NaN") - -#define EXPECT_ITS_INF_F64(actual) \ - TEST_EXPECT(isinf(actual), "Expected " #actual " to be infinity") - -// ************************************************** -// -// Numaric EXPECTions -// -// ************************************************** - -// Octal EXPECTions - -// O8 EXPECTions -#define EXPECT_ITS_EQUAL_O8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) == (uint8_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_O8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_O8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_O8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_O8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_O8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) != (uint8_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_O8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_O8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_O8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_O8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// O16 EXPECTions -#define EXPECT_ITS_EQUAL_O16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) == (uint16_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_O16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_O16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_O16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_O16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_O16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) != (uint16_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_O16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_O16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_O16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_O16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// O32 EXPECTions -#define EXPECT_ITS_EQUAL_O32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) == (uint32_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_O32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_O32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_O32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_O32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_O32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) != (uint32_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_O32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_O32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_O32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_O32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// OI64 EXPECTions -#define EXPECT_ITS_EQUAL_O64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) == (uint64_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_O64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_O64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_O64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_O64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_O64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) != (uint64_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_O64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_O64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_O64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_O64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// Hexadecimal EXPECTions - -// H8 EXPECTions -#define EXPECT_ITS_EQUAL_H8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) == (uint8_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_H8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_H8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_H8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_H8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_H8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) != (uint8_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_H8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_H8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_H8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_H8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// H16 EXPECTions -#define EXPECT_ITS_EQUAL_H16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) == (uint16_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_H16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_H16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_H16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_H16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_H16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) != (uint16_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_H16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_H16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_H16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_H16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// H32 EXPECTions -#define EXPECT_ITS_EQUAL_H32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) == (uint32_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_H32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_H32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_H32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_H32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_H32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) != (uint32_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_H32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_H32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_H32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_H32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// H64 EXPECTions -#define EXPECT_ITS_EQUAL_H64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) == (uint64_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_H64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_H64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_H64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_H64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_H64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) != (uint64_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_H64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_H64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_H64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_H64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// I8 EXPECTions -#define EXPECT_ITS_EQUAL_I8(actual, expected) \ - TEST_EXPECT((int8_t)(actual) == (int8_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_I8(actual, expected) \ - TEST_EXPECT((int8_t)(actual) < (int8_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_I8(actual, expected) \ - TEST_EXPECT((int8_t)(actual) > (int8_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_I8(actual, expected) \ - TEST_EXPECT((int8_t)(actual) <= (int8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_I8(actual, expected) \ - TEST_EXPECT((int8_t)(actual) >= (int8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_I8(actual, expected) \ - TEST_EXPECT((int8_t)(actual) != (int8_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_I8(actual, expected) \ - TEST_EXPECT((int8_t)(actual) >= (int8_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_I8(actual, expected) \ - TEST_EXPECT((int8_t)(actual) <= (int8_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_I8(actual, expected) \ - TEST_EXPECT((int8_t)(actual) > (int8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_I8(actual, expected) \ - TEST_EXPECT((int8_t)(actual) < (int8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// I16 EXPECTions -#define EXPECT_ITS_EQUAL_I16(actual, expected) \ - TEST_EXPECT((int16_t)(actual) == (int16_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_I16(actual, expected) \ - TEST_EXPECT((int16_t)(actual) < (int16_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_I16(actual, expected) \ - TEST_EXPECT((int16_t)(actual) > (int16_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_I16(actual, expected) \ - TEST_EXPECT((int16_t)(actual) <= (int16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_I16(actual, expected) \ - TEST_EXPECT((int16_t)(actual) >= (int16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_I16(actual, expected) \ - TEST_EXPECT((int16_t)(actual) != (int16_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_I16(actual, expected) \ - TEST_EXPECT((int16_t)(actual) >= (int16_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_I16(actual, expected) \ - TEST_EXPECT((int16_t)(actual) <= (int16_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_I16(actual, expected) \ - TEST_EXPECT((int16_t)(actual) > (int16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_I16(actual, expected) \ - TEST_EXPECT((int16_t)(actual) < (int16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// I32 EXPECTions -#define EXPECT_ITS_EQUAL_I32(actual, expected) \ - TEST_EXPECT((int32_t)(actual) == (int32_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_I32(actual, expected) \ - TEST_EXPECT((int32_t)(actual) < (int32_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_I32(actual, expected) \ - TEST_EXPECT((int32_t)(actual) > (int32_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_I32(actual, expected) \ - TEST_EXPECT((int32_t)(actual) <= (int32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_I32(actual, expected) \ - TEST_EXPECT((int32_t)(actual) >= (int32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_I32(actual, expected) \ - TEST_EXPECT((int32_t)(actual) != (int32_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_I32(actual, expected) \ - TEST_EXPECT((int32_t)(actual) >= (int32_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_I32(actual, expected) \ - TEST_EXPECT((int32_t)(actual) <= (int32_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_I32(actual, expected) \ - TEST_EXPECT((int32_t)(actual) > (int32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_I32(actual, expected) \ - TEST_EXPECT((int32_t)(actual) < (int32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// I64 EXPECTions -#define EXPECT_ITS_EQUAL_I64(actual, expected) \ - TEST_EXPECT((int64_t)(actual) == (int64_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_I64(actual, expected) \ - TEST_EXPECT((int64_t)(actual) < (int64_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_I64(actual, expected) \ - TEST_EXPECT((int64_t)(actual) > (int64_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_I64(actual, expected) \ - TEST_EXPECT((int64_t)(actual) <= (int64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_I64(actual, expected) \ - TEST_EXPECT((int64_t)(actual) >= (int64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_I64(actual, expected) \ - TEST_EXPECT((int64_t)(actual) != (int64_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_I64(actual, expected) \ - TEST_EXPECT((int64_t)(actual) >= (int64_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_I64(actual, expected) \ - TEST_EXPECT((int64_t)(actual) <= (int64_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_I64(actual, expected) \ - TEST_EXPECT((int64_t)(actual) > (int64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_I64(actual, expected) \ - TEST_EXPECT((int64_t)(actual) < (int64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// U8 EXPECTions -#define EXPECT_ITS_EQUAL_U8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) == (uint8_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_U8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_U8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_U8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_U8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_U8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) != (uint8_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_U8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_U8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_U8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_U8(actual, expected) \ - TEST_EXPECT((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// U16 EXPECTions -#define EXPECT_ITS_EQUAL_U16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) == (uint16_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_U16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_U16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_U16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_U16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_U16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) != (uint16_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_U16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_U16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_U16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_U16(actual, expected) \ - TEST_EXPECT((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// U32 EXPECTions -#define EXPECT_ITS_EQUAL_U32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) == (uint32_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_U32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_U32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_U32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_U32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_U32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) != (uint32_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_U32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_U32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_U32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_U32(actual, expected) \ - TEST_EXPECT((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// U64 EXPECTions -#define EXPECT_ITS_EQUAL_U64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) == (uint64_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define EXPECT_ITS_LESS_THAN_U64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to be less than " #expected) - -#define EXPECT_ITS_MORE_THAN_U64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to be more than " #expected) - -#define EXPECT_ITS_LESS_OR_EQUAL_U64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define EXPECT_ITS_MORE_OR_EQUAL_U64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define EXPECT_NOT_EQUAL_U64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) != (uint64_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define EXPECT_NOT_LESS_THAN_U64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define EXPECT_NOT_MORE_THAN_U64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define EXPECT_NOT_LESS_OR_EQUAL_U64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define EXPECT_NOT_MORE_OR_EQUAL_U64(actual, expected) \ - TEST_EXPECT((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// ************************************************** -// -// Null pointer EXPECTions (_CNULL) -// -// ************************************************** - -// ITS set -#define EXPECT_ITS_CNULL(actual) \ - TEST_EXPECT((actual) == xnull, "Expected " #actual " to be xnull") - -#define EXPECT_NOT_CNULL(actual) \ - TEST_EXPECT((actual) != xnull, "Expected " #actual " to not be xnull") - -// General pointer EXPECTions (_PTR) - -// ITS set -#define EXPECT_ITS_EQUAL_PTR(actual, expected) \ - TEST_EXPECT((actual) == (expected), "Expected pointer " #actual " to be equal to pointer " #expected " ") - -#define EXPECT_NOT_EQUAL_PTR(actual, expected) \ - TEST_EXPECT((actual) != (expected), "Expected pointer " #actual " to not be equal to pointer " #expected " ") - -// Size_t EXPECTions - -// Equal -#define EXPECT_ITS_EQUAL_SIZE(actual, expected) \ - TEST_EXPECT((size_t)(actual) == (size_t)(expected), "Expected " #actual " to be equal to " #expected) - -// Less than -#define EXPECT_ITS_LESS_THAN_SIZE(actual, expected) \ - TEST_EXPECT((size_t)(actual) < (size_t)(expected), "Expected " #actual " to be less than " #expected) - -// More than -#define EXPECT_ITS_MORE_THAN_SIZE(actual, expected) \ - TEST_EXPECT((size_t)(actual) > (size_t)(expected), "Expected " #actual " to be more than " #expected) - -// Less or equal -#define EXPECT_ITS_LESS_OR_EQUAL_SIZE(actual, expected) \ - TEST_EXPECT((size_t)(actual) <= (size_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -// More or equal -#define EXPECT_ITS_MORE_OR_EQUAL_SIZE(actual, expected) \ - TEST_EXPECT((size_t)(actual) >= (size_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -// Not equal -#define EXPECT_NOT_EQUAL_SIZE(actual, expected) \ - TEST_EXPECT((size_t)(actual) != (size_t)(expected), "Expected " #actual " to not be equal to " #expected) - -// ************************************************** -// -// Range EXPECTions -// -// ************************************************** - -// EXPECTion for checking if a value is within a specified range -#define EXPECT_ITS_WITHIN_RANGE(value, min, max) \ - TEST_EXPECT((value) >= (min) && (value) <= (max), "Value " #value " is not within range [" #min ", " #max "]") - -#define EXPECT_NOT_WITHIN_RANGE(value, min, max) \ - TEST_EXPECT((value) < (min) || (value) > (max), "Value " #value " is within range [" #min ", " #max "]") - -// Unsigned integer type EXPECTions - -#define EXPECT_ITS_WITHIN_RANGE_U8(value, min, max) \ - TEST_EXPECT((uint8_t)(value) >= (uint8_t)(min) && (uint8_t)(value) <= (uint8_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define EXPECT_NOT_WITHIN_RANGE_U8(value, min, max) \ - TEST_EXPECT((uint8_t)(value) < (uint8_t)(min) || (uint8_t)(value) > (uint8_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define EXPECT_ITS_WITHIN_RANGE_U16(value, min, max) \ - TEST_EXPECT((uint16_t)(value) >= (uint16_t)(min) && (uint16_t)(value) <= (uint16_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define EXPECT_NOT_WITHIN_RANGE_U16(value, min, max) \ - TEST_EXPECT((uint16_t)(value) < (uint16_t)(min) || (uint16_t)(value) > (uint16_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define EXPECT_ITS_WITHIN_RANGE_U32(value, min, max) \ - TEST_EXPECT((uint32_t)(value) >= (uint32_t)(min) && (uint32_t)(value) <= (uint32_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define EXPECT_NOT_WITHIN_RANGE_U32(value, min, max) \ - TEST_EXPECT((uint32_t)(value) < (uint32_t)(min) || (uint32_t)(value) > (uint32_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define EXPECT_ITS_WITHIN_RANGE_U64(value, min, max) \ - TEST_EXPECT((uint64_t)(value) >= (uint64_t)(min) && (uint64_t)(value) <= (uint64_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define EXPECT_NOT_WITHIN_RANGE_U64(value, min, max) \ - TEST_EXPECT((uint64_t)(value) < (uint64_t)(min) || (uint64_t)(value) > (uint64_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -// Signed integer type EXPECTions - -#define EXPECT_ITS_WITHIN_RANGE_I8(value, min, max) \ - TEST_EXPECT((int8_t)(value) >= (int8_t)(min) && (int8_t)(value) <= (int8_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define EXPECT_NOT_WITHIN_RANGE_I8(value, min, max) \ - TEST_EXPECT((int8_t)(value) < (int8_t)(min) || (int8_t)(value) > (int8_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define EXPECT_ITS_WITHIN_RANGE_I16(value, min, max) \ - TEST_EXPECT((int16_t)(value) >= (int16_t)(min) && (int16_t)(value) <= (int16_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define EXPECT_NOT_WITHIN_RANGE_I16(value, min, max) \ - TEST_EXPECT((int16_t)(value) < (int16_t)(min) || (int16_t)(value) > (int16_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define EXPECT_ITS_WITHIN_RANGE_I32(value, min, max) \ - TEST_EXPECT((int32_t)(value) >= (int32_t)(min) && (int32_t)(value) <= (int32_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define EXPECT_NOT_WITHIN_RANGE_I32(value, min, max) \ - TEST_EXPECT((int32_t)(value) < (int32_t)(min) || (int32_t)(value) > (int32_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define EXPECT_ITS_WITHIN_RANGE_I64(value, min, max) \ - TEST_EXPECT((int64_t)(value) >= (int64_t)(min) && (int64_t)(value) <= (int64_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define EXPECT_NOT_WITHIN_RANGE_I64(value, min, max) \ - TEST_EXPECT((int64_t)(value) < (int64_t)(min) || (int64_t)(value) > (int64_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -// Floating point type EXPECTions - -#define EXPECT_ITS_WITHIN_RANGE_F32(value, min, max) \ - TEST_EXPECT((value) >= (min) && (value) <= (max), "Value " #value " is not within range [" #min ", " #max "]") - -#define EXPECT_NOT_WITHIN_RANGE_F32(value, min, max) \ - TEST_EXPECT((value) < (min) || (value) > (max), "Value " #value " is within range [" #min ", " #max "]") - -#define EXPECT_ITS_WITHIN_RANGE_F64(value, min, max) \ - TEST_EXPECT((value) >= (min) && (value) <= (max), "Value " #value " is not within range [" #min ", " #max "]") - -#define EXPECT_NOT_WITHIN_RANGE_F64(value, min, max) \ - TEST_EXPECT((value) < (min) || (value) > (max), "Value " #value " is within range [" #min ", " #max "]") - -// Byte char type EXPECTions (uint8_t) - -#define EXPECT_ITS_WITHIN_RANGE_BCHAR(value, min, max) \ - TEST_EXPECT((uint8_t)(value) >= (uint8_t)(min) && (uint8_t)(value) <= (uint8_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define EXPECT_NOT_WITHIN_RANGE_BCHAR(value, min, max) \ - TEST_EXPECT((uint8_t)(value) < (uint8_t)(min) || (uint8_t)(value) > (uint8_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -// Char type EXPECTions (char) - -#define EXPECT_ITS_WITHIN_RANGE_CCHAR(value, min, max) \ - TEST_EXPECT((char)(value) >= (char)(min) && (char)(value) <= (char)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define EXPECT_NOT_WITHIN_RANGE_CCHAR(value, min, max) \ - TEST_EXPECT((char)(value) < (char)(min) || (char)(value) > (char)(max), "Value " #value " is within range [" #min ", " #max "]") - -// Wide char type EXPECTions (wchar_t) - -#define EXPECT_ITS_WITHIN_RANGE_WCHAR(value, min, max) \ - TEST_EXPECT((wchar_t)(value) >= (wchar_t)(min) && (wchar_t)(value) <= (wchar_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define EXPECT_NOT_WITHIN_RANGE_WCHAR(value, min, max) \ - TEST_EXPECT((wchar_t)(value) < (wchar_t)(min) || (wchar_t)(value) > (wchar_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -// ************************************************** -// -// String EXPECTions -// -// ************************************************** - -// Wide char string equality check -#define EXPECT_ITS_EQUAL_WSTR(actual, expected) \ - TEST_EXPECT(wcscmp((actual), (expected)) == 0, "Expected wide string " #actual " to be equal to " #expected) - -#define EXPECT_NOT_EQUAL_WSTR(actual, expected) \ - TEST_EXPECT(wcscmp((actual), (expected)) != 0, "Expected wide string " #actual " to not be equal to " #expected) - -// For length comparison -#define EXPECT_ITS_LENGTH_EQUAL_WSTR(actual, expected_len) \ - TEST_EXPECT(wcslen((actual)) == (expected_len), "Expected length of wide string " #actual " to be equal to " #expected_len) - -// Byte string equality check -#define EXPECT_ITS_EQUAL_BSTR(actual, expected) \ - TEST_EXPECT(strcmp((const char*)(actual), (const char*)(expected)) == 0, "Expected byte string " #actual " to be equal to " #expected) - -#define EXPECT_NOT_EQUAL_BSTR(actual, expected) \ - TEST_EXPECT(strcmp((const char*)(actual), (const char*)(expected)) != 0, "Expected byte string " #actual " to not be equal to " #expected) - -// For length comparison -#define EXPECT_ITS_LENGTH_EQUAL_BSTR(actual, expected_len) \ - TEST_EXPECT(strlen((const char*)(actual)) == (expected_len), "Expected length of byte string " #actual " to be equal to " #expected_len) - -// Classic C string equality check -#define EXPECT_ITS_EQUAL_CSTR(actual, expected) \ - TEST_EXPECT(strcmp((actual), (expected)) == 0, "Expected C string " #actual " to be equal to " #expected) - -#define EXPECT_NOT_EQUAL_CSTR(actual, expected) \ - TEST_EXPECT(strcmp((actual), (expected)) != 0, "Expected C string " #actual " to not be equal to " #expected) - -// For length comparison -#define EXPECT_ITS_LENGTH_EQUAL_CSTR(actual, expected_len) \ - TEST_EXPECT(strlen((actual)) == (expected_len), "Expected length of C string " #actual " to be equal to " #expected_len) - -// ************************************************** -// -// Array EXPECTions -// -// ************************************************** - -// Array equality check -#define EXPECT_ITS_EQUAL_ARRAY(actual, expected, length) \ - for (size_t i = 0; i < (length); i++) { \ - TEST_EXPECT((actual)[i] == (expected)[i], "Expected array element " #actual " to be equal to " #expected); \ - } - -// Array inequality check -#define EXPECT_NOT_EQUAL_ARRAY(actual, expected, length) \ - for (size_t i = 0; i < (length); i++) { \ - TEST_EXPECT((actual)[i] != (expected)[i], "Expected array element " #actual " to not be equal to " #expected); \ - } - -// Array length check -#define EXPECT_ITS_LENGTH_EQUAL_ARRAY(actual_length, expected_length) \ - TEST_EXPECT((actual_length) == (expected_length), "Expected array length " #actual_length " to be equal to " #expected_length) - -// Array element within range check -#define EXPECT_ITS_WITHIN_RANGE_ARRAY(array, min, max, length) \ - for (size_t i = 0; i < (length); i++) { \ - TEST_EXPECT((array)[i] >= (min) && (array)[i] <= (max), "Expected array element " #array " to be within range [" #min ", " #max "]"); \ - } - -// Array element not within range check -#define EXPECT_NOT_WITHIN_RANGE_ARRAY(array, min, max, length) \ - for (size_t i = 0; i < (length); i++) { \ - TEST_EXPECT((array)[i] < (min) || (array)[i] > (max), "Expected array element " #array " to not be within range [" #min ", " #max "]"); \ - } - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/code/logic/fossil/unittest/framework.h b/code/logic/fossil/unittest/framework.h index 966ada6f..bfe36ef6 100644 --- a/code/logic/fossil/unittest/framework.h +++ b/code/logic/fossil/unittest/framework.h @@ -55,7 +55,7 @@ void fossil_test_apply_priority(fossil_test_t *test, const char *priority); * @param line The line number where the assertion occurred. * @param func The function name where the assertion occurred. */ -void _fossil_test_assert_class(bool expression, xassert_type_t behavior, char* message, char* file, int line, char* func); +void _fossil_test_assert_class(bool expression, char* message, char* file, int line, char* func); /** @@ -616,34 +616,6 @@ void _fossil_test_assert_class(bool expression, xassert_type_t behavior, char* m // Assertion specific commands // ================================================================= -/** - * @brief Define macros for test assertions with expression and message. - * - * This macro is used to define a test assertion. It checks the given expression - * and, if the expression evaluates to false, logs the failure with the provided - * message, file name, line number, and function name. This type of assertion - * typically halts the test execution upon failure. - * - * @param expression The expression to be evaluated. - * @param message The message to log if the assertion fails. - */ -#define TEST_ASSERT(expression, message) \ - _fossil_test_assert_class(expression, TEST_ASSERT_AS_CLASS_ASSERT, (char*)message, (char*)__FILE__, __LINE__, (char*)__func__) - -/** - * @brief Define macros for test expectations with expression and message. - * - * This macro is used to define a test expectation. It checks the given expression - * and, if the expression evaluates to false, logs the failure with the provided - * message, file name, line number, and function name. Unlike assertions, expectations - * typically do not halt the test execution upon failure, allowing subsequent tests to run. - * - * @param expression The expression to be evaluated. - * @param message The message to log if the expectation fails. - */ -#define TEST_EXPECT(expression, message) \ - _fossil_test_assert_class(expression, TEST_ASSERT_AS_CLASS_EXPECT, (char*)message, (char*)__FILE__, __LINE__, (char*)__func__) - /** * @brief Define macros for test assumptions with expression and message. * @@ -657,36 +629,7 @@ void _fossil_test_assert_class(bool expression, xassert_type_t behavior, char* m * @param message The message to log if the assumption fails. */ #define TEST_ASSUME(expression, message) \ - _fossil_test_assert_class(expression, TEST_ASSERT_AS_CLASS_ASSUME, (char*)message, (char*)__FILE__, __LINE__, (char*)__func__) - -/** - * @brief Define macros for exception testing with expression and message. - * - * This macro is used to define a test for exceptions. It checks the given expression - * and, if the expression evaluates to false, logs the failure with the provided - * message, file name, line number, and function name. This is typically used to - * validate that the code under test correctly handles exceptions or error conditions. - * - * @param expression The expression to be evaluated. - * @param message The message to log if the exception test fails. - */ -#define TEST_EXCEPT(expression, message) \ - _fossil_test_assert_class(expression, TEST_ASSERT_AS_CLASS_EXCEPT, (char*)message, (char*)__FILE__, __LINE__, (char*)__func__) - -/** - * @brief Define macros for sanity pen testing with expression and message. - * - * This macro is used to define a sanity check for penetration testing. It checks - * the given expression and, if the expression evaluates to false, logs the failure - * with the provided message, file name, line number, and function name. Sanity checks - * are typically used for exact validation and security testing to ensure the system - * behaves as expected under specific conditions. - * - * @param expression The expression to be evaluated. - * @param message The message to log if the sanity test fails. - */ -#define TEST_SANITY(expression, message) \ - _fossil_test_assert_class(expression, TEST_ASSERT_AS_CLASS_SANITY, (char*)message, (char*)__FILE__, __LINE__, (char*)__func__) + _fossil_test_assert_class(expression, (char*)message, (char*)__FILE__, __LINE__, (char*)__func__) #ifdef __cplusplus } diff --git a/code/logic/fossil/unittest/internal.h b/code/logic/fossil/unittest/internal.h deleted file mode 100644 index 022ba4dd..00000000 --- a/code/logic/fossil/unittest/internal.h +++ /dev/null @@ -1,251 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#ifndef FOSSIL_TEST_INTERNAL_H -#define FOSSIL_TEST_INTERNAL_H - -#include "fossil/_common/common.h" -#include "fossil/_common/platform.h" - -/** - * Introspection Data in Fossil Test - * - * Introspection, in the context of Fossil Test, refers to the process of gathering - * detailed information about the testing environment. This information is crucial - * for ensuring test stability, reliability, and portability across different - * platforms and environments. Fossil Test relies heavily on introspection data to - * adapt its behavior dynamically based on the characteristics of the system where - * it runs. - * - * The importance of introspection data can be summarized as follows: - * - * 1. System Compatibility: - * Introspection data allows Fossil Test to identify the underlying architecture, - * operating system, CPU count, endianness, and memory size of the test environment. - * This information is vital for ensuring that tests execute correctly on diverse - * platforms, including ARM, Windows, macOS, and various POSIX-based systems. - * - * 2. Test Adaptation: - * By analyzing introspection data, Fossil Test can adapt its behavior and configuration - * to suit the characteristics of the current environment. For example, the console - * output may be adjusted based on the console width and height, and color support - * may be enabled or disabled depending on the capabilities of the terminal. - * - * 3. Performance Optimization: - * Introspection data helps Fossil Test optimize test execution performance by providing - * insights into system resources such as CPU count and memory size. This information - * allows Fossil Test to allocate resources efficiently and prioritize test execution - * based on available hardware resources. - * - * 4. Cross-Platform Testing: - * With introspection data, Fossil Test can facilitate cross-platform testing by - * identifying and handling platform-specific differences transparently. Whether - * running on Windows, macOS, Linux, or other operating systems, Fossil Test can - * leverage introspection data to ensure consistent test behavior and results. - * - * In conclusion, introspection data forms the foundation of Fossil Test's ability - * to operate effectively in diverse testing environments. By gathering and analyzing - * detailed information about the test environment, Fossil Test enhances compatibility, - * adaptability, performance, and cross-platform testing capabilities, thereby - * empowering developers to write robust and portable test suites. - */ - -// Define thread pool size -enum { - FOSSIL_TEST_MAX_FILTER_LENGTH = 50, - FOSSIL_TEST_ASSUME_MAX = 5, - FOSSIL_TEST_EXCEPT_MAX = 5, - FOSSIL_TEST_MAX_REPEATS = 100, - FOSSIL_TEST_MIN_REPEATS = 1, - FOSSIL_TEST_MAX_PRIORITY = 100, - FOSSIL_TEST_MIN_PRIORITY = 1, - MAX_EXPECTED_TIME_FAST = 1000, // Example value: 1000 milliseconds (1 second) - MAX_EXPECTED_TIME_SLOW = 2000, // 2000 milliseconds (2 seconds) - FOSSIL_TESTAULT_PRIORITY_THRESHOLD = 50, - FOSSIL_TEST_ABORT_FAIL = -1, -}; - -typedef enum { - FOSSIL_TEST_IO_AS_HUMAN, - FOSSIL_TEST_IO_AS_CUTBACK, - FOSSIL_TEST_IO_AS_TURBO -} fossil_test_mode; - -/** - * @brief Enumeration representing different types of assertion rules. - * - * This enum defines various types of assertion rules that can be applied to test cases. - * Each value represents a specific type of assertion behavior. - */ -typedef enum { - TEST_ASSERT_AS_CLASS_ASSERT, /**< Standard assert, used to enforce conditions that must be true. */ - TEST_ASSERT_AS_CLASS_EXPECT, /**< Expectation, used to define conditions that are expected but not mandatory. */ - TEST_ASSERT_AS_CLASS_ASSUME, /**< Assumption, used to specify assumptions that must hold true for the test to proceed. */ - TEST_ASSERT_AS_CLASS_EXCEPT, /**< Exception, used to handle conditions that are expected to raise exceptions. */ - TEST_ASSERT_AS_CLASS_SANITY /**< Sanity check, used for basic checks to ensure the test environment is stable. */ -} xassert_type_t; - -/** - * @brief Enumeration representing different priority rules for test assertions. - * - * This enum defines various priority rules for test assertions, indicating the importance - * or urgency of the tests. Tests with higher priority values are considered more critical. - */ -typedef enum { - TEST_ASSERT_PRIORITY_RULE_LOW, /**< Priority for tests with low importance. */ - TEST_ASSERT_PRIORITY_RULE_NORMAL, /**< Priority for tests with normal importance. */ - TEST_ASSERT_PRIORITY_RULE_HIGH, /**< Priority for tests with high importance. */ - TEST_ASSERT_PRIORITY_RULE_CRITICAL /**< Priority for tests with critical importance. */ -} xassert_priority_t; - -/** - * @brief Enumeration representing different mark rules for test assertions. - * - * This enum defines various marking rules for test assertions, indicating the expected - * outcome or behavior of the tests. - */ -typedef enum { - TEST_ASSERT_MARK_RULE_SKIP, /**< Mark for tests that should be skipped. */ - TEST_ASSERT_MARK_RULE_DEFAULT, /**< Default mark for tests with no specific expected outcome. */ - TEST_ASSERT_MARK_RULE_TIMEOUT, /**< Mark for tests that are expected to timeout. */ - TEST_ASSERT_MARK_RULE_ERROR, /**< Mark for tests that are expected to throw an error. */ - TEST_ASSERT_MARK_RULE_NONE, /**< Mark for tests with no specific expected outcome. */ - TEST_ASSERT_MARK_RULE_ONLY /**< Mark for tests that are the only ones to be run. */ -} xassert_mark_t; - -/** - * Structure representing rules or attributes of a test case. - * This structure is used to track various states or characteristics of a test case, - * such as whether it passed, was skipped, or was categorized as fast or slow. - */ -typedef struct { - bool should_pass; /**< Boolean indicating whether the test case passed. */ - bool skipped; /**< Boolean indicating whether the test case was skipped. */ - bool timeout; /**< Boolean indicating whether the test case timed out. */ - bool error; /**< Boolean indicating whether the test case threw an error. */ -} fossil_test_rule_t; - -/** - * @brief Structure to hold timing information for tests. - * - * This structure stores the timing information for tests, including the start time, - * end time, elapsed time, and detailed timing information in different units. - * It is used to track the duration of test executions to provide performance metrics. - */ -typedef struct { - clock_t start; /**< Processor time at the start of tests. */ - clock_t end; /**< Processor time at the end of tests. */ - clock_t elapsed; /**< Elapsed processor time for the tests. */ - struct { - int64_t minutes; /**< Elapsed time in minutes. */ - int64_t seconds; /**< Elapsed time in seconds. */ - int64_t milliseconds; /**< Elapsed time in milliseconds. */ - int64_t microseconds; /**< Elapsed time in microseconds. */ - int64_t nanoseconds; /**< Elapsed time in nanoseconds. */ - } detail; /**< Detailed timing information, providing a breakdown of elapsed time in various units. */ -} fossil_test_timer_t; - -/** - * Structure representing fixture information with setup and teardown functions. - * A fixture is used to set up any necessary environment or state before running a test - * and to clean up afterward. This is useful for initializing resources or configurations - * that multiple test cases share. - */ -typedef struct { - void (*setup)(void); /**< Function pointer to the setup function for the fixture. - This function is called before each test case to set up - the test environment. */ - void (*teardown)(void); /**< Function pointer to the teardown function for the fixture. - This function is called after each test case to clean up - the test environment. */ -} fossil_fixture_t; - -/** - * Structure representing a test case. - * This structure contains all the necessary information for a test case, including its name, - * the function implementing the test, priority, tags, and links to setup and teardown functions. - */ -typedef struct fossil_test_t fossil_test_t; -typedef struct fossil_test_t { - const char* name; /**< Name of the test case. */ - void (*test_function)(void); /**< Function pointer to the test case's implementation. */ - char* tags; /**< Array of tags associated with the test case. */ - char* marks; /**< Array of marks associated with the test case. */ - fossil_test_timer_t timer; /**< Timer for tracking the duration of the test case. */ - fossil_fixture_t fixture; /**< The fixture settings for setup and teardown functions. */ - int32_t priority; /**< Priority of the test case (higher value indicates higher priority). */ - struct fossil_test_t *prev; /**< Pointer to the previous fossil_test_t node in a linked list. */ - struct fossil_test_t *next; /**< Pointer to the next fossil_test_t node in a linked list. */ -} fossil_test_t; - -/** - * Structure representing a deque (double-ended queue) for managing test cases. - * This structure allows for the addition and removal of test cases from both ends of the queue. - */ -typedef struct { - fossil_test_t *front; /**< Pointer to the front of the deque. */ - fossil_test_t *rear; /**< Pointer to the rear of the deque. */ -} fossil_test_queue_t; - -/** - * Structure representing statistics for tracking test results. - * This structure keeps track of various counts related to the outcomes of test cases, - * including passed, failed, skipped, and timed-out tests. - */ -typedef struct { - uint16_t expected_passed_count; /**< Number of expected passed tests. */ - uint16_t expected_failed_count; /**< Number of expected failed tests. */ - uint16_t unexpected_passed_count; /**< Number of unexpected passed tests. */ - uint16_t unexpected_failed_count; /**< Number of unexpected failed tests. */ - uint16_t expected_skipped_count; /**< Number of skipped tests. */ - uint16_t expected_empty_count; /**< Number of empty tests. */ - uint16_t expected_timeout_count; /**< Number of tests that timed out. */ - uint16_t expected_total_count; /**< Total number of unit tests that were run. */ - uint16_t untested_count; /**< Total number of untested cases when exit or abort is called - from an assert. */ -} fossil_test_score_t; - -/** - * Structure representing information about an assertion. - * This structure contains detailed information about an assertion, including the name of the test case, - * the message associated with the assertion, the file name, line number, function name, timestamp, assertion type, - * execution time, test case identifier, severity level, custom data, stack trace, and result of the test case. - */ -typedef struct { - bool shoudl_timeout; /**< Flag indicating whether the test case should timeout (1 for true, 0 for false). */ - bool should_fail; /**< Flag indicating whether the test case should fail (1 for true, 0 for false). */ - bool has_assert; /**< Flag indicating if an assertion occurred (1 for true, 0 for false). */ - bool same_assert; /**< Flag indicating if the test case is the same (1 for true, 0 for false). */ - int32_t num_asserts; /**< Number of assertions that occurred. */ - int32_t line; /**< Line number where the assertion occurred. */ - char *func; /**< Function name where the assertion occurred. */ - char *file; /**< File name where the assertion occurred. */ - char *message; /**< Message associated with the assertion. */ -} xassert_info; - -/** - * Structure representing the test environment, holding overall test statistics and timing information. - * This structure is used to manage the state of the testing process, including the queue of test cases - * and the timer for tracking the duration of the tests. - */ -typedef struct { - fossil_test_score_t stats; /**< Test statistics, including counts of passed, failed, and skipped tests. */ - fossil_test_timer_t timer; /**< Timer for tracking the time taken to run the tests. */ - fossil_test_queue_t* queue; /**< Queue to hold the test cases, allowing them to be managed and executed in order. */ - fossil_test_rule_t rule; /**< Rule for the test case, including whether it should pass, fail, or be skipped. */ - uint8_t current_except_count; /**< Counter for the number of exceptions that occurred during testing. */ - uint8_t current_assume_count; /**< Counter for the number of assumptions that occurred during testing. */ -} fossil_env_t; - -#endif diff --git a/code/logic/unittest/old-unittest.c b/code/logic/unittest/old-unittest.c new file mode 100644 index 00000000..fd128881 --- /dev/null +++ b/code/logic/unittest/old-unittest.c @@ -0,0 +1,749 @@ +/* + * ----------------------------------------------------------------------------- + * Project: Fossil Logic + * + * This file is part of the Fossil Logic project, which aims to develop high- + * performance, cross-platform applications and libraries. The code contained + * herein is subject to the terms and conditions defined in the project license. + * + * Author: Michael Gene Brockus (Dreamer) + * Date: 07/01/2024 + * + * Copyright (C) 2024 Fossil Logic. All rights reserved. + * ----------------------------------------------------------------------------- + */ +#include "fossil/unittest/framework.h" +#include "fossil/_common/common.h" +#include "fossil/unittest/console.h" +#include "fossil/unittest/commands.h" +#include + +#define MAX_ASSERT_HISTORY 100 + +typedef struct { + bool expression; + char* message; + char* file; + int line; + unsigned long fingerprint; + char* func; +} assert_history_t; + +static assert_history_t assert_history[MAX_ASSERT_HISTORY]; +static int assert_history_count = 0; + +fossil_env_t _TEST_ENV; +xassert_info _ASSERT_INFO; + +fossil_test_queue_t* fossil_test_queue_create(void) { + fossil_test_queue_t* queue = (fossil_test_queue_t*)malloc(sizeof(fossil_test_queue_t)); + if (queue != xnullptr) { + queue->front = xnullptr; + queue->rear = xnullptr; + } else { + // Handle memory allocation failure + perror("Failed to allocate memory for queue"); + return xnullptr; + } + return queue; +} + +void fossil_test_queue_erase(fossil_test_queue_t* queue) { + fossil_test_t* current = queue->front; + fossil_test_t* next; + + while (current != xnullptr) { + next = current->next; + free(current); + current = next; + } + + queue->front = xnullptr; + queue->rear = xnullptr; +} + +// Function to add a test to the front of the queue +void fossil_test_queue_push_front(fossil_test_t *test, fossil_test_queue_t *queue) { + if (test == xnullptr || queue == xnullptr) { + return; + } + + if (queue->front == xnullptr) { + // The queue is empty + queue->front = test; + queue->rear = test; + } else { + // Insert test at the front + test->next = queue->front; + queue->front->prev = test; + queue->front = test; + } + test->prev = xnullptr; // Ensure previous pointer of new front is NULL +} + +// Function to add a test to the rear of the queue +void fossil_test_queue_push_back(fossil_test_t *test, fossil_test_queue_t *queue) { + if (test == xnullptr || queue == xnullptr) { + return; + } + + if (queue->rear == xnullptr) { + // The queue is empty + queue->front = test; + queue->rear = test; + } else { + // Insert test at the rear + queue->rear->next = test; + test->prev = queue->rear; + queue->rear = test; + } + test->next = xnullptr; // Ensure next pointer of new rear is NULL +} + +// Function to remove and return the test from the front of the queue +fossil_test_t* fossil_test_queue_pop_front(fossil_test_queue_t *queue) { + if (queue == xnullptr || queue->front == xnullptr) { + return xnullptr; + } + + fossil_test_t *front_test = queue->front; + + if (queue->front == queue->rear) { + // The queue has only one test + queue->front = xnullptr; + queue->rear = xnullptr; + } else { + // Remove test from the front + queue->front = queue->front->next; + queue->front->prev = xnullptr; + } + + return front_test; +} + +// Function to remove and return the test from the rear of the queue +fossil_test_t* fossil_test_queue_pop_back(fossil_test_queue_t *queue) { + if (queue == xnullptr || queue->rear == xnullptr) { + return xnullptr; + } + + fossil_test_t *rear_test = queue->rear; + + if (queue->front == queue->rear) { + // The queue has only one test + queue->front = xnullptr; + queue->rear = xnullptr; + } else { + // Remove test from the rear + queue->rear = queue->rear->prev; + queue->rear->next = xnullptr; + } + + return rear_test; +} + +// Function to add a test to the queue based on priority +void add_test_to_queue(fossil_test_t *test, fossil_test_queue_t *queue) { + fossil_test_queue_push_back(test, queue); +} + +// Function to remove and return the test with the highest priority from the queue +fossil_test_t* get_highest_priority_test(fossil_test_queue_t *queue) { + // In this implementation, the test with the highest priority is the one at the front of the queue + return fossil_test_queue_pop_front(queue); +} + +// Function to remove and return the test with the lowest priority from the queue +fossil_test_t* get_lowest_priority_test(fossil_test_queue_t *queue) { + // In this implementation, the test with the lowest priority is the one at the rear of the queue + return fossil_test_queue_pop_back(queue); +} + +// Function to search for a test by tag in the queue +fossil_test_t* fossil_test_queue_search_by_tag(fossil_test_queue_t *queue, const char *tag) { + if (queue == xnullptr || tag == xnullptr) { + return xnullptr; + } + + fossil_test_t *current = queue->front; + while (current != xnullptr) { + if (strcmp(current->tags, tag) == 0) { + return current; + } + current = current->next; + } + return xnullptr; +} + +// Function to search for a test by name in the queue +fossil_test_t* fossil_test_queue_search_by_name(fossil_test_queue_t *queue, const char *name) { + if (queue == xnullptr || name == xnullptr) { + return xnullptr; + } + + fossil_test_t *current = queue->front; + while (current != xnullptr) { + if (strcmp(current->name, name) == 0) { + return current; + } + current = current->next; + } + return xnullptr; +} + +void fossil_test_queue_reverse(fossil_test_queue_t *queue) { + if (queue == xnullptr) { + return; + } + + fossil_test_t *current = queue->front; + fossil_test_t *temp = xnullptr; + + // Swap the next and prev pointers for each node + while (current != xnullptr) { + temp = current->prev; + current->prev = current->next; + current->next = temp; + current = current->prev; + } + + // Swap the front and rear pointers of the queue + if (temp != xnullptr) { + temp = queue->front; + queue->front = queue->rear; + queue->rear = temp; + } +} + +// Function to convert queue to an array +fossil_test_t** queue_to_array(fossil_test_queue_t *queue, int *size) { + if (queue == xnullptr) { + return xnullptr; + } + + int count = 0; + fossil_test_t *current = queue->front; + while (current != xnullptr) { + count++; + current = current->next; + } + + fossil_test_t **array = (fossil_test_t**)malloc(count * sizeof(fossil_test_t*)); + current = queue->front; + for (int i = 0; i < count; i++) { + array[i] = current; + current = current->next; + } + + *size = count; + return array; +} + +// Function to convert array to a queue +void array_to_queue(fossil_test_t **array, int size, fossil_test_queue_t *queue) { + if (queue == xnullptr || array == xnullptr) { + return; + } + + queue->front = xnullptr; + queue->rear = xnullptr; + + for (int i = 0; i < size; i++) { + array[i]->next = xnullptr; + array[i]->prev = xnullptr; + fossil_test_queue_push_back(array[i], queue); + } +} + +// Fisher-Yates shuffle algorithm +void fossil_test_queue_shuffle(fossil_test_queue_t *queue) { + if (queue == xnullptr) { + return; + } + + int size; + fossil_test_t **array = queue_to_array(queue, &size); + if (array == xnullptr) { + return; + } + + srand(time(xnullptr)); + for (int i = size - 1; i > 0; i--) { + int j = rand() % (i + 1); + fossil_test_t *temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } + + array_to_queue(array, size, queue); + free(array); +} + +// +// Fossil Test Environment functions +// + +void fossil_test_environment_erase(void) { + if (_TEST_ENV.queue != xnullptr) { + free(_TEST_ENV.queue); // Fix memory leak by uncommenting free statement + } +} + +fossil_env_t fossil_test_environment_create(int argc, char **argv) { + _CLI = fossil_options_parse(argc, argv); + fossil_test_io_information(); // checkpoint for simple commands + + fossil_env_t env; + + // Initialize test statistics + env.stats.expected_passed_count = 0; + env.stats.expected_failed_count = 0; + env.stats.unexpected_passed_count = 0; + env.stats.unexpected_failed_count = 0; + env.stats.expected_skipped_count = 0; + env.stats.expected_empty_count = 0; + env.stats.expected_timeout_count = 0; + env.stats.expected_total_count = 0; + env.stats.untested_count = 0; + + // Initialize test rules + env.rule.should_pass = true; + env.rule.skipped = false; + env.rule.timeout = false; + env.rule.error = false; + + // Initialize test timer + env.timer.start = 0; + env.timer.end = 0; + env.timer.elapsed = 0; + env.timer.detail.minutes = 0; + env.timer.detail.seconds = 0; + env.timer.detail.milliseconds = 0; + env.timer.detail.microseconds = 0; + env.timer.detail.nanoseconds = 0; + + // Initialize test queue + env.queue = fossil_test_queue_create(); + atexit(fossil_test_environment_erase); // ensure memory leaks do not occur + + // Initialize exception and assumption counts + env.current_except_count = 0; + env.current_assume_count = 0; + + fossil_test_io_summary_start(); + + return env; +} + +void _fossil_test_scoreboard_update(void) { + // here we just update the scoreboard count + // add one to total tested cases and remove + // one from untested ghost cases. + // + // The main goal is to ensure ghost cases are removed + // accordingly and the total tested cases are updated. + // + // However in the event exit is called we will have + // record of test that are tested and those that are + // not tested. + _TEST_ENV.stats.untested_count--; + _TEST_ENV.stats.expected_total_count++; +} + +void _fossil_test_scoreboard_expected_rules(void) { + if (!_TEST_ENV.rule.should_pass) { + _TEST_ENV.stats.expected_failed_count++; + _TEST_ENV.rule.should_pass = false; + } else { + _TEST_ENV.stats.expected_passed_count++; + } +} + +void _fossil_test_scoreboard_unexpected_rules(void) { + if (_TEST_ENV.rule.should_pass) { + _TEST_ENV.stats.unexpected_failed_count++; + } else { + _TEST_ENV.stats.unexpected_passed_count++; + } +} + +void _fossil_test_scoreboard_feature_rules(fossil_test_t *test_case) { + if (_TEST_ENV.rule.skipped && strcmp(test_case->marks, "skip") == 0) { + _TEST_ENV.stats.expected_skipped_count++; + _TEST_ENV.rule.skipped = false; + } else if (!_ASSERT_INFO.has_assert && strcmp(test_case->marks, "tofu") != 0) { + _TEST_ENV.stats.expected_empty_count++; + } else if (!_TEST_ENV.rule.should_pass && strcmp(test_case->marks, "fail") == 0) { + if (_ASSERT_INFO.should_fail) { + _fossil_test_scoreboard_expected_rules(); + } else { + _fossil_test_scoreboard_unexpected_rules(); + } + } else { + _TEST_ENV.stats.expected_passed_count++; + } +} + +void fossil_test_environment_scoreboard(fossil_test_t *test) { + // for the first part we check if the given test case + // has any feature flags or rules triggered. + if (strcmp(test->marks, "fossil") != 0) { + _fossil_test_scoreboard_feature_rules(test); + } else { + _fossil_test_scoreboard_expected_rules(); + } + + // we just need to update the total scoreboard + // so it is accurate for the fossil test. + _fossil_test_scoreboard_update(); + _TEST_ENV.rule.should_pass = true; // reset counter for next test +} + +void fossil_test_run_testcase(fossil_test_t *test) { + if (test == xnullptr) { + return; + } + // set and reset step for assert scanning + _ASSERT_INFO.has_assert = false; + _ASSERT_INFO.should_fail = false; + _ASSERT_INFO.shoudl_timeout = false; + _ASSERT_INFO.num_asserts = 0; + _ASSERT_INFO.same_assert = false; + + if (_TEST_ENV.rule.skipped && strcmp(test->marks, "skip") == 0) { + return; + } else if (!_ASSERT_INFO.should_fail && strcmp(test->marks, "fail") == 0) { + _ASSERT_INFO.should_fail = true; + } + + fossil_test_io_unittest_start(test); + if (test->fixture.setup != xnullptr) { + test->fixture.setup(); + } + + // Run the test function + for (int32_t iter = 0; iter < _CLI.repeat_count; iter++) { + test->test_function(); + } + fossil_test_io_unittest_step(&_ASSERT_INFO); + + if (test->fixture.teardown != xnullptr) { + test->fixture.teardown(); + } + + fossil_test_io_unittest_ended(test); + fossil_test_environment_scoreboard(test); +} + +void fossil_test_environment_algorithms(fossil_env_t *env) { + if (env == xnullptr) { + return; + } + // Start the timer + env->timer.start = clock(); + + if (_CLI.shuffle_enabled) { + fossil_test_queue_shuffle(env->queue); + } + + if (_CLI.reverse) { + fossil_test_queue_reverse(env->queue); + } + + if (_CLI.only_tags) { + fossil_test_t *test = fossil_test_queue_search_by_tag(env->queue, _CLI.only_tags_value); + if (test != xnullptr) { + fossil_test_queue_erase(env->queue); + add_test_to_queue(test, env->queue); + } + } +} + +// Function to run the test environment +void fossil_test_environment_run(fossil_env_t *env) { + if (env == xnullptr) { + return; + } + // Apply the test environment algorithms for the given test cases + fossil_test_environment_algorithms(env); + + + + // Iterate through the test queue and run each test + fossil_test_t *current_test = env->queue->front; + while (current_test != xnullptr) { + // Run the test function + fossil_test_run_testcase(current_test); + + // Move to the next test + current_test = current_test->next; + } + + // Stop the timer + env->timer.end = clock(); + env->timer.elapsed = env->timer.end - env->timer.start; +} + +// Function to summarize the test environment +int fossil_test_environment_summary(void) { + fossil_test_io_summary_ended(); + int result = (_TEST_ENV.stats.expected_failed_count + + _TEST_ENV.stats.unexpected_failed_count + + _TEST_ENV.stats.unexpected_passed_count + + _TEST_ENV.stats.expected_timeout_count + + _TEST_ENV.stats.untested_count); + + return result; +} + +// Function to add a test to the test environment +void fossil_test_environment_add(fossil_env_t *env, fossil_test_t *test, fossil_fixture_t *fixture) { + if (test == xnullptr || env == xnullptr || env->queue == xnullptr) { + return; + } + + if (fixture != xnullptr) { + test->fixture.setup = fixture->setup; + test->fixture.teardown = fixture->teardown; + } + + // Update test statistics + add_test_to_queue(test, env->queue); + _TEST_ENV.stats.untested_count++; + fossil_test_io_sanity_load(test); +} + +// +// Feature function implementations +// + +// Function to apply a mark to a test case +void fossil_test_apply_mark(fossil_test_t *test, const char *mark) { + if (!test) { + return; + } else if (!mark) { + return; + } + + // we handle any rules for marks + if (strcmp(mark, "skip") == 0) { + test->marks = "skip"; + _TEST_ENV.rule.skipped = true; + } else if (strcmp(mark, "ghost") == 0) { + test->marks = "ghost"; // remember to call the ghostbusters whena team member marks an empty case. + } else if (strcmp(mark, "error") == 0) { + test->marks = "error"; + _TEST_ENV.rule.should_pass = false; + } else if (strcmp(mark, "fail") == 0){ + test->marks = "fail"; + _TEST_ENV.rule.should_pass = false; + } else if (strcmp(mark, "none") == 0) { + test->marks = "none"; + } else if (strcmp(mark, "only") == 0) { + test->marks = "only"; + } +} + +// Function to apply an extended tag to a test case +void fossil_test_apply_xtag(fossil_test_t *test, const char *tag) { + if (!test) { + return; + } else if (!tag) { + return; + } + + // we handle any rules for tags + // to be used in a run via tag feature. + if (strcmp(tag, "fast") == 0) { + test->tags = "fast"; + } else if (strcmp(tag, "slow") == 0) { + test->tags = "slow"; + } else if (strcmp(tag, "bug") == 0) { + test->tags = "bug"; + } else if (strcmp(tag, "feature") == 0) { + test->tags = "feature"; + } else if (strcmp(tag, "security") == 0) { + test->tags = "security"; + } else if (strcmp(tag, "performance") == 0) { + test->tags = "performance"; + } else if (strcmp(tag, "stress") == 0) { + test->tags = "stress"; + } else if (strcmp(tag, "regression") == 0) { + test->tags = "regression"; + } else if (strcmp(tag, "compatibility") == 0) { + test->tags = "compatibility"; + } else if (strcmp(tag, "usability") == 0) { + test->tags = "usability"; + } else if (strcmp(tag, "robustness") == 0) { + test->tags = "robustness"; + } else if (strcmp(tag, "corner case") == 0) { + test->tags = "corner case"; + } else if (strcmp(tag, "edge case") == 0) { + test->tags = "edge case"; + } else if (strcmp(tag, "boundary case") == 0) { + test->tags = "boundary case"; + } else if (strcmp(tag, "negative case") == 0) { + test->tags = "negative case"; + } else if (strcmp(tag, "positive case") == 0) { + test->tags = "positive case"; + } else if (strcmp(tag, "sanity") == 0) { + test->tags = "sanity"; + } else if (strcmp(tag, "smoke") == 0) { + test->tags = "smoke"; + } else if (strcmp(tag, "acceptance") == 0) { + test->tags = "acceptance"; + } else if (strcmp(tag, "regression") == 0) { + test->tags = "regression"; + } else if (strcmp(tag, "functional") == 0) { + test->tags = "functional"; + } else if (strcmp(tag, "integration") == 0) { + test->tags = "integration"; + } else if (strcmp(tag, "system") == 0) { + test->tags = "system"; + } else if (strcmp(tag, "end-to-end") == 0) { + test->tags = "end-to-end"; + } else if (strcmp(tag, "unit") == 0) { + test->tags = "unit"; + } else if (strcmp(tag, "component") == 0) { + test->tags = "component"; + } else if (strcmp(tag, "module") == 0) { + test->tags = "module"; + } else if (strcmp(tag, "api") == 0) { + test->tags = "api"; + } else if (strcmp(tag, "ui") == 0) { + test->tags = "ui"; + } else if (strcmp(tag, "usability") == 0) { + test->tags = "usability"; + } else if (strcmp(tag, "performance") == 0) { + test->tags = "performance"; + } else if (strcmp(tag, "security") == 0) { + test->tags = "security"; + } else if (strcmp(tag, "stress") == 0) { + test->tags = "stress"; + } +} + +// Function to apply a priority to a test case +void fossil_test_apply_priority(fossil_test_t *test, const char *priority) { + if (!test) { + return; + } else if (!priority) { + return; + } + + if (strcmp(priority, "lowest") == 0) { + test->priority = 0; + } else if (strcmp(priority, "very low") == 0) { + test->priority = 10; + } else if (strcmp(priority, "low") == 0) { + test->priority = 20; + } else if (strcmp(priority, "medium") == 0) { + test->priority = 50; + } else if (strcmp(priority, "high") == 0) { + test->priority = 70; + } else if (strcmp(priority, "very high") == 0) { + test->priority = 90; + } else if (strcmp(priority, "highest") == 0) { + test->priority = 100; + } else if (strcmp(priority, "urgent") == 0) { + test->priority = 95; + } else if (strcmp(priority, "critical") == 0) { + test->priority = 100; + } else if (strcmp(priority, "normal") == 0) { + test->priority = 50; + } else { + int priority_value = atoi(priority); + if (priority_value < 0 || priority_value > 100) { + return; + } + + test->priority = priority_value; + } +} + +// +// Assertion function implementations +// + +// Custom assumptions function with optional message. +void fossil_test_assert_impl_assume(bool expression, xassert_info *assume) { + if (_TEST_ENV.current_assume_count == FOSSIL_TEST_ASSUME_MAX) { + exit(FOSSIL_TEST_ABORT_FAIL); + return; + } + + if (!_ASSERT_INFO.should_fail) { + if (!expression) { + _TEST_ENV.rule.should_pass = false; + _TEST_ENV.current_assume_count++; + fossil_test_io_asserted(assume); + } + } else { + if (!expression) { + _TEST_ENV.rule.should_pass = true; + } else if (expression) { + _TEST_ENV.rule.should_pass = false; + _TEST_ENV.current_assume_count++; + fossil_test_io_asserted(assume); + } + } +} // end of func + +// Custom assertion function with optional message. +void fossil_test_assert_impl_assert(bool expression, xassert_info *assume) { + if (_ASSERT_INFO.should_fail) { + if (!expression) { + _TEST_ENV.rule.should_pass = true; + } else if (expression) { + _TEST_ENV.rule.should_pass = false; + fossil_test_io_asserted(assume); + exit(FOSSIL_TEST_ABORT_FAIL); + } + } else { + if (!expression) { + _TEST_ENV.rule.should_pass = false; + fossil_test_io_asserted(assume); + exit(FOSSIL_TEST_ABORT_FAIL); + } + } +} // end of func + +// Custom expectation function with optional message. +void fossil_test_assert_impl_expect(bool expression, xassert_info *assume) { + if (_ASSERT_INFO.should_fail) { + if (!expression) { + _TEST_ENV.rule.should_pass = true; + } else if (expression) { + _TEST_ENV.rule.should_pass = false; + fossil_test_io_asserted(assume); + } + } else { + if (!expression) { + _TEST_ENV.rule.should_pass = false; + fossil_test_io_asserted(assume); + } + } +} // end of func + +void _fossil_test_assert_class(bool expression, char* message, char* file, int line, char* func) { + + _ASSERT_INFO.func = func; + _ASSERT_INFO.file = file; + _ASSERT_INFO.line = line; + _ASSERT_INFO.message = message; + + fossil_test_assert_impl_assume(expression, &_ASSERT_INFO); + + _ASSERT_INFO.num_asserts++; // increment the number of asserts + _ASSERT_INFO.has_assert = true; // Make note of an assert being added in a given test case + + // Add the assertion to the history with its fingerprint + if (assert_history_count < MAX_ASSERT_HISTORY) { + assert_history[assert_history_count].expression = expression; + assert_history[assert_history_count].message = message; + assert_history[assert_history_count].file = file; + assert_history[assert_history_count].line = line; + assert_history[assert_history_count].func = func; + assert_history_count++; + } +} From d05b3356c1b0291914c88f1accdf7f1b65ecf58c Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Sat, 2 Nov 2024 12:08:47 -0500 Subject: [PATCH 03/40] place single header and source files --- code/logic/fossil/unittest/unittest.h | 263 ++++++++ code/logic/unittest/unittest.c | 866 ++++---------------------- 2 files changed, 389 insertions(+), 740 deletions(-) create mode 100644 code/logic/fossil/unittest/unittest.h diff --git a/code/logic/fossil/unittest/unittest.h b/code/logic/fossil/unittest/unittest.h new file mode 100644 index 00000000..a576e2a8 --- /dev/null +++ b/code/logic/fossil/unittest/unittest.h @@ -0,0 +1,263 @@ +/* + * ----------------------------------------------------------------------------- + * Project: Fossil Logic + * + * This file is part of the Fossil Logic project, which aims to develop high- + * performance, cross-platform applications and libraries. The code contained + * herein is subject to the terms and conditions defined in the project license. + * + * Author: Michael Gene Brockus (Dreamer) + * Date: 07/01/2024 + * + * Copyright (C) 2024 Fossil Logic. All rights reserved. + * ----------------------------------------------------------------------------- + */ +#ifndef FOSSIL_TEST_CORE_H +#define FOSSIL_TEST_CORE_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// ANSI color codes for output +#define FOSSIL_TEST_COLOR_RESET "\033[0m" +#define FOSSIL_TEST_COLOR_GREEN "\033[32m" +#define FOSSIL_TEST_COLOR_RED "\033[31m" +#define FOSSIL_TEST_COLOR_YELLOW "\033[33m" +#define FOSSIL_TEST_COLOR_BLUE "\033[34m" + +// Enumeration for test result types +typedef enum { + FOSSIL_TEST_PASS, + FOSSIL_TEST_FAIL, + FOSSIL_TEST_SKIP, + FOSSIL_TEST_UNEXPECTED, + FOSSIL_TEST_EXPECTED_FAIL, // New result type + FOSSIL_TEST_IGNORED // New result type +} fossil_test_result_t; + +// Structure to store individual test case information +typedef struct fossil_test_case { + const char *name; + fossil_test_result_t result; + void (*test_func)(void); + double duration; // Duration for this test case + bool is_expected_fail; // Flag for expected failures + bool is_ignored; // Flag for ignored tests +} fossil_test_case_t; + +// Structure for test suite +typedef struct fossil_test_suite { + const char *name; + fossil_test_case_t **tests; + size_t test_count; +} fossil_test_suite_t; + +// Priority Queue Node for Double-Ended Priority Queue +typedef struct fossil_test_node { + fossil_test_case_t *test_case; + struct fossil_test_node *next; + struct fossil_test_node *prev; +} fossil_test_node_t; + +// Double-Ended Priority Queue for Test Runner +typedef struct fossil_test_queue { + fossil_test_node_t *head; + fossil_test_node_t *tail; + size_t count; +} fossil_test_queue_t; + +// Stack for storing failure trace +typedef struct { + const char *stack[256]; + int top; +} fossil_test_stack_t; + +// Summary structure to track test results +typedef struct { + size_t passed; + size_t failed; + size_t skipped; + size_t unexpected; + size_t expected_failed; + size_t ignored; +} fossil_test_result_summary_t; + +// Jump buffer for error handling +extern jmp_buf fossil_test_env; // Declare the jump buffer +extern fossil_test_stack_t fossil_test_stack; // Declare the stack for failure trace + +/** + * Initialize the test queue. + * + * @param queue Pointer to the test queue to initialize. + */ +void fossil_test_queue_init(fossil_test_queue_t *queue); + +/** + * Enqueue a test case into the test queue. + * + * @param queue Pointer to the test queue. + * @param test_case Pointer to the test case to enqueue. + */ +void fossil_test_enqueue(fossil_test_queue_t *queue, fossil_test_case_t *test_case); + +/** + * Dequeue a test case from the test queue. + * + * @param queue Pointer to the test queue. + * @return Pointer to the dequeued test case. + */ +fossil_test_case_t *fossil_test_dequeue(fossil_test_queue_t *queue); + +/** + * Free the memory allocated for the test queue. + * + * @param queue Pointer to the test queue to free. + */ +void fossil_test_queue_free(fossil_test_queue_t *queue); + +/** + * Push a trace message onto the failure stack. + * + * @param stack Pointer to the failure stack. + * @param trace Trace message to push onto the stack. + */ +void fossil_test_stack_push(fossil_test_stack_t *stack, const char *trace); + +/** + * Print the contents of the failure stack. + * + * @param stack Pointer to the failure stack to print. + */ +void fossil_test_stack_print(const fossil_test_stack_t *stack); + +/** + * Handle a caught error by printing the error message and the failure stack. + * + * @param stack Pointer to the failure stack. + * @param error_msg Error message to print. + */ +void fossil_test_catch(fossil_test_stack_t *stack, const char *error_msg); + +/** + * Run all test cases in the test queue. + * + * @param queue Pointer to the test queue. + * @param stack Pointer to the failure stack. + * @param summary Pointer to the summary structure to track test results. + * @param verbose Flag to enable verbose output. + */ +void fossil_test_run(fossil_test_queue_t *queue, fossil_test_stack_t *stack, fossil_test_result_summary_t *summary, bool verbose); + +/** + * Print the summary of test results. + * + * @param summary Pointer to the summary structure containing test results. + */ +void fossil_test_summary(const fossil_test_result_summary_t *summary); + +/** + * Add a test case to a test suite. + * + * @param suite Pointer to the test suite. + * @param test_case Pointer to the test case to add. + */ +void fossil_test_add_suite(fossil_test_suite_t *suite, fossil_test_case_t *test_case); + +/** + * Run all test cases in a test suite. + * + * @param suite Pointer to the test suite. + * @param stack Pointer to the failure stack. + * @param summary Pointer to the summary structure to track test results. + * @param verbose Flag to enable verbose output. + */ +void fossil_test_run_suite(fossil_test_suite_t *suite, fossil_test_stack_t *stack, fossil_test_result_summary_t *summary, bool verbose); + +/** + * Set the setup function to be called before each test case. + * + * @param setup_func Pointer to the setup function. + */ +void fossil_test_setup(void (*setup_func)(void)); + +/** + * Set the teardown function to be called after each test case. + * + * @param teardown_func Pointer to the teardown function. + */ +void fossil_test_teardown(void (*teardown_func)(void)); + +// Macros for defining and adding test cases +#define FOSSIL_TEST_DEFINE(name) void name(void) +#define FOSSIL_TEST_ADD(queue, test_func) \ + do { \ + fossil_test_case_t *test_case = malloc(sizeof(fossil_test_case_t)); \ + test_case->name = #test_func; \ + test_case->test_func = test_func; \ + test_case->result = FOSSIL_TEST_SKIP; \ + test_case->duration = 0.0; \ + test_case->is_expected_fail = false; \ + test_case->is_ignored = false; \ + fossil_test_enqueue(queue, test_case); \ + } while(0) + +#define FOSSIL_TEST_EXPECT_FAIL(test_func) \ + do { \ + fossil_test_case_t *test_case = malloc(sizeof(fossil_test_case_t)); \ + test_case->name = #test_func; \ + test_case->test_func = test_func; \ + test_case->result = FOSSIL_TEST_EXPECTED_FAIL; \ + test_case->duration = 0.0; \ + test_case->is_expected_fail = true; \ + test_case->is_ignored = false; \ + fossil_test_enqueue(queue, test_case); \ + } while(0) + +#define FOSSIL_TEST_IGNORE(test_func) \ + do { \ + fossil_test_case_t *test_case = malloc(sizeof(fossil_test_case_t)); \ + test_case->name = #test_func; \ + test_case->test_func = test_func; \ + test_case->result = FOSSIL_TEST_IGNORED; \ + test_case->duration = 0.0; \ + test_case->is_expected_fail = false; \ + test_case->is_ignored = true; \ + fossil_test_enqueue(queue, test_case); \ + } while(0) + +// Assertion Macro +#define FOSSIL_TEST_ASSERT(cond, msg, line, func, file) \ + do { \ + if (!(cond)) { \ + char formatted_msg[256]; \ + snprintf(formatted_msg, sizeof(formatted_msg), "%s (at %s:%d in %s)", msg, file, line, func); \ + fossil_test_stack_push(fossil_test_stack, formatted_msg); \ + fossil_test_catch(fossil_test_stack, "Assertion failed"); \ + } \ + } while(0) + +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus +#include +#include + +namespace fossil { + +} +#endif + +#endif diff --git a/code/logic/unittest/unittest.c b/code/logic/unittest/unittest.c index ede63711..5fd380d4 100644 --- a/code/logic/unittest/unittest.c +++ b/code/logic/unittest/unittest.c @@ -12,798 +12,184 @@ * Copyright (C) 2024 Fossil Logic. All rights reserved. * ----------------------------------------------------------------------------- */ -#include "fossil/unittest/framework.h" -#include "fossil/_common/common.h" -#include "fossil/unittest/console.h" -#include "fossil/unittest/commands.h" -#include +#include "fossil/unittest/unittest.h" +#include +#include +#include +#include +#include -#define MAX_ASSERT_HISTORY 100 +jmp_buf fossil_test_env; +fossil_test_stack_t fossil_test_stack; // Declare the stack for failure trace -typedef struct { - bool expression; - xassert_type_t behavior; - char* message; - char* file; - int line; - unsigned long fingerprint; - char* func; -} assert_history_t; +static void (*setup_func)(void) = NULL; +static void (*teardown_func)(void) = NULL; -static assert_history_t assert_history[MAX_ASSERT_HISTORY]; -static int assert_history_count = 0; - -fossil_env_t _TEST_ENV; -xassert_info _ASSERT_INFO; - -fossil_test_queue_t* fossil_test_queue_create(void) { - fossil_test_queue_t* queue = (fossil_test_queue_t*)malloc(sizeof(fossil_test_queue_t)); - if (queue != xnullptr) { - queue->front = xnullptr; - queue->rear = xnullptr; - } else { - // Handle memory allocation failure - perror("Failed to allocate memory for queue"); - return xnullptr; - } - return queue; +void fossil_test_queue_init(fossil_test_queue_t *queue) { + queue->head = NULL; + queue->tail = NULL; + queue->count = 0; } -void fossil_test_queue_erase(fossil_test_queue_t* queue) { - fossil_test_t* current = queue->front; - fossil_test_t* next; - - while (current != xnullptr) { - next = current->next; - free(current); - current = next; - } - - queue->front = xnullptr; - queue->rear = xnullptr; -} - -// Function to add a test to the front of the queue -void fossil_test_queue_push_front(fossil_test_t *test, fossil_test_queue_t *queue) { - if (test == xnullptr || queue == xnullptr) { - return; - } - - if (queue->front == xnullptr) { - // The queue is empty - queue->front = test; - queue->rear = test; - } else { - // Insert test at the front - test->next = queue->front; - queue->front->prev = test; - queue->front = test; - } - test->prev = xnullptr; // Ensure previous pointer of new front is NULL -} +void fossil_test_enqueue(fossil_test_queue_t *queue, fossil_test_case_t *test_case) { + fossil_test_node_t *node = malloc(sizeof(fossil_test_node_t)); + node->test_case = test_case; + node->next = NULL; + node->prev = queue->tail; -// Function to add a test to the rear of the queue -void fossil_test_queue_push_back(fossil_test_t *test, fossil_test_queue_t *queue) { - if (test == xnullptr || queue == xnullptr) { - return; + if (queue->tail) { + queue->tail->next = node; } + queue->tail = node; - if (queue->rear == xnullptr) { - // The queue is empty - queue->front = test; - queue->rear = test; - } else { - // Insert test at the rear - queue->rear->next = test; - test->prev = queue->rear; - queue->rear = test; + if (!queue->head) { + queue->head = node; } - test->next = xnullptr; // Ensure next pointer of new rear is NULL + queue->count++; } -// Function to remove and return the test from the front of the queue -fossil_test_t* fossil_test_queue_pop_front(fossil_test_queue_t *queue) { - if (queue == xnullptr || queue->front == xnullptr) { - return xnullptr; +fossil_test_case_t *fossil_test_dequeue(fossil_test_queue_t *queue) { + if (!queue->head) { + return NULL; } - fossil_test_t *front_test = queue->front; + fossil_test_node_t *node = queue->head; + fossil_test_case_t *test_case = node->test_case; + queue->head = node->next; - if (queue->front == queue->rear) { - // The queue has only one test - queue->front = xnullptr; - queue->rear = xnullptr; + if (queue->head) { + queue->head->prev = NULL; } else { - // Remove test from the front - queue->front = queue->front->next; - queue->front->prev = xnullptr; + queue->tail = NULL; } - return front_test; + free(node); + queue->count--; + return test_case; } -// Function to remove and return the test from the rear of the queue -fossil_test_t* fossil_test_queue_pop_back(fossil_test_queue_t *queue) { - if (queue == xnullptr || queue->rear == xnullptr) { - return xnullptr; +void fossil_test_queue_free(fossil_test_queue_t *queue) { + while (queue->head) { + free(fossil_test_dequeue(queue)); } - - fossil_test_t *rear_test = queue->rear; - - if (queue->front == queue->rear) { - // The queue has only one test - queue->front = xnullptr; - queue->rear = xnullptr; - } else { - // Remove test from the rear - queue->rear = queue->rear->prev; - queue->rear->next = xnullptr; - } - - return rear_test; -} - -// Function to add a test to the queue based on priority -void add_test_to_queue(fossil_test_t *test, fossil_test_queue_t *queue) { - fossil_test_queue_push_back(test, queue); } -// Function to remove and return the test with the highest priority from the queue -fossil_test_t* get_highest_priority_test(fossil_test_queue_t *queue) { - // In this implementation, the test with the highest priority is the one at the front of the queue - return fossil_test_queue_pop_front(queue); -} - -// Function to remove and return the test with the lowest priority from the queue -fossil_test_t* get_lowest_priority_test(fossil_test_queue_t *queue) { - // In this implementation, the test with the lowest priority is the one at the rear of the queue - return fossil_test_queue_pop_back(queue); -} - -// Function to search for a test by tag in the queue -fossil_test_t* fossil_test_queue_search_by_tag(fossil_test_queue_t *queue, const char *tag) { - if (queue == xnullptr || tag == xnullptr) { - return xnullptr; +void fossil_test_stack_push(fossil_test_stack_t *stack, const char *trace) { + if (stack->top < 255) { + stack->stack[stack->top++] = trace; } - - fossil_test_t *current = queue->front; - while (current != xnullptr) { - if (strcmp(current->tags, tag) == 0) { - return current; - } - current = current->next; - } - return xnullptr; } -// Function to search for a test by name in the queue -fossil_test_t* fossil_test_queue_search_by_name(fossil_test_queue_t *queue, const char *name) { - if (queue == xnullptr || name == xnullptr) { - return xnullptr; +void fossil_test_stack_print(const fossil_test_stack_t *stack) { + printf("Stack Trace:\n"); + for (int i = 0; i < stack->top; i++) { + printf(" %s\n", stack->stack[i]); } - - fossil_test_t *current = queue->front; - while (current != xnullptr) { - if (strcmp(current->name, name) == 0) { - return current; - } - current = current->next; - } - return xnullptr; } -void fossil_test_queue_reverse(fossil_test_queue_t *queue) { - if (queue == xnullptr) { - return; - } - - fossil_test_t *current = queue->front; - fossil_test_t *temp = xnullptr; - - // Swap the next and prev pointers for each node - while (current != xnullptr) { - temp = current->prev; - current->prev = current->next; - current->next = temp; - current = current->prev; - } - - // Swap the front and rear pointers of the queue - if (temp != xnullptr) { - temp = queue->front; - queue->front = queue->rear; - queue->rear = temp; - } +void fossil_test_catch(fossil_test_stack_t *stack, const char *error_msg) { + printf(FOSSIL_TEST_COLOR_RED "Error: %s\n" FOSSIL_TEST_COLOR_RESET, error_msg); + longjmp(fossil_test_env, 1); } -// Function to convert queue to an array -fossil_test_t** queue_to_array(fossil_test_queue_t *queue, int *size) { - if (queue == xnullptr) { - return xnullptr; - } - - int count = 0; - fossil_test_t *current = queue->front; - while (current != xnullptr) { - count++; - current = current->next; - } - - fossil_test_t **array = (fossil_test_t**)malloc(count * sizeof(fossil_test_t*)); - current = queue->front; - for (int i = 0; i < count; i++) { - array[i] = current; - current = current->next; - } +void fossil_test_run(fossil_test_queue_t *queue, fossil_test_stack_t *stack, fossil_test_result_summary_t *summary, bool verbose) { + fossil_test_case_t *test_case; + while ((test_case = fossil_test_dequeue(queue))) { + if (setup_func) setup_func(); // Call setup if defined - *size = count; - return array; -} - -// Function to convert array to a queue -void array_to_queue(fossil_test_t **array, int size, fossil_test_queue_t *queue) { - if (queue == xnullptr || array == xnullptr) { - return; - } - - queue->front = xnullptr; - queue->rear = xnullptr; - - for (int i = 0; i < size; i++) { - array[i]->next = xnullptr; - array[i]->prev = xnullptr; - fossil_test_queue_push_back(array[i], queue); - } -} - -// Fisher-Yates shuffle algorithm -void fossil_test_queue_shuffle(fossil_test_queue_t *queue) { - if (queue == xnullptr) { - return; - } - - int size; - fossil_test_t **array = queue_to_array(queue, &size); - if (array == xnullptr) { - return; - } - - srand(time(xnullptr)); - for (int i = size - 1; i > 0; i--) { - int j = rand() % (i + 1); - fossil_test_t *temp = array[i]; - array[i] = array[j]; - array[j] = temp; - } - - array_to_queue(array, size, queue); - free(array); -} - -// -// Fossil Test Environment functions -// - -void fossil_test_environment_erase(void) { - if (_TEST_ENV.queue != xnullptr) { - free(_TEST_ENV.queue); // Fix memory leak by uncommenting free statement - } -} - -fossil_env_t fossil_test_environment_create(int argc, char **argv) { - _CLI = fossil_options_parse(argc, argv); - fossil_test_io_information(); // checkpoint for simple commands - - fossil_env_t env; - - // Initialize test statistics - env.stats.expected_passed_count = 0; - env.stats.expected_failed_count = 0; - env.stats.unexpected_passed_count = 0; - env.stats.unexpected_failed_count = 0; - env.stats.expected_skipped_count = 0; - env.stats.expected_empty_count = 0; - env.stats.expected_timeout_count = 0; - env.stats.expected_total_count = 0; - env.stats.untested_count = 0; - - // Initialize test rules - env.rule.should_pass = true; - env.rule.skipped = false; - env.rule.timeout = false; - env.rule.error = false; - - // Initialize test timer - env.timer.start = 0; - env.timer.end = 0; - env.timer.elapsed = 0; - env.timer.detail.minutes = 0; - env.timer.detail.seconds = 0; - env.timer.detail.milliseconds = 0; - env.timer.detail.microseconds = 0; - env.timer.detail.nanoseconds = 0; - - // Initialize test queue - env.queue = fossil_test_queue_create(); - atexit(fossil_test_environment_erase); // ensure memory leaks do not occur - - // Initialize exception and assumption counts - env.current_except_count = 0; - env.current_assume_count = 0; - - fossil_test_io_summary_start(); - - return env; -} - -void _fossil_test_scoreboard_update(void) { - // here we just update the scoreboard count - // add one to total tested cases and remove - // one from untested ghost cases. - // - // The main goal is to ensure ghost cases are removed - // accordingly and the total tested cases are updated. - // - // However in the event exit is called we will have - // record of test that are tested and those that are - // not tested. - _TEST_ENV.stats.untested_count--; - _TEST_ENV.stats.expected_total_count++; -} - -void _fossil_test_scoreboard_expected_rules(void) { - if (!_TEST_ENV.rule.should_pass) { - _TEST_ENV.stats.expected_failed_count++; - _TEST_ENV.rule.should_pass = false; - } else { - _TEST_ENV.stats.expected_passed_count++; - } -} - -void _fossil_test_scoreboard_unexpected_rules(void) { - if (_TEST_ENV.rule.should_pass) { - _TEST_ENV.stats.unexpected_failed_count++; - } else { - _TEST_ENV.stats.unexpected_passed_count++; - } -} - -void _fossil_test_scoreboard_feature_rules(fossil_test_t *test_case) { - if (_TEST_ENV.rule.skipped && strcmp(test_case->marks, "skip") == 0) { - _TEST_ENV.stats.expected_skipped_count++; - _TEST_ENV.rule.skipped = false; - } else if (!_ASSERT_INFO.has_assert && strcmp(test_case->marks, "tofu") != 0) { - _TEST_ENV.stats.expected_empty_count++; - } else if (!_TEST_ENV.rule.should_pass && strcmp(test_case->marks, "fail") == 0) { - if (_ASSERT_INFO.should_fail) { - _fossil_test_scoreboard_expected_rules(); + clock_t start_time = clock(); + if (setjmp(fossil_test_env) == 0) { + test_case->test_func(); + test_case->result = FOSSIL_TEST_PASS; } else { - _fossil_test_scoreboard_unexpected_rules(); + test_case->result = test_case->is_expected_fail ? FOSSIL_TEST_EXPECTED_FAIL : FOSSIL_TEST_FAIL; } - } else { - _TEST_ENV.stats.expected_passed_count++; - } -} - -void fossil_test_environment_scoreboard(fossil_test_t *test) { - // for the first part we check if the given test case - // has any feature flags or rules triggered. - if (strcmp(test->marks, "fossil") != 0) { - _fossil_test_scoreboard_feature_rules(test); - } else { - _fossil_test_scoreboard_expected_rules(); - } - - // we just need to update the total scoreboard - // so it is accurate for the fossil test. - _fossil_test_scoreboard_update(); - _TEST_ENV.rule.should_pass = true; // reset counter for next test -} - -void fossil_test_run_testcase(fossil_test_t *test) { - if (test == xnullptr) { - return; - } - // set and reset step for assert scanning - _ASSERT_INFO.has_assert = false; - _ASSERT_INFO.should_fail = false; - _ASSERT_INFO.shoudl_timeout = false; - _ASSERT_INFO.num_asserts = 0; - _ASSERT_INFO.same_assert = false; - - if (_TEST_ENV.rule.skipped && strcmp(test->marks, "skip") == 0) { - return; - } else if (!_ASSERT_INFO.should_fail && strcmp(test->marks, "fail") == 0) { - _ASSERT_INFO.should_fail = true; - } - - fossil_test_io_unittest_start(test); - if (test->fixture.setup != xnullptr) { - test->fixture.setup(); - } - - // Run the test function - for (int32_t iter = 0; iter < _CLI.repeat_count; iter++) { - test->test_function(); - } - fossil_test_io_unittest_step(&_ASSERT_INFO); - - if (test->fixture.teardown != xnullptr) { - test->fixture.teardown(); - } - - fossil_test_io_unittest_ended(test); - fossil_test_environment_scoreboard(test); -} - -void fossil_test_environment_algorithms(fossil_env_t *env) { - if (env == xnullptr) { - return; - } - // Start the timer - env->timer.start = clock(); - - if (_CLI.shuffle_enabled) { - fossil_test_queue_shuffle(env->queue); - } - - if (_CLI.reverse) { - fossil_test_queue_reverse(env->queue); - } - - if (_CLI.only_tags) { - fossil_test_t *test = fossil_test_queue_search_by_tag(env->queue, _CLI.only_tags_value); - if (test != xnullptr) { - fossil_test_queue_erase(env->queue); - add_test_to_queue(test, env->queue); + clock_t end_time = clock(); + + test_case->duration = (double)(end_time - start_time) / CLOCKS_PER_SEC; + + if (verbose) { + printf("%s: %s (%.2f seconds)\n", test_case->name, + test_case->result == FOSSIL_TEST_PASS ? FOSSIL_TEST_COLOR_GREEN "PASS" FOSSIL_TEST_COLOR_RESET : + test_case->result == FOSSIL_TEST_FAIL ? FOSSIL_TEST_COLOR_RED "FAIL" FOSSIL_TEST_COLOR_RESET : + test_case->result == FOSSIL_TEST_SKIP ? FOSSIL_TEST_COLOR_YELLOW "SKIP" FOSSIL_TEST_COLOR_RESET : + test_case->result == FOSSIL_TEST_EXPECTED_FAIL ? FOSSIL_TEST_COLOR_BLUE "EXPECTED FAIL" FOSSIL_TEST_COLOR_RESET : + FOSSIL_TEST_COLOR_YELLOW "IGNORED" FOSSIL_TEST_COLOR_RESET, + test_case->duration); } - } -} - -// Function to run the test environment -void fossil_test_environment_run(fossil_env_t *env) { - if (env == xnullptr) { - return; - } - // Apply the test environment algorithms for the given test cases - fossil_test_environment_algorithms(env); - - - - // Iterate through the test queue and run each test - fossil_test_t *current_test = env->queue->front; - while (current_test != xnullptr) { - // Run the test function - fossil_test_run_testcase(current_test); - - // Move to the next test - current_test = current_test->next; - } - - // Stop the timer - env->timer.end = clock(); - env->timer.elapsed = env->timer.end - env->timer.start; -} - -// Function to summarize the test environment -int fossil_test_environment_summary(void) { - fossil_test_io_summary_ended(); - int result = (_TEST_ENV.stats.expected_failed_count + - _TEST_ENV.stats.unexpected_failed_count + - _TEST_ENV.stats.unexpected_passed_count + - _TEST_ENV.stats.expected_timeout_count + - _TEST_ENV.stats.untested_count); - return result; -} - -// Function to add a test to the test environment -void fossil_test_environment_add(fossil_env_t *env, fossil_test_t *test, fossil_fixture_t *fixture) { - if (test == xnullptr || env == xnullptr || env->queue == xnullptr) { - return; - } - - if (fixture != xnullptr) { - test->fixture.setup = fixture->setup; - test->fixture.teardown = fixture->teardown; - } - - // Update test statistics - add_test_to_queue(test, env->queue); - _TEST_ENV.stats.untested_count++; - fossil_test_io_sanity_load(test); -} - -// -// Feature function implementations -// - -// Function to apply a mark to a test case -void fossil_test_apply_mark(fossil_test_t *test, const char *mark) { - if (!test) { - return; - } else if (!mark) { - return; - } + switch (test_case->result) { + case FOSSIL_TEST_PASS: summary->passed++; break; + case FOSSIL_TEST_FAIL: summary->failed++; break; + case FOSSIL_TEST_SKIP: summary->skipped++; break; + case FOSSIL_TEST_UNEXPECTED: summary->unexpected++; break; + case FOSSIL_TEST_EXPECTED_FAIL: summary->expected_failed++; break; + case FOSSIL_TEST_IGNORED: summary->ignored++; break; + } - // we handle any rules for marks - if (strcmp(mark, "skip") == 0) { - test->marks = "skip"; - _TEST_ENV.rule.skipped = true; - } else if (strcmp(mark, "ghost") == 0) { - test->marks = "ghost"; // remember to call the ghostbusters whena team member marks an empty case. - } else if (strcmp(mark, "error") == 0) { - test->marks = "error"; - _TEST_ENV.rule.should_pass = false; - } else if (strcmp(mark, "fail") == 0){ - test->marks = "fail"; - _TEST_ENV.rule.should_pass = false; - } else if (strcmp(mark, "none") == 0) { - test->marks = "none"; - } else if (strcmp(mark, "only") == 0) { - test->marks = "only"; + if (teardown_func) teardown_func(); // Call teardown if defined + free(test_case); // Free allocated test case } } -// Function to apply an extended tag to a test case -void fossil_test_apply_xtag(fossil_test_t *test, const char *tag) { - if (!test) { - return; - } else if (!tag) { - return; - } - - // we handle any rules for tags - // to be used in a run via tag feature. - if (strcmp(tag, "fast") == 0) { - test->tags = "fast"; - } else if (strcmp(tag, "slow") == 0) { - test->tags = "slow"; - } else if (strcmp(tag, "bug") == 0) { - test->tags = "bug"; - } else if (strcmp(tag, "feature") == 0) { - test->tags = "feature"; - } else if (strcmp(tag, "security") == 0) { - test->tags = "security"; - } else if (strcmp(tag, "performance") == 0) { - test->tags = "performance"; - } else if (strcmp(tag, "stress") == 0) { - test->tags = "stress"; - } else if (strcmp(tag, "regression") == 0) { - test->tags = "regression"; - } else if (strcmp(tag, "compatibility") == 0) { - test->tags = "compatibility"; - } else if (strcmp(tag, "usability") == 0) { - test->tags = "usability"; - } else if (strcmp(tag, "robustness") == 0) { - test->tags = "robustness"; - } else if (strcmp(tag, "corner case") == 0) { - test->tags = "corner case"; - } else if (strcmp(tag, "edge case") == 0) { - test->tags = "edge case"; - } else if (strcmp(tag, "boundary case") == 0) { - test->tags = "boundary case"; - } else if (strcmp(tag, "negative case") == 0) { - test->tags = "negative case"; - } else if (strcmp(tag, "positive case") == 0) { - test->tags = "positive case"; - } else if (strcmp(tag, "sanity") == 0) { - test->tags = "sanity"; - } else if (strcmp(tag, "smoke") == 0) { - test->tags = "smoke"; - } else if (strcmp(tag, "acceptance") == 0) { - test->tags = "acceptance"; - } else if (strcmp(tag, "regression") == 0) { - test->tags = "regression"; - } else if (strcmp(tag, "functional") == 0) { - test->tags = "functional"; - } else if (strcmp(tag, "integration") == 0) { - test->tags = "integration"; - } else if (strcmp(tag, "system") == 0) { - test->tags = "system"; - } else if (strcmp(tag, "end-to-end") == 0) { - test->tags = "end-to-end"; - } else if (strcmp(tag, "unit") == 0) { - test->tags = "unit"; - } else if (strcmp(tag, "component") == 0) { - test->tags = "component"; - } else if (strcmp(tag, "module") == 0) { - test->tags = "module"; - } else if (strcmp(tag, "api") == 0) { - test->tags = "api"; - } else if (strcmp(tag, "ui") == 0) { - test->tags = "ui"; - } else if (strcmp(tag, "usability") == 0) { - test->tags = "usability"; - } else if (strcmp(tag, "performance") == 0) { - test->tags = "performance"; - } else if (strcmp(tag, "security") == 0) { - test->tags = "security"; - } else if (strcmp(tag, "stress") == 0) { - test->tags = "stress"; - } +void fossil_test_summary(const fossil_test_result_summary_t *summary) { + printf("Test Summary:\n"); + printf(" Passed: %zu\n", summary->passed); + printf(" Failed: %zu\n", summary->failed); + printf(" Skipped: %zu\n", summary->skipped); + printf(" Unexpected: %zu\n", summary->unexpected); + printf(" Expected Failures: %zu\n", summary->expected_failed); + printf(" Ignored: %zu\n", summary->ignored); } -// Function to apply a priority to a test case -void fossil_test_apply_priority(fossil_test_t *test, const char *priority) { - if (!test) { - return; - } else if (!priority) { - return; - } - - if (strcmp(priority, "lowest") == 0) { - test->priority = 0; - } else if (strcmp(priority, "very low") == 0) { - test->priority = 10; - } else if (strcmp(priority, "low") == 0) { - test->priority = 20; - } else if (strcmp(priority, "medium") == 0) { - test->priority = 50; - } else if (strcmp(priority, "high") == 0) { - test->priority = 70; - } else if (strcmp(priority, "very high") == 0) { - test->priority = 90; - } else if (strcmp(priority, "highest") == 0) { - test->priority = 100; - } else if (strcmp(priority, "urgent") == 0) { - test->priority = 95; - } else if (strcmp(priority, "critical") == 0) { - test->priority = 100; - } else if (strcmp(priority, "normal") == 0) { - test->priority = 50; - } else { - int priority_value = atoi(priority); - if (priority_value < 0 || priority_value > 100) { - return; - } - - test->priority = priority_value; - } +void fossil_test_add_suite(fossil_test_suite_t *suite, fossil_test_case_t *test_case) { + suite->tests = realloc(suite->tests, sizeof(fossil_test_case_t *) * (suite->test_count + 1)); + suite->tests[suite->test_count++] = test_case; } -// -// Assertion function implementations -// +void fossil_test_run_suite(fossil_test_suite_t *suite, fossil_test_stack_t *stack, fossil_test_result_summary_t *summary, bool verbose) { + for (size_t i = 0; i < suite->test_count; i++) { + fossil_test_case_t *test_case = suite->tests[i]; + if (setup_func) setup_func(); // Call setup if defined -// Custom assumptions function with optional message. -void fossil_test_assert_impl_assume(bool expression, xassert_info *assume) { - if (_TEST_ENV.current_assume_count == FOSSIL_TEST_ASSUME_MAX) { - exit(FOSSIL_TEST_ABORT_FAIL); - return; - } - - if (!_ASSERT_INFO.should_fail) { - if (!expression) { - _TEST_ENV.rule.should_pass = false; - _TEST_ENV.current_assume_count++; - fossil_test_io_asserted(assume); - } - } else { - if (!expression) { - _TEST_ENV.rule.should_pass = true; - } else if (expression) { - _TEST_ENV.rule.should_pass = false; - _TEST_ENV.current_assume_count++; - fossil_test_io_asserted(assume); - } - } -} // end of func - -// Custom assertion function with optional message. -void fossil_test_assert_impl_assert(bool expression, xassert_info *assume) { - if (_ASSERT_INFO.should_fail) { - if (!expression) { - _TEST_ENV.rule.should_pass = true; - } else if (expression) { - _TEST_ENV.rule.should_pass = false; - fossil_test_io_asserted(assume); - exit(FOSSIL_TEST_ABORT_FAIL); + clock_t start_time = clock(); + if (setjmp(fossil_test_env) == 0) { + test_case->test_func(); + test_case->result = FOSSIL_TEST_PASS; + } else { + test_case->result = test_case->is_expected_fail ? FOSSIL_TEST_EXPECTED_FAIL : FOSSIL_TEST_FAIL; } - } else { - if (!expression) { - _TEST_ENV.rule.should_pass = false; - fossil_test_io_asserted(assume); - exit(FOSSIL_TEST_ABORT_FAIL); + clock_t end_time = clock(); + + test_case->duration = (double)(end_time - start_time) / CLOCKS_PER_SEC; + + if (verbose) { + printf("%s: %s (%.2f seconds)\n", test_case->name, + test_case->result == FOSSIL_TEST_PASS ? FOSSIL_TEST_COLOR_GREEN "PASS" FOSSIL_TEST_COLOR_RESET : + test_case->result == FOSSIL_TEST_FAIL ? FOSSIL_TEST_COLOR_RED "FAIL" FOSSIL_TEST_COLOR_RESET : + test_case->result == FOSSIL_TEST_SKIP ? FOSSIL_TEST_COLOR_YELLOW "SKIP" FOSSIL_TEST_COLOR_RESET : + test_case->result == FOSSIL_TEST_EXPECTED_FAIL ? FOSSIL_TEST_COLOR_BLUE "EXPECTED FAIL" FOSSIL_TEST_COLOR_RESET : + FOSSIL_TEST_COLOR_YELLOW "IGNORED" FOSSIL_TEST_COLOR_RESET, + test_case->duration); } - } -} // end of func -// Custom expectation function with optional message. -void fossil_test_assert_impl_expect(bool expression, xassert_info *assume) { - if (_ASSERT_INFO.should_fail) { - if (!expression) { - _TEST_ENV.rule.should_pass = true; - } else if (expression) { - _TEST_ENV.rule.should_pass = false; - fossil_test_io_asserted(assume); - } - } else { - if (!expression) { - _TEST_ENV.rule.should_pass = false; - fossil_test_io_asserted(assume); + switch (test_case->result) { + case FOSSIL_TEST_PASS: summary->passed++; break; + case FOSSIL_TEST_FAIL: summary->failed++; break; + case FOSSIL_TEST_SKIP: summary->skipped++; break; + case FOSSIL_TEST_UNEXPECTED: summary->unexpected++; break; + case FOSSIL_TEST_EXPECTED_FAIL: summary->expected_failed++; break; + case FOSSIL_TEST_IGNORED: summary->ignored++; break; } - } -} // end of func -bool is_assert_in_history(bool expression, xassert_type_t behavior, char* message, char* file, int line, char* func) { - for (int i = 0; i < assert_history_count; i++) { - if (assert_history[i].expression == expression && - assert_history[i].behavior == behavior && - strcmp(assert_history[i].message, message) == 0 && - strcmp(assert_history[i].file, file) == 0 && - assert_history[i].line == line && - strcmp(assert_history[i].func, func) == 0) { - return true; - } + if (teardown_func) teardown_func(); // Call teardown if defined } - return false; } -unsigned long generate_fingerprint(bool expression, xassert_type_t behavior, char* message, char* file, int line, char* func) { - unsigned long hash = 5381; - int c; - - hash = ((hash << 5) + hash) + expression; - hash = ((hash << 5) + hash) + behavior; - - while ((c = *message++)) - hash = ((hash << 5) + hash) + c; - - while ((c = *file++)) - hash = ((hash << 5) + hash) + c; - - hash = ((hash << 5) + hash) + line; - - while ((c = *func++)) - hash = ((hash << 5) + hash) + c; - - return hash; +void fossil_test_setup(void (*setup_func_param)(void)) { + setup_func = setup_func_param; } -bool is_assert_similar_in_history(unsigned long fingerprint) { - for (int i = 0; i < assert_history_count; i++) { - if (assert_history[i].fingerprint == fingerprint) { - return true; - } - } - return false; -} - -void _fossil_test_assert_class(bool expression, xassert_type_t behavior, char* message, char* file, int line, char* func) { - unsigned long fingerprint = generate_fingerprint(expression, behavior, message, file, line, func); - - if (is_assert_similar_in_history(fingerprint)) { - // Skip the assertion as a similar one has already been executed - _ASSERT_INFO.same_assert = true; - return; - } - - _ASSERT_INFO.func = func; - _ASSERT_INFO.file = file; - _ASSERT_INFO.line = line; - _ASSERT_INFO.message = message; - - if (behavior == TEST_ASSERT_AS_CLASS_ASSUME) { - fossil_test_assert_impl_assume(expression, &_ASSERT_INFO); - } else if (behavior == TEST_ASSERT_AS_CLASS_ASSERT) { - fossil_test_assert_impl_assert(expression, &_ASSERT_INFO); - } else if (behavior == TEST_ASSERT_AS_CLASS_EXPECT) { - fossil_test_assert_impl_expect(expression, &_ASSERT_INFO); - } - - _ASSERT_INFO.num_asserts++; // increment the number of asserts - _ASSERT_INFO.has_assert = true; // Make note of an assert being added in a given test case - - // Add the assertion to the history with its fingerprint - if (assert_history_count < MAX_ASSERT_HISTORY) { - assert_history[assert_history_count].expression = expression; - assert_history[assert_history_count].behavior = behavior; - assert_history[assert_history_count].message = message; - assert_history[assert_history_count].file = file; - assert_history[assert_history_count].line = line; - assert_history[assert_history_count].func = func; - assert_history[assert_history_count].fingerprint = fingerprint; - assert_history_count++; - } +void fossil_test_teardown(void (*teardown_func_param)(void)) { + teardown_func = teardown_func_param; } From 34fdea2ce30988c6534d668be7b4ddcbe68b17ad Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Sat, 2 Nov 2024 12:09:12 -0500 Subject: [PATCH 04/40] yeet this old miss --- code/logic/unittest/old-unittest.c | 749 ----------------------------- 1 file changed, 749 deletions(-) delete mode 100644 code/logic/unittest/old-unittest.c diff --git a/code/logic/unittest/old-unittest.c b/code/logic/unittest/old-unittest.c deleted file mode 100644 index fd128881..00000000 --- a/code/logic/unittest/old-unittest.c +++ /dev/null @@ -1,749 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#include "fossil/unittest/framework.h" -#include "fossil/_common/common.h" -#include "fossil/unittest/console.h" -#include "fossil/unittest/commands.h" -#include - -#define MAX_ASSERT_HISTORY 100 - -typedef struct { - bool expression; - char* message; - char* file; - int line; - unsigned long fingerprint; - char* func; -} assert_history_t; - -static assert_history_t assert_history[MAX_ASSERT_HISTORY]; -static int assert_history_count = 0; - -fossil_env_t _TEST_ENV; -xassert_info _ASSERT_INFO; - -fossil_test_queue_t* fossil_test_queue_create(void) { - fossil_test_queue_t* queue = (fossil_test_queue_t*)malloc(sizeof(fossil_test_queue_t)); - if (queue != xnullptr) { - queue->front = xnullptr; - queue->rear = xnullptr; - } else { - // Handle memory allocation failure - perror("Failed to allocate memory for queue"); - return xnullptr; - } - return queue; -} - -void fossil_test_queue_erase(fossil_test_queue_t* queue) { - fossil_test_t* current = queue->front; - fossil_test_t* next; - - while (current != xnullptr) { - next = current->next; - free(current); - current = next; - } - - queue->front = xnullptr; - queue->rear = xnullptr; -} - -// Function to add a test to the front of the queue -void fossil_test_queue_push_front(fossil_test_t *test, fossil_test_queue_t *queue) { - if (test == xnullptr || queue == xnullptr) { - return; - } - - if (queue->front == xnullptr) { - // The queue is empty - queue->front = test; - queue->rear = test; - } else { - // Insert test at the front - test->next = queue->front; - queue->front->prev = test; - queue->front = test; - } - test->prev = xnullptr; // Ensure previous pointer of new front is NULL -} - -// Function to add a test to the rear of the queue -void fossil_test_queue_push_back(fossil_test_t *test, fossil_test_queue_t *queue) { - if (test == xnullptr || queue == xnullptr) { - return; - } - - if (queue->rear == xnullptr) { - // The queue is empty - queue->front = test; - queue->rear = test; - } else { - // Insert test at the rear - queue->rear->next = test; - test->prev = queue->rear; - queue->rear = test; - } - test->next = xnullptr; // Ensure next pointer of new rear is NULL -} - -// Function to remove and return the test from the front of the queue -fossil_test_t* fossil_test_queue_pop_front(fossil_test_queue_t *queue) { - if (queue == xnullptr || queue->front == xnullptr) { - return xnullptr; - } - - fossil_test_t *front_test = queue->front; - - if (queue->front == queue->rear) { - // The queue has only one test - queue->front = xnullptr; - queue->rear = xnullptr; - } else { - // Remove test from the front - queue->front = queue->front->next; - queue->front->prev = xnullptr; - } - - return front_test; -} - -// Function to remove and return the test from the rear of the queue -fossil_test_t* fossil_test_queue_pop_back(fossil_test_queue_t *queue) { - if (queue == xnullptr || queue->rear == xnullptr) { - return xnullptr; - } - - fossil_test_t *rear_test = queue->rear; - - if (queue->front == queue->rear) { - // The queue has only one test - queue->front = xnullptr; - queue->rear = xnullptr; - } else { - // Remove test from the rear - queue->rear = queue->rear->prev; - queue->rear->next = xnullptr; - } - - return rear_test; -} - -// Function to add a test to the queue based on priority -void add_test_to_queue(fossil_test_t *test, fossil_test_queue_t *queue) { - fossil_test_queue_push_back(test, queue); -} - -// Function to remove and return the test with the highest priority from the queue -fossil_test_t* get_highest_priority_test(fossil_test_queue_t *queue) { - // In this implementation, the test with the highest priority is the one at the front of the queue - return fossil_test_queue_pop_front(queue); -} - -// Function to remove and return the test with the lowest priority from the queue -fossil_test_t* get_lowest_priority_test(fossil_test_queue_t *queue) { - // In this implementation, the test with the lowest priority is the one at the rear of the queue - return fossil_test_queue_pop_back(queue); -} - -// Function to search for a test by tag in the queue -fossil_test_t* fossil_test_queue_search_by_tag(fossil_test_queue_t *queue, const char *tag) { - if (queue == xnullptr || tag == xnullptr) { - return xnullptr; - } - - fossil_test_t *current = queue->front; - while (current != xnullptr) { - if (strcmp(current->tags, tag) == 0) { - return current; - } - current = current->next; - } - return xnullptr; -} - -// Function to search for a test by name in the queue -fossil_test_t* fossil_test_queue_search_by_name(fossil_test_queue_t *queue, const char *name) { - if (queue == xnullptr || name == xnullptr) { - return xnullptr; - } - - fossil_test_t *current = queue->front; - while (current != xnullptr) { - if (strcmp(current->name, name) == 0) { - return current; - } - current = current->next; - } - return xnullptr; -} - -void fossil_test_queue_reverse(fossil_test_queue_t *queue) { - if (queue == xnullptr) { - return; - } - - fossil_test_t *current = queue->front; - fossil_test_t *temp = xnullptr; - - // Swap the next and prev pointers for each node - while (current != xnullptr) { - temp = current->prev; - current->prev = current->next; - current->next = temp; - current = current->prev; - } - - // Swap the front and rear pointers of the queue - if (temp != xnullptr) { - temp = queue->front; - queue->front = queue->rear; - queue->rear = temp; - } -} - -// Function to convert queue to an array -fossil_test_t** queue_to_array(fossil_test_queue_t *queue, int *size) { - if (queue == xnullptr) { - return xnullptr; - } - - int count = 0; - fossil_test_t *current = queue->front; - while (current != xnullptr) { - count++; - current = current->next; - } - - fossil_test_t **array = (fossil_test_t**)malloc(count * sizeof(fossil_test_t*)); - current = queue->front; - for (int i = 0; i < count; i++) { - array[i] = current; - current = current->next; - } - - *size = count; - return array; -} - -// Function to convert array to a queue -void array_to_queue(fossil_test_t **array, int size, fossil_test_queue_t *queue) { - if (queue == xnullptr || array == xnullptr) { - return; - } - - queue->front = xnullptr; - queue->rear = xnullptr; - - for (int i = 0; i < size; i++) { - array[i]->next = xnullptr; - array[i]->prev = xnullptr; - fossil_test_queue_push_back(array[i], queue); - } -} - -// Fisher-Yates shuffle algorithm -void fossil_test_queue_shuffle(fossil_test_queue_t *queue) { - if (queue == xnullptr) { - return; - } - - int size; - fossil_test_t **array = queue_to_array(queue, &size); - if (array == xnullptr) { - return; - } - - srand(time(xnullptr)); - for (int i = size - 1; i > 0; i--) { - int j = rand() % (i + 1); - fossil_test_t *temp = array[i]; - array[i] = array[j]; - array[j] = temp; - } - - array_to_queue(array, size, queue); - free(array); -} - -// -// Fossil Test Environment functions -// - -void fossil_test_environment_erase(void) { - if (_TEST_ENV.queue != xnullptr) { - free(_TEST_ENV.queue); // Fix memory leak by uncommenting free statement - } -} - -fossil_env_t fossil_test_environment_create(int argc, char **argv) { - _CLI = fossil_options_parse(argc, argv); - fossil_test_io_information(); // checkpoint for simple commands - - fossil_env_t env; - - // Initialize test statistics - env.stats.expected_passed_count = 0; - env.stats.expected_failed_count = 0; - env.stats.unexpected_passed_count = 0; - env.stats.unexpected_failed_count = 0; - env.stats.expected_skipped_count = 0; - env.stats.expected_empty_count = 0; - env.stats.expected_timeout_count = 0; - env.stats.expected_total_count = 0; - env.stats.untested_count = 0; - - // Initialize test rules - env.rule.should_pass = true; - env.rule.skipped = false; - env.rule.timeout = false; - env.rule.error = false; - - // Initialize test timer - env.timer.start = 0; - env.timer.end = 0; - env.timer.elapsed = 0; - env.timer.detail.minutes = 0; - env.timer.detail.seconds = 0; - env.timer.detail.milliseconds = 0; - env.timer.detail.microseconds = 0; - env.timer.detail.nanoseconds = 0; - - // Initialize test queue - env.queue = fossil_test_queue_create(); - atexit(fossil_test_environment_erase); // ensure memory leaks do not occur - - // Initialize exception and assumption counts - env.current_except_count = 0; - env.current_assume_count = 0; - - fossil_test_io_summary_start(); - - return env; -} - -void _fossil_test_scoreboard_update(void) { - // here we just update the scoreboard count - // add one to total tested cases and remove - // one from untested ghost cases. - // - // The main goal is to ensure ghost cases are removed - // accordingly and the total tested cases are updated. - // - // However in the event exit is called we will have - // record of test that are tested and those that are - // not tested. - _TEST_ENV.stats.untested_count--; - _TEST_ENV.stats.expected_total_count++; -} - -void _fossil_test_scoreboard_expected_rules(void) { - if (!_TEST_ENV.rule.should_pass) { - _TEST_ENV.stats.expected_failed_count++; - _TEST_ENV.rule.should_pass = false; - } else { - _TEST_ENV.stats.expected_passed_count++; - } -} - -void _fossil_test_scoreboard_unexpected_rules(void) { - if (_TEST_ENV.rule.should_pass) { - _TEST_ENV.stats.unexpected_failed_count++; - } else { - _TEST_ENV.stats.unexpected_passed_count++; - } -} - -void _fossil_test_scoreboard_feature_rules(fossil_test_t *test_case) { - if (_TEST_ENV.rule.skipped && strcmp(test_case->marks, "skip") == 0) { - _TEST_ENV.stats.expected_skipped_count++; - _TEST_ENV.rule.skipped = false; - } else if (!_ASSERT_INFO.has_assert && strcmp(test_case->marks, "tofu") != 0) { - _TEST_ENV.stats.expected_empty_count++; - } else if (!_TEST_ENV.rule.should_pass && strcmp(test_case->marks, "fail") == 0) { - if (_ASSERT_INFO.should_fail) { - _fossil_test_scoreboard_expected_rules(); - } else { - _fossil_test_scoreboard_unexpected_rules(); - } - } else { - _TEST_ENV.stats.expected_passed_count++; - } -} - -void fossil_test_environment_scoreboard(fossil_test_t *test) { - // for the first part we check if the given test case - // has any feature flags or rules triggered. - if (strcmp(test->marks, "fossil") != 0) { - _fossil_test_scoreboard_feature_rules(test); - } else { - _fossil_test_scoreboard_expected_rules(); - } - - // we just need to update the total scoreboard - // so it is accurate for the fossil test. - _fossil_test_scoreboard_update(); - _TEST_ENV.rule.should_pass = true; // reset counter for next test -} - -void fossil_test_run_testcase(fossil_test_t *test) { - if (test == xnullptr) { - return; - } - // set and reset step for assert scanning - _ASSERT_INFO.has_assert = false; - _ASSERT_INFO.should_fail = false; - _ASSERT_INFO.shoudl_timeout = false; - _ASSERT_INFO.num_asserts = 0; - _ASSERT_INFO.same_assert = false; - - if (_TEST_ENV.rule.skipped && strcmp(test->marks, "skip") == 0) { - return; - } else if (!_ASSERT_INFO.should_fail && strcmp(test->marks, "fail") == 0) { - _ASSERT_INFO.should_fail = true; - } - - fossil_test_io_unittest_start(test); - if (test->fixture.setup != xnullptr) { - test->fixture.setup(); - } - - // Run the test function - for (int32_t iter = 0; iter < _CLI.repeat_count; iter++) { - test->test_function(); - } - fossil_test_io_unittest_step(&_ASSERT_INFO); - - if (test->fixture.teardown != xnullptr) { - test->fixture.teardown(); - } - - fossil_test_io_unittest_ended(test); - fossil_test_environment_scoreboard(test); -} - -void fossil_test_environment_algorithms(fossil_env_t *env) { - if (env == xnullptr) { - return; - } - // Start the timer - env->timer.start = clock(); - - if (_CLI.shuffle_enabled) { - fossil_test_queue_shuffle(env->queue); - } - - if (_CLI.reverse) { - fossil_test_queue_reverse(env->queue); - } - - if (_CLI.only_tags) { - fossil_test_t *test = fossil_test_queue_search_by_tag(env->queue, _CLI.only_tags_value); - if (test != xnullptr) { - fossil_test_queue_erase(env->queue); - add_test_to_queue(test, env->queue); - } - } -} - -// Function to run the test environment -void fossil_test_environment_run(fossil_env_t *env) { - if (env == xnullptr) { - return; - } - // Apply the test environment algorithms for the given test cases - fossil_test_environment_algorithms(env); - - - - // Iterate through the test queue and run each test - fossil_test_t *current_test = env->queue->front; - while (current_test != xnullptr) { - // Run the test function - fossil_test_run_testcase(current_test); - - // Move to the next test - current_test = current_test->next; - } - - // Stop the timer - env->timer.end = clock(); - env->timer.elapsed = env->timer.end - env->timer.start; -} - -// Function to summarize the test environment -int fossil_test_environment_summary(void) { - fossil_test_io_summary_ended(); - int result = (_TEST_ENV.stats.expected_failed_count + - _TEST_ENV.stats.unexpected_failed_count + - _TEST_ENV.stats.unexpected_passed_count + - _TEST_ENV.stats.expected_timeout_count + - _TEST_ENV.stats.untested_count); - - return result; -} - -// Function to add a test to the test environment -void fossil_test_environment_add(fossil_env_t *env, fossil_test_t *test, fossil_fixture_t *fixture) { - if (test == xnullptr || env == xnullptr || env->queue == xnullptr) { - return; - } - - if (fixture != xnullptr) { - test->fixture.setup = fixture->setup; - test->fixture.teardown = fixture->teardown; - } - - // Update test statistics - add_test_to_queue(test, env->queue); - _TEST_ENV.stats.untested_count++; - fossil_test_io_sanity_load(test); -} - -// -// Feature function implementations -// - -// Function to apply a mark to a test case -void fossil_test_apply_mark(fossil_test_t *test, const char *mark) { - if (!test) { - return; - } else if (!mark) { - return; - } - - // we handle any rules for marks - if (strcmp(mark, "skip") == 0) { - test->marks = "skip"; - _TEST_ENV.rule.skipped = true; - } else if (strcmp(mark, "ghost") == 0) { - test->marks = "ghost"; // remember to call the ghostbusters whena team member marks an empty case. - } else if (strcmp(mark, "error") == 0) { - test->marks = "error"; - _TEST_ENV.rule.should_pass = false; - } else if (strcmp(mark, "fail") == 0){ - test->marks = "fail"; - _TEST_ENV.rule.should_pass = false; - } else if (strcmp(mark, "none") == 0) { - test->marks = "none"; - } else if (strcmp(mark, "only") == 0) { - test->marks = "only"; - } -} - -// Function to apply an extended tag to a test case -void fossil_test_apply_xtag(fossil_test_t *test, const char *tag) { - if (!test) { - return; - } else if (!tag) { - return; - } - - // we handle any rules for tags - // to be used in a run via tag feature. - if (strcmp(tag, "fast") == 0) { - test->tags = "fast"; - } else if (strcmp(tag, "slow") == 0) { - test->tags = "slow"; - } else if (strcmp(tag, "bug") == 0) { - test->tags = "bug"; - } else if (strcmp(tag, "feature") == 0) { - test->tags = "feature"; - } else if (strcmp(tag, "security") == 0) { - test->tags = "security"; - } else if (strcmp(tag, "performance") == 0) { - test->tags = "performance"; - } else if (strcmp(tag, "stress") == 0) { - test->tags = "stress"; - } else if (strcmp(tag, "regression") == 0) { - test->tags = "regression"; - } else if (strcmp(tag, "compatibility") == 0) { - test->tags = "compatibility"; - } else if (strcmp(tag, "usability") == 0) { - test->tags = "usability"; - } else if (strcmp(tag, "robustness") == 0) { - test->tags = "robustness"; - } else if (strcmp(tag, "corner case") == 0) { - test->tags = "corner case"; - } else if (strcmp(tag, "edge case") == 0) { - test->tags = "edge case"; - } else if (strcmp(tag, "boundary case") == 0) { - test->tags = "boundary case"; - } else if (strcmp(tag, "negative case") == 0) { - test->tags = "negative case"; - } else if (strcmp(tag, "positive case") == 0) { - test->tags = "positive case"; - } else if (strcmp(tag, "sanity") == 0) { - test->tags = "sanity"; - } else if (strcmp(tag, "smoke") == 0) { - test->tags = "smoke"; - } else if (strcmp(tag, "acceptance") == 0) { - test->tags = "acceptance"; - } else if (strcmp(tag, "regression") == 0) { - test->tags = "regression"; - } else if (strcmp(tag, "functional") == 0) { - test->tags = "functional"; - } else if (strcmp(tag, "integration") == 0) { - test->tags = "integration"; - } else if (strcmp(tag, "system") == 0) { - test->tags = "system"; - } else if (strcmp(tag, "end-to-end") == 0) { - test->tags = "end-to-end"; - } else if (strcmp(tag, "unit") == 0) { - test->tags = "unit"; - } else if (strcmp(tag, "component") == 0) { - test->tags = "component"; - } else if (strcmp(tag, "module") == 0) { - test->tags = "module"; - } else if (strcmp(tag, "api") == 0) { - test->tags = "api"; - } else if (strcmp(tag, "ui") == 0) { - test->tags = "ui"; - } else if (strcmp(tag, "usability") == 0) { - test->tags = "usability"; - } else if (strcmp(tag, "performance") == 0) { - test->tags = "performance"; - } else if (strcmp(tag, "security") == 0) { - test->tags = "security"; - } else if (strcmp(tag, "stress") == 0) { - test->tags = "stress"; - } -} - -// Function to apply a priority to a test case -void fossil_test_apply_priority(fossil_test_t *test, const char *priority) { - if (!test) { - return; - } else if (!priority) { - return; - } - - if (strcmp(priority, "lowest") == 0) { - test->priority = 0; - } else if (strcmp(priority, "very low") == 0) { - test->priority = 10; - } else if (strcmp(priority, "low") == 0) { - test->priority = 20; - } else if (strcmp(priority, "medium") == 0) { - test->priority = 50; - } else if (strcmp(priority, "high") == 0) { - test->priority = 70; - } else if (strcmp(priority, "very high") == 0) { - test->priority = 90; - } else if (strcmp(priority, "highest") == 0) { - test->priority = 100; - } else if (strcmp(priority, "urgent") == 0) { - test->priority = 95; - } else if (strcmp(priority, "critical") == 0) { - test->priority = 100; - } else if (strcmp(priority, "normal") == 0) { - test->priority = 50; - } else { - int priority_value = atoi(priority); - if (priority_value < 0 || priority_value > 100) { - return; - } - - test->priority = priority_value; - } -} - -// -// Assertion function implementations -// - -// Custom assumptions function with optional message. -void fossil_test_assert_impl_assume(bool expression, xassert_info *assume) { - if (_TEST_ENV.current_assume_count == FOSSIL_TEST_ASSUME_MAX) { - exit(FOSSIL_TEST_ABORT_FAIL); - return; - } - - if (!_ASSERT_INFO.should_fail) { - if (!expression) { - _TEST_ENV.rule.should_pass = false; - _TEST_ENV.current_assume_count++; - fossil_test_io_asserted(assume); - } - } else { - if (!expression) { - _TEST_ENV.rule.should_pass = true; - } else if (expression) { - _TEST_ENV.rule.should_pass = false; - _TEST_ENV.current_assume_count++; - fossil_test_io_asserted(assume); - } - } -} // end of func - -// Custom assertion function with optional message. -void fossil_test_assert_impl_assert(bool expression, xassert_info *assume) { - if (_ASSERT_INFO.should_fail) { - if (!expression) { - _TEST_ENV.rule.should_pass = true; - } else if (expression) { - _TEST_ENV.rule.should_pass = false; - fossil_test_io_asserted(assume); - exit(FOSSIL_TEST_ABORT_FAIL); - } - } else { - if (!expression) { - _TEST_ENV.rule.should_pass = false; - fossil_test_io_asserted(assume); - exit(FOSSIL_TEST_ABORT_FAIL); - } - } -} // end of func - -// Custom expectation function with optional message. -void fossil_test_assert_impl_expect(bool expression, xassert_info *assume) { - if (_ASSERT_INFO.should_fail) { - if (!expression) { - _TEST_ENV.rule.should_pass = true; - } else if (expression) { - _TEST_ENV.rule.should_pass = false; - fossil_test_io_asserted(assume); - } - } else { - if (!expression) { - _TEST_ENV.rule.should_pass = false; - fossil_test_io_asserted(assume); - } - } -} // end of func - -void _fossil_test_assert_class(bool expression, char* message, char* file, int line, char* func) { - - _ASSERT_INFO.func = func; - _ASSERT_INFO.file = file; - _ASSERT_INFO.line = line; - _ASSERT_INFO.message = message; - - fossil_test_assert_impl_assume(expression, &_ASSERT_INFO); - - _ASSERT_INFO.num_asserts++; // increment the number of asserts - _ASSERT_INFO.has_assert = true; // Make note of an assert being added in a given test case - - // Add the assertion to the history with its fingerprint - if (assert_history_count < MAX_ASSERT_HISTORY) { - assert_history[assert_history_count].expression = expression; - assert_history[assert_history_count].message = message; - assert_history[assert_history_count].file = file; - assert_history[assert_history_count].line = line; - assert_history[assert_history_count].func = func; - assert_history_count++; - } -} From f52df8b8dfa35dda74c6280e84f78253d058904a Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Sat, 2 Nov 2024 18:22:50 -0500 Subject: [PATCH 05/40] apply changes --- code/logic/fossil/unittest/framework.h | 613 +------------------------ code/logic/fossil/unittest/unittest.h | 258 +++++------ code/logic/unittest/unittest.c | 242 ++++------ 3 files changed, 208 insertions(+), 905 deletions(-) diff --git a/code/logic/fossil/unittest/framework.h b/code/logic/fossil/unittest/framework.h index bfe36ef6..5109da37 100644 --- a/code/logic/fossil/unittest/framework.h +++ b/code/logic/fossil/unittest/framework.h @@ -15,621 +15,12 @@ #ifndef FOSSIL_TEST_FRAMEWORK_H #define FOSSIL_TEST_FRAMEWORK_H -// Fossil test specific header section of the test framework - -#include "fossil/_common/common.h" -#include "fossil/_common/platform.h" -#include "internal.h" -#include "console.h" -#include "commands.h" - #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif -extern fossil_env_t _TEST_ENV; -extern xassert_info _ASSERT_INFO; - -// ================================================================= -// Initial implementation -// ================================================================= - -// Function prototypes -fossil_env_t fossil_test_environment_create(int argc, char **argv); -void fossil_test_environment_run(fossil_env_t *env); -void fossil_test_environment_add(fossil_env_t *env, fossil_test_t *test, fossil_fixture_t *fixture); -int fossil_test_environment_summary(void); - -void fossil_test_apply_mark(fossil_test_t *test, const char *mark); -void fossil_test_apply_xtag(fossil_test_t *test, const char *tag); -void fossil_test_apply_priority(fossil_test_t *test, const char *priority); - -/** - * @brief Internal function for handling test assertions. - * - * @param expression The expression to evaluate. - * @param behavior The behavior of the assertion (e.g., ASSERT, EXPECT, ASSUME). - * @param message The message associated with the assertion. - * @param file The file name where the assertion occurred. - * @param line The line number where the assertion occurred. - * @param func The function name where the assertion occurred. - */ -void _fossil_test_assert_class(bool expression, char* message, char* file, int line, char* func); - - -/** - * @brief Macro to apply a priority to a test case. - * - * This macro is used to apply a priority to a test case. It is used in conjunction - * with the _APPLY_PRIORITY macro to define the priority to be applied. - * - * @param test_case The test case to which the priority is to be applied. - * @param priority The priority to be applied. - */ -#define _APPLY_PRIORITY(test_case, priority) fossil_test_apply_priority(test_case, (char*)priority) - -/** - * @brief Macro to apply a tag to a test case. - * - * This macro is used to apply a tag to a test case. It is used in conjunction - * with the _APPLY_XTAG macro to define the tag to be applied. - * - * @param test_case The test case to which the tag is to be applied. - * @param xtag The tag to be applied. - */ -#define _APPLY_XTAG(test_case, xtag) fossil_test_apply_xtag(&test_case, (char*)xtag) - -/** - * @brief Macro to apply a mark to a test case. - * - * This macro is used to apply a mark to a test case. It is used in conjunction - * with the _APPLY_MARK macro to define the mark to be applied. - * - * @param test_case The test case to which the mark is to be applied. - * @param mark The mark to be applied. - */ -#define _APPLY_MARK(test_case, mark) fossil_test_apply_mark(&test_case, (char*)mark) - -/** - * @brief Macro to add a test case. - * - * This macro is used to add a test case. It is used in conjunction with the - * _ADD_TEST macro to define the test case function. - * - * @param test_case The test case to be added. - */ -#define _ADD_TEST(test_case) fossil_test_environment_add(test_env, &test_case, xnullptr) - -/** - * @brief Macro to add a test case with a fixture. - * - * This macro is used to add a test case with a fixture. It is used in conjunction - * with the _FOSSIL_FIXTURE macro to define the fixture structure. - * - * @param test_case The test case to be added. - * @param fixture The fixture to be added. - */ -#define _ADD_TESTF(test_case, fixture) fossil_test_environment_add(test_env, &test_case, &fixture) - -/** - * @brief Macro to define a fixture. - * - * This macro is used to define a fixture. It is used in conjunction with the - * _FOSSIL_SETUP and _FOSSIL_TEARDOWN macros to define the setup and teardown functions for - * the fixture. - * - * @param fixture_name The name of the fixture. - * @param setup The setup function for the fixture. - * @param teardown The teardown function for the fixture. - */ -#define _FOSSIL_FIXTURE(fixture_name) \ - void setup_##fixture_name(void); \ - void teardown_##fixture_name(void); \ - fossil_fixture_t fixture_name = { setup_##fixture_name, teardown_##fixture_name } - -/** - * @brief Macro to define a setup function for a fixture. - * - * This macro is used to define a setup function for a fixture. It is used in - * conjunction with the _FOSSIL_FIXTURE macro to define the fixture structure. - * - * @param fixture_name The name of the fixture. - */ -#define _FOSSIL_SETUP(fixture_name) void setup_##fixture_name(void) - -/** - * @brief Macro to define a teardown function for a fixture. - * - * This macro is used to define a teardown function for a fixture. It is used in - * conjunction with the _FOSSIL_FIXTURE macro to define the fixture structure. - * - * @param fixture_name The name of the fixture. - */ -#define _FOSSIL_TEARDOWN(fixture_name) void teardown_##fixture_name(void) - -/** - * @brief Macro to define a test case. - * - * This macro is used to define a test case. It is used in conjunction with the - * _FOSSIL_TEST macro to define the test case function. - * - * @param name The name of the test case. - */ -#define _FOSSIL_TEST(name) \ - void name##_fossil_test(void); \ - fossil_test_t name = { \ - (char*)#name, \ - name##_fossil_test, \ - (char*)"fossil", \ - (char*)"fossil", \ - {0, 0, 0, {0, 0, 0, 0, 0}}, \ - {xnull, xnull}, \ - 0, \ - xnull, \ - xnull \ - }; \ - void name##_fossil_test(void) - -/** - * @brief Macro to define a test case with a priority. - * - * This macro is used to define a test case with a priority. It is used in conjunction - * with the _FOSSIL_TEST macro to define the test case function. - * - * @param name The name of the test case. - * @param priority The priority of the test case. - */ -#define _FOSSIL_TEST_ERASE() fossil_test_environment_summary() - -/** Macro to create the test environment. - * - * This macro is used to create the test environment by calling the _fossil_test_environment_create function. - * - * @param argc The number of command line arguments. - * @param argv The array of command line arguments. - */ -#define _FOSSIL_TEST_CREATE(argc, argv) _TEST_ENV = fossil_test_environment_create(argc, argv) - -/** Macro to run the test environment. - * - * This macro is used to run the test environment by calling the fossil_test_environment_run function. - */ -#define _FOSSIL_TEST_RUN() fossil_test_environment_run(&_TEST_ENV) - -/** - * @brief Define macro for defining a test queue. - * - * This macro is used to define a test queue function for a specific test group. - * It creates a function definition with the given group name and accepts a pointer - * to a TestRegistry structure as a parameter. This function typically registers - * all tests within the specified test group to the provided test registry. - * - * @param group_name The name of the test group. - */ -#define _FOSSIL_TEST_GROUP(group_name) void group_name(fossil_env_t* test_env) - -/** - * @brief Define macro for declaring an external test queue. - * - * This macro is used to declare an external test queue function for a specific - * test group. It creates an external function declaration with the given group name - * and accepts a pointer to a TestRegistry structure as a parameter. This declaration - * allows the test queue function to be defined in a separate source file and linked - * with the test framework. - * - * @param group_name The name of the test group. - */ -#define _FOSSIL_TEST_EXPORT(group_name) extern void group_name(fossil_env_t* test_env) - -/** - * @brief Define macro for importing and executing a test queue. - * - * This macro is used to import and execute a test queue function for a specific - * test group. It calls the test queue function with the provided TestRegistry - * structure, typically registering all tests within the specified test group - * to the test registry. - * - * @param group_name The name of the test group. - */ -#define _FOSSIL_TEST_IMPORT(group_name) group_name(&_TEST_ENV) - -#define _GIVEN(description) fossil_test_io_unittest_given(description); if (true) -#define _WHEN(description) fossil_test_io_unittest_when(description); if (true) -#define _THEN(description) fossil_test_io_unittest_then(description); if (true) - - - -// ================================================================= -// XTest create and erase commands -// ================================================================= - -/** - * Macro to create and initialize a test environment. - * This macro simplifies the process of calling the function to create a test environment, - * making the code more concise and readable. It initializes an fossil_env_t structure named `test_env`, - * which is used to manage the state and configuration of the test environment. - * - * Usage: FOSSIL_TEST_CREATE(argc, argv) - * - * @param argc The argument count from the command line. This is typically passed from the `main` function. - * @param argv The argument vector from the command line. This is typically passed from the `main` function. - * - * Example: - * int main(int argc, char *argv[]) { - * // Initialize the test environment with command-line arguments - * FOSSIL_TEST_CREATE(argc, argv); - * - * // Your test code here - * - * // Clean up the test environment before exiting - * return FOSSIL_TEST_ERASE(); - * } - */ -#define FOSSIL_TEST_CREATE(argc, argv) _FOSSIL_TEST_CREATE(argc, argv) - -/** - * @brief Macro to start the execution of the test environment. - * - * This macro serves as the primary entry point to run all the tests - * defined within the testing framework. When invoked, it calls the - * `_fossil_test_environment_run` function, which initializes the testing - * environment, executes all the test cases, and provides a summary - * of the test results. - * - * @details - * The `_fossil_test_environment_run` function performs several key tasks: - * 1. Initializes the test environment, which includes setting up - * necessary data structures, parsing command-line arguments, - * and preparing for test execution. - * 2. Executes each test case in the order they were defined or - * according to specified priorities. - * 3. Collects and aggregates test results, including counts of - * passed, failed, skipped, and timed-out tests. - * 4. Generates and outputs a summary report of the test execution, - * providing detailed information about each test case and the - * overall testing outcome. - * - * Usage: - * To use this macro, simply include it at the point in your test - * program where you want to initiate the test execution. Typically, - * this is done at the end of the `main` function after all test - * cases have been defined and added to the test suite. - * - * Example: - * @code - * int main(int argc, char *argv[]) { - * // Initialize the test suite and define test cases - * fossil_test_define_cases(); - * - * // Run all defined test cases - * FOSSIL_TEST_RUN(); - * - * return 0; - * } - * @endcode - * - * Note: - * - Ensure that all test cases are defined and properly configured - * before invoking `FOSSIL_TEST_RUN()`. Any test cases added after the - * macro is called will not be executed. - * - This macro abstracts the complexity of the underlying test - * execution function, providing a clean and simple interface for - * running the tests. - * - * @see _fossil_test_environment_run - */ -#define FOSSIL_TEST_RUN() _FOSSIL_TEST_RUN() - -/** - * Macro to erase and clean up the test environment. - * This macro simplifies the process of calling the function to clean up the test environment, - * ensuring that all allocated resources are properly released and the environment is reset. - * It operates on the `test_env` variable that was initialized using the FOSSIL_TEST_CREATE macro. - * - * Usage: FOSSIL_TEST_ERASE() - * - * Example: - * int main(int argc, char *argv[]) { - * // Initialize the test environment with command-line arguments - * FOSSIL_TEST_CREATE(argc, argv); - * - * // Your test code here - * - * // Clean up the test environment before exiting - * return FOSSIL_TEST_ERASE(); - * } - */ -#define FOSSIL_TEST_ERASE() _FOSSIL_TEST_ERASE() - -// ================================================================= -// XTest run commands -// ================================================================= +#include "unittest.h" -/** - * @brief Assign a mark to a test case. - * - * This macro is used to apply a mark to a given test case. It wraps the - * _fossil_test_apply_mark function, providing a convenient way to mark test cases - * with specific attributes or states. - * - * @param test_case The test case to which the mark will be applied. This should - * be a valid identifier for a registered test case. - * @param mark The mark to assign to the test case. This is typically a string - * used to indicate specific attributes or states of the test case. - * The mark is cast to char* for compatibility. - * - * Example usage: - * - * APPLY_MARK(my_test_case, "skip"); - * - * This would mark 'my_test_case' with the "skip" mark, indicating that the test - * should be skipped during execution. - */ -#define APPLY_MARK(test_case, mark) _APPLY_MARK(test_case, mark) - -/** - * @brief Assign an xtag to a test case. - * - * This macro is used to apply an xtag (extra tag) to a given test case. It wraps - * the _fossil_test_apply_xtag function, providing a convenient way to tag test cases - * with additional metadata. - * - * @param test_case The test case to which the xtag will be applied. This should - * be a valid identifier for a registered test case. - * @param xtag The xtag to assign to the test case. This is typically a string - * used to add additional metadata or categorization to the test - * case. The xtag is cast to char* for compatibility. - * - * Example usage: - * - * APPLY_XTAG(my_test_case, "regression"); - * - * This would tag 'my_test_case' with the "regression" xtag. - */ -#define APPLY_XTAG(test_case, xtag) _APPLY_XTAG(test_case, xtag) - -/** - * @brief Assign a priority to a test case. - * - * This macro is used to set the priority of a given test case. It wraps the - * _fossil_test_apply_priority function, providing a more intuitive and convenient - * way to specify test priorities in the code. - * - * @param test_case The test case to which the priority will be applied. This should - * be a valid identifier for a registered test case. - * @param priority The priority level to assign to the test case. Higher values - * typically indicate higher priority, though this depends on the - * implementation details of _fossil_test_apply_priority. - * - * Example usage: - * - * APPLY_PRIORITY(my_test_case, 5); - * - * This would set the priority of 'my_test_case' to 5. - */ -#define APPLY_PRIORITY(test_case, priority) _APPLY_PRIORITY(test_case, priority) - -/** - * @brief Macro for adding a test to the test registry. - * - * This macro is used to add a test to the test registry. It takes the test - * name as an argument and adds the corresponding Test structure to the registry. - * - * @param test The test to be added to the registry. - */ -#define ADD_TEST(test_case) _ADD_TEST(test_case) - -/** - * @brief Macro for adding a test with a fixture to the test registry. - * - * This macro is used to add a test with a fixture to the test registry. It - * takes the test name and fixture name as arguments, and adds the corresponding - * Test structure to the registry, along with the setup and teardown functions - * for the specified fixture. - * - * @param test The test to be added to the registry. - * @param fixture The fixture associated with the test. - */ -#define ADD_TESTF(test_case, fixture) _ADD_TESTF(test_case, fixture) - -/** - * @brief Define macro for declaring a test fixture. - * - * This macro is used to declare setup and teardown functions for a test fixture. - * It creates function declarations for the setup and teardown functions associated - * with the specified fixture name. These functions typically perform initialization - * and cleanup tasks before and after each test case, respectively. - * - * @param fixture_name The name of the test fixture. - */ -#define FOSSIL_FIXTURE(fixture_name) _FOSSIL_FIXTURE(fixture_name) - -/** - * @brief Define macro for declaring a BDD test fixture. - * - * This macro is used to declare a BDD test fixture. It creates function declarations - * for the setup and teardown functions associated with the specified fixture name. - * These functions typically perform initialization and cleanup tasks before and after - * - * @param fixture_name The name of the test fixture. - */ -#define FOSSIL_FEATURE(fixture_name) _FOSSIL_FIXTURE(fixture_name) - -/** - * @brief Define macro for declaring a setup function for a test fixture. - * - * This macro is used to declare a setup function for a test fixture. It creates - * a function declaration for the setup function associated with the specified - * fixture name. This function typically performs initialization tasks before - * each test case. - * - * @param fixture_name The name of the test fixture. - */ -#define FOSSIL_SETUP(fixture_name) _FOSSIL_SETUP(fixture_name) - -/** - * @brief Define macro for declaring a teardown function for a test fixture. - * - * This macro is used to declare a teardown function for a test fixture. It creates - * a function declaration for the teardown function associated with the specified - * fixture name. This function typically performs cleanup tasks after each test case. - * - * @param fixture_name The name of the test fixture. - */ -#define FOSSIL_TEARDOWN(fixture_name) _FOSSIL_TEARDOWN(fixture_name) - -/** - * Defines a test case with a given name and sets up its properties. - * - * This macro generates a function prototype and an instance of an fossil_test_t struct - * for the specified test case name. It initializes the test case with default - * values for various properties, including mark and tag rules, description - * strings, and flags. - * - * @param name The name of the test case. This name is used to generate the function - * prototype and the fossil_test_t struct instance. - */ -#define FOSSIL_TEST(name) _FOSSIL_TEST(name) - -/** - * @brief Define macro for a BDD style test case. - * - * This macro is used to define a BDD style test case. It creates a function prototype - * and an instance of an fossil_test_t struct for the specified test case name. It initializes - * the test case with default values for various properties, including mark and tag rules, - * description strings, and flags. This macro is typically used for behavior-driven - * development (BDD) style tests, where the test case is structured as a series of GIVEN, - * WHEN, and THEN conditions. - * - * @param name The name of the test case. - */ -#define FOSSIL_SONERO(name) _FOSSIL_TEST(name) - -// ================================================================= -// Test pool commands -// ================================================================= - -/** - * @brief Define macro for defining a test queue. - * - * This macro is used to define a test queue function for a specific test group. - * It creates a function definition with the given group name and accepts a pointer - * to a TestRegistry structure as a parameter. This function typically registers - * all tests within the specified test group to the provided test registry. - * - * @param group_name The name of the test group. - */ -#define FOSSIL_TEST_GROUP(group_name) _FOSSIL_TEST_GROUP(group_name) - -/** - * @brief Define macro for declaring an external test queue. - * - * This macro is used to declare an external test queue function for a specific - * test group. It creates an external function declaration with the given group name - * and accepts a pointer to a TestRegistry structure as a parameter. This declaration - * allows the test queue function to be defined in a separate source file and linked - * with the test framework. - * - * @param group_name The name of the test group. - */ -#define FOSSIL_TEST_EXPORT(group_name) _FOSSIL_TEST_EXPORT(group_name) - -/** - * @brief Define macro for importing and executing a test queue. - * - * This macro is used to import and execute a test queue function for a specific - * test group. It calls the test queue function with the provided TestRegistry - * structure, typically registering all tests within the specified test group - * to the test registry. - * - * @param group_name The name of the test group. - */ -#define FOSSIL_TEST_IMPORT(group_name) _FOSSIL_TEST_IMPORT(group_name) - -// ================================================================= -// BDD specific commands -// ================================================================= - -/** - * @brief Define macro for specifying a GIVEN condition in a test scenario. - * - * This macro is used to specify a GIVEN condition in a test scenario. - * It allows the test writer to describe the initial context or setup - * for the test. The condition is always true, indicating that the - * GIVEN condition is assumed to be true for the test scenario. - * - * @param description The description of the GIVEN condition. - */ -#define GIVEN(description) _GIVEN(description) - -/** - * @brief Define macro for specifying a WHEN condition in a test scenario. - * - * This macro is used to specify a WHEN condition in a test scenario. - * It allows the test writer to describe the action or event that - * triggers the behavior being tested. The condition is always true, - * indicating that the WHEN condition is assumed to be true for the - * test scenario. - * - * @param description The description of the WHEN condition. - */ -#define WHEN(description) _WHEN(description) - -/** - * @brief Define macro for specifying a THEN condition in a test scenario. - * - * This macro is used to specify a THEN condition in a test scenario. - * It allows the test writer to describe the expected outcome or result - * of the test scenario. The condition is always true, indicating that - * the THEN condition is assumed to be true for the test scenario. - * - * @param description The description of the THEN condition. - */ -#define THEN(description) _THEN(description) - -// ================================================================= -// TDD specific commands -// ================================================================= - -/** - * @brief Define macro for defining test data structures. - * - * This macro is used to define test data structures for a specific test group. - * It creates a typedef for the test data structure with the given group name - * and defines a struct with the same name suffixed with "_xdata". - * - * @param group_name The name of the test group. - */ -#define FOSSIL_TEST_DATA(group_name) typedef struct group_name##_xdata group_name##_xdata; struct group_name##_xdata - -/** - * @brief Define macro for indicating that a test is not implemented yet. - * - * This macro is used to mark a test as not implemented yet. It invokes - * the TEST_ASSUME macro with a false condition, indicating that the test - * is not implemented, and includes a message indicating the same. - */ -#define FOSSIL_TEST_NOT_IMPLEMENTED() TEST_ASSUME(false, (char*)"Test not implemented yet") - -// ================================================================= -// Assertion specific commands -// ================================================================= - -/** - * @brief Define macros for test assumptions with expression and message. - * - * This macro is used to define a test assumption. It checks the given expression - * and, if the expression evaluates to false, logs the failure with the provided - * message, file name, line number, and function name. Assumptions are used to - * validate preconditions for the test and can halt the test execution if a failure - * occurs. However, they may allow multiple failures before halting, depending on the implementation. - * - * @param expression The expression to be evaluated. - * @param message The message to log if the assumption fails. - */ -#define TEST_ASSUME(expression, message) \ - _fossil_test_assert_class(expression, (char*)message, (char*)__FILE__, __LINE__, (char*)__func__) #ifdef __cplusplus } diff --git a/code/logic/fossil/unittest/unittest.h b/code/logic/fossil/unittest/unittest.h index a576e2a8..3406da8e 100644 --- a/code/logic/fossil/unittest/unittest.h +++ b/code/logic/fossil/unittest/unittest.h @@ -28,6 +28,10 @@ extern "C" { #endif +// ***************************************************************************** +// Constants +// ***************************************************************************** + // ANSI color codes for output #define FOSSIL_TEST_COLOR_RESET "\033[0m" #define FOSSIL_TEST_COLOR_GREEN "\033[32m" @@ -35,171 +39,148 @@ extern "C" { #define FOSSIL_TEST_COLOR_YELLOW "\033[33m" #define FOSSIL_TEST_COLOR_BLUE "\033[34m" -// Enumeration for test result types +// ***************************************************************************** +// Type definitions +// ***************************************************************************** + typedef enum { FOSSIL_TEST_PASS, FOSSIL_TEST_FAIL, FOSSIL_TEST_SKIP, - FOSSIL_TEST_UNEXPECTED, - FOSSIL_TEST_EXPECTED_FAIL, // New result type - FOSSIL_TEST_IGNORED // New result type + FOSSIL_TEST_UNEXPECTED } fossil_test_result_t; -// Structure to store individual test case information +typedef enum { + FOSSIL_COLOR_DEFAULT, + FOSSIL_COLOR_GREEN, + FOSSIL_COLOR_RED, + FOSSIL_COLOR_YELLOW, + FOSSIL_COLOR_BLUE +} fossil_test_color_t; + typedef struct fossil_test_case { const char *name; - fossil_test_result_t result; void (*test_func)(void); - double duration; // Duration for this test case - bool is_expected_fail; // Flag for expected failures - bool is_ignored; // Flag for ignored tests + fossil_test_result_t result; + struct fossil_test_case *next; } fossil_test_case_t; -// Structure for test suite +typedef struct fossil_test_log { + const char *message; + fossil_test_result_t result; + struct fossil_test_log *prev; + struct fossil_test_log *next; +} fossil_test_log_t; + typedef struct fossil_test_suite { const char *name; - fossil_test_case_t **tests; - size_t test_count; + fossil_test_case_t *test_head; + struct fossil_test_suite *next; } fossil_test_suite_t; -// Priority Queue Node for Double-Ended Priority Queue -typedef struct fossil_test_node { - fossil_test_case_t *test_case; - struct fossil_test_node *next; - struct fossil_test_node *prev; -} fossil_test_node_t; - -// Double-Ended Priority Queue for Test Runner -typedef struct fossil_test_queue { - fossil_test_node_t *head; - fossil_test_node_t *tail; - size_t count; -} fossil_test_queue_t; - -// Stack for storing failure trace -typedef struct { - const char *stack[256]; - int top; -} fossil_test_stack_t; - -// Summary structure to track test results typedef struct { - size_t passed; - size_t failed; - size_t skipped; - size_t unexpected; - size_t expected_failed; - size_t ignored; -} fossil_test_result_summary_t; - -// Jump buffer for error handling -extern jmp_buf fossil_test_env; // Declare the jump buffer -extern fossil_test_stack_t fossil_test_stack; // Declare the stack for failure trace + fossil_test_suite_t *suite_head; + fossil_test_log_t *log_head; + int pass_count; + int fail_count; + int skip_count; + int unexpected_count; + jmp_buf jump_env; +} fossil_test_runner_t; + +// ***************************************************************************** +// Function prototypes +// ***************************************************************************** /** - * Initialize the test queue. - * - * @param queue Pointer to the test queue to initialize. + * @brief Create a new test runner. + * + * @return A pointer to the newly created test runner. */ -void fossil_test_queue_init(fossil_test_queue_t *queue); +fossil_test_runner_t *fossil_test_create_runner(void); /** - * Enqueue a test case into the test queue. - * - * @param queue Pointer to the test queue. - * @param test_case Pointer to the test case to enqueue. + * @brief Add a test case to a test suite. + * + * @param suite The test suite to which the test case will be added. + * @param name The name of the test case. + * @param test_func The function that implements the test case. */ -void fossil_test_enqueue(fossil_test_queue_t *queue, fossil_test_case_t *test_case); +void fossil_test_add_case(fossil_test_suite_t *suite, const char *name, void (*test_func)(void)); /** - * Dequeue a test case from the test queue. - * - * @param queue Pointer to the test queue. - * @return Pointer to the dequeued test case. + * @brief Create a new test suite. + * + * @param runner The test runner that will manage the test suite. + * @param name The name of the test suite. + * @return A pointer to the newly created test suite. */ -fossil_test_case_t *fossil_test_dequeue(fossil_test_queue_t *queue); +fossil_test_suite_t *fossil_test_create_suite(fossil_test_runner_t *runner, const char *name); /** - * Free the memory allocated for the test queue. - * - * @param queue Pointer to the test queue to free. - */ -void fossil_test_queue_free(fossil_test_queue_t *queue); - -/** - * Push a trace message onto the failure stack. - * - * @param stack Pointer to the failure stack. - * @param trace Trace message to push onto the stack. + * @brief Log a message with a specific test result. + * + * @param runner The test runner that manages the log. + * @param message The message to log. + * @param result The result of the test case. */ -void fossil_test_stack_push(fossil_test_stack_t *stack, const char *trace); +void fossil_test_log(fossil_test_runner_t *runner, const char *message, fossil_test_result_t result); /** - * Print the contents of the failure stack. - * - * @param stack Pointer to the failure stack to print. + * @brief Run all test cases in a test suite. + * + * @param runner The test runner that manages the test suite. + * @param suite The test suite to run. */ -void fossil_test_stack_print(const fossil_test_stack_t *stack); +void fossil_test_run_suite(fossil_test_runner_t *runner, fossil_test_suite_t *suite); /** - * Handle a caught error by printing the error message and the failure stack. - * - * @param stack Pointer to the failure stack. - * @param error_msg Error message to print. + * @brief Run all test suites managed by the test runner. + * + * @param runner The test runner that manages the test suites. */ -void fossil_test_catch(fossil_test_stack_t *stack, const char *error_msg); +void fossil_test_run(fossil_test_runner_t *runner); /** - * Run all test cases in the test queue. - * - * @param queue Pointer to the test queue. - * @param stack Pointer to the failure stack. - * @param summary Pointer to the summary structure to track test results. - * @param verbose Flag to enable verbose output. + * @brief Generate a report of the test results. + * + * @param runner The test runner that manages the test results. */ -void fossil_test_run(fossil_test_queue_t *queue, fossil_test_stack_t *stack, fossil_test_result_summary_t *summary, bool verbose); +void fossil_test_report(fossil_test_runner_t *runner); /** - * Print the summary of test results. - * - * @param summary Pointer to the summary structure containing test results. + * @brief Free the memory allocated for the test runner. + * + * @param runner The test runner to free. */ -void fossil_test_summary(const fossil_test_result_summary_t *summary); +void fossil_test_free_runner(fossil_test_runner_t *runner); /** - * Add a test case to a test suite. - * - * @param suite Pointer to the test suite. - * @param test_case Pointer to the test case to add. + * @brief Print text in a specified color. + * + * @param text The text to print. + * @param color The color to use for printing the text. */ -void fossil_test_add_suite(fossil_test_suite_t *suite, fossil_test_case_t *test_case); - -/** - * Run all test cases in a test suite. - * - * @param suite Pointer to the test suite. - * @param stack Pointer to the failure stack. - * @param summary Pointer to the summary structure to track test results. - * @param verbose Flag to enable verbose output. - */ -void fossil_test_run_suite(fossil_test_suite_t *suite, fossil_test_stack_t *stack, fossil_test_result_summary_t *summary, bool verbose); - -/** - * Set the setup function to be called before each test case. - * - * @param setup_func Pointer to the setup function. - */ -void fossil_test_setup(void (*setup_func)(void)); - -/** - * Set the teardown function to be called after each test case. - * - * @param teardown_func Pointer to the teardown function. - */ -void fossil_test_teardown(void (*teardown_func)(void)); +void fossil_test_print_color(const char *text, fossil_test_color_t color); +// ***************************************************************************** // Macros for defining and adding test cases -#define FOSSIL_TEST_DEFINE(name) void name(void) +// ***************************************************************************** + +#define FOSSIL_TEST(name) void name(void) +#define FOSSIL_TEST_SUITE(name) \ + fossil_test_suite_t name = { \ + .name = #name, \ + .tests = NULL, \ + .test_count = 0 \ + } +#define FOSSIL_TEST_SETUP(name) void name##_setup(void) +#define FOSSIL_TEST_TEARDOWN(name) void name##_teardown(void) + +#define FOSSIL_TEST_GROUP(name) void name##_group(fossil_test_runner_t runner) +#define FOSSIL_TEST_IMPORT(name) void name##_group(fossil_test_runner_t runner) +#define FOSSIL_TEST_EXPORT(name) void name##_group(fossil_test_runner_t runner) + #define FOSSIL_TEST_ADD(queue, test_func) \ do { \ fossil_test_case_t *test_case = malloc(sizeof(fossil_test_case_t)); \ @@ -212,40 +193,29 @@ void fossil_test_teardown(void (*teardown_func)(void)); fossil_test_enqueue(queue, test_case); \ } while(0) -#define FOSSIL_TEST_EXPECT_FAIL(test_func) \ - do { \ - fossil_test_case_t *test_case = malloc(sizeof(fossil_test_case_t)); \ - test_case->name = #test_func; \ - test_case->test_func = test_func; \ - test_case->result = FOSSIL_TEST_EXPECTED_FAIL; \ - test_case->duration = 0.0; \ - test_case->is_expected_fail = true; \ - test_case->is_ignored = false; \ - fossil_test_enqueue(queue, test_case); \ - } while(0) - -#define FOSSIL_TEST_IGNORE(test_func) \ +#define FOSSIL_TEST_ADDF(queue, test_func, suite) \ do { \ fossil_test_case_t *test_case = malloc(sizeof(fossil_test_case_t)); \ test_case->name = #test_func; \ test_case->test_func = test_func; \ - test_case->result = FOSSIL_TEST_IGNORED; \ + test_case->result = FOSSIL_TEST_SKIP; \ test_case->duration = 0.0; \ test_case->is_expected_fail = false; \ - test_case->is_ignored = true; \ - fossil_test_enqueue(queue, test_case); \ + test_case->is_ignored = false; \ + fossil_test_add_suite(suite, test_case); \ } while(0) -// Assertion Macro -#define FOSSIL_TEST_ASSERT(cond, msg, line, func, file) \ +#define FOSSIL_TEST_ASSUME(runner, condition, message) \ do { \ - if (!(cond)) { \ - char formatted_msg[256]; \ - snprintf(formatted_msg, sizeof(formatted_msg), "%s (at %s:%d in %s)", msg, file, line, func); \ - fossil_test_stack_push(fossil_test_stack, formatted_msg); \ - fossil_test_catch(fossil_test_stack, "Assertion failed"); \ + if (!(condition)) { \ + fossil_test_log(runner, message, FOSSIL_TEST_FAIL); \ + runner->fail_count++; \ + longjmp(runner->jump_env, 1); \ + } else { \ + fossil_test_log(runner, message, FOSSIL_TEST_PASS); \ + runner->pass_count++; \ } \ - } while(0) + } while (0) #ifdef __cplusplus } diff --git a/code/logic/unittest/unittest.c b/code/logic/unittest/unittest.c index 5fd380d4..4064f11f 100644 --- a/code/logic/unittest/unittest.c +++ b/code/logic/unittest/unittest.c @@ -19,177 +19,119 @@ #include #include -jmp_buf fossil_test_env; -fossil_test_stack_t fossil_test_stack; // Declare the stack for failure trace - -static void (*setup_func)(void) = NULL; -static void (*teardown_func)(void) = NULL; - -void fossil_test_queue_init(fossil_test_queue_t *queue) { - queue->head = NULL; - queue->tail = NULL; - queue->count = 0; -} - -void fossil_test_enqueue(fossil_test_queue_t *queue, fossil_test_case_t *test_case) { - fossil_test_node_t *node = malloc(sizeof(fossil_test_node_t)); - node->test_case = test_case; - node->next = NULL; - node->prev = queue->tail; - - if (queue->tail) { - queue->tail->next = node; +// Color Helper Function +void fossil_test_print_color(const char *text, fossil_test_color_t color) { + switch (color) { + case FOSSIL_COLOR_GREEN: printf("\033[0;32m%s\033[0m", text); break; + case FOSSIL_COLOR_RED: printf("\033[0;31m%s\033[0m", text); break; + case FOSSIL_COLOR_YELLOW: printf("\033[0;33m%s\033[0m", text); break; + case FOSSIL_COLOR_BLUE: printf("\033[0;34m%s\033[0m", text); break; + default: printf("%s", text); break; } - queue->tail = node; - - if (!queue->head) { - queue->head = node; - } - queue->count++; } -fossil_test_case_t *fossil_test_dequeue(fossil_test_queue_t *queue) { - if (!queue->head) { - return NULL; - } - - fossil_test_node_t *node = queue->head; - fossil_test_case_t *test_case = node->test_case; - queue->head = node->next; - - if (queue->head) { - queue->head->prev = NULL; - } else { - queue->tail = NULL; - } - - free(node); - queue->count--; - return test_case; +fossil_test_runner_t *fossil_test_create_runner() { + fossil_test_runner_t *runner = (fossil_test_runner_t*)malloc(sizeof(fossil_test_runner_t)); + if (!runner) return NULL; + runner->suite_head = NULL; + runner->log_head = NULL; + runner->pass_count = runner->fail_count = runner->skip_count = runner->unexpected_count = 0; + return runner; } -void fossil_test_queue_free(fossil_test_queue_t *queue) { - while (queue->head) { - free(fossil_test_dequeue(queue)); - } +void fossil_test_add_case(fossil_test_suite_t *suite, const char *name, void (*test_func)(void)) { + fossil_test_case_t *test_case = (fossil_test_case_t*)malloc(sizeof(fossil_test_case_t)); + test_case->name = name; + test_case->test_func = test_func; + test_case->result = FOSSIL_TEST_UNEXPECTED; + test_case->next = suite->test_head; + suite->test_head = test_case; } -void fossil_test_stack_push(fossil_test_stack_t *stack, const char *trace) { - if (stack->top < 255) { - stack->stack[stack->top++] = trace; - } +fossil_test_suite_t *fossil_test_create_suite(fossil_test_runner_t *runner, const char *name) { + fossil_test_suite_t *suite = (fossil_test_suite_t*)malloc(sizeof(fossil_test_suite_t)); + suite->name = name; + suite->test_head = NULL; + suite->next = runner->suite_head; + runner->suite_head = suite; + return suite; } -void fossil_test_stack_print(const fossil_test_stack_t *stack) { - printf("Stack Trace:\n"); - for (int i = 0; i < stack->top; i++) { - printf(" %s\n", stack->stack[i]); - } +void fossil_test_log(fossil_test_runner_t *runner, const char *message, fossil_test_result_t result) { + fossil_test_log_t *log = (fossil_test_log_t*)malloc(sizeof(fossil_test_log_t)); + log->message = message; + log->result = result; + log->prev = NULL; + log->next = runner->log_head; + if (runner->log_head) runner->log_head->prev = log; + runner->log_head = log; } -void fossil_test_catch(fossil_test_stack_t *stack, const char *error_msg) { - printf(FOSSIL_TEST_COLOR_RED "Error: %s\n" FOSSIL_TEST_COLOR_RESET, error_msg); - longjmp(fossil_test_env, 1); -} - -void fossil_test_run(fossil_test_queue_t *queue, fossil_test_stack_t *stack, fossil_test_result_summary_t *summary, bool verbose) { - fossil_test_case_t *test_case; - while ((test_case = fossil_test_dequeue(queue))) { - if (setup_func) setup_func(); // Call setup if defined - - clock_t start_time = clock(); - if (setjmp(fossil_test_env) == 0) { - test_case->test_func(); - test_case->result = FOSSIL_TEST_PASS; +void fossil_test_run_suite(fossil_test_runner_t *runner, fossil_test_suite_t *suite) { + fossil_test_case_t *current = suite->test_head; + while (current) { + printf(" Running test: %s\n", current->name); + if (setjmp(runner->jump_env) == 0) { + current->test_func(); + current->result = FOSSIL_TEST_PASS; } else { - test_case->result = test_case->is_expected_fail ? FOSSIL_TEST_EXPECTED_FAIL : FOSSIL_TEST_FAIL; + current->result = FOSSIL_TEST_FAIL; } - clock_t end_time = clock(); - - test_case->duration = (double)(end_time - start_time) / CLOCKS_PER_SEC; - - if (verbose) { - printf("%s: %s (%.2f seconds)\n", test_case->name, - test_case->result == FOSSIL_TEST_PASS ? FOSSIL_TEST_COLOR_GREEN "PASS" FOSSIL_TEST_COLOR_RESET : - test_case->result == FOSSIL_TEST_FAIL ? FOSSIL_TEST_COLOR_RED "FAIL" FOSSIL_TEST_COLOR_RESET : - test_case->result == FOSSIL_TEST_SKIP ? FOSSIL_TEST_COLOR_YELLOW "SKIP" FOSSIL_TEST_COLOR_RESET : - test_case->result == FOSSIL_TEST_EXPECTED_FAIL ? FOSSIL_TEST_COLOR_BLUE "EXPECTED FAIL" FOSSIL_TEST_COLOR_RESET : - FOSSIL_TEST_COLOR_YELLOW "IGNORED" FOSSIL_TEST_COLOR_RESET, - test_case->duration); - } - - switch (test_case->result) { - case FOSSIL_TEST_PASS: summary->passed++; break; - case FOSSIL_TEST_FAIL: summary->failed++; break; - case FOSSIL_TEST_SKIP: summary->skipped++; break; - case FOSSIL_TEST_UNEXPECTED: summary->unexpected++; break; - case FOSSIL_TEST_EXPECTED_FAIL: summary->expected_failed++; break; - case FOSSIL_TEST_IGNORED: summary->ignored++; break; - } - - if (teardown_func) teardown_func(); // Call teardown if defined - free(test_case); // Free allocated test case + current = current->next; } } -void fossil_test_summary(const fossil_test_result_summary_t *summary) { - printf("Test Summary:\n"); - printf(" Passed: %zu\n", summary->passed); - printf(" Failed: %zu\n", summary->failed); - printf(" Skipped: %zu\n", summary->skipped); - printf(" Unexpected: %zu\n", summary->unexpected); - printf(" Expected Failures: %zu\n", summary->expected_failed); - printf(" Ignored: %zu\n", summary->ignored); -} +void fossil_test_run(fossil_test_runner_t *runner) { + fossil_test_suite_t *suite = runner->suite_head; + while (suite) { + printf("\nRunning suite: "); + fossil_test_print_color(suite->name, FOSSIL_COLOR_BLUE); + printf("\n"); -void fossil_test_add_suite(fossil_test_suite_t *suite, fossil_test_case_t *test_case) { - suite->tests = realloc(suite->tests, sizeof(fossil_test_case_t *) * (suite->test_count + 1)); - suite->tests[suite->test_count++] = test_case; + fossil_test_run_suite(runner, suite); + suite = suite->next; + } } -void fossil_test_run_suite(fossil_test_suite_t *suite, fossil_test_stack_t *stack, fossil_test_result_summary_t *summary, bool verbose) { - for (size_t i = 0; i < suite->test_count; i++) { - fossil_test_case_t *test_case = suite->tests[i]; - if (setup_func) setup_func(); // Call setup if defined - - clock_t start_time = clock(); - if (setjmp(fossil_test_env) == 0) { - test_case->test_func(); - test_case->result = FOSSIL_TEST_PASS; - } else { - test_case->result = test_case->is_expected_fail ? FOSSIL_TEST_EXPECTED_FAIL : FOSSIL_TEST_FAIL; - } - clock_t end_time = clock(); - - test_case->duration = (double)(end_time - start_time) / CLOCKS_PER_SEC; - - if (verbose) { - printf("%s: %s (%.2f seconds)\n", test_case->name, - test_case->result == FOSSIL_TEST_PASS ? FOSSIL_TEST_COLOR_GREEN "PASS" FOSSIL_TEST_COLOR_RESET : - test_case->result == FOSSIL_TEST_FAIL ? FOSSIL_TEST_COLOR_RED "FAIL" FOSSIL_TEST_COLOR_RESET : - test_case->result == FOSSIL_TEST_SKIP ? FOSSIL_TEST_COLOR_YELLOW "SKIP" FOSSIL_TEST_COLOR_RESET : - test_case->result == FOSSIL_TEST_EXPECTED_FAIL ? FOSSIL_TEST_COLOR_BLUE "EXPECTED FAIL" FOSSIL_TEST_COLOR_RESET : - FOSSIL_TEST_COLOR_YELLOW "IGNORED" FOSSIL_TEST_COLOR_RESET, - test_case->duration); - } - - switch (test_case->result) { - case FOSSIL_TEST_PASS: summary->passed++; break; - case FOSSIL_TEST_FAIL: summary->failed++; break; - case FOSSIL_TEST_SKIP: summary->skipped++; break; - case FOSSIL_TEST_UNEXPECTED: summary->unexpected++; break; - case FOSSIL_TEST_EXPECTED_FAIL: summary->expected_failed++; break; - case FOSSIL_TEST_IGNORED: summary->ignored++; break; +void fossil_test_report(fossil_test_runner_t *runner) { + printf("\nTest Summary:\n"); + fossil_test_print_color("Pass: ", FOSSIL_COLOR_GREEN); printf("%d\n", runner->pass_count); + fossil_test_print_color("Fail: ", FOSSIL_COLOR_RED); printf("%d\n", runner->fail_count); + fossil_test_print_color("Skip: ", FOSSIL_COLOR_YELLOW); printf("%d\n", runner->skip_count); + printf("Unexpected: %d\n", runner->unexpected_count); + + printf("\nDetailed Log:\n"); + fossil_test_log_t *log = runner->log_head; + while (log) { + switch (log->result) { + case FOSSIL_TEST_PASS: fossil_test_print_color("[PASS] ", FOSSIL_COLOR_GREEN); break; + case FOSSIL_TEST_FAIL: fossil_test_print_color("[FAIL] ", FOSSIL_COLOR_RED); break; + case FOSSIL_TEST_SKIP: fossil_test_print_color("[SKIP] ", FOSSIL_COLOR_YELLOW); break; + default: printf("[UNEXPECTED] "); break; } - - if (teardown_func) teardown_func(); // Call teardown if defined + printf("%s\n", log->message); + log = log->next; } } -void fossil_test_setup(void (*setup_func_param)(void)) { - setup_func = setup_func_param; -} - -void fossil_test_teardown(void (*teardown_func_param)(void)) { - teardown_func = teardown_func_param; +void fossil_test_free_runner(fossil_test_runner_t *runner) { + fossil_test_suite_t *suite = runner->suite_head; + while (suite) { + fossil_test_case_t *test_case = suite->test_head; + while (test_case) { + fossil_test_case_t *temp = test_case; + test_case = test_case->next; + free(temp); + } + fossil_test_suite_t *temp_suite = suite; + suite = suite->next; + free(temp_suite); + } + fossil_test_log_t *log = runner->log_head; + while (log) { + fossil_test_log_t *temp = log; + log = log->next; + free(temp); + } + free(runner); } From 802298d1a474c1ae780ad9fe215c884480f5ce1a Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Sun, 3 Nov 2024 09:17:08 -0600 Subject: [PATCH 06/40] add macro interface --- code/logic/fossil/unittest/framework.h | 89 ++++++++++++++++++++++++++ code/logic/fossil/unittest/unittest.h | 81 +++++++++++++++++++---- 2 files changed, 159 insertions(+), 11 deletions(-) diff --git a/code/logic/fossil/unittest/framework.h b/code/logic/fossil/unittest/framework.h index 5109da37..4275d93d 100644 --- a/code/logic/fossil/unittest/framework.h +++ b/code/logic/fossil/unittest/framework.h @@ -21,6 +21,95 @@ extern "C" { #include "unittest.h" +/** + * Macro to define a test suite. + * This macro is used to declare a test suite, which is a collection of test + * cases that are related to each other. The test suite can be executed as a + * whole to verify the correctness of a group of functionalities. + */ +#define FOSSIL_TEST_SUITE(name) \ + _FOSSIL_TEST_SUITE(name) + +/** + * Macro to define a setup function for a test. + * This macro is used to declare a setup function that will be executed before + * each test case in a test suite. The setup function should contain the logic + * to initialize the environment or state required for the test cases. + */ +#define FOSSIL_SETUP(name) \ + _FOSSIL_TEST_SETUP(name) + +/** + * Macro to define a teardown function for a test. + * This macro is used to declare a teardown function that will be executed after + * each test case in a test suite. The teardown function should contain the logic + * to clean up the environment or state after the test cases have been executed. + */ +#define FOSSIL_TEARDOWN(name) \ + _FOSSIL_TEST_TEARDOWN(name) + +/** + * Macro to define a test group. + * This macro is used to declare a test group, which is a higher-level grouping + * of test suites. Test groups can be used to organize test suites into logical + * categories for easier management and execution. + */ +#define FOSSIL_TEST_GROUP(name) \ + _FOSSIL_TEST_GROUP(name) + +/** + * Macro to import a test. + * This macro is used to import a test case or test suite from another module + * or file. It allows for the reuse of test cases and test suites across + * different parts of the project. + */ +#define FOSSIL_TEST_IMPORT(name) \ + _FOSSIL_TEST_IMPORT(name) + +/** + * Macro to export a test. + * This macro is used to export a test case or test suite so that it can be + * imported and used in other modules or files. It facilitates the sharing of + * test cases and test suites across the project. + */ +#define FOSSIL_TEST_EXPORT(name) \ + _FOSSIL_TEST_EXPORT(name) + +/** + * Macro to define a test case. + * This macro is used to declare a test case function that will be executed + * as part of the test suite. The test case function should contain the logic + * to verify the correctness of a specific functionality. + */ +#define FOSSIL_TEST(name) \ + _FOSSIL_TEST_CASE(name) + +/** + * Macro to add a test function to a test queue. + * This macro is used to add a test function to a test queue, which is a + * collection of test functions that will be executed in sequence. The test + * queue allows for the orderly execution of multiple test functions. + */ +#define FOSSIL_TEST_ADD(queue, test_func) \ + _FOSSIL_TEST_ADD(queue, test_func) + +/** + * Macro to add a test function to a test queue with a suite. + * This macro is used to add a test function to a test queue, specifying the + * test suite to which the test function belongs. It allows for the organization + * of test functions within their respective test suites. + */ +#define FOSSIL_TEST_ADDF(queue, test_func, suite) \ + _FOSSIL_TEST_ADDF(queue, test_func, suite) + +/** + * Macro to assume a condition in a test runner. + * This macro is used to assert that a specific condition is true within a test + * runner. If the condition is false, the test runner will output the specified + * message and may abort the execution of the test case or test suite. + */ +#define FOSSIL_TEST_ASSUME(runner, condition, message) \ + _FOSSIL_TEST_ASSUME(runner, condition, message) #ifdef __cplusplus } diff --git a/code/logic/fossil/unittest/unittest.h b/code/logic/fossil/unittest/unittest.h index 3406da8e..98e9bdac 100644 --- a/code/logic/fossil/unittest/unittest.h +++ b/code/logic/fossil/unittest/unittest.h @@ -166,22 +166,67 @@ void fossil_test_print_color(const char *text, fossil_test_color_t color); // ***************************************************************************** // Macros for defining and adding test cases // ***************************************************************************** - -#define FOSSIL_TEST(name) void name(void) -#define FOSSIL_TEST_SUITE(name) \ +/** + * @brief Define a test suite. + * + * @param name The name of the test suite. + */ +#define _FOSSIL_TEST_SUITE(name) \ fossil_test_suite_t name = { \ .name = #name, \ .tests = NULL, \ .test_count = 0 \ } -#define FOSSIL_TEST_SETUP(name) void name##_setup(void) -#define FOSSIL_TEST_TEARDOWN(name) void name##_teardown(void) -#define FOSSIL_TEST_GROUP(name) void name##_group(fossil_test_runner_t runner) -#define FOSSIL_TEST_IMPORT(name) void name##_group(fossil_test_runner_t runner) -#define FOSSIL_TEST_EXPORT(name) void name##_group(fossil_test_runner_t runner) +/** + * @brief Define a setup function for a test suite. + * + * @param name The name of the setup function. + */ +#define _FOSSIL_TEST_SETUP(name) void name##_setup(void) -#define FOSSIL_TEST_ADD(queue, test_func) \ +/** + * @brief Define a teardown function for a test suite. + * + * @param name The name of the teardown function. + */ +#define _FOSSIL_TEST_TEARDOWN(name) void name##_teardown(void) + +/** + * @brief Define a group of test cases. + * + * @param name The name of the test group. + */ +#define _FOSSIL_TEST_GROUP(name) void name##_group(fossil_test_runner_t runner) + +/** + * @brief Import a group of test cases. + * + * @param name The name of the test group to import. + */ +#define _FOSSIL_TEST_IMPORT(name) void name##_group(fossil_test_runner_t runner) + +/** + * @brief Export a group of test cases. + * + * @param name The name of the test group to export. + */ +#define _FOSSIL_TEST_EXPORT(name) void name##_group(fossil_test_runner_t runner) + +/** + * @brief Define a test case. + * + * @param name The name of the test case. + */ +#define _FOSSIL_TEST_CASE(name) void name(void) + +/** + * @brief Add a test case to a queue. + * + * @param queue The queue to which the test case will be added. + * @param test_func The function that implements the test case. + */ +#define _FOSSIL_TEST_ADD(queue, test_func) \ do { \ fossil_test_case_t *test_case = malloc(sizeof(fossil_test_case_t)); \ test_case->name = #test_func; \ @@ -193,7 +238,14 @@ void fossil_test_print_color(const char *text, fossil_test_color_t color); fossil_test_enqueue(queue, test_case); \ } while(0) -#define FOSSIL_TEST_ADDF(queue, test_func, suite) \ +/** + * @brief Add a test case to a suite. + * + * @param queue The queue to which the test case will be added. + * @param test_func The function that implements the test case. + * @param suite The test suite to which the test case will be added. + */ +#define _FOSSIL_TEST_ADDF(queue, test_func, suite) \ do { \ fossil_test_case_t *test_case = malloc(sizeof(fossil_test_case_t)); \ test_case->name = #test_func; \ @@ -205,7 +257,14 @@ void fossil_test_print_color(const char *text, fossil_test_color_t color); fossil_test_add_suite(suite, test_case); \ } while(0) -#define FOSSIL_TEST_ASSUME(runner, condition, message) \ +/** + * @brief Assume a condition is true, otherwise log a failure and jump to the test runner's environment. + * + * @param runner The test runner that manages the test cases. + * @param condition The condition to assume. + * @param message The message to log if the condition is false. + */ +#define _FOSSIL_TEST_ASSUME(runner, condition, message) \ do { \ if (!(condition)) { \ fossil_test_log(runner, message, FOSSIL_TEST_FAIL); \ From d4e82011ea7fd58980137e6ac2f04a837e8f88de Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Sun, 3 Nov 2024 16:19:22 -0600 Subject: [PATCH 07/40] restructure entire framework --- code/logic/{benchmark => }/benchmark.c | 2 +- code/logic/benchmark/meson.build | 10 - code/logic/fossil/_common/common.h | 107 --- code/logic/fossil/_common/platform.h | 145 --- code/logic/fossil/mockup/framework.h | 98 -- code/logic/fossil/test/assume.h | 868 ++++++++++++++++++ .../fossil/{benchmark => test}/benchmark.h | 2 - .../fossil/{benchmark => test}/framework.h | 243 ++++- code/logic/fossil/{mockup => test}/mockup.h | 1 - code/logic/fossil/test/unittest.h | 261 ++++++ code/logic/fossil/unittest/assume.h | 868 ------------------ code/logic/fossil/unittest/framework.h | 118 --- code/logic/fossil/unittest/unittest.h | 292 ------ code/logic/meson.build | 13 +- code/logic/{mockup => }/mockup.c | 2 +- code/logic/mockup/meson.build | 10 - code/logic/unittest.c | 216 +++++ code/logic/unittest/commands.c | 115 --- code/logic/unittest/console.c | 491 ---------- code/logic/unittest/meson.build | 10 - code/logic/unittest/unittest.c | 137 --- code/tests/generate-runner.py | 4 +- code/tests/meson.build | 4 +- code/tests/test_bdd.c | 28 +- code/tests/test_marks.c | 26 +- code/tests/test_mocks.c | 4 +- code/tests/test_sample.c | 54 ++ code/tests/test_tags.c | 50 +- code/tests/test_tdd.c | 208 +++-- code/tests/test_xfixture.c | 99 -- code/tests/test_xsoneros.c | 152 --- code/tests/unit_runner.c | 17 + 32 files changed, 1822 insertions(+), 2833 deletions(-) rename code/logic/{benchmark => }/benchmark.c (99%) delete mode 100644 code/logic/benchmark/meson.build delete mode 100644 code/logic/fossil/_common/common.h delete mode 100644 code/logic/fossil/_common/platform.h delete mode 100644 code/logic/fossil/mockup/framework.h create mode 100644 code/logic/fossil/test/assume.h rename code/logic/fossil/{benchmark => test}/benchmark.h (99%) rename code/logic/fossil/{benchmark => test}/framework.h (50%) rename code/logic/fossil/{mockup => test}/mockup.h (99%) create mode 100644 code/logic/fossil/test/unittest.h delete mode 100644 code/logic/fossil/unittest/assume.h delete mode 100644 code/logic/fossil/unittest/framework.h delete mode 100644 code/logic/fossil/unittest/unittest.h rename code/logic/{mockup => }/mockup.c (98%) delete mode 100644 code/logic/mockup/meson.build create mode 100644 code/logic/unittest.c delete mode 100644 code/logic/unittest/commands.c delete mode 100644 code/logic/unittest/console.c delete mode 100644 code/logic/unittest/meson.build delete mode 100644 code/logic/unittest/unittest.c create mode 100644 code/tests/test_sample.c delete mode 100644 code/tests/test_xfixture.c delete mode 100644 code/tests/test_xsoneros.c create mode 100644 code/tests/unit_runner.c diff --git a/code/logic/benchmark/benchmark.c b/code/logic/benchmark.c similarity index 99% rename from code/logic/benchmark/benchmark.c rename to code/logic/benchmark.c index 0abff793..c864602e 100644 --- a/code/logic/benchmark/benchmark.c +++ b/code/logic/benchmark.c @@ -14,7 +14,7 @@ * Copyright (C) 2024 Fossil Logic. All rights reserved. * ----------------------------------------------------------------------------- */ -#include "fossil/benchmark/benchmark.h" +#include "fossil/test/benchmark.h" #include #include #include diff --git a/code/logic/benchmark/meson.build b/code/logic/benchmark/meson.build deleted file mode 100644 index ea9ee0b0..00000000 --- a/code/logic/benchmark/meson.build +++ /dev/null @@ -1,10 +0,0 @@ -mark_code = ['benchmark.c'] - -fossil_mark_lib = library('fossil-mark', - mark_code, - install: true, - include_directories: dir) - -fossil_mark_dep = declare_dependency( - link_with: fossil_mark_lib, - include_directories: dir) \ No newline at end of file diff --git a/code/logic/fossil/_common/common.h b/code/logic/fossil/_common/common.h deleted file mode 100644 index 071fde80..00000000 --- a/code/logic/fossil/_common/common.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#ifndef FOSSIL_TEST_COMMON_H -#define FOSSIL_TEST_COMMON_H - -#ifdef _WIN32 -#include -#else -#define _GNU_SOURCE // Define _GNU_SOURCE for C code -#endif - -#ifdef _WIN32 -#include -#else -#include -#include -#ifdef __APPLE__ -#include -#include -#include -#else -#include -#endif -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// becuase Microsoft had to be diffrent -#ifdef _WIN32 -#define wcsncasecmp _wcsnicmp -#endif - -// Used in floating-point asserts -#define FOSSIL_TEST_FLOAT_EPSILON 1e-6 -#define FOSSIL_TEST_DOUBLE_EPSILON 1e-9 - -#if __cplusplus >= 201103L || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) -/** - * @brief Definition for xnull pointers in C++11 and later or C23 and later. - * - * In C++11 or later, `xnullptr` is a keyword representing a xnull pointer constant. - * In C23 or later, `_xnullptr` is recognized in the same way as C++. - */ - #define xnull nullptr - #define xnullptr nullptr - #define xterm '\0' -#else - #if defined(_WIN64) || defined(_WIN32) -/** - * @brief Definition for xnull pointers on Windows systems. - * - * For Windows (both 32-bit and 64-bit), we define `xnull` and `xnullptr` as 0. - */ - #define xnull 0 - #define xnullptr 0 - #define xterm '\0' - #else -/** - * @brief Definition for xnull pointers on POSIX systems, macOS, and embedded systems. - * - * For POSIX, macOS, and embedded systems, we define `xnull` and `xnullptr` as a void pointer to 0. - */ - #define xnull (void *)(0) - #define xnullptr (void *)(0) - #define xterm '\0' - #endif -#endif - -// Custom implementation of strdup -static inline char* _custom_fossil_test_strdup(const char* str) { - if (!str) return xnull; // Handle NULL pointer gracefully - - size_t len = 0; - while (str[len] != '\0') len++; // Calculate the length of the string - - char* dup = (char*)malloc((len + 1) * sizeof(char)); // Allocate memory for the duplicate string - if (!dup) return xnull; // Check if malloc failed - - for (size_t i = 0; i < len; i++) { - dup[i] = str[i]; // Copy each character from the original string to the duplicate - } - dup[len] = '\0'; // Add null terminator to the end of the duplicate string - - return dup; -} - -#endif diff --git a/code/logic/fossil/_common/platform.h b/code/logic/fossil/_common/platform.h deleted file mode 100644 index 5e3feccd..00000000 --- a/code/logic/fossil/_common/platform.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#ifndef FOSSIL_TEST_PLATFORM_H -#define FOSSIL_TEST_PLATFORM_H - -#include "common.h" // for introspection data - -#ifdef __cplusplus -extern "C" { -#endif - -// Utility function to get the architecture -static inline char* _fossil_test_get_architecture(void) { - char* arch = (char*)malloc(10 * sizeof(char)); // Explicit cast for C++ - if (arch == NULL) { - return NULL; - } -#ifdef _WIN32 - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); - switch (sysinfo.wProcessorArchitecture) { - case PROCESSOR_ARCHITECTURE_AMD64: - strncpy(arch, "x86_64", 9); - break; - case PROCESSOR_ARCHITECTURE_ARM: - strncpy(arch, "ARM", 9); - break; - case PROCESSOR_ARCHITECTURE_ARM64: - strncpy(arch, "ARM64", 9); - break; - case PROCESSOR_ARCHITECTURE_INTEL: - strncpy(arch, "x86", 9); - break; - default: - strncpy(arch, "unknown", 9); - } - arch[9] = '\0'; -#else - struct utsname buffer; - if (uname(&buffer) == 0) { - strncpy(arch, buffer.machine, 9); - } else { - strncpy(arch, "unknown", 9); - } - arch[9] = '\0'; -#endif - return arch; -} - -// Utility function to get the OS name -static inline char* _fossil_test_get_os_name(void) { - char* os_name = (char*)malloc(20 * sizeof(char)); // Explicit cast for C++ - if (os_name == NULL) { - return NULL; - } -#ifdef _WIN32 - strncpy(os_name, "Windows", 19); -#else - struct utsname buffer; - if (uname(&buffer) == 0) { - strncpy(os_name, buffer.sysname, 19); - } else { - strncpy(os_name, "unknown", 19); - } -#endif - os_name[19] = '\0'; - return os_name; -} - -// Utility function to check if the system is big endian -static inline bool _fossil_test_assert_is_big_endian(void) { - uint16_t num = 0x1; - return (*(uint8_t *)&num == 0); -} - -// Utility function to get the number of CPUs -static inline int _fossil_test_get_num_cpus(void) { -#ifdef _WIN32 - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); - return sysinfo.dwNumberOfProcessors; -#elif defined(__APPLE__) - int num_cpus; - size_t size = sizeof(num_cpus); - if (sysctlbyname("hw.ncpu", &num_cpus, &size, NULL, 0) == 0) { - return num_cpus; - } else { - return 1; // Default to 1 if unable to get the number of CPUs - } -#else - return sysconf(_SC_NPROCESSORS_ONLN); -#endif -} - -// Utility function to get the total memory size in MB -static inline int _fossil_test_get_memory_size(void) { -#ifdef _WIN32 - MEMORYSTATUSEX status; - status.dwLength = sizeof(status); - if (GlobalMemoryStatusEx(&status)) { - return (int)(status.ullTotalPhys / (1024 * 1024)); - } else { - fprintf(stderr, "Failed to get memory status on Windows\n"); - return 0; - } -#elif defined(__APPLE__) - int64_t mem_size; - size_t size = sizeof(mem_size); - if (sysctlbyname("hw.memsize", &mem_size, &size, NULL, 0) == 0) { - return (int)(mem_size / (1024 * 1024)); - } else { - fprintf(stderr, "Failed to get memory size on macOS\n"); - return 0; - } -#elif defined(__linux__) - struct sysinfo info; - if (sysinfo(&info) == 0) { - return (int)(info.totalram * info.mem_unit / (1024 * 1024)); - } else { - fprintf(stderr, "Failed to get memory size on Linux\n"); - return 0; - } -#else - fprintf(stderr, "Unsupported platform\n"); - return 0; -#endif -} - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/code/logic/fossil/mockup/framework.h b/code/logic/fossil/mockup/framework.h deleted file mode 100644 index b7a86bc6..00000000 --- a/code/logic/fossil/mockup/framework.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * File: framework.hpp - * Project: Fossil Logic - * Description: This file implments the framework for mockup testing. - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#ifndef FOSSIL_MOCK_FRAMEWORK_H -#define FOSSIL_MOCK_FRAMEWORK_H - -#include "mockup.h" - -/** - * @brief Macro for initializing the mock list. - * - * This macro initializes the mock list by calling the fossil_mock_init function. - * - * @param list The mock list to initialize. - */ -#define MOCK_INIT(list) _MOCK_INIT(list) - -/** - * @brief Macro for destroying the mock list. - * - * This macro destroys the mock list by calling the fossil_mock_destroy function. - * - * @param list The mock list to destroy. - */ -#define MOCK_DESTROY(list) _MOCK_DESTROY(list) - -/** - * @brief Macro for adding a mock function call to the mock list. - * - * This macro adds a mock function call to the mock list by calling the fossil_mock_add_call function. - * - * @param list The mock list to add the call to. - * @param func The mock function to add the call for. - * @param args The arguments of the mock function call. - * @param num_args The number of arguments in the mock function call. - */ -#define MOCK_ADD_CALL(list, func, args, num_args) _MOCK_ADD_CALL(list, func, args, num_args) - -/** - * @brief Macro for printing the mock list. - * - * This macro prints the mock list by calling the fossil_mock_print function. - * - * @param list The mock list to print. - */ -#define MOCK_PRINT(list) _MOCK_PRINT(list) -/** - * @def FOSSIL_MOCK_FUNC - * @brief Macro for creating a mock function with the specified return type, name, and parameters. - * - * This macro simplifies the creation of mock functions by defining a function with the given return - * type, name, and parameters. The function name will be prefixed with "fossil_mockup_" to clearly indicate - * that it is a mock function. - * - * @param return_type The return type of the mock function. - * @param name The name of the mock function. - * @param ... The parameters of the mock function in the format: (type1 param1, type2 param2, ...). - * @return The return type specified for the mock function. - */ -#define FOSSIL_MOCK_FUNC(return_type, name, ...) _FOSSIL_MOCK_FUNC(return_type, name, __VA_ARGS__) - -/** - * @def FOSSIL_MOCK_ALIAS - * @brief Macro for creating a type alias based on an existing type. - * - * This macro creates a type alias for a given existing type. - * - * @param new_type The name of the new type alias. - * @param existing_type The existing type to create an alias for. - */ -#define FOSSIL_MOCK_ALIAS(new_type, existing_type) _FOSSIL_MOCK_ALIAS(new_type, existing_type) - -/** - * @def FOSSIL_MOCK_STRUCT - * @brief Macro for creating a mock struct with the specified name and members. - * - * This macro simplifies the creation of mock structs by defining a struct with the given name - * and members. The struct name will be prefixed with "fossil_mockup_" to clearly indicate that it is a mock struct. - * - * @param name The name of the mock struct. - * @param ... The members of the mock struct in the format: (type1 member1, type2 member2, ...). - */ -#define FOSSIL_MOCK_STRUCT(name, ...) _FOSSIL_MOCK_STRUCT(name, __VA_ARGS__) - -#endif // FOSSIL_MOCK_FRAMEWORK_H diff --git a/code/logic/fossil/test/assume.h b/code/logic/fossil/test/assume.h new file mode 100644 index 00000000..8095bd65 --- /dev/null +++ b/code/logic/fossil/test/assume.h @@ -0,0 +1,868 @@ +/* + * ----------------------------------------------------------------------------- + * Project: Fossil Logic + * + * This file is part of the Fossil Logic project, which aims to develop high- + * performance, cross-platform applications and libraries. The code contained + * herein is subject to the terms and conditions defined in the project license. + * + * Author: Michael Gene Brockus (Dreamer) + * Date: 07/01/2024 + * + * Copyright (C) 2024 Fossil Logic. All rights reserved. + * ----------------------------------------------------------------------------- + */ +#ifndef FOSSIL_TEST_ASSUME_TYPE_H +#define FOSSIL_TEST_ASSUME_TYPE_H + +#include "framework.h" + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// ************************************************** +// +// Boolean ASSUMEions +// +// ************************************************** + +// Boolean ITS ASSUMEions +#define ASSUME_ITS_TRUE(actual) \ + FOSSIL_TEST_ASSUME((actual), "Expected " #actual " to be true") + +#define ASSUME_ITS_FALSE(actual) \ + FOSSIL_TEST_ASSUME(!(actual), "Expected " #actual " to be false") + +// Boolean NOT ASSUMEions +#define ASSUME_NOT_TRUE(actual) \ + FOSSIL_TEST_ASSUME(!(actual), "Expected " #actual " to not be true") + +#define ASSUME_NOT_FALSE(actual) \ + FOSSIL_TEST_ASSUME((actual), "Expected " #actual " to not be false") + +// ************************************************** +// +// Floating point ASSUMEions +// +// ************************************************** + +// Double equality check with tolerance +#define ASSUME_ITS_EQUAL_F64(actual, expected, tol) \ + FOSSIL_TEST_ASSUME(fabs((actual) - (expected)) <= (tol), "Expected " #actual " to be equal to " #expected " within tolerance " #tol) + +#define ASSUME_ITS_LESS_THAN_F64(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) < (expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_F64(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) > (expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_F64(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) <= (expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_F64(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) >= (expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_F64(actual, expected, tol) \ + FOSSIL_TEST_ASSUME(fabs((actual) - (expected)) > (tol), "Expected " #actual " to not be equal to " #expected " within tolerance " #tol) + +#define ASSUME_NOT_LESS_THAN_F64(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) >= (expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_F64(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) <= (expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_F64(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) > (expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_F64(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) < (expected), "Expected " #actual " to not be more than or equal to " #expected) + +// Float equality check with tolerance +#define ASSUME_ITS_EQUAL_F32(actual, expected, tol) \ + FOSSIL_TEST_ASSUME(fabsf((actual) - (expected)) <= (tol), "Expected " #actual " to be equal to " #expected " within tolerance " #tol) + +#define ASSUME_ITS_LESS_THAN_F32(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) < (expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_F32(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) > (expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_F32(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) <= (expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_F32(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) >= (expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_F32(actual, expected, tol) \ + FOSSIL_TEST_ASSUME(fabsf((actual) - (expected)) > (tol), "Expected " #actual " to not be equal to " #expected " within tolerance " #tol) + +#define ASSUME_NOT_LESS_THAN_F32(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) >= (expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_F32(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) <= (expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_F32(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) > (expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_F32(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) < (expected), "Expected " #actual " to not be more than or equal to " #expected) + +// Float NaN and Infinity checks +#define ASSUME_ITS_NAN_F32(actual) \ + FOSSIL_TEST_ASSUME(isnan(actual), "Expected " #actual " to be NaN") + +#define ASSUME_ITS_INF_F32(actual) \ + FOSSIL_TEST_ASSUME(isinf(actual), "Expected " #actual " to be infinity") + +// Double NaN and Infinity checks +#define ASSUME_ITS_NAN_F64(actual) \ + FOSSIL_TEST_ASSUME(isnan(actual), "Expected " #actual " to be NaN") + +#define ASSUME_ITS_INF_F64(actual) \ + FOSSIL_TEST_ASSUME(isinf(actual), "Expected " #actual " to be infinity") + +// ************************************************** +// +// Numaric ASSUMEions +// +// ************************************************** + +// Octal ASSUMEions + +// O8 ASSUMEions +#define ASSUME_ITS_EQUAL_O8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) == (uint8_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_O8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_O8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_O8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_O8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_O8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) != (uint8_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_O8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_O8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_O8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_O8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// O16 ASSUMEions +#define ASSUME_ITS_EQUAL_O16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) == (uint16_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_O16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_O16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_O16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_O16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_O16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) != (uint16_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_O16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_O16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_O16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_O16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// O32 ASSUMEions +#define ASSUME_ITS_EQUAL_O32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) == (uint32_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_O32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_O32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_O32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_O32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_O32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) != (uint32_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_O32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_O32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_O32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_O32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// OI64 ASSUMEions +#define ASSUME_ITS_EQUAL_O64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) == (uint64_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_O64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_O64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_O64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_O64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_O64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) != (uint64_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_O64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_O64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_O64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_O64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// Hexadecimal ASSUMEions + +// H8 ASSUMEions +#define ASSUME_ITS_EQUAL_H8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) == (uint8_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_H8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_H8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_H8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_H8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_H8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) != (uint8_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_H8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_H8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_H8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_H8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// H16 ASSUMEions +#define ASSUME_ITS_EQUAL_H16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) == (uint16_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_H16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_H16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_H16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_H16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_H16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) != (uint16_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_H16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_H16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_H16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_H16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// H32 ASSUMEions +#define ASSUME_ITS_EQUAL_H32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) == (uint32_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_H32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_H32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_H32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_H32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_H32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) != (uint32_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_H32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_H32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_H32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_H32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// H64 ASSUMEions +#define ASSUME_ITS_EQUAL_H64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) == (uint64_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_H64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_H64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_H64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_H64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_H64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) != (uint64_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_H64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_H64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_H64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_H64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// I8 ASSUMEions +#define ASSUME_ITS_EQUAL_I8(actual, expected) \ + FOSSIL_TEST_ASSUME((int8_t)(actual) == (int8_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_I8(actual, expected) \ + FOSSIL_TEST_ASSUME((int8_t)(actual) < (int8_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_I8(actual, expected) \ + FOSSIL_TEST_ASSUME((int8_t)(actual) > (int8_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_I8(actual, expected) \ + FOSSIL_TEST_ASSUME((int8_t)(actual) <= (int8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_I8(actual, expected) \ + FOSSIL_TEST_ASSUME((int8_t)(actual) >= (int8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_I8(actual, expected) \ + FOSSIL_TEST_ASSUME((int8_t)(actual) != (int8_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_I8(actual, expected) \ + FOSSIL_TEST_ASSUME((int8_t)(actual) >= (int8_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_I8(actual, expected) \ + FOSSIL_TEST_ASSUME((int8_t)(actual) <= (int8_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_I8(actual, expected) \ + FOSSIL_TEST_ASSUME((int8_t)(actual) > (int8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_I8(actual, expected) \ + FOSSIL_TEST_ASSUME((int8_t)(actual) < (int8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// I16 ASSUMEions +#define ASSUME_ITS_EQUAL_I16(actual, expected) \ + FOSSIL_TEST_ASSUME((int16_t)(actual) == (int16_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_I16(actual, expected) \ + FOSSIL_TEST_ASSUME((int16_t)(actual) < (int16_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_I16(actual, expected) \ + FOSSIL_TEST_ASSUME((int16_t)(actual) > (int16_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_I16(actual, expected) \ + FOSSIL_TEST_ASSUME((int16_t)(actual) <= (int16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_I16(actual, expected) \ + FOSSIL_TEST_ASSUME((int16_t)(actual) >= (int16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_I16(actual, expected) \ + FOSSIL_TEST_ASSUME((int16_t)(actual) != (int16_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_I16(actual, expected) \ + FOSSIL_TEST_ASSUME((int16_t)(actual) >= (int16_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_I16(actual, expected) \ + FOSSIL_TEST_ASSUME((int16_t)(actual) <= (int16_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_I16(actual, expected) \ + FOSSIL_TEST_ASSUME((int16_t)(actual) > (int16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_I16(actual, expected) \ + FOSSIL_TEST_ASSUME((int16_t)(actual) < (int16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// I32 ASSUMEions +#define ASSUME_ITS_EQUAL_I32(actual, expected) \ + FOSSIL_TEST_ASSUME((int32_t)(actual) == (int32_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_I32(actual, expected) \ + FOSSIL_TEST_ASSUME((int32_t)(actual) < (int32_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_I32(actual, expected) \ + FOSSIL_TEST_ASSUME((int32_t)(actual) > (int32_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_I32(actual, expected) \ + FOSSIL_TEST_ASSUME((int32_t)(actual) <= (int32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_I32(actual, expected) \ + FOSSIL_TEST_ASSUME((int32_t)(actual) >= (int32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_I32(actual, expected) \ + FOSSIL_TEST_ASSUME((int32_t)(actual) != (int32_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_I32(actual, expected) \ + FOSSIL_TEST_ASSUME((int32_t)(actual) >= (int32_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_I32(actual, expected) \ + FOSSIL_TEST_ASSUME((int32_t)(actual) <= (int32_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_I32(actual, expected) \ + FOSSIL_TEST_ASSUME((int32_t)(actual) > (int32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_I32(actual, expected) \ + FOSSIL_TEST_ASSUME((int32_t)(actual) < (int32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// I64 ASSUMEions +#define ASSUME_ITS_EQUAL_I64(actual, expected) \ + FOSSIL_TEST_ASSUME((int64_t)(actual) == (int64_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_I64(actual, expected) \ + FOSSIL_TEST_ASSUME((int64_t)(actual) < (int64_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_I64(actual, expected) \ + FOSSIL_TEST_ASSUME((int64_t)(actual) > (int64_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_I64(actual, expected) \ + FOSSIL_TEST_ASSUME((int64_t)(actual) <= (int64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_I64(actual, expected) \ + FOSSIL_TEST_ASSUME((int64_t)(actual) >= (int64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_I64(actual, expected) \ + FOSSIL_TEST_ASSUME((int64_t)(actual) != (int64_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_I64(actual, expected) \ + FOSSIL_TEST_ASSUME((int64_t)(actual) >= (int64_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_I64(actual, expected) \ + FOSSIL_TEST_ASSUME((int64_t)(actual) <= (int64_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_I64(actual, expected) \ + FOSSIL_TEST_ASSUME((int64_t)(actual) > (int64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_I64(actual, expected) \ + FOSSIL_TEST_ASSUME((int64_t)(actual) < (int64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// U8 ASSUMEions +#define ASSUME_ITS_EQUAL_U8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) == (uint8_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_U8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_U8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_U8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_U8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_U8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) != (uint8_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_U8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_U8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_U8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_U8(actual, expected) \ + FOSSIL_TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// U16 ASSUMEions +#define ASSUME_ITS_EQUAL_U16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) == (uint16_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_U16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_U16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_U16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_U16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_U16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) != (uint16_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_U16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_U16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_U16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_U16(actual, expected) \ + FOSSIL_TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// U32 ASSUMEions +#define ASSUME_ITS_EQUAL_U32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) == (uint32_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_U32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_U32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_U32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_U32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_U32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) != (uint32_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_U32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_U32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_U32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_U32(actual, expected) \ + FOSSIL_TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// U64 ASSUMEions +#define ASSUME_ITS_EQUAL_U64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) == (uint64_t)(expected), "Expected " #actual " to be equal to " #expected) + +#define ASSUME_ITS_LESS_THAN_U64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to be less than " #expected) + +#define ASSUME_ITS_MORE_THAN_U64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to be more than " #expected) + +#define ASSUME_ITS_LESS_OR_EQUAL_U64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +#define ASSUME_ITS_MORE_OR_EQUAL_U64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +#define ASSUME_NOT_EQUAL_U64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) != (uint64_t)(expected), "Expected " #actual " to not be equal to " #expected) + +#define ASSUME_NOT_LESS_THAN_U64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to not be less than " #expected) + +#define ASSUME_NOT_MORE_THAN_U64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to not be more than " #expected) + +#define ASSUME_NOT_LESS_OR_EQUAL_U64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) + +#define ASSUME_NOT_MORE_OR_EQUAL_U64(actual, expected) \ + FOSSIL_TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + +// ************************************************** +// +// Null pointer ASSUMEions (_CNULL) +// +// ************************************************** + +// ITS set +#define ASSUME_ITS_CNULL(actual) \ + FOSSIL_TEST_ASSUME((actual) == xnull, "Expected " #actual " to be xnull") + +#define ASSUME_NOT_CNULL(actual) \ + FOSSIL_TEST_ASSUME((actual) != xnull, "Expected " #actual " to not be xnull") + +// General pointer ASSUMEions (_PTR) + +// ITS set +#define ASSUME_ITS_EQUAL_PTR(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) == (expected), "Expected pointer " #actual " to be equal to pointer " #expected " ") + +#define ASSUME_NOT_EQUAL_PTR(actual, expected) \ + FOSSIL_TEST_ASSUME((actual) != (expected), "Expected pointer " #actual " to not be equal to pointer " #expected " ") + +// Size_t ASSUMEions + +// Equal +#define ASSUME_ITS_EQUAL_SIZE(actual, expected) \ + FOSSIL_TEST_ASSUME((size_t)(actual) == (size_t)(expected), "Expected " #actual " to be equal to " #expected) + +// Less than +#define ASSUME_ITS_LESS_THAN_SIZE(actual, expected) \ + FOSSIL_TEST_ASSUME((size_t)(actual) < (size_t)(expected), "Expected " #actual " to be less than " #expected) + +// More than +#define ASSUME_ITS_MORE_THAN_SIZE(actual, expected) \ + FOSSIL_TEST_ASSUME((size_t)(actual) > (size_t)(expected), "Expected " #actual " to be more than " #expected) + +// Less or equal +#define ASSUME_ITS_LESS_OR_EQUAL_SIZE(actual, expected) \ + FOSSIL_TEST_ASSUME((size_t)(actual) <= (size_t)(expected), "Expected " #actual " to be less than or equal to " #expected) + +// More or equal +#define ASSUME_ITS_MORE_OR_EQUAL_SIZE(actual, expected) \ + FOSSIL_TEST_ASSUME((size_t)(actual) >= (size_t)(expected), "Expected " #actual " to be more than or equal to " #expected) + +// Not equal +#define ASSUME_NOT_EQUAL_SIZE(actual, expected) \ + FOSSIL_TEST_ASSUME((size_t)(actual) != (size_t)(expected), "Expected " #actual " to not be equal to " #expected) + +// ************************************************** +// +// Range ASSUMEions +// +// ************************************************** + +// ASSUMEion for checking if a value is within a specified range +#define ASSUME_ITS_WITHIN_RANGE(value, min, max) \ + FOSSIL_TEST_ASSUME((value) >= (min) && (value) <= (max), "Value " #value " is not within range [" #min ", " #max "]") + +#define ASSUME_NOT_WITHIN_RANGE(value, min, max) \ + FOSSIL_TEST_ASSUME((value) < (min) || (value) > (max), "Value " #value " is within range [" #min ", " #max "]") + +// Unsigned integer type ASSUMEions + +#define ASSUME_ITS_WITHIN_RANGE_U8(value, min, max) \ + FOSSIL_TEST_ASSUME((uint8_t)(value) >= (uint8_t)(min) && (uint8_t)(value) <= (uint8_t)(max), "Value " #value " is not within range [" #min ", " #max "]") + +#define ASSUME_NOT_WITHIN_RANGE_U8(value, min, max) \ + FOSSIL_TEST_ASSUME((uint8_t)(value) < (uint8_t)(min) || (uint8_t)(value) > (uint8_t)(max), "Value " #value " is within range [" #min ", " #max "]") + +#define ASSUME_ITS_WITHIN_RANGE_U16(value, min, max) \ + FOSSIL_TEST_ASSUME((uint16_t)(value) >= (uint16_t)(min) && (uint16_t)(value) <= (uint16_t)(max), "Value " #value " is not within range [" #min ", " #max "]") + +#define ASSUME_NOT_WITHIN_RANGE_U16(value, min, max) \ + FOSSIL_TEST_ASSUME((uint16_t)(value) < (uint16_t)(min) || (uint16_t)(value) > (uint16_t)(max), "Value " #value " is within range [" #min ", " #max "]") + +#define ASSUME_ITS_WITHIN_RANGE_U32(value, min, max) \ + FOSSIL_TEST_ASSUME((uint32_t)(value) >= (uint32_t)(min) && (uint32_t)(value) <= (uint32_t)(max), "Value " #value " is not within range [" #min ", " #max "]") + +#define ASSUME_NOT_WITHIN_RANGE_U32(value, min, max) \ + FOSSIL_TEST_ASSUME((uint32_t)(value) < (uint32_t)(min) || (uint32_t)(value) > (uint32_t)(max), "Value " #value " is within range [" #min ", " #max "]") + +#define ASSUME_ITS_WITHIN_RANGE_U64(value, min, max) \ + FOSSIL_TEST_ASSUME((uint64_t)(value) >= (uint64_t)(min) && (uint64_t)(value) <= (uint64_t)(max), "Value " #value " is not within range [" #min ", " #max "]") + +#define ASSUME_NOT_WITHIN_RANGE_U64(value, min, max) \ + FOSSIL_TEST_ASSUME((uint64_t)(value) < (uint64_t)(min) || (uint64_t)(value) > (uint64_t)(max), "Value " #value " is within range [" #min ", " #max "]") + +// Signed integer type ASSUMEions + +#define ASSUME_ITS_WITHIN_RANGE_I8(value, min, max) \ + FOSSIL_TEST_ASSUME((int8_t)(value) >= (int8_t)(min) && (int8_t)(value) <= (int8_t)(max), "Value " #value " is not within range [" #min ", " #max "]") + +#define ASSUME_NOT_WITHIN_RANGE_I8(value, min, max) \ + FOSSIL_TEST_ASSUME((int8_t)(value) < (int8_t)(min) || (int8_t)(value) > (int8_t)(max), "Value " #value " is within range [" #min ", " #max "]") + +#define ASSUME_ITS_WITHIN_RANGE_I16(value, min, max) \ + FOSSIL_TEST_ASSUME((int16_t)(value) >= (int16_t)(min) && (int16_t)(value) <= (int16_t)(max), "Value " #value " is not within range [" #min ", " #max "]") + +#define ASSUME_NOT_WITHIN_RANGE_I16(value, min, max) \ + FOSSIL_TEST_ASSUME((int16_t)(value) < (int16_t)(min) || (int16_t)(value) > (int16_t)(max), "Value " #value " is within range [" #min ", " #max "]") + +#define ASSUME_ITS_WITHIN_RANGE_I32(value, min, max) \ + FOSSIL_TEST_ASSUME((int32_t)(value) >= (int32_t)(min) && (int32_t)(value) <= (int32_t)(max), "Value " #value " is not within range [" #min ", " #max "]") + +#define ASSUME_NOT_WITHIN_RANGE_I32(value, min, max) \ + FOSSIL_TEST_ASSUME((int32_t)(value) < (int32_t)(min) || (int32_t)(value) > (int32_t)(max), "Value " #value " is within range [" #min ", " #max "]") + +#define ASSUME_ITS_WITHIN_RANGE_I64(value, min, max) \ + FOSSIL_TEST_ASSUME((int64_t)(value) >= (int64_t)(min) && (int64_t)(value) <= (int64_t)(max), "Value " #value " is not within range [" #min ", " #max "]") + +#define ASSUME_NOT_WITHIN_RANGE_I64(value, min, max) \ + FOSSIL_TEST_ASSUME((int64_t)(value) < (int64_t)(min) || (int64_t)(value) > (int64_t)(max), "Value " #value " is within range [" #min ", " #max "]") + +// Floating point type ASSUMEions + +#define ASSUME_ITS_WITHIN_RANGE_F32(value, min, max) \ + FOSSIL_TEST_ASSUME((value) >= (min) && (value) <= (max), "Value " #value " is not within range [" #min ", " #max "]") + +#define ASSUME_NOT_WITHIN_RANGE_F32(value, min, max) \ + FOSSIL_TEST_ASSUME((value) < (min) || (value) > (max), "Value " #value " is within range [" #min ", " #max "]") + +#define ASSUME_ITS_WITHIN_RANGE_F64(value, min, max) \ + FOSSIL_TEST_ASSUME((value) >= (min) && (value) <= (max), "Value " #value " is not within range [" #min ", " #max "]") + +#define ASSUME_NOT_WITHIN_RANGE_F64(value, min, max) \ + FOSSIL_TEST_ASSUME((value) < (min) || (value) > (max), "Value " #value " is within range [" #min ", " #max "]") + +// Byte char type ASSUMEions (uint8_t) + +#define ASSUME_ITS_WITHIN_RANGE_BCHAR(value, min, max) \ + FOSSIL_TEST_ASSUME((uint8_t)(value) >= (uint8_t)(min) && (uint8_t)(value) <= (uint8_t)(max), "Value " #value " is not within range [" #min ", " #max "]") + +#define ASSUME_NOT_WITHIN_RANGE_BCHAR(value, min, max) \ + FOSSIL_TEST_ASSUME((uint8_t)(value) < (uint8_t)(min) || (uint8_t)(value) > (uint8_t)(max), "Value " #value " is within range [" #min ", " #max "]") + +// Char type ASSUMEions (char) + +#define ASSUME_ITS_WITHIN_RANGE_CCHAR(value, min, max) \ + FOSSIL_TEST_ASSUME((char)(value) >= (char)(min) && (char)(value) <= (char)(max), "Value " #value " is not within range [" #min ", " #max "]") + +#define ASSUME_NOT_WITHIN_RANGE_CCHAR(value, min, max) \ + FOSSIL_TEST_ASSUME((char)(value) < (char)(min) || (char)(value) > (char)(max), "Value " #value " is within range [" #min ", " #max "]") + +// Wide char type ASSUMEions (wchar_t) + +#define ASSUME_ITS_WITHIN_RANGE_WCHAR(value, min, max) \ + FOSSIL_TEST_ASSUME((wchar_t)(value) >= (wchar_t)(min) && (wchar_t)(value) <= (wchar_t)(max), "Value " #value " is not within range [" #min ", " #max "]") + +#define ASSUME_NOT_WITHIN_RANGE_WCHAR(value, min, max) \ + FOSSIL_TEST_ASSUME((wchar_t)(value) < (wchar_t)(min) || (wchar_t)(value) > (wchar_t)(max), "Value " #value " is within range [" #min ", " #max "]") + +// ************************************************** +// +// String ASSUMEions +// +// ************************************************** + +// Wide char string equality check +#define ASSUME_ITS_EQUAL_WSTR(actual, expected) \ + FOSSIL_TEST_ASSUME(wcscmp((actual), (expected)) == 0, "Expected wide string " #actual " to be equal to " #expected) + +#define ASSUME_NOT_EQUAL_WSTR(actual, expected) \ + FOSSIL_TEST_ASSUME(wcscmp((actual), (expected)) != 0, "Expected wide string " #actual " to not be equal to " #expected) + +// For length comparison +#define ASSUME_ITS_LENGTH_EQUAL_WSTR(actual, expected_len) \ + FOSSIL_TEST_ASSUME(wcslen((actual)) == (expected_len), "Expected length of wide string " #actual " to be equal to " #expected_len) + +// Byte string equality check +#define ASSUME_ITS_EQUAL_BSTR(actual, expected) \ + FOSSIL_TEST_ASSUME(strcmp((const char*)(actual), (const char*)(expected)) == 0, "Expected byte string " #actual " to be equal to " #expected) + +#define ASSUME_NOT_EQUAL_BSTR(actual, expected) \ + FOSSIL_TEST_ASSUME(strcmp((const char*)(actual), (const char*)(expected)) != 0, "Expected byte string " #actual " to not be equal to " #expected) + +// For length comparison +#define ASSUME_ITS_LENGTH_EQUAL_BSTR(actual, expected_len) \ + FOSSIL_TEST_ASSUME(strlen((const char*)(actual)) == (expected_len), "Expected length of byte string " #actual " to be equal to " #expected_len) + +// Classic C string equality check +#define ASSUME_ITS_EQUAL_CSTR(actual, expected) \ + FOSSIL_TEST_ASSUME(strcmp((actual), (expected)) == 0, "Expected C string " #actual " to be equal to " #expected) + +#define ASSUME_NOT_EQUAL_CSTR(actual, expected) \ + FOSSIL_TEST_ASSUME(strcmp((actual), (expected)) != 0, "Expected C string " #actual " to not be equal to " #expected) + +// For length comparison +#define ASSUME_ITS_LENGTH_EQUAL_CSTR(actual, expected_len) \ + FOSSIL_TEST_ASSUME(strlen((actual)) == (expected_len), "Expected length of C string " #actual " to be equal to " #expected_len) + +// ************************************************** +// +// Array ASSUMEions +// +// ************************************************** + +// Array equality check +#define ASSUME_ITS_EQUAL_ARRAY(actual, expected, length) \ + for (size_t i = 0; i < (length); i++) { \ + FOSSIL_TEST_ASSUME((actual)[i] == (expected)[i], "Expected array element " #actual " to be equal to " #expected); \ + } + +// Array inequality check +#define ASSUME_NOT_EQUAL_ARRAY(actual, expected, length) \ + for (size_t i = 0; i < (length); i++) { \ + FOSSIL_TEST_ASSUME((actual)[i] != (expected)[i], "Expected array element " #actual " to not be equal to " #expected); \ + } + +// Array length check +#define ASSUME_ITS_LENGTH_EQUAL_ARRAY(actual_length, expected_length) \ + FOSSIL_TEST_ASSUME((actual_length) == (expected_length), "Expected array length " #actual_length " to be equal to " #expected_length) + +// Array element within range check +#define ASSUME_ITS_WITHIN_RANGE_ARRAY(array, min, max, length) \ + for (size_t i = 0; i < (length); i++) { \ + FOSSIL_TEST_ASSUME((array)[i] >= (min) && (array)[i] <= (max), "Expected array element " #array " to be within range [" #min ", " #max "]"); \ + } + +// Array element not within range check +#define ASSUME_NOT_WITHIN_RANGE_ARRAY(array, min, max, length) \ + for (size_t i = 0; i < (length); i++) { \ + FOSSIL_TEST_ASSUME((array)[i] < (min) || (array)[i] > (max), "Expected array element " #array " to not be within range [" #min ", " #max "]"); \ + } + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/logic/fossil/benchmark/benchmark.h b/code/logic/fossil/test/benchmark.h similarity index 99% rename from code/logic/fossil/benchmark/benchmark.h rename to code/logic/fossil/test/benchmark.h index 91071e3f..27b712c9 100644 --- a/code/logic/fossil/benchmark/benchmark.h +++ b/code/logic/fossil/test/benchmark.h @@ -15,8 +15,6 @@ #ifndef FOSSIL_MARK_BENCHMARK_H #define FOSSIL_MARK_BENCHMARK_H -#include "fossil/_common/common.h" - #include #include #include diff --git a/code/logic/fossil/benchmark/framework.h b/code/logic/fossil/test/framework.h similarity index 50% rename from code/logic/fossil/benchmark/framework.h rename to code/logic/fossil/test/framework.h index fc3975a6..762af821 100644 --- a/code/logic/fossil/benchmark/framework.h +++ b/code/logic/fossil/test/framework.h @@ -1,25 +1,246 @@ /* * ----------------------------------------------------------------------------- - * File: framework.hpp * Project: Fossil Logic - * Description: This file implments the framework for benchmarking. - * + * * This file is part of the Fossil Logic project, which aims to develop high- * performance, cross-platform applications and libraries. The code contained * herein is subject to the terms and conditions defined in the project license. - * + * * Author: Michael Gene Brockus (Dreamer) * Date: 07/01/2024 - * + * * Copyright (C) 2024 Fossil Logic. All rights reserved. * ----------------------------------------------------------------------------- */ -#ifndef FOSSIL_MARK_FRAMEWORK_HPP -#define FOSSIL_MARK_FRAMEWORK_HPP +#ifndef FOSSIL_TEST_FRAMEWORK_H +#define FOSSIL_TEST_FRAMEWORK_H + +#ifdef __cplusplus +extern "C" { +#endif #include "benchmark.h" +#include "unittest.h" +#include "mockup.h" +#include "assume.h" + +/** + * Macro to define a given step in a test case. + * This macro is used to define a given step in a test case. The given step + * should contain the setup logic required to prepare the environment for the + * test case. + */ +#define GIVEN(description) _GIVEN(description) + +/** + * Macro to define a when step in a test case. + * This macro is used to define a when step in a test case. The when step should + * contain the logic to execute the functionality that is being tested. + */ +#define WHEN(description) _WHEN(description) + +/** + * Macro to define a then step in a test case. + * This macro is used to define a then step in a test case. The then step should + * contain the logic to verify the correctness of the functionality that was + * tested. + */ +#define THEN(description) _THEN(description) + +/** + * Macro to define the main test runner. + * This macro is used to define the main test runner function that will be + * executed when the test suite is run. The main test runner function will + * initialize the test framework, run all test cases, and output the test + * results. + */ +#define FOSSIL_TEST_MAIN() \ + _FOSSIL_TEST_MAIN() + +/** + * Macro to start the test runner. + * This macro is used to start the test runner, which will initialize the test + * framework and prepare to run all test cases in the test suite. + */ +#define FOSSIL_TEST_START() \ + _FOSSIL_TEST_START() + +/** + * Macro to run all test cases in the test suite. + * This macro is used to run all test cases in the test suite. The test cases + * will be executed in sequence, and the results will be output to the console. + */ +#define FOSSIL_TEST_RUN() \ + _FOSSIL_TEST_RUN() + +/** + * Macro to print a summary of the test results. + * This macro is used to print a summary of the test results after all test + * cases have been executed. The summary will include the number of test cases + * that passed, failed, and were skipped. + */ +#define FOSSIL_TEST_SUMMARY() \ + _FOSSIL_TEST_SUMMARY() + +/** + * Macro to end the test runner. + * This macro is used to end the test runner, which will clean up the test + * framework and return the appropriate exit code based on the test results. + */ +#define FOSSIL_TEST_END() \ + _FOSSIL_TEST_END() + +/** + * Macro to define a test case. + * This macro is used to declare a test case function that will be executed + * as part of the test suite. The test case function should contain the logic + * to verify the correctness of a specific functionality. + */ +#define FOSSIL_TEST_ADD(suite, test_case) \ + _FOSSIL_TEST_ADD(suite, test_case) + +/** + * Macro to define a test suite. + * This macro is used to declare a test suite, which is a collection of test + * cases that are related to each other. The test suite can be executed as a + * whole to verify the correctness of a group of functionalities. + */ +#define FOSSIL_TEST_SUITE(suite_name) \ + _FOSSIL_TEST_SUITE(suite_name) + +/** + * Macro to define a setup function for a test. + * This macro is used to declare a setup function that will be executed before + * each test case in a test suite. The setup function should contain the logic + * to initialize the environment or state required for the test cases. + */ +#define FOSSIL_SETUP(name) \ + _FOSSIL_TEST_SETUP(name) + +/** + * Macro to define a teardown function for a test. + * This macro is used to declare a teardown function that will be executed after + * each test case in a test suite. The teardown function should contain the logic + * to clean up the environment or state after the test cases have been executed. + */ +#define FOSSIL_TEARDOWN(name) \ + _FOSSIL_TEST_TEARDOWN(name) + +/** + * Macro to define test data. + * This macro is used to declare a structure that contains the data required + * for a test case. The test data structure can be used to pass input parameters + * to the test case and store the expected output values. + */ +#define FOSSIL_TEST_DATA(name) \ + _FOSSIL_TEST_DATA(name) + +/** + * Macro to define a test case. + * This macro is used to declare a test case function that will be executed + * as part of the test suite. The test case function should contain the logic + * to verify the correctness of a specific functionality. + */ +#define FOSSIL_TEST_CASE(name) \ + _FOSSIL_TEST_CASE(name) + +/** + * Macro to assume a condition in a test runner. + * This macro is used to assert that a specific condition is true within a test + * runner. If the condition is false, the test runner will output the specified + * message and may abort the execution of the test case or test suite. + */ +#define FOSSIL_TEST_ASSUME(condition, message) \ + _FOSSIL_TEST_ASSUME(condition, message) + +#define FOSSIL_TEST_ASSERT(condition, message) \ + _FOSSIL_TEST_ASSUME(condition, message) + + +// ***************************************************************************** +// Mocking framework +// ***************************************************************************** + +/** + * @brief Macro for initializing the mock list. + * + * This macro initializes the mock list by calling the fossil_mock_init function. + * + * @param list The mock list to initialize. + */ +#define MOCK_INIT(list) _MOCK_INIT(list) + +/** + * @brief Macro for destroying the mock list. + * + * This macro destroys the mock list by calling the fossil_mock_destroy function. + * + * @param list The mock list to destroy. + */ +#define MOCK_DESTROY(list) _MOCK_DESTROY(list) + +/** + * @brief Macro for adding a mock function call to the mock list. + * + * This macro adds a mock function call to the mock list by calling the fossil_mock_add_call function. + * + * @param list The mock list to add the call to. + * @param func The mock function to add the call for. + * @param args The arguments of the mock function call. + * @param num_args The number of arguments in the mock function call. + */ +#define MOCK_ADD_CALL(list, func, args, num_args) _MOCK_ADD_CALL(list, func, args, num_args) + +/** + * @brief Macro for printing the mock list. + * + * This macro prints the mock list by calling the fossil_mock_print function. + * + * @param list The mock list to print. + */ +#define MOCK_PRINT(list) _MOCK_PRINT(list) +/** + * @def FOSSIL_MOCK_FUNC + * @brief Macro for creating a mock function with the specified return type, name, and parameters. + * + * This macro simplifies the creation of mock functions by defining a function with the given return + * type, name, and parameters. The function name will be prefixed with "fossil_mockup_" to clearly indicate + * that it is a mock function. + * + * @param return_type The return type of the mock function. + * @param name The name of the mock function. + * @param ... The parameters of the mock function in the format: (type1 param1, type2 param2, ...). + * @return The return type specified for the mock function. + */ +#define FOSSIL_MOCK_FUNC(return_type, name, ...) _FOSSIL_MOCK_FUNC(return_type, name, __VA_ARGS__) + +/** + * @def FOSSIL_MOCK_ALIAS + * @brief Macro for creating a type alias based on an existing type. + * + * This macro creates a type alias for a given existing type. + * + * @param new_type The name of the new type alias. + * @param existing_type The existing type to create an alias for. + */ +#define FOSSIL_MOCK_ALIAS(new_type, existing_type) _FOSSIL_MOCK_ALIAS(new_type, existing_type) + +/** + * @def FOSSIL_MOCK_STRUCT + * @brief Macro for creating a mock struct with the specified name and members. + * + * This macro simplifies the creation of mock structs by defining a struct with the given name + * and members. The struct name will be prefixed with "fossil_mockup_" to clearly indicate that it is a mock struct. + * + * @param name The name of the mock struct. + * @param ... The members of the mock struct in the format: (type1 member1, type2 member2, ...). + */ +#define FOSSIL_MOCK_STRUCT(name, ...) _FOSSIL_MOCK_STRUCT(name, __VA_ARGS__) + +// ***************************************************************************** +// Benchmark framework +// ***************************************************************************** -// Macros for benchmarking /** * @brief Define macro for marking a benchmark. * @@ -231,4 +452,8 @@ */ #define TEST_DURATION_YOC(elapsed, actual) TEST_DURATION((char*)"yoctoseconds", elapsed, actual) -#endif // FOSSIL_MARK_FRAMEWORK_HPP +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/logic/fossil/mockup/mockup.h b/code/logic/fossil/test/mockup.h similarity index 99% rename from code/logic/fossil/mockup/mockup.h rename to code/logic/fossil/test/mockup.h index 76b47f36..fa3d9c2c 100644 --- a/code/logic/fossil/mockup/mockup.h +++ b/code/logic/fossil/test/mockup.h @@ -20,7 +20,6 @@ #include #include #include -#include "fossil/_common/common.h" /** * @brief Macro for initializing the mock list. diff --git a/code/logic/fossil/test/unittest.h b/code/logic/fossil/test/unittest.h new file mode 100644 index 00000000..250a65cd --- /dev/null +++ b/code/logic/fossil/test/unittest.h @@ -0,0 +1,261 @@ +/* + * ----------------------------------------------------------------------------- + * Project: Fossil Logic + * + * This file is part of the Fossil Logic project, which aims to develop high- + * performance, cross-platform applications and libraries. The code contained + * herein is subject to the terms and conditions defined in the project license. + * + * Author: Michael Gene Brockus (Dreamer) + * Date: 07/01/2024 + * + * Copyright (C) 2024 Fossil Logic. All rights reserved. + * ----------------------------------------------------------------------------- + */ +#ifndef FOSSIL_TEST_CORE_H +#define FOSSIL_TEST_CORE_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// Test status enumeration +typedef enum { + test_status_pass, + test_status_fail, + test_status_skip, + test_status_unexpected +} test_status_t; + +// Stack frame structure for stack traces +typedef struct stack_frame { + const char *func; + const char *file; + int line; + struct stack_frame *next; +} stack_frame_t; + +// Test case structure +typedef struct test_case { + const char *name; + void (*test_func)(void); + void (*setup_func)(void); + void (*teardown_func)(void); + const char *tags; + test_status_t status; + const char *failure_message; + double execution_time; + stack_frame_t *stack_trace; + struct test_case *next; + struct test_case *prev; +} test_case_t; + +// Double-ended priority queue structure for test cases +typedef struct double_ended_priority_queue { + test_case_t *front; + test_case_t *back; +} double_ended_priority_queue_t; + +// Test suite structure with setup and teardown hooks +typedef struct test_suite { + const char *name; + double_ended_priority_queue_t *tests; + double total_execution_time; + void (*suite_setup_func)(void); + void (*suite_teardown_func)(void); + struct test_suite *next; // Pointer to next suite in the global list +} test_suite_t; + +// Global variables for test results +extern int pass_count; +extern int fail_count; +extern int skip_count; +extern int unexpected_count; +extern jmp_buf env; + +// List to store all test suites +extern test_suite_t *global_test_suites; + +// ***************************************************************************** +// Function declarations +// ***************************************************************************** + +/** + * Initialize the test framework. + */ +void fossil_test_init(void); + +/** + * Clean up the test framework. + */ +void fossil_test_cleanup(void); + +/** + * Print a summary of the test results. + */ +void fossil_test_summary(void); + +/** + * Add a test case to the double-ended priority queue. + * + * @param queue The double-ended priority queue. + * @param test The test case to add. + */ +void fossil_test_add_case(double_ended_priority_queue_t *queue, test_case_t *test); + +/** + * Remove the front test case from the double-ended priority queue. + * + * @param queue The double-ended priority queue. + */ +void fossil_test_remove_front(double_ended_priority_queue_t *queue); + +/** + * Remove the back test case from the double-ended priority queue. + * + * @param queue The double-ended priority queue. + */ +void fossil_test_remove_back(double_ended_priority_queue_t *queue); + +/** + * Run all test cases in a test suite. + * + * @param suite The test suite to run. + */ +void fossil_test_run_suite(test_suite_t *suite); + +/** + * Assert a condition in a test case. + * + * @param condition The condition to assert. + * @param message The failure message if the condition is false. + * @param file The file where the assertion failed. + * @param line The line number where the assertion failed. + * @param func The function where the assertion failed. + */ +void fossil_test_assume(bool condition, const char *message, const char *file, int line, const char *func); + +/** + * Register a test suite with the test framework. + * + * @param suite The test suite to register. + */ +void fossil_test_register_suite(test_suite_t *suite); + +// ***************************************************************************** +// Macro definitions +// ***************************************************************************** + +#define _FOSSIL_TEST_ASSUME(condition, message) fossil_test_assume(condition, message, __FILE__, __LINE__, __func__) + +// Macro for defining a test case +#define _FOSSIL_TEST_CASE(test_name) \ + void test_name##_test_func(void); \ + test_case_t test_name##_test_case = { \ + .name = #test_name, \ + .test_func = test_name##_test_func, \ + .setup_func = NULL, \ + .teardown_func = NULL, \ + .tags = NULL, \ + .status = test_status_pass, \ + .failure_message = NULL, \ + .execution_time = 0.0, \ + .stack_trace = NULL, \ + .next = NULL, \ + .prev = NULL \ + }; \ + void test_name##_test_func(void) + +#define _FOSSIL_TEST_DATA(name) \ + typedef struct name + +// Macro for setting up a test case +#define _FOSSIL_TEST_SETUP(name) \ + void name##_setup_func(void) + +// Macro for tearing down a test case +#define _FOSSIL_TEST_TEARDOWN(name) \ + void name##_teardown_func(void) + +// Macro to create a test suite with setup and teardown hooks +#define _FOSSIL_TEST_SUITE(suite_name) \ + test_suite_t suite_name = { \ + .name = #suite_name, \ + .tests = NULL, \ + .total_execution_time = 0.0, \ + .suite_setup_func = suite_name##_setup_func, \ + .suite_teardown_func = suite_name##_teardown_func, \ + .next = NULL \ + } + +// Macro to add a test case to a suite +#define _FOSSIL_TEST_ADD(suite, test_case) \ + fossil_test_add_case((suite).tests, &(test_case)); + +// main runner managment + +#define _FOSSIL_TEST_MAIN() \ + int main(void) { \ + FOSSIL_TEST_START(); \ + FOSSIL_TEST_RUN(); \ + FOSSIL_TEST_SUMMARY(); \ + FOSSIL_TEST_END(); \ + } // end of macro + +#define _FOSSIL_TEST_START() \ + fossil_test_init() + +#define _FOSSIL_TEST_RUN() \ + { \ + test_suite_t *suites = global_test_suites; \ + while (suites != NULL) { \ + fossil_test_run_suite(suite); \ + suites = suites->next; \ + } \ + } + +#define _FOSSIL_TEST_SUMMARY() \ + fossil_test_summary() + +#define _FOSSIL_TEST_END() \ + fossil_test_cleanup(); \ + return fail_count > 0 ? EXIT_FAILURE : EXIT_SUCCESS + +#define _GIVEN(description) \ + if (1) { \ + printf("Given %s\n", description); \ + } + +#define _WHEN(description) \ + if (1) { \ + printf("When %s\n", description); \ + } + +#define _THEN(description) \ + if (1) { \ + printf("Then %s\n", description); \ + } + +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus +#include +#include + +namespace fossil { + +} +#endif + +#endif diff --git a/code/logic/fossil/unittest/assume.h b/code/logic/fossil/unittest/assume.h deleted file mode 100644 index 92a3a94d..00000000 --- a/code/logic/fossil/unittest/assume.h +++ /dev/null @@ -1,868 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#ifndef FOSSIL_TEST_ASSUME_TYPE_H -#define FOSSIL_TEST_ASSUME_TYPE_H - -#include // using assurt rules from Fossil Test - -#include -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// ************************************************** -// -// Boolean ASSUMEions -// -// ************************************************** - -// Boolean ITS ASSUMEions -#define ASSUME_ITS_TRUE(actual) \ - TEST_ASSUME((actual), "Expected " #actual " to be true") - -#define ASSUME_ITS_FALSE(actual) \ - TEST_ASSUME(!(actual), "Expected " #actual " to be false") - -// Boolean NOT ASSUMEions -#define ASSUME_NOT_TRUE(actual) \ - TEST_ASSUME(!(actual), "Expected " #actual " to not be true") - -#define ASSUME_NOT_FALSE(actual) \ - TEST_ASSUME((actual), "Expected " #actual " to not be false") - -// ************************************************** -// -// Floating point ASSUMEions -// -// ************************************************** - -// Double equality check with tolerance -#define ASSUME_ITS_EQUAL_F64(actual, expected, tol) \ - TEST_ASSUME(fabs((actual) - (expected)) <= (tol), "Expected " #actual " to be equal to " #expected " within tolerance " #tol) - -#define ASSUME_ITS_LESS_THAN_F64(actual, expected) \ - TEST_ASSUME((actual) < (expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_F64(actual, expected) \ - TEST_ASSUME((actual) > (expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_F64(actual, expected) \ - TEST_ASSUME((actual) <= (expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_F64(actual, expected) \ - TEST_ASSUME((actual) >= (expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_F64(actual, expected, tol) \ - TEST_ASSUME(fabs((actual) - (expected)) > (tol), "Expected " #actual " to not be equal to " #expected " within tolerance " #tol) - -#define ASSUME_NOT_LESS_THAN_F64(actual, expected) \ - TEST_ASSUME((actual) >= (expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_F64(actual, expected) \ - TEST_ASSUME((actual) <= (expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_F64(actual, expected) \ - TEST_ASSUME((actual) > (expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_F64(actual, expected) \ - TEST_ASSUME((actual) < (expected), "Expected " #actual " to not be more than or equal to " #expected) - -// Float equality check with tolerance -#define ASSUME_ITS_EQUAL_F32(actual, expected, tol) \ - TEST_ASSUME(fabsf((actual) - (expected)) <= (tol), "Expected " #actual " to be equal to " #expected " within tolerance " #tol) - -#define ASSUME_ITS_LESS_THAN_F32(actual, expected) \ - TEST_ASSUME((actual) < (expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_F32(actual, expected) \ - TEST_ASSUME((actual) > (expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_F32(actual, expected) \ - TEST_ASSUME((actual) <= (expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_F32(actual, expected) \ - TEST_ASSUME((actual) >= (expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_F32(actual, expected, tol) \ - TEST_ASSUME(fabsf((actual) - (expected)) > (tol), "Expected " #actual " to not be equal to " #expected " within tolerance " #tol) - -#define ASSUME_NOT_LESS_THAN_F32(actual, expected) \ - TEST_ASSUME((actual) >= (expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_F32(actual, expected) \ - TEST_ASSUME((actual) <= (expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_F32(actual, expected) \ - TEST_ASSUME((actual) > (expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_F32(actual, expected) \ - TEST_ASSUME((actual) < (expected), "Expected " #actual " to not be more than or equal to " #expected) - -// Float NaN and Infinity checks -#define ASSUME_ITS_NAN_F32(actual) \ - TEST_ASSUME(isnan(actual), "Expected " #actual " to be NaN") - -#define ASSUME_ITS_INF_F32(actual) \ - TEST_ASSUME(isinf(actual), "Expected " #actual " to be infinity") - -// Double NaN and Infinity checks -#define ASSUME_ITS_NAN_F64(actual) \ - TEST_ASSUME(isnan(actual), "Expected " #actual " to be NaN") - -#define ASSUME_ITS_INF_F64(actual) \ - TEST_ASSUME(isinf(actual), "Expected " #actual " to be infinity") - -// ************************************************** -// -// Numaric ASSUMEions -// -// ************************************************** - -// Octal ASSUMEions - -// O8 ASSUMEions -#define ASSUME_ITS_EQUAL_O8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) == (uint8_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_O8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_O8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_O8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_O8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_O8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) != (uint8_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_O8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_O8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_O8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_O8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// O16 ASSUMEions -#define ASSUME_ITS_EQUAL_O16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) == (uint16_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_O16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_O16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_O16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_O16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_O16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) != (uint16_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_O16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_O16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_O16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_O16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// O32 ASSUMEions -#define ASSUME_ITS_EQUAL_O32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) == (uint32_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_O32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_O32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_O32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_O32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_O32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) != (uint32_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_O32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_O32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_O32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_O32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// OI64 ASSUMEions -#define ASSUME_ITS_EQUAL_O64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) == (uint64_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_O64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_O64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_O64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_O64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_O64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) != (uint64_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_O64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_O64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_O64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_O64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// Hexadecimal ASSUMEions - -// H8 ASSUMEions -#define ASSUME_ITS_EQUAL_H8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) == (uint8_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_H8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_H8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_H8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_H8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_H8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) != (uint8_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_H8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_H8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_H8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_H8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// H16 ASSUMEions -#define ASSUME_ITS_EQUAL_H16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) == (uint16_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_H16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_H16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_H16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_H16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_H16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) != (uint16_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_H16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_H16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_H16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_H16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// H32 ASSUMEions -#define ASSUME_ITS_EQUAL_H32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) == (uint32_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_H32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_H32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_H32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_H32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_H32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) != (uint32_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_H32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_H32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_H32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_H32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// H64 ASSUMEions -#define ASSUME_ITS_EQUAL_H64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) == (uint64_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_H64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_H64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_H64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_H64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_H64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) != (uint64_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_H64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_H64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_H64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_H64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// I8 ASSUMEions -#define ASSUME_ITS_EQUAL_I8(actual, expected) \ - TEST_ASSUME((int8_t)(actual) == (int8_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_I8(actual, expected) \ - TEST_ASSUME((int8_t)(actual) < (int8_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_I8(actual, expected) \ - TEST_ASSUME((int8_t)(actual) > (int8_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_I8(actual, expected) \ - TEST_ASSUME((int8_t)(actual) <= (int8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_I8(actual, expected) \ - TEST_ASSUME((int8_t)(actual) >= (int8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_I8(actual, expected) \ - TEST_ASSUME((int8_t)(actual) != (int8_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_I8(actual, expected) \ - TEST_ASSUME((int8_t)(actual) >= (int8_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_I8(actual, expected) \ - TEST_ASSUME((int8_t)(actual) <= (int8_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_I8(actual, expected) \ - TEST_ASSUME((int8_t)(actual) > (int8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_I8(actual, expected) \ - TEST_ASSUME((int8_t)(actual) < (int8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// I16 ASSUMEions -#define ASSUME_ITS_EQUAL_I16(actual, expected) \ - TEST_ASSUME((int16_t)(actual) == (int16_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_I16(actual, expected) \ - TEST_ASSUME((int16_t)(actual) < (int16_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_I16(actual, expected) \ - TEST_ASSUME((int16_t)(actual) > (int16_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_I16(actual, expected) \ - TEST_ASSUME((int16_t)(actual) <= (int16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_I16(actual, expected) \ - TEST_ASSUME((int16_t)(actual) >= (int16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_I16(actual, expected) \ - TEST_ASSUME((int16_t)(actual) != (int16_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_I16(actual, expected) \ - TEST_ASSUME((int16_t)(actual) >= (int16_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_I16(actual, expected) \ - TEST_ASSUME((int16_t)(actual) <= (int16_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_I16(actual, expected) \ - TEST_ASSUME((int16_t)(actual) > (int16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_I16(actual, expected) \ - TEST_ASSUME((int16_t)(actual) < (int16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// I32 ASSUMEions -#define ASSUME_ITS_EQUAL_I32(actual, expected) \ - TEST_ASSUME((int32_t)(actual) == (int32_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_I32(actual, expected) \ - TEST_ASSUME((int32_t)(actual) < (int32_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_I32(actual, expected) \ - TEST_ASSUME((int32_t)(actual) > (int32_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_I32(actual, expected) \ - TEST_ASSUME((int32_t)(actual) <= (int32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_I32(actual, expected) \ - TEST_ASSUME((int32_t)(actual) >= (int32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_I32(actual, expected) \ - TEST_ASSUME((int32_t)(actual) != (int32_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_I32(actual, expected) \ - TEST_ASSUME((int32_t)(actual) >= (int32_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_I32(actual, expected) \ - TEST_ASSUME((int32_t)(actual) <= (int32_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_I32(actual, expected) \ - TEST_ASSUME((int32_t)(actual) > (int32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_I32(actual, expected) \ - TEST_ASSUME((int32_t)(actual) < (int32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// I64 ASSUMEions -#define ASSUME_ITS_EQUAL_I64(actual, expected) \ - TEST_ASSUME((int64_t)(actual) == (int64_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_I64(actual, expected) \ - TEST_ASSUME((int64_t)(actual) < (int64_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_I64(actual, expected) \ - TEST_ASSUME((int64_t)(actual) > (int64_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_I64(actual, expected) \ - TEST_ASSUME((int64_t)(actual) <= (int64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_I64(actual, expected) \ - TEST_ASSUME((int64_t)(actual) >= (int64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_I64(actual, expected) \ - TEST_ASSUME((int64_t)(actual) != (int64_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_I64(actual, expected) \ - TEST_ASSUME((int64_t)(actual) >= (int64_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_I64(actual, expected) \ - TEST_ASSUME((int64_t)(actual) <= (int64_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_I64(actual, expected) \ - TEST_ASSUME((int64_t)(actual) > (int64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_I64(actual, expected) \ - TEST_ASSUME((int64_t)(actual) < (int64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// U8 ASSUMEions -#define ASSUME_ITS_EQUAL_U8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) == (uint8_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_U8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_U8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_U8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_U8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_U8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) != (uint8_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_U8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_U8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_U8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_U8(actual, expected) \ - TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// U16 ASSUMEions -#define ASSUME_ITS_EQUAL_U16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) == (uint16_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_U16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_U16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_U16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_U16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_U16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) != (uint16_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_U16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_U16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_U16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_U16(actual, expected) \ - TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// U32 ASSUMEions -#define ASSUME_ITS_EQUAL_U32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) == (uint32_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_U32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_U32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_U32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_U32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_U32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) != (uint32_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_U32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_U32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_U32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_U32(actual, expected) \ - TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// U64 ASSUMEions -#define ASSUME_ITS_EQUAL_U64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) == (uint64_t)(expected), "Expected " #actual " to be equal to " #expected) - -#define ASSUME_ITS_LESS_THAN_U64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to be less than " #expected) - -#define ASSUME_ITS_MORE_THAN_U64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to be more than " #expected) - -#define ASSUME_ITS_LESS_OR_EQUAL_U64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -#define ASSUME_ITS_MORE_OR_EQUAL_U64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -#define ASSUME_NOT_EQUAL_U64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) != (uint64_t)(expected), "Expected " #actual " to not be equal to " #expected) - -#define ASSUME_NOT_LESS_THAN_U64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to not be less than " #expected) - -#define ASSUME_NOT_MORE_THAN_U64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to not be more than " #expected) - -#define ASSUME_NOT_LESS_OR_EQUAL_U64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) - -#define ASSUME_NOT_MORE_OR_EQUAL_U64(actual, expected) \ - TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) - -// ************************************************** -// -// Null pointer ASSUMEions (_CNULL) -// -// ************************************************** - -// ITS set -#define ASSUME_ITS_CNULL(actual) \ - TEST_ASSUME((actual) == xnull, "Expected " #actual " to be xnull") - -#define ASSUME_NOT_CNULL(actual) \ - TEST_ASSUME((actual) != xnull, "Expected " #actual " to not be xnull") - -// General pointer ASSUMEions (_PTR) - -// ITS set -#define ASSUME_ITS_EQUAL_PTR(actual, expected) \ - TEST_ASSUME((actual) == (expected), "Expected pointer " #actual " to be equal to pointer " #expected " ") - -#define ASSUME_NOT_EQUAL_PTR(actual, expected) \ - TEST_ASSUME((actual) != (expected), "Expected pointer " #actual " to not be equal to pointer " #expected " ") - -// Size_t ASSUMEions - -// Equal -#define ASSUME_ITS_EQUAL_SIZE(actual, expected) \ - TEST_ASSUME((size_t)(actual) == (size_t)(expected), "Expected " #actual " to be equal to " #expected) - -// Less than -#define ASSUME_ITS_LESS_THAN_SIZE(actual, expected) \ - TEST_ASSUME((size_t)(actual) < (size_t)(expected), "Expected " #actual " to be less than " #expected) - -// More than -#define ASSUME_ITS_MORE_THAN_SIZE(actual, expected) \ - TEST_ASSUME((size_t)(actual) > (size_t)(expected), "Expected " #actual " to be more than " #expected) - -// Less or equal -#define ASSUME_ITS_LESS_OR_EQUAL_SIZE(actual, expected) \ - TEST_ASSUME((size_t)(actual) <= (size_t)(expected), "Expected " #actual " to be less than or equal to " #expected) - -// More or equal -#define ASSUME_ITS_MORE_OR_EQUAL_SIZE(actual, expected) \ - TEST_ASSUME((size_t)(actual) >= (size_t)(expected), "Expected " #actual " to be more than or equal to " #expected) - -// Not equal -#define ASSUME_NOT_EQUAL_SIZE(actual, expected) \ - TEST_ASSUME((size_t)(actual) != (size_t)(expected), "Expected " #actual " to not be equal to " #expected) - -// ************************************************** -// -// Range ASSUMEions -// -// ************************************************** - -// ASSUMEion for checking if a value is within a specified range -#define ASSUME_ITS_WITHIN_RANGE(value, min, max) \ - TEST_ASSUME((value) >= (min) && (value) <= (max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSUME_NOT_WITHIN_RANGE(value, min, max) \ - TEST_ASSUME((value) < (min) || (value) > (max), "Value " #value " is within range [" #min ", " #max "]") - -// Unsigned integer type ASSUMEions - -#define ASSUME_ITS_WITHIN_RANGE_U8(value, min, max) \ - TEST_ASSUME((uint8_t)(value) >= (uint8_t)(min) && (uint8_t)(value) <= (uint8_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSUME_NOT_WITHIN_RANGE_U8(value, min, max) \ - TEST_ASSUME((uint8_t)(value) < (uint8_t)(min) || (uint8_t)(value) > (uint8_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define ASSUME_ITS_WITHIN_RANGE_U16(value, min, max) \ - TEST_ASSUME((uint16_t)(value) >= (uint16_t)(min) && (uint16_t)(value) <= (uint16_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSUME_NOT_WITHIN_RANGE_U16(value, min, max) \ - TEST_ASSUME((uint16_t)(value) < (uint16_t)(min) || (uint16_t)(value) > (uint16_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define ASSUME_ITS_WITHIN_RANGE_U32(value, min, max) \ - TEST_ASSUME((uint32_t)(value) >= (uint32_t)(min) && (uint32_t)(value) <= (uint32_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSUME_NOT_WITHIN_RANGE_U32(value, min, max) \ - TEST_ASSUME((uint32_t)(value) < (uint32_t)(min) || (uint32_t)(value) > (uint32_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define ASSUME_ITS_WITHIN_RANGE_U64(value, min, max) \ - TEST_ASSUME((uint64_t)(value) >= (uint64_t)(min) && (uint64_t)(value) <= (uint64_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSUME_NOT_WITHIN_RANGE_U64(value, min, max) \ - TEST_ASSUME((uint64_t)(value) < (uint64_t)(min) || (uint64_t)(value) > (uint64_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -// Signed integer type ASSUMEions - -#define ASSUME_ITS_WITHIN_RANGE_I8(value, min, max) \ - TEST_ASSUME((int8_t)(value) >= (int8_t)(min) && (int8_t)(value) <= (int8_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSUME_NOT_WITHIN_RANGE_I8(value, min, max) \ - TEST_ASSUME((int8_t)(value) < (int8_t)(min) || (int8_t)(value) > (int8_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define ASSUME_ITS_WITHIN_RANGE_I16(value, min, max) \ - TEST_ASSUME((int16_t)(value) >= (int16_t)(min) && (int16_t)(value) <= (int16_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSUME_NOT_WITHIN_RANGE_I16(value, min, max) \ - TEST_ASSUME((int16_t)(value) < (int16_t)(min) || (int16_t)(value) > (int16_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define ASSUME_ITS_WITHIN_RANGE_I32(value, min, max) \ - TEST_ASSUME((int32_t)(value) >= (int32_t)(min) && (int32_t)(value) <= (int32_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSUME_NOT_WITHIN_RANGE_I32(value, min, max) \ - TEST_ASSUME((int32_t)(value) < (int32_t)(min) || (int32_t)(value) > (int32_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -#define ASSUME_ITS_WITHIN_RANGE_I64(value, min, max) \ - TEST_ASSUME((int64_t)(value) >= (int64_t)(min) && (int64_t)(value) <= (int64_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSUME_NOT_WITHIN_RANGE_I64(value, min, max) \ - TEST_ASSUME((int64_t)(value) < (int64_t)(min) || (int64_t)(value) > (int64_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -// Floating point type ASSUMEions - -#define ASSUME_ITS_WITHIN_RANGE_F32(value, min, max) \ - TEST_ASSUME((value) >= (min) && (value) <= (max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSUME_NOT_WITHIN_RANGE_F32(value, min, max) \ - TEST_ASSUME((value) < (min) || (value) > (max), "Value " #value " is within range [" #min ", " #max "]") - -#define ASSUME_ITS_WITHIN_RANGE_F64(value, min, max) \ - TEST_ASSUME((value) >= (min) && (value) <= (max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSUME_NOT_WITHIN_RANGE_F64(value, min, max) \ - TEST_ASSUME((value) < (min) || (value) > (max), "Value " #value " is within range [" #min ", " #max "]") - -// Byte char type ASSUMEions (uint8_t) - -#define ASSUME_ITS_WITHIN_RANGE_BCHAR(value, min, max) \ - TEST_ASSUME((uint8_t)(value) >= (uint8_t)(min) && (uint8_t)(value) <= (uint8_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSUME_NOT_WITHIN_RANGE_BCHAR(value, min, max) \ - TEST_ASSUME((uint8_t)(value) < (uint8_t)(min) || (uint8_t)(value) > (uint8_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -// Char type ASSUMEions (char) - -#define ASSUME_ITS_WITHIN_RANGE_CCHAR(value, min, max) \ - TEST_ASSUME((char)(value) >= (char)(min) && (char)(value) <= (char)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSUME_NOT_WITHIN_RANGE_CCHAR(value, min, max) \ - TEST_ASSUME((char)(value) < (char)(min) || (char)(value) > (char)(max), "Value " #value " is within range [" #min ", " #max "]") - -// Wide char type ASSUMEions (wchar_t) - -#define ASSUME_ITS_WITHIN_RANGE_WCHAR(value, min, max) \ - TEST_ASSUME((wchar_t)(value) >= (wchar_t)(min) && (wchar_t)(value) <= (wchar_t)(max), "Value " #value " is not within range [" #min ", " #max "]") - -#define ASSUME_NOT_WITHIN_RANGE_WCHAR(value, min, max) \ - TEST_ASSUME((wchar_t)(value) < (wchar_t)(min) || (wchar_t)(value) > (wchar_t)(max), "Value " #value " is within range [" #min ", " #max "]") - -// ************************************************** -// -// String ASSUMEions -// -// ************************************************** - -// Wide char string equality check -#define ASSUME_ITS_EQUAL_WSTR(actual, expected) \ - TEST_ASSUME(wcscmp((actual), (expected)) == 0, "Expected wide string " #actual " to be equal to " #expected) - -#define ASSUME_NOT_EQUAL_WSTR(actual, expected) \ - TEST_ASSUME(wcscmp((actual), (expected)) != 0, "Expected wide string " #actual " to not be equal to " #expected) - -// For length comparison -#define ASSUME_ITS_LENGTH_EQUAL_WSTR(actual, expected_len) \ - TEST_ASSUME(wcslen((actual)) == (expected_len), "Expected length of wide string " #actual " to be equal to " #expected_len) - -// Byte string equality check -#define ASSUME_ITS_EQUAL_BSTR(actual, expected) \ - TEST_ASSUME(strcmp((const char*)(actual), (const char*)(expected)) == 0, "Expected byte string " #actual " to be equal to " #expected) - -#define ASSUME_NOT_EQUAL_BSTR(actual, expected) \ - TEST_ASSUME(strcmp((const char*)(actual), (const char*)(expected)) != 0, "Expected byte string " #actual " to not be equal to " #expected) - -// For length comparison -#define ASSUME_ITS_LENGTH_EQUAL_BSTR(actual, expected_len) \ - TEST_ASSUME(strlen((const char*)(actual)) == (expected_len), "Expected length of byte string " #actual " to be equal to " #expected_len) - -// Classic C string equality check -#define ASSUME_ITS_EQUAL_CSTR(actual, expected) \ - TEST_ASSUME(strcmp((actual), (expected)) == 0, "Expected C string " #actual " to be equal to " #expected) - -#define ASSUME_NOT_EQUAL_CSTR(actual, expected) \ - TEST_ASSUME(strcmp((actual), (expected)) != 0, "Expected C string " #actual " to not be equal to " #expected) - -// For length comparison -#define ASSUME_ITS_LENGTH_EQUAL_CSTR(actual, expected_len) \ - TEST_ASSUME(strlen((actual)) == (expected_len), "Expected length of C string " #actual " to be equal to " #expected_len) - -// ************************************************** -// -// Array ASSUMEions -// -// ************************************************** - -// Array equality check -#define ASSUME_ITS_EQUAL_ARRAY(actual, expected, length) \ - for (size_t i = 0; i < (length); i++) { \ - TEST_ASSUME((actual)[i] == (expected)[i], "Expected array element " #actual " to be equal to " #expected); \ - } - -// Array inequality check -#define ASSUME_NOT_EQUAL_ARRAY(actual, expected, length) \ - for (size_t i = 0; i < (length); i++) { \ - TEST_ASSUME((actual)[i] != (expected)[i], "Expected array element " #actual " to not be equal to " #expected); \ - } - -// Array length check -#define ASSUME_ITS_LENGTH_EQUAL_ARRAY(actual_length, expected_length) \ - TEST_ASSUME((actual_length) == (expected_length), "Expected array length " #actual_length " to be equal to " #expected_length) - -// Array element within range check -#define ASSUME_ITS_WITHIN_RANGE_ARRAY(array, min, max, length) \ - for (size_t i = 0; i < (length); i++) { \ - TEST_ASSUME((array)[i] >= (min) && (array)[i] <= (max), "Expected array element " #array " to be within range [" #min ", " #max "]"); \ - } - -// Array element not within range check -#define ASSUME_NOT_WITHIN_RANGE_ARRAY(array, min, max, length) \ - for (size_t i = 0; i < (length); i++) { \ - TEST_ASSUME((array)[i] < (min) || (array)[i] > (max), "Expected array element " #array " to not be within range [" #min ", " #max "]"); \ - } - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/code/logic/fossil/unittest/framework.h b/code/logic/fossil/unittest/framework.h deleted file mode 100644 index 4275d93d..00000000 --- a/code/logic/fossil/unittest/framework.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#ifndef FOSSIL_TEST_FRAMEWORK_H -#define FOSSIL_TEST_FRAMEWORK_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "unittest.h" - -/** - * Macro to define a test suite. - * This macro is used to declare a test suite, which is a collection of test - * cases that are related to each other. The test suite can be executed as a - * whole to verify the correctness of a group of functionalities. - */ -#define FOSSIL_TEST_SUITE(name) \ - _FOSSIL_TEST_SUITE(name) - -/** - * Macro to define a setup function for a test. - * This macro is used to declare a setup function that will be executed before - * each test case in a test suite. The setup function should contain the logic - * to initialize the environment or state required for the test cases. - */ -#define FOSSIL_SETUP(name) \ - _FOSSIL_TEST_SETUP(name) - -/** - * Macro to define a teardown function for a test. - * This macro is used to declare a teardown function that will be executed after - * each test case in a test suite. The teardown function should contain the logic - * to clean up the environment or state after the test cases have been executed. - */ -#define FOSSIL_TEARDOWN(name) \ - _FOSSIL_TEST_TEARDOWN(name) - -/** - * Macro to define a test group. - * This macro is used to declare a test group, which is a higher-level grouping - * of test suites. Test groups can be used to organize test suites into logical - * categories for easier management and execution. - */ -#define FOSSIL_TEST_GROUP(name) \ - _FOSSIL_TEST_GROUP(name) - -/** - * Macro to import a test. - * This macro is used to import a test case or test suite from another module - * or file. It allows for the reuse of test cases and test suites across - * different parts of the project. - */ -#define FOSSIL_TEST_IMPORT(name) \ - _FOSSIL_TEST_IMPORT(name) - -/** - * Macro to export a test. - * This macro is used to export a test case or test suite so that it can be - * imported and used in other modules or files. It facilitates the sharing of - * test cases and test suites across the project. - */ -#define FOSSIL_TEST_EXPORT(name) \ - _FOSSIL_TEST_EXPORT(name) - -/** - * Macro to define a test case. - * This macro is used to declare a test case function that will be executed - * as part of the test suite. The test case function should contain the logic - * to verify the correctness of a specific functionality. - */ -#define FOSSIL_TEST(name) \ - _FOSSIL_TEST_CASE(name) - -/** - * Macro to add a test function to a test queue. - * This macro is used to add a test function to a test queue, which is a - * collection of test functions that will be executed in sequence. The test - * queue allows for the orderly execution of multiple test functions. - */ -#define FOSSIL_TEST_ADD(queue, test_func) \ - _FOSSIL_TEST_ADD(queue, test_func) - -/** - * Macro to add a test function to a test queue with a suite. - * This macro is used to add a test function to a test queue, specifying the - * test suite to which the test function belongs. It allows for the organization - * of test functions within their respective test suites. - */ -#define FOSSIL_TEST_ADDF(queue, test_func, suite) \ - _FOSSIL_TEST_ADDF(queue, test_func, suite) - -/** - * Macro to assume a condition in a test runner. - * This macro is used to assert that a specific condition is true within a test - * runner. If the condition is false, the test runner will output the specified - * message and may abort the execution of the test case or test suite. - */ -#define FOSSIL_TEST_ASSUME(runner, condition, message) \ - _FOSSIL_TEST_ASSUME(runner, condition, message) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/code/logic/fossil/unittest/unittest.h b/code/logic/fossil/unittest/unittest.h deleted file mode 100644 index 98e9bdac..00000000 --- a/code/logic/fossil/unittest/unittest.h +++ /dev/null @@ -1,292 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#ifndef FOSSIL_TEST_CORE_H -#define FOSSIL_TEST_CORE_H - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// ***************************************************************************** -// Constants -// ***************************************************************************** - -// ANSI color codes for output -#define FOSSIL_TEST_COLOR_RESET "\033[0m" -#define FOSSIL_TEST_COLOR_GREEN "\033[32m" -#define FOSSIL_TEST_COLOR_RED "\033[31m" -#define FOSSIL_TEST_COLOR_YELLOW "\033[33m" -#define FOSSIL_TEST_COLOR_BLUE "\033[34m" - -// ***************************************************************************** -// Type definitions -// ***************************************************************************** - -typedef enum { - FOSSIL_TEST_PASS, - FOSSIL_TEST_FAIL, - FOSSIL_TEST_SKIP, - FOSSIL_TEST_UNEXPECTED -} fossil_test_result_t; - -typedef enum { - FOSSIL_COLOR_DEFAULT, - FOSSIL_COLOR_GREEN, - FOSSIL_COLOR_RED, - FOSSIL_COLOR_YELLOW, - FOSSIL_COLOR_BLUE -} fossil_test_color_t; - -typedef struct fossil_test_case { - const char *name; - void (*test_func)(void); - fossil_test_result_t result; - struct fossil_test_case *next; -} fossil_test_case_t; - -typedef struct fossil_test_log { - const char *message; - fossil_test_result_t result; - struct fossil_test_log *prev; - struct fossil_test_log *next; -} fossil_test_log_t; - -typedef struct fossil_test_suite { - const char *name; - fossil_test_case_t *test_head; - struct fossil_test_suite *next; -} fossil_test_suite_t; - -typedef struct { - fossil_test_suite_t *suite_head; - fossil_test_log_t *log_head; - int pass_count; - int fail_count; - int skip_count; - int unexpected_count; - jmp_buf jump_env; -} fossil_test_runner_t; - -// ***************************************************************************** -// Function prototypes -// ***************************************************************************** - -/** - * @brief Create a new test runner. - * - * @return A pointer to the newly created test runner. - */ -fossil_test_runner_t *fossil_test_create_runner(void); - -/** - * @brief Add a test case to a test suite. - * - * @param suite The test suite to which the test case will be added. - * @param name The name of the test case. - * @param test_func The function that implements the test case. - */ -void fossil_test_add_case(fossil_test_suite_t *suite, const char *name, void (*test_func)(void)); - -/** - * @brief Create a new test suite. - * - * @param runner The test runner that will manage the test suite. - * @param name The name of the test suite. - * @return A pointer to the newly created test suite. - */ -fossil_test_suite_t *fossil_test_create_suite(fossil_test_runner_t *runner, const char *name); - -/** - * @brief Log a message with a specific test result. - * - * @param runner The test runner that manages the log. - * @param message The message to log. - * @param result The result of the test case. - */ -void fossil_test_log(fossil_test_runner_t *runner, const char *message, fossil_test_result_t result); - -/** - * @brief Run all test cases in a test suite. - * - * @param runner The test runner that manages the test suite. - * @param suite The test suite to run. - */ -void fossil_test_run_suite(fossil_test_runner_t *runner, fossil_test_suite_t *suite); - -/** - * @brief Run all test suites managed by the test runner. - * - * @param runner The test runner that manages the test suites. - */ -void fossil_test_run(fossil_test_runner_t *runner); - -/** - * @brief Generate a report of the test results. - * - * @param runner The test runner that manages the test results. - */ -void fossil_test_report(fossil_test_runner_t *runner); - -/** - * @brief Free the memory allocated for the test runner. - * - * @param runner The test runner to free. - */ -void fossil_test_free_runner(fossil_test_runner_t *runner); - -/** - * @brief Print text in a specified color. - * - * @param text The text to print. - * @param color The color to use for printing the text. - */ -void fossil_test_print_color(const char *text, fossil_test_color_t color); - -// ***************************************************************************** -// Macros for defining and adding test cases -// ***************************************************************************** -/** - * @brief Define a test suite. - * - * @param name The name of the test suite. - */ -#define _FOSSIL_TEST_SUITE(name) \ - fossil_test_suite_t name = { \ - .name = #name, \ - .tests = NULL, \ - .test_count = 0 \ - } - -/** - * @brief Define a setup function for a test suite. - * - * @param name The name of the setup function. - */ -#define _FOSSIL_TEST_SETUP(name) void name##_setup(void) - -/** - * @brief Define a teardown function for a test suite. - * - * @param name The name of the teardown function. - */ -#define _FOSSIL_TEST_TEARDOWN(name) void name##_teardown(void) - -/** - * @brief Define a group of test cases. - * - * @param name The name of the test group. - */ -#define _FOSSIL_TEST_GROUP(name) void name##_group(fossil_test_runner_t runner) - -/** - * @brief Import a group of test cases. - * - * @param name The name of the test group to import. - */ -#define _FOSSIL_TEST_IMPORT(name) void name##_group(fossil_test_runner_t runner) - -/** - * @brief Export a group of test cases. - * - * @param name The name of the test group to export. - */ -#define _FOSSIL_TEST_EXPORT(name) void name##_group(fossil_test_runner_t runner) - -/** - * @brief Define a test case. - * - * @param name The name of the test case. - */ -#define _FOSSIL_TEST_CASE(name) void name(void) - -/** - * @brief Add a test case to a queue. - * - * @param queue The queue to which the test case will be added. - * @param test_func The function that implements the test case. - */ -#define _FOSSIL_TEST_ADD(queue, test_func) \ - do { \ - fossil_test_case_t *test_case = malloc(sizeof(fossil_test_case_t)); \ - test_case->name = #test_func; \ - test_case->test_func = test_func; \ - test_case->result = FOSSIL_TEST_SKIP; \ - test_case->duration = 0.0; \ - test_case->is_expected_fail = false; \ - test_case->is_ignored = false; \ - fossil_test_enqueue(queue, test_case); \ - } while(0) - -/** - * @brief Add a test case to a suite. - * - * @param queue The queue to which the test case will be added. - * @param test_func The function that implements the test case. - * @param suite The test suite to which the test case will be added. - */ -#define _FOSSIL_TEST_ADDF(queue, test_func, suite) \ - do { \ - fossil_test_case_t *test_case = malloc(sizeof(fossil_test_case_t)); \ - test_case->name = #test_func; \ - test_case->test_func = test_func; \ - test_case->result = FOSSIL_TEST_SKIP; \ - test_case->duration = 0.0; \ - test_case->is_expected_fail = false; \ - test_case->is_ignored = false; \ - fossil_test_add_suite(suite, test_case); \ - } while(0) - -/** - * @brief Assume a condition is true, otherwise log a failure and jump to the test runner's environment. - * - * @param runner The test runner that manages the test cases. - * @param condition The condition to assume. - * @param message The message to log if the condition is false. - */ -#define _FOSSIL_TEST_ASSUME(runner, condition, message) \ - do { \ - if (!(condition)) { \ - fossil_test_log(runner, message, FOSSIL_TEST_FAIL); \ - runner->fail_count++; \ - longjmp(runner->jump_env, 1); \ - } else { \ - fossil_test_log(runner, message, FOSSIL_TEST_PASS); \ - runner->pass_count++; \ - } \ - } while (0) - -#ifdef __cplusplus -} -#endif - -#ifdef __cplusplus -#include -#include - -namespace fossil { - -} -#endif - -#endif diff --git a/code/logic/meson.build b/code/logic/meson.build index 5fbbb4b0..3e66dc73 100644 --- a/code/logic/meson.build +++ b/code/logic/meson.build @@ -1,5 +1,10 @@ -dir = include_directories('.') +test_code = ['mockup.c', 'unittest.c', 'benchmark.c'] -subdir('unittest') -subdir('mockup') -subdir('benchmark') \ No newline at end of file +fossil_test_lib = library('fossil-test', + test_code, + install: true, + include_directories: dir) + +fossil_test_dep = declare_dependency( + link_with: fossil_test_lib, + include_directories: dir) diff --git a/code/logic/mockup/mockup.c b/code/logic/mockup.c similarity index 98% rename from code/logic/mockup/mockup.c rename to code/logic/mockup.c index c7bb49a9..d1be2e89 100644 --- a/code/logic/mockup/mockup.c +++ b/code/logic/mockup.c @@ -14,7 +14,7 @@ * Copyright (C) 2024 Fossil Logic. All rights reserved. * ----------------------------------------------------------------------------- */ -#include "fossil/mockup/mockup.h" +#include "fossil/test/mockup.h" void fossil_mock_init(MockCallList *list) { list->head = xnullptr; diff --git a/code/logic/mockup/meson.build b/code/logic/mockup/meson.build deleted file mode 100644 index 1f615858..00000000 --- a/code/logic/mockup/meson.build +++ /dev/null @@ -1,10 +0,0 @@ -mock_code = ['mockup.c'] - -fossil_mock_lib = library('fossil-mock', - mock_code, - install: true, - include_directories: dir) - -fossil_mock_dep = declare_dependency( - link_with: fossil_mock_lib, - include_directories: dir) diff --git a/code/logic/unittest.c b/code/logic/unittest.c new file mode 100644 index 00000000..51eea2db --- /dev/null +++ b/code/logic/unittest.c @@ -0,0 +1,216 @@ +/* + * ----------------------------------------------------------------------------- + * Project: Fossil Logic + * + * This file is part of the Fossil Logic project, which aims to develop high- + * performance, cross-platform applications and libraries. The code contained + * herein is subject to the terms and conditions defined in the project license. + * + * Author: Michael Gene Brockus (Dreamer) + * Date: 07/01/2024 + * + * Copyright (C) 2024 Fossil Logic. All rights reserved. + * ----------------------------------------------------------------------------- + */ +#include "fossil/test/unittest.h" + +// Global variables for tracking test results +int pass_count = 0; +int fail_count = 0; +int skip_count = 0; +int unexpected_count = 0; +jmp_buf env; + +// Global list to store all test suites +test_suite_t *global_test_suites = NULL; + +// Initialize the test framework +void fossil_test_init(void) { + pass_count = 0; + fail_count = 0; + skip_count = 0; + unexpected_count = 0; +} + +// Cleanup after test execution +void fossil_test_cleanup(void) { + // Cleanup for all test suites can be added here +} + +void fossil_test_summary(void) { + printf("Test Summary:\n"); + printf(" Passed: %d\n", pass_count); + printf(" Failed: %d\n", fail_count); + printf(" Skipped: %d\n", skip_count); + printf(" Unexpected: %d\n", unexpected_count); +} + +// Register a test suite by adding it to the global list +void fossil_test_register_suite(test_suite_t *suite) { + if (global_test_suites == NULL) { + global_test_suites = suite; + } else { + test_suite_t *current = global_test_suites; + while (current->next != NULL) { + current = current->next; + } + current->next = suite; + } +} + +// Add a test case to the double-ended priority queue +void fossil_test_add_case(double_ended_priority_queue_t *queue, test_case_t *test) { + if (queue->back == NULL) { + queue->front = queue->back = test; + test->next = test->prev = NULL; + } else { + queue->back->next = test; + test->prev = queue->back; + test->next = NULL; + queue->back = test; + } +} + +// Remove a test case from the front of the queue +void fossil_test_remove_front(double_ended_priority_queue_t *queue) { + if (queue->front == NULL) return; + + test_case_t *test_to_remove = queue->front; + queue->front = queue->front->next; + + if (queue->front == NULL) { + queue->back = NULL; + } else { + queue->front->prev = NULL; + } + + free(test_to_remove); +} + +// Remove a test case from the back of the queue +void fossil_test_remove_back(double_ended_priority_queue_t *queue) { + if (queue->back == NULL) return; + + test_case_t *test_to_remove = queue->back; + queue->back = queue->back->prev; + + if (queue->back == NULL) { + queue->front = NULL; + } else { + queue->back->next = NULL; + } + + free(test_to_remove); +} + +// Run all tests in the test suite +void fossil_test_run_suite(test_suite_t *suite) { + printf("Running tests in suite: %s\n", suite->name); + clock_t suite_start_time = clock(); + + if (suite->suite_setup_func) { + suite->suite_setup_func(); + } + + while (suite->tests->front != NULL) { + test_case_t *test = suite->tests->front; + test->status = test_status_pass; + + if (test->setup_func) { + test->setup_func(); + } + + clock_t test_start_time = clock(); + + if (setjmp(env) == 0) { + test->test_func(); + } else { + test->status = test_status_fail; + unexpected_count++; + printf("FAIL: %s - %s\n", test->name, test->failure_message); + + printf("Stack Trace:\n"); + stack_frame_t *current_frame = test->stack_trace; + while (current_frame != NULL) { + printf(" at %s (%s:%d)\n", current_frame->func, current_frame->file, current_frame->line); + current_frame = current_frame->next; + } + } + + test->execution_time = (double)(clock() - test_start_time) / CLOCKS_PER_SEC; + + if (test->teardown_func) { + test->teardown_func(); + } + + if (test->status == test_status_pass) { + printf("PASS: %s (%.3f seconds)\n", test->name, test->execution_time); + pass_count++; + } else if (test->status == test_status_fail) { + fail_count++; + } else if (test->status == test_status_skip) { + printf("SKIP: %s\n", test->name); + skip_count++; + } + + stack_frame_t *frame_to_free; + while (test->stack_trace != NULL) { + frame_to_free = test->stack_trace; + test->stack_trace = test->stack_trace->next; + free(frame_to_free); + } + + fossil_test_remove_front(suite->tests); + } + + if (suite->suite_teardown_func) { + suite->suite_teardown_func(); + } + + suite->total_execution_time = (double)(clock() - suite_start_time) / CLOCKS_PER_SEC; + printf("Total time for suite %s: %.3f seconds\n", suite->name, suite->total_execution_time); +} + +/** + * Assert a condition in a test case. + * + * @param condition The condition to assert. + * @param message The failure message if the condition is false. + * @param file The file where the assertion failed. + * @param line The line number where the assertion failed. + * @param func The function where the assertion failed. + */ +void fossil_test_assume(bool condition, const char *message, const char *file, int line, const char *func) { + if (!condition) { + test_case_t *current_test = global_test_suites->tests->back; + current_test->status = test_status_fail; + current_test->failure_message = message; + + stack_frame_t *frame = malloc(sizeof(stack_frame_t)); + frame->func = func; + frame->file = file; + frame->line = line; + frame->next = current_test->stack_trace; + current_test->stack_trace = frame; + + longjmp(env, 1); + } +} + +void fossil_test_register_suite(test_suite_t *suite) { + if (!suite) return; // Ensure the suite is not NULL + + // Link the new suite at the front of the global list + suite->next = global_test_suites; + global_test_suites = suite; + + printf("Registered test suite: %s\n", suite->name); +} + +void fossil_test_assume(bool condition, const char *message, const char *file, int line, const char *func) { + if (!condition) { + fprintf(stderr, "ASSUMPTION FAILED: %s\nFile: %s, Line: %d, Function: %s\n", message, file, line, func); + // Increment the unexpected count for reporting + unexpected_count++; + } +} diff --git a/code/logic/unittest/commands.c b/code/logic/unittest/commands.c deleted file mode 100644 index 780dcf8a..00000000 --- a/code/logic/unittest/commands.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#include "fossil/unittest/commands.h" -#include "fossil/unittest/framework.h" -#include "fossil/unittest/console.h" -#include -#include - -fossil_options_t _CLI; - -// Initialize the options structure -fossil_options_t init_options(void) { - fossil_options_t options; - options.show_version = false; - options.show_help = false; - options.show_tip = false; - options.show_info = false; - options.show_author = false; - options.only_tags = false; - options.reverse = false; - options.repeat_enabled = false; - options.repeat_count = 1; - options.shuffle_enabled = false; - options.verbose_enabled = false; - options.verbose_level = 1; - options.list_tests = false; - options.summary_enabled = false; - options.color_enabled = false; - options.sanity_enabled = false; - return options; -} - -// Parse command-line arguments -fossil_options_t fossil_options_parse(int argc, char **argv) { - fossil_options_t options = init_options(); - - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "--version") == 0) { - options.show_version = true; - } else if (strcmp(argv[i], "--help") == 0) { - options.show_help = true; - } else if (strcmp(argv[i], "--tip") == 0) { - options.show_tip = true; - } else if (strcmp(argv[i], "--info") == 0) { - options.show_info = true; - } else if (strcmp(argv[i], "--author") == 0) { - options.show_author = true; - } else if (strcmp(argv[i], "only") == 0) { - options.only_tags = true; - if (i + 1 < argc && argv[i + 1][0] != '-') { - strcpy(options.only_tags_value, argv[i + 1]); - i++; - } - } else if (strcmp(argv[i], "reverse") == 0) { - if (i + 1 < argc && strcmp(argv[i + 1], "enable") == 0) { - options.reverse = true; - } else if (i + 1 < argc && strcmp(argv[i + 1], "disable") == 0) { - options.reverse = false; - } - } else if (strcmp(argv[i], "repeat") == 0) { - options.repeat_enabled = true; - if (i + 1 < argc && argv[i + 1][0] != '-') { - options.repeat_count = atoi(argv[i + 1]); - i++; - } - } else if (strcmp(argv[i], "shuffle") == 0) { - if (i + 1 < argc && strcmp(argv[i + 1], "enable") == 0) { - options.shuffle_enabled = true; - } else if (i + 1 < argc && strcmp(argv[i + 1], "disable") == 0) { - options.shuffle_enabled = false; - } - } else if (strcmp(argv[i], "verbose") == 0) { - options.verbose_enabled = true; - if (i + 1 < argc && strcmp(argv[i + 1], "cutback") == 0) { - options.verbose_level = 0; - } else if (i + 1 < argc && strcmp(argv[i + 1], "verbose") == 0) { - options.verbose_level = 2; - } - } else if (strcmp(argv[i], "list") == 0) { - options.list_tests = true; - } else if (strcmp(argv[i], "summary") == 0) { - if (i + 1 < argc && strcmp(argv[i + 1], "enable") == 0) { - options.summary_enabled = true; - } else if (i + 1 < argc && strcmp(argv[i + 1], "disable") == 0) { - options.summary_enabled = false; - } - } else if (strcmp(argv[i], "color") == 0) { - if (i + 1 < argc && strcmp(argv[i + 1], "enable") == 0) { - options.color_enabled = true; - } else if (i + 1 < argc && strcmp(argv[i + 1], "disable") == 0) { - options.color_enabled = false; - } - } else if (strcmp(argv[i], "sanity") == 0) { - if (i + 1 < argc && strcmp(argv[i + 1], "enable") == 0) { - options.sanity_enabled = true; - } else if (i + 1 < argc && strcmp(argv[i + 1], "disable") == 0) { - options.sanity_enabled = false; - } - } - } - - return options; -} diff --git a/code/logic/unittest/console.c b/code/logic/unittest/console.c deleted file mode 100644 index a6055e54..00000000 --- a/code/logic/unittest/console.c +++ /dev/null @@ -1,491 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#include "fossil/unittest/console.h" -#include "fossil/unittest/framework.h" -#include "fossil/unittest/commands.h" -#include - -static const char* FOSSIL_TEST_NAME = "Fossil Test"; -static const char* FOSSIL_TEST_AUTH = "Michael Gene Brockus (Dreamer)"; -static const char* FOSSIL_TEST_VERSION = "1.0.3"; -static const char* FOSSIL_TEST_INFO = "Fossil Test is a next-generation unit testing/mockup framework for C/C++."; - -// ============================================================================== -// Xtest internal console stream logic -// ============================================================================== - -// Function to generate a random humorous comment about an empty test runner -// becuse way not add a little sillyness. -char* empty_runner_comment(void) { - char* comments[] = { // add more to this - "Looks like the test runner is on a coffee break!", - "The test runner is feeling a bit empty today, like my coffee cup.", - "The test runner is as empty as a developer's coffee mug on Monday morning.", - "Did someone forget to load the tests? The runner seems quite empty!", - "The test runner is as empty as a promise to write documentation.", - "The test runner is emptier than a developer's promise to refactor code.", - "The test runner seems to be on a diet - it's looking quite empty!", - "Did the tests escape? The runner seems unusually empty!", - "The test runner is as empty as a JavaScript developer's promises.", - "The test runner seems as empty as my enthusiasm for Monday mornings.", - "The test runner is emptier than a meeting agenda without a clear purpose.", - "The test runner is looking as empty as a developer's patience with legacy code.", - "The test runner is as empty as a database without any data.", - "The test runner seems to be in stealth mode - it's quite empty!", - "The test runner is emptier than a startup's promise of equity.", - "The test runner is as empty as a meeting room during a free lunch seminar.", - "The test runner is looking as empty as a developer's snack stash on Friday afternoon.", - "The test runner seems to be as empty as a Git repository with no commits.", - "The test runner is emptier than a developer's memory after a long debugging session.", - "The test runner is looking as empty as a developer's inbox after vacation.", - "The test runner is as empty as a conference room during a fire drill.", - "The test runner seems to be as empty as a developer's coffee pot after a long night of coding.", - "The test runner is emptier than a developer's promise to write unit tests." - }; - - int num_comments = sizeof(comments) / sizeof(comments[0]); - - srand(time(xnullptr)); - - // Generate a random index - int random_index = rand() % num_comments; - - return comments[random_index]; -} - -char* passing_test_comment(void) { - char* comments[] = { - "Success! The test passed faster than a speeding processor!", - "Hooray! The test passed like a champ!", - "All green! The test passed with flying colors!", - "The test passed as smoothly as butter on a hot pancake!", - "Great job! The test passed like a breeze on a sunny day!", - "The test passed with more grace than a ballerina on stage!", - "Fantastic! The test passed like it was on a mission!", - "Woohoo! The test passed like a pro!", - "The test passed like a well-oiled machine!", - "Brilliant! The test passed without a hitch!", - "The test passed like a hot knife through butter!", - "Outstanding! The test passed like a well-orchestrated symphony!", - "Victory! The test passed like a champion!", - "The test passed as smoothly as a Tesla on autopilot!", - "Amazing! The test passed like a rocket to the moon!", - "The test passed like a marathon runner crossing the finish line!", - "Excellent! The test passed without breaking a sweat!", - "The test passed like a star pupil acing an exam!", - "Spectacular! The test passed with flying colors!", - "The test passed like a well-rehearsed play!", - "The test passed like a breeze through an open window!", - "The test passed like a pro on its first try!", - "The test passed like a dream come true!" - }; - - int num_comments = sizeof(comments) / sizeof(comments[0]); - - srand(time(NULL)); - - // Generate a random index - int random_index = rand() % num_comments; - - return comments[random_index]; -} - -char* failure_test_comment(void) { - char* comments[] = { - "Oops! The test failed like a buttered cat falling from the ceiling!", - "Yikes! The test failed harder than my New Year's resolutions!", - "Darn it! The test failed like a paper airplane in a storm!", - "Bummer! The test failed like a joke at a silent party!", - "Oh no! The test failed like my diet on a cheat day!", - "Rats! The test failed like a house of cards in a windstorm!", - "Drat! The test failed like a deflated balloon at a party!", - "Egads! The test failed like a bad pun in a dad joke contest!", - "Alas! The test failed like my plans to wake up early!", - "Shoot! The test failed like my internet connection during a crucial moment!", - "Dang it! The test failed like a soap opera plot twist!", - "Blast! The test failed like a lead balloon!", - "Crud! The test failed like my attempts to avoid procrastination!", - "Oh dear! The test failed like a misplaced semicolon!", - "Bother! The test failed like a comedian at a serious event!", - "Son of a gun! The test failed like a tech demo at a live presentation!", - "Aw, shucks! The test failed like my weekend plans to relax!", - "Fiddlesticks! The test failed like a magician's trick gone wrong!", - "Good grief! The test failed like a server on Black Friday!", - "Zounds! The test failed like my Wi-Fi when I need it most!", - "Oh snap! The test failed like a toaster in the bathtub!", - "Cripes! The test failed like a fish out of water!", - "Dagnabbit! The test failed like a cat trying to swim!", - "Holy moly! The test failed like a balloon in a cactus field!" - }; - - int num_comments = sizeof(comments) / sizeof(comments[0]); - - srand(time(NULL)); - - // Generate a random index - int random_index = rand() % num_comments; - - return comments[random_index]; -} - -// Function to generate a random tip for unit testing released tasks -// as this would servse as a handy feature and be helpful for teaching -// new developers how they can write good test cases. -char* helpful_tester_tip(void) { - char* tips[] = { - "Always write meaningful test names.", - "Test both positive and negative cases.", - "Use mocking for external dependencies.", - "Run tests frequently during development.", - "Ensure tests are isolated and independent.", - "Avoid hardcoding values in test cases.", - "Focus on testing the functionality, not the implementation.", - "Regularly update and maintain test cases.", - "Use code coverage tools to identify untested code.", - "Test edge cases and boundary conditions.", - "Keep unit tests fast and repeatable.", - "Use setup and teardown methods when necessary.", - "Automate the execution of tests.", - "Review and refactor tests regularly.", - "Write tests for both happy paths and error paths.", - "Test for performance and scalability where applicable.", - "Use assertions effectively to verify outcomes.", - "Consider using property-based testing for complex logic.", - "Document the purpose and expected run_as of each test.", - "Collaborate with the development team to identify test cases.", - "Prioritize and focus on critical and high-risk areas.", - "Write tests early in the development process.", - "Use version control for test code and test data.", - "Ensure that tests can run in different environments.", - "Consider the maintainability and readability of test code.", - "Use test frameworks and libraries to simplify testing.", - "Use test data generation tools to create test data.", - "Use test reporting tools to track test results.", - "Use test management tools to organize and execute tests.", - "Use continuous integration to automate test execution." - }; - - int num_tips = sizeof(tips) / sizeof(tips[0]); - - srand(time(xnullptr)); - - // Generate a random index - int random_index = rand() % num_tips; - - return tips[random_index]; -} - -char *summary_message(fossil_env_t *env) { - if (env->stats.expected_failed_count == 0 && env->stats.expected_passed_count > 0) { - return passing_test_comment(); - } else if (env->stats.expected_failed_count > 0) { - return failure_test_comment(); - } else { - return empty_runner_comment(); - } - return "No summary message available"; -} - -char* current_datetime(void) { - time_t rawtime; - struct tm* timeinfo; - static char datetime[20]; // Buffer to hold the formatted date and time - - time(&rawtime); - timeinfo = localtime(&rawtime); - - strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", timeinfo); - - char* copy = _custom_fossil_test_strdup(datetime); // Return a dynamically allocated copy of the datetime - if (!copy) { - return xnullptr; // Check for memory allocation failure - } - - char* result = _custom_fossil_test_strdup(datetime); // Return a dynamically allocated copy of the datetime - free(copy); // Free the temporary copy - - return result; -} - -static char* replace_underscore(const char* str) { - if (!str) { - return xnullptr; // Check for xnull input - } - - char* result = _custom_fossil_test_strdup(str); - if (!result) { - return xnullptr; // Check for memory allocation failure - } - - for (char* ptr = result; *ptr; ptr++) { - if (*ptr == '_') { - *ptr = ' '; - } - } - - char* copy = _custom_fossil_test_strdup(result); // Create a copy to free the original - free(result); // Free the original - - return copy; -} - -// Define color codes -#define COLOR_RED "\033[1;31m" -#define COLOR_GREEN "\033[1;32m" -#define COLOR_YELLOW "\033[1;33m" -#define COLOR_BLUE "\033[1;34m" -#define COLOR_BRIGHT_BLUE "\033[1;94m" -#define COLOR_DARK_BLUE "\033[0;34m" -#define COLOR_MAGENTA "\033[1;35m" -#define COLOR_CYAN "\033[1;36m" -#define COLOR_WHITE "\033[1;37m" -#define COLOR_RESET "\033[0m" - -// Define a structure to map color names to their corresponding codes -typedef struct { - const char* name; - const char* code; -} ColorMap; - -// Custom print function with color support -void fossil_test_cout(const char* color_name, const char* format, ...) { - static const ColorMap color_map[] = { - {"red", COLOR_RED}, - {"green", COLOR_GREEN}, - {"yellow", COLOR_YELLOW}, - {"blue", COLOR_BLUE}, - {"bright blue", COLOR_BRIGHT_BLUE}, - {"dark blue", COLOR_DARK_BLUE}, - {"magenta", COLOR_MAGENTA}, - {"cyan", COLOR_CYAN}, - {"white", COLOR_WHITE}, - {NULL, COLOR_RESET} // Default color - }; - - va_list args; - va_start(args, format); - - // Check if color output is enabled - if (_CLI.color_enabled) { - // Default color code - const char* color_code = COLOR_RESET; - - // Find the corresponding color code - for (int i = 0; color_map[i].name != NULL; i++) { - if (strcmp(color_name, color_map[i].name) == 0) { - color_code = color_map[i].code; - break; - } - } - - // Print color code and formatted string - printf("%s", color_code); - vprintf(format, args); - printf("%s", COLOR_RESET); // Reset color - } else { - // Color output disabled, print formatted string directly - vprintf(format, args); - } - - va_end(args); -} - -// Internal function to calculate elapsed time for a test -static void calculate_elapsed_time(fossil_test_timer_t *timer) { - timer->end = clock(); - // Calculate elapsed time - timer->elapsed = timer->end - timer->start; - - // Convert elapsed time to different units - timer->detail.minutes = timer->elapsed / (CLOCKS_PER_SEC * 60); - timer->detail.seconds = (timer->elapsed / CLOCKS_PER_SEC) % 60; - timer->detail.milliseconds = (timer->elapsed * 1000) / CLOCKS_PER_SEC; - timer->detail.microseconds = (timer->elapsed * 1000000) / CLOCKS_PER_SEC; - timer->detail.nanoseconds = (timer->elapsed * 1000000000) / CLOCKS_PER_SEC; -} - -// Function to handle CLI information output -void fossil_test_io_information(void) { - if (_CLI.show_version) { - fossil_test_cout("blue", "%s\n", FOSSIL_TEST_VERSION); - exit(0); - } else if (_CLI.show_info) { - fossil_test_cout("blue", "%s\n", FOSSIL_TEST_INFO); - exit(0); - } else if (_CLI.show_tip) { - fossil_test_cout("blue", "%s\n", helpful_tester_tip()); - exit(0); - } else if (_CLI.show_author) { - fossil_test_cout("blue", "%s\n", FOSSIL_TEST_AUTH); - exit(0); - } else if (_CLI.show_help) { - fossil_test_cout("blue", "Usage: fossil_test_cli [options]\n"); - fossil_test_cout("blue", "Options:\n"); - fossil_test_cout("cyan", " --version Displays the version of the Fossil Test CLI\n"); - fossil_test_cout("cyan", " --help Shows the help message with usage instructions\n"); - fossil_test_cout("cyan", " --tip Provides a tip or hint about using the Fossil Test CLI\n"); - fossil_test_cout("cyan", " --info Displays information about the test runner\n"); - fossil_test_cout("cyan", " --author Shows information about the author of the test runner\n"); - fossil_test_cout("cyan", " only= or only= Runs only the tests tagged with the specified tag(s)\n"); - fossil_test_cout("cyan", " reverse [enable/disable] Enables or disables the reverse order of test execution\n"); - fossil_test_cout("cyan", " repeat= Repeats the test suite for the specified number of times\n"); - fossil_test_cout("cyan", " shuffle [enable/disable] Enables or disables the shuffling of test execution order\n"); - fossil_test_cout("cyan", " verbose [cutback/normal/verbose] Sets the verbosity level of the output\n"); - fossil_test_cout("cyan", " list Lists all available tests\n"); - fossil_test_cout("cyan", " summary [enable/disable] Enables or disables the summary of test results after execution\n"); - fossil_test_cout("cyan", " color [enable/disable] Enables or disables colored output in the terminal\n"); - fossil_test_cout("cyan", " sanity [enable/disable] Enables or disables sanity checks before running the tests\n"); - exit(0); - } -} - -void fossil_test_io_sanity_load(fossil_test_t *test) { - if (_CLI.verbose_level == 2 && _CLI.sanity_enabled) { - fossil_test_cout("blue", "load test: "); - fossil_test_cout("cyan", " -> id: %.4d, tag: %s, name: %s\n", _TEST_ENV.stats.untested_count + 1, test->tags, test->name); - } else if (_CLI.verbose_level == 1 && _CLI.sanity_enabled) { - fossil_test_cout("blue", "[loaded] test: "); - fossil_test_cout("cyan", " -> %.4d %s\n", _TEST_ENV.stats.untested_count + 1, test->name); - } -} - -void fossil_test_io_unittest_start(fossil_test_t *test) { - test->timer.start = clock(); - - if (_CLI.verbose_level == 2) { - fossil_test_cout("blue", "%s[%.4d]%s\n", "=[started case]=====================================================================", - _TEST_ENV.stats.expected_total_count + 1, "==="); - fossil_test_cout("blue", "test name : "); - fossil_test_cout("cyan", " -> %s\n", replace_underscore(test->name)); - fossil_test_cout("blue", "priority : "); - fossil_test_cout("cyan", " -> %d\n", test->priority); - fossil_test_cout("blue", "tags : "); - fossil_test_cout("cyan", " -> %s\n", test->tags); - fossil_test_cout("blue", "marker : "); - fossil_test_cout("cyan", " -> %s\n", test->marks); - } else if (_CLI.verbose_level == 1) { - fossil_test_cout("blue", "[start] "); - fossil_test_cout("cyan", "%.4d: %s tag: %s mark: %s\n", _TEST_ENV.stats.expected_total_count + 1, replace_underscore(test->name), test->tags, test->marks); - } -} - -void fossil_test_io_unittest_given(char *description) { - if (_CLI.verbose_level == 2) { - fossil_test_cout("blue", " : "); - fossil_test_cout("magenta", "%s%s\n", "GIVEN ", description); - } -} - -void fossil_test_io_unittest_when(char *description) { - if (_CLI.verbose_level == 2) { - fossil_test_cout("blue", " : "); - fossil_test_cout("magenta", "%s%s\n", "\tWHEN ", description); - } -} - -void fossil_test_io_unittest_then(char *description) { - if (_CLI.verbose_level == 2) { - fossil_test_cout("blue", " : "); - fossil_test_cout("magenta", "%s%s\n", "\t\tTHEN ", description); - } -} - -void fossil_test_io_unittest_step(xassert_info *assume) { - if (_CLI.verbose_level == 2) { - fossil_test_cout("blue", "has assert : "); - fossil_test_cout("cyan", " -> %s\n", assume->has_assert ? COLOR_GREEN "has assertions" COLOR_RESET : COLOR_RED "missing assertions" COLOR_RESET); - fossil_test_cout("blue", "asserts used: "); - fossil_test_cout("cyan", COLOR_GREEN "%3i\n" COLOR_RESET , assume->num_asserts); - } else if (_CLI.verbose_level == 1) { - fossil_test_cout("blue", "[intro] has_assert : "); - fossil_test_cout("cyan", "%s\n", assume->has_assert ? COLOR_GREEN "yes" COLOR_RESET : COLOR_RED "no" COLOR_RESET); - fossil_test_cout("blue", "[intro] same_assert: "); - fossil_test_cout("cyan", "%s\n", assume->same_assert ? COLOR_RED "yes" COLOR_RESET : COLOR_GREEN "no" COLOR_RESET); - fossil_test_cout("blue", "[intro] num_asserts: "); - fossil_test_cout("cyan", COLOR_GREEN "%3i\n" COLOR_RESET , assume->num_asserts); - } -} - -void fossil_test_io_unittest_ended(fossil_test_t *test) { - calculate_elapsed_time(&test->timer); - - if (_CLI.verbose_level == 2) { - fossil_test_cout("blue", "timestamp : "); - fossil_test_cout("cyan", " -> %ld minutes, %ld seconds, %ld milliseconds, %ld microseconds, %ld nanoseconds\n", - (uint32_t)test->timer.detail.minutes, (uint32_t)test->timer.detail.seconds, (uint32_t)test->timer.detail.milliseconds, - (uint32_t)test->timer.detail.microseconds, (uint32_t)test->timer.detail.nanoseconds); - fossil_test_cout("blue", "%s\n", "=[ ended case ]=============================================================================="); - } else if (_CLI.verbose_level == 1) { - fossil_test_cout("blue", "[ended] time: "); - fossil_test_cout("cyan", "%ld:%ld:%ld:%ld:%ld\n", - (uint32_t)test->timer.detail.minutes, (uint32_t)test->timer.detail.seconds, (uint32_t)test->timer.detail.milliseconds, - (uint32_t)test->timer.detail.microseconds, (uint32_t)test->timer.detail.nanoseconds); - } else if (_CLI.verbose_level == 0 && !_ASSERT_INFO.should_fail) { - fossil_test_cout("green", "[#]"); - } - - // Check for timeout - if (test->timer.elapsed >= (2 * 60 * CLOCKS_PER_SEC)) { - _TEST_ENV.rule.timeout = true; - } -} - -void fossil_test_io_asserted(xassert_info *assume) { - if (_CLI.verbose_level == 2) { - fossil_test_cout("red", "=[F]=[assertion failed]======================================================================\n"); - fossil_test_cout("red", "message : -> %s\n", assume->message); - fossil_test_cout("red", "file name: -> %s\n", assume->file); - fossil_test_cout("red", "line num : -> %d\n", assume->line); - fossil_test_cout("red", "function : -> %s\n", assume->func); - fossil_test_cout("red", "=========================================================================================[F]=\n"); - } else if (_CLI.verbose_level == 1) { - fossil_test_cout("red", "name: %s line: -> %d msg: -> %s\n", assume->func, assume->line, assume->message); - } else { - fossil_test_cout("red", "[#]"); - } -} - -void fossil_test_io_summary_start(void) { - fossil_test_cout("blue", "=============================================================================================\n"); - fossil_test_cout("blue", "%s\n", "platform meta data about the host system:"); - fossil_test_cout("blue", "endian(%6s) cpus(%2i) memory(%4i) os(%s) arch(%s)\n", - _fossil_test_assert_is_big_endian() ? "big" : "little", _fossil_test_get_num_cpus(), _fossil_test_get_memory_size(), _fossil_test_get_os_name(), _fossil_test_get_architecture()); - fossil_test_cout("blue", "=============================================================================================\n"); -} - -void fossil_test_io_summary_ended(void) { - char *color = "green"; - if (_TEST_ENV.stats.expected_failed_count > 0) { - color = "red"; - } else if (_TEST_ENV.stats.expected_passed_count == 0) { - color = "yellow"; - } - - fossil_test_cout("blue", "\n%s %s: %s\n\n", FOSSIL_TEST_NAME, FOSSIL_TEST_VERSION, FOSSIL_TEST_INFO); - fossil_test_cout("blue", "=============================================================================================\n"); - fossil_test_cout("blue", "%s", " message: "); - fossil_test_cout(color, "%s\n", summary_message(&_TEST_ENV)); - fossil_test_cout("cyan", "> Expected Passed : %3d Expected Failed: %3d\n", _TEST_ENV.stats.expected_passed_count, _TEST_ENV.stats.expected_failed_count); - fossil_test_cout("cyan", "> Unexpected Passed: %3d Unexpected Failed: %3d\n", _TEST_ENV.stats.unexpected_passed_count, _TEST_ENV.stats.expected_failed_count); - fossil_test_cout("cyan", "> Timeout: %3d Skipped: %3d Empty: %3d\n", _TEST_ENV.stats.expected_timeout_count, _TEST_ENV.stats.expected_skipped_count, _TEST_ENV.stats.expected_empty_count); - fossil_test_cout("blue", "=============================================================================================\n"); - fossil_test_cout("blue", "Total Tests: %d\n", _TEST_ENV.stats.expected_total_count); - fossil_test_cout("blue", "Total Ghost: %d\n", _TEST_ENV.stats.untested_count); - fossil_test_cout("blue", "=============================================================================================\n"); - calculate_elapsed_time(&_TEST_ENV.timer); - fossil_test_cout("yellow", "timestamp : -> %ld minutes, %ld seconds, %ld milliseconds, %ld microseconds, %ld nanoseconds\n", - (uint32_t)_TEST_ENV.timer.detail.minutes, (uint32_t)_TEST_ENV.timer.detail.seconds, (uint32_t)_TEST_ENV.timer.detail.milliseconds, - (uint32_t)_TEST_ENV.timer.detail.microseconds, (uint32_t)_TEST_ENV.timer.detail.nanoseconds); -} diff --git a/code/logic/unittest/meson.build b/code/logic/unittest/meson.build deleted file mode 100644 index 5b4870af..00000000 --- a/code/logic/unittest/meson.build +++ /dev/null @@ -1,10 +0,0 @@ -test_code = ['commands.c', 'console.c', 'unittest.c'] - -fossil_test_lib = library('fossil-test', - test_code, - install: true, - include_directories: dir) - -fossil_test_dep = declare_dependency( - link_with: fossil_test_lib, - include_directories: dir) diff --git a/code/logic/unittest/unittest.c b/code/logic/unittest/unittest.c deleted file mode 100644 index 4064f11f..00000000 --- a/code/logic/unittest/unittest.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#include "fossil/unittest/unittest.h" -#include -#include -#include -#include -#include - -// Color Helper Function -void fossil_test_print_color(const char *text, fossil_test_color_t color) { - switch (color) { - case FOSSIL_COLOR_GREEN: printf("\033[0;32m%s\033[0m", text); break; - case FOSSIL_COLOR_RED: printf("\033[0;31m%s\033[0m", text); break; - case FOSSIL_COLOR_YELLOW: printf("\033[0;33m%s\033[0m", text); break; - case FOSSIL_COLOR_BLUE: printf("\033[0;34m%s\033[0m", text); break; - default: printf("%s", text); break; - } -} - -fossil_test_runner_t *fossil_test_create_runner() { - fossil_test_runner_t *runner = (fossil_test_runner_t*)malloc(sizeof(fossil_test_runner_t)); - if (!runner) return NULL; - runner->suite_head = NULL; - runner->log_head = NULL; - runner->pass_count = runner->fail_count = runner->skip_count = runner->unexpected_count = 0; - return runner; -} - -void fossil_test_add_case(fossil_test_suite_t *suite, const char *name, void (*test_func)(void)) { - fossil_test_case_t *test_case = (fossil_test_case_t*)malloc(sizeof(fossil_test_case_t)); - test_case->name = name; - test_case->test_func = test_func; - test_case->result = FOSSIL_TEST_UNEXPECTED; - test_case->next = suite->test_head; - suite->test_head = test_case; -} - -fossil_test_suite_t *fossil_test_create_suite(fossil_test_runner_t *runner, const char *name) { - fossil_test_suite_t *suite = (fossil_test_suite_t*)malloc(sizeof(fossil_test_suite_t)); - suite->name = name; - suite->test_head = NULL; - suite->next = runner->suite_head; - runner->suite_head = suite; - return suite; -} - -void fossil_test_log(fossil_test_runner_t *runner, const char *message, fossil_test_result_t result) { - fossil_test_log_t *log = (fossil_test_log_t*)malloc(sizeof(fossil_test_log_t)); - log->message = message; - log->result = result; - log->prev = NULL; - log->next = runner->log_head; - if (runner->log_head) runner->log_head->prev = log; - runner->log_head = log; -} - -void fossil_test_run_suite(fossil_test_runner_t *runner, fossil_test_suite_t *suite) { - fossil_test_case_t *current = suite->test_head; - while (current) { - printf(" Running test: %s\n", current->name); - if (setjmp(runner->jump_env) == 0) { - current->test_func(); - current->result = FOSSIL_TEST_PASS; - } else { - current->result = FOSSIL_TEST_FAIL; - } - current = current->next; - } -} - -void fossil_test_run(fossil_test_runner_t *runner) { - fossil_test_suite_t *suite = runner->suite_head; - while (suite) { - printf("\nRunning suite: "); - fossil_test_print_color(suite->name, FOSSIL_COLOR_BLUE); - printf("\n"); - - fossil_test_run_suite(runner, suite); - suite = suite->next; - } -} - -void fossil_test_report(fossil_test_runner_t *runner) { - printf("\nTest Summary:\n"); - fossil_test_print_color("Pass: ", FOSSIL_COLOR_GREEN); printf("%d\n", runner->pass_count); - fossil_test_print_color("Fail: ", FOSSIL_COLOR_RED); printf("%d\n", runner->fail_count); - fossil_test_print_color("Skip: ", FOSSIL_COLOR_YELLOW); printf("%d\n", runner->skip_count); - printf("Unexpected: %d\n", runner->unexpected_count); - - printf("\nDetailed Log:\n"); - fossil_test_log_t *log = runner->log_head; - while (log) { - switch (log->result) { - case FOSSIL_TEST_PASS: fossil_test_print_color("[PASS] ", FOSSIL_COLOR_GREEN); break; - case FOSSIL_TEST_FAIL: fossil_test_print_color("[FAIL] ", FOSSIL_COLOR_RED); break; - case FOSSIL_TEST_SKIP: fossil_test_print_color("[SKIP] ", FOSSIL_COLOR_YELLOW); break; - default: printf("[UNEXPECTED] "); break; - } - printf("%s\n", log->message); - log = log->next; - } -} - -void fossil_test_free_runner(fossil_test_runner_t *runner) { - fossil_test_suite_t *suite = runner->suite_head; - while (suite) { - fossil_test_case_t *test_case = suite->test_head; - while (test_case) { - fossil_test_case_t *temp = test_case; - test_case = test_case->next; - free(temp); - } - fossil_test_suite_t *temp_suite = suite; - suite = suite->next; - free(temp_suite); - } - fossil_test_log_t *log = runner->log_head; - while (log) { - fossil_test_log_t *temp = log; - log = log->next; - free(temp); - } - free(runner); -} diff --git a/code/tests/generate-runner.py b/code/tests/generate-runner.py index cdc3e069..850180fe 100644 --- a/code/tests/generate-runner.py +++ b/code/tests/generate-runner.py @@ -26,7 +26,7 @@ def generate_test_runner(self, test_groups): """ header += """ -#include +#include """ header += """ @@ -55,7 +55,7 @@ def generate_test_runner(self, test_groups): footer = """ FOSSIL_TEST_RUN(); - return FOSSIL_TEST_ERASE(); + FOSSIL_TEST_END(); } // end of func """ diff --git a/code/tests/meson.build b/code/tests/meson.build index 8e3aacb1..50fed56f 100644 --- a/code/tests/meson.build +++ b/code/tests/meson.build @@ -1,5 +1,5 @@ if get_option('with_test').enabled() - run_command(['python3', 'generate-runner.py'], check: true) + #run_command(['python3', 'generate-runner.py'], check: true) test_src = ['unit_runner.c'] test_cubes = [ @@ -10,6 +10,6 @@ if get_option('with_test').enabled() test_src += ['test_' + cube + '.c'] endforeach - pizza = executable('xcli', test_src, include_directories: dir, dependencies: [fossil_test_dep, fossil_mock_dep, fossil_mark_dep]) + pizza = executable('xcli', test_src, include_directories: dir, dependencies: [fossil_test_dep]) test('fossil_tests', pizza) # Renamed the test target for clarity endif diff --git a/code/tests/test_bdd.c b/code/tests/test_bdd.c index 152e4325..4af5e00b 100644 --- a/code/tests/test_bdd.c +++ b/code/tests/test_bdd.c @@ -12,7 +12,7 @@ * Copyright (C) 2024 Fossil Logic. All rights reserved. * ----------------------------------------------------------------------------- */ -#include +#include // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Utilites @@ -31,7 +31,7 @@ // as samples for library usage. // * * * * * * * * * * * * * * * * * * * * * * * * -FOSSIL_SONERO(xbdd_logic_test) { +FOSSIL_TEST_CASE(xbdd_logic_test) { GIVEN("a valid statement is passed") { // Set up the context bool givenExecuted = true; @@ -44,15 +44,15 @@ FOSSIL_SONERO(xbdd_logic_test) { // Check the expected outcome bool thenExecuted = true; - TEST_EXPECT(givenExecuted, "Given statement should have executed"); - TEST_EXPECT(whenExecuted, "When statement should have executed"); - TEST_EXPECT(thenExecuted, "Then statement should have executed"); + FOSSIL_TEST_ASSUME(givenExecuted, "Given statement should have executed"); + FOSSIL_TEST_ASSUME(whenExecuted, "When statement should have executed"); + FOSSIL_TEST_ASSUME(thenExecuted, "Then statement should have executed"); } } } } // end of case -FOSSIL_SONERO(xbdd_user_account) { +FOSSIL_TEST_CASE(xbdd_user_account) { GIVEN("a user's account with sufficient balance") { // Set up the context float accountBalance = 500.0; @@ -68,13 +68,13 @@ FOSSIL_SONERO(xbdd_user_account) { // Simulate the scenario float compareBalance = 500.0; - TEST_EXPECT(accountBalance == (compareBalance - withdrawalAmount), "Account balance should have been deducted by $200"); + FOSSIL_TEST_ASSUME(accountBalance == (compareBalance - withdrawalAmount), "Account balance should have been deducted by $200"); } } } } // end of case -FOSSIL_SONERO(xbdd_empty_cart) { +FOSSIL_TEST_CASE(xbdd_empty_cart) { GIVEN("a user with an empty shopping cart") { // Set up the context int cartItemCount = 0; @@ -86,13 +86,13 @@ FOSSIL_SONERO(xbdd_empty_cart) { // Check the expected outcome cartItemCount++; - TEST_EXPECT(cartItemCount == 1, "Cart item count should have increased by 1"); + FOSSIL_TEST_ASSUME(cartItemCount == 1, "Cart item count should have increased by 1"); } } } } // end of case -FOSSIL_SONERO(xbdd_valid_login) { +FOSSIL_TEST_CASE(xbdd_valid_login) { GIVEN("a registered user with valid credentials") { // Set up the context const char* validUsername = "user123"; @@ -106,8 +106,8 @@ FOSSIL_SONERO(xbdd_valid_login) { THEN("the login should be successful") { // Check the expected outcome // Simulate login validation - TEST_EXPECT(strcmp(inputUsername, validUsername) == 0, "Username should match"); - TEST_EXPECT(strcmp(inputPassword, validPassword) == 0, "Password should match"); + FOSSIL_TEST_ASSUME(strcmp(inputUsername, validUsername) == 0, "Username should match"); + FOSSIL_TEST_ASSUME(strcmp(inputPassword, validPassword) == 0, "Password should match"); } } @@ -119,8 +119,8 @@ FOSSIL_SONERO(xbdd_valid_login) { THEN("the login should fail with an error message") { // Check the expected outcome // Simulate login validation - TEST_EXPECT(strcmp(inputUsername, validUsername) == 0, "Username should match"); - TEST_EXPECT(strcmp(inputPassword, validPassword) != 0, "Password should not match"); + FOSSIL_TEST_ASSUME(strcmp(inputUsername, validUsername) == 0, "Username should match"); + FOSSIL_TEST_ASSUME(strcmp(inputPassword, validPassword) != 0, "Password should not match"); } } } diff --git a/code/tests/test_marks.c b/code/tests/test_marks.c index 938c5707..65bd322c 100644 --- a/code/tests/test_marks.c +++ b/code/tests/test_marks.c @@ -12,7 +12,7 @@ * Copyright (C) 2024 Fossil Logic. All rights reserved. * ----------------------------------------------------------------------------- */ -#include // basic test tools +#include // basic test tools #include // assertion tools #include // benchmark tools @@ -74,7 +74,7 @@ void selection_sort(int *array, size_t size) { // * * * * * * * * * * * * * * * * * * * * * * * * // Test cases for Bubble Sort -FOSSIL_TEST(bubble_sort_case_1) { +FOSSIL_TEST_CASE(bubble_sort_case_1) { // Test case 1 int data[] = {5, 1, 4, 2, 8}; size_t size = sizeof(data) / sizeof(data[0]); @@ -83,7 +83,7 @@ FOSSIL_TEST(bubble_sort_case_1) { TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } -FOSSIL_TEST(bubble_sort_case_2) { +FOSSIL_TEST_CASE(bubble_sort_case_2) { // Test case 2 int data[] = {9, 6, 7, 3, 1}; size_t size = sizeof(data) / sizeof(data[0]); @@ -92,7 +92,7 @@ FOSSIL_TEST(bubble_sort_case_2) { TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } -FOSSIL_TEST(bubble_sort_case_3) { +FOSSIL_TEST_CASE(bubble_sort_case_3) { // Test case 3 int data[] = {8, 2, 4, 1, 7}; size_t size = sizeof(data) / sizeof(data[0]); @@ -102,7 +102,7 @@ FOSSIL_TEST(bubble_sort_case_3) { } // Test cases for Insertion Sort -FOSSIL_TEST(insertion_sort_case_1) { +FOSSIL_TEST_CASE(insertion_sort_case_1) { // Test case 1 int data[] = {5, 1, 4, 2, 8, 6, 3, 7}; size_t size = sizeof(data) / sizeof(data[0]); @@ -111,7 +111,7 @@ FOSSIL_TEST(insertion_sort_case_1) { TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } -FOSSIL_TEST(insertion_sort_case_2) { +FOSSIL_TEST_CASE(insertion_sort_case_2) { // Test case 2 int data[] = {9, 6, 7, 3, 1, 5, 2, 4}; size_t size = sizeof(data) / sizeof(data[0]); @@ -120,7 +120,7 @@ FOSSIL_TEST(insertion_sort_case_2) { TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } -FOSSIL_TEST(insertion_sort_case_3) { +FOSSIL_TEST_CASE(insertion_sort_case_3) { // Test case 3 int data[] = {8, 2, 4, 1, 7, 5, 9, 3}; size_t size = sizeof(data) / sizeof(data[0]); @@ -130,7 +130,7 @@ FOSSIL_TEST(insertion_sort_case_3) { } // Test cases for Selection Sort -FOSSIL_TEST(selection_sort_case_1) { +FOSSIL_TEST_CASE(selection_sort_case_1) { // Test case 1 int data[] = {5, 1, 4, 2, 8, 6, 3, 7, 9}; size_t size = sizeof(data) / sizeof(data[0]); @@ -139,7 +139,7 @@ FOSSIL_TEST(selection_sort_case_1) { TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } -FOSSIL_TEST(selection_sort_case_2) { +FOSSIL_TEST_CASE(selection_sort_case_2) { // Test case 2 int data[] = {9, 6, 7, 3, 1, 5, 2, 4, 8}; size_t size = sizeof(data) / sizeof(data[0]); @@ -148,7 +148,7 @@ FOSSIL_TEST(selection_sort_case_2) { TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); } -FOSSIL_TEST(selection_sort_case_3) { +FOSSIL_TEST_CASE(selection_sort_case_3) { // Test case 3 int data[] = {8, 2, 4, 1, 7, 5, 9, 3, 6}; size_t size = sizeof(data) / sizeof(data[0]); @@ -158,7 +158,7 @@ FOSSIL_TEST(selection_sort_case_3) { } // Test Case for Bubble Sort with Small Input -FOSSIL_TEST(benchmark_bubble_sort_small) { +FOSSIL_TEST_CASE(benchmark_bubble_sort_small) { const int size = 100; int arr[size]; for (int i = 0; i < size; ++i) { @@ -178,7 +178,7 @@ FOSSIL_TEST(benchmark_bubble_sort_small) { } // Test Case for Bubble Sort with Medium Input -FOSSIL_TEST(benchmark_bubble_sort_medium) { +FOSSIL_TEST_CASE(benchmark_bubble_sort_medium) { const int size = 1000; int arr[size]; for (int i = 0; i < size; ++i) { @@ -198,7 +198,7 @@ FOSSIL_TEST(benchmark_bubble_sort_medium) { } // Test Case for Bubble Sort with Large Input -FOSSIL_TEST(benchmark_bubble_sort_large) { +FOSSIL_TEST_CASE(benchmark_bubble_sort_large) { const int size = 10000; int arr[size]; for (int i = 0; i < size; ++i) { diff --git a/code/tests/test_mocks.c b/code/tests/test_mocks.c index 237b3081..b813742c 100644 --- a/code/tests/test_mocks.c +++ b/code/tests/test_mocks.c @@ -12,7 +12,7 @@ * Copyright (C) 2024 Fossil Logic. All rights reserved. * ----------------------------------------------------------------------------- */ -#include // basic test tools +#include // basic test tools #include // library under test // * * * * * * * * * * * * * * * * * * * * * * * * @@ -33,7 +33,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * // Test Case for Mocking a Function -FOSSIL_TEST(mock_function_test) { +FOSSIL_TEST_CASE(mock_function_test) { MockCallList mock; MOCK_INIT(mock); diff --git a/code/tests/test_sample.c b/code/tests/test_sample.c new file mode 100644 index 00000000..699211cf --- /dev/null +++ b/code/tests/test_sample.c @@ -0,0 +1,54 @@ +/* + * ----------------------------------------------------------------------------- + * Project: Fossil Logic + * + * This file is part of the Fossil Logic project, which aims to develop high- + * performance, cross-platform applications and libraries. The code contained + * herein is subject to the terms and conditions defined in the project license. + * + * Author: Michael Gene Brockus (Dreamer) + * Date: 07/01/2024 + * + * Copyright (C) 2024 Fossil Logic. All rights reserved. + * ----------------------------------------------------------------------------- + */ + +#include "fossil/test/framework.h" + +// Test data structure for a sample test +FOSSIL_TEST_DATA(SampleTestData) { + int input; + int expected_output; +} SampleTestData; + +// Setup function for the test suite +FOSSIL_SETUP(sample_suite) { + // Setup code here +} + +// Teardown function for the test suite +FOSSIL_TEARDOWN(sample_suite) { + // Teardown code here +} + +// Define the test suite and add test cases +FOSSIL_TEST_SUITE(sample_suite); + +// A simple test case to check if input + 1 equals expected_output +FOSSIL_TEST_CASE(test_input_increment) { + SampleTestData data = { .input = 5, .expected_output = 6 }; + + int actual_output = data.input + 1; + + FOSSIL_TEST_ASSUME(actual_output == data.expected_output, "Increment test failed"); +} + +// A simple test case to check if input - 1 equals expected_output +FOSSIL_TEST_CASE(test_input_decrement) { + SampleTestData data = { .input = 5, .expected_output = 4 }; + + int actual_output = data.input - 1; + + FOSSIL_TEST_ASSUME(actual_output == data.expected_output, "Decrement test failed"); +} + diff --git a/code/tests/test_tags.c b/code/tests/test_tags.c index a29fbd00..8410628f 100644 --- a/code/tests/test_tags.c +++ b/code/tests/test_tags.c @@ -12,7 +12,7 @@ * Copyright (C) 2024 Fossil Logic. All rights reserved. * ----------------------------------------------------------------------------- */ -#include +#include // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Utilites @@ -31,52 +31,52 @@ // as samples for library usage. // * * * * * * * * * * * * * * * * * * * * * * * * -FOSSIL_TEST(testing_slow_tags) { +FOSSIL_TEST_CASE(testing_slow_tags) { int x = 42; int y = 20; // Test cases - TEST_ASSERT(x == 42, "Should have passed the test case"); - TEST_ASSERT(y == 20, "Should have passed the test case"); - TEST_ASSERT(x != y, "Should have passed the test case"); - TEST_ASSERT(y < x, "Should have passed the test case"); - TEST_ASSERT(y <= x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(x != y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y < x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y <= x, "Should have passed the test case"); } // end case -FOSSIL_TEST(testing_fast_tags) { +FOSSIL_TEST_CASE(testing_fast_tags) { int x = 42; int y = 20; // Test cases - TEST_ASSERT(x == 42, "Should have passed the test case"); - TEST_ASSERT(y == 20, "Should have passed the test case"); - TEST_ASSERT(x != y, "Should have passed the test case"); - TEST_ASSERT(y < x, "Should have passed the test case"); - TEST_ASSERT(y <= x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(x != y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y < x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y <= x, "Should have passed the test case"); } // end case -FOSSIL_TEST(testing_no_tags) { +FOSSIL_TEST_CASE(testing_no_tags) { int x = 42; int y = 20; // Test cases - TEST_ASSERT(x == 42, "Should have passed the test case"); - TEST_ASSERT(y == 20, "Should have passed the test case"); - TEST_ASSERT(x != y, "Should have passed the test case"); - TEST_ASSERT(y < x, "Should have passed the test case"); - TEST_ASSERT(y <= x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(x != y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y < x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y <= x, "Should have passed the test case"); } // end case -FOSSIL_TEST(testing_fake_tags) { +FOSSIL_TEST_CASE(testing_fake_tags) { int x = 42; int y = 20; // Test cases - TEST_ASSERT(x == 42, "Should have passed the test case"); - TEST_ASSERT(y == 20, "Should have passed the test case"); - TEST_ASSERT(x != y, "Should have passed the test case"); - TEST_ASSERT(y < x, "Should have passed the test case"); - TEST_ASSERT(y <= x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(x != y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y < x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y <= x, "Should have passed the test case"); } // end case // * * * * * * * * * * * * * * * * * * * * * * * * diff --git a/code/tests/test_tdd.c b/code/tests/test_tdd.c index 5200a7ff..efee8e68 100644 --- a/code/tests/test_tdd.c +++ b/code/tests/test_tdd.c @@ -12,13 +12,11 @@ * Copyright (C) 2024 Fossil Logic. All rights reserved. * ----------------------------------------------------------------------------- */ -#include +#include // list of include headers that extends // the framework assertion collection. -#include #include -#include // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Utilites @@ -37,67 +35,67 @@ // as samples for library usage. // * * * * * * * * * * * * * * * * * * * * * * * * -FOSSIL_TEST(xassert_run_of_int) { +FOSSIL_TEST_CASE(xassert_run_of_int) { int x = 42; int y = 20; // Test cases - TEST_ASSERT(x == 42, "Should have passed the test case"); - TEST_ASSERT(y == 20, "Should have passed the test case"); - TEST_ASSERT(x != y, "Should have passed the test case"); - TEST_ASSERT(y < x, "Should have passed the test case"); - TEST_ASSERT(y <= x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(x != y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y < x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y <= x, "Should have passed the test case"); } // end case -FOSSIL_TEST(xassert_run_of_int8) { +FOSSIL_TEST_CASE(xassert_run_of_int8) { int8_t x = 42; int8_t y = 20; // Test cases - TEST_ASSERT((int8_t)x == 42, "Should have passed the test case"); - TEST_ASSERT((int8_t)y == 20, "Should have passed the test case"); - TEST_ASSERT((int8_t)x != (int8_t)y, "Should have passed the test case"); - TEST_ASSERT((int8_t)y < (int8_t)x, "Should have passed the test case"); - TEST_ASSERT((int8_t)y <= (int8_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int8_t)x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int8_t)y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int8_t)x != (int8_t)y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int8_t)y < (int8_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int8_t)y <= (int8_t)x, "Should have passed the test case"); } // end case -FOSSIL_TEST(xassert_run_of_int16) { +FOSSIL_TEST_CASE(xassert_run_of_int16) { int16_t x = 42; int16_t y = 20; // Test cases - TEST_ASSERT((int16_t)x == 42, "Should have passed the test case"); - TEST_ASSERT((int16_t)y == 20, "Should have passed the test case"); - TEST_ASSERT((int16_t)x != (int16_t)y, "Should have passed the test case"); - TEST_ASSERT((int16_t)y < (int16_t)x, "Should have passed the test case"); - TEST_ASSERT((int16_t)y <= (int16_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int16_t)x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int16_t)y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int16_t)x != (int16_t)y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int16_t)y < (int16_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int16_t)y <= (int16_t)x, "Should have passed the test case"); } // end case -FOSSIL_TEST(xassert_run_of_int32) { +FOSSIL_TEST_CASE(xassert_run_of_int32) { int32_t x = 42; int32_t y = 20; // Test cases - TEST_ASSERT((int32_t)x == 42, "Should have passed the test case"); - TEST_ASSERT((int32_t)y == 20, "Should have passed the test case"); - TEST_ASSERT((int32_t)x != (int32_t)y, "Should have passed the test case"); - TEST_ASSERT((int32_t)y < (int32_t)x, "Should have passed the test case"); - TEST_ASSERT((int32_t)y <= (int32_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int32_t)x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int32_t)y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int32_t)x != (int32_t)y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int32_t)y < (int32_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int32_t)y <= (int32_t)x, "Should have passed the test case"); } // end case -FOSSIL_TEST(xassert_run_of_int64) { +FOSSIL_TEST_CASE(xassert_run_of_int64) { int64_t x = 42; int64_t y = 20; // Test cases - TEST_ASSERT((int64_t)x == 42, "Should have passed the test case"); - TEST_ASSERT((int64_t)y == 20, "Should have passed the test case"); - TEST_ASSERT((int64_t)x != (int64_t)y, "Should have passed the test case"); - TEST_ASSERT((int64_t)y < (int64_t)x, "Should have passed the test case"); - TEST_ASSERT((int64_t)y <= (int64_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int64_t)x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int64_t)y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int64_t)x != (int64_t)y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int64_t)y < (int64_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int64_t)y <= (int64_t)x, "Should have passed the test case"); } // end case -FOSSIL_TEST(xassert_run_of_int8_shortcut) { +FOSSIL_TEST_CASE(xassert_run_of_int8_shortcut) { int8_t x = 42; int8_t y = 20; @@ -109,7 +107,7 @@ FOSSIL_TEST(xassert_run_of_int8_shortcut) { ASSERT_ITS_LESS_OR_EQUAL_I8((int8_t)y, (int8_t)x); } // end case -FOSSIL_TEST(xassert_run_of_int16_shortcut) { +FOSSIL_TEST_CASE(xassert_run_of_int16_shortcut) { int16_t x = 42; int16_t y = 20; @@ -121,7 +119,7 @@ FOSSIL_TEST(xassert_run_of_int16_shortcut) { ASSERT_ITS_LESS_OR_EQUAL_I16((int16_t)y, (int16_t)x); } // end case -FOSSIL_TEST(xassert_run_of_int32_shortcut) { +FOSSIL_TEST_CASE(xassert_run_of_int32_shortcut) { int32_t x = 42; int32_t y = 20; @@ -133,7 +131,7 @@ FOSSIL_TEST(xassert_run_of_int32_shortcut) { ASSERT_ITS_LESS_OR_EQUAL_I32((int32_t)y, (int32_t)x); } // end case -FOSSIL_TEST(xassert_run_of_int64_shortcut) { +FOSSIL_TEST_CASE(xassert_run_of_int64_shortcut) { int64_t x = 42; int64_t y = 20; @@ -145,67 +143,67 @@ FOSSIL_TEST(xassert_run_of_int64_shortcut) { ASSERT_ITS_LESS_OR_EQUAL_I64((int64_t)y, (int64_t)x); } // end case -FOSSIL_TEST(xassume_run_of_int) { +FOSSIL_TEST_CASE(xassume_run_of_int) { int x = 42; int y = 20; // Test cases - TEST_ASSUME(x == 42, "Should have passed the test case"); - TEST_ASSUME(y == 20, "Should have passed the test case"); - TEST_ASSUME(x != y, "Should have passed the test case"); - TEST_ASSUME(y < x, "Should have passed the test case"); - TEST_ASSUME(y <= x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(x != y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y < x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y <= x, "Should have passed the test case"); } // end case -FOSSIL_TEST(xassume_run_of_int8) { +FOSSIL_TEST_CASE(xassume_run_of_int8) { int8_t x = 42; int8_t y = 20; // Test cases - TEST_ASSUME((int8_t)x == 42, "Should have passed the test case"); - TEST_ASSUME((int8_t)y == 20, "Should have passed the test case"); - TEST_ASSUME((int8_t)x != (int8_t)y, "Should have passed the test case"); - TEST_ASSUME((int8_t)y < (int8_t)x, "Should have passed the test case"); - TEST_ASSUME((int8_t)y <= (int8_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int8_t)x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int8_t)y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int8_t)x != (int8_t)y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int8_t)y < (int8_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int8_t)y <= (int8_t)x, "Should have passed the test case"); } // end case -FOSSIL_TEST(xassume_run_of_int16) { +FOSSIL_TEST_CASE(xassume_run_of_int16) { int16_t x = 42; int16_t y = 20; // Test cases - TEST_ASSUME((int16_t)x == 42, "Should have passed the test case"); - TEST_ASSUME((int16_t)y == 20, "Should have passed the test case"); - TEST_ASSUME((int16_t)x != (int16_t)y, "Should have passed the test case"); - TEST_ASSUME((int16_t)y < (int16_t)x, "Should have passed the test case"); - TEST_ASSUME((int16_t)y <= (int16_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int16_t)x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int16_t)y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int16_t)x != (int16_t)y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int16_t)y < (int16_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int16_t)y <= (int16_t)x, "Should have passed the test case"); } // end case -FOSSIL_TEST(xassume_run_of_int32) { +FOSSIL_TEST_CASE(xassume_run_of_int32) { int32_t x = 42; int32_t y = 20; // Test cases - TEST_ASSUME((int32_t)x == 42, "Should have passed the test case"); - TEST_ASSUME((int32_t)y == 20, "Should have passed the test case"); - TEST_ASSUME((int32_t)x != (int32_t)y, "Should have passed the test case"); - TEST_ASSUME((int32_t)y < (int32_t)x, "Should have passed the test case"); - TEST_ASSUME((int32_t)y <= (int32_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int32_t)x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int32_t)y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int32_t)x != (int32_t)y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int32_t)y < (int32_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int32_t)y <= (int32_t)x, "Should have passed the test case"); } // end case -FOSSIL_TEST(xassume_run_of_int64) { +FOSSIL_TEST_CASE(xassume_run_of_int64) { int64_t x = 42; int64_t y = 20; // Test cases - TEST_ASSUME((int64_t)x == 42, "Should have passed the test case"); - TEST_ASSUME((int64_t)y == 20, "Should have passed the test case"); - TEST_ASSUME((int64_t)x != (int64_t)y, "Should have passed the test case"); - TEST_ASSUME((int64_t)y < (int64_t)x, "Should have passed the test case"); - TEST_ASSUME((int64_t)y <= (int64_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int64_t)x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int64_t)y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int64_t)x != (int64_t)y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int64_t)y < (int64_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int64_t)y <= (int64_t)x, "Should have passed the test case"); } // end case -FOSSIL_TEST(xassume_run_of_int8_shortcut) { +FOSSIL_TEST_CASE(xassume_run_of_int8_shortcut) { int8_t x = 42; int8_t y = 20; @@ -217,7 +215,7 @@ FOSSIL_TEST(xassume_run_of_int8_shortcut) { ASSUME_ITS_LESS_OR_EQUAL_I8((int8_t)y, (int8_t)x); } // end case -FOSSIL_TEST(xassume_run_of_int16_shortcut) { +FOSSIL_TEST_CASE(xassume_run_of_int16_shortcut) { int16_t x = 42; int16_t y = 20; @@ -229,7 +227,7 @@ FOSSIL_TEST(xassume_run_of_int16_shortcut) { ASSUME_ITS_LESS_OR_EQUAL_I16((int16_t)y, (int16_t)x); } // end case -FOSSIL_TEST(xassume_run_of_int32_shortcut) { +FOSSIL_TEST_CASE(xassume_run_of_int32_shortcut) { int32_t x = 42; int32_t y = 20; @@ -241,7 +239,7 @@ FOSSIL_TEST(xassume_run_of_int32_shortcut) { ASSUME_ITS_LESS_OR_EQUAL_I32((int32_t)y, (int32_t)x); } // end case -FOSSIL_TEST(xassume_run_of_int64_shortcut) { +FOSSIL_TEST_CASE(xassume_run_of_int64_shortcut) { int64_t x = 42; int64_t y = 20; @@ -253,67 +251,67 @@ FOSSIL_TEST(xassume_run_of_int64_shortcut) { ASSUME_ITS_LESS_OR_EQUAL_I64((int64_t)y, (int64_t)x); } // end case -FOSSIL_TEST(xexpect_run_of_int) { +FOSSIL_TEST_CASE(xexpect_run_of_int) { int x = 42; int y = 20; // Test cases - TEST_EXPECT(x == 42, "Should have passed the test case"); - TEST_EXPECT(y == 20, "Should have passed the test case"); - TEST_EXPECT(x != y, "Should have passed the test case"); - TEST_EXPECT(y < x, "Should have passed the test case"); - TEST_EXPECT(y <= x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(x != y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y < x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME(y <= x, "Should have passed the test case"); } // end case -FOSSIL_TEST(xexpect_run_of_int8) { +FOSSIL_TEST_CASE(xexpect_run_of_int8) { int8_t x = 42; int8_t y = 20; // Test cases - TEST_EXPECT((int8_t)x == 42, "Should have passed the test case"); - TEST_EXPECT((int8_t)y == 20, "Should have passed the test case"); - TEST_EXPECT((int8_t)x != (int8_t)y, "Should have passed the test case"); - TEST_EXPECT((int8_t)y < (int8_t)x, "Should have passed the test case"); - TEST_EXPECT((int8_t)y <= (int8_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int8_t)x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int8_t)y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int8_t)x != (int8_t)y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int8_t)y < (int8_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int8_t)y <= (int8_t)x, "Should have passed the test case"); } // end case -FOSSIL_TEST(xexpect_run_of_int16) { +FOSSIL_TEST_CASE(xexpect_run_of_int16) { int16_t x = 42; int16_t y = 20; // Test cases - TEST_EXPECT((int16_t)x == 42, "Should have passed the test case"); - TEST_EXPECT((int16_t)y == 20, "Should have passed the test case"); - TEST_EXPECT((int16_t)x != (int16_t)y, "Should have passed the test case"); - TEST_EXPECT((int16_t)y < (int16_t)x, "Should have passed the test case"); - TEST_EXPECT((int16_t)y <= (int16_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int16_t)x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int16_t)y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int16_t)x != (int16_t)y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int16_t)y < (int16_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int16_t)y <= (int16_t)x, "Should have passed the test case"); } // end case -FOSSIL_TEST(xexpect_run_of_int32) { +FOSSIL_TEST_CASE(xexpect_run_of_int32) { int32_t x = 42; int32_t y = 20; // Test cases - TEST_EXPECT((int32_t)x == 42, "Should have passed the test case"); - TEST_EXPECT((int32_t)y == 20, "Should have passed the test case"); - TEST_EXPECT((int32_t)x != (int32_t)y, "Should have passed the test case"); - TEST_EXPECT((int32_t)y < (int32_t)x, "Should have passed the test case"); - TEST_EXPECT((int32_t)y <= (int32_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int32_t)x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int32_t)y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int32_t)x != (int32_t)y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int32_t)y < (int32_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int32_t)y <= (int32_t)x, "Should have passed the test case"); } // end case -FOSSIL_TEST(xexpect_run_of_int64) { +FOSSIL_TEST_CASE(xexpect_run_of_int64) { int64_t x = 42; int64_t y = 20; // Test cases - TEST_EXPECT((int64_t)x == 42, "Should have passed the test case"); - TEST_EXPECT((int64_t)y == 20, "Should have passed the test case"); - TEST_EXPECT((int64_t)x != (int64_t)y, "Should have passed the test case"); - TEST_EXPECT((int64_t)y < (int64_t)x, "Should have passed the test case"); - TEST_EXPECT((int64_t)y <= (int64_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int64_t)x == 42, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int64_t)y == 20, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int64_t)x != (int64_t)y, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int64_t)y < (int64_t)x, "Should have passed the test case"); + FOSSIL_TEST_ASSUME((int64_t)y <= (int64_t)x, "Should have passed the test case"); } // end case -FOSSIL_TEST(xexpect_run_of_int8_shortcut) { +FOSSIL_TEST_CASE(xexpect_run_of_int8_shortcut) { int8_t x = 42; int8_t y = 20; @@ -325,7 +323,7 @@ FOSSIL_TEST(xexpect_run_of_int8_shortcut) { EXPECT_ITS_LESS_OR_EQUAL_I8((int8_t)y, (int8_t)x); } // end case -FOSSIL_TEST(xexpect_run_of_int16_shortcut) { +FOSSIL_TEST_CASE(xexpect_run_of_int16_shortcut) { int16_t x = 42; int16_t y = 20; @@ -337,7 +335,7 @@ FOSSIL_TEST(xexpect_run_of_int16_shortcut) { EXPECT_ITS_LESS_OR_EQUAL_I16((int16_t)y, (int16_t)x); } // end case -FOSSIL_TEST(xexpect_run_of_int32_shortcut) { +FOSSIL_TEST_CASE(xexpect_run_of_int32_shortcut) { int32_t x = 42; int32_t y = 20; @@ -349,7 +347,7 @@ FOSSIL_TEST(xexpect_run_of_int32_shortcut) { EXPECT_ITS_LESS_OR_EQUAL_I32((int32_t)y, (int32_t)x); } // end case -FOSSIL_TEST(xexpect_run_of_int64_shortcut) { +FOSSIL_TEST_CASE(xexpect_run_of_int64_shortcut) { int64_t x = 42; int64_t y = 20; diff --git a/code/tests/test_xfixture.c b/code/tests/test_xfixture.c deleted file mode 100644 index 1430a5bf..00000000 --- a/code/tests/test_xfixture.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#include - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Utilites -// * * * * * * * * * * * * * * * * * * * * * * * * -// Setup steps for things like test fixtures and -// mock objects are set here. -// * * * * * * * * * * * * * * * * * * * * * * * * - -FOSSIL_TEST_DATA(sample_data) { - int x; - int y; -} sample_data; - -// Fixture setup and teardown procedures -FOSSIL_FIXTURE(sample_fixture); - -FOSSIL_SETUP(sample_fixture) { - sample_data.x = 42; - sample_data.y = 20; -} // end of setup - -FOSSIL_TEARDOWN(sample_fixture) { - // Teardown code goes here -} // end of teardown - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Cases -// * * * * * * * * * * * * * * * * * * * * * * * * -// The test cases below are provided as samples, inspired -// by the Meson build system's approach of using test cases -// as samples for library usage. -// * * * * * * * * * * * * * * * * * * * * * * * * - -FOSSIL_TEST(xassert_with_fixture_run_of_int) { - // Test cases - TEST_ASSERT(sample_data.x == 42, "Should have passed the test case"); - TEST_ASSERT(sample_data.y == 20, "Should have passed the test case"); - TEST_ASSERT(sample_data.x != sample_data.y, "Should have passed the test case"); - TEST_ASSERT(sample_data.y < sample_data.x, "Should have passed the test case"); - TEST_ASSERT(sample_data.y <= sample_data.x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST(xassert_with_fixture_run_of_int8) { - TEST_ASSERT((int8_t)sample_data.x == 42, "Should have passed the test case"); - TEST_ASSERT((int8_t)sample_data.y == 20, "Should have passed the test case"); - TEST_ASSERT((int8_t)sample_data.x != (int8_t)sample_data.y, "Should have passed the test case"); - TEST_ASSERT((int8_t)sample_data.y < (int8_t)sample_data.x, "Should have passed the test case"); - TEST_ASSERT((int8_t)sample_data.y <= (int8_t)sample_data.x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST(xassert_with_fixture_run_of_int16) { - TEST_ASSERT((int16_t)sample_data.x == 42, "Should have passed the test case"); - TEST_ASSERT((int16_t)sample_data.y == 20, "Should have passed the test case"); - TEST_ASSERT((int16_t)sample_data.x != (int16_t)sample_data.y, "Should have passed the test case"); - TEST_ASSERT((int16_t)sample_data.y < (int16_t)sample_data.x, "Should have passed the test case"); - TEST_ASSERT((int16_t)sample_data.y <= (int16_t)sample_data.x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST(xassert_with_fixture_run_of_int32) { - TEST_ASSERT((int32_t)sample_data.x == 42, "Should have passed the test case"); - TEST_ASSERT((int32_t)sample_data.y == 20, "Should have passed the test case"); - TEST_ASSERT((int32_t)sample_data.x != (int32_t)sample_data.y, "Should have passed the test case"); - TEST_ASSERT((int32_t)sample_data.y < (int32_t)sample_data.x, "Should have passed the test case"); - TEST_ASSERT((int32_t)sample_data.y <= (int32_t)sample_data.x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST(xassert_with_fixture_run_of_int64) { - TEST_ASSERT((int64_t)sample_data.x == 42, "Should have passed the test case"); - TEST_ASSERT((int64_t)sample_data.y == 20, "Should have passed the test case"); - TEST_ASSERT((int64_t)sample_data.x != (int64_t)sample_data.y, "Should have passed the test case"); - TEST_ASSERT((int64_t)sample_data.y < (int64_t)sample_data.x, "Should have passed the test case"); - TEST_ASSERT((int64_t)sample_data.y <= (int64_t)sample_data.x, "Should have passed the test case"); -} // end case - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Pool -// * * * * * * * * * * * * * * * * * * * * * * * * -FOSSIL_TEST_GROUP(fixture_test_group) { - ADD_TESTF(xassert_with_fixture_run_of_int, sample_fixture); - ADD_TESTF(xassert_with_fixture_run_of_int8, sample_fixture); - ADD_TESTF(xassert_with_fixture_run_of_int16, sample_fixture); - ADD_TESTF(xassert_with_fixture_run_of_int32, sample_fixture); - ADD_TESTF(xassert_with_fixture_run_of_int64, sample_fixture); -} // end of group diff --git a/code/tests/test_xsoneros.c b/code/tests/test_xsoneros.c deleted file mode 100644 index 1b44e0e8..00000000 --- a/code/tests/test_xsoneros.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#include - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Utilites -// * * * * * * * * * * * * * * * * * * * * * * * * -// Setup steps for things like test fixtures and -// mock objects are set here. -// * * * * * * * * * * * * * * * * * * * * * * * * - -FOSSIL_TEST_DATA(sample_block) { - int x; - int y; -} sample_block; - -// Fixture setup and teardown procedures -FOSSIL_FEATURE(sample_feature); - -FOSSIL_SETUP(sample_feature) { - sample_block.x = 42; - sample_block.y = 20; -} // end of setup - -FOSSIL_TEARDOWN(sample_feature) { - // Teardown code goes here -} // end of teardown - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Cases -// * * * * * * * * * * * * * * * * * * * * * * * * -// The test cases below are provided as samples, inspired -// by the Meson build system's approach of using test cases -// as samples for library usage. -// * * * * * * * * * * * * * * * * * * * * * * * * - -FOSSIL_SONERO(xbdd_logic_within_feature_test) { - GIVEN("a valid statement is passed") { - // Set up the context - bool givenExecuted = true; - - WHEN("a statement is true") { - // Perform the login action - bool whenExecuted = true; - - THEN("we validate everything was worked") { - // Check the expected outcome - bool thenExecuted = true; - - TEST_EXPECT(givenExecuted, "Given statement should have executed"); - TEST_EXPECT(whenExecuted, "When statement should have executed"); - TEST_EXPECT(thenExecuted, "Then statement should have executed"); - } - } - } -} // end of case - -FOSSIL_SONERO(xbdd_user_account_within_feature) { - GIVEN("a user's account with sufficient balance") { - // Set up the context - float accountBalance = 500.0; - float withdrawalAmount = 200.0; - - WHEN("the user requests a withdrawal of $200") { - // Perform the withdrawal action - if (accountBalance >= withdrawalAmount) { - accountBalance -= withdrawalAmount; - } // end if - THEN("the withdrawal amount should be deducted from the account balance") { - // Check the expected outcome - - // Simulate the scenario - float compareBalance = 500.0; - TEST_EXPECT(accountBalance == (compareBalance - withdrawalAmount), "Account balance should have been deducted by $200"); - } - } - } -} // end of case - -FOSSIL_SONERO(xbdd_empty_cart_within_feature) { - GIVEN("a user with an empty shopping cart") { - // Set up the context - int cartItemCount = 0; - - WHEN("the user adds a product to the cart") { - // Perform the action of adding a product - - THEN("the cart item count should increase by 1") { - // Check the expected outcome - cartItemCount++; - - TEST_EXPECT(cartItemCount == 1, "Cart item count should have increased by 1"); - } - } - } -} // end of case - -FOSSIL_SONERO(xbdd_valid_login_within_feature) { - GIVEN("a registered user with valid credentials") { - // Set up the context - const char* validUsername = "user123"; - const char* validPassword = "pass456"; - - WHEN("the user provides correct username and password") { - // Perform the action of user login - const char* inputUsername = "user123"; - const char* inputPassword = "pass456"; - - THEN("the login should be successful") { - // Check the expected outcome - // Simulate login validation - TEST_EXPECT(strcmp(inputUsername, validUsername) == 0, "Username should match"); - TEST_EXPECT(strcmp(inputPassword, validPassword) == 0, "Password should match"); - } - } - - WHEN("the user provides incorrect password") { - // Perform the action of user login - const char* inputUsername = "user123"; - const char* inputPassword = "wrongpass"; - - THEN("the login should fail with an error message") { - // Check the expected outcome - // Simulate login validation - TEST_EXPECT(strcmp(inputUsername, validUsername) == 0, "Username should match"); - TEST_EXPECT(strcmp(inputPassword, validPassword) != 0, "Password should not match"); - } - } - } -} // end of case - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Pool -// * * * * * * * * * * * * * * * * * * * * * * * * -FOSSIL_TEST_GROUP(feature_test_group) { - ADD_TESTF(xbdd_logic_within_feature_test, sample_feature); - ADD_TESTF(xbdd_user_account_within_feature, sample_feature); - ADD_TESTF(xbdd_empty_cart_within_feature, sample_feature); - ADD_TESTF(xbdd_valid_login_within_feature, sample_feature); -} // end of group diff --git a/code/tests/unit_runner.c b/code/tests/unit_runner.c new file mode 100644 index 00000000..a39489af --- /dev/null +++ b/code/tests/unit_runner.c @@ -0,0 +1,17 @@ +/* + * ----------------------------------------------------------------------------- + * Project: Fossil Logic + * + * This file is part of the Fossil Logic project, which aims to develop high- + * performance, cross-platform applications and libraries. The code contained + * herein is subject to the terms and conditions defined in the project license. + * + * Author: Michael Gene Brockus (Dreamer) + * Date: 07/01/2024 + * + * Copyright (C) 2024 Fossil Logic. All rights reserved. + * ----------------------------------------------------------------------------- + */ +#include + +FOSSIL_TEST_MAIN() From 9569d2c47ff03fc3dc5d5c9183f11f7fd4a9c85e Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Sun, 3 Nov 2024 16:26:10 -0600 Subject: [PATCH 08/40] change null types --- code/logic/fossil/test/assume.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/logic/fossil/test/assume.h b/code/logic/fossil/test/assume.h index 8095bd65..060c55b5 100644 --- a/code/logic/fossil/test/assume.h +++ b/code/logic/fossil/test/assume.h @@ -645,10 +645,10 @@ extern "C" { // ITS set #define ASSUME_ITS_CNULL(actual) \ - FOSSIL_TEST_ASSUME((actual) == xnull, "Expected " #actual " to be xnull") + FOSSIL_TEST_ASSUME((actual) == NULL, "Expected " #actual " to be NULL") #define ASSUME_NOT_CNULL(actual) \ - FOSSIL_TEST_ASSUME((actual) != xnull, "Expected " #actual " to not be xnull") + FOSSIL_TEST_ASSUME((actual) != NULL, "Expected " #actual " to not be NULL") // General pointer ASSUMEions (_PTR) From f3e4f731bbec0115e20af4f4fd543dfb8e3c541b Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Sun, 3 Nov 2024 16:26:27 -0600 Subject: [PATCH 09/40] move dir varible --- code/logic/fossil/meson.build | 1 - code/logic/meson.build | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 code/logic/fossil/meson.build diff --git a/code/logic/fossil/meson.build b/code/logic/fossil/meson.build deleted file mode 100644 index ff5b77c4..00000000 --- a/code/logic/fossil/meson.build +++ /dev/null @@ -1 +0,0 @@ -dir = include_directories('.') diff --git a/code/logic/meson.build b/code/logic/meson.build index 3e66dc73..8e23338e 100644 --- a/code/logic/meson.build +++ b/code/logic/meson.build @@ -1,3 +1,5 @@ +dir = include_directories('.') + test_code = ['mockup.c', 'unittest.c', 'benchmark.c'] fossil_test_lib = library('fossil-test', From 39e10d6734f8e31a635ab17af17b77c87efe51b3 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Sun, 3 Nov 2024 16:26:42 -0600 Subject: [PATCH 10/40] change null types --- code/logic/mockup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/logic/mockup.c b/code/logic/mockup.c index d1be2e89..f9761a48 100644 --- a/code/logic/mockup.c +++ b/code/logic/mockup.c @@ -17,8 +17,8 @@ #include "fossil/test/mockup.h" void fossil_mock_init(MockCallList *list) { - list->head = xnullptr; - list->tail = xnullptr; + list->head = NULL; + list->tail = NULL; list->size = 0; } @@ -44,7 +44,7 @@ void fossil_mock_add_call(MockCallList *list, const char *function_name, char ** call->arguments[i] = _custom_fossil_test_strdup(arguments[i]); } call->num_args = num_args; - call->next = xnullptr; + call->next = NULL; if (list->tail) { list->tail->next = call; From fc740eafa588a5da48fb0f6f4fa5775ef2591114 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Sun, 3 Nov 2024 16:27:05 -0600 Subject: [PATCH 11/40] prototyping a new test runner --- code/tests/unit_runner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/tests/unit_runner.c b/code/tests/unit_runner.c index a39489af..ee2d1733 100644 --- a/code/tests/unit_runner.c +++ b/code/tests/unit_runner.c @@ -12,6 +12,6 @@ * Copyright (C) 2024 Fossil Logic. All rights reserved. * ----------------------------------------------------------------------------- */ -#include +#include "fossil/test/framework.h" FOSSIL_TEST_MAIN() From 531db42c607a9a0d316b8f10732e070ce871bcad Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 4 Nov 2024 10:16:27 -0600 Subject: [PATCH 12/40] add comments to all assumtions --- code/logic/fossil/test/assume.h | 1528 +++++++++++++++++++++++++++++-- 1 file changed, 1474 insertions(+), 54 deletions(-) diff --git a/code/logic/fossil/test/assume.h b/code/logic/fossil/test/assume.h index 060c55b5..84765f2e 100644 --- a/code/logic/fossil/test/assume.h +++ b/code/logic/fossil/test/assume.h @@ -35,17 +35,35 @@ extern "C" { // // ************************************************** -// Boolean ITS ASSUMEions +/** + * @brief Assumes that the given boolean expression is true. + * + * @param actual The boolean expression to be evaluated. + */ #define ASSUME_ITS_TRUE(actual) \ FOSSIL_TEST_ASSUME((actual), "Expected " #actual " to be true") +/** + * @brief Assumes that the given boolean expression is false. + * + * @param actual The boolean expression to be evaluated. + */ #define ASSUME_ITS_FALSE(actual) \ FOSSIL_TEST_ASSUME(!(actual), "Expected " #actual " to be false") -// Boolean NOT ASSUMEions +/** + * @brief Assumes that the given boolean expression is not true. + * + * @param actual The boolean expression to be evaluated. + */ #define ASSUME_NOT_TRUE(actual) \ FOSSIL_TEST_ASSUME(!(actual), "Expected " #actual " to not be true") +/** + * @brief Assumes that the given boolean expression is not false. + * + * @param actual The boolean expression to be evaluated. + */ #define ASSUME_NOT_FALSE(actual) \ FOSSIL_TEST_ASSUME((actual), "Expected " #actual " to not be false") @@ -56,78 +74,222 @@ extern "C" { // ************************************************** // Double equality check with tolerance +/** + * @brief Assumes that the given double values are equal within a specified tolerance. + * + * @param actual The actual double value. + * @param expected The expected double value. + * @param tol The tolerance within which the values should be considered equal. + */ #define ASSUME_ITS_EQUAL_F64(actual, expected, tol) \ FOSSIL_TEST_ASSUME(fabs((actual) - (expected)) <= (tol), "Expected " #actual " to be equal to " #expected " within tolerance " #tol) +/** + * @brief Assumes that the given double value is less than the expected value. + * + * @param actual The actual double value. + * @param expected The expected double value. + */ #define ASSUME_ITS_LESS_THAN_F64(actual, expected) \ FOSSIL_TEST_ASSUME((actual) < (expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given double value is more than the expected value. + * + * @param actual The actual double value. + * @param expected The expected double value. + */ #define ASSUME_ITS_MORE_THAN_F64(actual, expected) \ FOSSIL_TEST_ASSUME((actual) > (expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given double value is less than or equal to the expected value. + * + * @param actual The actual double value. + * @param expected The expected double value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_F64(actual, expected) \ FOSSIL_TEST_ASSUME((actual) <= (expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given double value is more than or equal to the expected value. + * + * @param actual The actual double value. + * @param expected The expected double value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_F64(actual, expected) \ FOSSIL_TEST_ASSUME((actual) >= (expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given double values are not equal within a specified tolerance. + * + * @param actual The actual double value. + * @param expected The expected double value. + * @param tol The tolerance within which the values should not be considered equal. + */ #define ASSUME_NOT_EQUAL_F64(actual, expected, tol) \ FOSSIL_TEST_ASSUME(fabs((actual) - (expected)) > (tol), "Expected " #actual " to not be equal to " #expected " within tolerance " #tol) +/** + * @brief Assumes that the given double value is not less than the expected value. + * + * @param actual The actual double value. + * @param expected The expected double value. + */ #define ASSUME_NOT_LESS_THAN_F64(actual, expected) \ FOSSIL_TEST_ASSUME((actual) >= (expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given double value is not more than the expected value. + * + * @param actual The actual double value. + * @param expected The expected double value. + */ #define ASSUME_NOT_MORE_THAN_F64(actual, expected) \ FOSSIL_TEST_ASSUME((actual) <= (expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given double value is not less than or equal to the expected value. + * + * @param actual The actual double value. + * @param expected The expected double value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_F64(actual, expected) \ FOSSIL_TEST_ASSUME((actual) > (expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given double value is not more than or equal to the expected value. + * + * @param actual The actual double value. + * @param expected The expected double value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_F64(actual, expected) \ FOSSIL_TEST_ASSUME((actual) < (expected), "Expected " #actual " to not be more than or equal to " #expected) // Float equality check with tolerance +/** + * @brief Assumes that the given float values are equal within a specified tolerance. + * + * @param actual The actual float value. + * @param expected The expected float value. + * @param tol The tolerance within which the values should be considered equal. + */ #define ASSUME_ITS_EQUAL_F32(actual, expected, tol) \ FOSSIL_TEST_ASSUME(fabsf((actual) - (expected)) <= (tol), "Expected " #actual " to be equal to " #expected " within tolerance " #tol) +/** + * @brief Assumes that the given float value is less than the expected value. + * + * @param actual The actual float value. + * @param expected The expected float value. + */ #define ASSUME_ITS_LESS_THAN_F32(actual, expected) \ FOSSIL_TEST_ASSUME((actual) < (expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given float value is more than the expected value. + * + * @param actual The actual float value. + * @param expected The expected float value. + */ #define ASSUME_ITS_MORE_THAN_F32(actual, expected) \ FOSSIL_TEST_ASSUME((actual) > (expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given float value is less than or equal to the expected value. + * + * @param actual The actual float value. + * @param expected The expected float value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_F32(actual, expected) \ FOSSIL_TEST_ASSUME((actual) <= (expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given float value is more than or equal to the expected value. + * + * @param actual The actual float value. + * @param expected The expected float value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_F32(actual, expected) \ FOSSIL_TEST_ASSUME((actual) >= (expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given float values are not equal within a specified tolerance. + * + * @param actual The actual float value. + * @param expected The expected float value. + * @param tol The tolerance within which the values should not be considered equal. + */ #define ASSUME_NOT_EQUAL_F32(actual, expected, tol) \ FOSSIL_TEST_ASSUME(fabsf((actual) - (expected)) > (tol), "Expected " #actual " to not be equal to " #expected " within tolerance " #tol) +/** + * @brief Assumes that the given float value is not less than the expected value. + * + * @param actual The actual float value. + * @param expected The expected float value. + */ #define ASSUME_NOT_LESS_THAN_F32(actual, expected) \ FOSSIL_TEST_ASSUME((actual) >= (expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given float value is not more than the expected value. + * + * @param actual The actual float value. + * @param expected The expected float value. + */ #define ASSUME_NOT_MORE_THAN_F32(actual, expected) \ FOSSIL_TEST_ASSUME((actual) <= (expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given float value is not less than or equal to the expected value. + * + * @param actual The actual float value. + * @param expected The expected float value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_F32(actual, expected) \ FOSSIL_TEST_ASSUME((actual) > (expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given float value is not more than or equal to the expected value. + * + * @param actual The actual float value. + * @param expected The expected float value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_F32(actual, expected) \ FOSSIL_TEST_ASSUME((actual) < (expected), "Expected " #actual " to not be more than or equal to " #expected) // Float NaN and Infinity checks +/** + * @brief Assumes that the given float value is NaN (Not a Number). + * + * @param actual The actual float value. + */ #define ASSUME_ITS_NAN_F32(actual) \ FOSSIL_TEST_ASSUME(isnan(actual), "Expected " #actual " to be NaN") +/** + * @brief Assumes that the given float value is infinity. + * + * @param actual The actual float value. + */ #define ASSUME_ITS_INF_F32(actual) \ FOSSIL_TEST_ASSUME(isinf(actual), "Expected " #actual " to be infinity") // Double NaN and Infinity checks +/** + * @brief Assumes that the given double value is NaN (Not a Number). + * + * @param actual The actual double value. + */ #define ASSUME_ITS_NAN_F64(actual) \ FOSSIL_TEST_ASSUME(isnan(actual), "Expected " #actual " to be NaN") +/** + * @brief Assumes that the given double value is infinity. + * + * @param actual The actual double value. + */ #define ASSUME_ITS_INF_F64(actual) \ FOSSIL_TEST_ASSUME(isinf(actual), "Expected " #actual " to be infinity") @@ -137,503 +299,1445 @@ extern "C" { // // ************************************************** -// Octal ASSUMEions - -// O8 ASSUMEions +/** + * @brief Assumes that the given 8-bit octal values are equal. + * + * @param actual The actual 8-bit octal value. + * @param expected The expected 8-bit octal value. + */ #define ASSUME_ITS_EQUAL_O8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) == (uint8_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 8-bit octal value is less than the expected value. + * + * @param actual The actual 8-bit octal value. + * @param expected The expected 8-bit octal value. + */ #define ASSUME_ITS_LESS_THAN_O8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 8-bit octal value is more than the expected value. + * + * @param actual The actual 8-bit octal value. + * @param expected The expected 8-bit octal value. + */ #define ASSUME_ITS_MORE_THAN_O8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 8-bit octal value is less than or equal to the expected value. + * + * @param actual The actual 8-bit octal value. + * @param expected The expected 8-bit octal value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_O8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 8-bit octal value is more than or equal to the expected value. + * + * @param actual The actual 8-bit octal value. + * @param expected The expected 8-bit octal value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_O8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 8-bit octal values are not equal. + * + * @param actual The actual 8-bit octal value. + * @param expected The expected 8-bit octal value. + */ #define ASSUME_NOT_EQUAL_O8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) != (uint8_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 8-bit octal value is not less than the expected value. + * + * @param actual The actual 8-bit octal value. + * @param expected The expected 8-bit octal value. + */ #define ASSUME_NOT_LESS_THAN_O8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 8-bit octal value is not more than the expected value. + * + * @param actual The actual 8-bit octal value. + * @param expected The expected 8-bit octal value. + */ #define ASSUME_NOT_MORE_THAN_O8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 8-bit octal value is not less than or equal to the expected value. + * + * @param actual The actual 8-bit octal value. + * @param expected The expected 8-bit octal value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_O8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 8-bit octal value is not more than or equal to the expected value. + * + * @param actual The actual 8-bit octal value. + * @param expected The expected 8-bit octal value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_O8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) -// O16 ASSUMEions +/** + * @brief Assumes that the given 16-bit octal values are equal. + * + * @param actual The actual 16-bit octal value. + * @param expected The expected 16-bit octal value. + */ #define ASSUME_ITS_EQUAL_O16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) == (uint16_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 16-bit octal value is less than the expected value. + * + * @param actual The actual 16-bit octal value. + * @param expected The expected 16-bit octal value. + */ #define ASSUME_ITS_LESS_THAN_O16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 16-bit octal value is more than the expected value. + * + * @param actual The actual 16-bit octal value. + * @param expected The expected 16-bit octal value. + */ #define ASSUME_ITS_MORE_THAN_O16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 16-bit octal value is less than or equal to the expected value. + * + * @param actual The actual 16-bit octal value. + * @param expected The expected 16-bit octal value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_O16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 16-bit octal value is more than or equal to the expected value. + * + * @param actual The actual 16-bit octal value. + * @param expected The expected 16-bit octal value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_O16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 16-bit octal values are not equal. + * + * @param actual The actual 16-bit octal value. + * @param expected The expected 16-bit octal value. + */ #define ASSUME_NOT_EQUAL_O16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) != (uint16_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 16-bit octal value is not less than the expected value. + * + * @param actual The actual 16-bit octal value. + * @param expected The expected 16-bit octal value. + */ #define ASSUME_NOT_LESS_THAN_O16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 16-bit octal value is not more than the expected value. + * + * @param actual The actual 16-bit octal value. + * @param expected The expected 16-bit octal value. + */ #define ASSUME_NOT_MORE_THAN_O16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 16-bit octal value is not less than or equal to the expected value. + * + * @param actual The actual 16-bit octal value. + * @param expected The expected 16-bit octal value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_O16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 16-bit octal value is not more than or equal to the expected value. + * + * @param actual The actual 16-bit octal value. + * @param expected The expected 16-bit octal value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_O16(actual, expected) \ - FOSSIL_TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + FOSSIL_TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected") -// O32 ASSUMEions +/** + * @brief Assumes that the given 32-bit octal values are equal. + * + * @param actual The actual 32-bit octal value. + * @param expected The expected 32-bit octal value. + */ #define ASSUME_ITS_EQUAL_O32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) == (uint32_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 32-bit octal value is less than the expected value. + * + * @param actual The actual 32-bit octal value. + * @param expected The expected 32-bit octal value. + */ #define ASSUME_ITS_LESS_THAN_O32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 32-bit octal value is more than the expected value. + * + * @param actual The actual 32-bit octal value. + * @param expected The expected 32-bit octal value. + */ #define ASSUME_ITS_MORE_THAN_O32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 32-bit octal value is less than or equal to the expected value. + * + * @param actual The actual 32-bit octal value. + * @param expected The expected 32-bit octal value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_O32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 32-bit octal value is more than or equal to the expected value. + * + * @param actual The actual 32-bit octal value. + * @param expected The expected 32-bit octal value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_O32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 32-bit octal values are not equal. + * + * @param actual The actual 32-bit octal value. + * @param expected The expected 32-bit octal value. + */ #define ASSUME_NOT_EQUAL_O32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) != (uint32_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 32-bit octal value is not less than the expected value. + * + * @param actual The actual 32-bit octal value. + * @param expected The expected 32-bit octal value. + */ #define ASSUME_NOT_LESS_THAN_O32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 32-bit octal value is not more than the expected value. + * + * @param actual The actual 32-bit octal value. + * @param expected The expected 32-bit octal value. + */ #define ASSUME_NOT_MORE_THAN_O32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 32-bit octal value is not less than or equal to the expected value. + * + * @param actual The actual 32-bit octal value. + * @param expected The expected 32-bit octal value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_O32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 32-bit octal value is not more than or equal to the expected value. + * + * @param actual The actual 32-bit octal value. + * @param expected The expected 32-bit octal value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_O32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) -// OI64 ASSUMEions +/** + * @brief Assumes that the given 64-bit octal values are equal. + * + * @param actual The actual 64-bit octal value. + * @param expected The expected 64-bit octal value. + */ #define ASSUME_ITS_EQUAL_O64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) == (uint64_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 64-bit octal value is less than the expected value. + * + * @param actual The actual 64-bit octal value. + * @param expected The expected 64-bit octal value. + */ #define ASSUME_ITS_LESS_THAN_O64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 64-bit octal value is more than the expected value. + * + * @param actual The actual 64-bit octal value. + * @param expected The expected 64-bit octal value. + */ #define ASSUME_ITS_MORE_THAN_O64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 64-bit octal value is less than or equal to the expected value. + * + * @param actual The actual 64-bit octal value. + * @param expected The expected 64-bit octal value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_O64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 64-bit octal value is more than or equal to the expected value. + * + * @param actual The actual 64-bit octal value. + * @param expected The expected 64-bit octal value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_O64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 64-bit octal values are not equal. + * + * @param actual The actual 64-bit octal value. + * @param expected The expected 64-bit octal value. + */ #define ASSUME_NOT_EQUAL_O64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) != (uint64_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 64-bit octal value is not less than the expected value. + * + * @param actual The actual 64-bit octal value. + * @param expected The expected 64-bit octal value. + */ #define ASSUME_NOT_LESS_THAN_O64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 64-bit octal value is not more than the expected value. + * + * @param actual The actual 64-bit octal value. + * @param expected The expected 64-bit octal value. + */ #define ASSUME_NOT_MORE_THAN_O64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 64-bit octal value is not less than or equal to the expected value. + * + * @param actual The actual 64-bit octal value. + * @param expected The expected 64-bit octal value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_O64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 64-bit octal value is not more than or equal to the expected value. + * + * @param actual The actual 64-bit octal value. + * @param expected The expected 64-bit octal value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_O64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) // Hexadecimal ASSUMEions -// H8 ASSUMEions +/** + * @brief Assumes that the given 8-bit hexadecimal values are equal. + * + * @param actual The actual 8-bit hexadecimal value. + * @param expected The expected 8-bit hexadecimal value. + */ #define ASSUME_ITS_EQUAL_H8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) == (uint8_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 8-bit hexadecimal value is less than the expected value. + * + * @param actual The actual 8-bit hexadecimal value. + * @param expected The expected 8-bit hexadecimal value. + */ #define ASSUME_ITS_LESS_THAN_H8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 8-bit hexadecimal value is more than the expected value. + * + * @param actual The actual 8-bit hexadecimal value. + * @param expected The expected 8-bit hexadecimal value. + */ #define ASSUME_ITS_MORE_THAN_H8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 8-bit hexadecimal value is less than or equal to the expected value. + * + * @param actual The actual 8-bit hexadecimal value. + * @param expected The expected 8-bit hexadecimal value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_H8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 8-bit hexadecimal value is more than or equal to the expected value. + * + * @param actual The actual 8-bit hexadecimal value. + * @param expected The expected 8-bit hexadecimal value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_H8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 8-bit hexadecimal values are not equal. + * + * @param actual The actual 8-bit hexadecimal value. + * @param expected The expected 8-bit hexadecimal value. + */ #define ASSUME_NOT_EQUAL_H8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) != (uint8_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 8-bit hexadecimal value is not less than the expected value. + * + * @param actual The actual 8-bit hexadecimal value. + * @param expected The expected 8-bit hexadecimal value. + */ #define ASSUME_NOT_LESS_THAN_H8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 8-bit hexadecimal value is not more than the expected value. + * + * @param actual The actual 8-bit hexadecimal value. + * @param expected The expected 8-bit hexadecimal value. + */ #define ASSUME_NOT_MORE_THAN_H8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 8-bit hexadecimal value is not less than or equal to the expected value. + * + * @param actual The actual 8-bit hexadecimal value. + * @param expected The expected 8-bit hexadecimal value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_H8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 8-bit hexadecimal value is not more than or equal to the expected value. + * + * @param actual The actual 8-bit hexadecimal value. + * @param expected The expected 8-bit hexadecimal value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_H8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) -// H16 ASSUMEions +/** + * @brief Assumes that the given 16-bit hexadecimal values are equal. + * + * @param actual The actual 16-bit hexadecimal value. + * @param expected The expected 16-bit hexadecimal value. + */ #define ASSUME_ITS_EQUAL_H16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) == (uint16_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 16-bit hexadecimal value is less than the expected value. + * + * @param actual The actual 16-bit hexadecimal value. + * @param expected The expected 16-bit hexadecimal value. + */ #define ASSUME_ITS_LESS_THAN_H16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 16-bit hexadecimal value is more than the expected value. + * + * @param actual The actual 16-bit hexadecimal value. + * @param expected The expected 16-bit hexadecimal value. + */ #define ASSUME_ITS_MORE_THAN_H16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 16-bit hexadecimal value is less than or equal to the expected value. + * + * @param actual The actual 16-bit hexadecimal value. + * @param expected The expected 16-bit hexadecimal value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_H16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 16-bit hexadecimal value is more than or equal to the expected value. + * + * @param actual The actual 16-bit hexadecimal value. + * @param expected The expected 16-bit hexadecimal value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_H16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 16-bit hexadecimal values are not equal. + * + * @param actual The actual 16-bit hexadecimal value. + * @param expected The expected 16-bit hexadecimal value. + */ #define ASSUME_NOT_EQUAL_H16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) != (uint16_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 16-bit hexadecimal value is not less than the expected value. + * + * @param actual The actual 16-bit hexadecimal value. + * @param expected The expected 16-bit hexadecimal value. + */ #define ASSUME_NOT_LESS_THAN_H16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 16-bit hexadecimal value is not more than the expected value. + * + * @param actual The actual 16-bit hexadecimal value. + * @param expected The expected 16-bit hexadecimal value. + */ #define ASSUME_NOT_MORE_THAN_H16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 16-bit hexadecimal value is not less than or equal to the expected value. + * + * @param actual The actual 16-bit hexadecimal value. + * @param expected The expected 16-bit hexadecimal value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_H16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 16-bit hexadecimal value is not more than or equal to the expected value. + * + * @param actual The actual 16-bit hexadecimal value. + * @param expected The expected 16-bit hexadecimal value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_H16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) -// H32 ASSUMEions +/** + * @brief Assumes that the given 32-bit hexadecimal values are equal. + * + * @param actual The actual 32-bit hexadecimal value. + * @param expected The expected 32-bit hexadecimal value. + */ #define ASSUME_ITS_EQUAL_H32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) == (uint32_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 32-bit hexadecimal value is less than the expected value. + * + * @param actual The actual 32-bit hexadecimal value. + * @param expected The expected 32-bit hexadecimal value. + */ #define ASSUME_ITS_LESS_THAN_H32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 32-bit hexadecimal value is more than the expected value. + * + * @param actual The actual 32-bit hexadecimal value. + * @param expected The expected 32-bit hexadecimal value. + */ #define ASSUME_ITS_MORE_THAN_H32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 32-bit hexadecimal value is less than or equal to the expected value. + * + * @param actual The actual 32-bit hexadecimal value. + * @param expected The expected 32-bit hexadecimal value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_H32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 32-bit hexadecimal value is more than or equal to the expected value. + * + * @param actual The actual 32-bit hexadecimal value. + * @param expected The expected 32-bit hexadecimal value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_H32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 32-bit hexadecimal values are not equal. + * + * @param actual The actual 32-bit hexadecimal value. + * @param expected The expected 32-bit hexadecimal value. + */ #define ASSUME_NOT_EQUAL_H32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) != (uint32_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 32-bit hexadecimal value is not less than the expected value. + * + * @param actual The actual 32-bit hexadecimal value. + * @param expected The expected 32-bit hexadecimal value. + */ #define ASSUME_NOT_LESS_THAN_H32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 32-bit hexadecimal value is not more than the expected value. + * + * @param actual The actual 32-bit hexadecimal value. + * @param expected The expected 32-bit hexadecimal value. + */ #define ASSUME_NOT_MORE_THAN_H32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 32-bit hexadecimal value is not less than or equal to the expected value. + * + * @param actual The actual 32-bit hexadecimal value. + * @param expected The expected 32-bit hexadecimal value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_H32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 32-bit hexadecimal value is not more than or equal to the expected value. + * + * @param actual The actual 32-bit hexadecimal value. + * @param expected The expected 32-bit hexadecimal value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_H32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) -// H64 ASSUMEions +/** + * @brief Assumes that the given 64-bit hexadecimal values are equal. + * + * @param actual The actual 64-bit hexadecimal value. + * @param expected The expected 64-bit hexadecimal value. + */ #define ASSUME_ITS_EQUAL_H64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) == (uint64_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 64-bit hexadecimal value is less than the expected value. + * + * @param actual The actual 64-bit hexadecimal value. + * @param expected The expected 64-bit hexadecimal value. + */ #define ASSUME_ITS_LESS_THAN_H64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 64-bit hexadecimal value is more than the expected value. + * + * @param actual The actual 64-bit hexadecimal value. + * @param expected The expected 64-bit hexadecimal value. + */ #define ASSUME_ITS_MORE_THAN_H64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 64-bit hexadecimal value is less than or equal to the expected value. + * + * @param actual The actual 64-bit hexadecimal value. + * @param expected The expected 64-bit hexadecimal value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_H64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 64-bit hexadecimal value is more than or equal to the expected value. + * + * @param actual The actual 64-bit hexadecimal value. + * @param expected The expected 64-bit hexadecimal value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_H64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 64-bit hexadecimal values are not equal. + * + * @param actual The actual 64-bit hexadecimal value. + * @param expected The expected 64-bit hexadecimal value. + */ #define ASSUME_NOT_EQUAL_H64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) != (uint64_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 64-bit hexadecimal value is not less than the expected value. + * + * @param actual The actual 64-bit hexadecimal value. + * @param expected The expected 64-bit hexadecimal value. + */ #define ASSUME_NOT_LESS_THAN_H64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 64-bit hexadecimal value is not more than the expected value. + * + * @param actual The actual 64-bit hexadecimal value. + * @param expected The expected 64-bit hexadecimal value. + */ #define ASSUME_NOT_MORE_THAN_H64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 64-bit hexadecimal value is not less than or equal to the expected value. + * + * @param actual The actual 64-bit hexadecimal value. + * @param expected The expected 64-bit hexadecimal value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_H64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 64-bit hexadecimal value is not more than or equal to the expected value. + * + * @param actual The actual 64-bit hexadecimal value. + * @param expected The expected 64-bit hexadecimal value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_H64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) -// I8 ASSUMEions +/** + * @brief Assumes that the given 8-bit integer values are equal. + * + * @param actual The actual 8-bit integer value. + * @param expected The expected 8-bit integer value. + */ #define ASSUME_ITS_EQUAL_I8(actual, expected) \ FOSSIL_TEST_ASSUME((int8_t)(actual) == (int8_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 8-bit integer value is less than the expected value. + * + * @param actual The actual 8-bit integer value. + * @param expected The expected 8-bit integer value. + */ #define ASSUME_ITS_LESS_THAN_I8(actual, expected) \ FOSSIL_TEST_ASSUME((int8_t)(actual) < (int8_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 8-bit integer value is more than the expected value. + * + * @param actual The actual 8-bit integer value. + * @param expected The expected 8-bit integer value. + */ #define ASSUME_ITS_MORE_THAN_I8(actual, expected) \ FOSSIL_TEST_ASSUME((int8_t)(actual) > (int8_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 8-bit integer value is less than or equal to the expected value. + * + * @param actual The actual 8-bit integer value. + * @param expected The expected 8-bit integer value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_I8(actual, expected) \ FOSSIL_TEST_ASSUME((int8_t)(actual) <= (int8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 8-bit integer value is more than or equal to the expected value. + * + * @param actual The actual 8-bit integer value. + * @param expected The expected 8-bit integer value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_I8(actual, expected) \ FOSSIL_TEST_ASSUME((int8_t)(actual) >= (int8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 8-bit integer values are not equal. + * + * @param actual The actual 8-bit integer value. + * @param expected The expected 8-bit integer value. + */ #define ASSUME_NOT_EQUAL_I8(actual, expected) \ FOSSIL_TEST_ASSUME((int8_t)(actual) != (int8_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 8-bit integer value is not less than the expected value. + * + * @param actual The actual 8-bit integer value. + * @param expected The expected 8-bit integer value. + */ #define ASSUME_NOT_LESS_THAN_I8(actual, expected) \ FOSSIL_TEST_ASSUME((int8_t)(actual) >= (int8_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 8-bit integer value is not more than the expected value. + * + * @param actual The actual 8-bit integer value. + * @param expected The expected 8-bit integer value. + */ #define ASSUME_NOT_MORE_THAN_I8(actual, expected) \ FOSSIL_TEST_ASSUME((int8_t)(actual) <= (int8_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 8-bit integer value is not less than or equal to the expected value. + * + * @param actual The actual 8-bit integer value. + * @param expected The expected 8-bit integer value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_I8(actual, expected) \ FOSSIL_TEST_ASSUME((int8_t)(actual) > (int8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 8-bit integer value is not more than or equal to the expected value. + * + * @param actual The actual 8-bit integer value. + * @param expected The expected 8-bit integer value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_I8(actual, expected) \ - FOSSIL_TEST_ASSUME((int8_t)(actual) < (int8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + FOSSIL_TEST_ASSUME((int8_t)(actual) < (int8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected") -// I16 ASSUMEions +/** + * @brief Assumes that the given 16-bit integer values are equal. + * + * @param actual The actual 16-bit integer value. + * @param expected The expected 16-bit integer value. + */ #define ASSUME_ITS_EQUAL_I16(actual, expected) \ FOSSIL_TEST_ASSUME((int16_t)(actual) == (int16_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 16-bit integer value is less than the expected value. + * + * @param actual The actual 16-bit integer value. + * @param expected The expected 16-bit integer value. + */ #define ASSUME_ITS_LESS_THAN_I16(actual, expected) \ FOSSIL_TEST_ASSUME((int16_t)(actual) < (int16_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 16-bit integer value is more than the expected value. + * + * @param actual The actual 16-bit integer value. + * @param expected The expected 16-bit integer value. + */ #define ASSUME_ITS_MORE_THAN_I16(actual, expected) \ FOSSIL_TEST_ASSUME((int16_t)(actual) > (int16_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 16-bit integer value is less than or equal to the expected value. + * + * @param actual The actual 16-bit integer value. + * @param expected The expected 16-bit integer value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_I16(actual, expected) \ FOSSIL_TEST_ASSUME((int16_t)(actual) <= (int16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 16-bit integer value is more than or equal to the expected value. + * + * @param actual The actual 16-bit integer value. + * @param expected The expected 16-bit integer value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_I16(actual, expected) \ FOSSIL_TEST_ASSUME((int16_t)(actual) >= (int16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 16-bit integer values are not equal. + * + * @param actual The actual 16-bit integer value. + * @param expected The expected 16-bit integer value. + */ #define ASSUME_NOT_EQUAL_I16(actual, expected) \ FOSSIL_TEST_ASSUME((int16_t)(actual) != (int16_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 16-bit integer value is not less than the expected value. + * + * @param actual The actual 16-bit integer value. + * @param expected The expected 16-bit integer value. + */ #define ASSUME_NOT_LESS_THAN_I16(actual, expected) \ FOSSIL_TEST_ASSUME((int16_t)(actual) >= (int16_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 16-bit integer value is not more than the expected value. + * + * @param actual The actual 16-bit integer value. + * @param expected The expected 16-bit integer value. + */ #define ASSUME_NOT_MORE_THAN_I16(actual, expected) \ FOSSIL_TEST_ASSUME((int16_t)(actual) <= (int16_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 16-bit integer value is not less than or equal to the expected value. + * + * @param actual The actual 16-bit integer value. + * @param expected The expected 16-bit integer value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_I16(actual, expected) \ FOSSIL_TEST_ASSUME((int16_t)(actual) > (int16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 16-bit integer value is not more than or equal to the expected value. + * + * @param actual The actual 16-bit integer value. + * @param expected The expected 16-bit integer value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_I16(actual, expected) \ - FOSSIL_TEST_ASSUME((int16_t)(actual) < (int16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + FOSSIL_TEST_ASSUME((int16_t)(actual) < (int16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected") -// I32 ASSUMEions +/** + * @brief Assumes that the given 32-bit integer values are equal. + * + * @param actual The actual 32-bit integer value. + * @param expected The expected 32-bit integer value. + */ #define ASSUME_ITS_EQUAL_I32(actual, expected) \ FOSSIL_TEST_ASSUME((int32_t)(actual) == (int32_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 32-bit integer value is less than the expected value. + * + * @param actual The actual 32-bit integer value. + * @param expected The expected 32-bit integer value. + */ #define ASSUME_ITS_LESS_THAN_I32(actual, expected) \ FOSSIL_TEST_ASSUME((int32_t)(actual) < (int32_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 32-bit integer value is more than the expected value. + * + * @param actual The actual 32-bit integer value. + * @param expected The expected 32-bit integer value. + */ #define ASSUME_ITS_MORE_THAN_I32(actual, expected) \ FOSSIL_TEST_ASSUME((int32_t)(actual) > (int32_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 32-bit integer value is less than or equal to the expected value. + * + * @param actual The actual 32-bit integer value. + * @param expected The expected 32-bit integer value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_I32(actual, expected) \ FOSSIL_TEST_ASSUME((int32_t)(actual) <= (int32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 32-bit integer value is more than or equal to the expected value. + * + * @param actual The actual 32-bit integer value. + * @param expected The expected 32-bit integer value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_I32(actual, expected) \ FOSSIL_TEST_ASSUME((int32_t)(actual) >= (int32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 32-bit integer values are not equal. + * + * @param actual The actual 32-bit integer value. + * @param expected The expected 32-bit integer value. + */ #define ASSUME_NOT_EQUAL_I32(actual, expected) \ FOSSIL_TEST_ASSUME((int32_t)(actual) != (int32_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 32-bit integer value is not less than the expected value. + * + * @param actual The actual 32-bit integer value. + * @param expected The expected 32-bit integer value. + */ #define ASSUME_NOT_LESS_THAN_I32(actual, expected) \ FOSSIL_TEST_ASSUME((int32_t)(actual) >= (int32_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 32-bit integer value is not more than the expected value. + * + * @param actual The actual 32-bit integer value. + * @param expected The expected 32-bit integer value. + */ #define ASSUME_NOT_MORE_THAN_I32(actual, expected) \ FOSSIL_TEST_ASSUME((int32_t)(actual) <= (int32_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 32-bit integer value is not less than or equal to the expected value. + * + * @param actual The actual 32-bit integer value. + * @param expected The expected 32-bit integer value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_I32(actual, expected) \ FOSSIL_TEST_ASSUME((int32_t)(actual) > (int32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 32-bit integer value is not more than or equal to the expected value. + * + * @param actual The actual 32-bit integer value. + * @param expected The expected 32-bit integer value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_I32(actual, expected) \ - FOSSIL_TEST_ASSUME((int32_t)(actual) < (int32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + FOSSIL_TEST_ASSUME((int32_t)(actual) < (int32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected") -// I64 ASSUMEions +/** + * @brief Assumes that the given 64-bit integer values are equal. + * + * @param actual The actual 64-bit integer value. + * @param expected The expected 64-bit integer value. + */ #define ASSUME_ITS_EQUAL_I64(actual, expected) \ FOSSIL_TEST_ASSUME((int64_t)(actual) == (int64_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 64-bit integer value is less than the expected value. + * + * @param actual The actual 64-bit integer value. + * @param expected The expected 64-bit integer value. + */ #define ASSUME_ITS_LESS_THAN_I64(actual, expected) \ FOSSIL_TEST_ASSUME((int64_t)(actual) < (int64_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 64-bit integer value is more than the expected value. + * + * @param actual The actual 64-bit integer value. + * @param expected The expected 64-bit integer value. + */ #define ASSUME_ITS_MORE_THAN_I64(actual, expected) \ FOSSIL_TEST_ASSUME((int64_t)(actual) > (int64_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 64-bit integer value is less than or equal to the expected value. + * + * @param actual The actual 64-bit integer value. + * @param expected The expected 64-bit integer value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_I64(actual, expected) \ FOSSIL_TEST_ASSUME((int64_t)(actual) <= (int64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 64-bit integer value is more than or equal to the expected value. + * + * @param actual The actual 64-bit integer value. + * @param expected The expected 64-bit integer value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_I64(actual, expected) \ FOSSIL_TEST_ASSUME((int64_t)(actual) >= (int64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 64-bit integer values are not equal. + * + * @param actual The actual 64-bit integer value. + * @param expected The expected 64-bit integer value. + */ #define ASSUME_NOT_EQUAL_I64(actual, expected) \ FOSSIL_TEST_ASSUME((int64_t)(actual) != (int64_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 64-bit integer value is not less than the expected value. + * + * @param actual The actual 64-bit integer value. + * @param expected The expected 64-bit integer value. + */ #define ASSUME_NOT_LESS_THAN_I64(actual, expected) \ FOSSIL_TEST_ASSUME((int64_t)(actual) >= (int64_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 64-bit integer value is not more than the expected value. + * + * @param actual The actual 64-bit integer value. + * @param expected The expected 64-bit integer value. + */ #define ASSUME_NOT_MORE_THAN_I64(actual, expected) \ FOSSIL_TEST_ASSUME((int64_t)(actual) <= (int64_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 64-bit integer value is not less than or equal to the expected value. + * + * @param actual The actual 64-bit integer value. + * @param expected The expected 64-bit integer value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_I64(actual, expected) \ FOSSIL_TEST_ASSUME((int64_t)(actual) > (int64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 64-bit integer value is not more than or equal to the expected value. + * + * @param actual The actual 64-bit integer value. + * @param expected The expected 64-bit integer value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_I64(actual, expected) \ FOSSIL_TEST_ASSUME((int64_t)(actual) < (int64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) -// U8 ASSUMEions +/** + * @brief Assumes that the given 8-bit unsigned integer values are equal. + * + * @param actual The actual 8-bit unsigned integer value. + * @param expected The expected 8-bit unsigned integer value. + */ #define ASSUME_ITS_EQUAL_U8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) == (uint8_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 8-bit unsigned integer value is less than the expected value. + * + * @param actual The actual 8-bit unsigned integer value. + * @param expected The expected 8-bit unsigned integer value. + */ #define ASSUME_ITS_LESS_THAN_U8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 8-bit unsigned integer value is more than the expected value. + * + * @param actual The actual 8-bit unsigned integer value. + * @param expected The expected 8-bit unsigned integer value. + */ #define ASSUME_ITS_MORE_THAN_U8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 8-bit unsigned integer value is less than or equal to the expected value. + * + * @param actual The actual 8-bit unsigned integer value. + * @param expected The expected 8-bit unsigned integer value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_U8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 8-bit unsigned integer value is more than or equal to the expected value. + * + * @param actual The actual 8-bit unsigned integer value. + * @param expected The expected 8-bit unsigned integer value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_U8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 8-bit unsigned integer values are not equal. + * + * @param actual The actual 8-bit unsigned integer value. + * @param expected The expected 8-bit unsigned integer value. + */ #define ASSUME_NOT_EQUAL_U8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) != (uint8_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 8-bit unsigned integer value is not less than the expected value. + * + * @param actual The actual 8-bit unsigned integer value. + * @param expected The expected 8-bit unsigned integer value. + */ #define ASSUME_NOT_LESS_THAN_U8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) >= (uint8_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 8-bit unsigned integer value is not more than the expected value. + * + * @param actual The actual 8-bit unsigned integer value. + * @param expected The expected 8-bit unsigned integer value. + */ #define ASSUME_NOT_MORE_THAN_U8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) <= (uint8_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 8-bit unsigned integer value is not less than or equal to the expected value. + * + * @param actual The actual 8-bit unsigned integer value. + * @param expected The expected 8-bit unsigned integer value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_U8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) > (uint8_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 8-bit unsigned integer value is not more than or equal to the expected value. + * + * @param actual The actual 8-bit unsigned integer value. + * @param expected The expected 8-bit unsigned integer value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_U8(actual, expected) \ FOSSIL_TEST_ASSUME((uint8_t)(actual) < (uint8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) -// U16 ASSUMEions +/** + * @brief Assumes that the given 16-bit unsigned integer values are equal. + * + * @param actual The actual 16-bit unsigned integer value. + * @param expected The expected 16-bit unsigned integer value. + */ #define ASSUME_ITS_EQUAL_U16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) == (uint16_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 16-bit unsigned integer value is less than the expected value. + * + * @param actual The actual 16-bit unsigned integer value. + * @param expected The expected 16-bit unsigned integer value. + */ #define ASSUME_ITS_LESS_THAN_U16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 16-bit unsigned integer value is more than the expected value. + * + * @param actual The actual 16-bit unsigned integer value. + * @param expected The expected 16-bit unsigned integer value. + */ #define ASSUME_ITS_MORE_THAN_U16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 16-bit unsigned integer value is less than or equal to the expected value. + * + * @param actual The actual 16-bit unsigned integer value. + * @param expected The expected 16-bit unsigned integer value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_U16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 16-bit unsigned integer value is more than or equal to the expected value. + * + * @param actual The actual 16-bit unsigned integer value. + * @param expected The expected 16-bit unsigned integer value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_U16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 16-bit unsigned integer values are not equal. + * + * @param actual The actual 16-bit unsigned integer value. + * @param expected The expected 16-bit unsigned integer value. + */ #define ASSUME_NOT_EQUAL_U16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) != (uint16_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 16-bit unsigned integer value is not less than the expected value. + * + * @param actual The actual 16-bit unsigned integer value. + * @param expected The expected 16-bit unsigned integer value. + */ #define ASSUME_NOT_LESS_THAN_U16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) >= (uint16_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 16-bit unsigned integer value is not more than the expected value. + * + * @param actual The actual 16-bit unsigned integer value. + * @param expected The expected 16-bit unsigned integer value. + */ #define ASSUME_NOT_MORE_THAN_U16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) <= (uint16_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 16-bit unsigned integer value is not less than or equal to the expected value. + * + * @param actual The actual 16-bit unsigned integer value. + * @param expected The expected 16-bit unsigned integer value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_U16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) > (uint16_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 16-bit unsigned integer value is not more than or equal to the expected value. + * + * @param actual The actual 16-bit unsigned integer value. + * @param expected The expected 16-bit unsigned integer value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_U16(actual, expected) \ FOSSIL_TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) -// U32 ASSUMEions +/** + * @brief Assumes that the given 32-bit unsigned integer values are equal. + * + * @param actual The actual 32-bit unsigned integer value. + * @param expected The expected 32-bit unsigned integer value. + */ #define ASSUME_ITS_EQUAL_U32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) == (uint32_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 32-bit unsigned integer value is less than the expected value. + * + * @param actual The actual 32-bit unsigned integer value. + * @param expected The expected 32-bit unsigned integer value. + */ #define ASSUME_ITS_LESS_THAN_U32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 32-bit unsigned integer value is more than the expected value. + * + * @param actual The actual 32-bit unsigned integer value. + * @param expected The expected 32-bit unsigned integer value. + */ #define ASSUME_ITS_MORE_THAN_U32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 32-bit unsigned integer value is less than or equal to the expected value. + * + * @param actual The actual 32-bit unsigned integer value. + * @param expected The expected 32-bit unsigned integer value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_U32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 32-bit unsigned integer value is more than or equal to the expected value. + * + * @param actual The actual 32-bit unsigned integer value. + * @param expected The expected 32-bit unsigned integer value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_U32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 32-bit unsigned integer values are not equal. + * + * @param actual The actual 32-bit unsigned integer value. + * @param expected The expected 32-bit unsigned integer value. + */ #define ASSUME_NOT_EQUAL_U32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) != (uint32_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 32-bit unsigned integer value is not less than the expected value. + * + * @param actual The actual 32-bit unsigned integer value. + * @param expected The expected 32-bit unsigned integer value. + */ #define ASSUME_NOT_LESS_THAN_U32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) >= (uint32_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 32-bit unsigned integer value is not more than the expected value. + * + * @param actual The actual 32-bit unsigned integer value. + * @param expected The expected 32-bit unsigned integer value. + */ #define ASSUME_NOT_MORE_THAN_U32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) <= (uint32_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 32-bit unsigned integer value is not less than or equal to the expected value. + * + * @param actual The actual 32-bit unsigned integer value. + * @param expected The expected 32-bit unsigned integer value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_U32(actual, expected) \ FOSSIL_TEST_ASSUME((uint32_t)(actual) > (uint32_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 32-bit unsigned integer value is not more than or equal to the expected value. + * + * @param actual The actual 32-bit unsigned integer value. + * @param expected The expected 32-bit unsigned integer value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_U32(actual, expected) \ - FOSSIL_TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) + FOSSIL_TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected") -// U64 ASSUMEions +/** + * @brief Assumes that the given 64-bit unsigned integer values are equal. + * + * @param actual The actual 64-bit unsigned integer value. + * @param expected The expected 64-bit unsigned integer value. + */ #define ASSUME_ITS_EQUAL_U64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) == (uint64_t)(expected), "Expected " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given 64-bit unsigned integer value is less than the expected value. + * + * @param actual The actual 64-bit unsigned integer value. + * @param expected The expected 64-bit unsigned integer value. + */ #define ASSUME_ITS_LESS_THAN_U64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to be less than " #expected) +/** + * @brief Assumes that the given 64-bit unsigned integer value is more than the expected value. + * + * @param actual The actual 64-bit unsigned integer value. + * @param expected The expected 64-bit unsigned integer value. + */ #define ASSUME_ITS_MORE_THAN_U64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to be more than " #expected) +/** + * @brief Assumes that the given 64-bit unsigned integer value is less than or equal to the expected value. + * + * @param actual The actual 64-bit unsigned integer value. + * @param expected The expected 64-bit unsigned integer value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_U64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to be less than or equal to " #expected) +/** + * @brief Assumes that the given 64-bit unsigned integer value is more than or equal to the expected value. + * + * @param actual The actual 64-bit unsigned integer value. + * @param expected The expected 64-bit unsigned integer value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_U64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to be more than or equal to " #expected) +/** + * @brief Assumes that the given 64-bit unsigned integer values are not equal. + * + * @param actual The actual 64-bit unsigned integer value. + * @param expected The expected 64-bit unsigned integer value. + */ #define ASSUME_NOT_EQUAL_U64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) != (uint64_t)(expected), "Expected " #actual " to not be equal to " #expected) +/** + * @brief Assumes that the given 64-bit unsigned integer value is not less than the expected value. + * + * @param actual The actual 64-bit unsigned integer value. + * @param expected The expected 64-bit unsigned integer value. + */ #define ASSUME_NOT_LESS_THAN_U64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) >= (uint64_t)(expected), "Expected " #actual " to not be less than " #expected) +/** + * @brief Assumes that the given 64-bit unsigned integer value is not more than the expected value. + * + * @param actual The actual 64-bit unsigned integer value. + * @param expected The expected 64-bit unsigned integer value. + */ #define ASSUME_NOT_MORE_THAN_U64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) <= (uint64_t)(expected), "Expected " #actual " to not be more than " #expected) +/** + * @brief Assumes that the given 64-bit unsigned integer value is not less than or equal to the expected value. + * + * @param actual The actual 64-bit unsigned integer value. + * @param expected The expected 64-bit unsigned integer value. + */ #define ASSUME_NOT_LESS_OR_EQUAL_U64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) > (uint64_t)(expected), "Expected " #actual " to not be less than or equal to " #expected) +/** + * @brief Assumes that the given 64-bit unsigned integer value is not more than or equal to the expected value. + * + * @param actual The actual 64-bit unsigned integer value. + * @param expected The expected 64-bit unsigned integer value. + */ #define ASSUME_NOT_MORE_OR_EQUAL_U64(actual, expected) \ FOSSIL_TEST_ASSUME((uint64_t)(actual) < (uint64_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) @@ -643,45 +1747,91 @@ extern "C" { // // ************************************************** -// ITS set +/** + * @brief Assumes that the given pointer is NULL. + * + * @param actual The pointer to be evaluated. + */ #define ASSUME_ITS_CNULL(actual) \ FOSSIL_TEST_ASSUME((actual) == NULL, "Expected " #actual " to be NULL") +/** + * @brief Assumes that the given pointer is not NULL. + * + * @param actual The pointer to be evaluated. + */ #define ASSUME_NOT_CNULL(actual) \ FOSSIL_TEST_ASSUME((actual) != NULL, "Expected " #actual " to not be NULL") -// General pointer ASSUMEions (_PTR) - -// ITS set +/** + * @brief Assumes that the given pointers are equal. + * + * @param actual The actual pointer. + * @param expected The expected pointer. + */ #define ASSUME_ITS_EQUAL_PTR(actual, expected) \ FOSSIL_TEST_ASSUME((actual) == (expected), "Expected pointer " #actual " to be equal to pointer " #expected " ") +/** + * @brief Assumes that the given pointers are not equal. + * + * @param actual The actual pointer. + * @param expected The expected pointer. + */ #define ASSUME_NOT_EQUAL_PTR(actual, expected) \ FOSSIL_TEST_ASSUME((actual) != (expected), "Expected pointer " #actual " to not be equal to pointer " #expected " ") -// Size_t ASSUMEions - -// Equal +/** + * @brief Assumes that the given size_t values are equal. + * + * @param actual The actual size_t value. + * @param expected The expected size_t value. + */ #define ASSUME_ITS_EQUAL_SIZE(actual, expected) \ FOSSIL_TEST_ASSUME((size_t)(actual) == (size_t)(expected), "Expected " #actual " to be equal to " #expected) -// Less than +/** + * @brief Assumes that the given size_t value is less than the expected value. + * + * @param actual The actual size_t value. + * @param expected The expected size_t value. + */ #define ASSUME_ITS_LESS_THAN_SIZE(actual, expected) \ FOSSIL_TEST_ASSUME((size_t)(actual) < (size_t)(expected), "Expected " #actual " to be less than " #expected) -// More than +/** + * @brief Assumes that the given size_t value is more than the expected value. + * + * @param actual The actual size_t value. + * @param expected The expected size_t value. + */ #define ASSUME_ITS_MORE_THAN_SIZE(actual, expected) \ FOSSIL_TEST_ASSUME((size_t)(actual) > (size_t)(expected), "Expected " #actual " to be more than " #expected) -// Less or equal +/** + * @brief Assumes that the given size_t value is less than or equal to the expected value. + * + * @param actual The actual size_t value. + * @param expected The expected size_t value. + */ #define ASSUME_ITS_LESS_OR_EQUAL_SIZE(actual, expected) \ FOSSIL_TEST_ASSUME((size_t)(actual) <= (size_t)(expected), "Expected " #actual " to be less than or equal to " #expected) -// More or equal +/** + * @brief Assumes that the given size_t value is more than or equal to the expected value. + * + * @param actual The actual size_t value. + * @param expected The expected size_t value. + */ #define ASSUME_ITS_MORE_OR_EQUAL_SIZE(actual, expected) \ FOSSIL_TEST_ASSUME((size_t)(actual) >= (size_t)(expected), "Expected " #actual " to be more than or equal to " #expected) -// Not equal +/** + * @brief Assumes that the given size_t values are not equal. + * + * @param actual The actual size_t value. + * @param expected The expected size_t value. + */ #define ASSUME_NOT_EQUAL_SIZE(actual, expected) \ FOSSIL_TEST_ASSUME((size_t)(actual) != (size_t)(expected), "Expected " #actual " to not be equal to " #expected) @@ -691,100 +1841,291 @@ extern "C" { // // ************************************************** -// ASSUMEion for checking if a value is within a specified range +/** + * @brief Assumes that the given value is within the specified range. + * + * @param value The value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_ITS_WITHIN_RANGE(value, min, max) \ FOSSIL_TEST_ASSUME((value) >= (min) && (value) <= (max), "Value " #value " is not within range [" #min ", " #max "]") +/** + * @brief Assumes that the given value is not within the specified range. + * + * @param value The value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_NOT_WITHIN_RANGE(value, min, max) \ FOSSIL_TEST_ASSUME((value) < (min) || (value) > (max), "Value " #value " is within range [" #min ", " #max "]") -// Unsigned integer type ASSUMEions +// Unsigned integer type assumptions +/** + * @brief Assumes that the given 8-bit unsigned integer value is within the specified range. + * + * @param value The 8-bit unsigned integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_ITS_WITHIN_RANGE_U8(value, min, max) \ FOSSIL_TEST_ASSUME((uint8_t)(value) >= (uint8_t)(min) && (uint8_t)(value) <= (uint8_t)(max), "Value " #value " is not within range [" #min ", " #max "]") +/** + * @brief Assumes that the given 8-bit unsigned integer value is not within the specified range. + * + * @param value The 8-bit unsigned integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_NOT_WITHIN_RANGE_U8(value, min, max) \ FOSSIL_TEST_ASSUME((uint8_t)(value) < (uint8_t)(min) || (uint8_t)(value) > (uint8_t)(max), "Value " #value " is within range [" #min ", " #max "]") +/** + * @brief Assumes that the given 16-bit unsigned integer value is within the specified range. + * + * @param value The 16-bit unsigned integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_ITS_WITHIN_RANGE_U16(value, min, max) \ FOSSIL_TEST_ASSUME((uint16_t)(value) >= (uint16_t)(min) && (uint16_t)(value) <= (uint16_t)(max), "Value " #value " is not within range [" #min ", " #max "]") +/** + * @brief Assumes that the given 16-bit unsigned integer value is not within the specified range. + * + * @param value The 16-bit unsigned integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_NOT_WITHIN_RANGE_U16(value, min, max) \ FOSSIL_TEST_ASSUME((uint16_t)(value) < (uint16_t)(min) || (uint16_t)(value) > (uint16_t)(max), "Value " #value " is within range [" #min ", " #max "]") +/** + * @brief Assumes that the given 32-bit unsigned integer value is within the specified range. + * + * @param value The 32-bit unsigned integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_ITS_WITHIN_RANGE_U32(value, min, max) \ FOSSIL_TEST_ASSUME((uint32_t)(value) >= (uint32_t)(min) && (uint32_t)(value) <= (uint32_t)(max), "Value " #value " is not within range [" #min ", " #max "]") +/** + * @brief Assumes that the given 32-bit unsigned integer value is not within the specified range. + * + * @param value The 32-bit unsigned integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_NOT_WITHIN_RANGE_U32(value, min, max) \ FOSSIL_TEST_ASSUME((uint32_t)(value) < (uint32_t)(min) || (uint32_t)(value) > (uint32_t)(max), "Value " #value " is within range [" #min ", " #max "]") +/** + * @brief Assumes that the given 64-bit unsigned integer value is within the specified range. + * + * @param value The 64-bit unsigned integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_ITS_WITHIN_RANGE_U64(value, min, max) \ FOSSIL_TEST_ASSUME((uint64_t)(value) >= (uint64_t)(min) && (uint64_t)(value) <= (uint64_t)(max), "Value " #value " is not within range [" #min ", " #max "]") +/** + * @brief Assumes that the given 64-bit unsigned integer value is not within the specified range. + * + * @param value The 64-bit unsigned integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_NOT_WITHIN_RANGE_U64(value, min, max) \ FOSSIL_TEST_ASSUME((uint64_t)(value) < (uint64_t)(min) || (uint64_t)(value) > (uint64_t)(max), "Value " #value " is within range [" #min ", " #max "]") -// Signed integer type ASSUMEions - +/** + * @brief Assumes that the given 8-bit integer value is within the specified range. + * + * @param value The 8-bit integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_ITS_WITHIN_RANGE_I8(value, min, max) \ FOSSIL_TEST_ASSUME((int8_t)(value) >= (int8_t)(min) && (int8_t)(value) <= (int8_t)(max), "Value " #value " is not within range [" #min ", " #max "]") +/** + * @brief Assumes that the given 8-bit integer value is not within the specified range. + * + * @param value The 8-bit integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_NOT_WITHIN_RANGE_I8(value, min, max) \ FOSSIL_TEST_ASSUME((int8_t)(value) < (int8_t)(min) || (int8_t)(value) > (int8_t)(max), "Value " #value " is within range [" #min ", " #max "]") +/** + * @brief Assumes that the given 16-bit integer value is within the specified range. + * + * @param value The 16-bit integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_ITS_WITHIN_RANGE_I16(value, min, max) \ FOSSIL_TEST_ASSUME((int16_t)(value) >= (int16_t)(min) && (int16_t)(value) <= (int16_t)(max), "Value " #value " is not within range [" #min ", " #max "]") +/** + * @brief Assumes that the given 16-bit integer value is not within the specified range. + * + * @param value The 16-bit integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_NOT_WITHIN_RANGE_I16(value, min, max) \ FOSSIL_TEST_ASSUME((int16_t)(value) < (int16_t)(min) || (int16_t)(value) > (int16_t)(max), "Value " #value " is within range [" #min ", " #max "]") +/** + * @brief Assumes that the given 32-bit integer value is within the specified range. + * + * @param value The 32-bit integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_ITS_WITHIN_RANGE_I32(value, min, max) \ FOSSIL_TEST_ASSUME((int32_t)(value) >= (int32_t)(min) && (int32_t)(value) <= (int32_t)(max), "Value " #value " is not within range [" #min ", " #max "]") +/** + * @brief Assumes that the given 32-bit integer value is not within the specified range. + * + * @param value The 32-bit integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_NOT_WITHIN_RANGE_I32(value, min, max) \ FOSSIL_TEST_ASSUME((int32_t)(value) < (int32_t)(min) || (int32_t)(value) > (int32_t)(max), "Value " #value " is within range [" #min ", " #max "]") +/** + * @brief Assumes that the given 64-bit integer value is within the specified range. + * + * @param value The 64-bit integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_ITS_WITHIN_RANGE_I64(value, min, max) \ FOSSIL_TEST_ASSUME((int64_t)(value) >= (int64_t)(min) && (int64_t)(value) <= (int64_t)(max), "Value " #value " is not within range [" #min ", " #max "]") +/** + * @brief Assumes that the given 64-bit integer value is not within the specified range. + * + * @param value The 64-bit integer value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_NOT_WITHIN_RANGE_I64(value, min, max) \ FOSSIL_TEST_ASSUME((int64_t)(value) < (int64_t)(min) || (int64_t)(value) > (int64_t)(max), "Value " #value " is within range [" #min ", " #max "]") -// Floating point type ASSUMEions - +/** + * @brief Assumes that the given float value is within the specified range. + * + * @param value The float value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_ITS_WITHIN_RANGE_F32(value, min, max) \ FOSSIL_TEST_ASSUME((value) >= (min) && (value) <= (max), "Value " #value " is not within range [" #min ", " #max "]") +/** + * @brief Assumes that the given float value is not within the specified range. + * + * @param value The float value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_NOT_WITHIN_RANGE_F32(value, min, max) \ FOSSIL_TEST_ASSUME((value) < (min) || (value) > (max), "Value " #value " is within range [" #min ", " #max "]") +/** + * @brief Assumes that the given double value is within the specified range. + * + * @param value The double value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_ITS_WITHIN_RANGE_F64(value, min, max) \ FOSSIL_TEST_ASSUME((value) >= (min) && (value) <= (max), "Value " #value " is not within range [" #min ", " #max "]") +/** + * @brief Assumes that the given double value is not within the specified range. + * + * @param value The double value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_NOT_WITHIN_RANGE_F64(value, min, max) \ FOSSIL_TEST_ASSUME((value) < (min) || (value) > (max), "Value " #value " is within range [" #min ", " #max "]") // Byte char type ASSUMEions (uint8_t) +/** + * @brief Assumes that the given byte char value is within the specified range. + * + * @param value The byte char value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_ITS_WITHIN_RANGE_BCHAR(value, min, max) \ FOSSIL_TEST_ASSUME((uint8_t)(value) >= (uint8_t)(min) && (uint8_t)(value) <= (uint8_t)(max), "Value " #value " is not within range [" #min ", " #max "]") +/** + * @brief Assumes that the given byte char value is not within the specified range. + * + * @param value The byte char value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_NOT_WITHIN_RANGE_BCHAR(value, min, max) \ FOSSIL_TEST_ASSUME((uint8_t)(value) < (uint8_t)(min) || (uint8_t)(value) > (uint8_t)(max), "Value " #value " is within range [" #min ", " #max "]") // Char type ASSUMEions (char) +/** + * @brief Assumes that the given char value is within the specified range. + * + * @param value The char value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_ITS_WITHIN_RANGE_CCHAR(value, min, max) \ FOSSIL_TEST_ASSUME((char)(value) >= (char)(min) && (char)(value) <= (char)(max), "Value " #value " is not within range [" #min ", " #max "]") +/** + * @brief Assumes that the given char value is not within the specified range. + * + * @param value The char value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_NOT_WITHIN_RANGE_CCHAR(value, min, max) \ FOSSIL_TEST_ASSUME((char)(value) < (char)(min) || (char)(value) > (char)(max), "Value " #value " is within range [" #min ", " #max "]") // Wide char type ASSUMEions (wchar_t) +/** + * @brief Assumes that the given wide char value is within the specified range. + * + * @param value The wide char value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_ITS_WITHIN_RANGE_WCHAR(value, min, max) \ FOSSIL_TEST_ASSUME((wchar_t)(value) >= (wchar_t)(min) && (wchar_t)(value) <= (wchar_t)(max), "Value " #value " is not within range [" #min ", " #max "]") +/** + * @brief Assumes that the given wide char value is not within the specified range. + * + * @param value The wide char value to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + */ #define ASSUME_NOT_WITHIN_RANGE_WCHAR(value, min, max) \ FOSSIL_TEST_ASSUME((wchar_t)(value) < (wchar_t)(min) || (wchar_t)(value) > (wchar_t)(max), "Value " #value " is within range [" #min ", " #max "]") @@ -794,36 +2135,84 @@ extern "C" { // // ************************************************** -// Wide char string equality check +/** + * @brief Assumes that the given wide char strings are equal. + * + * @param actual The actual wide char string. + * @param expected The expected wide char string. + */ #define ASSUME_ITS_EQUAL_WSTR(actual, expected) \ FOSSIL_TEST_ASSUME(wcscmp((actual), (expected)) == 0, "Expected wide string " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given wide char strings are not equal. + * + * @param actual The actual wide char string. + * @param expected The expected wide char string. + */ #define ASSUME_NOT_EQUAL_WSTR(actual, expected) \ FOSSIL_TEST_ASSUME(wcscmp((actual), (expected)) != 0, "Expected wide string " #actual " to not be equal to " #expected) -// For length comparison +/** + * @brief Assumes that the length of the given wide char string is equal to the expected length. + * + * @param actual The actual wide char string. + * @param expected_len The expected length of the wide char string. + */ #define ASSUME_ITS_LENGTH_EQUAL_WSTR(actual, expected_len) \ FOSSIL_TEST_ASSUME(wcslen((actual)) == (expected_len), "Expected length of wide string " #actual " to be equal to " #expected_len) -// Byte string equality check +/** + * @brief Assumes that the given byte strings are equal. + * + * @param actual The actual byte string. + * @param expected The expected byte string. + */ #define ASSUME_ITS_EQUAL_BSTR(actual, expected) \ FOSSIL_TEST_ASSUME(strcmp((const char*)(actual), (const char*)(expected)) == 0, "Expected byte string " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given byte strings are not equal. + * + * @param actual The actual byte string. + * @param expected The expected byte string. + */ #define ASSUME_NOT_EQUAL_BSTR(actual, expected) \ FOSSIL_TEST_ASSUME(strcmp((const char*)(actual), (const char*)(expected)) != 0, "Expected byte string " #actual " to not be equal to " #expected) -// For length comparison +/** + * @brief Assumes that the length of the given byte string is equal to the expected length. + * + * @param actual The actual byte string. + * @param expected_len The expected length of the byte string. + */ #define ASSUME_ITS_LENGTH_EQUAL_BSTR(actual, expected_len) \ FOSSIL_TEST_ASSUME(strlen((const char*)(actual)) == (expected_len), "Expected length of byte string " #actual " to be equal to " #expected_len) -// Classic C string equality check +/** + * @brief Assumes that the given C strings are equal. + * + * @param actual The actual C string. + * @param expected The expected C string. + */ #define ASSUME_ITS_EQUAL_CSTR(actual, expected) \ FOSSIL_TEST_ASSUME(strcmp((actual), (expected)) == 0, "Expected C string " #actual " to be equal to " #expected) +/** + * @brief Assumes that the given C strings are not equal. + * + * @param actual The actual C string. + * @param expected The expected C string. + */ #define ASSUME_NOT_EQUAL_CSTR(actual, expected) \ FOSSIL_TEST_ASSUME(strcmp((actual), (expected)) != 0, "Expected C string " #actual " to not be equal to " #expected) -// For length comparison +/** + * @brief Assumes that the length of the given C string is equal to the expected length. + * + * @param actual The actual C string. + * @param expected_len The expected length of the C string. + */ #define ASSUME_ITS_LENGTH_EQUAL_CSTR(actual, expected_len) \ FOSSIL_TEST_ASSUME(strlen((actual)) == (expected_len), "Expected length of C string " #actual " to be equal to " #expected_len) @@ -833,29 +2222,60 @@ extern "C" { // // ************************************************** -// Array equality check +/** + * @brief Assumes that the given arrays are equal. + * + * @param actual The actual array. + * @param expected The expected array. + * @param length The length of the arrays. + */ #define ASSUME_ITS_EQUAL_ARRAY(actual, expected, length) \ for (size_t i = 0; i < (length); i++) { \ FOSSIL_TEST_ASSUME((actual)[i] == (expected)[i], "Expected array element " #actual " to be equal to " #expected); \ } -// Array inequality check +/** + * @brief Assumes that the given arrays are not equal. + * + * @param actual The actual array. + * @param expected The expected array. + * @param length The length of the arrays. + */ #define ASSUME_NOT_EQUAL_ARRAY(actual, expected, length) \ for (size_t i = 0; i < (length); i++) { \ FOSSIL_TEST_ASSUME((actual)[i] != (expected)[i], "Expected array element " #actual " to not be equal to " #expected); \ } -// Array length check +/** + * @brief Assumes that the length of the given arrays are equal. + * + * @param actual_length The actual length of the array. + * @param expected_length The expected length of the array. + */ #define ASSUME_ITS_LENGTH_EQUAL_ARRAY(actual_length, expected_length) \ FOSSIL_TEST_ASSUME((actual_length) == (expected_length), "Expected array length " #actual_length " to be equal to " #expected_length) -// Array element within range check +/** + * @brief Assumes that the elements of the given array are within the specified range. + * + * @param array The array to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + * @param length The length of the array. + */ #define ASSUME_ITS_WITHIN_RANGE_ARRAY(array, min, max, length) \ for (size_t i = 0; i < (length); i++) { \ FOSSIL_TEST_ASSUME((array)[i] >= (min) && (array)[i] <= (max), "Expected array element " #array " to be within range [" #min ", " #max "]"); \ } -// Array element not within range check +/** + * @brief Assumes that the elements of the given array are not within the specified range. + * + * @param array The array to be evaluated. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + * @param length The length of the array. + */ #define ASSUME_NOT_WITHIN_RANGE_ARRAY(array, min, max, length) \ for (size_t i = 0; i < (length); i++) { \ FOSSIL_TEST_ASSUME((array)[i] < (min) || (array)[i] > (max), "Expected array element " #array " to not be within range [" #min ", " #max "]"); \ From a9525312a8c5d4ca61aa8b70004fca4364e0e133 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 4 Nov 2024 10:18:29 -0600 Subject: [PATCH 13/40] move generator file into new directory --- code/tests/{ => tools}/generate-runner.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename code/tests/{ => tools}/generate-runner.py (100%) diff --git a/code/tests/generate-runner.py b/code/tests/tools/generate-runner.py similarity index 100% rename from code/tests/generate-runner.py rename to code/tests/tools/generate-runner.py From c196ae92fd1b24c19a1863a14b286673a34e462c Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 4 Nov 2024 10:26:17 -0600 Subject: [PATCH 14/40] change up sample --- code/tests/test_sample.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/tests/test_sample.c b/code/tests/test_sample.c index 699211cf..da19981a 100644 --- a/code/tests/test_sample.c +++ b/code/tests/test_sample.c @@ -52,3 +52,7 @@ FOSSIL_TEST_CASE(test_input_decrement) { FOSSIL_TEST_ASSUME(actual_output == data.expected_output, "Decrement test failed"); } +FOSSIL_TEST_GROUP(sample_test_group) { + FOSSIL_TEST_ADD(sample_suite, test_input_increment); + FOSSIL_TEST_ADD(sample_suite, test_input_decrement); +} From 482f912e381b466cdf6341e6ba6aaf77488cb114 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 4 Nov 2024 10:27:14 -0600 Subject: [PATCH 15/40] add test group methods --- code/logic/fossil/test/framework.h | 25 +++++++++++++++++++++++++ code/logic/fossil/test/unittest.h | 24 ++++++++++++++---------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/code/logic/fossil/test/framework.h b/code/logic/fossil/test/framework.h index 762af821..ef49a1a8 100644 --- a/code/logic/fossil/test/framework.h +++ b/code/logic/fossil/test/framework.h @@ -47,6 +47,31 @@ extern "C" { */ #define THEN(description) _THEN(description) +/** + * Macro to define a test group. + * This macro is used to define a test group, which is a collection of test + * cases that are related to each other. The test group can be executed as a + * whole to verify the correctness of a group of functionalities. + */ +#define FOSSIL_TEST_GROUP(name) \ + _FOSSIL_TEST_GROUP(name) + +/** + * Macro to export a test group. + * This macro is used to export a test group from a test file. The test group + * will be available to other test files that import it. + */ +#define FOSSIL_TEST_EXPORT(name) \ + _FOSSIL_TEST_EXPORT(name) + +/** + * Macro to import a test group. + * This macro is used to import a test group into the test runner. The test group + * will be executed when the test runner is run. + */ +#define FOSSIL_TEST_IMPORT(name) \ + _FOSSIL_TEST_IMPORT(name) + /** * Macro to define the main test runner. * This macro is used to define the main test runner function that will be diff --git a/code/logic/fossil/test/unittest.h b/code/logic/fossil/test/unittest.h index 250a65cd..71e864e1 100644 --- a/code/logic/fossil/test/unittest.h +++ b/code/logic/fossil/test/unittest.h @@ -195,21 +195,25 @@ void fossil_test_register_suite(test_suite_t *suite); .suite_setup_func = suite_name##_setup_func, \ .suite_teardown_func = suite_name##_teardown_func, \ .next = NULL \ + }; \ + __attribute__((constructor)) static void register_##suite_name() { \ + fossil_test_register_suite(&suite_name); \ } // Macro to add a test case to a suite -#define _FOSSIL_TEST_ADD(suite, test_case) \ - fossil_test_add_case((suite).tests, &(test_case)); +#define _FOSSIL_TEST_ADD(suite, test) \ + fossil_test_add_case((suite).tests, &(test##_test_case)); -// main runner managment +#define _FOSSIL_TEST_GROUP(name) \ + void name##_test_group(void) + +#define _FOSSIL_TEST_EXPORT(name) \ + void name##_test_group(void) -#define _FOSSIL_TEST_MAIN() \ - int main(void) { \ - FOSSIL_TEST_START(); \ - FOSSIL_TEST_RUN(); \ - FOSSIL_TEST_SUMMARY(); \ - FOSSIL_TEST_END(); \ - } // end of macro +#define _FOSSIL_TEST_IMPORT(name) \ + name##_test_group() + +// main runner managment #define _FOSSIL_TEST_START() \ fossil_test_init() From b4fde2b9fd1990729e2162ba946cff09a2c4dbce Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 4 Nov 2024 10:27:37 -0600 Subject: [PATCH 16/40] change runner --- code/tests/unit_runner.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/code/tests/unit_runner.c b/code/tests/unit_runner.c index ee2d1733..8bb1c62c 100644 --- a/code/tests/unit_runner.c +++ b/code/tests/unit_runner.c @@ -12,6 +12,17 @@ * Copyright (C) 2024 Fossil Logic. All rights reserved. * ----------------------------------------------------------------------------- */ -#include "fossil/test/framework.h" +#include -FOSSIL_TEST_MAIN() +FOSSIL_TEST_EXPORT(sample_test_group); + +int main(void) { + FOSSIL_TEST_START(); + + FOSSIL_TEST_IMPORT(sample_test_group); + + FOSSIL_TEST_RUN(); + + FOSSIL_TEST_SUMMARY(); + FOSSIL_TEST_END(); +} // end of macro \ No newline at end of file From fb2e05a943a721185987b81d4409bb91e227d2c9 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 4 Nov 2024 10:43:07 -0600 Subject: [PATCH 17/40] clear away old test files --- code/tests/meson.build | 2 +- code/tests/test_marks.c | 246 ---------------------------------------- code/tests/test_mocks.c | 60 ---------- code/tests/test_tags.c | 96 ---------------- 4 files changed, 1 insertion(+), 403 deletions(-) delete mode 100644 code/tests/test_marks.c delete mode 100644 code/tests/test_mocks.c delete mode 100644 code/tests/test_tags.c diff --git a/code/tests/meson.build b/code/tests/meson.build index 50fed56f..ba326ccf 100644 --- a/code/tests/meson.build +++ b/code/tests/meson.build @@ -3,7 +3,7 @@ if get_option('with_test').enabled() test_src = ['unit_runner.c'] test_cubes = [ - 'mocks', 'marks', 'xfixture', 'xsoneros', 'bdd', 'tdd', 'tags', + 'sample', 'bdd', 'tdd', ] foreach cube : test_cubes diff --git a/code/tests/test_marks.c b/code/tests/test_marks.c deleted file mode 100644 index 65bd322c..00000000 --- a/code/tests/test_marks.c +++ /dev/null @@ -1,246 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#include // basic test tools -#include // assertion tools -#include // benchmark tools - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Utilites -// * * * * * * * * * * * * * * * * * * * * * * * * -// Setup steps for things like test fixtures and -// mock objects are set here. -// * * * * * * * * * * * * * * * * * * * * * * * * - -// Algorithm 1: Bubble Sort -void bubble_sort(int *array, size_t size) { - for (size_t i = 0; i < size - 1; ++i) { - for (size_t j = 0; j < size - i - 1; ++j) { - if (*(array + j) > *(array + j + 1)) { - int temp = *(array + j); - *(array + j) = *(array + j + 1); - *(array + j + 1) = temp; - } - } - } -} - -// Algorithm 2: Insertion Sort -void insertion_sort(int *array, size_t size) { - int key, j; - for (size_t i = 1; i < size; ++i) { - key = array[i]; - j = i - 1; - while (j >= 0 && array[j] > key) { - array[j + 1] = array[j]; - j = j - 1; - } - array[j + 1] = key; - } -} - -// Algorithm 3: Selection Sort -void selection_sort(int *array, size_t size) { - for (size_t i = 0; i < size - 1; ++i) { - size_t min_index = i; - for (size_t j = i + 1; j < size; ++j) { - if (array[j] < array[min_index]) { - min_index = j; - } - } - int temp = array[min_index]; - array[min_index] = array[i]; - array[i] = temp; - } -} - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Cases -// * * * * * * * * * * * * * * * * * * * * * * * * -// The test cases below are provided as samples, inspired -// by the Meson build system's approach of using test cases -// as samples for library usage. -// * * * * * * * * * * * * * * * * * * * * * * * * - -// Test cases for Bubble Sort -FOSSIL_TEST_CASE(bubble_sort_case_1) { - // Test case 1 - int data[] = {5, 1, 4, 2, 8}; - size_t size = sizeof(data) / sizeof(data[0]); - TEST_BENCHMARK(); - bubble_sort(data, size); - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} - -FOSSIL_TEST_CASE(bubble_sort_case_2) { - // Test case 2 - int data[] = {9, 6, 7, 3, 1}; - size_t size = sizeof(data) / sizeof(data[0]); - TEST_BENCHMARK(); - bubble_sort(data, size); - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} - -FOSSIL_TEST_CASE(bubble_sort_case_3) { - // Test case 3 - int data[] = {8, 2, 4, 1, 7}; - size_t size = sizeof(data) / sizeof(data[0]); - TEST_BENCHMARK(); - bubble_sort(data, size); - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} - -// Test cases for Insertion Sort -FOSSIL_TEST_CASE(insertion_sort_case_1) { - // Test case 1 - int data[] = {5, 1, 4, 2, 8, 6, 3, 7}; - size_t size = sizeof(data) / sizeof(data[0]); - TEST_BENCHMARK(); - insertion_sort(data, size); - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} - -FOSSIL_TEST_CASE(insertion_sort_case_2) { - // Test case 2 - int data[] = {9, 6, 7, 3, 1, 5, 2, 4}; - size_t size = sizeof(data) / sizeof(data[0]); - TEST_BENCHMARK(); - insertion_sort(data, size); - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} - -FOSSIL_TEST_CASE(insertion_sort_case_3) { - // Test case 3 - int data[] = {8, 2, 4, 1, 7, 5, 9, 3}; - size_t size = sizeof(data) / sizeof(data[0]); - TEST_BENCHMARK(); - insertion_sort(data, size); - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} - -// Test cases for Selection Sort -FOSSIL_TEST_CASE(selection_sort_case_1) { - // Test case 1 - int data[] = {5, 1, 4, 2, 8, 6, 3, 7, 9}; - size_t size = sizeof(data) / sizeof(data[0]); - TEST_BENCHMARK(); - selection_sort(data, size); - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} - -FOSSIL_TEST_CASE(selection_sort_case_2) { - // Test case 2 - int data[] = {9, 6, 7, 3, 1, 5, 2, 4, 8}; - size_t size = sizeof(data) / sizeof(data[0]); - TEST_BENCHMARK(); - selection_sort(data, size); - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} - -FOSSIL_TEST_CASE(selection_sort_case_3) { - // Test case 3 - int data[] = {8, 2, 4, 1, 7, 5, 9, 3, 6}; - size_t size = sizeof(data) / sizeof(data[0]); - TEST_BENCHMARK(); - selection_sort(data, size); - TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0); -} - -// Test Case for Bubble Sort with Small Input -FOSSIL_TEST_CASE(benchmark_bubble_sort_small) { - const int size = 100; - int arr[size]; - for (int i = 0; i < size; ++i) { - arr[i] = rand(); - } - - MARK_BENCHMARK(bench_bubble_sort_small); - { - MARK_SCOPED(bench_bubble_sort_small); - bubble_sort(arr, size); - } - MARK_REPORT(bench_bubble_sort_small); - - for (int i = 0; i < size - 1; ++i) { - ASSUME_ITS_TRUE(arr[i] <= arr[i + 1]); - } -} - -// Test Case for Bubble Sort with Medium Input -FOSSIL_TEST_CASE(benchmark_bubble_sort_medium) { - const int size = 1000; - int arr[size]; - for (int i = 0; i < size; ++i) { - arr[i] = rand(); - } - - MARK_BENCHMARK(bench_bubble_sort_medium); - { - MARK_SCOPED(bench_bubble_sort_medium); - bubble_sort(arr, size); - } - MARK_REPORT(bench_bubble_sort_medium); - - for (int i = 0; i < size - 1; ++i) { - ASSUME_ITS_TRUE(arr[i] <= arr[i + 1]); - } -} - -// Test Case for Bubble Sort with Large Input -FOSSIL_TEST_CASE(benchmark_bubble_sort_large) { - const int size = 10000; - int arr[size]; - for (int i = 0; i < size; ++i) { - arr[i] = rand(); - } - - MARK_BENCHMARK(bench_bubble_sort_large); - { - MARK_SCOPED(bench_bubble_sort_large); - bubble_sort(arr, size); - } - MARK_REPORT(bench_bubble_sort_large); - - for (int i = 0; i < size - 1; ++i) { - ASSUME_ITS_TRUE(arr[i] <= arr[i + 1]); - } -} - -// XUNIT-GROUP -FOSSIL_TEST_GROUP(benchmark_group) { - APPLY_MARK(bubble_sort_case_1, "ghost"); - ADD_TEST(bubble_sort_case_1); - APPLY_MARK(bubble_sort_case_2, "ghost"); - ADD_TEST(bubble_sort_case_2); - APPLY_MARK(bubble_sort_case_3, "ghost"); - ADD_TEST(bubble_sort_case_3); - - APPLY_MARK(insertion_sort_case_1, "ghost"); - ADD_TEST(insertion_sort_case_1); - APPLY_MARK(insertion_sort_case_2, "ghost"); - ADD_TEST(insertion_sort_case_2); - APPLY_MARK(insertion_sort_case_3, "ghost"); - ADD_TEST(insertion_sort_case_3); - - APPLY_MARK(selection_sort_case_1, "ghost"); - ADD_TEST(selection_sort_case_1); - APPLY_MARK(selection_sort_case_2, "ghost"); - ADD_TEST(selection_sort_case_2); - APPLY_MARK(selection_sort_case_3, "ghost"); - ADD_TEST(selection_sort_case_3); - - ADD_TEST(benchmark_bubble_sort_small); - ADD_TEST(benchmark_bubble_sort_medium); - ADD_TEST(benchmark_bubble_sort_large); -} diff --git a/code/tests/test_mocks.c b/code/tests/test_mocks.c deleted file mode 100644 index b813742c..00000000 --- a/code/tests/test_mocks.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#include // basic test tools -#include // library under test - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Utilites -// * * * * * * * * * * * * * * * * * * * * * * * * -// Setup steps for things like test fixtures and -// mock objects are set here. -// * * * * * * * * * * * * * * * * * * * * * * * * - -// placeholder - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Cases -// * * * * * * * * * * * * * * * * * * * * * * * * -// The test cases below are provided as samples, inspired -// by the Meson build system's approach of using test cases -// as samples for library usage. -// * * * * * * * * * * * * * * * * * * * * * * * * - -// Test Case for Mocking a Function -FOSSIL_TEST_CASE(mock_function_test) { - MockCallList mock; - MOCK_INIT(mock); - - // Simulating function calls - char *args1[] = {"arg1", "arg2"}; - MOCK_ADD_CALL(mock, "mock_function", args1, 2); - - char *args2[] = {"arg3", "arg4"}; - MOCK_ADD_CALL(mock, "mock_function", args2, 2); - - // Validate that the calls were recorded - printf("Mock function calls:\n"); - MOCK_PRINT(mock); - - MOCK_DESTROY(mock); -} - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Pool -// * * * * * * * * * * * * * * * * * * * * * * * * - -FOSSIL_TEST_GROUP(test_using_mock_group) { - ADD_TEST(mock_function_test); -} diff --git a/code/tests/test_tags.c b/code/tests/test_tags.c deleted file mode 100644 index 8410628f..00000000 --- a/code/tests/test_tags.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#include - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Utilites -// * * * * * * * * * * * * * * * * * * * * * * * * -// Setup steps for things like test fixtures and -// mock objects are set here. -// * * * * * * * * * * * * * * * * * * * * * * * * - -// placeholder - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Cases -// * * * * * * * * * * * * * * * * * * * * * * * * -// The test cases below are provided as samples, inspired -// by the Meson build system's approach of using test cases -// as samples for library usage. -// * * * * * * * * * * * * * * * * * * * * * * * * - -FOSSIL_TEST_CASE(testing_slow_tags) { - int x = 42; - int y = 20; - - // Test cases - FOSSIL_TEST_ASSUME(x == 42, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y == 20, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(x != y, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y < x, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y <= x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST_CASE(testing_fast_tags) { - int x = 42; - int y = 20; - - // Test cases - FOSSIL_TEST_ASSUME(x == 42, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y == 20, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(x != y, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y < x, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y <= x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST_CASE(testing_no_tags) { - int x = 42; - int y = 20; - - // Test cases - FOSSIL_TEST_ASSUME(x == 42, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y == 20, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(x != y, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y < x, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y <= x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST_CASE(testing_fake_tags) { - int x = 42; - int y = 20; - - // Test cases - FOSSIL_TEST_ASSUME(x == 42, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y == 20, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(x != y, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y < x, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y <= x, "Should have passed the test case"); -} // end case - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Pool -// * * * * * * * * * * * * * * * * * * * * * * * * -FOSSIL_TEST_GROUP(tags_test_group) { - // Should do nothing beyond show an error message that the tag does not exist - APPLY_XTAG(testing_fake_tags, "pizza pizza pizza"); - ADD_TEST(testing_fake_tags); - APPLY_XTAG(testing_slow_tags, "slow"); - ADD_TEST(testing_slow_tags); - APPLY_XTAG(testing_fast_tags, "fast"); - ADD_TEST(testing_fast_tags); - - // No tags should affect this test case - ADD_TEST(testing_no_tags); -} // end of group From 11a51b966dc95c3de60ee81af1b9e0673ceb6caa Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 4 Nov 2024 10:53:04 -0600 Subject: [PATCH 18/40] apply some changes --- code/logic/benchmark.c | 2 ++ code/logic/fossil/test/assume.h | 10 +++++----- code/logic/mockup.c | 2 ++ code/logic/unittest.c | 10 ++++++++++ code/tests/meson.build | 2 +- code/tests/tools/generate-runner.py | 5 +++-- code/tests/unit_runner.c | 28 ---------------------------- 7 files changed, 23 insertions(+), 36 deletions(-) delete mode 100644 code/tests/unit_runner.c diff --git a/code/logic/benchmark.c b/code/logic/benchmark.c index c864602e..7ac1064c 100644 --- a/code/logic/benchmark.c +++ b/code/logic/benchmark.c @@ -16,6 +16,8 @@ */ #include "fossil/test/benchmark.h" #include +#include +#include #include #include #include diff --git a/code/logic/fossil/test/assume.h b/code/logic/fossil/test/assume.h index 84765f2e..85b8e19b 100644 --- a/code/logic/fossil/test/assume.h +++ b/code/logic/fossil/test/assume.h @@ -477,7 +477,7 @@ extern "C" { * @param expected The expected 16-bit octal value. */ #define ASSUME_NOT_MORE_OR_EQUAL_O16(actual, expected) \ - FOSSIL_TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected") + FOSSIL_TEST_ASSUME((uint16_t)(actual) < (uint16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) /** * @brief Assumes that the given 32-bit octal values are equal. @@ -1109,7 +1109,7 @@ extern "C" { * @param expected The expected 8-bit integer value. */ #define ASSUME_NOT_MORE_OR_EQUAL_I8(actual, expected) \ - FOSSIL_TEST_ASSUME((int8_t)(actual) < (int8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected") + FOSSIL_TEST_ASSUME((int8_t)(actual) < (int8_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) /** * @brief Assumes that the given 16-bit integer values are equal. @@ -1199,7 +1199,7 @@ extern "C" { * @param expected The expected 16-bit integer value. */ #define ASSUME_NOT_MORE_OR_EQUAL_I16(actual, expected) \ - FOSSIL_TEST_ASSUME((int16_t)(actual) < (int16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected") + FOSSIL_TEST_ASSUME((int16_t)(actual) < (int16_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) /** * @brief Assumes that the given 32-bit integer values are equal. @@ -1289,7 +1289,7 @@ extern "C" { * @param expected The expected 32-bit integer value. */ #define ASSUME_NOT_MORE_OR_EQUAL_I32(actual, expected) \ - FOSSIL_TEST_ASSUME((int32_t)(actual) < (int32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected") + FOSSIL_TEST_ASSUME((int32_t)(actual) < (int32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) /** * @brief Assumes that the given 64-bit integer values are equal. @@ -1649,7 +1649,7 @@ extern "C" { * @param expected The expected 32-bit unsigned integer value. */ #define ASSUME_NOT_MORE_OR_EQUAL_U32(actual, expected) \ - FOSSIL_TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected") + FOSSIL_TEST_ASSUME((uint32_t)(actual) < (uint32_t)(expected), "Expected " #actual " to not be more than or equal to " #expected) /** * @brief Assumes that the given 64-bit unsigned integer values are equal. diff --git a/code/logic/mockup.c b/code/logic/mockup.c index f9761a48..f35425bd 100644 --- a/code/logic/mockup.c +++ b/code/logic/mockup.c @@ -16,6 +16,8 @@ */ #include "fossil/test/mockup.h" +extern char *_custom_fossil_test_strdup(const char *str); + void fossil_mock_init(MockCallList *list) { list->head = NULL; list->tail = NULL; diff --git a/code/logic/unittest.c b/code/logic/unittest.c index 51eea2db..a77c10a3 100644 --- a/code/logic/unittest.c +++ b/code/logic/unittest.c @@ -14,6 +14,16 @@ */ #include "fossil/test/unittest.h" +char *_custom_fossil_test_strdup(const char *str) { + size_t len = strlen(str) + 1; + char *new_str = (char *)malloc(len); + if (new_str == NULL) { + return NULL; + } + memcpy(new_str, str, len); + return new_str; +} + // Global variables for tracking test results int pass_count = 0; int fail_count = 0; diff --git a/code/tests/meson.build b/code/tests/meson.build index ba326ccf..b69d25fb 100644 --- a/code/tests/meson.build +++ b/code/tests/meson.build @@ -1,5 +1,5 @@ if get_option('with_test').enabled() - #run_command(['python3', 'generate-runner.py'], check: true) + run_command(['python3', 'tools' / 'generate-runner.py'], check: true) test_src = ['unit_runner.c'] test_cubes = [ diff --git a/code/tests/tools/generate-runner.py b/code/tests/tools/generate-runner.py index 850180fe..bf12db24 100644 --- a/code/tests/tools/generate-runner.py +++ b/code/tests/tools/generate-runner.py @@ -46,8 +46,8 @@ def generate_test_runner(self, test_groups): // * * * * * * * * * * * * * * * * * * * * * * * *""" runner += """ -int main(int argc, char **argv) { - FOSSIL_TEST_CREATE(argc, argv);\n""" +int main(void) { + FOSSIL_TEST_START();\n""" import_pools = "\n".join( [f" FOSSIL_TEST_IMPORT({group});" for group in test_groups] @@ -55,6 +55,7 @@ def generate_test_runner(self, test_groups): footer = """ FOSSIL_TEST_RUN(); + FOSSIL_TEST_SUMMARY(); FOSSIL_TEST_END(); } // end of func """ diff --git a/code/tests/unit_runner.c b/code/tests/unit_runner.c deleted file mode 100644 index 8bb1c62c..00000000 --- a/code/tests/unit_runner.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * Date: 07/01/2024 - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#include - -FOSSIL_TEST_EXPORT(sample_test_group); - -int main(void) { - FOSSIL_TEST_START(); - - FOSSIL_TEST_IMPORT(sample_test_group); - - FOSSIL_TEST_RUN(); - - FOSSIL_TEST_SUMMARY(); - FOSSIL_TEST_END(); -} // end of macro \ No newline at end of file From 0ea1cbd82fa69047ab43255002e39c78bfd26a7d Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 4 Nov 2024 11:20:54 -0600 Subject: [PATCH 19/40] apply some more changea --- code/logic/benchmark.c | 7 +++++++ code/logic/fossil/test/assume.h | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/code/logic/benchmark.c b/code/logic/benchmark.c index 7ac1064c..820d4815 100644 --- a/code/logic/benchmark.c +++ b/code/logic/benchmark.c @@ -22,6 +22,13 @@ #include #include +#ifndef _WIN32 +#include +#include +#else +#include +#endif + // // local types // diff --git a/code/logic/fossil/test/assume.h b/code/logic/fossil/test/assume.h index 85b8e19b..f699c264 100644 --- a/code/logic/fossil/test/assume.h +++ b/code/logic/fossil/test/assume.h @@ -29,6 +29,15 @@ extern "C" { #endif +// becuase Microsoft had to be diffrent +#ifdef _WIN32 +#define wcsncasecmp _wcsnicmp +#endif + +// Used in floating-point asserts +#define FOSSIL_TEST_FLOAT_EPSILON 1e-6 +#define FOSSIL_TEST_DOUBLE_EPSILON 1e-9 + // ************************************************** // // Boolean ASSUMEions From a4fff3319ae67de8df288756e7ca1ccbed4e9fd9 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 4 Nov 2024 11:44:07 -0600 Subject: [PATCH 20/40] apply some more changes --- code/logic/benchmark.c | 7 +++---- code/logic/fossil/test/unittest.h | 3 --- code/logic/unittest.c | 21 --------------------- 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/code/logic/benchmark.c b/code/logic/benchmark.c index 820d4815..e8e011f5 100644 --- a/code/logic/benchmark.c +++ b/code/logic/benchmark.c @@ -22,11 +22,10 @@ #include #include -#ifndef _WIN32 -#include -#include -#else +#if defined(_WIN32) #include +#elif defined(__APPLE__) +#define _GNU_SOURCE // Define _GNU_SOURCE for C code #endif // diff --git a/code/logic/fossil/test/unittest.h b/code/logic/fossil/test/unittest.h index 71e864e1..2163a691 100644 --- a/code/logic/fossil/test/unittest.h +++ b/code/logic/fossil/test/unittest.h @@ -195,9 +195,6 @@ void fossil_test_register_suite(test_suite_t *suite); .suite_setup_func = suite_name##_setup_func, \ .suite_teardown_func = suite_name##_teardown_func, \ .next = NULL \ - }; \ - __attribute__((constructor)) static void register_##suite_name() { \ - fossil_test_register_suite(&suite_name); \ } // Macro to add a test case to a suite diff --git a/code/logic/unittest.c b/code/logic/unittest.c index a77c10a3..a14cc193 100644 --- a/code/logic/unittest.c +++ b/code/logic/unittest.c @@ -55,19 +55,6 @@ void fossil_test_summary(void) { printf(" Unexpected: %d\n", unexpected_count); } -// Register a test suite by adding it to the global list -void fossil_test_register_suite(test_suite_t *suite) { - if (global_test_suites == NULL) { - global_test_suites = suite; - } else { - test_suite_t *current = global_test_suites; - while (current->next != NULL) { - current = current->next; - } - current->next = suite; - } -} - // Add a test case to the double-ended priority queue void fossil_test_add_case(double_ended_priority_queue_t *queue, test_case_t *test) { if (queue->back == NULL) { @@ -216,11 +203,3 @@ void fossil_test_register_suite(test_suite_t *suite) { printf("Registered test suite: %s\n", suite->name); } - -void fossil_test_assume(bool condition, const char *message, const char *file, int line, const char *func) { - if (!condition) { - fprintf(stderr, "ASSUMPTION FAILED: %s\nFile: %s, Line: %d, Function: %s\n", message, file, line, func); - // Increment the unexpected count for reporting - unexpected_count++; - } -} From c5b057628ebfd62e31db8419ce9fb7b65d263b71 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 4 Nov 2024 12:13:37 -0600 Subject: [PATCH 21/40] apply some changes --- code/logic/fossil/test/unittest.h | 2 +- code/tests/test_bdd.c | 21 ++- code/tests/test_tdd.c | 269 +++--------------------------- 3 files changed, 38 insertions(+), 254 deletions(-) diff --git a/code/logic/fossil/test/unittest.h b/code/logic/fossil/test/unittest.h index 2163a691..d7215024 100644 --- a/code/logic/fossil/test/unittest.h +++ b/code/logic/fossil/test/unittest.h @@ -219,7 +219,7 @@ void fossil_test_register_suite(test_suite_t *suite); { \ test_suite_t *suites = global_test_suites; \ while (suites != NULL) { \ - fossil_test_run_suite(suite); \ + fossil_test_run_suite(suites); \ suites = suites->next; \ } \ } diff --git a/code/tests/test_bdd.c b/code/tests/test_bdd.c index 4af5e00b..7ba83cb7 100644 --- a/code/tests/test_bdd.c +++ b/code/tests/test_bdd.c @@ -21,7 +21,18 @@ // mock objects are set here. // * * * * * * * * * * * * * * * * * * * * * * * * -// placeholder +// Setup function for the test suite +FOSSIL_SETUP(bdd_suite) { + // Setup code here +} + +// Teardown function for the test suite +FOSSIL_TEARDOWN(bdd_suite) { + // Teardown code here +} + +// Define the test suite and add test cases +FOSSIL_TEST_SUITE(bdd_suite); // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Cases @@ -130,8 +141,8 @@ FOSSIL_TEST_CASE(xbdd_valid_login) { // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * FOSSIL_TEST_GROUP(bdd_test_group) { - ADD_TEST(xbdd_logic_test); - ADD_TEST(xbdd_user_account); - ADD_TEST(xbdd_empty_cart); - ADD_TEST(xbdd_valid_login); + FOSSIL_TEST_ADD(bdd_suite, xbdd_logic_test); + FOSSIL_TEST_ADD(bdd_suite, xbdd_user_account); + FOSSIL_TEST_ADD(bdd_suite, xbdd_empty_cart); + FOSSIL_TEST_ADD(bdd_suite, xbdd_valid_login); } // end of group diff --git a/code/tests/test_tdd.c b/code/tests/test_tdd.c index efee8e68..4b52e0e9 100644 --- a/code/tests/test_tdd.c +++ b/code/tests/test_tdd.c @@ -14,10 +14,6 @@ */ #include -// list of include headers that extends -// the framework assertion collection. -#include - // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Utilites // * * * * * * * * * * * * * * * * * * * * * * * * @@ -25,7 +21,18 @@ // mock objects are set here. // * * * * * * * * * * * * * * * * * * * * * * * * -// placeholder +// Setup function for the test suite +FOSSIL_TEST_SETUP(tdd_suite) { + // Setup code here +} + +// Teardown function for the test suite +FOSSIL_TEST_TEARDOWN(tdd_suite) { + // Teardown code here +} + +// Define the test suite and add test cases +FOSSIL_TEST_SUITE(tdd_suite); // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Cases @@ -35,114 +42,6 @@ // as samples for library usage. // * * * * * * * * * * * * * * * * * * * * * * * * -FOSSIL_TEST_CASE(xassert_run_of_int) { - int x = 42; - int y = 20; - - // Test cases - FOSSIL_TEST_ASSUME(x == 42, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y == 20, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(x != y, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y < x, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y <= x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST_CASE(xassert_run_of_int8) { - int8_t x = 42; - int8_t y = 20; - - // Test cases - FOSSIL_TEST_ASSUME((int8_t)x == 42, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int8_t)y == 20, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int8_t)x != (int8_t)y, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int8_t)y < (int8_t)x, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int8_t)y <= (int8_t)x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST_CASE(xassert_run_of_int16) { - int16_t x = 42; - int16_t y = 20; - - // Test cases - FOSSIL_TEST_ASSUME((int16_t)x == 42, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int16_t)y == 20, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int16_t)x != (int16_t)y, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int16_t)y < (int16_t)x, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int16_t)y <= (int16_t)x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST_CASE(xassert_run_of_int32) { - int32_t x = 42; - int32_t y = 20; - - // Test cases - FOSSIL_TEST_ASSUME((int32_t)x == 42, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int32_t)y == 20, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int32_t)x != (int32_t)y, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int32_t)y < (int32_t)x, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int32_t)y <= (int32_t)x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST_CASE(xassert_run_of_int64) { - int64_t x = 42; - int64_t y = 20; - - // Test cases - FOSSIL_TEST_ASSUME((int64_t)x == 42, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int64_t)y == 20, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int64_t)x != (int64_t)y, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int64_t)y < (int64_t)x, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int64_t)y <= (int64_t)x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST_CASE(xassert_run_of_int8_shortcut) { - int8_t x = 42; - int8_t y = 20; - - // Test cases - ASSERT_ITS_EQUAL_I8((int8_t)x, 42); - ASSERT_ITS_EQUAL_I8((int8_t)y, 20); - ASSERT_NOT_EQUAL_I8((int8_t)x, (int8_t)y); - ASSERT_ITS_LESS_THAN_I8((int8_t)y, (int8_t)x); - ASSERT_ITS_LESS_OR_EQUAL_I8((int8_t)y, (int8_t)x); -} // end case - -FOSSIL_TEST_CASE(xassert_run_of_int16_shortcut) { - int16_t x = 42; - int16_t y = 20; - - // Test cases - ASSERT_ITS_EQUAL_I16((int16_t)x, 42); - ASSERT_ITS_EQUAL_I16((int16_t)y, 20); - ASSERT_NOT_EQUAL_I16((int16_t)x, (int16_t)y); - ASSERT_ITS_LESS_THAN_I16((int16_t)y, (int16_t)x); - ASSERT_ITS_LESS_OR_EQUAL_I16((int16_t)y, (int16_t)x); -} // end case - -FOSSIL_TEST_CASE(xassert_run_of_int32_shortcut) { - int32_t x = 42; - int32_t y = 20; - - // Test cases - ASSERT_ITS_EQUAL_I32((int32_t)x, 42); - ASSERT_ITS_EQUAL_I32((int32_t)y, 20); - ASSERT_NOT_EQUAL_I32((int32_t)x, (int32_t)y); - ASSERT_ITS_LESS_THAN_I32((int32_t)y, (int32_t)x); - ASSERT_ITS_LESS_OR_EQUAL_I32((int32_t)y, (int32_t)x); -} // end case - -FOSSIL_TEST_CASE(xassert_run_of_int64_shortcut) { - int64_t x = 42; - int64_t y = 20; - - // Test cases - ASSERT_ITS_EQUAL_I64((int64_t)x, 42); - ASSERT_ITS_EQUAL_I64((int64_t)y, 20); - ASSERT_NOT_EQUAL_I64((int64_t)x, (int64_t)y); - ASSERT_ITS_LESS_THAN_I64((int64_t)y, (int64_t)x); - ASSERT_ITS_LESS_OR_EQUAL_I64((int64_t)y, (int64_t)x); -} // end case - FOSSIL_TEST_CASE(xassume_run_of_int) { int x = 42; int y = 20; @@ -251,143 +150,17 @@ FOSSIL_TEST_CASE(xassume_run_of_int64_shortcut) { ASSUME_ITS_LESS_OR_EQUAL_I64((int64_t)y, (int64_t)x); } // end case -FOSSIL_TEST_CASE(xexpect_run_of_int) { - int x = 42; - int y = 20; - - // Test cases - FOSSIL_TEST_ASSUME(x == 42, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y == 20, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(x != y, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y < x, "Should have passed the test case"); - FOSSIL_TEST_ASSUME(y <= x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST_CASE(xexpect_run_of_int8) { - int8_t x = 42; - int8_t y = 20; - - // Test cases - FOSSIL_TEST_ASSUME((int8_t)x == 42, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int8_t)y == 20, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int8_t)x != (int8_t)y, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int8_t)y < (int8_t)x, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int8_t)y <= (int8_t)x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST_CASE(xexpect_run_of_int16) { - int16_t x = 42; - int16_t y = 20; - - // Test cases - FOSSIL_TEST_ASSUME((int16_t)x == 42, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int16_t)y == 20, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int16_t)x != (int16_t)y, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int16_t)y < (int16_t)x, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int16_t)y <= (int16_t)x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST_CASE(xexpect_run_of_int32) { - int32_t x = 42; - int32_t y = 20; - - // Test cases - FOSSIL_TEST_ASSUME((int32_t)x == 42, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int32_t)y == 20, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int32_t)x != (int32_t)y, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int32_t)y < (int32_t)x, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int32_t)y <= (int32_t)x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST_CASE(xexpect_run_of_int64) { - int64_t x = 42; - int64_t y = 20; - - // Test cases - FOSSIL_TEST_ASSUME((int64_t)x == 42, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int64_t)y == 20, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int64_t)x != (int64_t)y, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int64_t)y < (int64_t)x, "Should have passed the test case"); - FOSSIL_TEST_ASSUME((int64_t)y <= (int64_t)x, "Should have passed the test case"); -} // end case - -FOSSIL_TEST_CASE(xexpect_run_of_int8_shortcut) { - int8_t x = 42; - int8_t y = 20; - - // Test cases - EXPECT_ITS_EQUAL_I8((int8_t)x, 42); - EXPECT_ITS_EQUAL_I8((int8_t)y, 20); - EXPECT_NOT_EQUAL_I8((int8_t)x, (int8_t)y); - EXPECT_ITS_LESS_THAN_I8((int8_t)y, (int8_t)x); - EXPECT_ITS_LESS_OR_EQUAL_I8((int8_t)y, (int8_t)x); -} // end case - -FOSSIL_TEST_CASE(xexpect_run_of_int16_shortcut) { - int16_t x = 42; - int16_t y = 20; - - // Test cases - EXPECT_ITS_EQUAL_I16((int16_t)x, 42); - EXPECT_ITS_EQUAL_I16((int16_t)y, 20); - EXPECT_NOT_EQUAL_I16((int16_t)x, (int16_t)y); - EXPECT_ITS_LESS_THAN_I16((int16_t)y, (int16_t)x); - EXPECT_ITS_LESS_OR_EQUAL_I16((int16_t)y, (int16_t)x); -} // end case - -FOSSIL_TEST_CASE(xexpect_run_of_int32_shortcut) { - int32_t x = 42; - int32_t y = 20; - - // Test cases - EXPECT_ITS_EQUAL_I32((int32_t)x, 42); - EXPECT_ITS_EQUAL_I32((int32_t)y, 20); - EXPECT_NOT_EQUAL_I32((int32_t)x, (int32_t)y); - EXPECT_ITS_LESS_THAN_I32((int32_t)y, (int32_t)x); - EXPECT_ITS_LESS_OR_EQUAL_I32((int32_t)y, (int32_t)x); -} // end case - -FOSSIL_TEST_CASE(xexpect_run_of_int64_shortcut) { - int64_t x = 42; - int64_t y = 20; - - // Test cases - EXPECT_ITS_EQUAL_I64((int64_t)x, 42); - EXPECT_ITS_EQUAL_I64((int64_t)y, 20); - EXPECT_NOT_EQUAL_I64((int64_t)x, (int64_t)y); - EXPECT_ITS_LESS_THAN_I64((int64_t)y, (int64_t)x); - EXPECT_ITS_LESS_OR_EQUAL_I64((int64_t)y, (int64_t)x); -} // end case - // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * FOSSIL_TEST_GROUP(tdd_test_group) { - ADD_TEST(xassert_run_of_int); - ADD_TEST(xassert_run_of_int8); - ADD_TEST(xassert_run_of_int16); - ADD_TEST(xassert_run_of_int32); - ADD_TEST(xassert_run_of_int64); - ADD_TEST(xassert_run_of_int8_shortcut); - ADD_TEST(xassert_run_of_int16_shortcut); - ADD_TEST(xassert_run_of_int32_shortcut); - ADD_TEST(xassert_run_of_int64_shortcut); - ADD_TEST(xassume_run_of_int); - ADD_TEST(xassume_run_of_int8); - ADD_TEST(xassume_run_of_int16); - ADD_TEST(xassume_run_of_int32); - ADD_TEST(xassume_run_of_int64); - ADD_TEST(xassume_run_of_int8_shortcut); - ADD_TEST(xassume_run_of_int16_shortcut); - ADD_TEST(xassume_run_of_int32_shortcut); - ADD_TEST(xassume_run_of_int64_shortcut); - ADD_TEST(xexpect_run_of_int); - ADD_TEST(xexpect_run_of_int8); - ADD_TEST(xexpect_run_of_int16); - ADD_TEST(xexpect_run_of_int32); - ADD_TEST(xexpect_run_of_int64); - ADD_TEST(xexpect_run_of_int8_shortcut); - ADD_TEST(xexpect_run_of_int16_shortcut); - ADD_TEST(xexpect_run_of_int32_shortcut); - ADD_TEST(xexpect_run_of_int64_shortcut); + FOSSIL_TEST_ADD(tdd_suite, xassume_run_of_int); + FOSSIL_TEST_ADD(tdd_suite, xassume_run_of_int8); + FOSSIL_TEST_ADD(tdd_suite, xassume_run_of_int16); + FOSSIL_TEST_ADD(tdd_suite, xassume_run_of_int32); + FOSSIL_TEST_ADD(tdd_suite, xassume_run_of_int64); + FOSSIL_TEST_ADD(tdd_suite, xassume_run_of_int8_shortcut); + FOSSIL_TEST_ADD(tdd_suite, xassume_run_of_int16_shortcut); + FOSSIL_TEST_ADD(tdd_suite, xassume_run_of_int32_shortcut); + FOSSIL_TEST_ADD(tdd_suite, xassume_run_of_int64_shortcut); } // end of group From e7abc7760e1d8d6a681449ef9538bee54532219d Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 4 Nov 2024 12:21:31 -0600 Subject: [PATCH 22/40] ensure test suites are flexable --- code/logic/fossil/test/unittest.h | 2 ++ code/tests/test_bdd.c | 6 +++--- code/tests/test_tdd.c | 10 +++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/code/logic/fossil/test/unittest.h b/code/logic/fossil/test/unittest.h index d7215024..ed6dbc48 100644 --- a/code/logic/fossil/test/unittest.h +++ b/code/logic/fossil/test/unittest.h @@ -188,6 +188,8 @@ void fossil_test_register_suite(test_suite_t *suite); // Macro to create a test suite with setup and teardown hooks #define _FOSSIL_TEST_SUITE(suite_name) \ + void suite_name##_setup_func(void); \ + void suite_name##_teardown_func(void); \ test_suite_t suite_name = { \ .name = #suite_name, \ .tests = NULL, \ diff --git a/code/tests/test_bdd.c b/code/tests/test_bdd.c index 7ba83cb7..1597f6ec 100644 --- a/code/tests/test_bdd.c +++ b/code/tests/test_bdd.c @@ -21,6 +21,9 @@ // mock objects are set here. // * * * * * * * * * * * * * * * * * * * * * * * * +// Define the test suite and add test cases +FOSSIL_TEST_SUITE(bdd_suite); + // Setup function for the test suite FOSSIL_SETUP(bdd_suite) { // Setup code here @@ -31,9 +34,6 @@ FOSSIL_TEARDOWN(bdd_suite) { // Teardown code here } -// Define the test suite and add test cases -FOSSIL_TEST_SUITE(bdd_suite); - // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Cases // * * * * * * * * * * * * * * * * * * * * * * * * diff --git a/code/tests/test_tdd.c b/code/tests/test_tdd.c index 4b52e0e9..36c95b65 100644 --- a/code/tests/test_tdd.c +++ b/code/tests/test_tdd.c @@ -21,19 +21,19 @@ // mock objects are set here. // * * * * * * * * * * * * * * * * * * * * * * * * +// Define the test suite and add test cases +FOSSIL_TEST_SUITE(tdd_suite); + // Setup function for the test suite -FOSSIL_TEST_SETUP(tdd_suite) { +FOSSIL_SETUP(tdd_suite) { // Setup code here } // Teardown function for the test suite -FOSSIL_TEST_TEARDOWN(tdd_suite) { +FOSSIL_TEARDOWN(tdd_suite) { // Teardown code here } -// Define the test suite and add test cases -FOSSIL_TEST_SUITE(tdd_suite); - // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Cases // * * * * * * * * * * * * * * * * * * * * * * * * From 00c80a3c1d3ef0f0b6eaf28c413e5962c59c1777 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 4 Nov 2024 12:53:26 -0600 Subject: [PATCH 23/40] fixing up benchmark --- code/logic/benchmark.c | 73 ++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/code/logic/benchmark.c b/code/logic/benchmark.c index e8e011f5..3445b975 100644 --- a/code/logic/benchmark.c +++ b/code/logic/benchmark.c @@ -25,7 +25,22 @@ #if defined(_WIN32) #include #elif defined(__APPLE__) -#define _GNU_SOURCE // Define _GNU_SOURCE for C code +#include +#else +#include +#include +#endif + +#if defined(__APPLE__) && !defined(CLOCK_MONOTONIC) +#include +#endif + +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 199309L +#endif + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE #endif // @@ -39,46 +54,40 @@ static double frequency; // Variable to store the frequency for Windows void fossil_test_start_benchmark(void) { #if defined(_WIN32) - LARGE_INTEGER freq; - if (!QueryPerformanceFrequency(&freq)) { - // Handle error - fprintf(stderr, "Error: QueryPerformanceFrequency failed\n"); - exit(EXIT_FAILURE); - } - frequency = (double)freq.QuadPart; - if (!QueryPerformanceCounter((LARGE_INTEGER*)&start_time)) { - // Handle error - fprintf(stderr, "Error: QueryPerformanceCounter failed\n"); - exit(EXIT_FAILURE); - } -#else + QueryPerformanceFrequency(&frequency); + QueryPerformanceCounter(&start_time); +#elif defined(__APPLE__) + start_time = mach_absolute_time(); +#elif defined(_POSIX_VERSION) struct timespec ts; - if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) { - // Handle error - perror("Error: clock_gettime failed"); - exit(EXIT_FAILURE); - } + clock_gettime(CLOCK_MONOTONIC, &ts); start_time = ts.tv_sec * 1e9 + ts.tv_nsec; +#else + struct timeval tv; + gettimeofday(&tv, NULL); + start_time = (uint64_t)tv.tv_sec * 1e6 + tv.tv_usec; #endif } uint64_t fossil_test_stop_benchmark(void) { #if defined(_WIN32) LARGE_INTEGER end_time; - if (!QueryPerformanceCounter(&end_time)) { - // Handle error - fprintf(stderr, "Error: QueryPerformanceCounter failed\n"); - exit(EXIT_FAILURE); - } - return (uint64_t)((end_time.QuadPart - start_time) * 1e9 / frequency); -#else + QueryPerformanceCounter(&end_time); + return (uint64_t)((end_time.QuadPart - start_time.QuadPart) * 1e9 / frequency.QuadPart); +#elif defined(__APPLE__) + uint64_t end_time = mach_absolute_time(); + mach_timebase_info_data_t timebase; + mach_timebase_info(&timebase); + return (end_time - start_time) * timebase.numer / timebase.denom; +#elif defined(_POSIX_VERSION) struct timespec ts; - if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) { - // Handle error - perror("Error: clock_gettime failed"); - exit(EXIT_FAILURE); - } - return (uint64_t)((ts.tv_sec * 1e9 + ts.tv_nsec) - start_time); + clock_gettime(CLOCK_MONOTONIC, &ts); + return (ts.tv_sec * 1e9 + ts.tv_nsec) - start_time; +#else + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t end_time = (uint64_t)tv.tv_sec * 1e6 + tv.tv_usec; + return (end_time - start_time) * 1e3; #endif } From 8760702c8cf0325153bffadae1facd4631aa620f Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 4 Nov 2024 13:09:10 -0600 Subject: [PATCH 24/40] add missing varibles --- code/logic/benchmark.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/logic/benchmark.c b/code/logic/benchmark.c index 3445b975..d338b4bf 100644 --- a/code/logic/benchmark.c +++ b/code/logic/benchmark.c @@ -24,6 +24,8 @@ #if defined(_WIN32) #include +static LARGE_INTEGER frequency; +static LARGE_INTEGER start_time; #elif defined(__APPLE__) #include #else From 19b296accb85203fdbf636708d792c96b5f987fb Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 4 Nov 2024 13:30:01 -0600 Subject: [PATCH 25/40] add CLI handling --- code/logic/fossil/test/framework.h | 14 +--- code/logic/fossil/test/unittest.h | 31 +++++++- code/logic/unittest.c | 115 +++++++++++++++++++++++++--- code/tests/tools/generate-runner.py | 4 +- 4 files changed, 138 insertions(+), 26 deletions(-) diff --git a/code/logic/fossil/test/framework.h b/code/logic/fossil/test/framework.h index ef49a1a8..1e489500 100644 --- a/code/logic/fossil/test/framework.h +++ b/code/logic/fossil/test/framework.h @@ -72,23 +72,13 @@ extern "C" { #define FOSSIL_TEST_IMPORT(name) \ _FOSSIL_TEST_IMPORT(name) -/** - * Macro to define the main test runner. - * This macro is used to define the main test runner function that will be - * executed when the test suite is run. The main test runner function will - * initialize the test framework, run all test cases, and output the test - * results. - */ -#define FOSSIL_TEST_MAIN() \ - _FOSSIL_TEST_MAIN() - /** * Macro to start the test runner. * This macro is used to start the test runner, which will initialize the test * framework and prepare to run all test cases in the test suite. */ -#define FOSSIL_TEST_START() \ - _FOSSIL_TEST_START() +#define FOSSIL_TEST_START(argc, argv) \ + _FOSSIL_TEST_START(argc, argv) /** * Macro to run all test cases in the test suite. diff --git a/code/logic/fossil/test/unittest.h b/code/logic/fossil/test/unittest.h index ed6dbc48..ef220f80 100644 --- a/code/logic/fossil/test/unittest.h +++ b/code/logic/fossil/test/unittest.h @@ -28,6 +28,27 @@ extern "C" { #endif +// Define the structure to hold parsed options +typedef struct { + bool show_version; + bool show_help; + bool show_tip; + bool show_info; + bool show_author; + bool only_tags; + char only_tags_value[256]; + bool reverse; + bool repeat_enabled; + int repeat_count; + bool shuffle_enabled; + bool verbose_enabled; + int verbose_level; // 0 for cutback, 1 for normal, 2 for verbose + bool list_tests; + bool summary_enabled; + bool color_enabled; + bool sanity_enabled; +} fossil_options_t; + // Test status enumeration typedef enum { test_status_pass, @@ -81,6 +102,7 @@ extern int fail_count; extern int skip_count; extern int unexpected_count; extern jmp_buf env; +extern fossil_options_t global_options; // List to store all test suites extern test_suite_t *global_test_suites; @@ -91,8 +113,11 @@ extern test_suite_t *global_test_suites; /** * Initialize the test framework. + * + * @param argc The number of command-line arguments. + * @param argv The command-line arguments. */ -void fossil_test_init(void); +void fossil_test_init(int argc, char **argv); /** * Clean up the test framework. @@ -214,8 +239,8 @@ void fossil_test_register_suite(test_suite_t *suite); // main runner managment -#define _FOSSIL_TEST_START() \ - fossil_test_init() +#define _FOSSIL_TEST_START(argc, argv) \ + fossil_test_init(argc, argv) #define _FOSSIL_TEST_RUN() \ { \ diff --git a/code/logic/unittest.c b/code/logic/unittest.c index a14cc193..9552d95b 100644 --- a/code/logic/unittest.c +++ b/code/logic/unittest.c @@ -14,6 +14,17 @@ */ #include "fossil/test/unittest.h" +// Global variables for tracking test results +int pass_count = 0; +int fail_count = 0; +int skip_count = 0; +int unexpected_count = 0; +fossil_options_t global_options; +jmp_buf env; + +// Global list to store all test suites +test_suite_t *global_test_suites = NULL; + char *_custom_fossil_test_strdup(const char *str) { size_t len = strlen(str) + 1; char *new_str = (char *)malloc(len); @@ -24,18 +35,104 @@ char *_custom_fossil_test_strdup(const char *str) { return new_str; } -// Global variables for tracking test results -int pass_count = 0; -int fail_count = 0; -int skip_count = 0; -int unexpected_count = 0; -jmp_buf env; +// Initialize the options structure +fossil_options_t init_options(void) { + fossil_options_t options; + options.show_version = false; + options.show_help = false; + options.show_tip = false; + options.show_info = false; + options.show_author = false; + options.only_tags = false; + options.reverse = false; + options.repeat_enabled = false; + options.repeat_count = 1; + options.shuffle_enabled = false; + options.verbose_enabled = false; + options.verbose_level = 1; + options.list_tests = false; + options.summary_enabled = false; + options.color_enabled = false; + options.sanity_enabled = false; + return options; +} -// Global list to store all test suites -test_suite_t *global_test_suites = NULL; +// Parse command-line arguments +fossil_options_t fossil_options_parse(int argc, char **argv) { + fossil_options_t options = init_options(); + + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i], "--version") == 0) { + options.show_version = true; + } else if (strcmp(argv[i], "--help") == 0) { + options.show_help = true; + } else if (strcmp(argv[i], "--tip") == 0) { + options.show_tip = true; + } else if (strcmp(argv[i], "--info") == 0) { + options.show_info = true; + } else if (strcmp(argv[i], "--author") == 0) { + options.show_author = true; + } else if (strcmp(argv[i], "only") == 0) { + options.only_tags = true; + if (i + 1 < argc && argv[i + 1][0] != '-') { + strcpy(options.only_tags_value, argv[i + 1]); + i++; + } + } else if (strcmp(argv[i], "reverse") == 0) { + if (i + 1 < argc && strcmp(argv[i + 1], "enable") == 0) { + options.reverse = true; + } else if (i + 1 < argc && strcmp(argv[i + 1], "disable") == 0) { + options.reverse = false; + } + } else if (strcmp(argv[i], "repeat") == 0) { + options.repeat_enabled = true; + if (i + 1 < argc && argv[i + 1][0] != '-') { + options.repeat_count = atoi(argv[i + 1]); + i++; + } + } else if (strcmp(argv[i], "shuffle") == 0) { + if (i + 1 < argc && strcmp(argv[i + 1], "enable") == 0) { + options.shuffle_enabled = true; + } else if (i + 1 < argc && strcmp(argv[i + 1], "disable") == 0) { + options.shuffle_enabled = false; + } + } else if (strcmp(argv[i], "verbose") == 0) { + options.verbose_enabled = true; + if (i + 1 < argc && strcmp(argv[i + 1], "cutback") == 0) { + options.verbose_level = 0; + } else if (i + 1 < argc && strcmp(argv[i + 1], "verbose") == 0) { + options.verbose_level = 2; + } + } else if (strcmp(argv[i], "list") == 0) { + options.list_tests = true; + } else if (strcmp(argv[i], "summary") == 0) { + if (i + 1 < argc && strcmp(argv[i + 1], "enable") == 0) { + options.summary_enabled = true; + } else if (i + 1 < argc && strcmp(argv[i + 1], "disable") == 0) { + options.summary_enabled = false; + } + } else if (strcmp(argv[i], "color") == 0) { + if (i + 1 < argc && strcmp(argv[i + 1], "enable") == 0) { + options.color_enabled = true; + } else if (i + 1 < argc && strcmp(argv[i + 1], "disable") == 0) { + options.color_enabled = false; + } + } else if (strcmp(argv[i], "sanity") == 0) { + if (i + 1 < argc && strcmp(argv[i + 1], "enable") == 0) { + options.sanity_enabled = true; + } else if (i + 1 < argc && strcmp(argv[i + 1], "disable") == 0) { + options.sanity_enabled = false; + } + } + } + + return options; +} // Initialize the test framework -void fossil_test_init(void) { +void fossil_test_init(int argc, char **argv) { + fossil_options_parse(argc, argv); + pass_count = 0; fail_count = 0; skip_count = 0; diff --git a/code/tests/tools/generate-runner.py b/code/tests/tools/generate-runner.py index bf12db24..afa54ff7 100644 --- a/code/tests/tools/generate-runner.py +++ b/code/tests/tools/generate-runner.py @@ -46,8 +46,8 @@ def generate_test_runner(self, test_groups): // * * * * * * * * * * * * * * * * * * * * * * * *""" runner += """ -int main(void) { - FOSSIL_TEST_START();\n""" +int main(int argc, char **argv) { + FOSSIL_TEST_START(argc, argv);\n""" import_pools = "\n".join( [f" FOSSIL_TEST_IMPORT({group});" for group in test_groups] From be71b463736a08a3118ffab7d8fbcc3ae1358b4c Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 4 Nov 2024 14:08:45 -0600 Subject: [PATCH 26/40] add register --- code/logic/fossil/test/framework.h | 9 +++++++++ code/logic/fossil/test/unittest.h | 3 +++ code/tests/test_bdd.c | 2 ++ code/tests/test_sample.c | 2 ++ code/tests/test_tdd.c | 2 ++ 5 files changed, 18 insertions(+) diff --git a/code/logic/fossil/test/framework.h b/code/logic/fossil/test/framework.h index 1e489500..d88d30e3 100644 --- a/code/logic/fossil/test/framework.h +++ b/code/logic/fossil/test/framework.h @@ -123,6 +123,15 @@ extern "C" { #define FOSSIL_TEST_SUITE(suite_name) \ _FOSSIL_TEST_SUITE(suite_name) +/** + * Macro to register a test suite with the test framework. + * This macro is used to register a test suite with the test framework. The test + * suite will be added to the list of test suites that will be executed by the + * test runner. + */ +#define FOSSIL_TEST_REGISTER(suite) \ + _FOSSIL_TEST_REGISTER(suite) + /** * Macro to define a setup function for a test. * This macro is used to declare a setup function that will be executed before diff --git a/code/logic/fossil/test/unittest.h b/code/logic/fossil/test/unittest.h index ef220f80..97bbf715 100644 --- a/code/logic/fossil/test/unittest.h +++ b/code/logic/fossil/test/unittest.h @@ -224,6 +224,9 @@ void fossil_test_register_suite(test_suite_t *suite); .next = NULL \ } +#define _FOSSIL_TEST_REGISTER(suite) \ + fossil_test_register_suite(&suite) + // Macro to add a test case to a suite #define _FOSSIL_TEST_ADD(suite, test) \ fossil_test_add_case((suite).tests, &(test##_test_case)); diff --git a/code/tests/test_bdd.c b/code/tests/test_bdd.c index 1597f6ec..ddb0a7c0 100644 --- a/code/tests/test_bdd.c +++ b/code/tests/test_bdd.c @@ -145,4 +145,6 @@ FOSSIL_TEST_GROUP(bdd_test_group) { FOSSIL_TEST_ADD(bdd_suite, xbdd_user_account); FOSSIL_TEST_ADD(bdd_suite, xbdd_empty_cart); FOSSIL_TEST_ADD(bdd_suite, xbdd_valid_login); + + FOSSIL_TEST_REGISTER(bdd_suite); } // end of group diff --git a/code/tests/test_sample.c b/code/tests/test_sample.c index da19981a..34983dc2 100644 --- a/code/tests/test_sample.c +++ b/code/tests/test_sample.c @@ -55,4 +55,6 @@ FOSSIL_TEST_CASE(test_input_decrement) { FOSSIL_TEST_GROUP(sample_test_group) { FOSSIL_TEST_ADD(sample_suite, test_input_increment); FOSSIL_TEST_ADD(sample_suite, test_input_decrement); + + FOSSIL_TEST_REGISTER(sample_suite); } diff --git a/code/tests/test_tdd.c b/code/tests/test_tdd.c index 36c95b65..dc19182f 100644 --- a/code/tests/test_tdd.c +++ b/code/tests/test_tdd.c @@ -163,4 +163,6 @@ FOSSIL_TEST_GROUP(tdd_test_group) { FOSSIL_TEST_ADD(tdd_suite, xassume_run_of_int16_shortcut); FOSSIL_TEST_ADD(tdd_suite, xassume_run_of_int32_shortcut); FOSSIL_TEST_ADD(tdd_suite, xassume_run_of_int64_shortcut); + + FOSSIL_TEST_REGISTER(tdd_suite); } // end of group From 0e2935328ff235e742705bbb9c754c85de725cd9 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Thu, 7 Nov 2024 13:29:51 -0600 Subject: [PATCH 27/40] resolving memory issues --- code/logic/unittest.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/code/logic/unittest.c b/code/logic/unittest.c index 9552d95b..055e4d17 100644 --- a/code/logic/unittest.c +++ b/code/logic/unittest.c @@ -141,7 +141,18 @@ void fossil_test_init(int argc, char **argv) { // Cleanup after test execution void fossil_test_cleanup(void) { - // Cleanup for all test suites can be added here + while (global_test_suites != NULL) { + test_suite_t *current_suite = global_test_suites; + global_test_suites = global_test_suites->next; + + // Free all test cases in the suite + while (current_suite->tests->front != NULL) { + fossil_test_remove_front(current_suite->tests); // this already frees each test case + } + + free(current_suite->tests); + free(current_suite); + } } void fossil_test_summary(void) { @@ -178,6 +189,14 @@ void fossil_test_remove_front(double_ended_priority_queue_t *queue) { queue->front->prev = NULL; } + // Free the stack_trace frames for the test case + stack_frame_t *frame = test_to_remove->stack_trace; + while (frame != NULL) { + stack_frame_t *next = frame->next; + free(frame); + frame = next; + } + free(test_to_remove); } @@ -281,11 +300,13 @@ void fossil_test_assume(bool condition, const char *message, const char *file, i current_test->failure_message = message; stack_frame_t *frame = malloc(sizeof(stack_frame_t)); - frame->func = func; - frame->file = file; - frame->line = line; - frame->next = current_test->stack_trace; - current_test->stack_trace = frame; + if (frame) { // Ensure allocation succeeded + frame->func = func; + frame->file = file; + frame->line = line; + frame->next = current_test->stack_trace; + current_test->stack_trace = frame; + } longjmp(env, 1); } From fe5285084a96c57c1e5ce65de4cf9c8dac809a83 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Thu, 7 Nov 2024 15:40:38 -0600 Subject: [PATCH 28/40] fix impl --- code/logic/fossil/test/benchmark.h | 17 ++ code/logic/fossil/test/framework.h | 6 + code/logic/fossil/test/mockup.h | 9 ++ code/logic/fossil/test/unittest.h | 249 ++++++++++++++++------------- 4 files changed, 173 insertions(+), 108 deletions(-) diff --git a/code/logic/fossil/test/benchmark.h b/code/logic/fossil/test/benchmark.h index 27b712c9..5ac8b8a9 100644 --- a/code/logic/fossil/test/benchmark.h +++ b/code/logic/fossil/test/benchmark.h @@ -20,6 +20,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { const char* name; clock_t start_time; @@ -128,4 +132,17 @@ void fossil_test_start_benchmark(void); */ uint64_t fossil_test_stop_benchmark(void); +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus +#include +#include + +namespace fossil { + +} +#endif + #endif // FOSSIL_MARK_FRAMEWORK_H diff --git a/code/logic/fossil/test/framework.h b/code/logic/fossil/test/framework.h index d88d30e3..4c2d5d32 100644 --- a/code/logic/fossil/test/framework.h +++ b/code/logic/fossil/test/framework.h @@ -177,6 +177,12 @@ extern "C" { #define FOSSIL_TEST_ASSUME(condition, message) \ _FOSSIL_TEST_ASSUME(condition, message) +/** + * Macro to assert a condition in a test runner. + * This macro is used to assert that a specific condition is true within a test + * runner. If the condition is false, the test runner will output the specified + * message and abort the execution of the test case or test suite. + */ #define FOSSIL_TEST_ASSERT(condition, message) \ _FOSSIL_TEST_ASSUME(condition, message) diff --git a/code/logic/fossil/test/mockup.h b/code/logic/fossil/test/mockup.h index fa3d9c2c..ddb884d7 100644 --- a/code/logic/fossil/test/mockup.h +++ b/code/logic/fossil/test/mockup.h @@ -158,4 +158,13 @@ void fossil_mock_print(MockCallList *list); } #endif +#ifdef __cplusplus +#include +#include + +namespace fossil { + +} +#endif + #endif // FOSSIL_MOCK_FRAMEWORK_H diff --git a/code/logic/fossil/test/unittest.h b/code/logic/fossil/test/unittest.h index 97bbf715..ecc4e926 100644 --- a/code/logic/fossil/test/unittest.h +++ b/code/logic/fossil/test/unittest.h @@ -15,6 +15,17 @@ #ifndef FOSSIL_TEST_CORE_H #define FOSSIL_TEST_CORE_H +#define MAX_NAME_LENGTH 256 + +// Color codes +#define COLOR_RESET "\033[0m" +#define COLOR_PASS "\033[32m" // Green +#define COLOR_FAIL "\033[31m" // Red +#define COLOR_SKIP "\033[33m" // Yellow +#define COLOR_INFO "\033[34m" // Blue +#define COLOR_BDD "\033[35m" // Magenta +#define COLOR_CYAN "\033[36m" // Cyan + #include #include #include @@ -32,32 +43,19 @@ extern "C" { typedef struct { bool show_version; bool show_help; - bool show_tip; - bool show_info; - bool show_author; - bool only_tags; - char only_tags_value[256]; bool reverse; bool repeat_enabled; int repeat_count; bool shuffle_enabled; - bool verbose_enabled; - int verbose_level; // 0 for cutback, 1 for normal, 2 for verbose - bool list_tests; - bool summary_enabled; - bool color_enabled; - bool sanity_enabled; } fossil_options_t; -// Test status enumeration typedef enum { - test_status_pass, - test_status_fail, - test_status_skip, - test_status_unexpected + TEST_STATUS_PASS, + TEST_STATUS_FAIL, + TEST_STATUS_SKIP } test_status_t; -// Stack frame structure for stack traces +// Stack frame structure for tracking function call details during failures typedef struct stack_frame { const char *func; const char *file; @@ -67,120 +65,151 @@ typedef struct stack_frame { // Test case structure typedef struct test_case { - const char *name; - void (*test_func)(void); - void (*setup_func)(void); - void (*teardown_func)(void); - const char *tags; - test_status_t status; - const char *failure_message; - double execution_time; - stack_frame_t *stack_trace; - struct test_case *next; - struct test_case *prev; + const char *name; // Test case name + void (*test_func)(void); // Pointer to test function + void (*setup_func)(void); // Pointer to setup function (optional) + void (*teardown_func)(void); // Pointer to teardown function (optional) + test_status_t status; // Test status (pass, fail, skip) + const char *failure_message; // Failure message (if any) + stack_frame_t *stack_trace; // Stack trace for failures + double execution_time; // Execution time of the test + struct test_case *next; // Pointer to next test case in the list } test_case_t; -// Double-ended priority queue structure for test cases -typedef struct double_ended_priority_queue { - test_case_t *front; - test_case_t *back; -} double_ended_priority_queue_t; - -// Test suite structure with setup and teardown hooks +// Test suite structure typedef struct test_suite { - const char *name; - double_ended_priority_queue_t *tests; - double total_execution_time; - void (*suite_setup_func)(void); - void (*suite_teardown_func)(void); - struct test_suite *next; // Pointer to next suite in the global list + const char *name; // Suite name + void (*suite_setup_func)(void); // Suite setup function (optional) + void (*suite_teardown_func)(void); // Suite teardown function (optional) + double total_execution_time; // Total execution time of all test cases + test_case_t *tests; // List of test cases + struct test_suite *next; // Pointer to next suite in the list } test_suite_t; -// Global variables for test results -extern int pass_count; -extern int fail_count; -extern int skip_count; -extern int unexpected_count; -extern jmp_buf env; -extern fossil_options_t global_options; - -// List to store all test suites -extern test_suite_t *global_test_suites; +typedef struct fossil_test_env { + fossil_options_t options; + jmp_buf env; + int total_tests; + int pass_count; + int fail_count; + int skip_count; + int unexpected_count; + double total_execution_time; + test_suite_t *test_suites; +} fossil_test_env_t; // ***************************************************************************** // Function declarations // ***************************************************************************** /** - * Initialize the test framework. - * - * @param argc The number of command-line arguments. - * @param argv The command-line arguments. + * @brief Creates a new test suite. + * + * @param name The name of the test suite. + * @return A pointer to the created test suite. */ -void fossil_test_init(int argc, char **argv); +test_suite_t* fossil_test_create_suite(const char *name); /** - * Clean up the test framework. + * @brief Registers a test suite with the test environment. + * + * @param env The test environment. + * @param suite The test suite to register. */ -void fossil_test_cleanup(void); +void fossil_test_register_suite(fossil_test_env_t *env, test_suite_t *suite); /** - * Print a summary of the test results. + * @brief Adds a test case to a test suite. + * + * @param suite The test suite. + * @param test_case The test case to add. */ -void fossil_test_summary(void); +void fossil_test_add_case(test_suite_t *suite, test_case_t *test_case); /** - * Add a test case to the double-ended priority queue. - * - * @param queue The double-ended priority queue. - * @param test The test case to add. + * @brief Removes a test case from a test suite. + * + * @param suite The test suite. + * @param test_case The test case to remove. */ -void fossil_test_add_case(double_ended_priority_queue_t *queue, test_case_t *test); +void fossil_test_remove_case(test_suite_t *suite, test_case_t *test_case); /** - * Remove the front test case from the double-ended priority queue. - * - * @param queue The double-ended priority queue. + * @brief Sets up a test case. + * + * @param test_case The test case to set up. */ -void fossil_test_remove_front(double_ended_priority_queue_t *queue); +void fossil_test_case_setup(test_case_t *test_case); /** - * Remove the back test case from the double-ended priority queue. - * - * @param queue The double-ended priority queue. + * @brief Tears down a test case. + * + * @param test_case The test case to tear down. */ -void fossil_test_remove_back(double_ended_priority_queue_t *queue); +void fossil_test_case_teardown(test_case_t *test_case); /** - * Run all test cases in a test suite. - * + * @brief Runs a test case. + * + * @param test_case The test case to run. + * @param env The test environment. + */ +void fossil_test_run_case(test_case_t *test_case, fossil_test_env_t *env); + +/** + * @brief Runs all test cases in a test suite. + * * @param suite The test suite to run. + * @param env The test environment. */ -void fossil_test_run_suite(test_suite_t *suite); +void fossil_test_run_suite(test_suite_t *suite, fossil_test_env_t *env); /** - * Assert a condition in a test case. - * + * @brief Asserts a condition and prints a message if the assertion fails. + * * @param condition The condition to assert. - * @param message The failure message if the condition is false. + * @param message The message to print if the assertion fails. * @param file The file where the assertion failed. * @param line The line number where the assertion failed. * @param func The function where the assertion failed. */ -void fossil_test_assume(bool condition, const char *message, const char *file, int line, const char *func); +void fossil_test_assert_internal(bool condition, const char *message, const char *file, int line, const char *func); /** - * Register a test suite with the test framework. - * - * @param suite The test suite to register. + * @brief Initializes the test environment. + * + * @param env The test environment to initialize. + */ +void fossil_test_init(fossil_test_env_t *env, int argc, char **argv); + +/** + * @brief Prints a summary of the test results. + * + * @param env The test environment. */ -void fossil_test_register_suite(test_suite_t *suite); +void fossil_test_summary(fossil_test_env_t *env); + +/** + * @brief Runs all test suites and test cases in the test environment. + * + * @param env The test environment. + */ +void fossil_test_run_all(fossil_test_env_t *env); + +/** + * @brief Prints the stack trace. + * + * @param stack_trace The stack trace to print. + */ +void fossil_test_print_stack_trace(stack_frame_t *stack_trace); // ***************************************************************************** // Macro definitions // ***************************************************************************** -#define _FOSSIL_TEST_ASSUME(condition, message) fossil_test_assume(condition, message, __FILE__, __LINE__, __func__) +// Assertion macro to assume a condition is true +#define _FOSSIL_TEST_ASSUME(condition, message) \ + fossil_test_assert_internal((condition), (message), __FILE__, __LINE__, __func__) // Macro for defining a test case #define _FOSSIL_TEST_CASE(test_name) \ @@ -190,16 +219,15 @@ void fossil_test_register_suite(test_suite_t *suite); .test_func = test_name##_test_func, \ .setup_func = NULL, \ .teardown_func = NULL, \ - .tags = NULL, \ - .status = test_status_pass, \ + .status = TEST_STATUS_PASS, \ .failure_message = NULL, \ .execution_time = 0.0, \ .stack_trace = NULL, \ - .next = NULL, \ - .prev = NULL \ + .next = NULL \ }; \ void test_name##_test_func(void) +// Macro for defining test data structures #define _FOSSIL_TEST_DATA(name) \ typedef struct name @@ -224,56 +252,61 @@ void fossil_test_register_suite(test_suite_t *suite); .next = NULL \ } +// Macro to register a suite with the test environment #define _FOSSIL_TEST_REGISTER(suite) \ - fossil_test_register_suite(&suite) + fossil_test_register_suite(_env, &suite) // Macro to add a test case to a suite #define _FOSSIL_TEST_ADD(suite, test) \ - fossil_test_add_case((suite).tests, &(test##_test_case)); + fossil_test_add_case(&suite, &(test##_test_case)) +// Macro to define a test group, grouping tests under a common environment #define _FOSSIL_TEST_GROUP(name) \ - void name##_test_group(void) + void name##_test_group(fossil_test_env_t *_env) +// Macro to export a test group #define _FOSSIL_TEST_EXPORT(name) \ - void name##_test_group(void) + void name##_test_group(fossil_test_env_t *_env) +// Macro to import a test group into the environment #define _FOSSIL_TEST_IMPORT(name) \ - name##_test_group() + name##_test_group(&_env) -// main runner managment +// Main runner management macros +// Macro to initialize the test environment and handle command-line args #define _FOSSIL_TEST_START(argc, argv) \ - fossil_test_init(argc, argv) + fossil_test_env_t _env; \ + fossil_test_init(&_env, argc, argv) +// Macro to run all tests in the environment #define _FOSSIL_TEST_RUN() \ - { \ - test_suite_t *suites = global_test_suites; \ - while (suites != NULL) { \ - fossil_test_run_suite(suites); \ - suites = suites->next; \ - } \ - } + fossil_test_run_all(&_env) +// Macro to output a summary of the test results #define _FOSSIL_TEST_SUMMARY() \ - fossil_test_summary() + fossil_test_summary(&_env) +// Macro to clean up after all tests and exit with appropriate status code #define _FOSSIL_TEST_END() \ - fossil_test_cleanup(); \ + int fail_count = _env.fail_count; \ return fail_count > 0 ? EXIT_FAILURE : EXIT_SUCCESS +// Behavior-driven development macros for Given, When, Then structure + #define _GIVEN(description) \ if (1) { \ - printf("Given %s\n", description); \ + printf(COLOR_BDD "Given %s\n" COLOR_RESET, description); \ } #define _WHEN(description) \ if (1) { \ - printf("When %s\n", description); \ + printf(COLOR_BDD "When %s\n" COLOR_RESET, description); \ } #define _THEN(description) \ if (1) { \ - printf("Then %s\n", description); \ + printf(COLOR_BDD "Then %s\n" COLOR_RESET, description); \ } #ifdef __cplusplus From f1acb5d79c71bfb1ad2348820023058213ed2b9e Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Thu, 7 Nov 2024 15:41:00 -0600 Subject: [PATCH 29/40] strip more features --- code/logic/unittest.c | 378 +++++++++++++++++++----------------------- 1 file changed, 171 insertions(+), 207 deletions(-) diff --git a/code/logic/unittest.c b/code/logic/unittest.c index 055e4d17..826ce91f 100644 --- a/code/logic/unittest.c +++ b/code/logic/unittest.c @@ -14,16 +14,15 @@ */ #include "fossil/test/unittest.h" -// Global variables for tracking test results -int pass_count = 0; -int fail_count = 0; -int skip_count = 0; -int unexpected_count = 0; -fossil_options_t global_options; -jmp_buf env; +int pass_count; +int fail_count; +int skip_count; +int unexpected_count; -// Global list to store all test suites -test_suite_t *global_test_suites = NULL; +jmp_buf test_jump_buffer; // This will hold the jump buffer for longjmp + +// Global variable to hold the current test case (set to the current test case). +test_case_t *current_test; char *_custom_fossil_test_strdup(const char *str) { size_t len = strlen(str) + 1; @@ -40,20 +39,10 @@ fossil_options_t init_options(void) { fossil_options_t options; options.show_version = false; options.show_help = false; - options.show_tip = false; - options.show_info = false; - options.show_author = false; - options.only_tags = false; options.reverse = false; options.repeat_enabled = false; options.repeat_count = 1; options.shuffle_enabled = false; - options.verbose_enabled = false; - options.verbose_level = 1; - options.list_tests = false; - options.summary_enabled = false; - options.color_enabled = false; - options.sanity_enabled = false; return options; } @@ -66,18 +55,6 @@ fossil_options_t fossil_options_parse(int argc, char **argv) { options.show_version = true; } else if (strcmp(argv[i], "--help") == 0) { options.show_help = true; - } else if (strcmp(argv[i], "--tip") == 0) { - options.show_tip = true; - } else if (strcmp(argv[i], "--info") == 0) { - options.show_info = true; - } else if (strcmp(argv[i], "--author") == 0) { - options.show_author = true; - } else if (strcmp(argv[i], "only") == 0) { - options.only_tags = true; - if (i + 1 < argc && argv[i + 1][0] != '-') { - strcpy(options.only_tags_value, argv[i + 1]); - i++; - } } else if (strcmp(argv[i], "reverse") == 0) { if (i + 1 < argc && strcmp(argv[i + 1], "enable") == 0) { options.reverse = true; @@ -96,228 +73,215 @@ fossil_options_t fossil_options_parse(int argc, char **argv) { } else if (i + 1 < argc && strcmp(argv[i + 1], "disable") == 0) { options.shuffle_enabled = false; } - } else if (strcmp(argv[i], "verbose") == 0) { - options.verbose_enabled = true; - if (i + 1 < argc && strcmp(argv[i + 1], "cutback") == 0) { - options.verbose_level = 0; - } else if (i + 1 < argc && strcmp(argv[i + 1], "verbose") == 0) { - options.verbose_level = 2; - } - } else if (strcmp(argv[i], "list") == 0) { - options.list_tests = true; - } else if (strcmp(argv[i], "summary") == 0) { - if (i + 1 < argc && strcmp(argv[i + 1], "enable") == 0) { - options.summary_enabled = true; - } else if (i + 1 < argc && strcmp(argv[i + 1], "disable") == 0) { - options.summary_enabled = false; - } - } else if (strcmp(argv[i], "color") == 0) { - if (i + 1 < argc && strcmp(argv[i + 1], "enable") == 0) { - options.color_enabled = true; - } else if (i + 1 < argc && strcmp(argv[i + 1], "disable") == 0) { - options.color_enabled = false; - } - } else if (strcmp(argv[i], "sanity") == 0) { - if (i + 1 < argc && strcmp(argv[i + 1], "enable") == 0) { - options.sanity_enabled = true; - } else if (i + 1 < argc && strcmp(argv[i + 1], "disable") == 0) { - options.sanity_enabled = false; - } } } return options; } -// Initialize the test framework -void fossil_test_init(int argc, char **argv) { - fossil_options_parse(argc, argv); - - pass_count = 0; - fail_count = 0; - skip_count = 0; - unexpected_count = 0; +// Creates and returns a new test suite +test_suite_t* fossil_test_create_suite(const char *name) { + test_suite_t *suite = (test_suite_t*)malloc(sizeof(test_suite_t)); + suite->name = name; + suite->suite_setup_func = NULL; + suite->suite_teardown_func = NULL; + suite->tests = NULL; + suite->next = NULL; + return suite; } -// Cleanup after test execution -void fossil_test_cleanup(void) { - while (global_test_suites != NULL) { - test_suite_t *current_suite = global_test_suites; - global_test_suites = global_test_suites->next; - - // Free all test cases in the suite - while (current_suite->tests->front != NULL) { - fossil_test_remove_front(current_suite->tests); // this already frees each test case - } - - free(current_suite->tests); - free(current_suite); - } +// Registers a test suite in the environment +void fossil_test_register_suite(fossil_test_env_t *env, test_suite_t *suite) { + if (!suite) return; + suite->next = env->test_suites; + env->test_suites = suite; + printf(COLOR_INFO "Registered test suite: %s\n" COLOR_RESET, suite->name); } -void fossil_test_summary(void) { - printf("Test Summary:\n"); - printf(" Passed: %d\n", pass_count); - printf(" Failed: %d\n", fail_count); - printf(" Skipped: %d\n", skip_count); - printf(" Unexpected: %d\n", unexpected_count); -} +// Adds a test case to a suite +void fossil_test_add_case(test_suite_t *suite, test_case_t *test_case) { + if (!suite || !test_case) return; -// Add a test case to the double-ended priority queue -void fossil_test_add_case(double_ended_priority_queue_t *queue, test_case_t *test) { - if (queue->back == NULL) { - queue->front = queue->back = test; - test->next = test->prev = NULL; - } else { - queue->back->next = test; - test->prev = queue->back; - test->next = NULL; - queue->back = test; - } + test_case->next = suite->tests; + suite->tests = test_case; } -// Remove a test case from the front of the queue -void fossil_test_remove_front(double_ended_priority_queue_t *queue) { - if (queue->front == NULL) return; +// Removes and frees a test case from a suite +void fossil_test_remove_case(test_suite_t *suite, test_case_t *test_case) { + if (!suite || !test_case) return; - test_case_t *test_to_remove = queue->front; - queue->front = queue->front->next; + test_case_t *prev = NULL; + test_case_t *curr = suite->tests; - if (queue->front == NULL) { - queue->back = NULL; - } else { - queue->front->prev = NULL; + while (curr) { + if (curr == test_case) { + if (prev) { + prev->next = curr->next; + } else { + suite->tests = curr->next; + } + free(curr); + return; + } + prev = curr; + curr = curr->next; } +} - // Free the stack_trace frames for the test case - stack_frame_t *frame = test_to_remove->stack_trace; - while (frame != NULL) { - stack_frame_t *next = frame->next; - free(frame); - frame = next; +// Setup for individual test case +void fossil_test_case_setup(test_case_t *test_case) { + if (test_case && test_case->setup_func) { + test_case->setup_func(); } +} - free(test_to_remove); +// Teardown for individual test case +void fossil_test_case_teardown(test_case_t *test_case) { + if (test_case && test_case->teardown_func) { + test_case->teardown_func(); + } } -// Remove a test case from the back of the queue -void fossil_test_remove_back(double_ended_priority_queue_t *queue) { - if (queue->back == NULL) return; +// Run an individual test case +void fossil_test_run_case(test_case_t *test_case, fossil_test_env_t *env) { + if (!test_case) return; - test_case_t *test_to_remove = queue->back; - queue->back = queue->back->prev; + test_case->status = TEST_STATUS_PASS; - if (queue->back == NULL) { - queue->front = NULL; + // Run setup + fossil_test_case_setup(test_case); + + clock_t test_start_time = clock(); + if (setjmp(env->env) == 0) { + test_case->test_func(); } else { - queue->back->next = NULL; + test_case->status = TEST_STATUS_FAIL; + printf(COLOR_FAIL "FAIL: " COLOR_INFO " %s\n", test_case->name); + printf("Failure Message: %s\n" COLOR_RESET, test_case->failure_message); + } + test_case->execution_time = (double)(clock() - test_start_time) / CLOCKS_PER_SEC; + + // Run teardown + fossil_test_case_teardown(test_case); + + // Log result + if (test_case->status == TEST_STATUS_PASS) { + printf(COLOR_PASS "PASS: " COLOR_INFO " %s (%.3f seconds)\n" COLOR_RESET, test_case->name, test_case->execution_time); + } else if (test_case->status == TEST_STATUS_FAIL) { + env->fail_count++; + } else if (test_case->status == TEST_STATUS_SKIP) { + env->skip_count++; } - - free(test_to_remove); } -// Run all tests in the test suite -void fossil_test_run_suite(test_suite_t *suite) { - printf("Running tests in suite: %s\n", suite->name); - clock_t suite_start_time = clock(); +// Run all test cases in a test suite +void fossil_test_run_suite(test_suite_t *suite, fossil_test_env_t *env) { + if (!suite) return; + printf(COLOR_INFO "Running suite: %s\n" COLOR_RESET, suite->name); if (suite->suite_setup_func) { suite->suite_setup_func(); } - while (suite->tests->front != NULL) { - test_case_t *test = suite->tests->front; - test->status = test_status_pass; + double total_execution_time = 0.0; + test_case_t *current_test = suite->tests; + while (current_test) { + fossil_test_run_case(current_test, env); + total_execution_time += current_test->execution_time; + current_test = current_test->next; + } - if (test->setup_func) { - test->setup_func(); - } + if (suite->suite_teardown_func) { + suite->suite_teardown_func(); + } - clock_t test_start_time = clock(); + printf(COLOR_CYAN "Total execution time for suite %s: %.3f seconds\n" COLOR_RESET, suite->name, total_execution_time); +} - if (setjmp(env) == 0) { - test->test_func(); - } else { - test->status = test_status_fail; - unexpected_count++; - printf("FAIL: %s - %s\n", test->name, test->failure_message); +// Internal function to handle assertions +void fossil_test_assert_internal(bool condition, const char *message, const char *file, int line, const char *func) { + if (!condition) { + printf("Assertion failed: %s (%s:%d in %s)\n", message, file, line, func); + longjmp(test_jump_buffer, 1); // Jump back to test case failure handler + } +} - printf("Stack Trace:\n"); - stack_frame_t *current_frame = test->stack_trace; - while (current_frame != NULL) { - printf(" at %s (%s:%d)\n", current_frame->func, current_frame->file, current_frame->line); - current_frame = current_frame->next; - } - } +void fossil_test_run_all(fossil_test_env_t *env) { + test_suite_t *current_suite = env->test_suites; - test->execution_time = (double)(clock() - test_start_time) / CLOCKS_PER_SEC; + while (current_suite) { + fossil_test_run_suite(current_suite, env); + current_suite = current_suite->next; + } +} - if (test->teardown_func) { - test->teardown_func(); - } +void fossil_test_init(fossil_test_env_t *env, int argc, char **argv) { + env->options = fossil_options_parse(argc, argv); + env->pass_count = 0; + env->fail_count = 0; + env->skip_count = 0; + env->total_tests = 0; + env->total_execution_time = 0.0; + env->unexpected_count = 0; + env->test_suites = NULL; +} - if (test->status == test_status_pass) { - printf("PASS: %s (%.3f seconds)\n", test->name, test->execution_time); - pass_count++; - } else if (test->status == test_status_fail) { - fail_count++; - } else if (test->status == test_status_skip) { - printf("SKIP: %s\n", test->name); - skip_count++; - } +// Summary function for test results +void fossil_test_summary(fossil_test_env_t *env) { + int total_tests = 0; + int passed = 0; + int failed = 0; + int skipped = 0; + double total_time = 0.0; + + test_suite_t *suite = env->test_suites; + while (suite != NULL) { + test_case_t *test = suite->tests; + while (test != NULL) { + total_tests++; + total_time += test->execution_time; + + if (test->status == TEST_STATUS_PASS) { + passed++; + } else if (test->status == TEST_STATUS_FAIL) { + failed++; + if (test->failure_message) { + printf("Test '%s' failed: %s\n", test->name, test->failure_message); + } + } else if (test->status == TEST_STATUS_SKIP) { + skipped++; + } - stack_frame_t *frame_to_free; - while (test->stack_trace != NULL) { - frame_to_free = test->stack_trace; - test->stack_trace = test->stack_trace->next; - free(frame_to_free); + test = test->next; } - - fossil_test_remove_front(suite->tests); + suite = suite->next; } - if (suite->suite_teardown_func) { - suite->suite_teardown_func(); - } + printf(COLOR_INFO "====================================" COLOR_RESET); + printf(COLOR_INFO "\nFossil Test Summary:\n" COLOR_RESET); + printf(COLOR_INFO "====================================\n" COLOR_RESET); - suite->total_execution_time = (double)(clock() - suite_start_time) / CLOCKS_PER_SEC; - printf("Total time for suite %s: %.3f seconds\n", suite->name, suite->total_execution_time); -} + printf(COLOR_PASS "Passed: %d\n" COLOR_RESET, passed); + printf(COLOR_FAIL "Failed: %d\n" COLOR_RESET, failed); + printf(COLOR_SKIP "Skipped: %d\n" COLOR_RESET, skipped); + printf(COLOR_INFO "Total: %d tests\n" COLOR_RESET, passed + failed + skipped); -/** - * Assert a condition in a test case. - * - * @param condition The condition to assert. - * @param message The failure message if the condition is false. - * @param file The file where the assertion failed. - * @param line The line number where the assertion failed. - * @param func The function where the assertion failed. - */ -void fossil_test_assume(bool condition, const char *message, const char *file, int line, const char *func) { - if (!condition) { - test_case_t *current_test = global_test_suites->tests->back; - current_test->status = test_status_fail; - current_test->failure_message = message; - - stack_frame_t *frame = malloc(sizeof(stack_frame_t)); - if (frame) { // Ensure allocation succeeded - frame->func = func; - frame->file = file; - frame->line = line; - frame->next = current_test->stack_trace; - current_test->stack_trace = frame; - } - - longjmp(env, 1); + // Optionally, you could add the total execution time summary here + printf(COLOR_INFO "\n====================================\n" COLOR_RESET); + printf(COLOR_INFO "Total execution time: %.3f seconds\n" COLOR_RESET, env->total_execution_time); + printf(COLOR_INFO "====================================\n" COLOR_RESET); + + if (failed > 0) { + printf("Some tests failed.\n"); + } else { + printf("All tests passed.\n"); } } -void fossil_test_register_suite(test_suite_t *suite) { - if (!suite) return; // Ensure the suite is not NULL - - // Link the new suite at the front of the global list - suite->next = global_test_suites; - global_test_suites = suite; - - printf("Registered test suite: %s\n", suite->name); +void fossil_test_print_stack_trace(stack_frame_t *stack_trace) { + stack_frame_t *current_frame = stack_trace; + while (current_frame) { + printf(" at %s (%s:%d)\n", current_frame->func, current_frame->file, current_frame->line); + current_frame = current_frame->next; + } } From b6f0771b9297843589284839c55da55c7b39f5d4 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Thu, 7 Nov 2024 16:54:16 -0600 Subject: [PATCH 30/40] apply CLI methods --- README.md | 145 ++++++++---------- code/logic/fossil/test/unittest.h | 7 +- code/logic/unittest.c | 241 ++++++++++++++++++++++++++---- 3 files changed, 280 insertions(+), 113 deletions(-) diff --git a/README.md b/README.md index 902506f4..49fb9fa9 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,53 @@ # ***Fossil Test: Unit Testing/Mocking Framework*** - `C, C++` **Overview:** -Fossil Test is a robust unit testing and mocking framework developed by Fossil Logic. It is designed to facilitate the creation of high-quality test cases across any C and C++ project. The framework supports Behavior-Driven Development (BDD), Domain Driven Development (DDD), and Test-Driven Development (TDD) styles, providing a flexible and comprehensive solution for ensuring software reliability and correctness. +Fossil Test is a robust unit testing and mocking framework developed by Fossil Logic. It is designed to facilitate the creation of high-quality test cases for C and C++ projects, promoting software reliability and correctness. The framework supports various development methodologies, including Behavior-Driven Development (BDD), Domain-Driven Design (DDD), and Test-Driven Development (TDD), offering flexibility for diverse development workflows. -In addition to Fossil Test, Fossil Logic also offers two additional frameworks: Fossil Mark and Fossil Mock. Fossil Mark is a powerful benchmarking framework that allows developers to measure the performance of their code and identify areas for optimization. With built-in timing information and detailed reporting, developers can easily track the execution time of each test case and make informed decisions to improve the efficiency of their software. +In addition to Fossil Test, Fossil Logic also offers two additional frameworks to enhance your development experience: +- **Fossil Mark**: A powerful benchmarking tool that allows developers to measure code performance, identify bottlenecks, and optimize execution time. It offers detailed timing information and reporting. +- **Fossil Mock**: A mocking library enabling developers to simulate the behavior of complex dependencies. By using mock objects, you can write focused unit tests that test isolated components, enhancing test reliability and coverage. -Fossil Mock, on the other hand, provides powerful mocking capabilities that enable developers to simulate the behavior of complex dependencies. This ensures focused and reliable unit tests, as developers can create mock objects that mimic the behavior of real dependencies, allowing for thorough testing of different scenarios. +Together, Fossil Test, Fossil Mark, and Fossil Mock provide a comprehensive toolkit for developing, testing, and optimizing high-quality software. -By combining the features of Fossil Test, Fossil Mark, and Fossil Mock, developers can create robust and performant code, ensuring the quality and reliability of their software projects. +--- **Key Features:** | Feature | Description | |--------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------| -| **BDD and TDD Support** | Allows developers to write tests in both BDD and TDD styles, catering to various development and testing preferences. | -| **Unit Testing** | Provides a complete suite of tools for writing and executing unit tests, ensuring that individual units of code perform as expected. | -| **Mocking Capabilities** | Includes powerful mocking features that enable developers to simulate the behavior of complex dependencies, ensuring focused and reliable unit tests. | -| **Test Case Management** | Supports organizing and managing test cases efficiently, with features for categorizing, prioritizing, and tagging tests. | -| **Detailed Reporting** | Generates detailed reports on test execution, including information on passed, failed, skipped, and timed-out tests, helping developers quickly address issues. | -| **Performance Tracking** | Tracks the performance of each test case with built-in timing information, allowing developers to monitor and optimize test execution time. | -| **Assertion Detection** | Detects whether assertions are used within the code, ensuring that critical conditions are enforced and identifying areas that may lack proper validation. | -| **Command-Line Interface (CLI)** | Includes a powerful CLI for running tests, generating reports, and managing the test suite from the command line, enhancing automation and integration. | -| **Extensible and Configurable** | Designed to be extensible and configurable, allowing developers to tailor the framework to their specific needs, from reporting formats to tool integration.| +| **BDD, DDD, and TDD Support** | Supports Behavior-Driven, Domain-Driven, and Test-Driven Development styles, catering to various project methodologies. | +| **Comprehensive Unit Testing** | A full suite of tools for creating, managing, and executing unit tests, ensuring that individual units of code behave as expected. | +| **Mocking Capabilities** | Powerful mocking features allow developers to simulate complex dependencies, ensuring focused and reliable unit tests. | +| **Test Case Management** | Organize and manage test cases with features for categorization, prioritization, and tagging, improving test suite maintainability. | +| **Detailed Reporting** | Generates comprehensive reports on test execution, including information on passed, failed, skipped, and timed-out tests, aiding quick issue resolution. | +| **Performance Tracking** | Measures and reports the performance of each test case, helping developers optimize test execution time and performance. | +| **Assertion Detection** | Ensures that assertions are properly used in code, enforcing critical conditions and identifying potential areas lacking validation. | +| **Command-Line Interface (CLI)** | A powerful CLI for running tests, generating reports, and managing the test suite, supporting automation and integration workflows. | +| **Extensible and Configurable** | Highly extensible, allowing developers to customize the framework to their needs, from reporting formats to tool integration. | + +--- ## ***Prerequisites*** -Before getting started, make sure you have the following installed: +To get started with Fossil Test, ensure you have the following installed: -- **Meson Build System**: This project relies on Meson. If you don't have Meson installed, visit the official [Meson website](https://mesonbuild.com/Getting-meson.html) for installation instructions. +- **Meson Build System**: Fossil Test requires Meson. If you don’t have Meson installed, follow the installation instructions on the official [Meson website](https://mesonbuild.com/Getting-meson.html). -## Adding Dependency +--- -1. **Install Meson Build System**: Before integrating the dependency, ensure you have Meson `1.3` or newer installed on your host system. You can install it with this command. +### Adding Fossil Test Dependency +To integrate Fossil Test into your project, follow these steps: + +1. **Install Meson Build System**: + Install Meson version `1.3` or newer: ```sh - python -m pip install meson # to install Meson - python -m pip install --upgrade meson # to upgrade Meson + python -m pip install meson # To install Meson + python -m pip install --upgrade meson # To upgrade Meson ``` -2. **Adding Wrap File**: You can add a `.wrap` file by first navigating to the `subprojects` directory and creating `fossil-test.wrap`. Next, copy the definition into the file: +2. **Create a `.wrap` File**: + Add the `fossil-test.wrap` file in your `subprojects` directory and include the following content: ```ini # ====================== @@ -54,111 +63,89 @@ Before getting started, make sure you have the following installed: fossil-mark = fossil_mark_dep ``` -3. **Integrate the New Dependency**: After creating the dependency `.wrap` file, you need to integrate it into your Meson project. This typically involves adding the dependency to your `meson.build` file. Here's an example of how you might do that: - +3. **Integrate the Dependency**: + In your `meson.build` file, integrate Fossil Test by adding the following line: ```ini dep = dependency('fossil-test') ``` - This line retrieves the `fossil-test` dependency, allowing you to use it in your project. **Releases Page**: Head over to the [Fossil Test Releases](https://github.com/fossillogic/fossil-test/releases) to find any preferred version of the framework. For the best experience with Fossil Test, it is recommended to always use the latest release. + **Note**: For the best experience, always use the latest release of Fossil Test. Visit the [Fossil Test Releases](https://github.com/fossillogic/fossil-test/releases) page for the latest versions. + +--- ## Fossil Test CLI Usage -The Fossil Test CLI is a command-line tool designed to help you run and manage your test suite efficiently. Below are the available commands and options: +The Fossil Test CLI provides an efficient way to run and manage tests directly from the terminal. Here are the available commands and options: ### Commands and Options | Command | Description | -|---------------------------------|-----------------------------------------------------------------------------------------------| -| `--version` | Displays the version of the Fossil Test CLI. | -| `--help` | Shows the help message with usage instructions. | -| `--tip` | Provides a tip or hint about using the Fossil Test CLI. | -| `--info` | Displays information about the test runner. | -| `--author` | Shows information about the author of the test runner. | -| `only=` or `only=` | Runs only the tests tagged with the specified tag(s). Tags should be comma-separated for multiple tags. | -| `reverse [enable/disable]` | Enables or disables the reverse order of test execution. | -| `repeat=` | Repeats the test suite for the specified number of times. | -| `shuffle [enable/disable]` | Enables or disables the shuffling of test execution order. | -| `verbose [cutback/normal/verbose]` | Sets the verbosity level of the output. Options are `cutback`, `normal`, and `verbose`. | -| `list` | Lists all available tests. | -| `summary [enable/disable]` | Enables or disables the summary of test results after execution. | -| `color [enable/disable]` | Enables or disables colored output in the terminal. | -| `sanity [enable/disable]` | Enables or disables sanity checks before running the tests. | - -### Examples - -- Display version information: - +|----------------------------------|-----------------------------------------------------------------------------------------------| +| `--version` | Displays the current version of the Fossil Test CLI. | +| `--help` | Shows help message with usage instructions. | +| `--tip` | Displays a tip or hint related to the CLI usage. | +| `--info` | Displays detailed information about the test runner configuration. | +| `--author` | Shows information about the author of the test runner. | +| `only=` or `only=` | Runs only tests tagged with the specified tag(s). Tags can be comma-separated for multiple tags. | +| `reverse [enable/disable]` | Enables or disables reverse order of test execution. | +| `repeat=` | Repeats the test suite a specified number of times. | +| `shuffle [enable/disable]` | Enables or disables shuffling of test execution order. | +| `verbose [cutback/normal/verbose]` | Sets verbosity level of the output. Options are `cutback`, `normal`, and `verbose`. | +| `list` | Lists all available tests. | +| `summary [enable/disable]` | Enables or disables a summary of test results after execution. | +| `color [enable/disable]` | Enables or disables colored output in the terminal. | +| `sanity [enable/disable]` | Enables or disables sanity checks before running tests. | + +### Example Usage + +- Display the version: ```sh fossil_cli --version ``` -- Show help message: - - ```sh - fossil_cli --help - ``` - -- Run only tests tagged with "unit" and "integration": - +- Run tests tagged with `unit` and `integration`: ```sh fossil_cli only=unit,integration ``` - Enable reverse order of test execution: - ```sh fossil_cli reverse enable ``` - Repeat the test suite 5 times: - ```sh fossil_cli repeat=5 ``` -- Enable verbose output: - - ```sh - fossil_cli verbose verbose - ``` - -- List all available tests: - - ```sh - fossil_cli list - ``` - -- Enable test result summary: - +- Show a summary after execution: ```sh fossil_cli summary enable ``` - Enable colored output: - ```sh fossil_cli color enable ``` -Feel free to explore and use the various commands and options to tailor the test runner to your needs. For further assistance, refer to the `--help` command. - -## Configure Options +--- -You have options when configuring the build, each serving a different purpose: +## Configure Build Options -- **Running Tests**: To enable running tests, use `-Dwith_test=enabled` when configuring the build. - -Example: +To configure the build system with testing enabled, use the following command: ```sh meson setup builddir -Dwith_test=enabled ``` +--- + ## ***Contributing and Support*** -If you're interested in contributing to this project, encounter any issues, have questions, or would like to provide feedback, don't hesitate to open an issue or visit the [Fossil Logic Docs](https://fossillogic.com/docs) for more information. +If you would like to contribute, have questions, or need help, feel free to open an issue on the [Fossil Test GitHub repository](https://github.com/fossillogic/fossil-test) or consult the [Fossil Logic Docs](https://fossillogic.com/docs). + +--- -## ***Conclusion:*** +## ***Conclusion*** -Fossil Test is a comprehensive solution for C and C++ developers aiming to ensure the quality and reliability of their code. By supporting both BDD and TDD, along with powerful mocking, assertion detection, detailed reporting, and a robust CLI, Fossil Test empowers developers to create robust and maintainable test suites. Its flexibility and extensibility make it a valuable tool for projects of any size and complexity, fostering a culture of quality and continuous improvement. +Fossil Test is a powerful and flexible framework for C and C++ developers, designed to support a wide range of testing methodologies such as BDD, DDD, and TDD. With features like mocking, detailed reporting, and performance tracking, Fossil Test empowers developers to create high-quality software and maintainable test suites. Combined with Fossil Mark and Fossil Mock, it provides a complete suite for testing, optimization, and dependency management. Whether you're building small projects or large-scale applications, Fossil Test is an essential tool to ensure the reliability and performance of your code. diff --git a/code/logic/fossil/test/unittest.h b/code/logic/fossil/test/unittest.h index ecc4e926..ce6faea8 100644 --- a/code/logic/fossil/test/unittest.h +++ b/code/logic/fossil/test/unittest.h @@ -43,6 +43,7 @@ extern "C" { typedef struct { bool show_version; bool show_help; + bool show_info; bool reverse; bool repeat_enabled; int repeat_count; @@ -295,17 +296,17 @@ void fossil_test_print_stack_trace(stack_frame_t *stack_trace); // Behavior-driven development macros for Given, When, Then structure #define _GIVEN(description) \ - if (1) { \ + if (0) { \ printf(COLOR_BDD "Given %s\n" COLOR_RESET, description); \ } #define _WHEN(description) \ - if (1) { \ + if (0) { \ printf(COLOR_BDD "When %s\n" COLOR_RESET, description); \ } #define _THEN(description) \ - if (1) { \ + if (0) { \ printf(COLOR_BDD "Then %s\n" COLOR_RESET, description); \ } diff --git a/code/logic/unittest.c b/code/logic/unittest.c index 826ce91f..2b5a19ea 100644 --- a/code/logic/unittest.c +++ b/code/logic/unittest.c @@ -14,16 +14,48 @@ */ #include "fossil/test/unittest.h" -int pass_count; -int fail_count; -int skip_count; -int unexpected_count; +// Array of messages for each category +const char *sarcastic_messages[] = { + "Wow, no tests were run! What a productive day! 😏", + "No tests to run, guess we're all just too good at writing code. 🧐", + "Congratulations, you’ve done absolutely nothing today. 🙃", + "Oh, look! No tests were executed. What an achievement! 🥳", + "Not a single test run, but hey, that's one way to keep things perfect! 😆", + "All set for a day of zero productivity? Nice! 💤", + "The test suite is empty, but hey, at least the code didn’t break! 😜", + "Zero tests executed. Clearly, you've mastered the art of doing nothing. 😎", + "Great! We’ve made it through an entire test run without running a single test. 🥳", + "Isn’t it great when there’s nothing to test? 🙃" +}; + +const char *humorous_messages[] = { + "Well, that was an epic failure! Better luck next time! 😂", + "Whoops! Someone’s definitely gonna need to debug that. 🐞", + "Looks like someone forgot to write the test cases. 🤷‍♂️", + "Your tests failed, but at least you got closer to perfection... not. 🤦‍♂️", + "Not all heroes wear capes. Some of them fail tests. 🦸‍♂️", + "Don't worry, failure is just success in disguise. Or maybe not. 😅", + "Well, that was awkward. Let's try again, shall we? 🤔", + "Looks like we’ve encountered a bug! Hope you’ve got a magnifying glass. 🧐", + "Your tests are taking a nap, but don’t worry, we’ll wake them up! 😴", + "It’s not a failure, it’s just a learning experience! A very *expensive* one. 💸" +}; + +const char *great_news_messages[] = { + "Great news! All tests passed. You’re a testing genius! 🎉", + "Success! Everything works as expected. Go celebrate! 🥳", + "You did it! All tests passed. You’re officially a rock star! 🌟", + "Congrats, all tests passed! You’ve earned a gold star! 🏅", + "Woohoo! All tests passed with flying colors! 🎨", + "No bugs found today, you’re on fire! 🔥", + "Amazing! You’ve got a perfect test suite. Keep it up! 💪", + "Nice job! All tests passed. I think we’ve found the next coding superhero! 🦸‍♀️", + "Fantastic! No issues at all, just pure success! 😎", + "All tests passed, everything’s awesome. 🎶" +}; jmp_buf test_jump_buffer; // This will hold the jump buffer for longjmp -// Global variable to hold the current test case (set to the current test case). -test_case_t *current_test; - char *_custom_fossil_test_strdup(const char *str) { size_t len = strlen(str) + 1; char *new_str = (char *)malloc(len); @@ -39,6 +71,7 @@ fossil_options_t init_options(void) { fossil_options_t options; options.show_version = false; options.show_help = false; + options.show_info = false; options.reverse = false; options.repeat_enabled = false; options.repeat_count = 1; @@ -46,6 +79,25 @@ fossil_options_t init_options(void) { return options; } +void usage_info(void) { + printf("Usage: fossil [options] [command]\n"); + printf("Options:\n"); + printf(" --version\t\tShow version information\n"); + printf(" --help\t\tShow help information\n"); + printf(" --info\t\tShow additional information\n"); + printf("Commands:\n"); + printf(" reverse [enable|disable]\tEnable or disable reverse order of test cases\n"); + printf(" repeat [count]\t\tEnable repeat mode with optional count\n"); + printf(" shuffle [enable|disable]\tEnable or disable shuffle mode\n"); +} + +void version_info(void) { + printf("Fossil Logic Test Framework\n"); + printf("Version: 1.0.7\n"); + printf("Author: Michael Gene Brockus (Dreamer)\n"); + printf("License: Mozila Public License 2.0\n"); +} + // Parse command-line arguments fossil_options_t fossil_options_parse(int argc, char **argv) { fossil_options_t options = init_options(); @@ -55,6 +107,8 @@ fossil_options_t fossil_options_parse(int argc, char **argv) { options.show_version = true; } else if (strcmp(argv[i], "--help") == 0) { options.show_help = true; + } else if (strcmp(argv[i], "--info") == 0) { + options.show_info = true; } else if (strcmp(argv[i], "reverse") == 0) { if (i + 1 < argc && strcmp(argv[i + 1], "enable") == 0) { options.reverse = true; @@ -79,6 +133,86 @@ fossil_options_t fossil_options_parse(int argc, char **argv) { return options; } +// Function to reverse the order of test cases in the linked list +void reverse_test_cases(test_case_t **test_cases) { + if (!test_cases || !*test_cases) { + return; // No test cases to reverse + } + + test_case_t *prev = NULL; + test_case_t *current = *test_cases; + test_case_t *next = NULL; + + // Traverse the linked list and reverse the 'next' pointers + while (current) { + next = current->next; // Store the next node + current->next = prev; // Reverse the current node's pointer + prev = current; // Move prev and current one step forward + current = next; + } + + // After the loop, prev will point to the new head of the list + *test_cases = prev; +} + +// Function to shuffle test cases using the Fisher-Yates algorithm +void shuffle_test_cases(test_case_t **test_cases) { + if (!test_cases || !*test_cases) { + return; // No test cases to shuffle + } + + // Calculate the length of the linked list (number of test cases) + int n = 0; + test_case_t *current = *test_cases; + while (current) { + n++; + current = current->next; + } + + // If there is only one or zero test cases, no need to shuffle + if (n <= 1) { + return; + } + + // Create an array to hold the test cases + test_case_t **array = malloc(sizeof(test_case_t *) * n); + if (!array) { + return; // Memory allocation failed + } + + // Fill the array with the test case pointers + current = *test_cases; + for (int i = 0; i < n; i++) { + array[i] = current; + current = current->next; + } + + // Shuffle the array using the Fisher-Yates algorithm + srand(time(NULL)); // Seed the random number generator + + for (int i = n - 1; i > 0; i--) { + // Generate a random index between 0 and i + int j = rand() % (i + 1); + + // Swap the elements + test_case_t *temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } + + // Rebuild the linked list from the shuffled array + for (int i = 0; i < n - 1; i++) { + array[i]->next = array[i + 1]; + } + array[n - 1]->next = NULL; // Last test case points to NULL + + // Update the original test cases pointer + *test_cases = array[0]; + + // Free the array after use + free(array); +} + // Creates and returns a new test suite test_suite_t* fossil_test_create_suite(const char *name) { test_suite_t *suite = (test_suite_t*)malloc(sizeof(test_suite_t)); @@ -95,7 +229,9 @@ void fossil_test_register_suite(fossil_test_env_t *env, test_suite_t *suite) { if (!suite) return; suite->next = env->test_suites; env->test_suites = suite; - printf(COLOR_INFO "Registered test suite: %s\n" COLOR_RESET, suite->name); + if (env->options.show_info) { + printf(COLOR_INFO "Registered test suite: %s\n" COLOR_RESET, suite->name); + } } // Adds a test case to a suite @@ -153,7 +289,9 @@ void fossil_test_run_case(test_case_t *test_case, fossil_test_env_t *env) { clock_t test_start_time = clock(); if (setjmp(env->env) == 0) { - test_case->test_func(); + for (int i = 0; i < env->options.repeat_count; i++) { + test_case->test_func(); + } } else { test_case->status = TEST_STATUS_FAIL; printf(COLOR_FAIL "FAIL: " COLOR_INFO " %s\n", test_case->name); @@ -166,7 +304,9 @@ void fossil_test_run_case(test_case_t *test_case, fossil_test_env_t *env) { // Log result if (test_case->status == TEST_STATUS_PASS) { - printf(COLOR_PASS "PASS: " COLOR_INFO " %s (%.3f seconds)\n" COLOR_RESET, test_case->name, test_case->execution_time); + if (env->options.show_info) { + printf(COLOR_PASS "PASS: " COLOR_INFO " %s (%.3f seconds)\n" COLOR_RESET, test_case->name, test_case->execution_time); + } } else if (test_case->status == TEST_STATUS_FAIL) { env->fail_count++; } else if (test_case->status == TEST_STATUS_SKIP) { @@ -178,7 +318,18 @@ void fossil_test_run_case(test_case_t *test_case, fossil_test_env_t *env) { void fossil_test_run_suite(test_suite_t *suite, fossil_test_env_t *env) { if (!suite) return; - printf(COLOR_INFO "Running suite: %s\n" COLOR_RESET, suite->name); + if (env->options.show_info) { + printf(COLOR_INFO "Running suite: %s\n" COLOR_RESET, suite->name); + } + + if (env->options.shuffle_enabled){ + shuffle_test_cases(&suite->tests); + } + + if (env->options.reverse) { + reverse_test_cases(&suite->tests); + } + if (suite->suite_setup_func) { suite->suite_setup_func(); } @@ -195,7 +346,9 @@ void fossil_test_run_suite(test_suite_t *suite, fossil_test_env_t *env) { suite->suite_teardown_func(); } - printf(COLOR_CYAN "Total execution time for suite %s: %.3f seconds\n" COLOR_RESET, suite->name, total_execution_time); + if (env->options.show_info) { + printf(COLOR_CYAN "Total execution time for suite %s: %.3f seconds\n" COLOR_RESET, suite->name, total_execution_time); + } } // Internal function to handle assertions @@ -217,21 +370,49 @@ void fossil_test_run_all(fossil_test_env_t *env) { void fossil_test_init(fossil_test_env_t *env, int argc, char **argv) { env->options = fossil_options_parse(argc, argv); + if (env->options.show_version) { + version_info(); + exit(EXIT_SUCCESS); + } + if (env->options.show_help) { + usage_info(); + exit(EXIT_SUCCESS); + } env->pass_count = 0; env->fail_count = 0; env->skip_count = 0; env->total_tests = 0; - env->total_execution_time = 0.0; + env->total_execution_time = clock(); env->unexpected_count = 0; env->test_suites = NULL; } +// Function to generate a dynamic message based on the test results +void fossil_test_message(fossil_test_env_t *env) { + // Seed random number generator + srand(time(NULL)); + + // Sarcastic message for no tests run + if (env->pass_count == 0 && env->fail_count == 0 && env->skip_count == 0) { + printf(COLOR_INFO "%s\n" COLOR_RESET, sarcastic_messages[rand() % 10]); + } + // Humorous message for failed tests + else if (env->fail_count > 0) { + printf(COLOR_FAIL "%s\n" COLOR_RESET, humorous_messages[rand() % 10]); + } + // Great news for passed tests + else if (env->pass_count > 0) { + printf(COLOR_PASS "%s\n" COLOR_RESET, great_news_messages[rand() % 10]); + } + // Default message for mixed results + else { + printf(COLOR_INFO "Test results are in. Keep pushing, you’re getting there! 💪\n" COLOR_RESET); + } +} + // Summary function for test results void fossil_test_summary(fossil_test_env_t *env) { int total_tests = 0; - int passed = 0; - int failed = 0; - int skipped = 0; double total_time = 0.0; test_suite_t *suite = env->test_suites; @@ -242,14 +423,16 @@ void fossil_test_summary(fossil_test_env_t *env) { total_time += test->execution_time; if (test->status == TEST_STATUS_PASS) { - passed++; + env->pass_count++; } else if (test->status == TEST_STATUS_FAIL) { - failed++; + env->fail_count++; if (test->failure_message) { printf("Test '%s' failed: %s\n", test->name, test->failure_message); } } else if (test->status == TEST_STATUS_SKIP) { - skipped++; + env->skip_count++; + } else { + env->unexpected_count++; } test = test->next; @@ -261,21 +444,17 @@ void fossil_test_summary(fossil_test_env_t *env) { printf(COLOR_INFO "\nFossil Test Summary:\n" COLOR_RESET); printf(COLOR_INFO "====================================\n" COLOR_RESET); - printf(COLOR_PASS "Passed: %d\n" COLOR_RESET, passed); - printf(COLOR_FAIL "Failed: %d\n" COLOR_RESET, failed); - printf(COLOR_SKIP "Skipped: %d\n" COLOR_RESET, skipped); - printf(COLOR_INFO "Total: %d tests\n" COLOR_RESET, passed + failed + skipped); + printf(COLOR_INFO "Passed: " COLOR_PASS " %d\n" COLOR_RESET, env->pass_count); + printf(COLOR_INFO "Failed: " COLOR_FAIL " %d\n" COLOR_RESET, env->fail_count); + printf(COLOR_INFO "Skipped: " COLOR_SKIP " %d\n" COLOR_RESET, env->skip_count); + printf(COLOR_INFO "Total: %d tests\n" COLOR_RESET, env->pass_count + env->fail_count + env->skip_count); // Optionally, you could add the total execution time summary here - printf(COLOR_INFO "\n====================================\n" COLOR_RESET); - printf(COLOR_INFO "Total execution time: %.3f seconds\n" COLOR_RESET, env->total_execution_time); printf(COLOR_INFO "====================================\n" COLOR_RESET); - - if (failed > 0) { - printf("Some tests failed.\n"); - } else { - printf("All tests passed.\n"); - } + printf(COLOR_INFO "Total execution time: %.3f seconds\n" COLOR_RESET, env->total_execution_time / CLOCKS_PER_SEC); + printf(COLOR_INFO "====================================\n" COLOR_RESET); + + fossil_test_message(env); } void fossil_test_print_stack_trace(stack_frame_t *stack_trace) { From addf169afb0d79b15f0a486056a965d3f09cec45 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:01:25 -0600 Subject: [PATCH 31/40] Removed conflict variables --- code/logic/benchmark.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/code/logic/benchmark.c b/code/logic/benchmark.c index d338b4bf..497d34b3 100644 --- a/code/logic/benchmark.c +++ b/code/logic/benchmark.c @@ -45,15 +45,6 @@ static LARGE_INTEGER start_time; #define _GNU_SOURCE #endif -// -// local types -// -static uint64_t start_time; - -#if defined(_WIN32) -static double frequency; // Variable to store the frequency for Windows -#endif - void fossil_test_start_benchmark(void) { #if defined(_WIN32) QueryPerformanceFrequency(&frequency); From f440d5b4ea3f22d19661be30b2a7851732ae6093 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:14:09 -0600 Subject: [PATCH 32/40] Update benchmark.c --- code/logic/benchmark.c | 1 + 1 file changed, 1 insertion(+) diff --git a/code/logic/benchmark.c b/code/logic/benchmark.c index 497d34b3..aba65b19 100644 --- a/code/logic/benchmark.c +++ b/code/logic/benchmark.c @@ -31,6 +31,7 @@ static LARGE_INTEGER start_time; #else #include #include +clock_t start_time; #endif #if defined(__APPLE__) && !defined(CLOCK_MONOTONIC) From a7d8192951d746f7e12c071c630764106bc3f141 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:21:09 -0600 Subject: [PATCH 33/40] Removing these unused variables --- code/logic/unittest.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/code/logic/unittest.c b/code/logic/unittest.c index 2b5a19ea..a067c0bf 100644 --- a/code/logic/unittest.c +++ b/code/logic/unittest.c @@ -412,9 +412,6 @@ void fossil_test_message(fossil_test_env_t *env) { // Summary function for test results void fossil_test_summary(fossil_test_env_t *env) { - int total_tests = 0; - double total_time = 0.0; - test_suite_t *suite = env->test_suites; while (suite != NULL) { test_case_t *test = suite->tests; From 348f547eec306cfe7672ebc83a942e5578b0bc65 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:23:09 -0600 Subject: [PATCH 34/40] Update benchmark.c --- code/logic/benchmark.c | 1 + 1 file changed, 1 insertion(+) diff --git a/code/logic/benchmark.c b/code/logic/benchmark.c index aba65b19..62535ba4 100644 --- a/code/logic/benchmark.c +++ b/code/logic/benchmark.c @@ -28,6 +28,7 @@ static LARGE_INTEGER frequency; static LARGE_INTEGER start_time; #elif defined(__APPLE__) #include +clock_t start_time; #else #include #include From ce7e884bf79228cfb5898e9be21e8024f5b97ee6 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:25:33 -0600 Subject: [PATCH 35/40] Update unittest.c --- code/logic/unittest.c | 1 + 1 file changed, 1 insertion(+) diff --git a/code/logic/unittest.c b/code/logic/unittest.c index a067c0bf..64444de8 100644 --- a/code/logic/unittest.c +++ b/code/logic/unittest.c @@ -412,6 +412,7 @@ void fossil_test_message(fossil_test_env_t *env) { // Summary function for test results void fossil_test_summary(fossil_test_env_t *env) { + double total_time = 0.0; test_suite_t *suite = env->test_suites; while (suite != NULL) { test_case_t *test = suite->tests; From eed3c9b498860412a86ec52d7dff2268cead54f4 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:28:41 -0600 Subject: [PATCH 36/40] Update unittest.c --- code/logic/unittest.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/logic/unittest.c b/code/logic/unittest.c index 64444de8..5ee03c68 100644 --- a/code/logic/unittest.c +++ b/code/logic/unittest.c @@ -417,7 +417,6 @@ void fossil_test_summary(fossil_test_env_t *env) { while (suite != NULL) { test_case_t *test = suite->tests; while (test != NULL) { - total_tests++; total_time += test->execution_time; if (test->status == TEST_STATUS_PASS) { @@ -449,7 +448,7 @@ void fossil_test_summary(fossil_test_env_t *env) { // Optionally, you could add the total execution time summary here printf(COLOR_INFO "====================================\n" COLOR_RESET); - printf(COLOR_INFO "Total execution time: %.3f seconds\n" COLOR_RESET, env->total_execution_time / CLOCKS_PER_SEC); + printf(COLOR_INFO "Total execution time: %.3f seconds\n" COLOR_RESET, total_time / CLOCKS_PER_SEC); printf(COLOR_INFO "====================================\n" COLOR_RESET); fossil_test_message(env); From 9f7aceacd265d6d1c3a44618927330ad9b9e3cc8 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:36:51 -0600 Subject: [PATCH 37/40] Update benchmark.c --- code/logic/benchmark.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/code/logic/benchmark.c b/code/logic/benchmark.c index 62535ba4..d4aa9cc5 100644 --- a/code/logic/benchmark.c +++ b/code/logic/benchmark.c @@ -35,10 +35,6 @@ clock_t start_time; clock_t start_time; #endif -#if defined(__APPLE__) && !defined(CLOCK_MONOTONIC) -#include -#endif - #ifndef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 199309L #endif @@ -87,9 +83,10 @@ uint64_t fossil_test_stop_benchmark(void) { } void assume_duration(double expected, double actual, double unit) { - clock_t end_time = clock(); - double elapsed_time = (double)(end_time - start_time) / ((double)CLOCKS_PER_SEC / unit); - if (elapsed_time < expected) { + uint64_t elapsed_time = fossil_test_stop_benchmark(); + double elapsed_seconds = elapsed_time / (1e9 / unit); // Convert to the desired time unit + + if (elapsed_seconds < expected) { printf("Benchmark failed: expected %f, got %f\n", expected, actual); } } From 549ffdb8d580b99cacb3e9192b654e9d3cb7fae4 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Thu, 7 Nov 2024 17:53:31 -0600 Subject: [PATCH 38/40] split into two sets --- code/logic/unittest.c | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/code/logic/unittest.c b/code/logic/unittest.c index 5ee03c68..e1ce2ff5 100644 --- a/code/logic/unittest.c +++ b/code/logic/unittest.c @@ -14,6 +14,49 @@ */ #include "fossil/test/unittest.h" +#ifdef __WIN32 +// Array of messages for each category +const char *sarcastic_messages[] = { + "Wow, no tests were run! What a productive day!", + "No tests to run, guess we're all just too good at writing code.", + "Congratulations, you’ve done absolutely nothing today.", + "Oh, look! No tests were executed. What an achievement!", + "Not a single test run, but hey, that's one way to keep things perfect!", + "All set for a day of zero productivity? Nice!", + "The test suite is empty, but hey, at least the code didn’t break!", + "Zero tests executed. Clearly, you've mastered the art of doing nothing.", + "Great! We’ve made it through an entire test run without running a single test.", + "Isn’t it great when there’s nothing to test?" +}; + +const char *humorous_messages[] = { + "Well, that was an epic failure! Better luck next time!", + "Whoops! Someone’s definitely gonna need to debug that.", + "Looks like someone forgot to write the test cases.", + "Your tests failed, but at least you got closer to perfection... not.", + "Not all heroes wear capes. Some of them fail tests.", + "Don't worry, failure is just success in disguise. Or maybe not.", + "Well, that was awkward. Let's try again, shall we?", + "Looks like we’ve encountered a bug! Hope you’ve got a magnifying glass.", + "Your tests are taking a nap, but don’t worry, we’ll wake them up!", + "It’s not a failure, it’s just a learning experience! A very *expensive* one." +}; + +const char *great_news_messages[] = { + "Great news! All tests passed. You’re a testing genius!", + "Success! Everything works as expected. Go celebrate!", + "You did it! All tests passed. You’re officially a rock star!", + "Congrats, all tests passed! You’ve earned a gold star!", + "Woohoo! All tests passed with flying colors!", + "No bugs found today, you’re on fire!", + "Amazing! You’ve got a perfect test suite. Keep it up!", + "Nice job! All tests passed. I think we’ve found the next coding superhero!", + "Fantastic! No issues at all, just pure success!", + "All tests passed, everything’s awesome." +}; + +#else + // Array of messages for each category const char *sarcastic_messages[] = { "Wow, no tests were run! What a productive day! 😏", @@ -54,6 +97,8 @@ const char *great_news_messages[] = { "All tests passed, everything’s awesome. 🎶" }; +#endif + jmp_buf test_jump_buffer; // This will hold the jump buffer for longjmp char *_custom_fossil_test_strdup(const char *str) { From bdb10dcca78228c0c29b6427a6f286cdf47317dc Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Thu, 7 Nov 2024 18:14:11 -0600 Subject: [PATCH 39/40] last patch --- README.md | 48 +++++++++---------------------------------- code/logic/unittest.c | 14 ++++++------- 2 files changed, 17 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 49fb9fa9..c11cb96c 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,14 @@ -# ***Fossil Test: Unit Testing/Mocking Framework*** - `C, C++` +# ***Fossil Test by Fossil Logic*** -**Overview:** -Fossil Test is a robust unit testing and mocking framework developed by Fossil Logic. It is designed to facilitate the creation of high-quality test cases for C and C++ projects, promoting software reliability and correctness. The framework supports various development methodologies, including Behavior-Driven Development (BDD), Domain-Driven Design (DDD), and Test-Driven Development (TDD), offering flexibility for diverse development workflows. +**Fossil Test** is a comprehensive unit testing, mocking, and benchmarking suite created by Fossil Logic, designed to ensure the reliability and performance of C and C++ projects. With support for multiple development methodologies, including Behavior-Driven Development (BDD), Domain-Driven Design (DDD), and Test-Driven Development (TDD), Fossil Test provides a versatile foundation for crafting high-quality test cases across various workflows. -In addition to Fossil Test, Fossil Logic also offers two additional frameworks to enhance your development experience: -- **Fossil Mark**: A powerful benchmarking tool that allows developers to measure code performance, identify bottlenecks, and optimize execution time. It offers detailed timing information and reporting. -- **Fossil Mock**: A mocking library enabling developers to simulate the behavior of complex dependencies. By using mock objects, you can write focused unit tests that test isolated components, enhancing test reliability and coverage. +The Fossil suite consists of three complementary frameworks to streamline the development and testing process: -Together, Fossil Test, Fossil Mark, and Fossil Mock provide a comprehensive toolkit for developing, testing, and optimizing high-quality software. +- **Fossil Test**: The core unit testing framework that enables developers to create, manage, and execute unit tests effectively, ensuring each component functions as expected. +- **Fossil Mock**: A dedicated mocking library that simulates complex dependencies. Using mock objects, developers can isolate and thoroughly test individual components, improving the precision and reliability of test coverage. +- **Fossil Mark**: A benchmarking tool that provides detailed performance insights by measuring execution time, identifying bottlenecks, and offering in-depth reporting to optimize code efficiency. + +Together, **Fossil Test**, **Fossil Mock**, and **Fossil Mark** offer a powerful, integrated toolkit for developing, testing, and optimizing robust software, making them an essential asset for developers committed to quality and performance. --- @@ -18,12 +19,8 @@ Together, Fossil Test, Fossil Mark, and Fossil Mock provide a comprehensive tool | **BDD, DDD, and TDD Support** | Supports Behavior-Driven, Domain-Driven, and Test-Driven Development styles, catering to various project methodologies. | | **Comprehensive Unit Testing** | A full suite of tools for creating, managing, and executing unit tests, ensuring that individual units of code behave as expected. | | **Mocking Capabilities** | Powerful mocking features allow developers to simulate complex dependencies, ensuring focused and reliable unit tests. | -| **Test Case Management** | Organize and manage test cases with features for categorization, prioritization, and tagging, improving test suite maintainability. | -| **Detailed Reporting** | Generates comprehensive reports on test execution, including information on passed, failed, skipped, and timed-out tests, aiding quick issue resolution. | | **Performance Tracking** | Measures and reports the performance of each test case, helping developers optimize test execution time and performance. | -| **Assertion Detection** | Ensures that assertions are properly used in code, enforcing critical conditions and identifying potential areas lacking validation. | | **Command-Line Interface (CLI)** | A powerful CLI for running tests, generating reports, and managing the test suite, supporting automation and integration workflows. | -| **Extensible and Configurable** | Highly extensible, allowing developers to customize the framework to their needs, from reporting formats to tool integration. | --- @@ -59,8 +56,6 @@ To integrate Fossil Test into your project, follow these steps: [provide] fossil-test = fossil_test_dep - fossil-mock = fossil_mock_dep - fossil-mark = fossil_mark_dep ``` 3. **Integrate the Dependency**: @@ -81,20 +76,12 @@ The Fossil Test CLI provides an efficient way to run and manage tests directly f | Command | Description | |----------------------------------|-----------------------------------------------------------------------------------------------| -| `--version` | Displays the current version of the Fossil Test CLI. | +| `--version` | Displays the current version of Fossil Test. | | `--help` | Shows help message with usage instructions. | -| `--tip` | Displays a tip or hint related to the CLI usage. | -| `--info` | Displays detailed information about the test runner configuration. | -| `--author` | Shows information about the author of the test runner. | -| `only=` or `only=` | Runs only tests tagged with the specified tag(s). Tags can be comma-separated for multiple tags. | +| `--info` | Displays detailed information about the test run. | | `reverse [enable/disable]` | Enables or disables reverse order of test execution. | | `repeat=` | Repeats the test suite a specified number of times. | | `shuffle [enable/disable]` | Enables or disables shuffling of test execution order. | -| `verbose [cutback/normal/verbose]` | Sets verbosity level of the output. Options are `cutback`, `normal`, and `verbose`. | -| `list` | Lists all available tests. | -| `summary [enable/disable]` | Enables or disables a summary of test results after execution. | -| `color [enable/disable]` | Enables or disables colored output in the terminal. | -| `sanity [enable/disable]` | Enables or disables sanity checks before running tests. | ### Example Usage @@ -103,11 +90,6 @@ The Fossil Test CLI provides an efficient way to run and manage tests directly f fossil_cli --version ``` -- Run tests tagged with `unit` and `integration`: - ```sh - fossil_cli only=unit,integration - ``` - - Enable reverse order of test execution: ```sh fossil_cli reverse enable @@ -118,16 +100,6 @@ The Fossil Test CLI provides an efficient way to run and manage tests directly f fossil_cli repeat=5 ``` -- Show a summary after execution: - ```sh - fossil_cli summary enable - ``` - -- Enable colored output: - ```sh - fossil_cli color enable - ``` - --- ## Configure Build Options diff --git a/code/logic/unittest.c b/code/logic/unittest.c index e1ce2ff5..45900969 100644 --- a/code/logic/unittest.c +++ b/code/logic/unittest.c @@ -127,13 +127,13 @@ fossil_options_t init_options(void) { void usage_info(void) { printf("Usage: fossil [options] [command]\n"); printf("Options:\n"); - printf(" --version\t\tShow version information\n"); - printf(" --help\t\tShow help information\n"); - printf(" --info\t\tShow additional information\n"); + printf(" --version\t\tDisplays the current version of Fossil Test\n"); + printf(" --help\t\tShows help message with usage\n"); + printf(" --info\t\tDisplays detailed information about the test run.\n"); printf("Commands:\n"); - printf(" reverse [enable|disable]\tEnable or disable reverse order of test cases\n"); - printf(" repeat [count]\t\tEnable repeat mode with optional count\n"); - printf(" shuffle [enable|disable]\tEnable or disable shuffle mode\n"); + printf(" reverse [enable|disable]\tEnables or disables reverse order of test execution\n"); + printf(" repeat [count]\t\tRepeats the test suite a specified number of times\n"); + printf(" shuffle [enable|disable]\tEnables or disables shuffling of test execution order\n"); } void version_info(void) { @@ -493,7 +493,7 @@ void fossil_test_summary(fossil_test_env_t *env) { // Optionally, you could add the total execution time summary here printf(COLOR_INFO "====================================\n" COLOR_RESET); - printf(COLOR_INFO "Total execution time: %.3f seconds\n" COLOR_RESET, total_time / CLOCKS_PER_SEC); + printf(COLOR_INFO "Total execution time: %.3f seconds\n" COLOR_RESET, (env->total_execution_time - total_time) / CLOCKS_PER_SEC); printf(COLOR_INFO "====================================\n" COLOR_RESET); fossil_test_message(env); From 54511748e546cba1afd204ac0caa59dcf4963dcb Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Thu, 7 Nov 2024 18:44:44 -0600 Subject: [PATCH 40/40] testing meson mixed language version feature --- .github/workflows/meson_ci.yml | 2 +- meson.build | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/meson_ci.yml b/.github/workflows/meson_ci.yml index 8ccc7787..2bd197aa 100644 --- a/.github/workflows/meson_ci.yml +++ b/.github/workflows/meson_ci.yml @@ -243,7 +243,7 @@ jobs: -w /workspace \ ${GITHUB_REPOSITORY}:${{ matrix.distro }} \ /bin/bash -c " - meson setup builddir --fatal-meson-warnings -Dwerror=true -Dwith_test=enabled -Dwarning_level=3 -Dc_std=c17 + meson setup builddir --fatal-meson-warnings -Dwerror=true -Dwith_test=enabled -Dwarning_level=3 meson compile -C builddir meson test -C builddir -v" diff --git a/meson.build b/meson.build index 711e856a..46c5a017 100644 --- a/meson.build +++ b/meson.build @@ -2,6 +2,6 @@ project('Fossil Test', 'c', 'cpp', meson_version: '>=1.3.0', license: 'MPL-2.0', version: '1.0.7', - default_options: ['c_std=c18', 'cpp_std=c++20']) + default_options: ['c_std=c11,c18', 'cpp_std=c++20']) subdir('code')