test-stuff.h

00001 /* Modified by bstanley 20010320
00002  * Added do_test macro, do_test_call and do_test_call_args,
00003  * print_test_results, set_success_print.
00004  *
00005  * Modified by bstanley 20010323
00006  * removed testing functionality which depends on the rest of gnucash -
00007  * sepearated into gnc-test-stuff.h
00008  *
00009  */
00010 
00011 /* Outline of a test program using the new testing functions:
00012 #include "test-stuff.h"
00013 int main( int argc, char* argv[] )
00014 {
00015         int a, b;
00016         g_log_set_always_fatal( G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING );
00017         a = b = 1;
00018         do_test( a == b, 'integer equality" );
00019         do_test( a != b, 'integer inequality? (should fail)" );
00020 
00021         do_test_args( a == b, "fancy info", __FILE__, __LINE__, "a = %d, b = %b", a, b );
00022 
00023         print_test_results();
00024         return get_rv();
00025 }
00026 */
00027 /* If you want to see test passes, use
00028 set_success_print(TRUE);
00029 before you execute the tests.
00030 Otherwise, only failures are printed out.
00031 */
00032 
00033 
00034 #ifndef TEST_STUFF_H
00035 #define TEST_STUFF_H
00036 
00037 #include "config.h"
00038 
00039 #include <glib.h>
00040 #include <stdlib.h>
00041 
00048 #define do_test( result, title ) do_test_call( result, title, __FILE__, __LINE__ )
00049 #define success( title ) success_call( title, __FILE__, __LINE__ );
00050 #define failure( title ) failure_call( title, __FILE__, __LINE__ );
00051 
00058 /* Privately used to indicate a test result. You may use these if you
00059  * wish, but it's easier to use the do_test macro above.
00060  */
00061 gboolean do_test_call(
00062                 gboolean result,
00063                 const char* test_title,
00064                 const char* filename,
00065                 int line );
00066 gboolean do_test_args(
00067                 gboolean result,
00068                 const char* test_title,
00069                 const char* filename,
00070                 int line,
00071                 const char* format, ... );
00072 
00073 
00077 void print_test_results(void);
00078 
00088 void set_success_print( gboolean in_should_print );
00089 
00090 /* Value to return from main. Set to 1 if there were any fails, 0 otherwise. */
00091 int get_rv(void);
00092 
00097 void success_call(
00098                 const char *test_title,
00099                 const char *file,
00100                 int line );
00101 
00102 void success_args(
00103                 const char *test_title,
00104                 const char *file,
00105                 int line,
00106                 const char *format,
00107                 ... );
00108 
00109 void failure_call(
00110                 const char *test_title,
00111                 const char *file,
00112                 int line);
00113 
00114 void failure_args(
00115                 const char *test_title,
00116                 const char *file,
00117                 int line,
00118                 const char *format,
00119                 ... );
00120 
00121 gboolean get_random_boolean(void);
00122 gint get_random_int_in_range(int start, int end);
00123 void random_character_include_funky_chars (gboolean use_funky_chars);
00124 gchar get_random_character(void);
00125 gchar* get_random_string(void);
00126 gchar* get_random_string_without(const char *exclude_chars);
00127 gint64 get_random_gint64(void);
00128 double get_random_double(void);
00129 const char* get_random_string_in_array(const char* str_list[]);
00130 
00131 #endif /* TEST_STUFF_H */

Generated on Fri May 12 18:00:33 2006 for QOF by  doxygen 1.4.4