diff --git a/code/logic/fossil/test/framework.h b/code/logic/fossil/test/framework.h index bcc59a85..d4af179a 100644 --- a/code/logic/fossil/test/framework.h +++ b/code/logic/fossil/test/framework.h @@ -150,15 +150,6 @@ extern "C" { #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 @@ -168,6 +159,14 @@ extern "C" { #define FOSSIL_TEST_CASE(name) \ _FOSSIL_TEST_CASE(name) +/** + * Macro to skip a test case. + * This macro is used to skip a test case in the test runner. The test case will + * be marked as skipped, and the specified message will be output to the console. + */ +#define FOSSIL_TEST_SKIP(test_name, message) \ + _FOSSIL_TEST_SKIP(test_name, message) + /** * Macro to assume a condition in a test runner. * This macro is used to assert that a specific condition is true within a test @@ -264,16 +263,16 @@ extern "C" { /** * @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__) +#define FOSSIL_MOCK_STRUCT(name) \ + _FOSSIL_MOCK_STRUCT(name) // ***************************************************************************** // Benchmark framework @@ -288,8 +287,7 @@ extern "C" { * @param name The name of the benchmark. */ #define MARK_BENCHMARK(name) \ - fossil_benchmark_t benchmark_##name; \ - fossil_benchmark_init(&benchmark_##name, #name) + _MARK_BENCHMARK(name) /** * @brief Define macro for starting a benchmark. @@ -300,7 +298,7 @@ extern "C" { * @param name The name of the benchmark. */ #define MARK_START(name) \ - fossil_benchmark_start(&benchmark_##name) + _MARK_START(name) /** * @brief Define macro for stopping a benchmark. @@ -311,7 +309,7 @@ extern "C" { * @param name The name of the benchmark. */ #define MARK_STOP(name) \ - fossil_benchmark_stop(&benchmark_##name) + _MARK_STOP(name) /** * @brief Define macro for reporting a benchmark. @@ -322,7 +320,7 @@ extern "C" { * @param name The name of the benchmark. */ #define MARK_REPORT(name) \ - fossil_benchmark_report(&benchmark_##name) + _MARK_REPORT(name) /** * @brief Define macro for scoped benchmarking. @@ -334,8 +332,7 @@ extern "C" { * @param name The name of the benchmark. */ #define MARK_SCOPED(name) \ - scoped_benchmark_t scoped_benchmark_##name; \ - fossil_scoped_benchmark_init(&scoped_benchmark_##name, &benchmark_##name) + _MARK_SCOPED(name) // ================================================================= // Bench specific commands diff --git a/code/logic/fossil/test/mocking.h b/code/logic/fossil/test/mocking.h index fa3d9c2c..d9f83b04 100644 --- a/code/logic/fossil/test/mocking.h +++ b/code/logic/fossil/test/mocking.h @@ -20,6 +20,7 @@ #include #include #include +#include /** * @brief Macro for initializing the mock list. @@ -73,8 +74,13 @@ * @param ... The parameters of the mock function in the format: (type1 param1, type2 param2, ...). * @return The return type specified for the mock function. */ +#ifdef _WIN32 +#define _FOSSIL_MOCK_FUNC(return_type, name, ...) \ + __declspec(dllexport) return_type fossil_mockup_##name(__VA_ARGS__) +#else #define _FOSSIL_MOCK_FUNC(return_type, name, ...) \ return_type fossil_mockup_##name(__VA_ARGS__) +#endif /** * @def _FOSSIL_MOCK_ALIAS @@ -94,15 +100,17 @@ * @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. + * 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; ... + * @param name The name of the mock struct. */ -#define _FOSSIL_MOCK_STRUCT(name, ...) \ - typedef struct { \ - __VA_ARGS__ \ - } fossil_mockup_##name; +#ifdef __cplusplus +#define _FOSSIL_MOCK_STRUCT(name) \ + struct name +#else +#define _FOSSIL_MOCK_STRUCT(name) \ + typedef struct name +#endif #ifdef __cplusplus extern "C" { diff --git a/code/logic/fossil/test/testing.h b/code/logic/fossil/test/testing.h index 8075c80c..302951d3 100644 --- a/code/logic/fossil/test/testing.h +++ b/code/logic/fossil/test/testing.h @@ -218,17 +218,15 @@ void fossil_test_print_stack_trace(stack_frame_t *stack_trace); fossil_test_assert_internal((condition), (message), __FILE__, __LINE__, __func__) /** - * @brief Macro to define a test case. + * @brief Macro to fail a test case. * - * This macro is used to define a test case, which is a single unit of testing - * that verifies the correctness of a specific functionality. The test case - * should contain the logic to set up the environment, execute the functionality, - * and verify the results. - * - * @param test_name The name of the test case. + * This macro is used to fail a test case with a specific message. The test case + * will be marked as failed, and the message will be displayed in the test results. */ -#define _FOSSIL_TEST_DATA(name) \ - typedef struct name +#define _FOSSIL_TEST_SKIP(test_name, message) \ + test_name##_test_case.status = TEST_STATUS_SKIP; \ + test_name##_test_case.failure_message = message; \ + printf(COLOR_SKIP "SKIP: %s - %s\n" COLOR_RESET, #test_name, message); \ /** * @brief Macro to define a test case. diff --git a/code/tests/cases/test_mark.c b/code/tests/cases/test_mark.c new file mode 100644 index 00000000..02add5d9 --- /dev/null +++ b/code/tests/cases/test_mark.c @@ -0,0 +1,61 @@ +/* + * ----------------------------------------------------------------------------- + * 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" + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Utilites +// * * * * * * * * * * * * * * * * * * * * * * * * +// Setup steps for things like test fixtures and +// mock objects are set here. +// * * * * * * * * * * * * * * * * * * * * * * * * + +// Define the test suite and add test cases +FOSSIL_TEST_SUITE(c_mark_suite); + +// Setup function for the test suite +FOSSIL_SETUP(c_mark_suite) { + // Setup code here +} + +// Teardown function for the test suite +FOSSIL_TEARDOWN(c_mark_suite) { + // Teardown code here +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * 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. +// * * * * * * * * * * * * * * * * * * * * * * * * + +// A test case to check if the benchmark stop works correctly +FOSSIL_TEST_CASE(c_mark_start_and_stop) { + MARK_BENCHMARK(stop_test); + MARK_START(stop_test); + MARK_STOP(stop_test); + ASSUME_ITS_EQUAL_CSTR(benchmark_stop_test.name, "stop_test"); +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Pool +// * * * * * * * * * * * * * * * * * * * * * * * * +FOSSIL_TEST_GROUP(c_mark_test_cases) { + FOSSIL_TEST_ADD(c_mark_suite, c_mark_start_and_stop); + + FOSSIL_TEST_REGISTER(c_mark_suite); +} diff --git a/code/tests/cases/test_mark.cpp b/code/tests/cases/test_mark.cpp new file mode 100644 index 00000000..941fd41c --- /dev/null +++ b/code/tests/cases/test_mark.cpp @@ -0,0 +1,63 @@ +/* + * ----------------------------------------------------------------------------- + * 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" +#include + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Utilites +// * * * * * * * * * * * * * * * * * * * * * * * * +// Setup steps for things like test fixtures and +// mock objects are set here. +// * * * * * * * * * * * * * * * * * * * * * * * * + +// Define the test suite and add test cases +FOSSIL_TEST_SUITE(cpp_mark_suite); + +// Setup function for the test suite +FOSSIL_SETUP(cpp_mark_suite) { + // Setup code here +} + +// Teardown function for the test suite +FOSSIL_TEARDOWN(cpp_mark_suite) { + // Teardown code here +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * 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. +// * * * * * * * * * * * * * * * * * * * * * * * * + +// A test case to check if the benchmark stop works correctly +FOSSIL_TEST_CASE(cpp_mark_start_and_stop) { + std::string benchmark_stop_test_name = "stop_test"; + MARK_BENCHMARK(stop_test); + MARK_START(stop_test); + MARK_STOP(stop_test); + ASSUME_ITS_EQUAL_CSTR(benchmark_stop_test.name, benchmark_stop_test_name.c_str()); +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Pool +// * * * * * * * * * * * * * * * * * * * * * * * * +FOSSIL_TEST_GROUP(cpp_mark_test_cases) { + FOSSIL_TEST_ADD(cpp_mark_suite, cpp_mark_start_and_stop); + + FOSSIL_TEST_REGISTER(cpp_mark_suite); +} diff --git a/code/tests/cases/test_sample.c b/code/tests/cases/test_sample.c index eed168d4..27d0cc73 100644 --- a/code/tests/cases/test_sample.c +++ b/code/tests/cases/test_sample.c @@ -16,7 +16,7 @@ #include "fossil/test/framework.h" // Test data structure for a sample test -FOSSIL_TEST_DATA(CSampleTestData) { +FOSSIL_MOCK_STRUCT(CSampleTestData) { int input; int expected_output; } CSampleTestData; @@ -70,11 +70,17 @@ FOSSIL_TEST_CASE(test_input_half) { FOSSIL_TEST_ASSUME(actual_output == data.expected_output, "Half test failed"); } +FOSSIL_TEST_CASE(test_should_not_run) { + FOSSIL_TEST_ASSUME(1 == 0, "This test should not run"); +} + FOSSIL_TEST_GROUP(c_sample_test_cases) { FOSSIL_TEST_ADD(sample_suite, test_input_increment); FOSSIL_TEST_ADD(sample_suite, test_input_decrement); FOSSIL_TEST_ADD(sample_suite, test_input_double); FOSSIL_TEST_ADD(sample_suite, test_input_half); + FOSSIL_TEST_SKIP(test_should_not_run, "This test should not run"); + FOSSIL_TEST_REGISTER(sample_suite); } diff --git a/code/tests/cases/test_sample.cpp b/code/tests/cases/test_sample.cpp index e8b33f3f..3897dabc 100644 --- a/code/tests/cases/test_sample.cpp +++ b/code/tests/cases/test_sample.cpp @@ -16,7 +16,7 @@ #include "fossil/test/framework.h" // Test data structure for a sample test -struct CppSampleTestData { +FOSSIL_MOCK_STRUCT(CppSampleTestData) { int input; int expected_output; }; @@ -70,11 +70,17 @@ FOSSIL_TEST_CASE(cpp_test_input_half) { FOSSIL_TEST_ASSUME(actual_output == data.expected_output, "Half test failed"); } +FOSSIL_TEST_CASE(cpp_test_should_not_run) { + FOSSIL_TEST_ASSUME(1 == 0, "This test should not run"); +} + FOSSIL_TEST_GROUP(cpp_sample_test_cases) { FOSSIL_TEST_ADD(cpp_sample_suite, cpp_test_input_increment); FOSSIL_TEST_ADD(cpp_sample_suite, cpp_test_input_decrement); FOSSIL_TEST_ADD(cpp_sample_suite, cpp_test_input_double); FOSSIL_TEST_ADD(cpp_sample_suite, cpp_test_input_half); + FOSSIL_TEST_SKIP(cpp_test_should_not_run, "This test should not run"); + FOSSIL_TEST_REGISTER(cpp_sample_suite); } diff --git a/code/tests/meson.build b/code/tests/meson.build index 03cb78b2..33aae7d9 100644 --- a/code/tests/meson.build +++ b/code/tests/meson.build @@ -4,7 +4,7 @@ if get_option('with_test').enabled() test_c = ['unit_runner.c'] test_cpp = ['unit_runner.cpp'] test_cases = [ - 'sample', 'bdd', 'tdd', 'ddd' + 'sample', 'bdd', 'tdd', 'ddd', 'mark' ] foreach cases : test_cases