-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctest.h
More file actions
69 lines (58 loc) · 1.54 KB
/
ctest.h
File metadata and controls
69 lines (58 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* ctest.h: Defines a test framework for C projects.
* Author: Chuck Allison
* Source:
* The Simplest Automated Unit Test Framework That Could Possibly Work:
* http://www.ddj.com/184401279?pgno=1
*/
#ifndef CTEST_H
#define CTEST_H
#include <stdio.h>
#include <stdbool.h>
#define ct_test(test, cond) \
ct_do_test(test, #cond, cond, __FILE__, __LINE__)
#define ct_fail(test, str) \
ct_do_fail(test, str, __FILE__, __LINE__)
typedef struct _Test Test;
typedef void (*TestFunc) (Test *);
struct _Test {
char *name;
FILE *pStream;
size_t nTests;
size_t maxTests;
TestFunc *pTestFuns;
long nPass;
long nFail;
};
#ifdef __cplusplus
extern "C" {
#endif
Test *ct_create(const char *name,
void (*init) (Test *));
void ct_destroy(Test * pTest);
const char *ct_getName(Test * pTest);
long ct_getNumPassed(Test * pTest);
long ct_getNumFailed(Test * pTest);
long ct_getNumTests(Test * pTest);
FILE *ct_getStream(Test * pTest);
void ct_setStream(Test * pTest,
FILE * stream);
bool ct_addTestFunction(Test * pTest,
TestFunc tfun);
void ct_succeed(Test * pTest);
long ct_run(Test * pTest);
long ct_report(Test * pTest);
void ct_reset(Test * pTest);
/* Not intended for end-users: */
void ct_do_test(Test * pTest,
const char *str,
bool cond,
const char *file,
long line);
void ct_do_fail(Test * pTest,
const char *str,
const char *file,
long line);
#ifdef __cplusplus
}
#endif
#endif