src/vfer_tests.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2005, 2006, Internet2
00003  * Legal conditions are in file LICENSE
00004  * (MD5 = c434f2e53b8089d8b4d0172c7ce07360).
00005  */
00006 /**
00007  *
00008  * @file   vfer_tests.h
00009  * @author Ivan Beschastnikh
00010  * @brief  Header file that is used by protocol tests
00011  *
00012  * This header file includes useful macros & functions for error and debug
00013  * processing.
00014  *
00015  * -     02/04/05        ivan            updated with new macros to report test failure and summary
00016  * -     08/21/05        ivan            created
00017  */
00018 
00019 #ifndef VFER_TESTS_H
00020 #define VFER_TESTS_H
00021 
00022 #include "vfer.h"
00023 
00024 /* these can be reset to point to open files, but they are not used if
00025  * TEST_ERR and/or TEST_OUT are commented out */
00026 FILE* test_out;
00027 FILE* test_err;
00028 /* keeps the tests's name - useful for printing out debug/err messages */
00029 char test_name[32];
00030 char test_file[32];
00031 
00032 /* these keep the number of faults and the number of max faults for the test */
00033 int test_faults;
00034 int test_max_faults;
00035 
00036 /* determines whether we output any err msgs */
00037 #define TEST_ERR
00038 /* determines whether we output any debug msgs */
00039 #define TEST_OUT
00040 
00041 /**/
00042 #ifdef TEST_OUT
00043         #define TEST_PRINT(FUNC, ...) do { \
00044                 if (test_out != NULL) { \
00045                 fprintf(test_out, "%-13s [ %-20s ] ", test_name, FUNC); \
00046                 fprintf(test_out, __VA_ARGS__); \
00047                 fprintf(test_out, "\n"); }} while (0)
00048 #else
00049         #define TEST_PRINT(FUNC, ...)
00050 #endif
00051 /**/
00052 #ifdef TEST_ERR
00053         #define T_ERR(FUNC, ...) do { \
00054                 if (test_err != NULL) { \
00055                 fprintf(test_err, "%-13s [ %-20s ] ERROR ", test_name, FUNC); \
00056                 fprintf(test_err, __VA_ARGS__); \
00057                 fprintf(test_err, "\n"); }} while (0)
00058 #else
00059         #define T_ERR(FUNC, ...)
00060 #endif
00061 /**/
00062 
00063 /*
00064  * these cars determine the printing of messages for specific tests
00065  * of the protocol, they are set with TEST_INIT below
00066  */
00067 
00068 /*
00069  * to specify no debug output, set OUT to NULL
00070  * NEVER pass a NULL ERR argument (used by TEST_CHECK and TEST_SUMMARY)
00071  */
00072 void TEST_INIT(char* TEST, char* File, FILE* OUT, FILE* ERR) {
00073         if (strlen(TEST) > 32) {
00074                 printf("error: test's name too long\n");
00075                 exit(-1);
00076         }
00077         if (strlen(File) > 32) {
00078                 printf("error: file's name too long\n");
00079                 exit(-1);
00080         }
00081         strncpy(test_name, TEST, 32);
00082         strncpy(test_file, File, 32);
00083         test_faults     = 0;
00084         test_max_faults = 0;
00085         ReqMem          = 0;
00086         test_out        = OUT;
00087         test_err        = ERR;
00088         debug_out       = OUT;
00089         error_out       = ERR;
00090 }
00091 
00092 #define TEST_CHECK(TO_TEST, MESG) { \
00093         test_max_faults++; \
00094         if (!TO_TEST) { \
00095                 fprintf(test_err, "%s *** test failed: %s ***\n", test_name, MESG); \
00096                 test_faults++; \
00097         }}
00098 
00099 #define TEST_SUMMARY() { fprintf(test_err, "%s faulty tests: %d / %d\n", test_name, test_faults, test_max_faults); }
00100 
00101 //! abort if test fails
00102 #define ASSERT(TEST) do { \
00103      bool _ok = (TEST); \
00104      TEST_CHECK(_ok, #TEST " is false"); \
00105      if (!_ok) { \
00106          TEST_SUMMARY(); \
00107          exit(1); \
00108      } \
00109      } while(0)
00110 
00111 #endif /* VFER_TESTS_H */

Generated on Tue Aug 8 16:07:19 2006 for VFER by  doxygen 1.4.7