Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2015 Samsung Electronics Co., Ltd |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to deal in the Software without restriction, including |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | * permit persons to whom the Software is furnished to do so, subject to |
| 10 | * the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the |
| 13 | * next paragraph) shall be included in all copies or substantial |
| 14 | * portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
| 24 | */ |
| 25 | |
| 26 | #ifndef Z_UNIT_C_H |
| 27 | #define Z_UNIT_C_H |
| 28 | |
| 29 | #include <limits.h> |
| 30 | #include <stdarg.h> |
| 31 | #include <stdbool.h> |
| 32 | #include <stdint.h> |
| 33 | |
| 34 | #include "zunitc/zunitc_impl.h" |
| 35 | |
| 36 | #if !__GNUC__ |
| 37 | #error Framework currently requires gcc or compatible compiler. |
| 38 | #endif |
| 39 | |
| 40 | #if INTPTR_MAX < INT_MAX |
| 41 | #error Odd platform requires rework of value type from intptr_t to custom. |
| 42 | #endif |
| 43 | |
| 44 | /** |
| 45 | * @file |
| 46 | * Simple unit test framework declarations. |
| 47 | */ |
| 48 | |
| 49 | #ifdef __cplusplus |
| 50 | extern "C" { |
| 51 | #endif |
| 52 | |
| 53 | /** |
| 54 | * @page zunitc |
| 55 | */ |
| 56 | |
| 57 | /** |
| 58 | * Structure to use when defining a test fixture. |
| 59 | * @note likely pending refactoring as use cases are refined. |
| 60 | */ |
| 61 | struct zuc_fixture { |
| 62 | /** |
| 63 | * Initial optional seed data to pass to setup functions and/or tests. |
| 64 | */ |
| 65 | const void *data; |
| 66 | |
| 67 | /** |
| 68 | * Per-suite setup called before invoking any of the tests |
| 69 | * contained in the suite. |
| 70 | * |
| 71 | * @return a pointer to test data, or NULL. |
| 72 | */ |
| 73 | void *(*set_up_test_case)(const void *data); |
| 74 | |
| 75 | /** |
| 76 | * Per-suite tear-down called after invoking all of the tests |
| 77 | * contained in the suite. |
| 78 | * |
| 79 | * @param data pointer returned from the setup function. |
| 80 | */ |
| 81 | void (*tear_down_test_case)(void *data); |
| 82 | |
| 83 | /** |
| 84 | * Setup called before running each of the tests in the suite. |
| 85 | * |
| 86 | * @param data optional data from suite setup, or NULL. |
| 87 | * @return a pointer to test data, or NULL. |
| 88 | */ |
| 89 | void *(*set_up)(void *data); |
| 90 | |
| 91 | /** |
| 92 | * Tear-down called after running each of the tests in the suite. |
| 93 | * |
| 94 | * @param data pointer returned from the setup function. |
| 95 | */ |
| 96 | void (*tear_down)(void *data); |
| 97 | }; |
| 98 | |
| 99 | /** |
| 100 | * Process exit code to mark skipped tests, consistent with |
| 101 | * automake tests. |
| 102 | */ |
| 103 | #define ZUC_EXIT_SKIP 77 |
| 104 | |
| 105 | /** |
| 106 | * Accesses the test executable program name. |
| 107 | * This version will include any full or partial path used to |
| 108 | * launch the executable. |
| 109 | * |
| 110 | * @note This depends on zuc_initialize() having been called. |
| 111 | * |
| 112 | * @return the name of the running program. |
| 113 | * The caller should not free nor hold this pointer. It will not stay |
| 114 | * valid across calls to zuc_initialize() or zuc_cleanup(). |
| 115 | * @see zuc_get_program_basename() |
| 116 | */ |
| 117 | const char * |
| 118 | zuc_get_program_name(void); |
| 119 | |
| 120 | /** |
| 121 | * Accesses the test executable program name in trimmed format. |
| 122 | * If the program is launched via a partial or full path, this |
| 123 | * version trims to return only the basename. |
| 124 | * |
| 125 | * @note This depends on zuc_initialize() having been called. |
| 126 | * |
| 127 | * @return the name of the running program. |
| 128 | * The caller should not free nor hold this pointer. It will not stay |
| 129 | * valid across calls to zuc_initialize() or zuc_cleanup(). |
| 130 | * @see zuc_get_program_name() |
| 131 | */ |
| 132 | const char * |
| 133 | zuc_get_program_basename(void); |
| 134 | |
| 135 | /** |
| 136 | * Initializes the test framework and consumes any known command-line |
| 137 | * parameters from the list. |
| 138 | * The exception is 'h/help' which will be left in place for follow-up |
| 139 | * processing by the hosting app if so desired. |
| 140 | * |
| 141 | * @param argc pointer to argc value to read and possibly change. |
| 142 | * @param argv array of parameter pointers to read and possibly change. |
| 143 | * @param help_flagged if non-NULL will be set to true if the user |
| 144 | * specifies the help flag (and framework help has been output). |
| 145 | * @return EXIT_SUCCESS upon success setting or help, EXIT_FAILURE otherwise. |
| 146 | */ |
| 147 | int zuc_initialize(int *argc, char *argv[], bool *help_flagged); |
| 148 | |
| 149 | /** |
| 150 | * Runs all tests that have been registered. |
| 151 | * Expected return values include EXIT_FAILURE if any errors or failures |
| 152 | * have occurred, ::ZUC_EXIT_SKIP if no failures have occurred but at least |
| 153 | * one test reported skipped, otherwise EXIT_SUCCESS if nothing of note |
| 154 | * was recorded. |
| 155 | * |
| 156 | * @note for consistency with other frameworks and to allow for additional |
| 157 | * cleanup to be added later this is implemented as a wrapper macro. |
| 158 | * |
| 159 | * @return expected exit status - normally EXIT_SUCCESS, ::ZUC_EXIT_SKIP, |
| 160 | * or EXIT_FAILURE. |
| 161 | * Normally an application can use this value directly in calling exit(), |
| 162 | * however there could be cases where some additional processing such as |
| 163 | * resource cleanup or library shutdown that a program might want to do |
| 164 | * first. |
| 165 | */ |
| 166 | #define ZUC_RUN_TESTS() \ |
| 167 | zucimpl_run_tests() |
| 168 | |
| 169 | /** |
| 170 | * Clears the test system in preparation for application shutdown. |
| 171 | */ |
| 172 | void |
| 173 | zuc_cleanup(void); |
| 174 | |
| 175 | /** |
| 176 | * Displays all known tests. |
Bryce Harrington | 35e7b10 | 2015-07-13 12:23:01 -0700 | [diff] [blame] | 177 | * The list returned is affected by any filtering in place. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 178 | * |
| 179 | * @see zuc_set_filter() |
| 180 | */ |
| 181 | void |
| 182 | zuc_list_tests(void); |
| 183 | |
| 184 | /** |
| 185 | * Sets the filter string to use for tests. |
| 186 | * The format is a series of patterns separated by a colon, with wildcards |
| 187 | * and an optional flag for negative matching. For wildcards, the '*' |
| 188 | * character will match any sequence and the '?' character will match any |
| 189 | * single character. |
| 190 | * The '-' character at the start of a pattern marks the end of the |
| 191 | * patterns required to match and the begining of patterns that names |
| 192 | * must not match. |
| 193 | * Defaults to use all tests. |
| 194 | * |
| 195 | * @param filter the filter string to apply to tests. |
| 196 | */ |
| 197 | void |
| 198 | zuc_set_filter(const char *filter); |
| 199 | |
| 200 | /** |
| 201 | * Trigger specific failure/signal upon test failures; useful when |
| 202 | * running under a debugger. |
| 203 | * Currently this is implemented to raise a SIGABRT signal when any |
| 204 | * failure is reported. |
| 205 | * Defaults to false. |
| 206 | * |
| 207 | * @param break_on_failure true to cause a break when tests fail, false to |
| 208 | * allow normal operation upon failures. |
| 209 | */ |
| 210 | void |
| 211 | zuc_set_break_on_failure(bool break_on_failure); |
| 212 | |
| 213 | /** |
| 214 | * Sets the number of times to repeat the tests. |
| 215 | * Any number higher than 1 will cause the tests to be repeated the |
| 216 | * specified number of times. |
| 217 | * Defaults to 1/no repeating. |
| 218 | * |
| 219 | * @param repeat number of times to repeat the tests. |
| 220 | */ |
| 221 | void |
| 222 | zuc_set_repeat(int repeat); |
| 223 | |
| 224 | /** |
| 225 | * Randomizes the order in which tests are executed. |
| 226 | * A value of 0 (the default) means tests are executed in their natural |
| 227 | * ordering. A value of 1 will pick a random seed based on the time to |
| 228 | * use for running tests in a pseudo-random order. A value greater than 1 |
| 229 | * will be used directly for the initial seed. |
| 230 | * |
| 231 | * If the tests are also repeated, the seed will be incremented for each |
| 232 | * subsequent run. |
| 233 | * Defaults to 0/not randomize. |
| 234 | * |
| 235 | * @param random 0|1|seed value. |
| 236 | * @see zuc_set_repeat() |
| 237 | */ |
| 238 | void |
| 239 | zuc_set_random(int random); |
| 240 | |
| 241 | /** |
| 242 | * Controls whether or not to run the tests as forked child processes. |
| 243 | * Defaults to true. |
| 244 | * |
| 245 | * @param spawn true to spawn each test in a forked child process, |
| 246 | * false to run tests directly. |
| 247 | */ |
| 248 | void |
| 249 | zuc_set_spawn(bool spawn); |
| 250 | |
| 251 | /** |
| 252 | * Enables output in the JUnit XML format. |
| 253 | * Defaults to false. |
| 254 | * |
| 255 | * @param enable true to generate JUnit XML output, false to disable. |
| 256 | */ |
| 257 | void |
| 258 | zuc_set_output_junit(bool enable); |
| 259 | |
| 260 | /** |
| 261 | * Defines a test case that can be registered to run. |
| 262 | */ |
| 263 | #define ZUC_TEST(tcase, test) \ |
| 264 | static void zuctest_##tcase##_##test(void); \ |
| 265 | \ |
| 266 | const struct zuc_registration zzz_##tcase##_##test \ |
| 267 | __attribute__ ((section ("zuc_tsect"))) = \ |
| 268 | { \ |
| 269 | #tcase, #test, 0, \ |
| 270 | zuctest_##tcase##_##test, \ |
| 271 | 0 \ |
| 272 | }; \ |
| 273 | \ |
| 274 | static void zuctest_##tcase##_##test(void) |
| 275 | |
| 276 | /** |
| 277 | * Defines a test case that can be registered to run along with setup/teardown |
| 278 | * support per-test and/or per test case. |
| 279 | * |
| 280 | * @note likely pending refactoring as use cases are refined. |
| 281 | */ |
| 282 | #define ZUC_TEST_F(tcase, test) \ |
| 283 | static void zuctest_##tcase##_##test(void *data); \ |
| 284 | \ |
| 285 | const struct zuc_registration zzz_##tcase##_##test \ |
| 286 | __attribute__ ((section ("zuc_tsect"))) = \ |
| 287 | { \ |
| 288 | #tcase, #test, &tcase, \ |
| 289 | 0, \ |
| 290 | zuctest_##tcase##_##test \ |
| 291 | }; \ |
| 292 | \ |
| 293 | static void zuctest_##tcase##_##test(void *data) |
| 294 | |
| 295 | |
| 296 | /** |
| 297 | * Returns true if the currently executing test has encountered any skips. |
| 298 | * |
| 299 | * @return true if there is currently a test executing and it has |
| 300 | * encountered any skips. |
| 301 | * @see zuc_has_failure |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 302 | * @see ZUC_SKIP() |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 303 | */ |
| 304 | bool |
| 305 | zuc_has_skip(void); |
| 306 | |
| 307 | /** |
| 308 | * Returns true if the currently executing test has encountered any failures. |
| 309 | * |
| 310 | * @return true if there is currently a test executing and it has |
| 311 | * encountered any failures. |
| 312 | * @see zuc_has_skip |
| 313 | */ |
| 314 | bool |
| 315 | zuc_has_failure(void); |
| 316 | |
| 317 | /** |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 318 | * Marks the running test as skipped without marking it as failed, and returns |
| 319 | * from the current function. |
| 320 | * |
| 321 | * For details on return and test termination see @ref zunitc_overview_return. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 322 | * |
| 323 | * @param message the message to log as to why the test has been skipped. |
| 324 | */ |
| 325 | #define ZUC_SKIP(message) \ |
| 326 | do { \ |
| 327 | zucimpl_terminate(__FILE__, __LINE__, false, false, #message); \ |
| 328 | return; \ |
| 329 | } \ |
| 330 | while (0) |
| 331 | |
| 332 | /** |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 333 | * Marks the running test as failed and returns from the current function. |
| 334 | * |
| 335 | * For details on return and test termination see @ref zunitc_overview_return. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 336 | * |
| 337 | * @param message the message to log as to why the test has failed. |
| 338 | */ |
| 339 | #define ZUC_FATAL(message) \ |
| 340 | do { \ |
| 341 | zucimpl_terminate(__FILE__, __LINE__, true, true, #message); \ |
| 342 | return; \ |
| 343 | } \ |
| 344 | while (0) |
| 345 | |
| 346 | /** |
| 347 | * Marks the current test as failed with a fatal issue, but does not |
| 348 | * immediately return from the current function. ZUC_FATAL() is normally |
| 349 | * preferred, but when further cleanup is needed, or the current function |
| 350 | * needs to return a value, this macro may be required. |
| 351 | * |
| 352 | * @param message the message to log as to why the test has failed. |
| 353 | * @see ZUC_FATAL() |
| 354 | */ |
| 355 | #define ZUC_MARK_FATAL(message) \ |
| 356 | do { \ |
| 357 | zucimpl_terminate(__FILE__, __LINE__, true, true, #message); \ |
| 358 | } \ |
| 359 | while (0) |
| 360 | |
| 361 | /** |
| 362 | * Creates a message that will be processed in the case of failure. |
| 363 | * If the test encounters any failures (fatal or non-fatal) then these |
| 364 | * messages are included in output. Otherwise they are discarded at the |
| 365 | * end of the test run. |
| 366 | * |
| 367 | * @param message the format string style message. |
| 368 | */ |
| 369 | #define ZUC_TRACEPOINT(message, ...) \ |
| 370 | zucimpl_tracepoint(__FILE__, __LINE__, message, ##__VA_ARGS__); |
| 371 | |
| 372 | /** |
| 373 | * Internal use macro for ASSERT implementation. |
| 374 | * Should not be used directly in code. |
| 375 | */ |
| 376 | #define ZUCIMPL_ASSERT(opcode, valtype, lhs, rhs) \ |
| 377 | do { \ |
| 378 | if (zucimpl_expect_pred2(__FILE__, __LINE__, \ |
| 379 | (opcode), (valtype), true, \ |
| 380 | (intptr_t)(lhs), (intptr_t)(rhs), \ |
| 381 | #lhs, #rhs)) { \ |
| 382 | return; \ |
| 383 | } \ |
| 384 | } \ |
| 385 | while (0) |
| 386 | |
| 387 | /** |
| 388 | * Internal use macro for ASSERT with Goto implementation. |
| 389 | * Should not be used directly in code. |
| 390 | */ |
| 391 | #define ZUCIMPL_ASSERTG(label, opcode, valtype, lhs, rhs) \ |
| 392 | do { \ |
| 393 | if (zucimpl_expect_pred2(__FILE__, __LINE__, \ |
| 394 | (opcode), (valtype), true, \ |
| 395 | (intptr_t)(lhs), (intptr_t)(rhs), \ |
| 396 | #lhs, #rhs)) { \ |
| 397 | goto label; \ |
| 398 | } \ |
| 399 | } \ |
| 400 | while (0) |
| 401 | |
| 402 | /** |
| 403 | * Verifies that the specified expression is true, marks the test as failed |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 404 | * and exits the current function via 'return' if it is not. |
| 405 | * |
| 406 | * For details on return and test termination see @ref zunitc_overview_return. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 407 | * |
| 408 | * @param condition the expression that is expected to be true. |
| 409 | * @note it is far better to use a more specific check when possible |
| 410 | * (e.g. ZUC_ASSERT_EQ(), ZUC_ASSERT_NE(), etc.) |
| 411 | * @see ZUC_ASSERTG_TRUE() |
| 412 | */ |
| 413 | #define ZUC_ASSERT_TRUE(condition) \ |
| 414 | ZUCIMPL_ASSERT(ZUC_OP_TRUE, ZUC_VAL_INT, condition, 0) |
| 415 | |
| 416 | /** |
| 417 | * Verifies that the specified expression is false, marks the test as |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 418 | * failed and exits the current function via 'return' if it is not. |
| 419 | * |
| 420 | * For details on return and test termination see @ref zunitc_overview_return. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 421 | * |
| 422 | * @param condition the expression that is expected to be false. |
| 423 | * @note it is far better to use a more specific check when possible |
| 424 | * (e.g. ZUC_ASSERT_EQ(), ZUC_ASSERT_NE(), etc.) |
| 425 | * @see ZUC_ASSERTG_FALSE() |
| 426 | */ |
| 427 | #define ZUC_ASSERT_FALSE(condition) \ |
| 428 | ZUCIMPL_ASSERT(ZUC_OP_FALSE, ZUC_VAL_INT, condition, 0) |
| 429 | |
| 430 | /** |
| 431 | * Verifies that the specified expression is NULL, marks the test as failed |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 432 | * and exits the current function via 'return' if it is not. |
| 433 | * |
| 434 | * For details on return and test termination see @ref zunitc_overview_return. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 435 | * |
| 436 | * @param condition the expression that is expected to be a NULL pointer. |
| 437 | * @see ZUC_ASSERTG_NULL() |
| 438 | */ |
| 439 | #define ZUC_ASSERT_NULL(condition) \ |
| 440 | ZUCIMPL_ASSERT(ZUC_OP_NULL, ZUC_VAL_PTR, condition, 0) |
| 441 | |
| 442 | /** |
| 443 | * Verifies that the specified expression is non-NULL, marks the test as |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 444 | * failed and exits the current function via 'return' if it is not. |
| 445 | * |
| 446 | * For details on return and test termination see @ref zunitc_overview_return. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 447 | * |
| 448 | * @param condition the expression that is expected to be a non-NULL pointer. |
| 449 | * @see ZUC_ASSERTG_NOT_NULL() |
| 450 | */ |
| 451 | #define ZUC_ASSERT_NOT_NULL(condition) \ |
| 452 | ZUCIMPL_ASSERT(ZUC_OP_NOT_NULL, ZUC_VAL_PTR, condition, 0) |
| 453 | |
| 454 | /** |
| 455 | * Verifies that the values of the specified expressions match, marks the |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 456 | * test as failed and exits the current function via 'return' if they do not. |
| 457 | * |
| 458 | * For details on return and test termination see @ref zunitc_overview_return. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 459 | * |
| 460 | * @param expected the value the result should hold. |
| 461 | * @param actual the actual value seen in testing. |
| 462 | * @see ZUC_ASSERTG_EQ() |
| 463 | */ |
| 464 | #define ZUC_ASSERT_EQ(expected, actual) \ |
| 465 | ZUCIMPL_ASSERT(ZUC_OP_EQ, ZUC_VAL_INT, expected, actual) |
| 466 | |
| 467 | /** |
| 468 | * Verifies that the values of the specified expressions differ, marks the |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 469 | * test as failed and exits the current function via 'return' if they do not. |
| 470 | * |
| 471 | * For details on return and test termination see @ref zunitc_overview_return. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 472 | * |
| 473 | * @param expected the value the result should not hold. |
| 474 | * @param actual the actual value seen in testing. |
| 475 | * @see ZUC_ASSERTG_NE() |
| 476 | */ |
| 477 | #define ZUC_ASSERT_NE(expected, actual) \ |
| 478 | ZUCIMPL_ASSERT(ZUC_OP_NE, ZUC_VAL_INT, expected, actual) |
| 479 | |
| 480 | /** |
| 481 | * Verifies that the value of the first expression is less than the value |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 482 | * of the second expression, marks the test as failed and exits the current |
| 483 | * function via 'return' if it is not. |
| 484 | * |
| 485 | * For details on return and test termination see @ref zunitc_overview_return. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 486 | * |
| 487 | * @param lesser the expression whose value should be lesser than the other. |
| 488 | * @param greater the expression whose value should be greater than the other. |
| 489 | * @see ZUC_ASSERTG_LT() |
| 490 | */ |
| 491 | #define ZUC_ASSERT_LT(lesser, greater) \ |
| 492 | ZUCIMPL_ASSERT(ZUC_OP_LT, ZUC_VAL_INT, lesser, greater) |
| 493 | |
| 494 | /** |
| 495 | * Verifies that the value of the first expression is less than or equal |
| 496 | * to the value of the second expression, marks the test as failed and |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 497 | * exits the current function via 'return' if it is not. |
| 498 | * |
| 499 | * For details on return and test termination see @ref zunitc_overview_return. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 500 | * |
| 501 | * @param lesser the expression whose value should be lesser than or equal to |
| 502 | * the other. |
| 503 | * @param greater the expression whose value should be greater than or equal to |
| 504 | * the other. |
| 505 | * @see ZUC_ASSERTG_LE() |
| 506 | */ |
| 507 | #define ZUC_ASSERT_LE(lesser, greater) \ |
| 508 | ZUCIMPL_ASSERT(ZUC_OP_LE, ZUC_VAL_INT, lesser, greater) |
| 509 | |
| 510 | /** |
| 511 | * Verifies that the value of the first expression is greater than the |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 512 | * value of the second expression, marks the test as failed and exits the |
| 513 | * current function via 'return' if it is not. |
| 514 | * |
| 515 | * For details on return and test termination see @ref zunitc_overview_return. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 516 | * |
| 517 | * @param greater the expression whose value should be greater than the other. |
| 518 | * @param lesser the expression whose value should be lesser than the other. |
| 519 | * @see ZUC_ASSERTG_GT() |
| 520 | */ |
| 521 | #define ZUC_ASSERT_GT(greater, lesser) \ |
| 522 | ZUCIMPL_ASSERT(ZUC_OP_GT, ZUC_VAL_INT, greater, lesser) |
| 523 | |
| 524 | /** |
| 525 | * Verifies that the value of the first expression is greater than or equal |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 526 | * to the value of the second expression, marks the test as failed and exits |
| 527 | * the current function via 'return' if it is not. |
| 528 | * |
| 529 | * For details on return and test termination see @ref zunitc_overview_return. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 530 | * |
| 531 | * @param greater the expression whose value should be greater than or equal to |
| 532 | * the other. |
| 533 | * @param lesser the expression whose value should be lesser than or equal to |
| 534 | * the other. |
| 535 | * @see ZUC_ASSERTG_GE() |
| 536 | */ |
| 537 | #define ZUC_ASSERT_GE(greater, lesser) \ |
| 538 | ZUCIMPL_ASSERT(ZUC_OP_GE, ZUC_VAL_INT, greater, lesser) |
| 539 | |
| 540 | /** |
| 541 | * Verifies that the values of the specified expressions match when |
| 542 | * compared as null-terminated C-style strings, marks the test as failed |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 543 | * and exits the current function via 'return' if they do not. |
| 544 | * |
| 545 | * For details on return and test termination see @ref zunitc_overview_return. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 546 | * |
| 547 | * @param expected the value the result should hold. |
| 548 | * @param actual the actual value seen in testing. |
| 549 | * @see ZUC_ASSERTG_STREQ() |
| 550 | */ |
| 551 | #define ZUC_ASSERT_STREQ(expected, actual) \ |
| 552 | ZUCIMPL_ASSERT(ZUC_OP_EQ, ZUC_VAL_CSTR, expected, actual) |
| 553 | |
| 554 | /** |
| 555 | * Verifies that the values of the specified expressions differ when |
| 556 | * compared as null-terminated C-style strings, marks the test as failed |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 557 | * and exits the current function via 'return' if they do not. |
| 558 | * |
| 559 | * For details on return and test termination see @ref zunitc_overview_return. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 560 | * |
| 561 | * @param expected the value the result should not hold. |
| 562 | * @param actual the actual value seen in testing. |
| 563 | * @see ZUC_ASSERTG_STRNE() |
| 564 | */ |
| 565 | #define ZUC_ASSERT_STRNE(expected, actual) \ |
| 566 | ZUCIMPL_ASSERT(ZUC_OP_NE, ZUC_VAL_CSTR, expected, actual) |
| 567 | |
| 568 | /** |
| 569 | * Verifies that the specified expression is true, marks the test as failed |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 570 | * and interrupts the current execution via a 'goto' if it is not. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 571 | * |
| 572 | * @param condition the expression that is expected to be true. |
| 573 | * @note it is far better to use a more specific check when possible |
| 574 | * (e.g. ZUC_ASSERTG_EQ(), ZUC_ASSERTG_NE(), etc.) |
| 575 | * @param label the target for 'goto' if the assertion fails. |
| 576 | * @see ZUC_ASSERT_TRUE() |
| 577 | */ |
| 578 | #define ZUC_ASSERTG_TRUE(condition, label) \ |
| 579 | ZUCIMPL_ASSERTG(label, ZUC_OP_TRUE, ZUC_VAL_INT, condition, 0) |
| 580 | |
| 581 | /** |
| 582 | * Verifies that the specified expression is false, marks the test as |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 583 | * failed and interrupts the current execution via a 'goto' if it is not. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 584 | * |
| 585 | * @param condition the expression that is expected to be false. |
| 586 | * @note it is far better to use a more specific check when possible |
| 587 | * (e.g. ZUC_ASSERTG_EQ(), ZUC_ASSERTG_NE(), etc.) |
| 588 | * @param label the target for 'goto' if the assertion fails. |
| 589 | * @see ZUC_ASSERT_FALSE() |
| 590 | */ |
| 591 | #define ZUC_ASSERTG_FALSE(condition, label) \ |
| 592 | ZUCIMPL_ASSERTG(label, ZUC_OP_FALSE, ZUC_VAL_INT, condition, 0) |
| 593 | |
| 594 | /** |
| 595 | * Verifies that the specified expression is NULL, marks the test as failed |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 596 | * and interrupts the current execution via a 'goto' if it is not. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 597 | * |
| 598 | * @param condition the expression that is expected to be a NULL pointer. |
| 599 | * @param label the target for 'goto' if the assertion fails. |
| 600 | * @see ZUC_ASSERT_NULL() |
| 601 | */ |
| 602 | #define ZUC_ASSERTG_NULL(condition, label) \ |
| 603 | ZUCIMPL_ASSERTG(label, ZUC_OP_NULL, ZUC_VAL_PTR, condition, 0) |
| 604 | |
| 605 | /** |
| 606 | * Verifies that the specified expression is non-NULL, marks the test as |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 607 | * failed and interrupts the current execution via a 'goto' if it is not. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 608 | * |
| 609 | * @param condition the expression that is expected to be a non-NULL pointer. |
| 610 | * @param label the target for 'goto' if the assertion fails. |
| 611 | * @see ZUC_ASSERT_NOT_NULL() |
| 612 | */ |
| 613 | #define ZUC_ASSERTG_NOT_NULL(condition, label) \ |
| 614 | ZUCIMPL_ASSERTG(label, ZUC_OP_NOT_NULL, ZUC_VAL_PTR, condition, 0) |
| 615 | |
| 616 | /** |
| 617 | * Verifies that the values of the specified expressions match, marks the |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 618 | * test as failed and interrupts the current execution via a 'goto' if they |
| 619 | * do not. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 620 | * |
| 621 | * @param expected the value the result should hold. |
| 622 | * @param actual the actual value seen in testing. |
| 623 | * @param label the target for 'goto' if the assertion fails. |
| 624 | * @see ZUC_ASSERT_EQ() |
| 625 | */ |
| 626 | #define ZUC_ASSERTG_EQ(expected, actual, label) \ |
| 627 | ZUCIMPL_ASSERTG(label, ZUC_OP_EQ, ZUC_VAL_INT, expected, actual) |
| 628 | |
| 629 | /** |
| 630 | * Verifies that the values of the specified expressions differ, marks the |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 631 | * test as failed and interrupts the current execution via a 'goto' if they |
| 632 | * do not. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 633 | * |
| 634 | * @param expected the value the result should not hold. |
| 635 | * @param actual the actual value seen in testing. |
| 636 | * @param label the target for 'goto' if the assertion fails. |
| 637 | * @see ZUC_ASSERT_NE() |
| 638 | */ |
| 639 | #define ZUC_ASSERTG_NE(expected, actual, label) \ |
| 640 | ZUCIMPL_ASSERTG(label, ZUC_OP_NE, ZUC_VAL_INT, expected, actual) |
| 641 | |
| 642 | /** |
| 643 | * Verifies that the value of the first expression is less than the value |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 644 | * of the second expression, marks the test as failed and interrupts the |
| 645 | * current execution via a 'goto' if it is not. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 646 | * |
| 647 | * @param lesser the expression whose value should be lesser than the other. |
| 648 | * @param greater the expression whose value should be greater than the other. |
| 649 | * @param label the target for 'goto' if the assertion fails. |
| 650 | * @see ZUC_ASSERT_LT() |
| 651 | */ |
| 652 | #define ZUC_ASSERTG_LT(lesser, greater, label) \ |
| 653 | ZUCIMPL_ASSERTG(label, ZUC_OP_LT, ZUC_VAL_INT, lesser, greater) |
| 654 | |
| 655 | /** |
| 656 | * Verifies that the value of the first expression is less than or equal |
| 657 | * to the value of the second expression, marks the test as failed and |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 658 | * interrupts the current execution via a 'goto' if it is not. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 659 | * |
| 660 | * @param lesser the expression whose value should be lesser than or equal to |
| 661 | * the other. |
| 662 | * @param greater the expression whose value should be greater than or equal to |
| 663 | * the other. |
| 664 | * @param label the target for 'goto' if the assertion fails. |
| 665 | * @see ZUC_ASSERT_LE() |
| 666 | */ |
| 667 | #define ZUC_ASSERTG_LE(lesser, greater, label) \ |
| 668 | ZUCIMPL_ASSERTG(label, ZUC_OP_LE, ZUC_VAL_INT, lesser, greater) |
| 669 | |
| 670 | /** |
| 671 | * Verifies that the value of the first expression is greater than the |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 672 | * value of the second expression, marks the test as failed and interrupts the |
| 673 | * current execution via a 'goto' if it is not. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 674 | * |
| 675 | * @param greater the expression whose value should be greater than the other. |
| 676 | * @param lesser the expression whose value should be lesser than the other. |
| 677 | * @param label the target for 'goto' if the assertion fails. |
| 678 | * @see ZUC_ASSERT_GT() |
| 679 | */ |
| 680 | #define ZUC_ASSERTG_GT(greater, lesser, label) \ |
| 681 | ZUCIMPL_ASSERTG(label, ZUC_OP_GT, ZUC_VAL_INT, greater, lesser) |
| 682 | |
| 683 | /** |
| 684 | * Verifies that the value of the first expression is greater than or equal |
| 685 | * to the value of the second expression, marks the test as failed and |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 686 | * interrupts the current execution via a 'goto' if it is not. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 687 | * |
| 688 | * @param greater the expression whose value should be greater than or equal to |
| 689 | * the other. |
| 690 | * @param lesser the expression whose value should be lesser than or equal to |
| 691 | * the other. |
| 692 | * @param label the target for 'goto' if the assertion fails. |
| 693 | * @see ZUC_ASSERT_GE() |
| 694 | */ |
| 695 | #define ZUC_ASSERTG_GE(greater, lesser, label) \ |
| 696 | ZUCIMPL_ASSERTG(label, ZUC_OP_GE, ZUC_VAL_INT, greater, lesser) |
| 697 | |
| 698 | /** |
| 699 | * Verifies that the values of the specified expressions match when |
| 700 | * compared as null-terminated C-style strings, marks the test as failed |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 701 | * and interrupts the current execution via a 'goto' if they do not. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 702 | * |
| 703 | * @param expected the value the result should hold. |
| 704 | * @param actual the actual value seen in testing. |
| 705 | * @param label the target for 'goto' if the assertion fails. |
| 706 | * @see ZUC_ASSERT_STREQ() |
| 707 | */ |
| 708 | #define ZUC_ASSERTG_STREQ(expected, actual, label) \ |
| 709 | ZUCIMPL_ASSERTG(label, ZUC_OP_EQ, ZUC_VAL_CSTR, expected, actual) |
| 710 | |
| 711 | /** |
| 712 | * Verifies that the values of the specified expressions differ when |
| 713 | * compared as null-terminated C-style strings, marks the test as failed |
Jon Cruz | 2ffb0af | 2015-10-22 13:25:54 -0700 | [diff] [blame^] | 714 | * and interrupts the current execution via a 'goto' if they do not. |
Jon A. Cruz | 5a75a41 | 2015-07-02 23:36:44 -0700 | [diff] [blame] | 715 | * |
| 716 | * @param expected the value the result should not hold. |
| 717 | * @param actual the actual value seen in testing. |
| 718 | * @param label the target for 'goto' if the assertion fails. |
| 719 | * @see ZUC_ASSERT_STRNE() |
| 720 | */ |
| 721 | #define ZUC_ASSERTG_STRNE(expected, actual, label) \ |
| 722 | ZUCIMPL_ASSERTG(label, ZUC_OP_NE, ZUC_VAL_CSTR, expected, actual) |
| 723 | |
| 724 | #ifdef __cplusplus |
| 725 | } /* extern "C" */ |
| 726 | #endif |
| 727 | |
| 728 | #endif /* Z_UNIT_C_H */ |