Debian Codegraph @

engine/read_only/tests/simple/marpa_m_test.h

raw
1 /*
2 * Copyright 2022 Jeffrey Kegler
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included
11 * in all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
17 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19 * OTHER DEALINGS IN THE SOFTWARE.
20 */
21
22 /* Libmarpa method test interface -- marpa_m_test */
23
24 #ifndef MARPA_M_TEST_H
25 #define MARPA_M_TEST_H 1
26
27 #include <stdio.h>
28 #include "marpa.h"
29
30 #include "tap/basic.h"
31
32 extern Marpa_Symbol_ID S_invalid, S_no_such;
33 extern Marpa_Rule_ID R_invalid, R_no_such;
34
35 /* Marpa method test interface */
36
37 const char *marpa_m_error_message (Marpa_Error_Code error_code);
38
39 typedef union {
40 void *ptr_rv;
41 long long_rv;
42 unsigned long ulong_rv;
43 } API_RV;
44
45 typedef struct api_test_data {
46 Marpa_Grammar g;
47 Marpa_Error_Code expected_errcode;
48 char *msg;
49 API_RV rv_seen;
50 } API_test_data;
51
52 void rv_std_report (API_test_data * td,
53 const char *method, int rv_wanted, Marpa_Error_Code err_wanted);
54 void rv_code_report (API_test_data * td,
55 const char *method, Marpa_Error_Code err_seen,
56 Marpa_Error_Code err_wanted);
57 void rv_hidden_report (API_test_data * td, const char *name, int rv_wanted,
58 Marpa_Error_Code err_wanted);
59 void rv_ptr_report (API_test_data * td, const char *name,
60 Marpa_Error_Code err_wanted);
61
62 #define API_STD_TEST0(test_data, rv_wanted, err_wanted, method, object) \
63 { \
64 test_data.rv_seen.long_rv = method(object); \
65 rv_std_report(&test_data, #method , rv_wanted, err_wanted); \
66 }
67
68 #define API_STD_TEST0U(test_data, rv_wanted, err_wanted, method, object) \
69 { \
70 test_data.rv_seen.ulong_rv = method(object); \
71 rv_std_report(&test_data, #method , rv_wanted, err_wanted); \
72 }
73
74 #define API_STD_TEST1(test_data, rv_wanted, err_wanted, method, object, arg1) \
75 { \
76 test_data.rv_seen.long_rv = method(object, arg1); \
77 rv_std_report(&test_data, #method , rv_wanted, err_wanted); \
78 }
79
80 #define API_STD_TEST2(test_data, rv_wanted, err_wanted, method, object, arg1, arg2) \
81 { \
82 test_data.rv_seen.long_rv = method(object, arg1, arg2); \
83 rv_std_report(&test_data, #method , rv_wanted, err_wanted); \
84 }
85
86 #define API_STD_TEST3(test_data, rv_wanted, err_wanted, method, object, arg1, arg2, arg3) \
87 { \
88 test_data.rv_seen.long_rv = method(object, arg1, arg2, arg3); \
89 rv_std_report(&test_data, #method , rv_wanted, err_wanted); \
90 }
91
92 #define API_STD_TEST5(test_data, rv_wanted, err_wanted, method, object, \
93 arg1, arg2, arg3, arg4, arg5) \
94 { \
95 test_data.rv_seen.long_rv = method(object, arg1, arg2, arg3, arg4, arg5); \
96 rv_std_report(&test_data, #method , rv_wanted, err_wanted); \
97 }
98
99 #define API_CODE_TEST3(test_data, err_wanted, method, object, arg1, arg2, arg3) \
100 { \
101 Marpa_Error_Code err_seen = method(object, arg1, arg2, arg3); \
102 rv_code_report(&test_data, #method , err_seen, err_wanted); \
103 }
104
105 #define API_HIDDEN_TEST1(test_data, rv_wanted, err_wanted, method, object, arg1 ) \
106 { \
107 test_data.rv_seen.long_rv = method(object, arg1 ); \
108 rv_hidden_report(&test_data, #method , rv_wanted, err_wanted); \
109 }
110
111 #define API_HIDDEN_TEST2(test_data, rv_wanted, err_wanted, method, object, arg1, arg2 ) \
112 { \
113 test_data.rv_seen.long_rv = method(object, arg1, arg2 ); \
114 rv_hidden_report(&test_data, #method , rv_wanted, err_wanted); \
115 }
116
117 #define API_PTR_TEST1(test_data, err_wanted, method, object, arg1 ) \
118 { \
119 test_data.rv_seen.ptr_rv = method(object, arg1 ); \
120 rv_ptr_report(&test_data, #method , err_wanted); \
121 }
122
123 #endif /* MARPA_M_TEST_H */