mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Return the actual number of test failures with get_rv().
Use shorter strings for commodity mnemonics. Ensure that test splits amount and value have the same sign. Avoid numerical overflow in rate calculation when generating test splits. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13718 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
3233622edc
commit
ec1bcb86df
@ -525,7 +525,7 @@ get_random_commodity (QofBook *book)
|
|||||||
gchar *name;
|
gchar *name;
|
||||||
const gchar *space;
|
const gchar *space;
|
||||||
gchar *mn;
|
gchar *mn;
|
||||||
gchar *xcode;
|
gchar *cusip;
|
||||||
int ran_int;
|
int ran_int;
|
||||||
gnc_commodity_table *table;
|
gnc_commodity_table *table;
|
||||||
|
|
||||||
@ -538,7 +538,7 @@ get_random_commodity (QofBook *book)
|
|||||||
return get_random_commodity_from_table (table);
|
return get_random_commodity_from_table (table);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mn = get_random_string();
|
mn = get_random_string_length_in_range(1, 3);
|
||||||
space = get_random_commodity_namespace();
|
space = get_random_commodity_namespace();
|
||||||
|
|
||||||
if (table)
|
if (table)
|
||||||
@ -553,15 +553,15 @@ get_random_commodity (QofBook *book)
|
|||||||
}
|
}
|
||||||
|
|
||||||
name = get_random_string();
|
name = get_random_string();
|
||||||
xcode = get_random_string();
|
cusip = get_random_string();
|
||||||
|
|
||||||
ran_int = get_random_int_in_range(min_scu, max_scu);
|
ran_int = get_random_int_in_range(min_scu, max_scu);
|
||||||
|
|
||||||
ret = gnc_commodity_new (book, name, space, mn, xcode, ran_int);
|
ret = gnc_commodity_new(book, name, space, mn, cusip, ran_int);
|
||||||
|
|
||||||
g_free(mn);
|
g_free(mn);
|
||||||
g_free(name);
|
g_free(name);
|
||||||
g_free(xcode);
|
g_free(cusip);
|
||||||
|
|
||||||
if (table)
|
if (table)
|
||||||
ret = gnc_commodity_table_insert (table, ret);
|
ret = gnc_commodity_table_insert (table, ret);
|
||||||
@ -921,7 +921,7 @@ add_random_splits(QofBook *book, Transaction *trn, GList *account_list)
|
|||||||
{
|
{
|
||||||
Account *acc, *bcc;
|
Account *acc, *bcc;
|
||||||
Split *s;
|
Split *s;
|
||||||
gnc_numeric num;
|
gnc_numeric val, amt;
|
||||||
|
|
||||||
/* Gotta have at least two different accounts */
|
/* Gotta have at least two different accounts */
|
||||||
if (1 >= g_list_length (account_list)) return;
|
if (1 >= g_list_length (account_list)) return;
|
||||||
@ -943,23 +943,33 @@ add_random_splits(QofBook *book, Transaction *trn, GList *account_list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set up two splits whose values really are opposites. */
|
/* Set up two splits whose values really are opposites. */
|
||||||
num = xaccSplitGetValue(s);
|
val = xaccSplitGetValue(s);
|
||||||
s = get_random_split(book, bcc, trn);
|
s = get_random_split(book, bcc, trn);
|
||||||
|
|
||||||
/* Other split should have equal and opposite value */
|
/* Other split should have equal and opposite value */
|
||||||
if (do_bork())
|
if (do_bork())
|
||||||
{
|
{
|
||||||
num = get_random_gnc_numeric();
|
val = get_random_gnc_numeric();
|
||||||
}
|
}
|
||||||
xaccSplitSetValue(s, gnc_numeric_neg(num));
|
val = gnc_numeric_neg(val);
|
||||||
|
xaccSplitSetValue(s, val);
|
||||||
|
|
||||||
if (gnc_commodity_equal (xaccTransGetCurrency(trn),
|
if (gnc_commodity_equal (xaccTransGetCurrency(trn),
|
||||||
xaccAccountGetCommodity(bcc)) &&
|
xaccAccountGetCommodity(bcc)) &&
|
||||||
(!do_bork()))
|
(!do_bork()))
|
||||||
{
|
{
|
||||||
xaccSplitSetAmount(s, gnc_numeric_neg(num));
|
amt = val;
|
||||||
|
} else {
|
||||||
|
gnc_numeric amt2 = xaccSplitGetAmount(s);
|
||||||
|
int i = gnc_numeric_positive_p(amt2) + gnc_numeric_positive_p(amt);
|
||||||
|
if (i % 2)
|
||||||
|
amt = gnc_numeric_neg(amt2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gnc_numeric_zero_p(val))
|
||||||
|
amt = val;
|
||||||
|
|
||||||
|
xaccSplitSetAmount(s, val);
|
||||||
xaccTransCommitEdit(trn);
|
xaccTransCommitEdit(trn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1270,10 +1280,10 @@ Split*
|
|||||||
get_random_split(QofBook *book, Account *acct, Transaction *trn)
|
get_random_split(QofBook *book, Account *acct, Transaction *trn)
|
||||||
{
|
{
|
||||||
Split *ret;
|
Split *ret;
|
||||||
gnc_numeric amt, val;
|
gnc_numeric amt, val, rate;
|
||||||
const gchar *str;
|
const gchar *str;
|
||||||
gnc_commodity *com;
|
gnc_commodity *com;
|
||||||
int scu;
|
int scu, denom;
|
||||||
Timespec *ts;
|
Timespec *ts;
|
||||||
|
|
||||||
com = xaccTransGetCurrency (trn);
|
com = xaccTransGetCurrency (trn);
|
||||||
@ -1295,8 +1305,8 @@ get_random_split(QofBook *book, Account *acct, Transaction *trn)
|
|||||||
/* Split must be in an account before we can set an amount */
|
/* Split must be in an account before we can set an amount */
|
||||||
/* and in a transaction before it can be added to an account. */
|
/* and in a transaction before it can be added to an account. */
|
||||||
xaccTransBeginEdit(trn);
|
xaccTransBeginEdit(trn);
|
||||||
xaccTransAppendSplit(trn, ret);
|
xaccSplitSetParent(ret, trn);
|
||||||
xaccAccountInsertSplit (acct, ret);
|
xaccSplitSetAccount(ret, acct);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
val = get_random_gnc_numeric ();
|
val = get_random_gnc_numeric ();
|
||||||
@ -1304,7 +1314,7 @@ get_random_split(QofBook *book, Account *acct, Transaction *trn)
|
|||||||
fprintf(stderr, "get_random_split: Created split with zero value: %p\n", ret);
|
fprintf(stderr, "get_random_split: Created split with zero value: %p\n", ret);
|
||||||
|
|
||||||
if (!do_bork())
|
if (!do_bork())
|
||||||
val = gnc_numeric_convert (val, scu, GNC_HOW_RND_ROUND);
|
val.denom = scu;
|
||||||
} while (gnc_numeric_check(val) != GNC_ERROR_OK);
|
} while (gnc_numeric_check(val) != GNC_ERROR_OK);
|
||||||
xaccSplitSetValue(ret, val);
|
xaccSplitSetValue(ret, val);
|
||||||
|
|
||||||
@ -1315,11 +1325,18 @@ get_random_split(QofBook *book, Account *acct, Transaction *trn)
|
|||||||
(!do_bork())) {
|
(!do_bork())) {
|
||||||
amt = val;
|
amt = val;
|
||||||
} else {
|
} else {
|
||||||
amt = get_random_gnc_numeric ();
|
denom = gnc_commodity_get_fraction(xaccAccountGetCommodity(
|
||||||
if (gnc_numeric_negative_p(val) && !gnc_numeric_negative_p(amt))
|
xaccSplitGetAccount(ret)));
|
||||||
amt = gnc_numeric_neg(amt);
|
do {
|
||||||
|
rate = gnc_numeric_abs(get_random_gnc_numeric());
|
||||||
|
amt = gnc_numeric_mul(val, rate,
|
||||||
|
GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);
|
||||||
|
amt = gnc_numeric_convert(amt, denom, GNC_HOW_RND_ROUND);
|
||||||
|
} while (gnc_numeric_check(amt) != GNC_ERROR_OK);
|
||||||
}
|
}
|
||||||
xaccSplitSetAmount(ret, amt);
|
xaccSplitSetAmount(ret, amt);
|
||||||
|
if (gnc_numeric_positive_p(val))
|
||||||
|
g_assert(gnc_numeric_positive_p(amt));
|
||||||
|
|
||||||
xaccSplitSetSlots_nc(ret, get_random_kvp_frame());
|
xaccSplitSetSlots_nc(ret, get_random_kvp_frame());
|
||||||
xaccTransCommitEdit(trn);
|
xaccTransCommitEdit(trn);
|
||||||
|
@ -578,5 +578,5 @@ main (int argc, char **argv)
|
|||||||
print_test_results();
|
print_test_results();
|
||||||
qof_session_end(session);
|
qof_session_end(session);
|
||||||
qof_close();
|
qof_close();
|
||||||
return 0;
|
return (get_rv() > 1);
|
||||||
}
|
}
|
||||||
|
@ -120,10 +120,7 @@ vfailure_args(
|
|||||||
int
|
int
|
||||||
get_rv(void)
|
get_rv(void)
|
||||||
{
|
{
|
||||||
if( failures ) {
|
return failures;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
@ -244,6 +241,20 @@ get_random_character(void)
|
|||||||
return random_chars[get_random_int_in_range(0, rcend)];
|
return random_chars[get_random_int_in_range(0, rcend)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gchar *
|
||||||
|
get_random_string_length_in_range(int minlen, int maxlen)
|
||||||
|
{
|
||||||
|
gchar *ret;
|
||||||
|
int i, len = get_random_int_in_range(minlen, maxlen);
|
||||||
|
|
||||||
|
ret = g_new0(gchar, len);
|
||||||
|
|
||||||
|
for (i = 0; i < len - 1; i++)
|
||||||
|
ret[i] = get_random_character ();
|
||||||
|
|
||||||
|
return g_strstrip(ret);
|
||||||
|
}
|
||||||
|
|
||||||
gchar *
|
gchar *
|
||||||
get_random_string_without(const char *exclude_chars)
|
get_random_string_without(const char *exclude_chars)
|
||||||
{
|
{
|
||||||
|
@ -121,6 +121,7 @@ gint get_random_int_in_range(int start, int end);
|
|||||||
void random_character_include_funky_chars (gboolean use_funky_chars);
|
void random_character_include_funky_chars (gboolean use_funky_chars);
|
||||||
gchar get_random_character(void);
|
gchar get_random_character(void);
|
||||||
gchar* get_random_string(void);
|
gchar* get_random_string(void);
|
||||||
|
gchar * get_random_string_length_in_range(int minlen, int maxlen);
|
||||||
gchar* get_random_string_without(const char *exclude_chars);
|
gchar* get_random_string_without(const char *exclude_chars);
|
||||||
gint64 get_random_gint64(void);
|
gint64 get_random_gint64(void);
|
||||||
double get_random_double(void);
|
double get_random_double(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user