test/test_apu.h

00001 /* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
00002  * applicable.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /* Some simple functions to make the test apps easier to write and
00018  * a bit more consistent...
00019  * this is a >copy< of apr_test.h
00020  */
00021 
00022 /* Things to bear in mind when using these...
00023  *
00024  * If you include '\t' within the string passed in it won't be included
00025  * in the spacing, so use spaces instead :)
00026  * 
00027  */ 
00028 
00029 #ifndef APU_TEST_INCLUDES
00030 #define APU_TEST_INCLUDES
00031 
00032 #include "apr_strings.h"
00033 #include "apr_time.h"
00034 
00035 #define TEST_EQ(str, func, value, good, bad) \
00036     printf("%-60s", str); \
00037     { \
00038     apr_status_t rv; \
00039     if ((rv = func) == value){ \
00040         char errmsg[200]; \
00041         printf("%s\n", bad); \
00042         fprintf(stderr, "Error was %d : %s\n", rv, \
00043                 apr_strerror(rv, (char*)&errmsg, 200)); \
00044         exit(-1); \
00045     } \
00046     printf("%s\n", good); \
00047     }
00048 
00049 #define TEST_NEQ(str, func, value, good, bad) \
00050     printf("%-60s", str); \
00051     { \
00052     apr_status_t rv; \
00053     if ((rv = func) != value){ \
00054         char errmsg[200]; \
00055         printf("%s\n", bad); \
00056         fprintf(stderr, "Error was %d : %s\n", rv, \
00057                 apr_strerror(rv, (char*)&errmsg, 200)); \
00058         exit(-1); \
00059     } \
00060     printf("%s\n", good); \
00061     }
00062 
00063 #define TEST_STATUS(str, func, testmacro, good, bad) \
00064     printf("%-60s", str); \
00065     { \
00066         apr_status_t rv = func; \
00067         if (!testmacro(rv)) { \
00068             char errmsg[200]; \
00069             printf("%s\n", bad); \
00070             fprintf(stderr, "Error was %d : %s\n", rv, \
00071                     apr_strerror(rv, (char*)&errmsg, 200)); \
00072             exit(-1); \
00073         } \
00074         printf("%s\n", good); \
00075     }
00076 
00077 #define STD_TEST_NEQ(str, func) \
00078         TEST_NEQ(str, func, APR_SUCCESS, "OK", "Failed");
00079 
00080 #define PRINT_ERROR(rv) \
00081     { \
00082         char errmsg[200]; \
00083         fprintf(stderr, "Error was %d : %s\n", rv, \
00084                 apr_strerror(rv, (char*)&errmsg, 200)); \
00085         exit(-1); \
00086     }
00087 
00088 #define MSG_AND_EXIT(msg) \
00089     printf("%s\n", msg); \
00090     exit (-1);
00091 
00092 #define TIME_FUNCTION(time, function) \
00093     { \
00094         apr_time_t tt = apr_time_now(); \
00095         function; \
00096         time = apr_time_now() - tt; \
00097     }
00098     
00099     
00100 #endif /* APU_TEST_INCLUDES */

Generated on Tue Sep 11 08:13:14 2007 for Apache Portable Runtime Utility Library by  doxygen 1.5.2