[Gnucash-changes] r12202 - gnucash/trunk/src/engine/test-core -
Minor improvements to engine testing infrastructure
Chris Shoemaker
chris at cvs.gnucash.org
Thu Dec 29 23:36:39 EST 2005
Author: chris
Date: 2005-12-29 23:36:38 -0500 (Thu, 29 Dec 2005)
New Revision: 12202
Trac: http://svn.gnucash.org/trac/changeset/12202
Added:
gnucash/trunk/src/engine/test-core/test-engine-strings.h
Modified:
gnucash/trunk/src/engine/test-core/Makefile.am
gnucash/trunk/src/engine/test-core/test-engine-stuff.c
Log:
Minor improvements to engine testing infrastructure
* add some arrays of realistic string values for various
Account and Transaction fields
* use the arrays to generate slightly more human-readable
random books
* pull some hardcoded constants out into static knobs
* wrap Transaction creation in begin/commit
Modified: gnucash/trunk/src/engine/test-core/Makefile.am
===================================================================
--- gnucash/trunk/src/engine/test-core/Makefile.am 2005-12-30 03:34:22 UTC (rev 12201)
+++ gnucash/trunk/src/engine/test-core/Makefile.am 2005-12-30 04:36:38 UTC (rev 12202)
@@ -19,7 +19,7 @@
${QOF_LIBS} \
${GLIB_LIBS}
-noinst_HEADERS=test-engine-stuff.h
+noinst_HEADERS=test-engine-stuff.h test-engine-strings.h
AM_CFLAGS = \
-I${top_srcdir}/src \
Added: gnucash/trunk/src/engine/test-core/test-engine-strings.h
===================================================================
--- gnucash/trunk/src/engine/test-core/test-engine-strings.h 2005-12-30 03:34:22 UTC (rev 12201)
+++ gnucash/trunk/src/engine/test-core/test-engine-strings.h 2005-12-30 04:36:38 UTC (rev 12202)
@@ -0,0 +1,170 @@
+
+static const gchar* sane_account_names[] = {
+ "Bank CD",
+ "Brokerage Account",
+ "Bond",
+ "Stock",
+ "Market Index",
+ "Mutual Fund",
+ "Checking Account",
+ "Money Market",
+ "Retirement",
+ "Bond",
+ "Stock",
+ "Market Index",
+ "Mutual Fund",
+ "Savings Account",
+ "Spouse Retirement",
+ "Bond",
+ "Stock",
+ "Market Index",
+ "Mutual Fund",
+ "Currency Trading",
+ "Cash in Wallet",
+ "House",
+ "Other Asset",
+ "Vehicle",
+ "Credit Card",
+ "Line of Credit",
+ "Education Loan",
+ "Mortgage Loan",
+ "Other Loan",
+ "Vehicle Loan",
+ "Bonus",
+ "Dividend Income",
+ "Gifts Received",
+ "Interest Income",
+ "Bond Interest",
+ "CD Interest",
+ "Checking Interest",
+ "Money Market Interest",
+ "Other Interest",
+ "Savings Interest",
+ "Other Income",
+ "Salary",
+ "Salary (Spouse)",
+ "Adjustment",
+ "Auto",
+ "Fees",
+ "Gas",
+ "Parking",
+ "Repair and Maintenance",
+ "Bank Service Charge",
+ "Books",
+ "Cable",
+ "Charity",
+ "Childcare",
+ "Clothes",
+ "Commissions",
+ "Computer",
+ "Dining",
+ "Education",
+ "Entertainment",
+ "Music/Movies",
+ "Recreation",
+ "Travel",
+ "Gifts",
+ "Groceries",
+ "Hobbies",
+ "Home Repair",
+ "Insurance",
+ "Auto Insurance",
+ "Health Insurance",
+ "Home Insurance",
+ "Life Insurance",
+ "Rental Insurance",
+ "Interest",
+ "Education Loan Interest",
+ "Mortgage Interest",
+ "Other Interest",
+ "Vehicle Loan Interest",
+ "Laundry/Dry Cleaning",
+ "Medical Expenses",
+ "Miscellaneous",
+ "Online Services",
+ "Phone",
+ "Public Transportation",
+ "Rent",
+ "Subscriptions",
+ "Supplies",
+ "Taxes",
+ "Federal",
+ "Medicare",
+ "Other Tax",
+ "Property Tax",
+ "Social Security",
+ "State/Province",
+ "Taxes (Spouse)",
+ "Federal",
+ "Medicare",
+ "Other Tax",
+ "Social Security",
+ "State/Province",
+ "Utilities",
+ "Electric",
+ "Garbage collection",
+ "Gas",
+ "Water",
+ "Opening Balances",
+ NULL,
+};
+
+static const gchar* sane_descriptions[] = {
+ "401k Income",
+ "401k match 50%",
+ "Cap. gain (long)",
+ "Cap. gain (short)",
+ "Car Repair",
+ "Charity",
+ "Child Care",
+ "Credit Card Refund",
+ "Dividends",
+ "Fed Est Tax",
+ "Fed Tax Witholding",
+ "Insurance Rembersal",
+ "Interect Earned",
+ "Interest Earned",
+ "Investment Interest",
+ "IRA Contrib, non Deductable",
+ "IRA Contrib, Non work Spouse",
+ "IRA Contrib, Spouse",
+ "IRA Contribution",
+ "IRA Management Fee",
+ "Job One",
+ "Job Two",
+ "Medical, Dental",
+ "Medicare",
+ "Medicine",
+ "Mortgage Interest",
+ "Opening Balance",
+ "Pointe Paid",
+ "Real Estate Tax",
+ "Soc Sec",
+ "State and Local",
+ "test dup ",
+ "Unemployment Comp",
+ NULL,
+};
+
+static const gchar* sane_actions[] = {
+ "Dep",
+ "Wthdrw",
+ "Check",
+ "Int",
+ "Div",
+ "ATM",
+ "Teller",
+ "POS",
+ "Phone",
+ "Online",
+ "AutoDep",
+ "Wire",
+ "EFT",
+ "Credit",
+ "Refund",
+ "Rebate",
+ "Xfer",
+ "DDebit",
+ NULL,
+};
+
Modified: gnucash/trunk/src/engine/test-core/test-engine-stuff.c
===================================================================
--- gnucash/trunk/src/engine/test-core/test-engine-stuff.c 2005-12-30 03:34:22 UTC (rev 12201)
+++ gnucash/trunk/src/engine/test-core/test-engine-stuff.c 2005-12-30 04:36:38 UTC (rev 12202)
@@ -37,6 +37,7 @@
#include "test-engine-stuff.h"
#include "test-stuff.h"
+#include "test-engine-strings.h"
static gboolean glist_strings_only = FALSE;
@@ -44,10 +45,14 @@
static gint kvp_max_depth = 5;
static gint kvp_frame_max_elements = 10;
-static gint max_group_depth = 4;
-static gint max_group_accounts = 10;
-static gint max_total_accounts = 1000;
+static gint max_group_depth = 1;
+static gint max_group_accounts = 3;
+static gint max_total_accounts = 10;
+static gint max_trans_num = 1000;
static gint total_num_accounts = 0;
+/* SCU == smallest currency unit -- the value of the denominator */
+static gint max_scu = 100; //6000;
+static gint min_scu = 100; //1;
/* The inverse fraction of split/transaction data that should
@@ -548,9 +553,7 @@
name = get_random_string();
xcode = get_random_string();
- /* SCU == smallest currency unit -- the value of the denominator */
-#define MAX_SCU 6000
- ran_int = get_random_int_in_range(1, MAX_SCU);
+ ran_int = get_random_int_in_range(min_scu, max_scu);
ret = gnc_commodity_new (book, name, space, mn, xcode, ran_int);
@@ -810,6 +813,17 @@
}
static void
+set_account_random_string_from_array(
+ Account* act, void(*func)(Account *act, const gchar*str),
+ const gchar *list[])
+{
+ const gchar *tmp_str = get_random_string_in_array(list);
+ if(tmp_str)
+ (func)(act, tmp_str);
+
+}
+
+static void
account_add_subaccounts (QofBook *book, Account *account, int depth)
{
int num_accounts;
@@ -912,10 +926,10 @@
scu = gnc_commodity_get_fraction(com);
num = get_random_gnc_numeric();
- if (!do_bork()) num = gnc_numeric_convert (num, scu, GNC_HOW_RND_ROUND);
-
acc = get_random_list_element (account_list);
+ xaccTransBeginEdit(trn);
s = get_random_split(book, acc, trn);
+ if (!do_bork()) num = gnc_numeric_convert (num, scu, GNC_HOW_RND_ROUND);
xaccSplitSetValue(s, num);
/* If the currencies are the same, the split amount should equal
@@ -959,6 +973,7 @@
}
if (do_bork()) xaccAccountRemoveSplit (s->acc, s);
+ xaccTransCommitEdit(trn);
}
typedef struct
@@ -1200,7 +1215,8 @@
xaccAccountBeginEdit(ret);
- set_account_random_string(ret, xaccAccountSetName);
+ set_account_random_string_from_array(ret, xaccAccountSetName,
+ sane_account_names);
tmp_int = get_random_int_in_range(BANK, NUM_ACCOUNT_TYPES - 1);
xaccAccountSetType(ret, tmp_int);
@@ -1268,11 +1284,14 @@
{
Split *ret;
gnc_numeric num;
+ const gchar *str;
ret = xaccMallocSplit(book);
- set_split_random_string(ret, xaccSplitSetMemo);
- set_split_random_string(ret, xaccSplitSetAction);
+ str = get_random_string_in_array(sane_descriptions);
+ xaccSplitSetMemo(ret, str);
+ str = get_random_string_in_array(sane_actions);
+ xaccSplitSetAction(ret, str);
xaccSplitSetReconcile(ret, possible_chars[get_random_int_in_range(0, 3)]);
@@ -1280,6 +1299,7 @@
/* 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);
num = get_random_gnc_numeric ();
@@ -1288,7 +1308,11 @@
if (num.num == 0)
fprintf(stderr, "get_random_split: Created split with zero amount: %p\n", ret);
+ num = get_random_gnc_numeric ();
+ xaccSplitSetValue(ret, num);
+
xaccSplitSetSlots_nc(ret, get_random_kvp_frame());
+ xaccTransCommitEdit(trn);
return ret;
}
@@ -1336,6 +1360,17 @@
}
static void
+set_tran_random_string_from_array(
+ Transaction* trn, void(*func)(Transaction *trn, const gchar*str),
+ const gchar *list[])
+{
+ const gchar *tmp_str = get_random_string_in_array(list);
+ if(tmp_str)
+ (func)(trn, tmp_str);
+}
+
+
+static void
trn_add_ran_timespec(Transaction *trn, void (*func)(Transaction*,
const Timespec*))
{
@@ -1352,8 +1387,10 @@
gnc_commodity *currency,
GList *account_list)
{
- Transaction* ret;
+ Transaction* trans;
KvpFrame *f;
+ gint num;
+ gchar *numstr;
if (!account_list)
{
@@ -1363,40 +1400,43 @@
/* Gotta have at least two different accounts */
if (1 >= g_list_length (account_list)) return NULL;
- ret = xaccMallocTransaction(book);
+ trans = xaccMallocTransaction(book);
- xaccTransBeginEdit(ret);
+ xaccTransBeginEdit(trans);
- xaccTransSetCurrency (ret,
+ xaccTransSetCurrency (trans,
currency ? currency :
get_random_commodity (book));
- set_tran_random_string(ret, xaccTransSetNum);
- set_tran_random_string(ret, xaccTransSetDescription);
- trn_add_ran_timespec(ret, xaccTransSetDatePostedTS);
- trn_add_ran_timespec(ret, xaccTransSetDateEnteredTS);
+ num = get_random_int_in_range (1, max_trans_num);
+ numstr = g_strdup_printf("%d", num);
+ xaccTransSetNum(trans, numstr);
+ set_tran_random_string_from_array(trans, xaccTransSetDescription,
+ sane_descriptions);
+ trn_add_ran_timespec(trans, xaccTransSetDatePostedTS);
+ trn_add_ran_timespec(trans, xaccTransSetDateEnteredTS);
f = get_random_kvp_frame();
- xaccTransSetSlots_nc(ret, f);
+ xaccTransSetSlots_nc(trans, f);
- add_random_splits(book, ret, account_list);
+ add_random_splits(book, trans, account_list);
if (get_random_int_in_range (1, 10) == 1)
{
char *reason = get_random_string ();
- xaccTransVoid (ret, reason);
+ xaccTransVoid (trans, reason);
g_free (reason);
}
- xaccTransCommitEdit(ret);
- if(!ret)
+ xaccTransCommitEdit(trans);
+ if (!trans)
{
failure_args("engine-stuff", __FILE__, __LINE__,
"get_random_transaction_with_currency failed");
return NULL;
}
- return ret;
+ return trans;
}
Transaction*
@@ -1802,18 +1842,14 @@
{
gnc_commodity_table *table;
GList *accounts;
- gint num_accounts;
if (num_transactions <= 0) return;
g_return_if_fail (book);
accounts = xaccGroupGetSubAccounts (xaccGetAccountGroup (book));
-
g_return_if_fail (accounts);
- num_accounts = g_list_length (accounts);
-
table = gnc_commodity_table_get_table (book);
while (num_transactions--)
More information about the gnucash-changes
mailing list