Apache Portable Runtime Utility Library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test_apu.h
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements. See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /* Some simple functions to make the test apps easier to write and
18  * a bit more consistent...
19  * this is a >copy< of apr_test.h
20  */
21 
22 /* Things to bear in mind when using these...
23  *
24  * If you include '\t' within the string passed in it won't be included
25  * in the spacing, so use spaces instead :)
26  *
27  */
28 
29 #ifndef APU_TEST_INCLUDES
30 #define APU_TEST_INCLUDES
31 
32 #include "apr_strings.h"
33 #include "apr_time.h"
34 
35 #define TEST_EQ(str, func, value, good, bad) \
36  printf("%-60s", str); \
37  { \
38  apr_status_t rv; \
39  if ((rv = func) == value){ \
40  char errmsg[200]; \
41  printf("%s\n", bad); \
42  fprintf(stderr, "Error was %d : %s\n", rv, \
43  apr_strerror(rv, (char*)&errmsg, 200)); \
44  exit(-1); \
45  } \
46  printf("%s\n", good); \
47  }
48 
49 #define TEST_NEQ(str, func, value, good, bad) \
50  printf("%-60s", str); \
51  { \
52  apr_status_t rv; \
53  if ((rv = func) != value){ \
54  char errmsg[200]; \
55  printf("%s\n", bad); \
56  fprintf(stderr, "Error was %d : %s\n", rv, \
57  apr_strerror(rv, (char*)&errmsg, 200)); \
58  exit(-1); \
59  } \
60  printf("%s\n", good); \
61  }
62 
63 #define TEST_STATUS(str, func, testmacro, good, bad) \
64  printf("%-60s", str); \
65  { \
66  apr_status_t rv = func; \
67  if (!testmacro(rv)) { \
68  char errmsg[200]; \
69  printf("%s\n", bad); \
70  fprintf(stderr, "Error was %d : %s\n", rv, \
71  apr_strerror(rv, (char*)&errmsg, 200)); \
72  exit(-1); \
73  } \
74  printf("%s\n", good); \
75  }
76 
77 #define STD_TEST_NEQ(str, func) \
78  TEST_NEQ(str, func, APR_SUCCESS, "OK", "Failed");
79 
80 #define PRINT_ERROR(rv) \
81  { \
82  char errmsg[200]; \
83  fprintf(stderr, "Error was %d : %s\n", rv, \
84  apr_strerror(rv, (char*)&errmsg, 200)); \
85  exit(-1); \
86  }
87 
88 #define MSG_AND_EXIT(msg) \
89  printf("%s\n", msg); \
90  exit (-1);
91 
92 #define TIME_FUNCTION(time, function) \
93  { \
94  apr_time_t tt = apr_time_now(); \
95  function; \
96  time = apr_time_now() - tt; \
97  }
98 
99 
100 #endif /* APU_TEST_INCLUDES */