|
| 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 | +#include <fossil/test/framework.h> |
| 16 | +#include <string.h> |
| 17 | + |
| 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(c_mock_suite); |
| 28 | + |
| 29 | +// Setup function for the test suite |
| 30 | +FOSSIL_SETUP(c_mock_suite) { |
| 31 | + // Setup code here |
| 32 | +} |
| 33 | + |
| 34 | +// Teardown function for the test suite |
| 35 | +FOSSIL_TEARDOWN(c_mock_suite) { |
| 36 | + // Teardown code here |
| 37 | +} |
| 38 | + |
| 39 | +FOSSIL_MOCK_ALIAS(MockInt, int); |
| 40 | + |
| 41 | +// Example of creating a mock struct using the macro |
| 42 | +FOSSIL_MOCK_STRUCT(MockStruct) { |
| 43 | + int a; |
| 44 | + char b; |
| 45 | +} MockStruct; |
| 46 | + |
| 47 | +// Example of creating a mock function using the macro |
| 48 | +FOSSIL_MOCK_FUNC(int, mock_function, int a, int b) { |
| 49 | + return a + b; |
| 50 | +} |
| 51 | + |
| 52 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 53 | +// * Fossil Logic Test Cases |
| 54 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 55 | +// The test cases below are provided as samples, showcasing |
| 56 | +// Domain-Driven Design (DDD) usage in the Fossil Logic project. |
| 57 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 58 | + |
| 59 | +FOSSIL_TEST_CASE(c_mock_call_list_initialization) { |
| 60 | + // Example of initializing a MockCallList |
| 61 | + MockCallList list; |
| 62 | + fossil_mock_init(&list); |
| 63 | + |
| 64 | + // Test cases |
| 65 | + FOSSIL_TEST_ASSUME(list.head == NULL, "MockCallList head should be NULL after initialization"); |
| 66 | + FOSSIL_TEST_ASSUME(list.tail == NULL, "MockCallList tail should be NULL after initialization"); |
| 67 | + FOSSIL_TEST_ASSUME(list.size == 0, "MockCallList size should be 0 after initialization"); |
| 68 | +} // end case |
| 69 | + |
| 70 | +FOSSIL_TEST_CASE(c_mock_call_list_addition) { |
| 71 | + // Example of adding a MockCall to a MockCallList |
| 72 | + MockCallList list; |
| 73 | + fossil_mock_init(&list); |
| 74 | + char *args[] = {"arg1", "arg2"}; |
| 75 | + fossil_mock_add_call(&list, "test_function", args, 2); |
| 76 | + |
| 77 | + // Test cases |
| 78 | + FOSSIL_TEST_ASSUME(list.size == 1, "MockCallList size should be 1 after adding a call"); |
| 79 | + FOSSIL_TEST_ASSUME(strcmp(list.head->function_name, "test_function") == 0, "Function name should be 'test_function'"); |
| 80 | + FOSSIL_TEST_ASSUME(list.head->num_args == 2, "Number of arguments should be 2"); |
| 81 | + FOSSIL_TEST_ASSUME(strcmp(list.head->arguments[0], "arg1") == 0, "First argument should be 'arg1'"); |
| 82 | + FOSSIL_TEST_ASSUME(strcmp(list.head->arguments[1], "arg2") == 0, "Second argument should be 'arg2'"); |
| 83 | +} // end case |
| 84 | + |
| 85 | +FOSSIL_TEST_CASE(c_mock_call_list_destruction) { |
| 86 | + // Example of destroying a MockCallList |
| 87 | + MockCallList list; |
| 88 | + fossil_mock_init(&list); |
| 89 | + char *args[] = {"arg1", "arg2"}; |
| 90 | + fossil_mock_add_call(&list, "test_function", args, 2); |
| 91 | + fossil_mock_destroy(&list); |
| 92 | + |
| 93 | + // Test cases |
| 94 | + FOSSIL_TEST_ASSUME(list.head == NULL, "MockCallList head should be NULL after destruction"); |
| 95 | + FOSSIL_TEST_ASSUME(list.tail == NULL, "MockCallList tail should be NULL after destruction"); |
| 96 | + FOSSIL_TEST_ASSUME(list.size == 0, "MockCallList size should be 0 after destruction"); |
| 97 | +} // end case |
| 98 | + |
| 99 | +FOSSIL_TEST_CASE(c_mock_call_list_initialization_macro) { |
| 100 | + // Example of initializing a MockCallList using the macro |
| 101 | + MockCallList list; |
| 102 | + MOCK_INIT(list); |
| 103 | + |
| 104 | + // Test cases |
| 105 | + FOSSIL_TEST_ASSUME(list.head == NULL, "MockCallList head should be NULL after initialization"); |
| 106 | + FOSSIL_TEST_ASSUME(list.tail == NULL, "MockCallList tail should be NULL after initialization"); |
| 107 | + FOSSIL_TEST_ASSUME(list.size == 0, "MockCallList size should be 0 after initialization"); |
| 108 | +} // end case |
| 109 | + |
| 110 | +FOSSIL_TEST_CASE(c_mock_call_list_addition_macro) { |
| 111 | + // Example of adding a MockCall to a MockCallList using the macro |
| 112 | + MockCallList list; |
| 113 | + MOCK_INIT(list); |
| 114 | + char *args[] = {"arg1", "arg2"}; |
| 115 | + MOCK_ADD_CALL(list, "test_function", args, 2); |
| 116 | + |
| 117 | + // Test cases |
| 118 | + FOSSIL_TEST_ASSUME(list.size == 1, "MockCallList size should be 1 after adding a call"); |
| 119 | + FOSSIL_TEST_ASSUME(strcmp(list.head->function_name, "test_function") == 0, "Function name should be 'test_function'"); |
| 120 | + FOSSIL_TEST_ASSUME(list.head->num_args == 2, "Number of arguments should be 2"); |
| 121 | + FOSSIL_TEST_ASSUME(strcmp(list.head->arguments[0], "arg1") == 0, "First argument should be 'arg1'"); |
| 122 | + FOSSIL_TEST_ASSUME(strcmp(list.head->arguments[1], "arg2") == 0, "Second argument should be 'arg2'"); |
| 123 | +} // end case |
| 124 | + |
| 125 | +FOSSIL_TEST_CASE(c_mock_call_list_destruction_macro) { |
| 126 | + // Example of destroying a MockCallList using the macro |
| 127 | + MockCallList list; |
| 128 | + MOCK_INIT(list); |
| 129 | + char *args[] = {"arg1", "arg2"}; |
| 130 | + MOCK_ADD_CALL(list, "test_function", args, 2); |
| 131 | + MOCK_DESTROY(list); |
| 132 | + |
| 133 | + // Test cases |
| 134 | + FOSSIL_TEST_ASSUME(list.head == NULL, "MockCallList head should be NULL after destruction"); |
| 135 | + FOSSIL_TEST_ASSUME(list.tail == NULL, "MockCallList tail should be NULL after destruction"); |
| 136 | + FOSSIL_TEST_ASSUME(list.size == 0, "MockCallList size should be 0 after destruction"); |
| 137 | +} // end case |
| 138 | + |
| 139 | +FOSSIL_TEST_CASE(c_mock_function_creation) { |
| 140 | + // Test cases |
| 141 | + FOSSIL_TEST_ASSUME(fossil_mockup_mock_function(2, 3) == 5, "Mock function should return the sum of its arguments"); |
| 142 | +} // end case |
| 143 | + |
| 144 | +FOSSIL_TEST_CASE(c_mock_alias_creation) { |
| 145 | + // Example of creating a type alias using the macro |
| 146 | + |
| 147 | + |
| 148 | + // Test cases |
| 149 | + MockInt x = 10; |
| 150 | + FOSSIL_TEST_ASSUME(x == 10, "Mock alias should behave like the original type"); |
| 151 | +} // end case |
| 152 | + |
| 153 | +FOSSIL_TEST_CASE(c_mock_struct_creation) { |
| 154 | + // Test cases |
| 155 | + MockStruct instance; |
| 156 | + instance.a = 5; |
| 157 | + instance.b = 'c'; |
| 158 | + FOSSIL_TEST_ASSUME(instance.a == 5, "Mock struct member 'a' should be 5"); |
| 159 | + FOSSIL_TEST_ASSUME(instance.b == 'c', "Mock struct member 'b' should be 'c'"); |
| 160 | +} // end case |
| 161 | + |
| 162 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 163 | +// * Fossil Logic Test Pool |
| 164 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 165 | +FOSSIL_TEST_GROUP(c_mock_test_cases) { |
| 166 | + FOSSIL_TEST_ADD(c_mock_suite, c_mock_call_list_initialization); |
| 167 | + FOSSIL_TEST_ADD(c_mock_suite, c_mock_call_list_addition); |
| 168 | +// FOSSIL_TEST_ADD(c_mock_suite, c_mock_call_list_destruction); |
| 169 | + FOSSIL_TEST_ADD(c_mock_suite, c_mock_call_list_initialization_macro); |
| 170 | + FOSSIL_TEST_ADD(c_mock_suite, c_mock_call_list_addition_macro); |
| 171 | + // FOSSIL_TEST_ADD(c_mock_suite, c_mock_call_list_destruction_macro); |
| 172 | + FOSSIL_TEST_ADD(c_mock_suite, c_mock_function_creation); |
| 173 | + FOSSIL_TEST_ADD(c_mock_suite, c_mock_alias_creation); |
| 174 | + FOSSIL_TEST_ADD(c_mock_suite, c_mock_struct_creation); |
| 175 | + |
| 176 | + FOSSIL_TEST_REGISTER(c_mock_suite); |
| 177 | +} // end of group |
0 commit comments