source: trunk/include/CuTest.h@ 131

Last change on this file since 131 was 17, checked in by katerina, 19 years ago

Optimized version of tiger algorithm, and basic ingredients for unit testing (part 1)

File size: 4.7 KB
Line 
1/*******************
2
3LICENSE
4
5Copyright (c) 2003 Asim Jalis
6
7This software is provided 'as-is', without any express or implied
8warranty. In no event will the authors be held liable for any damages
9arising from the use of this software.
10
11Permission is granted to anyone to use this software for any purpose,
12including commercial applications, and to alter it and redistribute it
13freely, subject to the following restrictions:
14
151. The origin of this software must not be misrepresented; you must not
16claim that you wrote the original software. If you use this software in
17a product, an acknowledgment in the product documentation would be
18appreciated but is not required.
19
202. Altered source versions must be plainly marked as such, and must not
21be misrepresented as being the original software.
22
233. This notice may not be removed or altered from any source
24distribution.
25
26**********************/
27
28#ifndef CU_TEST_H
29#define CU_TEST_H
30
31#include <setjmp.h>
32#include <stdarg.h>
33
34/* CuString */
35
36char* CuStrAlloc(int size);
37char* CuStrCopy(const char* old);
38
39#define CU_ALLOC(TYPE) ((TYPE*) malloc(sizeof(TYPE)))
40
41#define HUGE_STRING_LEN 8192
42#define STRING_MAX 256
43#define STRING_INC 256
44
45typedef struct
46{
47 int length;
48 int size;
49 char* buffer;
50} CuString;
51
52void CuStringInit(CuString* str);
53CuString* CuStringNew(void);
54void CuStringRead(CuString* str, const char* path);
55void CuStringAppend(CuString* str, const char* text);
56void CuStringAppendChar(CuString* str, char ch);
57void CuStringAppendFormat(CuString* str, const char* format, ...);
58void CuStringInsert(CuString* str, const char* text, int pos);
59void CuStringResize(CuString* str, int newSize);
60
61/* CuTest */
62
63typedef struct CuTest CuTest;
64
65typedef void (*TestFunction)(CuTest *);
66
67struct CuTest
68{
69 const char* name;
70 TestFunction function;
71 int failed;
72 int ran;
73 const char* message;
74 jmp_buf *jumpBuf;
75};
76
77void CuTestInit(CuTest* t, const char* name, TestFunction function);
78CuTest* CuTestNew(const char* name, TestFunction function);
79void CuTestRun(CuTest* tc);
80
81/* Internal versions of assert functions -- use the public versions */
82void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, const char* message);
83void CuAssert_Line(CuTest* tc, const char* file, int line, const char* message, int condition);
84void CuAssertStrEquals_LineMsg(CuTest* tc,
85 const char* file, int line, const char* message,
86 const char* expected, const char* actual);
87void CuAssertIntEquals_LineMsg(CuTest* tc,
88 const char* file, int line, const char* message,
89 int expected, int actual);
90void CuAssertDblEquals_LineMsg(CuTest* tc,
91 const char* file, int line, const char* message,
92 double expected, double actual, double delta);
93void CuAssertPtrEquals_LineMsg(CuTest* tc,
94 const char* file, int line, const char* message,
95 void* expected, void* actual);
96
97/* public assert functions */
98
99#define CuFail(tc, ms) CuFail_Line( (tc), __FILE__, __LINE__, NULL, (ms))
100#define CuAssert(tc, ms, cond) CuAssert_Line((tc), __FILE__, __LINE__, (ms), (cond))
101#define CuAssertTrue(tc, cond) CuAssert_Line((tc), __FILE__, __LINE__, "assert failed", (cond))
102
103#define CuAssertStrEquals(tc,ex,ac) CuAssertStrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
104#define CuAssertStrEquals_Msg(tc,ms,ex,ac) CuAssertStrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
105#define CuAssertIntEquals(tc,ex,ac) CuAssertIntEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
106#define CuAssertIntEquals_Msg(tc,ms,ex,ac) CuAssertIntEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
107#define CuAssertDblEquals(tc,ex,ac,dl) CuAssertDblEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac),(dl))
108#define CuAssertDblEquals_Msg(tc,ms,ex,ac,dl) CuAssertDblEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac),(dl))
109#define CuAssertPtrEquals(tc,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
110#define CuAssertPtrEquals_Msg(tc,ms,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
111
112#define CuAssertPtrNotNull(tc,p) CuAssert_Line((tc),__FILE__,__LINE__,"null pointer unexpected",(p != NULL))
113#define CuAssertPtrNotNullMsg(tc,msg,p) CuAssert_Line((tc),__FILE__,__LINE__,(msg),(p != NULL))
114
115/* CuSuite */
116
117#define MAX_TEST_CASES 1024
118
119#define SUITE_ADD_TEST(SUITE,TEST) CuSuiteAdd(SUITE, CuTestNew(#TEST, TEST))
120
121typedef struct
122{
123 int count;
124 CuTest* list[MAX_TEST_CASES];
125 int failCount;
126
127} CuSuite;
128
129
130void CuSuiteInit(CuSuite* testSuite);
131CuSuite* CuSuiteNew(void);
132void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase);
133void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2);
134void CuSuiteRun(CuSuite* testSuite);
135void CuSuiteSummary(CuSuite* testSuite, CuString* summary);
136void CuSuiteDetails(CuSuite* testSuite, CuString* details);
137
138#endif /* CU_TEST_H */
Note: See TracBrowser for help on using the repository browser.