upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / test / CuTest.h
1 /*
2  * Copyright (c) 2002-2006 Asim Jalis
3  *
4  * This library is released under the zlib/libpng license as described at
5  *
6  * http://www.opensource.org/licenses/zlib-license.html
7  *
8  * Here is the statement of the license:
9  *
10  * This software is provided 'as-is', without any express or implied warranty.
11  * In no event will the authors be held liable for any damages arising from
12  * the use of this software.
13  *
14  * Permission is granted to anyone to use this software for any purpose,
15  * including commercial applications, and to alter it and redistribute it
16  * freely, subject to the following restrictions:
17  *
18  * 1. The origin of this software must not be misrepresented; you must not
19  * claim that you wrote the original software. If you use this software in a
20  * product, an acknowledgment in the product documentation would be
21  * appreciated but is not required.
22  *
23  * 2. Altered source versions must be plainly marked as such, and must not be
24  * misrepresented as being the original software.
25  *
26  * 3. This notice may not be removed or altered from any source distribution.
27  */
28 /*
29  * This file has been modified from the original distribution.
30  */
31
32 #ifndef CU_TEST_H
33 #define CU_TEST_H
34
35 #include <setjmp.h>
36 #include <stdarg.h>
37
38 /* CuString */
39
40 char* CuStrAlloc(int size);
41 char* CuStrCopy(const char* old);
42
43 #define CU_ALLOC(TYPE)          ((TYPE*) malloc(sizeof(TYPE)))
44
45 #define HUGE_STRING_LEN 8192
46 #define STRING_MAX              256
47 #define STRING_INC              256
48
49 typedef struct
50 {
51         int length;
52         int size;
53         char* buffer;
54 } CuString;
55
56 void CuStringInit(CuString* str);
57 CuString* CuStringNew(void);
58 void CuStringRead(CuString* str, char* path);
59 void CuStringAppend(CuString* str, const char* text);
60 void CuStringAppendChar(CuString* str, char ch);
61 void CuStringAppendFormat(CuString* str, const char* format, ...);
62 void CuStringResize(CuString* str, int newSize);
63
64 /* CuTest */
65
66 typedef struct CuTest CuTest;
67
68 typedef void (*TestFunction)(CuTest *);
69
70 struct CuTest
71 {
72         char* name;
73         TestFunction function;
74         int notimpl;
75         int failed;
76         int ran;
77         char* message;
78         jmp_buf *jumpBuf;
79 };
80
81 void CuInit(int argc, char *argv[]);
82 void CuTestInit(CuTest* t, char* name, TestFunction function);
83 CuTest* CuTestNew(char* name, TestFunction function);
84 void CuFail(CuTest* tc, const char* message);
85 void CuNotImpl(CuTest* tc, const char* message);
86 void CuAssert(CuTest* tc, const char* message, int condition);
87 void CuAssertTrue(CuTest* tc, int condition);
88 void CuAssertStrEquals(CuTest* tc, const char* expected, const char* actual);
89 void CuAssertStrNEquals(CuTest* tc, const char* expected, const char* actual,
90                         int n);
91 void CuAssertIntEquals(CuTest* tc, int expected, int actual);
92 void CuAssertPtrEquals(CuTest* tc, const void* expected, const void* actual);
93 void CuAssertPtrNotNull(CuTest* tc, const void* pointer);
94
95 void CuTestRun(CuTest* tc);
96
97 /* CuSuite */
98
99 #define MAX_TEST_CASES  1024    
100
101 #define SUITE_ADD_TEST(SUITE,TEST)      CuSuiteAdd(SUITE, CuTestNew(#TEST, TEST))
102
103 typedef struct
104 {
105         char *name;
106         int count;
107         CuTest* list[MAX_TEST_CASES]; 
108         int failCount;
109         int notimplCount;
110
111 } CuSuite;
112
113
114 void CuSuiteInit(CuSuite* testSuite, char* name);
115 CuSuite* CuSuiteNew(char* name);
116 void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase);
117 void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2);
118 void CuSuiteRun(CuSuite* testSuite);
119 void CuSuiteSummary(CuSuite* testSuite, CuString* summary);
120 void CuSuiteOverView(CuSuite* testSuite, CuString* details);
121 void CuSuiteDetails(CuSuite* testSuite, CuString* details);
122
123 typedef struct
124 {
125         char *name;
126         int count;
127         CuSuite* list[MAX_TEST_CASES]; 
128 } CuSuiteList;
129
130
131 CuSuiteList* CuSuiteListNew(char* name);
132 void CuSuiteListAdd(CuSuiteList* testSuite, CuSuite *testCase);
133 void CuSuiteListRun(CuSuiteList* testSuite);
134 void CuSuiteListRunWithSummary(CuSuiteList* testSuite);
135 void CuSuiteListSummary(CuSuiteList* testSuite, CuString* summary);
136 /* Print details of test suite results; returns total number of
137  * tests which failed. */
138 int CuSuiteListDetails(CuSuiteList* testSuite, CuString* details);
139 #endif /* CU_TEST_H */
140