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\nResult: %d",
31 (unsigned long)test_number, command, result);
32 printf("AT LINE: %d, FILE: %s\n\n", line, file);
35 void success_msg(int result __attribute__((unused)), const char* command __attribute__((unused)))
38 printf("passed test: %s == 0\n", command);
42 void done_testing(void)
45 printf("Failed %d tests\n", failures);
48 printf("All functions tested sucessfully\n");
53 void init_testsuite(const char* testname)
55 printf("%s", testname);
58 #if !defined(__UCLIBC__) || defined(__UCLIBC_DYNAMIC_ATEXIT__)
63 #endif /* __NO_TESTCODE__ */
66 #define TEST_STRING_OUTPUT(command, expected_result) \
68 int result = strcmp(command, expected_result); \
70 if (result == expected_result) { \
71 success_msg(result, "command"); \
73 error_msg(result, __LINE__, __FILE__, command); \
77 #define TEST_NUMERIC(command, expected_result) \
79 int result = (command); \
81 if (result == expected_result) { \
82 success_msg(result, # command); \
84 error_msg(result, __LINE__, __FILE__, # command); \
88 #define TEST(command) \
90 int result = (command); \
93 success_msg(result, # command); \
95 error_msg(result, __LINE__, __FILE__, # command); \
99 #define STR_CMD(cmd) cmd
101 #endif /* TESTSUITE_H */