Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions code/logic/fossil/test/framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down
22 changes: 15 additions & 7 deletions code/logic/fossil/test/mocking.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

/**
* @brief Macro for initializing the mock list.
Expand Down Expand Up @@ -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
Expand All @@ -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" {
Expand Down
16 changes: 7 additions & 9 deletions code/logic/fossil/test/testing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
61 changes: 61 additions & 0 deletions code/tests/cases/test_mark.c
Original file line number Diff line number Diff line change
@@ -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);
}
63 changes: 63 additions & 0 deletions code/tests/cases/test_mark.cpp
Original file line number Diff line number Diff line change
@@ -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 <string>

// * * * * * * * * * * * * * * * * * * * * * * * *
// * 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);
}
8 changes: 7 additions & 1 deletion code/tests/cases/test_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
8 changes: 7 additions & 1 deletion code/tests/cases/test_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion code/tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down