GnuCash  5.6-150-g038405b370+
test-stuff.h
1 /* Modified by bstanley 20010320
2  * Added do_test macro, do_test_call and do_test_call_args,
3  * print_test_results, set_success_print.
4  *
5  * Modified by bstanley 20010323
6  * removed testing functionality which depends on the rest of gnucash -
7  * separated into gnc-test-stuff.h
8  *
9  */
10 /********************************************************************\
11  * This program is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public License as *
13  * published by the Free Software Foundation; either version 2 of *
14  * the License, or (at your option) any later version. *
15  * *
16  * This program is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19  * GNU General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU General Public License*
22  * along with this program; if not, contact: *
23  * *
24  * Free Software Foundation Voice: +1-617-542-5942 *
25  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
26  * Boston, MA 02110-1301, USA gnu@gnu.org *
27  * *
28 \********************************************************************/
29 
30 
31 /* Outline of a test program using the new testing functions:
32 #include "test-stuff.h"
33 int main( int argc, char* argv[] )
34 {
35  int a, b;
36  g_log_set_always_fatal( G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING );
37  a = b = 1;
38  do_test( a == b, "integer equality" );
39  do_test( a != b, "integer inequality? (should fail)" );
40 
41  do_test_args( a == b, "fancy info", __FILE__, __LINE__, "a = %d, b = %b", a, b );
42 
43  print_test_results();
44  return get_rv();
45 }
46 */
47 /* If you want to see test passes, use
48 set_success_print(TRUE);
49 before you execute the tests.
50 Otherwise, only failures are printed out.
51 */
52 
53 
54 #ifndef TEST_STUFF_H
55 #define TEST_STUFF_H
56 
57 #include <glib.h>
58 #include <stdlib.h>
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 /* Privately used to indicate a test result. You may use these if you
65  * wish, but it's easier to use the do_test macro above.
66  */
67 gboolean do_test_call(
68  gboolean result,
69  const char* test_title,
70  const char* filename,
71  int line );
72 gboolean do_test_args(
73  gboolean result,
74  const char* test_title,
75  const char* filename,
76  int line,
77  const char* format, ... );
78 
79 
83 void print_test_results(void);
84 
94 void set_success_print( gboolean in_should_print );
95 
96 /* Value to return from main. Set to 1 if there were any fails, 0 otherwise. */
97 int get_rv(void);
98 
103 void success_call(
104  const char *test_title,
105  const char *file,
106  int line );
107 
108 void success_args(
109  const char *test_title,
110  const char *file,
111  int line,
112  const char *format,
113  ... );
114 
115 void failure_call(
116  const char *test_title,
117  const char *file,
118  int line);
119 
120 void failure_args(
121  const char *test_title,
122  const char *file,
123  int line,
124  const char *format,
125  ... );
126 
133 #define do_test( result, title ) do_test_call( result, title, __FILE__, __LINE__ )
134 #define success( title ) success_call( title, __FILE__, __LINE__ );
135 #define failure( title ) failure_call( title, __FILE__, __LINE__ );
136 #define failuref( title, format, ... ) failure_args( title, __FILE__, __LINE__, format, ## __VA_ARGS__ );
137 
138 
145 gboolean get_random_boolean(void);
146 gint get_random_int_in_range(int start, int end);
147 void random_character_include_funky_chars (gboolean use_funky_chars);
148 gchar get_random_character(void);
149 gchar* get_random_string(void);
150 gchar * get_random_string_length_in_range(int minlen, int maxlen);
151 gchar* get_random_string_without(const char *exclude_chars);
152 gint32 get_random_gint32 (void);
153 gint64 get_random_gint64(void);
154 double get_random_double(void);
155 const char* get_random_string_in_array(const char* str_list[]);
156 
157 #ifdef __cplusplus
158 } /*extern "C"*/
159 #endif
160 
161 #endif /* TEST_STUFF_H */