00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031
00032 #include "event-test.h"
00033
00034 RCSTAG("@(#)$Id: t_event_log.c,v 1.6 2005/12/18 00:15:17 klmitch Exp $");
00035
00036 TEST_PROG(t_event_log, "Test operation of event_log_* functions")
00037
00038
00045 #define _str(a) #a
00046
00054 #define str(a) _str(a)
00055
00062 #define LC_START 0xf720e0a9
00063
00070 #define LC_EVLOGTEST 0x4ed403d2
00071
00078 #define LC_EVDEBUGTEST 0x2d8fcebe
00079
00086 static unsigned int log_called = LC_START;
00087
00103 static void
00104 t_log(const char *file, int line, const char *func, const char *msg)
00105 {
00106 fprintf(stderr, "%s:%d%s%s%s: %s\n", file, line,
00107 func ? " (" : "", func ? func : "", func ? ")" : "", msg);
00108 log_called = strtoul(msg, 0, 16);
00109 }
00110
00111
00112 static unsigned int _ev_log(ev_flags_t flag, const char *msg);
00113 static ev_err_t _ev_assert(int expr);
00114 static ev_err_t _ev_abort(void);
00115 static ev_err_t _ev_init(void);
00116
00125 int
00126 main(int argc, char **argv)
00127 {
00128 ev_log_t logger = _ev_debuglog;
00129 ev_err_t err;
00130
00131
00132
00133
00134
00135
00136 TEST(t_event_log, el_set, "Test event_log_set() operation",
00137 (!(err = event_log_set(t_log)) && _ev_debuglog == t_log &&
00138 _ev_asflags == EVAS_LOG), FATAL(0),
00139 ("event_log_set() properly sets logging callback"),
00140 ("event_log_set() operation failed; error code %u, logger %p (should "
00141 "be %p), _ev_asflags 0x%08lx (should be 0x%08lx)", err,
00142 (void *)_ev_debuglog, (void *)t_log, _ev_asflags,
00143 (ev_flags_t)EVAS_LOG));
00144
00145
00146 TEST(t_event_log, el_reset, "Test event_log_reset() operation",
00147 (!(err = event_log_reset()) && _ev_debuglog == logger &&
00148 _ev_asflags == 0), FATAL(0),
00149 ("event_log_reset() properly resets logging callback"),
00150 ("event_log_reset() operation failed; error code %u, logger %p (should "
00151 "be %p), _ev_asflags 0x%08lx (should be 0)", err, (void *)_ev_debuglog,
00152 (void *)logger, _ev_asflags));
00153
00154
00155 _ev_debuglog = t_log;
00156
00157
00158
00159 TEST(t_event_log, el_debug_on, "Test event_log_debug() can turn on logging",
00160 (!(err = event_log_debug(1)) && _ev_asflags == EVAS_LOG), 0,
00161 ("event_log_debug(1) properly turns on debug logging"),
00162 ("event_log_debug(1) fails to turn on debug logging; error %u", err));
00163
00164
00165 TEST(t_event_log, el_debug_off, "Test event_log_debug() can turn off "
00166 "logging",
00167 (!(err = event_log_debug(0)) && _ev_asflags == 0), 0,
00168 ("event_log_debug(0) properly turns off debug logging"),
00169 ("event_log_debug(0) fails to turn off debug logging; error %u", err));
00170
00171 _ev_asflags = 0;
00172
00173
00174 TEST(t_event_log, el_logmsg_start, "Test that log messages have not yet "
00175 "been written",
00176 (log_called == LC_START), 0,
00177 ("Log messages have not been written yet (as expected)"),
00178 ("An unexpected log message appears to have been written..."));
00179
00180
00181 TEST(t_event_log, el_trace_on, "Test event_log_trace() can turn on tracing",
00182 (!(err = event_log_trace(1)) && _ev_asflags == EVAS_TRACE), 0,
00183 ("event_log_trace(1) properly turns function tracing on"),
00184 ("event_log_trace(1) fails to turn on function tracing; error %u",
00185 err));
00186
00187
00188 TEST(t_event_log, el_trace_off, "Test event_log_trace() can turn off "
00189 "tracing",
00190 (!(err = event_log_trace(0)) && _ev_asflags == 0), 0,
00191 ("event_log_trace(0) properly turns function tracing off"),
00192 ("event_log_trace(0) fails to turn off function tracing; error %u",
00193 err));
00194
00195
00196 TEST(t_event_log, el_logmsg_first, "Test that a function trace message was "
00197 "written",
00198 (log_called != LC_START), 0,
00199 ("Function trace log message written (as expected)"),
00200 ("Function trace log message seems to have not been written..."));
00201
00202
00203 log_called = LC_START;
00204
00205 _ev_asflags = 0;
00206
00207
00208 TEST(t_event_log, el_abort_on, "Test event_log_abort() can turn on aborting",
00209 (!(err = event_log_abort(1)) && _ev_asflags == EVAS_ABORT), 0,
00210 ("event_log_abort(1) properly turns on aborting functionality"),
00211 ("event_log_abort(1) fails to turn on library abort; error %u", err));
00212
00213
00214 TEST(t_event_log, el_abort_off, "Test event_log_abort() can turn off "
00215 "aborting",
00216 (!(err = event_log_abort(0)) && _ev_asflags == 0), 0,
00217 ("event_log_abort(0) properly turns aborting functionality off"),
00218 ("event_log_abort(0) fails to turn off library abort; error %u", err));
00219
00220 _ev_asflags = 0;
00221
00222
00223 TEST(t_event_log, el_evlog_off, "Test that ev_log() does nothing when off",
00224 (_ev_log(EVAS_LOG, str(LC_EVLOGTEST)) == LC_START), 0,
00225 ("ev_log() macro properly ignored log message when off"),
00226 ("ev_log() macro wrote a message even though it was turned off"));
00227
00228 log_called = LC_START;
00229 _ev_asflags = EVAS_LOG;
00230
00231
00232 TEST(t_event_log, el_evlog_on, "Test that ev_log() logs when on",
00233 (_ev_log(EVAS_LOG, str(LC_EVLOGTEST)) == LC_EVLOGTEST), 0,
00234 ("ev_log() macro properly writes log message when on"),
00235 ("ev_log() failed to write log message even though it was turned on"));
00236
00237 log_called = LC_START;
00238 _ev_asflags = 0;
00239
00240
00241 _ev_debug(EVAS_LOG, __FILE__, __LINE__, _gca_func, "0x%08x", LC_EVDEBUGTEST);
00242 TEST(t_event_log, el_evdebug_off, "Test that _ev_debug() does nothing "
00243 "when off",
00244 (log_called == LC_START), 0,
00245 ("_ev_debug() call properly ignored log message when off"),
00246 ("_ev_debug() call wrote a message even though it was turned off"));
00247
00248 log_called = LC_START;
00249 _ev_asflags = EVAS_LOG;
00250
00251
00252 _ev_debug(EVAS_LOG, __FILE__, __LINE__, _gca_func, "0x%08x", LC_EVDEBUGTEST);
00253 TEST(t_event_log, el_evdebug_on, "Test that _ev_debug() logs when on",
00254 (log_called == LC_EVDEBUGTEST), 0,
00255 ("_ev_debug() properly writes log message when on"),
00256 ("_ev_debug() failed to write log message even though it was "
00257 "turned on"));
00258
00259
00260 _ev_asflags = 0;
00261 TEST(t_event_log, el_evabort_off, "Test that ev_abort() does a return when "
00262 "turned off",
00263 ((err = _ev_abort()) == EV_ERR_ASSERT), 0,
00264 ("ev_abort() macro properly returns EV_ERR_ASSERT when turned off"),
00265 ("ev_abort() macro failed to operate properly; error %u", err));
00266
00267
00268 _ev_asflags = 0;
00269 TEST(t_event_log, el_assert_true, "Test that ev_assert() accepts true "
00270 "values",
00271 ((err = _ev_assert(1)) == 0 && _ev_asflags == 0), 0,
00272 ("ev_assert() macro properly accepts true value"),
00273 ("ev_assert() macro rejected true value; error %u asflags 0x%08lx", err,
00274 _ev_asflags));
00275
00276 _ev_asflags = 0;
00277 TEST(t_event_log, el_assert_false, "Test that ev_assert() rejects false "
00278 "values",
00279 ((err = _ev_assert(0)) == EV_ERR_ASSERT && _ev_asflags == EVAS_LOOP), 0,
00280 ("ev_assert() macro properly rejects false value"),
00281 ("ev_assert() macro accepted false value; error %u asflags 0x%08lx",
00282 err, _ev_asflags));
00283
00284
00285
00286
00287 _ev_asflags = EVAS_LOOP;
00288 TEST(t_event_log, el_init_loop, "Test that ev_init() returns if an "
00289 "assertion has been thrown",
00290 ((err = _ev_init()) == EV_ERR_ASSERT), 0,
00291 ("ev_init() macro causes return when EVAS_LOOP is set"),
00292 ("ev_init() macro failed to return properly; error %u", err));
00293
00294 return 0;
00295 }
00296
00308 static unsigned int
00309 _ev_log(ev_flags_t flag, const char *msg)
00310 {
00311 ev_log(flag, msg);
00312
00313 return log_called;
00314 }
00315
00325 static ev_err_t
00326 _ev_assert(int expr)
00327 {
00328 ev_assert(expr);
00329
00330 return 0;
00331 }
00332
00340 static ev_err_t
00341 _ev_abort(void)
00342 {
00343 ev_abort();
00344
00345 return 0;
00346 }
00347
00354 static ev_err_t
00355 _ev_init(void)
00356 {
00357 ev_init();
00358
00359 return 0;
00360 }