1 /* vi: set sw=4 ts=4: */
3 * Some simple macros for use in test applications.
4 * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org>
6 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
12 #ifdef __NO_TESTCODE__
13 extern size_t test_number;
16 extern void init_testsuite(const char* testname);
17 extern void done_testing(void) __attribute__((noreturn));
18 extern void success_msg(int result, const char* command);
19 extern void error_msg(int result, int line, const char* file, const char* command);
21 #ifndef __NO_TESTCODE__
23 size_t test_number = 0;
24 static int failures = 0;
26 void error_msg(int result, int line, const char* file, const char* command)
30 printf("\nFAILED TEST %lu: \n\t%s\n", (unsigned long)test_number, command);
31 printf("AT LINE: %d, FILE: %s\n\n", line, file);
34 void success_msg(int result, const char* command)
37 printf("passed test: %s == 0\n", command);
41 void done_testing(void)
44 printf("Failed %d tests\n", failures);
47 printf("All functions tested sucessfully\n");
52 void init_testsuite(const char* testname)
54 printf("%s", testname);
57 #if !defined(__UCLIBC__) || defined(__UCLIBC_DYNAMIC_ATEXIT__)
62 #endif /* __NO_TESTCODE__ */
65 #define TEST_STRING_OUTPUT(command, expected_result) \
67 int result = strcmp(command, expected_result); \
69 if (result == expected_result) { \
70 success_msg(result, "command"); \
72 error_msg(result, __LINE__, __FILE__, command); \
76 #define TEST_NUMERIC(command, expected_result) \
78 int result = (command); \
80 if (result == expected_result) { \
81 success_msg(result, # command); \
83 error_msg(result, __LINE__, __FILE__, # command); \
87 #define TEST(command) \
89 int result = (command); \
92 success_msg(result, # command); \
94 error_msg(result, __LINE__, __FILE__, # command); \
98 #define STR_CMD(cmd) cmd
100 #endif /* TESTSUITE_H */