From 271d456ee1e55d55892d48f0adfc5d9fa3b8ff13 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 17:37:54 -0500 Subject: [PATCH 01/27] adding test for mock io redirect --- code/tests/cases/test_mock.c | 61 +++++++++++++++++++++++++++ code/tests/cases/test_mock.cpp | 75 ++++++++++++++++++++++++++++++---- 2 files changed, 129 insertions(+), 7 deletions(-) diff --git a/code/tests/cases/test_mock.c b/code/tests/cases/test_mock.c index 3a3b0bc7..2005b4ce 100644 --- a/code/tests/cases/test_mock.c +++ b/code/tests/cases/test_mock.c @@ -49,6 +49,14 @@ FOSSIL_MOCK_FUNC(int, c_mock_function, int a, int b) { return a + b; } +FOSSIL_MOCK_FUNC(void, c_mock_function_with_output) { + pizza_io_printf("Hello, Fossil Logic!"); +} + +FOSSIL_MOCK_FUNC(void, mock_function_redirection) { + pizza_io_printf("Testing macro redirection!"); +} + // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Cases // * * * * * * * * * * * * * * * * * * * * * * * * @@ -323,6 +331,53 @@ FOSSIL_TEST(c_mock_macro_destruction) { FOSSIL_TEST_ASSUME(list.size == 0, "fossil_mock_calllist_t size should be 0 after destruction using macro"); } // end case +FOSSIL_TEST(c_mock_io_capture_output) { + // Buffer to capture output + char buffer[256]; + + // Capture the output of the mock function + int captured_size = fossil_mock_capture_output(buffer, sizeof(buffer), fossil_mockup_c_mock_function_with_output); + + // Test cases + FOSSIL_TEST_ASSUME(captured_size > 0, "Captured size should be greater than 0"); + FOSSIL_TEST_ASSUME(strcmp(buffer, "Hello, Fossil Logic!") == 0, "Captured output should match expected output"); +} // end case + +FOSSIL_TEST(c_mock_io_compare_output) { + // Captured and expected outputs + const char *captured = "Hello, Fossil Logic!"; + const char *expected = "Hello, Fossil Logic!"; + + // Compare the outputs + bool result = fossil_mock_compare_output(captured, expected); + + // Test cases + FOSSIL_TEST_ASSUME(result == true, "Captured output should match expected output"); +} // end case + +FOSSIL_TEST(c_mock_io_redirect_stdout_macro) { + // Buffer to capture output + char buffer[256]; + + // Use the macro to redirect stdout and capture output + FOSSIL_MOCK_REDIRECT_STDOUT(buffer, sizeof(buffer), fossil_mockup_mock_function_redirection, NULL); + + // Test cases + FOSSIL_TEST_ASSUME(strcmp(buffer, "Testing macro redirection!") == 0, "Captured output should match expected output"); +} // end case + +FOSSIL_TEST(c_mock_io_compare_output_macro) { + // Captured and expected outputs + const char *captured = "Macro comparison test!"; + const char *expected = "Macro comparison test!"; + + // Use the macro to compare outputs + bool result = FOSSIL_MOCK_COMPARE_OUTPUT(captured, expected); + + // Test cases + FOSSIL_TEST_ASSUME(result == true, "Captured output should match expected output using macro"); +} // end case + // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -341,5 +396,11 @@ FOSSIL_TEST_GROUP(c_mock_test_cases) { FOSSIL_TEST_ADD(c_mock_suite, c_mock_macro_addition); FOSSIL_TEST_ADD(c_mock_suite, c_mock_macro_destruction); + FOSSIL_TEST_ADD(c_mock_suite, c_mock_io_capture_output); + FOSSIL_TEST_ADD(c_mock_suite, c_mock_io_compare_output); + FOSSIL_TEST_ADD(c_mock_suite, c_mock_io_redirect_stdout_macro); + FOSSIL_TEST_ADD(c_mock_suite, c_mock_io_compare_output_macro); + FOSSIL_TEST_ADD(c_mock_suite, c_mock_io_compare_output); + FOSSIL_TEST_REGISTER(c_mock_suite); } // end of group diff --git a/code/tests/cases/test_mock.cpp b/code/tests/cases/test_mock.cpp index 23462907..2a389b67 100644 --- a/code/tests/cases/test_mock.cpp +++ b/code/tests/cases/test_mock.cpp @@ -49,6 +49,14 @@ FOSSIL_MOCK_FUNC(int, cpp_mock_function, int a, int b) { return a + b; } +FOSSIL_MOCK_FUNC(void, cpp_mock_function_with_output) { + pizza_io_printf("Hello, Fossil Logic!"); +} + +FOSSIL_MOCK_FUNC(void, mock_function_redirection) { + pizza_io_printf("Testing macro redirection!"); +} + // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Cases // * * * * * * * * * * * * * * * * * * * * * * * * @@ -62,8 +70,8 @@ FOSSIL_TEST(cpp_mock_call_list_initialization) { fossil_mock_init(&list); // Test cases - FOSSIL_TEST_ASSUME(list.head == nullptr, "fossil_mock_calllist_t head should be nullptr after initialization"); - FOSSIL_TEST_ASSUME(list.tail == nullptr, "fossil_mock_calllist_t tail should be nullptr after initialization"); + FOSSIL_TEST_ASSUME(list.head == NULL, "fossil_mock_calllist_t head should be NULL after initialization"); + FOSSIL_TEST_ASSUME(list.tail == NULL, "fossil_mock_calllist_t tail should be NULL after initialization"); FOSSIL_TEST_ASSUME(list.size == 0, "fossil_mock_calllist_t size should be 0 after initialization"); } // end case @@ -208,7 +216,7 @@ FOSSIL_TEST(cpp_mock_call_list_edge_cases) { fossil_mock_init(&list); // Add a call with no arguments - fossil_mock_add_call(&list, "no_args_function", nullptr, 0); + fossil_mock_add_call(&list, "no_args_function", NULL, 0); // Test cases FOSSIL_TEST_ASSUME(list.size == 1, "fossil_mock_calllist_t size should be 1 after adding a call with no arguments"); @@ -253,8 +261,8 @@ FOSSIL_TEST(cpp_mock_macro_initialization) { MOCK_INIT(list); // Test cases - FOSSIL_TEST_ASSUME(list.head == nullptr, "fossil_mock_calllist_t head should be nullptr after initialization using macro"); - FOSSIL_TEST_ASSUME(list.tail == nullptr, "fossil_mock_calllist_t tail should be nullptr after initialization using macro"); + FOSSIL_TEST_ASSUME(list.head == NULL, "fossil_mock_calllist_t head should be NULL after initialization using macro"); + FOSSIL_TEST_ASSUME(list.tail == NULL, "fossil_mock_calllist_t tail should be NULL after initialization using macro"); FOSSIL_TEST_ASSUME(list.size == 0, "fossil_mock_calllist_t size should be 0 after initialization using macro"); } // end case @@ -318,11 +326,58 @@ FOSSIL_TEST(cpp_mock_macro_destruction) { MOCK_DESTROY(list); // Test cases - FOSSIL_TEST_ASSUME(list.head == nullptr, "fossil_mock_calllist_t head should be nullptr after destruction using macro"); - FOSSIL_TEST_ASSUME(list.tail == nullptr, "fossil_mock_calllist_t tail should be nullptr after destruction using macro"); + FOSSIL_TEST_ASSUME(list.head == NULL, "fossil_mock_calllist_t head should be NULL after destruction using macro"); + FOSSIL_TEST_ASSUME(list.tail == NULL, "fossil_mock_calllist_t tail should be NULL after destruction using macro"); FOSSIL_TEST_ASSUME(list.size == 0, "fossil_mock_calllist_t size should be 0 after destruction using macro"); } // end case +FOSSIL_TEST(cpp_mock_io_capture_output) { + // Buffer to capture output + char buffer[256]; + + // Capture the output of the mock function + int captured_size = fossil_mock_capture_output(buffer, sizeof(buffer), fossil_mockup_cpp_mock_function_with_output); + + // Test cases + FOSSIL_TEST_ASSUME(captured_size > 0, "Captured size should be greater than 0"); + FOSSIL_TEST_ASSUME(strcmp(buffer, "Hello, Fossil Logic!") == 0, "Captured output should match expected output"); +} // end case + +FOSSIL_TEST(cpp_mock_io_compare_output) { + // Captured and expected outputs + const char *captured = "Hello, Fossil Logic!"; + const char *expected = "Hello, Fossil Logic!"; + + // Compare the outputs + bool result = fossil_mock_compare_output(captured, expected); + + // Test cases + FOSSIL_TEST_ASSUME(result == true, "Captured output should match expected output"); +} // end case + +FOSSIL_TEST(cpp_mock_io_redirect_stdout_macro) { + // Buffer to capture output + char buffer[256]; + + // Use the macro to redirect stdout and capture output + FOSSIL_MOCK_REDIRECT_STDOUT(buffer, sizeof(buffer), fossil_mockup_mock_function_redirection, NULL); + + // Test cases + FOSSIL_TEST_ASSUME(strcmp(buffer, "Testing macro redirection!") == 0, "Captured output should match expected output"); +} // end case + +FOSSIL_TEST(cpp_mock_io_compare_output_macro) { + // Captured and expected outputs + const char *captured = "Macro comparison test!"; + const char *expected = "Macro comparison test!"; + + // Use the macro to compare outputs + bool result = FOSSIL_MOCK_COMPARE_OUTPUT(captured, expected); + + // Test cases + FOSSIL_TEST_ASSUME(result == true, "Captured output should match expected output using macro"); +} // end case + // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -341,5 +396,11 @@ FOSSIL_TEST_GROUP(cpp_mock_test_cases) { FOSSIL_TEST_ADD(cpp_mock_suite, cpp_mock_macro_addition); FOSSIL_TEST_ADD(cpp_mock_suite, cpp_mock_macro_destruction); + FOSSIL_TEST_ADD(cpp_mock_suite, cpp_mock_io_capture_output); + FOSSIL_TEST_ADD(cpp_mock_suite, cpp_mock_io_compare_output); + FOSSIL_TEST_ADD(cpp_mock_suite, cpp_mock_io_redirect_stdout_macro); + FOSSIL_TEST_ADD(cpp_mock_suite, cpp_mock_io_compare_output_macro); + FOSSIL_TEST_ADD(cpp_mock_suite, cpp_mock_io_compare_output); + FOSSIL_TEST_REGISTER(cpp_mock_suite); } // end of group From 7119439fc738a9faab5cea1d7ed1e374bc659554 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 17:38:22 -0500 Subject: [PATCH 02/27] ensure io streams are in common source --- code/logic/common.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/logic/common.c b/code/logic/common.c index 231fa98f..86bb8d76 100644 --- a/code/logic/common.c +++ b/code/logic/common.c @@ -1205,6 +1205,10 @@ bool pizza_sys_memory_is_valid(const pizza_sys_memory_t ptr) { // output management // ***************************************************************************** +pizza_fstream_t *PIZZA_STDIN; +pizza_fstream_t *PIZZA_STDOUT; +pizza_fstream_t *PIZZA_STDERR; + int32_t PIZZA_IO_COLOR_ENABLE = 1; // Flag to enable/disable color output int32_t FOSSIL_IO_ATTR_ENABLE = 1; // Flag to enable/disable attribute output From d5f53bd3d5bcae930abd843c9a4eedeecb171b74 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 17:38:41 -0500 Subject: [PATCH 03/27] add mock io --- code/logic/fossil/pizza/mock.h | 95 ++++++++++++++++++++++++++++++++++ code/logic/mock.c | 59 +++++++++++++++++++++ 2 files changed, 154 insertions(+) diff --git a/code/logic/fossil/pizza/mock.h b/code/logic/fossil/pizza/mock.h index 753cb36b..9262dd77 100644 --- a/code/logic/fossil/pizza/mock.h +++ b/code/logic/fossil/pizza/mock.h @@ -117,6 +117,26 @@ void fossil_mock_add_call(fossil_mock_calllist_t *list, const char *function_nam */ void fossil_mock_print(fossil_mock_calllist_t *list); +/** + * Captures the output of a function to a buffer for testing purposes. + * + * @param buffer The buffer to store the captured output. + * @param size The size of the buffer. + * @param function The function whose output is to be captured. + * @param ... The arguments to pass to the function. + * @return The number of characters captured. + */ +int fossil_mock_capture_output(char *buffer, size_t size, void (*function)(void), ...); + +/** + * Compares the captured output with the expected output. + * + * @param captured The captured output. + * @param expected The expected output. + * @return True if the captured output matches the expected output, false otherwise. + */ +bool fossil_mock_compare_output(const char *captured, const char *expected); + #ifdef __cplusplus } #endif @@ -211,6 +231,43 @@ void fossil_mock_print(fossil_mock_calllist_t *list); typedef struct name #endif +/** + * @def _FOSSIL_MOCK_REDIRECT_STDOUT + * @brief Macro for redirecting stdout to a buffer. + * + * This macro redirects stdout to a buffer for capturing output. + * + * @param buffer The buffer to capture the output. + * @param size The size of the buffer. + */ +#ifdef _WIN32 +#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ + fossil_mock_capture_output(buffer, size, function, __VA_ARGS__) +#elif defined(__APPLE__) +#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ + fossil_mock_capture_output(buffer, size, function, __VA_OPT(, __VA_ARGS__)) +#else +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L +#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ + fossil_mock_capture_output(buffer, size, function, __VA_OPT(, __VA_ARGS__)) +#else +#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ + fossil_mock_capture_output(buffer, size, function, __VA_ARGS__) +#endif +#endif + +/** + * @def _FOSSIL_MOCK_REDIRECT_STDOUT + * @brief Macro for redirecting stdout to a buffer. + * + * This macro redirects stdout to a buffer for capturing output. + * + * @param buffer The buffer to capture the output. + * @param size The size of the buffer. + */ +#define _FOSSIL_MOCK_COMPARE_OUTPUT(captured, expected) \ + fossil_mock_compare_output(captured, expected) + // ***************************************************************************** // Public API Macros // ***************************************************************************** @@ -299,4 +356,42 @@ void fossil_mock_print(fossil_mock_calllist_t *list); #define FOSSIL_MOCK_STRUCT(name) \ _FOSSIL_MOCK_STRUCT(name) +/** + * @def FOSSIL_MOCK_REDIRECT_STDOUT + * @brief Macro for redirecting stdout to a buffer. + * + * This macro redirects stdout to a buffer for capturing output. + * + * @param buffer The buffer to capture the output. + * @param size The size of the buffer. + */ +#ifdef _WIN32 +#define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ + _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_ARGS__) +#elif defined(__APPLE__) +#define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ + _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_OPT(, __VA_ARGS__)) +#else +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L +#define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ + _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_OPT(, __VA_ARGS__)) +#else +#define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ + _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_ARGS__) +#endif +#endif + +/** + * @def FOSSIL_MOCK_COMPARE_OUTPUT + * @brief Macro for comparing captured output with expected output. + * + * This macro compares the captured output with the expected output. + * + * @param captured The captured output. + * @param expected The expected output. + * @return True if the captured output matches the expected output, false otherwise. + */ +#define FOSSIL_MOCK_COMPARE_OUTPUT(captured, expected) \ + _FOSSIL_MOCK_COMPARE_OUTPUT(captured, expected) + #endif // FOSSIL_MOCK_FRAMEWORK_H diff --git a/code/logic/mock.c b/code/logic/mock.c index 6eb5bc47..ae2d9cc3 100644 --- a/code/logic/mock.c +++ b/code/logic/mock.c @@ -134,3 +134,62 @@ void fossil_mock_print(fossil_mock_calllist_t *list) { current = current->next; } } + +/** + * Captures the output of a function to a buffer for testing purposes. + * + * @param buffer The buffer to store the captured output. + * @param size The size of the buffer. + * @param function The function whose output is to be captured. + * @param ... The arguments to pass to the function. + * @return The number of characters captured. + */ +int fossil_mock_capture_output(char *buffer, size_t size, void (*function)(void), ...) { + if (!buffer || size == 0 || !function) { + return -1; + } + + // Create a temporary file to capture stdout + FILE *temp_file = tmpfile(); + if (!temp_file) { + return -1; + } + + // Redirect stdout to the temporary file + FILE *original_stdout = stdout; + stdout = temp_file; + + // Call the function with variable arguments + va_list args; + va_start(args, function); + function(); + va_end(args); + + // Restore stdout + fflush(temp_file); + stdout = original_stdout; + + // Rewind the temporary file and read its contents into the buffer + rewind(temp_file); + size_t read_size = fread(buffer, 1, size - 1, temp_file); + buffer[read_size] = '\0'; // Null-terminate the buffer + + // Close the temporary file + fclose(temp_file); + + return (int)read_size; +} + +/** + * Compares the captured output with the expected output. + * + * @param captured The captured output. + * @param expected The expected output. + * @return True if the captured output matches the expected output, false otherwise. + */ +bool fossil_mock_compare_output(const char *captured, const char *expected) { + if (!captured || !expected) { + return false; + } + return strcmp(captured, expected) == 0; +} From 40e8f6835cc577f05c8d452de123af111446f05d Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 18:02:09 -0500 Subject: [PATCH 04/27] add macro for posix source --- code/logic/mock.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/code/logic/mock.c b/code/logic/mock.c index ae2d9cc3..e77c5943 100644 --- a/code/logic/mock.c +++ b/code/logic/mock.c @@ -12,8 +12,8 @@ * Copyright (C) 2014-2025 Fossil Logic. All rights reserved. * ----------------------------------------------------------------------------- */ +#define _POSIX_C_SOURCE 200809L #include "fossil/pizza/mock.h" -#include "fossil/pizza/common.h" // ***************************************************************************** // Function declarations @@ -156,8 +156,17 @@ int fossil_mock_capture_output(char *buffer, size_t size, void (*function)(void) } // Redirect stdout to the temporary file - FILE *original_stdout = stdout; - stdout = temp_file; + int original_stdout_fd = dup(STDOUT_FILENO); + if (original_stdout_fd == -1) { + fclose(temp_file); + return -1; + } + fflush(stdout); + if (dup2(fileno(temp_file), STDOUT_FILENO) == -1) { + fclose(temp_file); + close(original_stdout_fd); + return -1; + } // Call the function with variable arguments va_list args; @@ -166,8 +175,9 @@ int fossil_mock_capture_output(char *buffer, size_t size, void (*function)(void) va_end(args); // Restore stdout - fflush(temp_file); - stdout = original_stdout; + fflush(stdout); + dup2(original_stdout_fd, STDOUT_FILENO); + close(original_stdout_fd); // Rewind the temporary file and read its contents into the buffer rewind(temp_file); From f8ec949489cde10f223c4ed3af2e48c3e5acc7df Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 18:09:16 -0500 Subject: [PATCH 05/27] make mock function request for params optional --- code/logic/fossil/pizza/mock.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/code/logic/fossil/pizza/mock.h b/code/logic/fossil/pizza/mock.h index 9262dd77..7995cfc3 100644 --- a/code/logic/fossil/pizza/mock.h +++ b/code/logic/fossil/pizza/mock.h @@ -196,10 +196,18 @@ bool fossil_mock_compare_output(const char *captured, const char *expected); #ifdef _WIN32 #define _FOSSIL_MOCK_FUNC(return_type, name, ...) \ __declspec(dllexport) return_type fossil_mockup_##name(__VA_ARGS__) +#elif defined(__APPLE__) +#define _FOSSIL_MOCK_FUNC(return_type, name, ...) \ + return_type fossil_mockup_##name(__VA_OPT(, __VA_ARGS__)) +#else +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L +#define _FOSSIL_MOCK_FUNC(return_type, name, ...) \ + return_type fossil_mockup_##name(__VA_OPT(, __VA_ARGS__)) #else #define _FOSSIL_MOCK_FUNC(return_type, name, ...) \ return_type fossil_mockup_##name(__VA_ARGS__) #endif +#endif /** * @def _FOSSIL_MOCK_ALIAS @@ -328,8 +336,21 @@ bool fossil_mock_compare_output(const char *captured, const char *expected); * @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, ...) \ _FOSSIL_MOCK_FUNC(return_type, name, __VA_ARGS__) +#elif defined(__APPLE__) +#define FOSSIL_MOCK_FUNC(return_type, name, ...) \ + _FOSSIL_MOCK_FUNC(return_type, name, __VA_OPT(, __VA_ARGS__)) +#else +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L +#define FOSSIL_MOCK_FUNC(return_type, name, ...) \ + _FOSSIL_MOCK_FUNC(return_type, name, __VA_OPT(, __VA_ARGS__)) +#else +#define FOSSIL_MOCK_FUNC(return_type, name, ...) \ + _FOSSIL_MOCK_FUNC(return_type, name, __VA_ARGS__) +#endif +#endif /** * @def FOSSIL_MOCK_ALIAS From 6d316109e83a502de075d772cb000c5fe84396e7 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 18:13:59 -0500 Subject: [PATCH 06/27] do a magic trick to allow void no args list --- code/tests/cases/test_mock.c | 4 ++-- code/tests/cases/test_mock.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/tests/cases/test_mock.c b/code/tests/cases/test_mock.c index 2005b4ce..4f6ed6cc 100644 --- a/code/tests/cases/test_mock.c +++ b/code/tests/cases/test_mock.c @@ -49,11 +49,11 @@ FOSSIL_MOCK_FUNC(int, c_mock_function, int a, int b) { return a + b; } -FOSSIL_MOCK_FUNC(void, c_mock_function_with_output) { +FOSSIL_MOCK_FUNC(void, c_mock_function_with_output, void) { pizza_io_printf("Hello, Fossil Logic!"); } -FOSSIL_MOCK_FUNC(void, mock_function_redirection) { +FOSSIL_MOCK_FUNC(void, mock_function_redirection, void) { pizza_io_printf("Testing macro redirection!"); } diff --git a/code/tests/cases/test_mock.cpp b/code/tests/cases/test_mock.cpp index 2a389b67..c015145b 100644 --- a/code/tests/cases/test_mock.cpp +++ b/code/tests/cases/test_mock.cpp @@ -49,11 +49,11 @@ FOSSIL_MOCK_FUNC(int, cpp_mock_function, int a, int b) { return a + b; } -FOSSIL_MOCK_FUNC(void, cpp_mock_function_with_output) { +FOSSIL_MOCK_FUNC(void, cpp_mock_function_with_output, void) { pizza_io_printf("Hello, Fossil Logic!"); } -FOSSIL_MOCK_FUNC(void, mock_function_redirection) { +FOSSIL_MOCK_FUNC(void, mock_function_redirection, void) { pizza_io_printf("Testing macro redirection!"); } From 2767d89cc3e069cb8df24e634b050c322bc67e0c Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 18:18:11 -0500 Subject: [PATCH 07/27] give mac a slice of types --- code/logic/fossil/pizza/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/logic/fossil/pizza/common.h b/code/logic/fossil/pizza/common.h index e9a94a30..1d2e3581 100644 --- a/code/logic/fossil/pizza/common.h +++ b/code/logic/fossil/pizza/common.h @@ -32,7 +32,7 @@ #include #elif defined(__APPLE__) #include - #include + #include // Ensure this is included before sysctl.h #include #include #include From 325ce01e75f36fba613a866c83abbce8fbfb4679 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 18:20:35 -0500 Subject: [PATCH 08/27] adding another macro code --- code/logic/fossil/pizza/common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/code/logic/fossil/pizza/common.h b/code/logic/fossil/pizza/common.h index 1d2e3581..5fb83f26 100644 --- a/code/logic/fossil/pizza/common.h +++ b/code/logic/fossil/pizza/common.h @@ -47,6 +47,7 @@ #endif #ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L #define _POSIX_C_SOURCE 199309L #endif From c1f3d21b285b3d92db66f69ad1fd362704fe7dbf Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 18:21:55 -0500 Subject: [PATCH 09/27] apply simple change --- code/logic/fossil/pizza/common.h | 1 - code/logic/mock.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/code/logic/fossil/pizza/common.h b/code/logic/fossil/pizza/common.h index 5fb83f26..1d2e3581 100644 --- a/code/logic/fossil/pizza/common.h +++ b/code/logic/fossil/pizza/common.h @@ -47,7 +47,6 @@ #endif #ifndef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 200809L #define _POSIX_C_SOURCE 199309L #endif diff --git a/code/logic/mock.c b/code/logic/mock.c index e77c5943..5f2c0a09 100644 --- a/code/logic/mock.c +++ b/code/logic/mock.c @@ -13,6 +13,7 @@ * ----------------------------------------------------------------------------- */ #define _POSIX_C_SOURCE 200809L +#include #include "fossil/pizza/mock.h" // ***************************************************************************** From 2dff9a8ce041f92f4728cb845e01a67c9c0bd7fe Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 18:24:39 -0500 Subject: [PATCH 10/27] testing --- .github/workflows/meson_ci.yml | 12 ++++++++---- code/logic/mock.c | 2 -- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/meson_ci.yml b/.github/workflows/meson_ci.yml index 0c8fe604..7b05d569 100644 --- a/.github/workflows/meson_ci.yml +++ b/.github/workflows/meson_ci.yml @@ -60,11 +60,11 @@ jobs: run: meson test -C builddir_msvc_${{ matrix.msvc_version }} -v --test-args='verbose=ci' build_macosx: - name: Building on macOS with Xcode ${{ matrix.xcode_version }} + name: Building on macOS with Clang ${{ matrix.clang_version }} runs-on: macos-latest strategy: matrix: - xcode_version: ["15.2", "15.3"] + clang_version: ["15.2", "15.3"] steps: - name: Checkout code uses: actions/checkout@v4 @@ -76,8 +76,12 @@ jobs: with: python-version: '3.12' - - name: Install Xcode - run: sudo xcode-select --switch /Applications/Xcode_${{ matrix.xcode_version }}.app + - name: Set Clang Version + run: | + export CC=/usr/bin/clang-${{ matrix.clang_version }} + export CXX=/usr/bin/clang++-${{ matrix.clang_version }} + echo "CC=/usr/bin/clang-${{ matrix.clang_version }}" >> $GITHUB_ENV + echo "CXX=/usr/bin/clang++-${{ matrix.clang_version }}" >> $GITHUB_ENV - name: Install Meson and Ninja run: | diff --git a/code/logic/mock.c b/code/logic/mock.c index 5f2c0a09..300c9e56 100644 --- a/code/logic/mock.c +++ b/code/logic/mock.c @@ -12,8 +12,6 @@ * Copyright (C) 2014-2025 Fossil Logic. All rights reserved. * ----------------------------------------------------------------------------- */ -#define _POSIX_C_SOURCE 200809L -#include #include "fossil/pizza/mock.h" // ***************************************************************************** From e48883c4a0e7981f0ff5b10c384ece2d1ff826c6 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 18:27:17 -0500 Subject: [PATCH 11/27] clang compiler --- .github/workflows/meson_ci.yml | 4 ++-- code/logic/mock.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/meson_ci.yml b/.github/workflows/meson_ci.yml index 7b05d569..dc13cc5c 100644 --- a/.github/workflows/meson_ci.yml +++ b/.github/workflows/meson_ci.yml @@ -64,8 +64,8 @@ jobs: runs-on: macos-latest strategy: matrix: - clang_version: ["15.2", "15.3"] - steps: + clang_version: ["16.0", "16.1", "16.2"] + steps: - name: Checkout code uses: actions/checkout@v4 with: diff --git a/code/logic/mock.c b/code/logic/mock.c index 300c9e56..55245ea1 100644 --- a/code/logic/mock.c +++ b/code/logic/mock.c @@ -14,6 +14,7 @@ */ #include "fossil/pizza/mock.h" + // ***************************************************************************** // Function declarations // ***************************************************************************** From 4334eac0d9e9e403d12298075f0e2084677fea6c Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 18:28:16 -0500 Subject: [PATCH 12/27] fix ci file format --- .github/workflows/meson_ci.yml | 2 +- code/logic/mock.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/meson_ci.yml b/.github/workflows/meson_ci.yml index dc13cc5c..922367e0 100644 --- a/.github/workflows/meson_ci.yml +++ b/.github/workflows/meson_ci.yml @@ -65,7 +65,7 @@ jobs: strategy: matrix: clang_version: ["16.0", "16.1", "16.2"] - steps: + steps: - name: Checkout code uses: actions/checkout@v4 with: diff --git a/code/logic/mock.c b/code/logic/mock.c index 55245ea1..300c9e56 100644 --- a/code/logic/mock.c +++ b/code/logic/mock.c @@ -14,7 +14,6 @@ */ #include "fossil/pizza/mock.h" - // ***************************************************************************** // Function declarations // ***************************************************************************** From da8298fd75107146355f43bb9436c8da9a3ae195 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 18:32:05 -0500 Subject: [PATCH 13/27] revert --- .github/workflows/meson_ci.yml | 12 ++++-------- code/logic/mock.c | 1 + 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/meson_ci.yml b/.github/workflows/meson_ci.yml index 922367e0..0c8fe604 100644 --- a/.github/workflows/meson_ci.yml +++ b/.github/workflows/meson_ci.yml @@ -60,11 +60,11 @@ jobs: run: meson test -C builddir_msvc_${{ matrix.msvc_version }} -v --test-args='verbose=ci' build_macosx: - name: Building on macOS with Clang ${{ matrix.clang_version }} + name: Building on macOS with Xcode ${{ matrix.xcode_version }} runs-on: macos-latest strategy: matrix: - clang_version: ["16.0", "16.1", "16.2"] + xcode_version: ["15.2", "15.3"] steps: - name: Checkout code uses: actions/checkout@v4 @@ -76,12 +76,8 @@ jobs: with: python-version: '3.12' - - name: Set Clang Version - run: | - export CC=/usr/bin/clang-${{ matrix.clang_version }} - export CXX=/usr/bin/clang++-${{ matrix.clang_version }} - echo "CC=/usr/bin/clang-${{ matrix.clang_version }}" >> $GITHUB_ENV - echo "CXX=/usr/bin/clang++-${{ matrix.clang_version }}" >> $GITHUB_ENV + - name: Install Xcode + run: sudo xcode-select --switch /Applications/Xcode_${{ matrix.xcode_version }}.app - name: Install Meson and Ninja run: | diff --git a/code/logic/mock.c b/code/logic/mock.c index 300c9e56..55245ea1 100644 --- a/code/logic/mock.c +++ b/code/logic/mock.c @@ -14,6 +14,7 @@ */ #include "fossil/pizza/mock.h" + // ***************************************************************************** // Function declarations // ***************************************************************************** From 194c23e5a1522f86672a858cfc21f8279cd7d23d Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 18:34:31 -0500 Subject: [PATCH 14/27] revert change to mock func --- code/logic/fossil/pizza/mock.h | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/code/logic/fossil/pizza/mock.h b/code/logic/fossil/pizza/mock.h index 7995cfc3..9262dd77 100644 --- a/code/logic/fossil/pizza/mock.h +++ b/code/logic/fossil/pizza/mock.h @@ -196,18 +196,10 @@ bool fossil_mock_compare_output(const char *captured, const char *expected); #ifdef _WIN32 #define _FOSSIL_MOCK_FUNC(return_type, name, ...) \ __declspec(dllexport) return_type fossil_mockup_##name(__VA_ARGS__) -#elif defined(__APPLE__) -#define _FOSSIL_MOCK_FUNC(return_type, name, ...) \ - return_type fossil_mockup_##name(__VA_OPT(, __VA_ARGS__)) -#else -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L -#define _FOSSIL_MOCK_FUNC(return_type, name, ...) \ - return_type fossil_mockup_##name(__VA_OPT(, __VA_ARGS__)) #else #define _FOSSIL_MOCK_FUNC(return_type, name, ...) \ return_type fossil_mockup_##name(__VA_ARGS__) #endif -#endif /** * @def _FOSSIL_MOCK_ALIAS @@ -336,21 +328,8 @@ bool fossil_mock_compare_output(const char *captured, const char *expected); * @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, ...) \ _FOSSIL_MOCK_FUNC(return_type, name, __VA_ARGS__) -#elif defined(__APPLE__) -#define FOSSIL_MOCK_FUNC(return_type, name, ...) \ - _FOSSIL_MOCK_FUNC(return_type, name, __VA_OPT(, __VA_ARGS__)) -#else -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L -#define FOSSIL_MOCK_FUNC(return_type, name, ...) \ - _FOSSIL_MOCK_FUNC(return_type, name, __VA_OPT(, __VA_ARGS__)) -#else -#define FOSSIL_MOCK_FUNC(return_type, name, ...) \ - _FOSSIL_MOCK_FUNC(return_type, name, __VA_ARGS__) -#endif -#endif /** * @def FOSSIL_MOCK_ALIAS From cd89bca1123fc0371d631789e93eeee87e3020ec Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 18:37:44 -0500 Subject: [PATCH 15/27] update macro logic --- code/logic/fossil/pizza/mock.h | 16 +++------------- code/logic/mock.c | 2 +- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/code/logic/fossil/pizza/mock.h b/code/logic/fossil/pizza/mock.h index 9262dd77..b282a7be 100644 --- a/code/logic/fossil/pizza/mock.h +++ b/code/logic/fossil/pizza/mock.h @@ -245,15 +245,10 @@ bool fossil_mock_compare_output(const char *captured, const char *expected); fossil_mock_capture_output(buffer, size, function, __VA_ARGS__) #elif defined(__APPLE__) #define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ - fossil_mock_capture_output(buffer, size, function, __VA_OPT(, __VA_ARGS__)) + fossil_mock_capture_output(buffer, size, function, ##__VA_ARGS__) #else -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L #define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ - fossil_mock_capture_output(buffer, size, function, __VA_OPT(, __VA_ARGS__)) -#else -#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ - fossil_mock_capture_output(buffer, size, function, __VA_ARGS__) -#endif + fossil_mock_capture_output(buffer, size, function, ##__VA_ARGS__) #endif /** @@ -372,13 +367,8 @@ bool fossil_mock_compare_output(const char *captured, const char *expected); #define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_OPT(, __VA_ARGS__)) #else -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L #define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ - _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_OPT(, __VA_ARGS__)) -#else -#define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ - _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_ARGS__) -#endif + _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ##__VA_ARGS__) #endif /** diff --git a/code/logic/mock.c b/code/logic/mock.c index 55245ea1..e77c5943 100644 --- a/code/logic/mock.c +++ b/code/logic/mock.c @@ -12,9 +12,9 @@ * Copyright (C) 2014-2025 Fossil Logic. All rights reserved. * ----------------------------------------------------------------------------- */ +#define _POSIX_C_SOURCE 200809L #include "fossil/pizza/mock.h" - // ***************************************************************************** // Function declarations // ***************************************************************************** From 3d10e35e2008b115b256df0b8db36ceb3744e128 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 18:42:30 -0500 Subject: [PATCH 16/27] fix macro and cheese --- code/logic/fossil/pizza/mock.h | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/code/logic/fossil/pizza/mock.h b/code/logic/fossil/pizza/mock.h index b282a7be..257d19d8 100644 --- a/code/logic/fossil/pizza/mock.h +++ b/code/logic/fossil/pizza/mock.h @@ -241,14 +241,19 @@ bool fossil_mock_compare_output(const char *captured, const char *expected); * @param size The size of the buffer. */ #ifdef _WIN32 -#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ - fossil_mock_capture_output(buffer, size, function, __VA_ARGS__) +#define _FOSSIL_TEST_ASSUME_MESSAGE(message, ...) \ + pizza_test_assert_messagef((message), __VA_ARGS__) #elif defined(__APPLE__) -#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ - fossil_mock_capture_output(buffer, size, function, ##__VA_ARGS__) +#define _FOSSIL_TEST_ASSUME_MESSAGE(message, ...) \ + pizza_test_assert_messagef((message) __VA_OPT__(, __VA_ARGS__)) #else -#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ - fossil_mock_capture_output(buffer, size, function, ##__VA_ARGS__) +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L +#define _FOSSIL_TEST_ASSUME_MESSAGE(message, ...) \ + pizza_test_assert_messagef((message) __VA_OPT__(, __VA_ARGS__)) +#else +#define _FOSSIL_TEST_ASSUME_MESSAGE(message, ...) \ + pizza_test_assert_messagef((message), __VA_ARGS__) +#endif #endif /** @@ -365,10 +370,15 @@ bool fossil_mock_compare_output(const char *captured, const char *expected); _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_ARGS__) #elif defined(__APPLE__) #define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ - _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_OPT(, __VA_ARGS__)) + _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function __VA_OPT__(, __VA_ARGS__)) +#else +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L +#define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ + _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function __VA_OPT__(, __VA_ARGS__)) #else #define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ - _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ##__VA_ARGS__) + _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_ARGS__) +#endif #endif /** From 8c2f1a58ec1a3893e0ca3d86eb0c7de4154a5a30 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Mon, 19 May 2025 18:54:38 -0500 Subject: [PATCH 17/27] test --- code/logic/fossil/pizza/mock.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/code/logic/fossil/pizza/mock.h b/code/logic/fossil/pizza/mock.h index 257d19d8..9262dd77 100644 --- a/code/logic/fossil/pizza/mock.h +++ b/code/logic/fossil/pizza/mock.h @@ -241,18 +241,18 @@ bool fossil_mock_compare_output(const char *captured, const char *expected); * @param size The size of the buffer. */ #ifdef _WIN32 -#define _FOSSIL_TEST_ASSUME_MESSAGE(message, ...) \ - pizza_test_assert_messagef((message), __VA_ARGS__) +#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ + fossil_mock_capture_output(buffer, size, function, __VA_ARGS__) #elif defined(__APPLE__) -#define _FOSSIL_TEST_ASSUME_MESSAGE(message, ...) \ - pizza_test_assert_messagef((message) __VA_OPT__(, __VA_ARGS__)) +#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ + fossil_mock_capture_output(buffer, size, function, __VA_OPT(, __VA_ARGS__)) #else #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L -#define _FOSSIL_TEST_ASSUME_MESSAGE(message, ...) \ - pizza_test_assert_messagef((message) __VA_OPT__(, __VA_ARGS__)) +#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ + fossil_mock_capture_output(buffer, size, function, __VA_OPT(, __VA_ARGS__)) #else -#define _FOSSIL_TEST_ASSUME_MESSAGE(message, ...) \ - pizza_test_assert_messagef((message), __VA_ARGS__) +#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ + fossil_mock_capture_output(buffer, size, function, __VA_ARGS__) #endif #endif @@ -370,11 +370,11 @@ bool fossil_mock_compare_output(const char *captured, const char *expected); _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_ARGS__) #elif defined(__APPLE__) #define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ - _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function __VA_OPT__(, __VA_ARGS__)) + _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_OPT(, __VA_ARGS__)) #else #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L #define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ - _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function __VA_OPT__(, __VA_ARGS__)) + _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_OPT(, __VA_ARGS__)) #else #define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_ARGS__) From 8f7446710f8d5ab81a7d5d698d3609f547791e77 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Wed, 21 May 2025 09:39:42 -0500 Subject: [PATCH 18/27] Update common.h --- code/logic/fossil/pizza/common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/code/logic/fossil/pizza/common.h b/code/logic/fossil/pizza/common.h index 1d2e3581..a99425a4 100644 --- a/code/logic/fossil/pizza/common.h +++ b/code/logic/fossil/pizza/common.h @@ -31,6 +31,7 @@ #include #include #elif defined(__APPLE__) + #define _DARWIN_C_SOURCE #include #include // Ensure this is included before sysctl.h #include From 2ed669d80bd9591191b4c8c75607b82afb208f0d Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Wed, 21 May 2025 09:43:47 -0500 Subject: [PATCH 19/27] Update common.h --- code/logic/fossil/pizza/common.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/code/logic/fossil/pizza/common.h b/code/logic/fossil/pizza/common.h index a99425a4..6dda45a3 100644 --- a/code/logic/fossil/pizza/common.h +++ b/code/logic/fossil/pizza/common.h @@ -19,13 +19,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include // Only include once #ifdef _WIN32 #include @@ -33,8 +33,7 @@ #elif defined(__APPLE__) #define _DARWIN_C_SOURCE #include - #include // Ensure this is included before sysctl.h - #include + #include // Before sysctl.h #include #include #include @@ -44,7 +43,6 @@ #include #include #include - #include #endif #ifndef _POSIX_C_SOURCE From b033bd6a6c49398e12629149772e233782cc3344 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Wed, 21 May 2025 09:49:20 -0500 Subject: [PATCH 20/27] Update test_mock.c --- code/tests/cases/test_mock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/tests/cases/test_mock.c b/code/tests/cases/test_mock.c index 4f6ed6cc..5acdfb09 100644 --- a/code/tests/cases/test_mock.c +++ b/code/tests/cases/test_mock.c @@ -360,7 +360,7 @@ FOSSIL_TEST(c_mock_io_redirect_stdout_macro) { char buffer[256]; // Use the macro to redirect stdout and capture output - FOSSIL_MOCK_REDIRECT_STDOUT(buffer, sizeof(buffer), fossil_mockup_mock_function_redirection, NULL); + FOSSIL_MOCK_REDIRECT_STDOUT(buffer, sizeof(buffer), fossil_mockup_mock_function_redirection); // Test cases FOSSIL_TEST_ASSUME(strcmp(buffer, "Testing macro redirection!") == 0, "Captured output should match expected output"); From f40ad225bbeacfe17af7cba3a8359d4b29e55b77 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Wed, 21 May 2025 09:50:07 -0500 Subject: [PATCH 21/27] Update test_mock.cpp --- code/tests/cases/test_mock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/tests/cases/test_mock.cpp b/code/tests/cases/test_mock.cpp index c015145b..a27dc738 100644 --- a/code/tests/cases/test_mock.cpp +++ b/code/tests/cases/test_mock.cpp @@ -360,7 +360,7 @@ FOSSIL_TEST(cpp_mock_io_redirect_stdout_macro) { char buffer[256]; // Use the macro to redirect stdout and capture output - FOSSIL_MOCK_REDIRECT_STDOUT(buffer, sizeof(buffer), fossil_mockup_mock_function_redirection, NULL); + FOSSIL_MOCK_REDIRECT_STDOUT(buffer, sizeof(buffer), fossil_mockup_mock_function_redirection); // Test cases FOSSIL_TEST_ASSUME(strcmp(buffer, "Testing macro redirection!") == 0, "Captured output should match expected output"); From 0febec07444b5b276097ef17d8cadc283d0dde0b Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Wed, 21 May 2025 09:51:45 -0500 Subject: [PATCH 22/27] Update mock.h --- code/logic/fossil/pizza/mock.h | 1 + 1 file changed, 1 insertion(+) diff --git a/code/logic/fossil/pizza/mock.h b/code/logic/fossil/pizza/mock.h index 9262dd77..295a205b 100644 --- a/code/logic/fossil/pizza/mock.h +++ b/code/logic/fossil/pizza/mock.h @@ -395,3 +395,4 @@ bool fossil_mock_compare_output(const char *captured, const char *expected); _FOSSIL_MOCK_COMPARE_OUTPUT(captured, expected) #endif // FOSSIL_MOCK_FRAMEWORK_H + From 9b8edc1b43a4bbd79b6dd763df51dbe055024ca1 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Wed, 21 May 2025 09:59:39 -0500 Subject: [PATCH 23/27] Update test_mock.c --- code/tests/cases/test_mock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/tests/cases/test_mock.c b/code/tests/cases/test_mock.c index 5acdfb09..4f6ed6cc 100644 --- a/code/tests/cases/test_mock.c +++ b/code/tests/cases/test_mock.c @@ -360,7 +360,7 @@ FOSSIL_TEST(c_mock_io_redirect_stdout_macro) { char buffer[256]; // Use the macro to redirect stdout and capture output - FOSSIL_MOCK_REDIRECT_STDOUT(buffer, sizeof(buffer), fossil_mockup_mock_function_redirection); + FOSSIL_MOCK_REDIRECT_STDOUT(buffer, sizeof(buffer), fossil_mockup_mock_function_redirection, NULL); // Test cases FOSSIL_TEST_ASSUME(strcmp(buffer, "Testing macro redirection!") == 0, "Captured output should match expected output"); From 6c762a4c94c514acb411957a4f1b2a62566e7fff Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Wed, 21 May 2025 10:02:46 -0500 Subject: [PATCH 24/27] Update mock.c --- code/logic/mock.c | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/code/logic/mock.c b/code/logic/mock.c index e77c5943..0d22dfa5 100644 --- a/code/logic/mock.c +++ b/code/logic/mock.c @@ -135,27 +135,16 @@ void fossil_mock_print(fossil_mock_calllist_t *list) { } } -/** - * Captures the output of a function to a buffer for testing purposes. - * - * @param buffer The buffer to store the captured output. - * @param size The size of the buffer. - * @param function The function whose output is to be captured. - * @param ... The arguments to pass to the function. - * @return The number of characters captured. - */ -int fossil_mock_capture_output(char *buffer, size_t size, void (*function)(void), ...) { +int fossil_mock_capture_output(char *buffer, size_t size, void (*function)(void)) { if (!buffer || size == 0 || !function) { return -1; } - // Create a temporary file to capture stdout FILE *temp_file = tmpfile(); if (!temp_file) { return -1; } - // Redirect stdout to the temporary file int original_stdout_fd = dup(STDOUT_FILENO); if (original_stdout_fd == -1) { fclose(temp_file); @@ -168,35 +157,20 @@ int fossil_mock_capture_output(char *buffer, size_t size, void (*function)(void) return -1; } - // Call the function with variable arguments - va_list args; - va_start(args, function); - function(); - va_end(args); + function(); // no arguments passed - // Restore stdout fflush(stdout); dup2(original_stdout_fd, STDOUT_FILENO); close(original_stdout_fd); - // Rewind the temporary file and read its contents into the buffer rewind(temp_file); size_t read_size = fread(buffer, 1, size - 1, temp_file); - buffer[read_size] = '\0'; // Null-terminate the buffer + buffer[read_size] = '\0'; - // Close the temporary file fclose(temp_file); - return (int)read_size; } -/** - * Compares the captured output with the expected output. - * - * @param captured The captured output. - * @param expected The expected output. - * @return True if the captured output matches the expected output, false otherwise. - */ bool fossil_mock_compare_output(const char *captured, const char *expected) { if (!captured || !expected) { return false; From 2dbe8efb378920796a19a51704b0e3055673ed7e Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Wed, 21 May 2025 10:05:33 -0500 Subject: [PATCH 25/27] Update mock.h --- code/logic/fossil/pizza/mock.h | 36 +++++----------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/code/logic/fossil/pizza/mock.h b/code/logic/fossil/pizza/mock.h index 295a205b..45ffaaf8 100644 --- a/code/logic/fossil/pizza/mock.h +++ b/code/logic/fossil/pizza/mock.h @@ -123,10 +123,9 @@ void fossil_mock_print(fossil_mock_calllist_t *list); * @param buffer The buffer to store the captured output. * @param size The size of the buffer. * @param function The function whose output is to be captured. - * @param ... The arguments to pass to the function. * @return The number of characters captured. */ -int fossil_mock_capture_output(char *buffer, size_t size, void (*function)(void), ...); +int fossil_mock_capture_output(char *buffer, size_t size, void (*function)(void)); /** * Compares the captured output with the expected output. @@ -240,20 +239,8 @@ bool fossil_mock_compare_output(const char *captured, const char *expected); * @param buffer The buffer to capture the output. * @param size The size of the buffer. */ -#ifdef _WIN32 -#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ - fossil_mock_capture_output(buffer, size, function, __VA_ARGS__) -#elif defined(__APPLE__) -#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ - fossil_mock_capture_output(buffer, size, function, __VA_OPT(, __VA_ARGS__)) -#else -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L -#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ - fossil_mock_capture_output(buffer, size, function, __VA_OPT(, __VA_ARGS__)) -#else -#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, ...) \ - fossil_mock_capture_output(buffer, size, function, __VA_ARGS__) -#endif +#define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function) \ + fossil_mock_capture_output(buffer, size, function) #endif /** @@ -365,21 +352,8 @@ bool fossil_mock_compare_output(const char *captured, const char *expected); * @param buffer The buffer to capture the output. * @param size The size of the buffer. */ -#ifdef _WIN32 -#define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ - _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_ARGS__) -#elif defined(__APPLE__) -#define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ - _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_OPT(, __VA_ARGS__)) -#else -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L -#define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ - _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_OPT(, __VA_ARGS__)) -#else -#define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function, ...) \ - _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function, __VA_ARGS__) -#endif -#endif +#define FOSSIL_MOCK_REDIRECT_STDOUT(buffer, size, function) \ + _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function) /** * @def FOSSIL_MOCK_COMPARE_OUTPUT From d2909a5a6ea8ce8507781fc8f8efd03b885d737e Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Wed, 21 May 2025 10:07:26 -0500 Subject: [PATCH 26/27] Update mock.h --- code/logic/fossil/pizza/mock.h | 1 - 1 file changed, 1 deletion(-) diff --git a/code/logic/fossil/pizza/mock.h b/code/logic/fossil/pizza/mock.h index 45ffaaf8..583c6687 100644 --- a/code/logic/fossil/pizza/mock.h +++ b/code/logic/fossil/pizza/mock.h @@ -241,7 +241,6 @@ bool fossil_mock_compare_output(const char *captured, const char *expected); */ #define _FOSSIL_MOCK_CAPTURE_OUTPUT(buffer, size, function) \ fossil_mock_capture_output(buffer, size, function) -#endif /** * @def _FOSSIL_MOCK_REDIRECT_STDOUT From 2d767554128ba4d8978279da22fe9313347d972b Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" <55331536+dreamer-coding@users.noreply.github.com> Date: Wed, 21 May 2025 10:09:20 -0500 Subject: [PATCH 27/27] Update test_mock.c --- code/tests/cases/test_mock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/tests/cases/test_mock.c b/code/tests/cases/test_mock.c index 4f6ed6cc..5acdfb09 100644 --- a/code/tests/cases/test_mock.c +++ b/code/tests/cases/test_mock.c @@ -360,7 +360,7 @@ FOSSIL_TEST(c_mock_io_redirect_stdout_macro) { char buffer[256]; // Use the macro to redirect stdout and capture output - FOSSIL_MOCK_REDIRECT_STDOUT(buffer, sizeof(buffer), fossil_mockup_mock_function_redirection, NULL); + FOSSIL_MOCK_REDIRECT_STDOUT(buffer, sizeof(buffer), fossil_mockup_mock_function_redirection); // Test cases FOSSIL_TEST_ASSUME(strcmp(buffer, "Testing macro redirection!") == 0, "Captured output should match expected output");