Debian Codegraph @

tests/vhdi_test_tools_signal.c

raw symbols SCIP
1 /*
2 * Tools signal functions test program
3 *
4 * Copyright (C) 2012-2025, Joachim Metz <[email protected]>
5 *
6 * Refer to AUTHORS for acknowledgements.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #include <common.h>
23 #include <file_stream.h>
24 #include <types.h>
25
26 #if defined( HAVE_STDLIB_H ) || defined( WINAPI )
27 #include <stdlib.h>
28 #endif
29
30 #include "vhdi_test_libcerror.h"
31 #include "vhdi_test_macros.h"
32 #include "vhdi_test_unused.h"
33
34 #include "../vhditools/vhditools_signal.h"
35
36 void vhdi_test_tools_signal_handler_function(
37 vhditools_signal_t signal VHDI_TEST_ATTRIBUTE_UNUSED )
38 {
39 VHDI_TEST_UNREFERENCED_PARAMETER( signal )
40 }
41
42 #if defined( WINAPI )
43
44 /* Tests the vhditools_signal_handler function
45 * Returns 1 if successful or 0 if not
46 */
47 int vhdi_test_tools_signal_handler(
48 void )
49 {
50 BOOL result = 0;
51
52 /* Test regular cases
53 */
54 result = vhditools_signal_handler(
55 CTRL_C_EVENT );
56
57 VHDI_TEST_ASSERT_EQUAL_INT(
58 "result",
59 result,
60 (int) TRUE );
61
62 result = vhditools_signal_handler(
63 CTRL_LOGOFF_EVENT );
64
65 VHDI_TEST_ASSERT_EQUAL_INT(
66 "result",
67 result,
68 (int) FALSE );
69
70 return( 1 );
71
72 on_error:
73 return( 0 );
74 }
75
76 #if defined( _MSC_VER )
77
78 /* TODO add tests for vhditools_signal_initialize_memory_debug */
79
80 #endif /* defined( _MSC_VER ) */
81
82 #endif /* defined( WINAPI ) */
83
84 /* Tests the vhditools_signal_attach function
85 * Returns 1 if successful or 0 if not
86 */
87 int vhdi_test_tools_signal_attach(
88 void )
89 {
90 libcerror_error_t *error = NULL;
91 int result = 0;
92
93 /* Test regular cases
94 */
95 result = vhditools_signal_attach(
96 vhdi_test_tools_signal_handler_function,
97 &error );
98
99 VHDI_TEST_ASSERT_EQUAL_INT(
100 "result",
101 result,
102 1 );
103
104 VHDI_TEST_ASSERT_IS_NULL(
105 "error",
106 error );
107
108 /* Test error cases
109 */
110 result = vhditools_signal_attach(
111 NULL,
112 &error );
113
114 VHDI_TEST_ASSERT_EQUAL_INT(
115 "result",
116 result,
117 -1 );
118
119 VHDI_TEST_ASSERT_IS_NOT_NULL(
120 "error",
121 error );
122
123 libcerror_error_free(
124 &error );
125
126 return( 1 );
127
128 on_error:
129 if( error != NULL )
130 {
131 libcerror_error_free(
132 &error );
133 }
134 return( 0 );
135 }
136
137 /* Tests the vhditools_signal_detach function
138 * Returns 1 if successful or 0 if not
139 */
140 int vhdi_test_tools_signal_detach(
141 void )
142 {
143 libcerror_error_t *error = NULL;
144 int result = 0;
145
146 /* Test regular cases
147 */
148 result = vhditools_signal_detach(
149 &error );
150
151 VHDI_TEST_ASSERT_EQUAL_INT(
152 "result",
153 result,
154 1 );
155
156 VHDI_TEST_ASSERT_IS_NULL(
157 "error",
158 error );
159
160 return( 1 );
161
162 on_error:
163 if( error != NULL )
164 {
165 libcerror_error_free(
166 &error );
167 }
168 return( 0 );
169 }
170
171 /* The main program
172 */
173 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
174 int wmain(
175 int argc VHDI_TEST_ATTRIBUTE_UNUSED,
176 wchar_t * const argv[] VHDI_TEST_ATTRIBUTE_UNUSED )
177 #else
178 int main(
179 int argc VHDI_TEST_ATTRIBUTE_UNUSED,
180 char * const argv[] VHDI_TEST_ATTRIBUTE_UNUSED )
181 #endif
182 {
183 VHDI_TEST_UNREFERENCED_PARAMETER( argc )
184 VHDI_TEST_UNREFERENCED_PARAMETER( argv )
185
186 #if defined( WINAPI )
187
188 VHDI_TEST_RUN(
189 "vhditools_signal_handler",
190 vhdi_test_tools_signal_handler )
191
192 #if defined( _MSC_VER )
193
194 /* TODO add tests for vhditools_signal_initialize_memory_debug */
195
196 #endif /* defined( _MSC_VER ) */
197
198 #endif /* defined( WINAPI ) */
199
200 VHDI_TEST_RUN(
201 "vhditools_signal_attach",
202 vhdi_test_tools_signal_attach )
203
204 VHDI_TEST_RUN(
205 "vhditools_signal_detach",
206 vhdi_test_tools_signal_detach )
207
208 return( EXIT_SUCCESS );
209
210 on_error:
211 return( EXIT_FAILURE );
212 }
213