diff --git a/src/engine/test-core/test-engine-stuff.c b/src/engine/test-core/test-engine-stuff.c index 5fee48786a..9b1c85e566 100644 --- a/src/engine/test-core/test-engine-stuff.c +++ b/src/engine/test-core/test-engine-stuff.c @@ -19,7 +19,7 @@ static gboolean glist_strings_only = FALSE; static GHashTable *exclude_kvp_types = NULL; -static gint kvp_max_depth = G_MAXINT; +static gint kvp_max_depth = 5; static gint kvp_frame_max_elements = 10; static gint max_group_depth = 4; @@ -218,11 +218,17 @@ get_random_glist_depth (gint depth) for (i = 0; i < count; i++) { kvp_value_t kvpt; + kvp_value *value; kvpt = glist_strings_only ? KVP_TYPE_STRING : -2; - ret = g_list_prepend(ret, - get_random_kvp_value_depth (kvpt, depth + 1)); + do + { + value = get_random_kvp_value_depth (kvpt, depth + 1); + } + while (!value); + + ret = g_list_prepend(ret, value); } return ret; @@ -258,6 +264,7 @@ get_random_kvp_frame_depth (gint depth) { kvp_frame *ret; int vals_to_add; + gboolean val_added; if (depth >= kvp_max_depth) return NULL; @@ -265,6 +272,7 @@ get_random_kvp_frame_depth (gint depth) ret = kvp_frame_new(); vals_to_add = get_random_int_in_range(1,kvp_frame_max_elements); + val_added = FALSE; for(;vals_to_add > 0; vals_to_add--) { @@ -278,12 +286,16 @@ get_random_kvp_frame_depth (gint depth) { return NULL; } + if (!val) { - vals_to_add++; + if (!val_added) + vals_to_add++; continue; } + val_added = TRUE; + kvp_frame_set_slot_nc(ret, key, val); g_free(key); @@ -303,16 +315,16 @@ get_random_kvp_value_depth (int type, gint depth) { int datype = type; - if(datype == -1) - { - datype = get_random_int_in_range(KVP_TYPE_GINT64, KVP_TYPE_FRAME + 1); - } - - if(datype == -2) + if (datype == -1) { datype = get_random_int_in_range(KVP_TYPE_GINT64, KVP_TYPE_FRAME); } + if (datype == -2) + { + datype = get_random_int_in_range(KVP_TYPE_GINT64, KVP_TYPE_FRAME - 1); + } + if (datype == KVP_TYPE_FRAME && depth >= kvp_max_depth) return NULL; @@ -440,7 +452,7 @@ get_random_group_depth(GNCSession *session, int depth) AccountGroup *group; int num_accounts; - if (depth == 0) + if (depth <= 0) return NULL; group = xaccMallocAccountGroup (session); @@ -508,7 +520,7 @@ set_split_random_string(Split *spl, } } -static char possible_chars[] = { 'c', 'y', 'f', 'n' }; +static char possible_chars[] = { 'c', 'y', 'f', 'n', 'v' }; Split* get_random_split(GNCSession *session, gnc_numeric num) @@ -542,6 +554,12 @@ get_random_split(GNCSession *session, gnc_numeric num) return ret; } +void +make_random_changes_to_split (Split *split) +{ + g_return_if_fail (split); +} + static void set_tran_random_string(Transaction* trn, void(*func)(Transaction *act, const gchar*str)) diff --git a/src/engine/test-core/test-engine-stuff.h b/src/engine/test-core/test-engine-stuff.h index b9beaad905..4fdcb596ce 100644 --- a/src/engine/test-core/test-engine-stuff.h +++ b/src/engine/test-core/test-engine-stuff.h @@ -59,4 +59,6 @@ GNCSession * get_random_session (void); void add_random_transactions_to_session (GNCSession *session, gint num_transactions); +void make_random_changes_to_split (Split *split); + #endif diff --git a/src/test-core/test-stuff.c b/src/test-core/test-stuff.c index b4f877d50d..68e308fa9b 100644 --- a/src/test-core/test-stuff.c +++ b/src/test-core/test-stuff.c @@ -142,7 +142,7 @@ do_test_call( return result; } -void +gboolean do_test_args( gboolean result, const char* test_title, @@ -160,6 +160,8 @@ do_test_args( vfailure_args( test_title, filename, line, format, ap ); } va_end(ap); + + return result; } void @@ -199,7 +201,10 @@ get_random_boolean(void) gint get_random_int_in_range(int start, int end) { - return start + (int)((double)end * rand() / (RAND_MAX + 1.0)); + return CLAMP (start + (int)((double)(end - start + 1) * rand() / + (RAND_MAX + 1.0)), + start, + end); } static char *random_chars = NULL; diff --git a/src/test-core/test-stuff.h b/src/test-core/test-stuff.h index 5be3fac73e..979eb18127 100644 --- a/src/test-core/test-stuff.h +++ b/src/test-core/test-stuff.h @@ -63,7 +63,7 @@ gboolean do_test_call( const char* test_title, const char* filename, int line ); -void do_test_args( +gboolean do_test_args( gboolean result, const char* test_title, const char* filename,