[Gnucash-changes] r13718 - gnucash/trunk/src - Return the actual
number of test failures with get_rv().
Chris Shoemaker
chris at cvs.gnucash.org
Thu Mar 30 20:43:17 EST 2006
Author: chris
Date: 2006-03-30 20:43:16 -0500 (Thu, 30 Mar 2006)
New Revision: 13718
Trac: http://svn.gnucash.org/trac/changeset/13718
Modified:
gnucash/trunk/src/engine/test-core/test-engine-stuff.c
gnucash/trunk/src/engine/test/test-freq-spec.c
gnucash/trunk/src/test-core/test-stuff.c
gnucash/trunk/src/test-core/test-stuff.h
Log:
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.
Modified: gnucash/trunk/src/engine/test/test-freq-spec.c
===================================================================
--- gnucash/trunk/src/engine/test/test-freq-spec.c 2006-03-31 00:00:43 UTC (rev 13717)
+++ gnucash/trunk/src/engine/test/test-freq-spec.c 2006-03-31 01:43:16 UTC (rev 13718)
@@ -562,21 +562,21 @@
int
main (int argc, char **argv)
{
- QofSession *session;
+ QofSession *session;
- qof_init();
- g_return_val_if_fail(cashobjects_register(), -1);
- session = qof_session_new ();
- book = qof_session_get_book(session);
- test_once();
- test_caseA();
- test_daily();
- test_weekly();
- test_monthly();
- test_month_relative();
- test_composite();
- print_test_results();
- qof_session_end(session);
- qof_close();
- return 0;
+ qof_init();
+ g_return_val_if_fail(cashobjects_register(), -1);
+ session = qof_session_new ();
+ book = qof_session_get_book(session);
+ test_once();
+ test_caseA();
+ test_daily();
+ test_weekly();
+ test_monthly();
+ test_month_relative();
+ test_composite();
+ print_test_results();
+ qof_session_end(session);
+ qof_close();
+ return (get_rv() > 1);
}
Modified: gnucash/trunk/src/engine/test-core/test-engine-stuff.c
===================================================================
--- gnucash/trunk/src/engine/test-core/test-engine-stuff.c 2006-03-31 00:00:43 UTC (rev 13717)
+++ gnucash/trunk/src/engine/test-core/test-engine-stuff.c 2006-03-31 01:43:16 UTC (rev 13718)
@@ -525,7 +525,7 @@
gchar *name;
const gchar *space;
gchar *mn;
- gchar *xcode;
+ gchar *cusip;
int ran_int;
gnc_commodity_table *table;
@@ -538,7 +538,7 @@
return get_random_commodity_from_table (table);
#endif
- mn = get_random_string();
+ mn = get_random_string_length_in_range(1, 3);
space = get_random_commodity_namespace();
if (table)
@@ -553,15 +553,15 @@
}
name = get_random_string();
- xcode = get_random_string();
+ cusip = get_random_string();
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(name);
- g_free(xcode);
+ g_free(cusip);
if (table)
ret = gnc_commodity_table_insert (table, ret);
@@ -921,7 +921,7 @@
{
Account *acc, *bcc;
Split *s;
- gnc_numeric num;
+ gnc_numeric val, amt;
/* Gotta have at least two different accounts */
if (1 >= g_list_length (account_list)) return;
@@ -943,23 +943,33 @@
}
/* Set up two splits whose values really are opposites. */
- num = xaccSplitGetValue(s);
+ val = xaccSplitGetValue(s);
s = get_random_split(book, bcc, trn);
/* Other split should have equal and opposite value */
if (do_bork())
{
- num = get_random_gnc_numeric();
- }
- xaccSplitSetValue(s, gnc_numeric_neg(num));
+ val = get_random_gnc_numeric();
+ }
+ val = gnc_numeric_neg(val);
+ xaccSplitSetValue(s, val);
if (gnc_commodity_equal (xaccTransGetCurrency(trn),
xaccAccountGetCommodity(bcc)) &&
(!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);
}
@@ -1270,10 +1280,10 @@
get_random_split(QofBook *book, Account *acct, Transaction *trn)
{
Split *ret;
- gnc_numeric amt, val;
+ gnc_numeric amt, val, rate;
const gchar *str;
gnc_commodity *com;
- int scu;
+ int scu, denom;
Timespec *ts;
com = xaccTransGetCurrency (trn);
@@ -1295,8 +1305,8 @@
/* Split must be in an account before we can set an amount */
/* and in a transaction before it can be added to an account. */
xaccTransBeginEdit(trn);
- xaccTransAppendSplit(trn, ret);
- xaccAccountInsertSplit (acct, ret);
+ xaccSplitSetParent(ret, trn);
+ xaccSplitSetAccount(ret, acct);
do {
val = get_random_gnc_numeric ();
@@ -1304,7 +1314,7 @@
fprintf(stderr, "get_random_split: Created split with zero value: %p\n", ret);
if (!do_bork())
- val = gnc_numeric_convert (val, scu, GNC_HOW_RND_ROUND);
+ val.denom = scu;
} while (gnc_numeric_check(val) != GNC_ERROR_OK);
xaccSplitSetValue(ret, val);
@@ -1315,11 +1325,18 @@
(!do_bork())) {
amt = val;
} else {
- amt = get_random_gnc_numeric ();
- if (gnc_numeric_negative_p(val) && !gnc_numeric_negative_p(amt))
- amt = gnc_numeric_neg(amt);
+ denom = gnc_commodity_get_fraction(xaccAccountGetCommodity(
+ xaccSplitGetAccount(ret)));
+ 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);
+ if (gnc_numeric_positive_p(val))
+ g_assert(gnc_numeric_positive_p(amt));
xaccSplitSetSlots_nc(ret, get_random_kvp_frame());
xaccTransCommitEdit(trn);
Modified: gnucash/trunk/src/test-core/test-stuff.c
===================================================================
--- gnucash/trunk/src/test-core/test-stuff.c 2006-03-31 00:00:43 UTC (rev 13717)
+++ gnucash/trunk/src/test-core/test-stuff.c 2006-03-31 01:43:16 UTC (rev 13718)
@@ -120,10 +120,7 @@
int
get_rv(void)
{
- if( failures ) {
- return 1;
- }
- return 0;
+ return failures;
}
gboolean
@@ -245,6 +242,20 @@
}
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 *
get_random_string_without(const char *exclude_chars)
{
gchar *ret;
Modified: gnucash/trunk/src/test-core/test-stuff.h
===================================================================
--- gnucash/trunk/src/test-core/test-stuff.h 2006-03-31 00:00:43 UTC (rev 13717)
+++ gnucash/trunk/src/test-core/test-stuff.h 2006-03-31 01:43:16 UTC (rev 13718)
@@ -121,6 +121,7 @@
void random_character_include_funky_chars (gboolean use_funky_chars);
gchar get_random_character(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);
gint64 get_random_gint64(void);
double get_random_double(void);
More information about the gnucash-changes
mailing list