check: Import version 0.9.14
[platform/upstream/gstreamer.git] / libs / gst / check / libcheck / check_impl.h
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,
18  * Boston, 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 };
69
70 typedef struct TestStats
71 {
72   int n_checked;
73   int n_failed;
74   int n_errors;
75 } TestStats;
76
77 struct TestResult
78 {
79   enum test_result rtype;       /* Type of result */
80   enum ck_result_ctx ctx;       /* When the result occurred */
81   char *file;                   /* File where the test occured */
82   int line;                     /* Line number where the test occurred */
83   int iter;                     /* The iteration value for looping tests */
84   int duration;                 /* duration of this test in microseconds */
85   const char *tcname;           /* Test case that generated the result */
86   const char *tname;            /* Test that generated the result */
87   char *msg;                    /* Failure message */
88 };
89
90 TestResult *tr_create (void);
91 void tr_reset (TestResult * tr);
92 void tr_free (TestResult * tr);
93
94 enum cl_event
95 {
96   CLINITLOG_SR,                 /* Initialize log file */
97   CLENDLOG_SR,                  /* Tests are complete */
98   CLSTART_SR,                   /* Suite runner start */
99   CLSTART_S,                    /* Suite start */
100   CLEND_SR,                     /* Suite runner end */
101   CLEND_S,                      /* Suite end */
102   CLSTART_T,                    /* A test case is about to run */
103   CLEND_T                       /* Test case end */
104 };
105
106 typedef void (*LFun) (SRunner *, FILE *, enum print_output,
107     void *, enum cl_event);
108
109 typedef struct Log
110 {
111   FILE *lfile;
112   LFun lfun;
113   int close;
114   enum print_output mode;
115 } Log;
116
117 struct SRunner
118 {
119   List *slst;                   /* List of Suite objects */
120   TestStats *stats;             /* Run statistics */
121   List *resultlst;              /* List of unit test results */
122   const char *log_fname;        /* name of log file */
123   const char *xml_fname;        /* name of xml output file */
124   const char *tap_fname;        /* name of tap output file */
125   List *loglst;                 /* list of Log objects */
126   enum fork_status fstat;       /* controls if suites are forked or not
127                                    NOTE: Don't use this value directly,
128                                    instead use srunner_fork_status */
129 };
130
131
132 void set_fork_status (enum fork_status fstat);
133 enum fork_status cur_fork_status (void);
134
135 clockid_t check_get_clockid (void);
136
137 #endif /* CHECK_IMPL_H */