00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _GATTESTUTILS_H_
00018 #define _GATTESTUTILS_H_
00019
00020 #include <stdio.h>
00021
00022 #define GAT_EXIT_ON_ERROR 0
00023
00024 #ifdef TESTS
00025 # define _GAT_TESTS 1
00026 #else
00027 # define _GAT_TESTS 0
00028 #endif
00029
00030 #ifndef TEMP
00031 # define TEMP "/tmp/"
00032 #endif
00033
00034 #ifdef __cplusplus
00035 extern "C" {
00036 #endif
00037
00038 int _GAT_TEST_INIT(int t);
00039 void _GAT_TEST_FINISH(const char* rcs);
00040
00041 const char* GATTest_GetTempDirName (void);
00042 const char* GATTest_GetTempFileName (const char* name);
00043 const char* GATTest_CreateTempFile (const char* name);
00044 const char* GATTest_GetTempFileNameF (const char* format, ...);
00045
00046 int GATTest_GetIndent (void);
00047 void GATTest_SetIndent (int indent);
00048 int GATTest_GetError (void);
00049 void GATTest_SetError (int error);
00050
00051 #ifdef __cplusplus
00052 }
00053 #endif
00054
00055 #define GAT_PREFIX_SUITE "------- %s -------\n"
00056 #define GAT_PREFIX_LINE "Test : %-45s \t : "
00057 #define GAT_PREFIX_NLINE " %-45s \t : "
00058 #define GAT_POSTFIX_EEXIT "- %3d ERRORs\n"
00059 #define GAT_POSTFIX_SEXIT "- SUCCESS\n"
00060 #define GAT_PREFIX_ERRLINE "- ERROR : %s +%d\n", __FILE__, __LINE__
00061 #define GAT_PREFIX_DEBUG "\n %s\n"
00062
00063 #define GAT_TEST_INIT(x) { \
00064 if ( ! _GAT_TEST_INIT (_GAT_TESTS) ) \
00065 { \
00066 return (x); \
00067 } \
00068 }
00069
00070 #define GAT_TEST_FINISH() _GAT_TEST_FINISH (rcsid)
00071
00072 #define GAT_TEST_SUITE(x) { \
00073 if ( GATTest_GetIndent() ) \
00074 { \
00075 GATTest_SetIndent(0); \
00076 GATTest_SetError(0); \
00077 } \
00078 fprintf (stderr, GAT_PREFIX_SUITE, x); \
00079 fflush (stderr); \
00080 }
00081
00082 #define GAT_TEST_START(x) { \
00083 if ( ! GATTest_GetIndent() ) \
00084 { \
00085 fprintf (stderr, GAT_PREFIX_LINE, x); \
00086 fflush (stderr); \
00087 GATTest_SetError(0); \
00088 } \
00089 GATTest_SetIndent(GATTest_GetIndent() +1); \
00090 } \
00091 \
00092 {
00093
00094 #define GAT_TEST_STOP() { \
00095 GATTest_SetIndent(GATTest_GetIndent() -1); \
00096 if ( ! GATTest_GetIndent() ) \
00097 { \
00098 if ( GATTest_GetError() ) \
00099 { \
00100 fprintf (stderr, GAT_POSTFIX_EEXIT, GATTest_GetError()); \
00101 } \
00102 else \
00103 { \
00104 fprintf (stderr, GAT_POSTFIX_SEXIT); \
00105 } \
00106 fflush (stderr); \
00107 } \
00108 } \
00109 \
00110 }
00111
00112 #define GAT_TEST_EXIT() { \
00113 GATTest_SetIndent(GATTest_GetIndent() -1); \
00114 if ( ! GATTest_GetIndent() ) \
00115 { \
00116 if ( GATTest_GetError() ) \
00117 { \
00118 fprintf (stderr, GAT_PREFIX_NLINE, " "); \
00119 fprintf (stderr, GAT_POSTFIX_EEXIT, GATTest_GetError()); \
00120 } \
00121 else \
00122 { \
00123 fprintf (stderr, GAT_POSTFIX_SEXIT); \
00124 } \
00125 fflush (stderr); \
00126 } \
00127 }
00128
00129 #define GAT_TEST(y) { \
00130 if ( y ) \
00131 { \
00132 } \
00133 else \
00134 { \
00135 fprintf (stderr, GAT_PREFIX_ERRLINE); \
00136 fprintf (stderr, GAT_PREFIX_NLINE, " "); \
00137 fflush (stderr); \
00138 GATTest_SetError (GATTest_GetError() +1); \
00139 if ( GAT_EXIT_ON_ERROR ) \
00140 { \
00141 exit (-__LINE__); \
00142 } \
00143 } \
00144 }
00145
00146 #define GAT_TEST_TRACE(y, context) { \
00147 if ( y ) \
00148 { \
00149 } \
00150 else \
00151 { \
00152 fprintf (stderr, GAT_PREFIX_ERRLINE); \
00153 GATTest_SetError (GATTest_GetError() +1); \
00154 { \
00155 GATStatus status = NULL; \
00156 if (GAT_SUCCEEDED(GATContext_GetCurrentStatus(context, &status))) \
00157 { \
00158 GATStatus_Trace(status); \
00159 } \
00160 else \
00161 { \
00162 fprintf (stderr, GAT_PREFIX_NLINE, " "); \
00163 } \
00164 } \
00165 fprintf (stderr, GAT_PREFIX_NLINE, " "); \
00166 fflush (stderr); \
00167 if ( GAT_EXIT_ON_ERROR ) \
00168 { \
00169 exit (-__LINE__); \
00170 } \
00171 } \
00172 }
00173
00174 #define GAT_DEBUG(x) { \
00175 fprintf (stderr, GAT_PREFIX_DEBUG, x); \
00176 fflush (stderr); \
00177 }
00178
00179 #endif // _GATTESTUTILS_H_
00180