26 #include <sys/types.h> 38 #include "test-stuff.h" 40 static gboolean glist_strings_only = FALSE;
42 static GHashTable *exclude_kvp_types = NULL;
43 static gint kvp_max_depth = 5;
44 static gint kvp_frame_max_elements = 10;
46 gboolean gnc_engine_debug_random = FALSE;
52 set_max_kvp_depth (gint max_kvp_depth)
54 kvp_max_depth = MAX (max_kvp_depth, 1);
58 set_max_kvp_frame_elements (gint max_kvp_frame_elements)
60 kvp_frame_max_elements = MAX (max_kvp_frame_elements, 1);
68 if (!exclude_kvp_types)
69 exclude_kvp_types = g_hash_table_new (g_int_hash, g_int_equal);
71 key = g_new (gint, 1);
74 g_hash_table_insert (exclude_kvp_types, key, exclude_kvp_types);
82 if (!exclude_kvp_types)
85 if (g_hash_table_lookup (exclude_kvp_types, &key))
92 random_glist_strings_only (gboolean strings_only)
94 glist_strings_only = strings_only;
100 static gint borked = 80;
102 static inline gboolean
105 if (1 == get_random_int_in_range (0, borked))
125 static KvpValue *get_random_kvp_value_depth (
int type, gint depth);
128 get_random_glist_depth (gint depth)
131 int count = get_random_int_in_range (1, 5);
134 if (depth >= kvp_max_depth)
137 for (i = 0; i < count; i++)
146 value = get_random_kvp_value_depth (kvpt, depth + 1);
150 ret = g_list_prepend (ret, value);
157 get_random_glist (
void)
159 return get_random_glist_depth (0);
166 get_random_guid (
void)
170 ret = g_new (
GUID, 1);
177 get_random_binary_data (
void)
182 len = get_random_int_in_range (20, 100);
184 ret->data = g_new (guchar, len);
187 for (len--; len >= 0; len--)
189 ret->data[len] = (guchar) get_random_int_in_range (0, 255);
198 static KvpFrame *get_random_kvp_frame_depth (gint depth);
201 get_random_kvp_value_depth (
int type, gint depth)
223 if (kvp_type_excluded (datype))
229 ret = kvp_value_new_gint64 (get_random_gint64 ());
237 ret = kvp_value_new_numeric (get_random_qof_numeric ());
243 tmp_str = get_random_string ();
247 ret = kvp_value_new_string (tmp_str);
255 tmp_guid = get_random_guid ();
256 ret = kvp_value_new_guid (tmp_guid);
263 tmp_data = get_random_binary_data ();
264 ret = kvp_value_new_binary (tmp_data->data, tmp_data->len);
265 g_free (tmp_data->data);
277 tmp_frame = get_random_kvp_frame_depth (depth + 1);
278 ret = kvp_value_new_frame (tmp_frame);
291 get_random_kvp_frame_depth (gint depth)
297 if (depth >= kvp_max_depth)
302 vals_to_add = get_random_int_in_range (1, kvp_frame_max_elements);
305 for (; vals_to_add > 0; vals_to_add--)
313 key = get_random_string_without (
"/");
321 val = get_random_kvp_value_depth (-1, depth + 1);
341 get_random_kvp_frame (
void)
343 return get_random_kvp_frame_depth (0);
347 get_random_kvp_value (
int type)
349 return get_random_kvp_value_depth (type, 0);
355 #define RAND_IN_RANGE(X) (((X)*((gint64) (rand()+1)))/RAND_MAX) 358 get_random_qof_numeric (
void)
363 if (RAND_MAX / 8 > rand ())
366 deno = RAND_IN_RANGE (6000ULL);
370 gint64 norm = RAND_IN_RANGE (10ULL);
384 numer = get_random_gint64 () / 100000;
473 get_random_query_type (
void)
475 switch (get_random_int_in_range (0, 4))
KvpValueType
possible types in the union KvpValue
struct _KvpFrame KvpFrame
This file declares testing functions for the engine.
struct _QofQuery QofQuery
128bit denominator/numerator maths.
void kvp_frame_delete(KvpFrame *frame)
struct _KvpValue KvpValue
static QofNumeric qof_numeric_create(gint64 num, gint64 denom)
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *slot, KvpValue *value)
void guid_new(GUID *guid)
KvpValue * kvp_value_new_glist_nc(GList *value)
KvpFrame * kvp_frame_new(void)