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 | * Common definitions internally used in PCUT.
|
---|
31 | */
|
---|
32 |
|
---|
33 | #ifndef PCUT_INTERNAL_H_GUARD
|
---|
34 | #define PCUT_INTERNAL_H_GUARD
|
---|
35 |
|
---|
36 | #include <pcut/pcut.h>
|
---|
37 | #include <stdlib.h>
|
---|
38 |
|
---|
39 | /** Mark a variable as unused. */
|
---|
40 | #define PCUT_UNUSED(x) ((void)x)
|
---|
41 |
|
---|
42 | /** Forking mode for test execution.
|
---|
43 | *
|
---|
44 | * In this mode, each test is run in a separate process.
|
---|
45 | * This ensures that even SIGSEGV does not stop the framework itself.
|
---|
46 | */
|
---|
47 | #define PCUT_RUN_MODE_FORKING 1
|
---|
48 |
|
---|
49 | /** Single-process mode for test execution.
|
---|
50 | *
|
---|
51 | * This mode is used when new process is launched when in forking-mode or
|
---|
52 | * this mode can be used if we are sure that no test would fail
|
---|
53 | * fatally (that is causing an unexpected program exit).
|
---|
54 | */
|
---|
55 | #define PCUT_RUN_MODE_SINGLE 2
|
---|
56 |
|
---|
57 | /** Test outcome: test passed. */
|
---|
58 | #define TEST_OUTCOME_PASS 1
|
---|
59 |
|
---|
60 | /** Test outcome: test failed. */
|
---|
61 | #define TEST_OUTCOME_FAIL 2
|
---|
62 |
|
---|
63 | /** Test outcome: test failed unexpectedly. */
|
---|
64 | #define TEST_OUTCOME_ERROR 3
|
---|
65 |
|
---|
66 | extern int pcut_run_mode;
|
---|
67 |
|
---|
68 |
|
---|
69 | pcut_item_t *pcut_fix_list_get_real_head(pcut_item_t *last);
|
---|
70 | int pcut_count_tests(pcut_item_t *it);
|
---|
71 | void pcut_print_items(pcut_item_t *first);
|
---|
72 |
|
---|
73 | pcut_item_t *pcut_get_real_next(pcut_item_t *item);
|
---|
74 | pcut_item_t *pcut_get_real(pcut_item_t *item);
|
---|
75 | void pcut_print_tests(pcut_item_t *first);
|
---|
76 | int pcut_is_arg_with_number(const char *arg, const char *opt, int *value);
|
---|
77 |
|
---|
78 | void pcut_run_test_forking(const char *self_path, pcut_item_t *test);
|
---|
79 | int pcut_run_test_forked(pcut_item_t *test);
|
---|
80 | int pcut_run_test_single(pcut_item_t *test);
|
---|
81 |
|
---|
82 | int pcut_get_test_timeout(pcut_item_t *test);
|
---|
83 |
|
---|
84 | void pcut_failed_assertion(const char *message);
|
---|
85 | void pcut_print_fail_message(const char *msg);
|
---|
86 |
|
---|
87 | /** Reporting callbacks structure. */
|
---|
88 | typedef struct pcut_report_ops pcut_report_ops_t;
|
---|
89 |
|
---|
90 | /** @copydoc pcut_report_ops_t */
|
---|
91 | struct pcut_report_ops {
|
---|
92 | /** Initialize the reporting, given all tests. */
|
---|
93 | void (*init)(pcut_item_t *);
|
---|
94 | /** Test suite just started. */
|
---|
95 | void (*suite_start)(pcut_item_t *);
|
---|
96 | /** Test suite completed. */
|
---|
97 | void (*suite_done)(pcut_item_t *);
|
---|
98 | /** Test is about to start. */
|
---|
99 | void (*test_start)(pcut_item_t *);
|
---|
100 | /** Test completed. */
|
---|
101 | void (*test_done)(pcut_item_t *, int, const char *, const char *,
|
---|
102 | const char *);
|
---|
103 | /** Finalize the reporting. */
|
---|
104 | void (*done)(void);
|
---|
105 | };
|
---|
106 |
|
---|
107 | void pcut_report_register_handler(pcut_report_ops_t *ops);
|
---|
108 |
|
---|
109 | void pcut_report_init(pcut_item_t *all_items);
|
---|
110 | void pcut_report_suite_start(pcut_item_t *suite);
|
---|
111 | void pcut_report_suite_done(pcut_item_t *suite);
|
---|
112 | void pcut_report_test_start(pcut_item_t *test);
|
---|
113 | void pcut_report_test_done(pcut_item_t *test, int outcome,
|
---|
114 | const char *error_message, const char *teardown_error_message,
|
---|
115 | const char *extra_output);
|
---|
116 | void pcut_report_test_done_unparsed(pcut_item_t *test, int outcome,
|
---|
117 | const char *unparsed_output, size_t unparsed_output_size);
|
---|
118 | void pcut_report_done(void);
|
---|
119 |
|
---|
120 | /* OS-dependent functions. */
|
---|
121 |
|
---|
122 | /** Tell whether two strings start with the same prefix.
|
---|
123 | *
|
---|
124 | * @param a First string.
|
---|
125 | * @param b Second string.
|
---|
126 | * @param len Length of common prefix.
|
---|
127 | * @return Whether first @p len characters of @p a are the same as in @p b.
|
---|
128 | */
|
---|
129 | int pcut_str_start_equals(const char *a, const char *b, int len);
|
---|
130 |
|
---|
131 | /** Get size of string in bytes.
|
---|
132 | *
|
---|
133 | * @param s String in question.
|
---|
134 | * @return Size of @p s in bytes.
|
---|
135 | */
|
---|
136 | int pcut_str_size(const char *s);
|
---|
137 |
|
---|
138 | /** Convert string to integer.
|
---|
139 | *
|
---|
140 | * @param s String with integer.
|
---|
141 | * @return Converted integer.
|
---|
142 | */
|
---|
143 | int pcut_str_to_int(const char *s);
|
---|
144 |
|
---|
145 | /** Find character in a string.
|
---|
146 | *
|
---|
147 | * @param haystack Where to look for the @p needle.
|
---|
148 | * @param needle Character to find.
|
---|
149 | * @return String starting with @p needle.
|
---|
150 | * @retval NULL there is no @p needle in @p haystack.
|
---|
151 | */
|
---|
152 | char *pcut_str_find_char(const char *haystack, const char needle);
|
---|
153 |
|
---|
154 |
|
---|
155 | #endif
|
---|