@@ -49,6 +49,14 @@ FOSSIL_MOCK_FUNC(int, cpp_mock_function, int a, int b) {
4949 return a + b;
5050}
5151
52+ FOSSIL_MOCK_FUNC (void , cpp_mock_function_with_output, void ) {
53+ pizza_io_printf (" Hello, Fossil Logic!" );
54+ }
55+
56+ FOSSIL_MOCK_FUNC (void , mock_function_redirection, void ) {
57+ pizza_io_printf (" Testing macro redirection!" );
58+ }
59+
5260// * * * * * * * * * * * * * * * * * * * * * * * *
5361// * Fossil Logic Test Cases
5462// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -62,8 +70,8 @@ FOSSIL_TEST(cpp_mock_call_list_initialization) {
6270 fossil_mock_init (&list);
6371
6472 // Test cases
65- FOSSIL_TEST_ASSUME (list.head == nullptr , " fossil_mock_calllist_t head should be nullptr after initialization" );
66- FOSSIL_TEST_ASSUME (list.tail == nullptr , " fossil_mock_calllist_t tail should be nullptr after initialization" );
73+ FOSSIL_TEST_ASSUME (list.head == NULL , " fossil_mock_calllist_t head should be NULL after initialization" );
74+ FOSSIL_TEST_ASSUME (list.tail == NULL , " fossil_mock_calllist_t tail should be NULL after initialization" );
6775 FOSSIL_TEST_ASSUME (list.size == 0 , " fossil_mock_calllist_t size should be 0 after initialization" );
6876} // end case
6977
@@ -208,7 +216,7 @@ FOSSIL_TEST(cpp_mock_call_list_edge_cases) {
208216 fossil_mock_init (&list);
209217
210218 // Add a call with no arguments
211- fossil_mock_add_call (&list, " no_args_function" , nullptr , 0 );
219+ fossil_mock_add_call (&list, " no_args_function" , NULL , 0 );
212220
213221 // Test cases
214222 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) {
253261 MOCK_INIT (list);
254262
255263 // Test cases
256- FOSSIL_TEST_ASSUME (list.head == nullptr , " fossil_mock_calllist_t head should be nullptr after initialization using macro" );
257- FOSSIL_TEST_ASSUME (list.tail == nullptr , " fossil_mock_calllist_t tail should be nullptr after initialization using macro" );
264+ FOSSIL_TEST_ASSUME (list.head == NULL , " fossil_mock_calllist_t head should be NULL after initialization using macro" );
265+ FOSSIL_TEST_ASSUME (list.tail == NULL , " fossil_mock_calllist_t tail should be NULL after initialization using macro" );
258266 FOSSIL_TEST_ASSUME (list.size == 0 , " fossil_mock_calllist_t size should be 0 after initialization using macro" );
259267} // end case
260268
@@ -318,11 +326,58 @@ FOSSIL_TEST(cpp_mock_macro_destruction) {
318326 MOCK_DESTROY (list);
319327
320328 // Test cases
321- FOSSIL_TEST_ASSUME (list.head == nullptr , " fossil_mock_calllist_t head should be nullptr after destruction using macro" );
322- FOSSIL_TEST_ASSUME (list.tail == nullptr , " fossil_mock_calllist_t tail should be nullptr after destruction using macro" );
329+ FOSSIL_TEST_ASSUME (list.head == NULL , " fossil_mock_calllist_t head should be NULL after destruction using macro" );
330+ FOSSIL_TEST_ASSUME (list.tail == NULL , " fossil_mock_calllist_t tail should be NULL after destruction using macro" );
323331 FOSSIL_TEST_ASSUME (list.size == 0 , " fossil_mock_calllist_t size should be 0 after destruction using macro" );
324332} // end case
325333
334+ FOSSIL_TEST (cpp_mock_io_capture_output) {
335+ // Buffer to capture output
336+ char buffer[256 ];
337+
338+ // Capture the output of the mock function
339+ int captured_size = fossil_mock_capture_output (buffer, sizeof (buffer), fossil_mockup_cpp_mock_function_with_output);
340+
341+ // Test cases
342+ FOSSIL_TEST_ASSUME (captured_size > 0 , " Captured size should be greater than 0" );
343+ FOSSIL_TEST_ASSUME (strcmp (buffer, " Hello, Fossil Logic!" ) == 0 , " Captured output should match expected output" );
344+ } // end case
345+
346+ FOSSIL_TEST (cpp_mock_io_compare_output) {
347+ // Captured and expected outputs
348+ const char *captured = " Hello, Fossil Logic!" ;
349+ const char *expected = " Hello, Fossil Logic!" ;
350+
351+ // Compare the outputs
352+ bool result = fossil_mock_compare_output (captured, expected);
353+
354+ // Test cases
355+ FOSSIL_TEST_ASSUME (result == true , " Captured output should match expected output" );
356+ } // end case
357+
358+ FOSSIL_TEST (cpp_mock_io_redirect_stdout_macro) {
359+ // Buffer to capture output
360+ char buffer[256 ];
361+
362+ // Use the macro to redirect stdout and capture output
363+ FOSSIL_MOCK_REDIRECT_STDOUT (buffer, sizeof (buffer), fossil_mockup_mock_function_redirection);
364+
365+ // Test cases
366+ FOSSIL_TEST_ASSUME (strcmp (buffer, " Testing macro redirection!" ) == 0 , " Captured output should match expected output" );
367+ } // end case
368+
369+ FOSSIL_TEST (cpp_mock_io_compare_output_macro) {
370+ // Captured and expected outputs
371+ const char *captured = " Macro comparison test!" ;
372+ const char *expected = " Macro comparison test!" ;
373+
374+ // Use the macro to compare outputs
375+ bool result = FOSSIL_MOCK_COMPARE_OUTPUT (captured, expected);
376+
377+ // Test cases
378+ FOSSIL_TEST_ASSUME (result == true , " Captured output should match expected output using macro" );
379+ } // end case
380+
326381// * * * * * * * * * * * * * * * * * * * * * * * *
327382// * Fossil Logic Test Pool
328383// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -341,5 +396,11 @@ FOSSIL_TEST_GROUP(cpp_mock_test_cases) {
341396 FOSSIL_TEST_ADD (cpp_mock_suite, cpp_mock_macro_addition);
342397 FOSSIL_TEST_ADD (cpp_mock_suite, cpp_mock_macro_destruction);
343398
399+ FOSSIL_TEST_ADD (cpp_mock_suite, cpp_mock_io_capture_output);
400+ FOSSIL_TEST_ADD (cpp_mock_suite, cpp_mock_io_compare_output);
401+ FOSSIL_TEST_ADD (cpp_mock_suite, cpp_mock_io_redirect_stdout_macro);
402+ FOSSIL_TEST_ADD (cpp_mock_suite, cpp_mock_io_compare_output_macro);
403+ FOSSIL_TEST_ADD (cpp_mock_suite, cpp_mock_io_compare_output);
404+
344405 FOSSIL_TEST_REGISTER (cpp_mock_suite);
345406} // end of group
0 commit comments