1 /* vi: set sw=4 ts=4: */
3 * Some simple macros for use in test applications.
5 * Copyright (C) 2000 by Lineo, inc. and Erik Andersen
6 * Copyright (C) 2000,2001 by Erik Andersen <andersen@uclibc.org>
7 * Written by Erik Andersen <andersen@uclibc.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Library General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
19 * You should have received a copy of the GNU Library General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifdef __NO_TESTCODE__
30 extern size_t test_number;
33 extern void init_testsuite(const char* testname);
34 extern void done_testing(void) __attribute__((noreturn));
35 extern void success_msg(int result, const char* command);
36 extern void error_msg(int result, int line, const char* file, const char* command);
41 size_t test_number = 0;
42 static int failures = 0;
44 void error_msg(int result, int line, const char* file, const char* command)
48 printf("\nFAILED TEST %d: \n\t%s\n", test_number, command);
49 printf("AT LINE: %d, FILE: %s\n\n", line, file);
52 void success_msg(int result, const char* command)
55 printf("passed test: %s == 0\n", command);
59 void done_testing(void)
62 printf("Failed %d tests\n", failures);
65 printf("All functions tested sucessfully\n");
70 void init_testsuite(const char* testname)
72 printf("%s", testname);
82 #define TEST_STRING_OUTPUT( command, expected_result ) \
84 int result=strcmp( command, expected_result); \
86 if ( result == expected_result ) { \
87 success_msg( result, "command"); \
89 error_msg(result, __LINE__, __FILE__, command); \
93 #define TEST_NUMERIC( command, expected_result ) \
95 int result=(command); \
97 if ( result == expected_result ) { \
98 success_msg( result, # command); \
100 error_msg(result, __LINE__, __FILE__, # command); \
104 #define TEST(command) \
106 int result=(command); \
108 if ( result == 1) { \
109 success_msg( result, # command); \
111 error_msg(result, __LINE__, __FILE__, # command ); \
115 #define STR_CMD(cmd) cmd
117 #endif /* TESTSUITE_H */