mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
2001-10-13 Dave Peticolas <dave@krondo.com>
* src/guile/Makefile.am (libgncguile_la_LIBADD): remove gncgnome.la dependency * src/engine/test-core/test-engine-stuff.c (get_random_timespec): add flag to always set nsec to 0. (get_random_transaction_with_currency): new func (add_random_transactions_to_session): new func * src/backend/postgres/test/db-control.sh: add 'connect' argument to start psql connection * src/backend/postgres/test/test-db.c: add random transactions to the mix * src/backend/postgres/account.c (pgendStoreAccountNoLock): expound on commodity table comment git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5596 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
df8bb66f5d
commit
4d915c5e8c
19
ChangeLog
19
ChangeLog
@ -1,3 +1,22 @@
|
||||
2001-10-13 Dave Peticolas <dave@krondo.com>
|
||||
|
||||
* src/guile/Makefile.am (libgncguile_la_LIBADD): remove gncgnome.la
|
||||
dependency
|
||||
|
||||
* src/engine/test-core/test-engine-stuff.c (get_random_timespec):
|
||||
add flag to always set nsec to 0.
|
||||
(get_random_transaction_with_currency): new func
|
||||
(add_random_transactions_to_session): new func
|
||||
|
||||
* src/backend/postgres/test/db-control.sh: add 'connect' argument
|
||||
to start psql connection
|
||||
|
||||
* src/backend/postgres/test/test-db.c: add random transactions
|
||||
to the mix
|
||||
|
||||
* src/backend/postgres/account.c (pgendStoreAccountNoLock): expound
|
||||
on commodity table comment
|
||||
|
||||
2001-10-12 Rob Browning <rlb@defaultvalue.org>
|
||||
|
||||
* configure.in (GNC_ADD_ON_SRFIS): compute needed SRFIs.
|
||||
|
@ -118,8 +118,13 @@ pgendStoreAccountNoLock (PGBackend *be, Account *acct,
|
||||
pgendPutOneAccountOnly (be, acct);
|
||||
|
||||
/* make sure the account's commodity is in the commodity table */
|
||||
|
||||
/* XXX hack alert FIXME -- it would be more efficient to do
|
||||
* this elsewhere, and not here. Or put a mark on it ...
|
||||
* this elsewhere, and not here. Furthermore, with this method
|
||||
* the transaction currencies must be stored in the same way,
|
||||
* as the transactions are traversed individually, and that
|
||||
* is even more inefficient.
|
||||
*
|
||||
* See StoreAllPrices for an example of how to do this.
|
||||
*/
|
||||
com = xaccAccountGetCommodity (acct);
|
||||
|
@ -4,6 +4,8 @@ EXIT_VALUE=0
|
||||
|
||||
DB=$PWD/gnc_test
|
||||
|
||||
PG_CTL="pg_ctl -D $DB -o -p7777"
|
||||
|
||||
case $1 in
|
||||
create)
|
||||
rm -rf $DB
|
||||
@ -13,10 +15,14 @@ case $1 in
|
||||
rm -rf $DB
|
||||
;;
|
||||
start)
|
||||
pg_ctl -D $DB -o "-p 7777" start
|
||||
$PG_CTL start
|
||||
;;
|
||||
stop)
|
||||
pg_ctl -D $DB -o "-p 7777" stop
|
||||
$PG_CTL stop
|
||||
;;
|
||||
connect)
|
||||
$PG_CTL status | grep "not running" && $PG_CTL start && sleep 1
|
||||
psql -p 7777 gnc_test
|
||||
;;
|
||||
*)
|
||||
echo "Bad command: $1"
|
||||
|
@ -62,6 +62,9 @@ run_test (void)
|
||||
|
||||
session = get_random_session ();
|
||||
|
||||
add_random_transactions_to_session (session,
|
||||
get_random_int_in_range (1, 20));
|
||||
|
||||
filename = g_strdup ("postgres://localhost:7777/gnc_test?mode=single-file");
|
||||
|
||||
gnc_session_begin (session, filename, FALSE, TRUE);
|
||||
@ -116,6 +119,8 @@ guile_main (int argc, char **argv)
|
||||
gnc_module_system_init ();
|
||||
gnc_module_load ("gnucash/engine", 0);
|
||||
|
||||
g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
|
||||
|
||||
glist_exclude_type (KVP_TYPE_BINARY);
|
||||
glist_exclude_type (KVP_TYPE_GLIST);
|
||||
|
||||
@ -129,6 +134,8 @@ guile_main (int argc, char **argv)
|
||||
set_max_group_depth (3);
|
||||
set_max_group_accounts (5);
|
||||
|
||||
random_timespec_zero_nsec (TRUE);
|
||||
|
||||
xaccLogDisable ();
|
||||
|
||||
run_test ();
|
||||
|
@ -88,6 +88,14 @@ random_glist_strings_only (gboolean strings_only)
|
||||
glist_strings_only = strings_only;
|
||||
}
|
||||
|
||||
static gboolean zero_nsec = FALSE;
|
||||
|
||||
void
|
||||
random_timespec_zero_nsec (gboolean zero_nsec_in)
|
||||
{
|
||||
zero_nsec = zero_nsec_in;
|
||||
}
|
||||
|
||||
Timespec*
|
||||
get_random_timespec(void)
|
||||
{
|
||||
@ -96,7 +104,7 @@ get_random_timespec(void)
|
||||
ret = g_new(Timespec, 1);
|
||||
|
||||
ret->tv_sec = rand();
|
||||
ret->tv_nsec = rand();
|
||||
ret->tv_nsec = zero_nsec ? 0 : rand();
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -567,8 +575,9 @@ trn_add_ran_timespec(Transaction *trn, void (*func)(Transaction*,
|
||||
}
|
||||
|
||||
|
||||
Transaction*
|
||||
get_random_transaction(GNCSession *session)
|
||||
Transaction *
|
||||
get_random_transaction_with_currency(GNCSession *session,
|
||||
gnc_commodity *currency)
|
||||
{
|
||||
Transaction* ret;
|
||||
|
||||
@ -576,7 +585,9 @@ get_random_transaction(GNCSession *session)
|
||||
|
||||
xaccTransBeginEdit(ret);
|
||||
|
||||
xaccTransSetCurrency(ret, get_random_commodity (session));
|
||||
xaccTransSetCurrency (ret,
|
||||
currency ? currency :
|
||||
get_random_commodity (session));
|
||||
|
||||
set_tran_random_string(ret, xaccTransSetNum);
|
||||
|
||||
@ -594,6 +605,55 @@ get_random_transaction(GNCSession *session)
|
||||
return ret;
|
||||
}
|
||||
|
||||
Transaction*
|
||||
get_random_transaction (GNCSession *session)
|
||||
{
|
||||
return get_random_transaction_with_currency (session, NULL);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
get_random_list_element (GList *list)
|
||||
{
|
||||
g_return_val_if_fail (list, NULL);
|
||||
|
||||
return g_list_nth_data (list,
|
||||
get_random_int_in_range (0,
|
||||
g_list_length (list) - 1));
|
||||
}
|
||||
|
||||
static gnc_commodity *
|
||||
get_random_commodity_from_table (gnc_commodity_table *table)
|
||||
{
|
||||
GList *namespaces;
|
||||
gnc_commodity *com = NULL;
|
||||
|
||||
g_return_val_if_fail (table, NULL);
|
||||
|
||||
namespaces = gnc_commodity_table_get_namespaces (table);
|
||||
|
||||
do
|
||||
{
|
||||
GList *commodities;
|
||||
char *namespace;
|
||||
|
||||
namespace = get_random_list_element (namespaces);
|
||||
|
||||
commodities = gnc_commodity_table_get_commodities (table, namespace);
|
||||
if (!commodities)
|
||||
continue;
|
||||
|
||||
com = get_random_list_element (commodities);
|
||||
|
||||
g_list_free (commodities);
|
||||
|
||||
} while (!com);
|
||||
|
||||
|
||||
g_list_free (namespaces);
|
||||
|
||||
return com;
|
||||
}
|
||||
|
||||
gnc_commodity*
|
||||
get_random_commodity (GNCSession *session)
|
||||
{
|
||||
@ -605,11 +665,18 @@ get_random_commodity (GNCSession *session)
|
||||
int ran_int;
|
||||
gnc_commodity_table *table;
|
||||
|
||||
table = gnc_book_get_commodity_table (gnc_session_get_book (session));
|
||||
|
||||
#if 0
|
||||
if (table &&
|
||||
(gnc_commodity_table_get_size (table) > 0) &&
|
||||
get_random_int_in_range (1, 5) < 5)
|
||||
return get_random_commodity_from_table (table);
|
||||
#endif
|
||||
|
||||
mn = get_random_string();
|
||||
space = get_random_commodity_namespace();
|
||||
|
||||
table = gnc_book_get_commodity_table (gnc_session_get_book (session));
|
||||
|
||||
if (table)
|
||||
{
|
||||
ret = gnc_commodity_table_lookup (table, space, mn);
|
||||
@ -852,3 +919,52 @@ get_random_session (void)
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
void
|
||||
add_random_transactions_to_session (GNCSession *session, gint num_transactions)
|
||||
{
|
||||
gnc_commodity_table *table;
|
||||
GList *accounts;
|
||||
gint num_accounts;
|
||||
GNCBook *book;
|
||||
|
||||
if (num_transactions <= 0) return;
|
||||
|
||||
g_return_if_fail (session);
|
||||
|
||||
book = gnc_session_get_book (session);
|
||||
|
||||
accounts = xaccGroupGetSubAccounts (gnc_book_get_group (book));
|
||||
|
||||
g_return_if_fail (accounts);
|
||||
|
||||
num_accounts = g_list_length (accounts);
|
||||
|
||||
table = gnc_book_get_commodity_table (gnc_session_get_book (session));
|
||||
|
||||
while (num_transactions--)
|
||||
{
|
||||
gnc_commodity *com;
|
||||
Transaction *trans;
|
||||
Account *account;
|
||||
Split *split;
|
||||
|
||||
com = get_random_commodity_from_table (table);
|
||||
|
||||
trans = get_random_transaction_with_currency (session, com);
|
||||
|
||||
xaccTransBeginEdit (trans);
|
||||
|
||||
split = xaccTransGetSplit (trans, 0);
|
||||
account = get_random_list_element (accounts);
|
||||
xaccAccountInsertSplit (account, split);
|
||||
|
||||
split = xaccTransGetSplit (trans, 1);
|
||||
account = get_random_list_element (accounts);
|
||||
xaccAccountInsertSplit (account, split);
|
||||
|
||||
xaccTransCommitEdit (trans);
|
||||
}
|
||||
|
||||
g_list_free (accounts);
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include "gnc-pricedb.h"
|
||||
|
||||
Timespec* get_random_timespec(void);
|
||||
void random_timespec_zero_nsec (gboolean zero_nsec);
|
||||
|
||||
kvp_value* get_random_kvp_value(int type);
|
||||
|
||||
typedef struct
|
||||
@ -44,6 +46,8 @@ AccountGroup * get_random_group(GNCSession * session);
|
||||
Account* get_random_account(GNCSession * session);
|
||||
Split* get_random_split(GNCSession *session, gnc_numeric num);
|
||||
Transaction* get_random_transaction(GNCSession *session);
|
||||
Transaction* get_random_transaction_with_currency(GNCSession *session,
|
||||
gnc_commodity *currency);
|
||||
gnc_commodity* get_random_commodity(GNCSession *session);
|
||||
const char *get_random_commodity_namespace(void);
|
||||
|
||||
@ -52,4 +56,7 @@ Query* get_random_query(void);
|
||||
GNCBook * get_random_book (GNCSession *session);
|
||||
GNCSession * get_random_session (void);
|
||||
|
||||
void add_random_transactions_to_session (GNCSession *session,
|
||||
gint num_transactions);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user