1 /*
2  * Library notification functions test program
3  *
4  * Copyright (C) 2014-2021, Joachim Metz <joachim.metz@gmail.com>
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 "sigscan_test_libcerror.h"
31 #include "sigscan_test_libsigscan.h"
32 #include "sigscan_test_macros.h"
33 #include "sigscan_test_unused.h"
34 
35 /* Tests the libsigscan_notify_set_verbose function
36  * Returns 1 if successful or 0 if not
37  */
sigscan_test_notify_set_verbose(void)38 int sigscan_test_notify_set_verbose(
39      void )
40 {
41 	/* Test invocation of function only
42 	 */
43 	libsigscan_notify_set_verbose(
44 	 0 );
45 
46 	return( 1 );
47 }
48 
49 /* Tests the libsigscan_notify_set_stream function
50  * Returns 1 if successful or 0 if not
51  */
sigscan_test_notify_set_stream(void)52 int sigscan_test_notify_set_stream(
53      void )
54 {
55 	libcerror_error_t *error = NULL;
56 	int result               = 0;
57 
58 	/* Test regular cases
59 	 */
60 	result = libsigscan_notify_set_stream(
61 	          NULL,
62 	          &error );
63 
64 	SIGSCAN_TEST_ASSERT_EQUAL_INT(
65 	 "result",
66 	 result,
67 	 1 );
68 
69 	SIGSCAN_TEST_ASSERT_IS_NULL(
70 	 "error",
71 	 error );
72 
73 	/* Test error cases
74 	 */
75 /* TODO test libcnotify_stream_set failure */
76 
77 	return( 1 );
78 
79 on_error:
80 	if( error != NULL )
81 	{
82 		libcerror_error_free(
83 		 &error );
84 	}
85 	return( 0 );
86 }
87 
88 /* Tests the libsigscan_notify_stream_open function
89  * Returns 1 if successful or 0 if not
90  */
sigscan_test_notify_stream_open(void)91 int sigscan_test_notify_stream_open(
92      void )
93 {
94 	libcerror_error_t *error = NULL;
95 	int result               = 0;
96 
97 	/* Test regular cases
98 	 */
99 	result = libsigscan_notify_stream_open(
100 	          "notify_stream.log",
101 	          &error );
102 
103 	SIGSCAN_TEST_ASSERT_EQUAL_INT(
104 	 "result",
105 	 result,
106 	 1 );
107 
108 	SIGSCAN_TEST_ASSERT_IS_NULL(
109 	 "error",
110 	 error );
111 
112 	/* Test error cases
113 	 */
114 	result = libsigscan_notify_stream_open(
115 	          NULL,
116 	          &error );
117 
118 	SIGSCAN_TEST_ASSERT_EQUAL_INT(
119 	 "result",
120 	 result,
121 	 -1 );
122 
123 	SIGSCAN_TEST_ASSERT_IS_NOT_NULL(
124 	 "error",
125 	 error );
126 
127 	libcerror_error_free(
128 	 &error );
129 
130 	/* Clean up
131 	 */
132 	result = libsigscan_notify_stream_close(
133 	          &error );
134 
135 	SIGSCAN_TEST_ASSERT_EQUAL_INT(
136 	 "result",
137 	 result,
138 	 0 );
139 
140 	SIGSCAN_TEST_ASSERT_IS_NULL(
141 	 "error",
142 	 error );
143 
144 	return( 1 );
145 
146 on_error:
147 	if( error != NULL )
148 	{
149 		libcerror_error_free(
150 		 &error );
151 	}
152 	return( 0 );
153 }
154 
155 /* Tests the libsigscan_notify_stream_close function
156  * Returns 1 if successful or 0 if not
157  */
sigscan_test_notify_stream_close(void)158 int sigscan_test_notify_stream_close(
159      void )
160 {
161 	libcerror_error_t *error = NULL;
162 	int result               = 0;
163 
164 	/* Test regular cases
165 	 */
166 	result = libsigscan_notify_stream_close(
167 	          &error );
168 
169 	SIGSCAN_TEST_ASSERT_EQUAL_INT(
170 	 "result",
171 	 result,
172 	 0 );
173 
174 	SIGSCAN_TEST_ASSERT_IS_NULL(
175 	 "error",
176 	 error );
177 
178 	/* Test error cases
179 	 */
180 /* TODO test libcnotify_stream_close failure */
181 
182 	return( 1 );
183 
184 on_error:
185 	if( error != NULL )
186 	{
187 		libcerror_error_free(
188 		 &error );
189 	}
190 	return( 0 );
191 }
192 
193 /* The main program
194  */
195 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
wmain(int argc SIGSCAN_TEST_ATTRIBUTE_UNUSED,wchar_t * const argv[]SIGSCAN_TEST_ATTRIBUTE_UNUSED)196 int wmain(
197      int argc SIGSCAN_TEST_ATTRIBUTE_UNUSED,
198      wchar_t * const argv[] SIGSCAN_TEST_ATTRIBUTE_UNUSED )
199 #else
200 int main(
201      int argc SIGSCAN_TEST_ATTRIBUTE_UNUSED,
202      char * const argv[] SIGSCAN_TEST_ATTRIBUTE_UNUSED )
203 #endif
204 {
205 	SIGSCAN_TEST_UNREFERENCED_PARAMETER( argc )
206 	SIGSCAN_TEST_UNREFERENCED_PARAMETER( argv )
207 
208 	SIGSCAN_TEST_RUN(
209 	 "libsigscan_notify_set_verbose",
210 	 sigscan_test_notify_set_verbose )
211 
212 	SIGSCAN_TEST_RUN(
213 	 "libsigscan_notify_set_stream",
214 	 sigscan_test_notify_set_stream )
215 
216 	SIGSCAN_TEST_RUN(
217 	 "libsigscan_notify_stream_open",
218 	 sigscan_test_notify_stream_open )
219 
220 	SIGSCAN_TEST_RUN(
221 	 "libsigscan_notify_stream_close",
222 	 sigscan_test_notify_stream_close )
223 
224 	return( EXIT_SUCCESS );
225 
226 on_error:
227 	return( EXIT_FAILURE );
228 }
229 
230