1 /*
2  * Check: a unit test framework for C
3  * Copyright (C) 2001, 2002 Arien Malec
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
18  * MA 02110-1301, USA.
19  */
20 
21 #ifndef CHECK_IMPL_H
22 #define CHECK_IMPL_H
23 
24 /* This header should be included by any module that needs
25    to know the implementation details of the check structures
26    Include stdio.h, time.h, & list.h before this header
27 */
28 
29 #define US_PER_SEC 1000000
30 #define NANOS_PER_SECONDS 1000000000
31 
32 /** calculate the difference in useconds out of two "struct timespec"s */
33 #define DIFF_IN_USEC(begin, end) \
34   ( (((end).tv_sec - (begin).tv_sec) * US_PER_SEC) + \
35     ((end).tv_nsec/1000) - ((begin).tv_nsec/1000) )
36 
37 typedef struct TF
38 {
39   TFun fn;
40   int loop_start;
41   int loop_end;
42   const char *name;
43   int signal;
44   signed char allowed_exit_value;
45 } TF;
46 
47 struct Suite
48 {
49   const char *name;
50   List *tclst;                  /* List of test cases */
51 };
52 
53 typedef struct Fixture
54 {
55   int ischecked;
56   SFun fun;
57 } Fixture;
58 
59 struct TCase
60 {
61   const char *name;
62   struct timespec timeout;
63   List *tflst;                  /* list of test functions */
64   List *unch_sflst;
65   List *unch_tflst;
66   List *ch_sflst;
67   List *ch_tflst;
68   List *tags;
69 };
70 
71 typedef struct TestStats
72 {
73   int n_checked;
74   int n_failed;
75   int n_errors;
76 } TestStats;
77 
78 struct TestResult
79 {
80   enum test_result rtype;       /* Type of result */
81   enum ck_result_ctx ctx;       /* When the result occurred */
82   char *file;                   /* File where the test occurred */
83   int line;                     /* Line number where the test occurred */
84   int iter;                     /* The iteration value for looping tests */
85   int duration;                 /* duration of this test in microseconds */
86   const char *tcname;           /* Test case that generated the result */
87   const char *tname;            /* Test that generated the result */
88   char *msg;                    /* Failure message */
89 };
90 
91 TestResult *tr_create (void);
92 void tr_reset (TestResult * tr);
93 void tr_free (TestResult * tr);
94 
95 enum cl_event
96 {
97   CLINITLOG_SR,                 /* Initialize log file */
98   CLENDLOG_SR,                  /* Tests are complete */
99   CLSTART_SR,                   /* Suite runner start */
100   CLSTART_S,                    /* Suite start */
101   CLEND_SR,                     /* Suite runner end */
102   CLEND_S,                      /* Suite end */
103   CLSTART_T,                    /* A test case is about to run */
104   CLEND_T                       /* Test case end */
105 };
106 
107 typedef void (*LFun) (SRunner *, FILE *, enum print_output,
108     void *, enum cl_event);
109 
110 typedef struct Log
111 {
112   FILE *lfile;
113   LFun lfun;
114   int close;
115   enum print_output mode;
116 } Log;
117 
118 struct SRunner
119 {
120   List *slst;                   /* List of Suite objects */
121   TestStats *stats;             /* Run statistics */
122   List *resultlst;              /* List of unit test results */
123   const char *log_fname;        /* name of log file */
124   const char *xml_fname;        /* name of xml output file */
125   const char *tap_fname;        /* name of tap output file */
126   List *loglst;                 /* list of Log objects */
127   enum fork_status fstat;       /* controls if suites are forked or not
128                                    NOTE: Don't use this value directly,
129                                    instead use srunner_fork_status */
130 };
131 
132 
133 void set_fork_status (enum fork_status fstat);
134 enum fork_status cur_fork_status (void);
135 
136 clockid_t check_get_clockid (void);
137 
138 unsigned int tcase_matching_tag (TCase * tc, List * check_for);
139 List *tag_string_to_list (const char *tags_string);
140 
141 #endif /* CHECK_IMPL_H */
142