| 1 | #ifndef CU_TEST_H |
|---|
| 2 | #define CU_TEST_H |
|---|
| 3 | |
|---|
| 4 | #include <setjmp.h> |
|---|
| 5 | #include <stdarg.h> |
|---|
| 6 | |
|---|
| 7 | /* CuString */ |
|---|
| 8 | |
|---|
| 9 | char* CuStrAlloc(int size); |
|---|
| 10 | char* CuStrCopy(char* old); |
|---|
| 11 | |
|---|
| 12 | #define CU_ALLOC(TYPE) ((TYPE*) malloc(sizeof(TYPE))) |
|---|
| 13 | |
|---|
| 14 | #define HUGE_STRING_LEN 8192 |
|---|
| 15 | #define STRING_MAX 256 |
|---|
| 16 | #define STRING_INC 256 |
|---|
| 17 | |
|---|
| 18 | typedef struct |
|---|
| 19 | { |
|---|
| 20 | int length; |
|---|
| 21 | int size; |
|---|
| 22 | char* buffer; |
|---|
| 23 | } CuString; |
|---|
| 24 | |
|---|
| 25 | void CuStringInit(CuString* str); |
|---|
| 26 | CuString* CuStringNew(void); |
|---|
| 27 | void CuStringRead(CuString* str, char* path); |
|---|
| 28 | void CuStringAppend(CuString* str, char* text); |
|---|
| 29 | void CuStringAppendLen(CuString* str, char* text, long length); |
|---|
| 30 | void CuStringAppendChar(CuString* str, char ch); |
|---|
| 31 | void CuStringAppendFormat(CuString* str, char* format, ...); |
|---|
| 32 | void CuStringResize(CuString* str, int newSize); |
|---|
| 33 | void CuStringFree(CuString* str); |
|---|
| 34 | |
|---|
| 35 | void CuStringFree(CuString *str); |
|---|
| 36 | |
|---|
| 37 | /* CuTest */ |
|---|
| 38 | |
|---|
| 39 | typedef struct CuTest CuTest; |
|---|
| 40 | |
|---|
| 41 | typedef void (*TestFunction)(CuTest *); |
|---|
| 42 | |
|---|
| 43 | struct CuTest |
|---|
| 44 | { |
|---|
| 45 | char* name; |
|---|
| 46 | TestFunction function; |
|---|
| 47 | int failed; |
|---|
| 48 | int ran; |
|---|
| 49 | char* message; |
|---|
| 50 | jmp_buf *jumpBuf; |
|---|
| 51 | }; |
|---|
| 52 | |
|---|
| 53 | void CuTestInit(CuTest* t, char* name, TestFunction function); |
|---|
| 54 | CuTest* CuTestNew(char* name, TestFunction function); |
|---|
| 55 | void CuFail(CuTest* tc, char* message); |
|---|
| 56 | void CuAssert(CuTest* tc, char* message, int condition); |
|---|
| 57 | void CuAssertTrue(CuTest* tc, int condition); |
|---|
| 58 | void CuAssertStrEquals(CuTest* tc, char* expected, char* actual); |
|---|
| 59 | void CuAssertIntEquals(CuTest* tc, int expected, int actual); |
|---|
| 60 | void CuAssertPtrEquals(CuTest* tc, void* expected, void* actual); |
|---|
| 61 | void CuAssertPtrNotNull(CuTest* tc, void* pointer); |
|---|
| 62 | void CuTestRun(CuTest* tc); |
|---|
| 63 | |
|---|
| 64 | /* CuSuite */ |
|---|
| 65 | |
|---|
| 66 | #define MAX_TEST_CASES 1024 |
|---|
| 67 | |
|---|
| 68 | #define SUITE_ADD_TEST(SUITE,TEST) CuSuiteAdd(SUITE, CuTestNew(#TEST, TEST)) |
|---|
| 69 | |
|---|
| 70 | typedef struct |
|---|
| 71 | { |
|---|
| 72 | int count; |
|---|
| 73 | CuTest* list[MAX_TEST_CASES]; |
|---|
| 74 | int failCount; |
|---|
| 75 | |
|---|
| 76 | } CuSuite; |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | void CuSuiteInit(CuSuite* testSuite); |
|---|
| 80 | CuSuite* CuSuiteNew(); |
|---|
| 81 | void CuSuiteFree(CuSuite* testSuite); |
|---|
| 82 | void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase); |
|---|
| 83 | void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2); |
|---|
| 84 | void CuSuiteRun(CuSuite* testSuite); |
|---|
| 85 | void CuSuiteSummary(CuSuite* testSuite, CuString* summary); |
|---|
| 86 | void CuSuiteDetails(CuSuite* testSuite, CuString* details); |
|---|
| 87 | void CuSuiteFree(CuSuite *testsuite); |
|---|
| 88 | |
|---|
| 89 | #endif /* CU_TEST_H */ |
|---|