2001-08-17 17:49:17 -05:00
|
|
|
/* Modified by bstanley 20010320
|
|
|
|
* Added do_test macro, do_test_call and do_test_call_args,
|
|
|
|
* print_test_results, set_success_print.
|
|
|
|
*
|
|
|
|
* Modified by bstanley 20010323
|
|
|
|
* removed testing functionality which depends on the rest of gnucash -
|
|
|
|
* sepearated into gnc-test-stuff.h
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Outline of a test program using the new testing functions:
|
|
|
|
#include "test-stuff.h"
|
|
|
|
int main( int argc, char* argv[] )
|
|
|
|
{
|
|
|
|
int a, b;
|
|
|
|
g_log_set_always_fatal( G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING );
|
|
|
|
a = b = 1;
|
2006-03-31 15:08:24 -06:00
|
|
|
do_test( a == b, "integer equality" );
|
|
|
|
do_test( a != b, "integer inequality? (should fail)" );
|
2001-08-17 17:49:17 -05:00
|
|
|
|
|
|
|
do_test_args( a == b, "fancy info", __FILE__, __LINE__, "a = %d, b = %b", a, b );
|
|
|
|
|
|
|
|
print_test_results();
|
|
|
|
return get_rv();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
/* If you want to see test passes, use
|
|
|
|
set_success_print(TRUE);
|
|
|
|
before you execute the tests.
|
|
|
|
Otherwise, only failures are printed out.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef TEST_STUFF_H
|
|
|
|
#define TEST_STUFF_H
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use this to indicate the result of a test.
|
|
|
|
* The result is TRUE for success, FALSE for failure.
|
|
|
|
* title describes the test
|
|
|
|
* Tests are automatically identified by their source file and line.
|
|
|
|
*/
|
2001-09-28 04:04:43 -05:00
|
|
|
#define do_test( result, title ) do_test_call( result, title, __FILE__, __LINE__ )
|
2001-08-17 17:49:17 -05:00
|
|
|
#define success( title ) success_call( title, __FILE__, __LINE__ );
|
|
|
|
#define failure( title ) failure_call( title, __FILE__, __LINE__ );
|
|
|
|
|
|
|
|
/** This one doesn't work because macros can't take a variable number of arguments.
|
|
|
|
* well, apparently gcc can, but it's non-standard.
|
|
|
|
* Apparently C99 can, too, but it's not exactly standard either.
|
|
|
|
#define do_test_args( result, title, format ) do_test_call( result, title, __FILE__, __LINE__, format, ... );
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Privately used to indicate a test result. You may use these if you
|
|
|
|
* wish, but it's easier to use the do_test macro above.
|
|
|
|
*/
|
2001-09-28 04:04:43 -05:00
|
|
|
gboolean do_test_call(
|
2009-12-29 14:12:48 -06:00
|
|
|
gboolean result,
|
|
|
|
const char* test_title,
|
|
|
|
const char* filename,
|
|
|
|
int line );
|
2001-10-15 19:50:01 -05:00
|
|
|
gboolean do_test_args(
|
2009-12-29 14:12:48 -06:00
|
|
|
gboolean result,
|
|
|
|
const char* test_title,
|
|
|
|
const char* filename,
|
|
|
|
int line,
|
|
|
|
const char* format, ... );
|
2001-08-17 17:49:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prints out the number of tests passed and failed.
|
|
|
|
*/
|
|
|
|
void print_test_results(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use this to set whether successful tests
|
|
|
|
* should print a message.
|
|
|
|
* Default is false.
|
|
|
|
* Successful test messages are useful while initally constructing the
|
|
|
|
* test suite, but when it's completed, no news is good news.
|
|
|
|
* A successful test run will be indicated by the message
|
|
|
|
* from print_test_results().
|
|
|
|
*/
|
|
|
|
void set_success_print( gboolean in_should_print );
|
|
|
|
|
|
|
|
/* Value to return from main. Set to 1 if there were any fails, 0 otherwise. */
|
|
|
|
int get_rv(void);
|
|
|
|
|
|
|
|
/** Testing primitives.
|
|
|
|
* Sometimes you just have to put the results of
|
|
|
|
* a test into different forks of the code.
|
|
|
|
*/
|
|
|
|
void success_call(
|
2009-12-29 14:12:48 -06:00
|
|
|
const char *test_title,
|
|
|
|
const char *file,
|
|
|
|
int line );
|
2001-08-17 17:49:17 -05:00
|
|
|
|
|
|
|
void success_args(
|
2009-12-29 14:12:48 -06:00
|
|
|
const char *test_title,
|
|
|
|
const char *file,
|
|
|
|
int line,
|
|
|
|
const char *format,
|
|
|
|
... );
|
2001-08-17 17:49:17 -05:00
|
|
|
|
|
|
|
void failure_call(
|
2009-12-29 14:12:48 -06:00
|
|
|
const char *test_title,
|
|
|
|
const char *file,
|
|
|
|
int line);
|
2001-08-17 17:49:17 -05:00
|
|
|
|
|
|
|
void failure_args(
|
2009-12-29 14:12:48 -06:00
|
|
|
const char *test_title,
|
|
|
|
const char *file,
|
|
|
|
int line,
|
|
|
|
const char *format,
|
|
|
|
... );
|
2001-08-17 17:49:17 -05:00
|
|
|
|
2001-08-17 19:13:45 -05:00
|
|
|
gboolean get_random_boolean(void);
|
|
|
|
gint get_random_int_in_range(int start, int end);
|
2001-10-11 03:22:44 -05:00
|
|
|
void random_character_include_funky_chars (gboolean use_funky_chars);
|
2001-08-17 19:13:45 -05:00
|
|
|
gchar get_random_character(void);
|
|
|
|
gchar* get_random_string(void);
|
2006-03-30 19:43:16 -06:00
|
|
|
gchar * get_random_string_length_in_range(int minlen, int maxlen);
|
2001-10-12 05:50:35 -05:00
|
|
|
gchar* get_random_string_without(const char *exclude_chars);
|
2001-08-17 19:13:45 -05:00
|
|
|
gint64 get_random_gint64(void);
|
|
|
|
double get_random_double(void);
|
|
|
|
const char* get_random_string_in_array(const char* str_list[]);
|
|
|
|
|
2001-08-17 17:49:17 -05:00
|
|
|
#endif /* TEST_STUFF_H */
|