Skip to content

Commit f1485e1

Browse files
Merge pull request #27 from dreamer-coding/main
Update for release 1.1.0
2 parents ff4350e + 8a6a797 commit f1485e1

File tree

8 files changed

+179
-40
lines changed

8 files changed

+179
-40
lines changed

code/logic/fossil/test/framework.h

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,6 @@ extern "C" {
150150
#define FOSSIL_TEARDOWN(name) \
151151
_FOSSIL_TEST_TEARDOWN(name)
152152

153-
/**
154-
* Macro to define test data.
155-
* This macro is used to declare a structure that contains the data required
156-
* for a test case. The test data structure can be used to pass input parameters
157-
* to the test case and store the expected output values.
158-
*/
159-
#define FOSSIL_TEST_DATA(name) \
160-
_FOSSIL_TEST_DATA(name)
161-
162153
/**
163154
* Macro to define a test case.
164155
* This macro is used to declare a test case function that will be executed
@@ -168,6 +159,14 @@ extern "C" {
168159
#define FOSSIL_TEST_CASE(name) \
169160
_FOSSIL_TEST_CASE(name)
170161

162+
/**
163+
* Macro to skip a test case.
164+
* This macro is used to skip a test case in the test runner. The test case will
165+
* be marked as skipped, and the specified message will be output to the console.
166+
*/
167+
#define FOSSIL_TEST_SKIP(test_name, message) \
168+
_FOSSIL_TEST_SKIP(test_name, message)
169+
171170
/**
172171
* Macro to assume a condition in a test runner.
173172
* This macro is used to assert that a specific condition is true within a test
@@ -264,16 +263,16 @@ extern "C" {
264263

265264
/**
266265
* @def FOSSIL_MOCK_STRUCT
266+
*
267267
* @brief Macro for creating a mock struct with the specified name and members.
268-
*
268+
*
269269
* This macro simplifies the creation of mock structs by defining a struct with the given name
270270
* and members. The struct name will be prefixed with "fossil_mockup_" to clearly indicate that it is a mock struct.
271-
*
271+
*
272272
* @param name The name of the mock struct.
273-
* @param ... The members of the mock struct in the format: (type1 member1, type2 member2, ...).
274273
*/
275-
#define FOSSIL_MOCK_STRUCT(name, ...) \
276-
_FOSSIL_MOCK_STRUCT(name, __VA_ARGS__)
274+
#define FOSSIL_MOCK_STRUCT(name) \
275+
_FOSSIL_MOCK_STRUCT(name)
277276

278277
// *****************************************************************************
279278
// Benchmark framework
@@ -288,8 +287,7 @@ extern "C" {
288287
* @param name The name of the benchmark.
289288
*/
290289
#define MARK_BENCHMARK(name) \
291-
fossil_benchmark_t benchmark_##name; \
292-
fossil_benchmark_init(&benchmark_##name, #name)
290+
_MARK_BENCHMARK(name)
293291

294292
/**
295293
* @brief Define macro for starting a benchmark.
@@ -300,7 +298,7 @@ extern "C" {
300298
* @param name The name of the benchmark.
301299
*/
302300
#define MARK_START(name) \
303-
fossil_benchmark_start(&benchmark_##name)
301+
_MARK_START(name)
304302

305303
/**
306304
* @brief Define macro for stopping a benchmark.
@@ -311,7 +309,7 @@ extern "C" {
311309
* @param name The name of the benchmark.
312310
*/
313311
#define MARK_STOP(name) \
314-
fossil_benchmark_stop(&benchmark_##name)
312+
_MARK_STOP(name)
315313

316314
/**
317315
* @brief Define macro for reporting a benchmark.
@@ -322,7 +320,7 @@ extern "C" {
322320
* @param name The name of the benchmark.
323321
*/
324322
#define MARK_REPORT(name) \
325-
fossil_benchmark_report(&benchmark_##name)
323+
_MARK_REPORT(name)
326324

327325
/**
328326
* @brief Define macro for scoped benchmarking.
@@ -334,8 +332,7 @@ extern "C" {
334332
* @param name The name of the benchmark.
335333
*/
336334
#define MARK_SCOPED(name) \
337-
scoped_benchmark_t scoped_benchmark_##name; \
338-
fossil_scoped_benchmark_init(&scoped_benchmark_##name, &benchmark_##name)
335+
_MARK_SCOPED(name)
339336

340337
// =================================================================
341338
// Bench specific commands

code/logic/fossil/test/mocking.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <stdio.h>
2121
#include <stdlib.h>
2222
#include <string.h>
23+
#include <stdbool.h>
2324

2425
/**
2526
* @brief Macro for initializing the mock list.
@@ -73,8 +74,13 @@
7374
* @param ... The parameters of the mock function in the format: (type1 param1, type2 param2, ...).
7475
* @return The return type specified for the mock function.
7576
*/
77+
#ifdef _WIN32
78+
#define _FOSSIL_MOCK_FUNC(return_type, name, ...) \
79+
__declspec(dllexport) return_type fossil_mockup_##name(__VA_ARGS__)
80+
#else
7681
#define _FOSSIL_MOCK_FUNC(return_type, name, ...) \
7782
return_type fossil_mockup_##name(__VA_ARGS__)
83+
#endif
7884

7985
/**
8086
* @def _FOSSIL_MOCK_ALIAS
@@ -94,15 +100,17 @@
94100
* @brief Macro for creating a mock struct with the specified name and members.
95101
*
96102
* This macro simplifies the creation of mock structs by defining a struct with the given name
97-
* and members.
103+
* and members. The struct name will be prefixed with "fossil_mockup_" to clearly indicate that it is a mock struct.
98104
*
99-
* @param name The name of the mock struct.
100-
* @param ... The members of the mock struct in the format: type1 member1; type2 member2; ...
105+
* @param name The name of the mock struct.
101106
*/
102-
#define _FOSSIL_MOCK_STRUCT(name, ...) \
103-
typedef struct { \
104-
__VA_ARGS__ \
105-
} fossil_mockup_##name;
107+
#ifdef __cplusplus
108+
#define _FOSSIL_MOCK_STRUCT(name) \
109+
struct name
110+
#else
111+
#define _FOSSIL_MOCK_STRUCT(name) \
112+
typedef struct name
113+
#endif
106114

107115
#ifdef __cplusplus
108116
extern "C" {

code/logic/fossil/test/testing.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,15 @@ void fossil_test_print_stack_trace(stack_frame_t *stack_trace);
218218
fossil_test_assert_internal((condition), (message), __FILE__, __LINE__, __func__)
219219

220220
/**
221-
* @brief Macro to define a test case.
221+
* @brief Macro to fail a test case.
222222
*
223-
* This macro is used to define a test case, which is a single unit of testing
224-
* that verifies the correctness of a specific functionality. The test case
225-
* should contain the logic to set up the environment, execute the functionality,
226-
* and verify the results.
227-
*
228-
* @param test_name The name of the test case.
223+
* This macro is used to fail a test case with a specific message. The test case
224+
* will be marked as failed, and the message will be displayed in the test results.
229225
*/
230-
#define _FOSSIL_TEST_DATA(name) \
231-
typedef struct name
226+
#define _FOSSIL_TEST_SKIP(test_name, message) \
227+
test_name##_test_case.status = TEST_STATUS_SKIP; \
228+
test_name##_test_case.failure_message = message; \
229+
printf(COLOR_SKIP "SKIP: %s - %s\n" COLOR_RESET, #test_name, message); \
232230

233231
/**
234232
* @brief Macro to define a test case.

code/tests/cases/test_mark.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* -----------------------------------------------------------------------------
3+
* Project: Fossil Logic
4+
*
5+
* This file is part of the Fossil Logic project, which aims to develop high-
6+
* performance, cross-platform applications and libraries. The code contained
7+
* herein is subject to the terms and conditions defined in the project license.
8+
*
9+
* Author: Michael Gene Brockus (Dreamer)
10+
* Date: 07/01/2024
11+
*
12+
* Copyright (C) 2024 Fossil Logic. All rights reserved.
13+
* -----------------------------------------------------------------------------
14+
*/
15+
16+
#include "fossil/test/framework.h"
17+
18+
// * * * * * * * * * * * * * * * * * * * * * * * *
19+
// * Fossil Logic Test Utilites
20+
// * * * * * * * * * * * * * * * * * * * * * * * *
21+
// Setup steps for things like test fixtures and
22+
// mock objects are set here.
23+
// * * * * * * * * * * * * * * * * * * * * * * * *
24+
25+
// Define the test suite and add test cases
26+
FOSSIL_TEST_SUITE(c_mark_suite);
27+
28+
// Setup function for the test suite
29+
FOSSIL_SETUP(c_mark_suite) {
30+
// Setup code here
31+
}
32+
33+
// Teardown function for the test suite
34+
FOSSIL_TEARDOWN(c_mark_suite) {
35+
// Teardown code here
36+
}
37+
38+
// * * * * * * * * * * * * * * * * * * * * * * * *
39+
// * Fossil Logic Test Cases
40+
// * * * * * * * * * * * * * * * * * * * * * * * *
41+
// The test cases below are provided as samples, inspired
42+
// by the Meson build system's approach of using test cases
43+
// as samples for library usage.
44+
// * * * * * * * * * * * * * * * * * * * * * * * *
45+
46+
// A test case to check if the benchmark stop works correctly
47+
FOSSIL_TEST_CASE(c_mark_start_and_stop) {
48+
MARK_BENCHMARK(stop_test);
49+
MARK_START(stop_test);
50+
MARK_STOP(stop_test);
51+
ASSUME_ITS_EQUAL_CSTR(benchmark_stop_test.name, "stop_test");
52+
}
53+
54+
// * * * * * * * * * * * * * * * * * * * * * * * *
55+
// * Fossil Logic Test Pool
56+
// * * * * * * * * * * * * * * * * * * * * * * * *
57+
FOSSIL_TEST_GROUP(c_mark_test_cases) {
58+
FOSSIL_TEST_ADD(c_mark_suite, c_mark_start_and_stop);
59+
60+
FOSSIL_TEST_REGISTER(c_mark_suite);
61+
}

code/tests/cases/test_mark.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* -----------------------------------------------------------------------------
3+
* Project: Fossil Logic
4+
*
5+
* This file is part of the Fossil Logic project, which aims to develop high-
6+
* performance, cross-platform applications and libraries. The code contained
7+
* herein is subject to the terms and conditions defined in the project license.
8+
*
9+
* Author: Michael Gene Brockus (Dreamer)
10+
* Date: 07/01/2024
11+
*
12+
* Copyright (C) 2024 Fossil Logic. All rights reserved.
13+
* -----------------------------------------------------------------------------
14+
*/
15+
16+
#include "fossil/test/framework.h"
17+
#include <string>
18+
19+
// * * * * * * * * * * * * * * * * * * * * * * * *
20+
// * Fossil Logic Test Utilites
21+
// * * * * * * * * * * * * * * * * * * * * * * * *
22+
// Setup steps for things like test fixtures and
23+
// mock objects are set here.
24+
// * * * * * * * * * * * * * * * * * * * * * * * *
25+
26+
// Define the test suite and add test cases
27+
FOSSIL_TEST_SUITE(cpp_mark_suite);
28+
29+
// Setup function for the test suite
30+
FOSSIL_SETUP(cpp_mark_suite) {
31+
// Setup code here
32+
}
33+
34+
// Teardown function for the test suite
35+
FOSSIL_TEARDOWN(cpp_mark_suite) {
36+
// Teardown code here
37+
}
38+
39+
// * * * * * * * * * * * * * * * * * * * * * * * *
40+
// * Fossil Logic Test Cases
41+
// * * * * * * * * * * * * * * * * * * * * * * * *
42+
// The test cases below are provided as samples, inspired
43+
// by the Meson build system's approach of using test cases
44+
// as samples for library usage.
45+
// * * * * * * * * * * * * * * * * * * * * * * * *
46+
47+
// A test case to check if the benchmark stop works correctly
48+
FOSSIL_TEST_CASE(cpp_mark_start_and_stop) {
49+
std::string benchmark_stop_test_name = "stop_test";
50+
MARK_BENCHMARK(stop_test);
51+
MARK_START(stop_test);
52+
MARK_STOP(stop_test);
53+
ASSUME_ITS_EQUAL_CSTR(benchmark_stop_test.name, benchmark_stop_test_name.c_str());
54+
}
55+
56+
// * * * * * * * * * * * * * * * * * * * * * * * *
57+
// * Fossil Logic Test Pool
58+
// * * * * * * * * * * * * * * * * * * * * * * * *
59+
FOSSIL_TEST_GROUP(cpp_mark_test_cases) {
60+
FOSSIL_TEST_ADD(cpp_mark_suite, cpp_mark_start_and_stop);
61+
62+
FOSSIL_TEST_REGISTER(cpp_mark_suite);
63+
}

code/tests/cases/test_sample.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "fossil/test/framework.h"
1717

1818
// Test data structure for a sample test
19-
FOSSIL_TEST_DATA(CSampleTestData) {
19+
FOSSIL_MOCK_STRUCT(CSampleTestData) {
2020
int input;
2121
int expected_output;
2222
} CSampleTestData;
@@ -70,11 +70,17 @@ FOSSIL_TEST_CASE(test_input_half) {
7070
FOSSIL_TEST_ASSUME(actual_output == data.expected_output, "Half test failed");
7171
}
7272

73+
FOSSIL_TEST_CASE(test_should_not_run) {
74+
FOSSIL_TEST_ASSUME(1 == 0, "This test should not run");
75+
}
76+
7377
FOSSIL_TEST_GROUP(c_sample_test_cases) {
7478
FOSSIL_TEST_ADD(sample_suite, test_input_increment);
7579
FOSSIL_TEST_ADD(sample_suite, test_input_decrement);
7680
FOSSIL_TEST_ADD(sample_suite, test_input_double);
7781
FOSSIL_TEST_ADD(sample_suite, test_input_half);
7882

83+
FOSSIL_TEST_SKIP(test_should_not_run, "This test should not run");
84+
7985
FOSSIL_TEST_REGISTER(sample_suite);
8086
}

code/tests/cases/test_sample.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "fossil/test/framework.h"
1717

1818
// Test data structure for a sample test
19-
struct CppSampleTestData {
19+
FOSSIL_MOCK_STRUCT(CppSampleTestData) {
2020
int input;
2121
int expected_output;
2222
};
@@ -70,11 +70,17 @@ FOSSIL_TEST_CASE(cpp_test_input_half) {
7070
FOSSIL_TEST_ASSUME(actual_output == data.expected_output, "Half test failed");
7171
}
7272

73+
FOSSIL_TEST_CASE(cpp_test_should_not_run) {
74+
FOSSIL_TEST_ASSUME(1 == 0, "This test should not run");
75+
}
76+
7377
FOSSIL_TEST_GROUP(cpp_sample_test_cases) {
7478
FOSSIL_TEST_ADD(cpp_sample_suite, cpp_test_input_increment);
7579
FOSSIL_TEST_ADD(cpp_sample_suite, cpp_test_input_decrement);
7680
FOSSIL_TEST_ADD(cpp_sample_suite, cpp_test_input_double);
7781
FOSSIL_TEST_ADD(cpp_sample_suite, cpp_test_input_half);
7882

83+
FOSSIL_TEST_SKIP(cpp_test_should_not_run, "This test should not run");
84+
7985
FOSSIL_TEST_REGISTER(cpp_sample_suite);
8086
}

code/tests/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if get_option('with_test').enabled()
44
test_c = ['unit_runner.c']
55
test_cpp = ['unit_runner.cpp']
66
test_cases = [
7-
'sample', 'bdd', 'tdd', 'ddd'
7+
'sample', 'bdd', 'tdd', 'ddd', 'mark'
88
]
99

1010
foreach cases : test_cases

0 commit comments

Comments
 (0)