[134ac5d] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012-2013 Vojtech Horky
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @file
|
---|
| 30 | * Data types internally used by PCUT.
|
---|
| 31 | */
|
---|
| 32 | #ifndef PCUT_DATADEF_H_GUARD
|
---|
| 33 | #define PCUT_DATADEF_H_GUARD
|
---|
| 34 |
|
---|
| 35 | #include <pcut/prevs.h>
|
---|
| 36 | #include <stdlib.h>
|
---|
| 37 | #include <stddef.h>
|
---|
| 38 |
|
---|
| 39 | /** @cond devel */
|
---|
| 40 |
|
---|
| 41 | enum {
|
---|
| 42 | PCUT_KIND_SKIP,
|
---|
| 43 | PCUT_KIND_NESTED,
|
---|
| 44 | PCUT_KIND_SETUP,
|
---|
| 45 | PCUT_KIND_TEARDOWN,
|
---|
| 46 | PCUT_KIND_TESTSUITE,
|
---|
| 47 | PCUT_KIND_TEST
|
---|
| 48 | };
|
---|
| 49 |
|
---|
| 50 | enum {
|
---|
| 51 | PCUT_EXTRA_TIMEOUT,
|
---|
| 52 | PCUT_EXTRA_SKIP,
|
---|
| 53 | PCUT_EXTRA_LAST
|
---|
| 54 | };
|
---|
| 55 |
|
---|
| 56 | /** Generic wrapper for test cases, test suites etc. */
|
---|
| 57 | typedef struct pcut_item pcut_item_t;
|
---|
| 58 |
|
---|
| 59 | /** Extra information about a test. */
|
---|
| 60 | typedef struct pcut_extra pcut_extra_t;
|
---|
| 61 |
|
---|
| 62 | /** Test method type. */
|
---|
| 63 | typedef void (*pcut_test_func_t)(void);
|
---|
| 64 |
|
---|
| 65 | /** Set-up or tear-down method type. */
|
---|
| 66 | typedef void (*pcut_setup_func_t)(void);
|
---|
| 67 |
|
---|
| 68 | /** @copydoc pcut_extra_t */
|
---|
| 69 | struct pcut_extra {
|
---|
| 70 | /** Discriminator for the union.
|
---|
| 71 | *
|
---|
| 72 | * Use PCUT_EXTRA_* to determine which field of the union is used.
|
---|
| 73 | */
|
---|
| 74 | int type;
|
---|
| 75 | union {
|
---|
| 76 | /** Test-specific time-out in seconds. */
|
---|
| 77 | int timeout;
|
---|
| 78 | };
|
---|
| 79 | };
|
---|
| 80 |
|
---|
| 81 | /** @copydoc pcut_item_t */
|
---|
| 82 | struct pcut_item {
|
---|
| 83 | /** Link to previous item. */
|
---|
| 84 | pcut_item_t *previous;
|
---|
| 85 | /** Link to next item. */
|
---|
| 86 | pcut_item_t *next;
|
---|
| 87 |
|
---|
| 88 | /** Unique id of this item. */
|
---|
| 89 | int id;
|
---|
| 90 |
|
---|
| 91 | /** Discriminator for the union.
|
---|
| 92 | *
|
---|
| 93 | * Use PCUT_KIND_* to determine which field of the union is used.
|
---|
| 94 | */
|
---|
| 95 | int kind;
|
---|
| 96 | union {
|
---|
| 97 | struct {
|
---|
| 98 | const char *name;
|
---|
| 99 | pcut_setup_func_t setup;
|
---|
| 100 | pcut_setup_func_t teardown;
|
---|
| 101 | } suite;
|
---|
| 102 | struct {
|
---|
| 103 | const char *name;
|
---|
| 104 | pcut_test_func_t func;
|
---|
| 105 | pcut_extra_t *extras;
|
---|
| 106 | } test;
|
---|
| 107 | /* setup is used for both set-up and tear-down */
|
---|
| 108 | struct {
|
---|
| 109 | pcut_setup_func_t func;
|
---|
| 110 | } setup;
|
---|
| 111 | struct {
|
---|
| 112 | pcut_item_t *last;
|
---|
| 113 | } nested;
|
---|
| 114 | struct {
|
---|
| 115 | int dummy;
|
---|
| 116 | } meta;
|
---|
| 117 | };
|
---|
| 118 | };
|
---|
| 119 |
|
---|
| 120 | #ifdef PCUT_DEBUG_BUILD
|
---|
| 121 | #define PCUT_DEBUG(msg, ...) \
|
---|
| 122 | printf("[PCUT]: Debug: " msg "\n", ##__VA_ARGS__)
|
---|
| 123 | #else
|
---|
| 124 |
|
---|
| 125 | /** Debug printing.
|
---|
| 126 | *
|
---|
| 127 | * By default, this macro does nothing. Define PCUT_DEBUG_BUILD to
|
---|
| 128 | * actually print the messages to the console.
|
---|
| 129 | *
|
---|
| 130 | * @param msg Printf-like formatting message.
|
---|
| 131 | * @param ... Extra arguments for printf.
|
---|
| 132 | */
|
---|
| 133 | #define PCUT_DEBUG(msg, ...) (void)0
|
---|
| 134 | #endif
|
---|
| 135 |
|
---|
| 136 | /** @endcond */
|
---|
| 137 |
|
---|
| 138 | #endif
|
---|