|
| 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 | + * |
| 11 | + * Copyright (C) 2024 Fossil Logic. All rights reserved. |
| 12 | + * ----------------------------------------------------------------------------- |
| 13 | + */ |
| 14 | +#include <fossil/test/framework.h> |
| 15 | + |
| 16 | +#include "fossil/io/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_error_suite); |
| 27 | + |
| 28 | +// Setup function for the test suite |
| 29 | +FOSSIL_SETUP(c_error_suite) { |
| 30 | + // Setup code here |
| 31 | +} |
| 32 | + |
| 33 | +// Teardown function for the test suite |
| 34 | +FOSSIL_TEARDOWN(c_error_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 | +FOSSIL_TEST_CASE(c_test_io_what_no_error) { |
| 47 | + const char *result = fossil_io_what(FOSSIL_ERROR_OK); |
| 48 | + ASSUME_ITS_EQUAL_CSTR("No error, operation successful.", result); |
| 49 | +} |
| 50 | + |
| 51 | +FOSSIL_TEST_CASE(c_test_io_what_null_pointer) { |
| 52 | + const char *result = fossil_io_what(FOSSIL_ERROR_NULL_POINTER); |
| 53 | + ASSUME_ITS_EQUAL_CSTR("Null pointer encountered.", result); |
| 54 | +} |
| 55 | + |
| 56 | +FOSSIL_TEST_CASE(c_test_io_what_invalid_argument) { |
| 57 | + const char *result = fossil_io_what(FOSSIL_ERROR_INVALID_ARGUMENT); |
| 58 | + ASSUME_ITS_EQUAL_CSTR("Invalid argument provided.", result); |
| 59 | +} |
| 60 | + |
| 61 | +FOSSIL_TEST_CASE(c_test_io_what_type_mismatch) { |
| 62 | + const char *result = fossil_io_what(FOSSIL_ERROR_TYPE_MISMATCH); |
| 63 | + ASSUME_ITS_EQUAL_CSTR("Type mismatch encountered.", result); |
| 64 | +} |
| 65 | + |
| 66 | +FOSSIL_TEST_CASE(c_test_io_what_invalid_operation) { |
| 67 | + const char *result = fossil_io_what(FOSSIL_ERROR_INVALID_OPERATION); |
| 68 | + ASSUME_ITS_EQUAL_CSTR("Invalid operation.", result); |
| 69 | +} |
| 70 | + |
| 71 | +FOSSIL_TEST_CASE(c_test_io_what_unknown) { |
| 72 | + const char *result = fossil_io_what(FOSSIL_ERROR_UNKNOWN); |
| 73 | + ASSUME_ITS_EQUAL_CSTR("Unknown error.", result); |
| 74 | +} |
| 75 | + |
| 76 | +FOSSIL_TEST_CASE(c_test_io_what_custom) { |
| 77 | + const char *result = fossil_io_what(FOSSIL_ERROR_CUSTOM); |
| 78 | + ASSUME_ITS_EQUAL_CSTR("Custom error occurred.", result); |
| 79 | +} |
| 80 | + |
| 81 | +FOSSIL_TEST_CASE(c_test_io_what_internal) { |
| 82 | + const char *result = fossil_io_what(FOSSIL_ERROR_INTERNAL); |
| 83 | + ASSUME_ITS_EQUAL_CSTR("Internal error.", result); |
| 84 | +} |
| 85 | + |
| 86 | +FOSSIL_TEST_CASE(c_test_io_what_unknown_error_code) { |
| 87 | + const char *result = fossil_io_what(FOSSIL_ERROR_UNKNOWN_ERROR_CODE); |
| 88 | + ASSUME_ITS_EQUAL_CSTR("Unknown error code.", result); |
| 89 | +} |
| 90 | + |
| 91 | +FOSSIL_TEST_CASE(c_test_io_what_overflow_int) { |
| 92 | + const char *result = fossil_io_what(FOSSIL_ERROR_OVERFLOW_INT); |
| 93 | + ASSUME_ITS_EQUAL_CSTR("Integer overflow.", result); |
| 94 | +} |
| 95 | + |
| 96 | +FOSSIL_TEST_CASE(c_test_io_what_underflow_int) { |
| 97 | + const char *result = fossil_io_what(FOSSIL_ERROR_UNDERFLOW_INT); |
| 98 | + ASSUME_ITS_EQUAL_CSTR("Integer underflow.", result); |
| 99 | +} |
| 100 | + |
| 101 | +FOSSIL_TEST_CASE(c_test_io_what_overflow_float) { |
| 102 | + const char *result = fossil_io_what(FOSSIL_ERROR_OVERFLOW_FLOAT); |
| 103 | + ASSUME_ITS_EQUAL_CSTR("Float overflow.", result); |
| 104 | +} |
| 105 | + |
| 106 | +FOSSIL_TEST_CASE(c_test_io_what_underflow_float) { |
| 107 | + const char *result = fossil_io_what(FOSSIL_ERROR_UNDERFLOW_FLOAT); |
| 108 | + ASSUME_ITS_EQUAL_CSTR("Float underflow.", result); |
| 109 | +} |
| 110 | + |
| 111 | +FOSSIL_TEST_CASE(c_test_io_what_division_by_zero) { |
| 112 | + const char *result = fossil_io_what(FOSSIL_ERROR_DIVISION_BY_ZERO); |
| 113 | + ASSUME_ITS_EQUAL_CSTR("Division by zero.", result); |
| 114 | +} |
| 115 | + |
| 116 | +FOSSIL_TEST_CASE(c_test_io_what_invalid_cast) { |
| 117 | + const char *result = fossil_io_what(FOSSIL_ERROR_INVALID_CAST); |
| 118 | + ASSUME_ITS_EQUAL_CSTR("Invalid type cast.", result); |
| 119 | +} |
| 120 | + |
| 121 | +FOSSIL_TEST_CASE(c_test_io_what_out_of_memory) { |
| 122 | + const char *result = fossil_io_what(FOSSIL_ERROR_OUT_OF_MEMORY); |
| 123 | + ASSUME_ITS_EQUAL_CSTR("Out of memory.", result); |
| 124 | +} |
| 125 | + |
| 126 | +FOSSIL_TEST_CASE(c_test_io_what_memory_corruption) { |
| 127 | + const char *result = fossil_io_what(FOSSIL_ERROR_MEMORY_CORRUPTION); |
| 128 | + ASSUME_ITS_EQUAL_CSTR("Memory corruption detected.", result); |
| 129 | +} |
| 130 | + |
| 131 | +FOSSIL_TEST_CASE(c_test_io_what_buffer_overflow) { |
| 132 | + const char *result = fossil_io_what(FOSSIL_ERROR_BUFFER_OVERFLOW); |
| 133 | + ASSUME_ITS_EQUAL_CSTR("Buffer overflow.", result); |
| 134 | +} |
| 135 | + |
| 136 | +FOSSIL_TEST_CASE(c_test_io_what_buffer_underflow) { |
| 137 | + const char *result = fossil_io_what(FOSSIL_ERROR_BUFFER_UNDERFLOW); |
| 138 | + ASSUME_ITS_EQUAL_CSTR("Buffer underflow.", result); |
| 139 | +} |
| 140 | + |
| 141 | +FOSSIL_TEST_CASE(c_test_io_what_file_not_found) { |
| 142 | + const char *result = fossil_io_what(FOSSIL_ERROR_FILE_NOT_FOUND); |
| 143 | + ASSUME_ITS_EQUAL_CSTR("File not found.", result); |
| 144 | +} |
| 145 | + |
| 146 | +FOSSIL_TEST_CASE(c_test_io_what_permission_denied) { |
| 147 | + const char *result = fossil_io_what(FOSSIL_ERROR_PERMISSION_DENIED); |
| 148 | + ASSUME_ITS_EQUAL_CSTR("Permission denied.", result); |
| 149 | +} |
| 150 | + |
| 151 | +FOSSIL_TEST_CASE(c_test_io_what_network_failure) { |
| 152 | + const char *result = fossil_io_what(FOSSIL_ERROR_NETWORK_FAILURE); |
| 153 | + ASSUME_ITS_EQUAL_CSTR("Network failure.", result); |
| 154 | +} |
| 155 | + |
| 156 | +FOSSIL_TEST_CASE(c_test_io_what_timeout) { |
| 157 | + const char *result = fossil_io_what(FOSSIL_ERROR_TIMEOUT); |
| 158 | + ASSUME_ITS_EQUAL_CSTR("Network timeout.", result); |
| 159 | +} |
| 160 | + |
| 161 | +FOSSIL_TEST_CASE(c_test_io_what_unknown_host) { |
| 162 | + const char *result = fossil_io_what(FOSSIL_ERROR_UNKNOWN_HOST); |
| 163 | + ASSUME_ITS_EQUAL_CSTR("Unknown host.", result); |
| 164 | +} |
| 165 | + |
| 166 | +FOSSIL_TEST_CASE(c_test_io_what_connection_refused) { |
| 167 | + const char *result = fossil_io_what(FOSSIL_ERROR_CONNECTION_REFUSED); |
| 168 | + ASSUME_ITS_EQUAL_CSTR("Connection refused.", result); |
| 169 | +} |
| 170 | + |
| 171 | +FOSSIL_TEST_CASE(c_test_io_what_sql_injection) { |
| 172 | + const char *result = fossil_io_what(FOSSIL_ERROR_SQL_INJECTION); |
| 173 | + ASSUME_ITS_EQUAL_CSTR("SQL injection attempt detected.", result); |
| 174 | +} |
| 175 | + |
| 176 | +FOSSIL_TEST_CASE(c_test_io_what_xss_attack) { |
| 177 | + const char *result = fossil_io_what(FOSSIL_ERROR_XSS_ATTACK); |
| 178 | + ASSUME_ITS_EQUAL_CSTR("Cross-site scripting attack detected.", result); |
| 179 | +} |
| 180 | + |
| 181 | +FOSSIL_TEST_CASE(c_test_io_what_csrf_attack) { |
| 182 | + const char *result = fossil_io_what(FOSSIL_ERROR_CSRF_ATTACK); |
| 183 | + ASSUME_ITS_EQUAL_CSTR("Cross-site request forgery attack detected.", result); |
| 184 | +} |
| 185 | + |
| 186 | +FOSSIL_TEST_CASE(c_test_io_what_user_abort) { |
| 187 | + const char *result = fossil_io_what(FOSSIL_ERROR_USER_ABORT); |
| 188 | + ASSUME_ITS_EQUAL_CSTR("User aborted operation.", result); |
| 189 | +} |
| 190 | + |
| 191 | +FOSSIL_TEST_CASE(c_test_io_what_database_connection_failed) { |
| 192 | + const char *result = fossil_io_what(FOSSIL_ERROR_DATABASE_CONNECTION_FAILED); |
| 193 | + ASSUME_ITS_EQUAL_CSTR("Database connection failed.", result); |
| 194 | +} |
| 195 | + |
| 196 | +FOSSIL_TEST_CASE(c_test_io_what_serialization_failed) { |
| 197 | + const char *result = fossil_io_what(FOSSIL_ERROR_SERIALIZATION_FAILED); |
| 198 | + ASSUME_ITS_EQUAL_CSTR("Serialization failed.", result); |
| 199 | +} |
| 200 | + |
| 201 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 202 | +// * Fossil Logic Test Pool |
| 203 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 204 | + |
| 205 | +FOSSIL_TEST_GROUP(c_error_tests) { |
| 206 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_no_error); |
| 207 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_null_pointer); |
| 208 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_invalid_argument); |
| 209 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_type_mismatch); |
| 210 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_invalid_operation); |
| 211 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_unknown); |
| 212 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_custom); |
| 213 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_internal); |
| 214 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_unknown_error_code); |
| 215 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_overflow_int); |
| 216 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_underflow_int); |
| 217 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_overflow_float); |
| 218 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_underflow_float); |
| 219 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_division_by_zero); |
| 220 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_invalid_cast); |
| 221 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_out_of_memory); |
| 222 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_memory_corruption); |
| 223 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_buffer_overflow); |
| 224 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_buffer_underflow); |
| 225 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_file_not_found); |
| 226 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_permission_denied); |
| 227 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_network_failure); |
| 228 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_timeout); |
| 229 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_unknown_host); |
| 230 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_connection_refused); |
| 231 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_sql_injection); |
| 232 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_xss_attack); |
| 233 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_csrf_attack); |
| 234 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_user_abort); |
| 235 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_database_connection_failed); |
| 236 | + FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_serialization_failed); |
| 237 | + |
| 238 | + FOSSIL_TEST_REGISTER(c_error_suite); |
| 239 | +} |
0 commit comments