mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-09-03 20:53:02 -05:00
Unit test Transaction.c
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@23139 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
+12
-2
@@ -37,6 +37,8 @@
|
||||
# define g_fopen fopen
|
||||
#endif
|
||||
|
||||
static QofLogModule log_module = "gnc.translog";
|
||||
|
||||
/*
|
||||
* Some design philosphy that I think would be good to keep in mind:
|
||||
* (0) Simplicity and foolproofness are the over-riding design points.
|
||||
@@ -157,7 +159,11 @@ xaccOpenLog (void)
|
||||
char * filename;
|
||||
char * timestamp;
|
||||
|
||||
if (!gen_logs) return;
|
||||
if (!gen_logs)
|
||||
{
|
||||
PINFO ("Attempt to open disabled transaction log");
|
||||
return;
|
||||
}
|
||||
if (trans_log) return;
|
||||
|
||||
if (!log_base_name) log_base_name = g_strdup ("translog");
|
||||
@@ -221,7 +227,11 @@ xaccTransWriteLog (Transaction *trans, char flag)
|
||||
char dnow[100], dent[100], dpost[100], drecn[100];
|
||||
Timespec ts;
|
||||
|
||||
if (!gen_logs) return;
|
||||
if (!gen_logs)
|
||||
{
|
||||
PINFO ("Attempt to write disabled transaction log");
|
||||
return;
|
||||
}
|
||||
if (!trans_log) return;
|
||||
|
||||
timespecFromTime64(&ts, gnc_time (NULL));
|
||||
|
||||
@@ -234,7 +234,6 @@ void mark_trans (Transaction *trans)
|
||||
G_INLINE_FUNC void gen_event_trans (Transaction *trans);
|
||||
void gen_event_trans (Transaction *trans)
|
||||
{
|
||||
#ifndef REGISTER_STILL_DEPENDS_ON_ACCOUNT_EVENTS
|
||||
GList *node;
|
||||
|
||||
for (node = trans->splits; node; node = node->next)
|
||||
@@ -251,7 +250,6 @@ void gen_event_trans (Transaction *trans)
|
||||
qof_event_gen (QOF_INSTANCE(lot), QOF_EVENT_MODIFY, NULL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* GObject Initialization */
|
||||
@@ -1576,11 +1574,26 @@ xaccTransRollbackEdit (Transaction *trans)
|
||||
Transaction *orig;
|
||||
GList *slist;
|
||||
int num_preexist, i;
|
||||
|
||||
/* FIXME: This isn't quite the right way to handle nested edits --
|
||||
* there should be a stack of transaction states that are popped off
|
||||
* and restored at each level -- but it does prevent restoring to the
|
||||
* editlevel 0 state until one is returning to editlevel 0, and
|
||||
* thereby prevents a crash caused by trans->orig getting NULLed too
|
||||
* soon.
|
||||
*/
|
||||
if (!qof_instance_get_editlevel (QOF_INSTANCE (trans))) return;
|
||||
if (qof_instance_get_editlevel (QOF_INSTANCE (trans)) > 1) {
|
||||
qof_instance_decrease_editlevel (QOF_INSTANCE (trans));
|
||||
return;
|
||||
}
|
||||
|
||||
ENTER ("trans addr=%p\n", trans);
|
||||
|
||||
check_open(trans);
|
||||
|
||||
/* copy the original values back in. */
|
||||
|
||||
orig = trans->orig;
|
||||
SWAP(trans->num, orig->num);
|
||||
SWAP(trans->description, orig->description);
|
||||
@@ -2716,5 +2729,22 @@ gboolean xaccTransRegister (void)
|
||||
return qof_object_register (&trans_object_def);
|
||||
}
|
||||
|
||||
TransTestFunctions*
|
||||
_utest_trans_fill_functions (void)
|
||||
{
|
||||
TransTestFunctions *func = g_new (TransTestFunctions, 1);
|
||||
|
||||
func->mark_trans = mark_trans;
|
||||
func->gen_event_trans = gen_event_trans;
|
||||
func->xaccFreeTransaction = xaccFreeTransaction;
|
||||
func->destroy_gains = destroy_gains;
|
||||
func->do_destroy = do_destroy;
|
||||
func->was_trans_emptied = was_trans_emptied;
|
||||
func->trans_on_error = trans_on_error;
|
||||
func->trans_cleanup_commit = trans_cleanup_commit;
|
||||
func->xaccTransScrubGainsDate = xaccTransScrubGainsDate;
|
||||
return func;
|
||||
}
|
||||
|
||||
/************************ END OF ************************************\
|
||||
\************************* FILE *************************************/
|
||||
|
||||
@@ -174,6 +174,23 @@ void xaccDisableDataScrubbing(void);
|
||||
void xaccTransRemoveSplit (Transaction *trans, const Split *split);
|
||||
void check_open (const Transaction *trans);
|
||||
|
||||
/* Structure for accessing static functions for testing */
|
||||
typedef struct
|
||||
{
|
||||
void (*mark_trans)(Transaction*);
|
||||
void (*gen_event_trans)(Transaction*);
|
||||
void (*xaccFreeTransaction)(Transaction*);
|
||||
void (*destroy_gains)(Transaction*);
|
||||
void (*do_destroy)(Transaction*);
|
||||
gboolean (*was_trans_emptied)(Transaction*);
|
||||
void (*trans_on_error)(Transaction*, QofBackendError);
|
||||
void (*trans_cleanup_commit)(Transaction*);
|
||||
void (*xaccTransScrubGainsDate)(Transaction*);
|
||||
|
||||
} TransTestFunctions;
|
||||
|
||||
TransTestFunctions* _utest_trans_fill_functions (void);
|
||||
|
||||
/*@}*/
|
||||
|
||||
|
||||
|
||||
@@ -118,8 +118,8 @@ test_engine_SOURCES = \
|
||||
|
||||
test_engine_LDADD = \
|
||||
libutest-Split.la \
|
||||
libutest-Trans.la \
|
||||
$(LDADD)
|
||||
|
||||
test_engine_CFLAGS = \
|
||||
${DEFAULT_INCLUDES} \
|
||||
-I${top_srcdir}/${MODULEPATH}/ \
|
||||
@@ -127,14 +127,22 @@ test_engine_CFLAGS = \
|
||||
${GLIB_CFLAGS}
|
||||
|
||||
noinst_LTLIBRARIES = \
|
||||
libutest-Split.la
|
||||
libutest-Split.la \
|
||||
libutest-Trans.la
|
||||
|
||||
libutest_Split_la_SOURCES = \
|
||||
utest-Split.c \
|
||||
${top_srcdir}/src/libqof/qof/gnc-numeric.c
|
||||
|
||||
|
||||
libutest_Split_la_LIBADD = $(LDADD)
|
||||
|
||||
libutest_Trans_la_SOURCES = \
|
||||
utest-Transaction.c
|
||||
|
||||
libutest_Trans_la_LIBADD = $(LDADD)
|
||||
|
||||
|
||||
clean-local:
|
||||
rm -f translog.*
|
||||
|
||||
|
||||
@@ -21,14 +21,15 @@
|
||||
\********************************************************************/
|
||||
|
||||
|
||||
#include "config.h"
|
||||
#include <config.h>
|
||||
#include <glib.h>
|
||||
#include "qof.h"
|
||||
#include <qof.h>
|
||||
#include <TransLog.h>
|
||||
|
||||
extern void test_suite_account();
|
||||
extern void test_suite_budget();
|
||||
extern void test_suite_gncInvoice();
|
||||
//extern void test_suite_transaction();
|
||||
extern void test_suite_transaction();
|
||||
extern void test_suite_split();
|
||||
|
||||
int
|
||||
@@ -40,11 +41,13 @@ main (int argc,
|
||||
g_test_init ( &argc, &argv, NULL ); /* initialize test program */
|
||||
//qof_log_set_level("gnc", G_LOG_LEVEL_DEBUG);
|
||||
g_test_bug_base("https://bugzilla.gnome.org/show_bug.cgi?id="); /* init the bugzilla URL */
|
||||
/* Disable the transaction log */
|
||||
xaccLogDisable();
|
||||
|
||||
test_suite_account();
|
||||
test_suite_budget();
|
||||
test_suite_gncInvoice();
|
||||
// test_suite_transaction();
|
||||
test_suite_transaction();
|
||||
test_suite_split();
|
||||
|
||||
return g_test_run( );
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -47,6 +47,7 @@ test_error_struct_new (gchar *log_domain, GLogLevelFlags log_level, gchar *msg)
|
||||
err->log_domain = g_strdup (log_domain);
|
||||
err->log_level = log_level;
|
||||
err->msg = g_strdup (msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -176,7 +177,7 @@ gboolean
|
||||
test_list_nohit_handler (const char *log_domain, GLogLevelFlags log_level,
|
||||
const gchar *msg, gpointer user_data)
|
||||
{
|
||||
return do_test_list_handler (log_domain, log_level, msg, user_data, TRUE);
|
||||
return do_test_list_handler (log_domain, log_level, msg, user_data, FALSE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -207,14 +208,16 @@ gboolean
|
||||
test_checked_handler (const char *log_domain, GLogLevelFlags log_level,
|
||||
const gchar *msg, gpointer user_data )
|
||||
{
|
||||
do_test_checked_handler (log_domain, log_level, msg, user_data, TRUE);
|
||||
return do_test_checked_handler (log_domain, log_level, msg,
|
||||
user_data, TRUE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
test_checked_nohit_handler (const char *log_domain, GLogLevelFlags log_level,
|
||||
const gchar *msg, gpointer user_data )
|
||||
{
|
||||
do_test_checked_handler (log_domain, log_level, msg, user_data, FALSE);
|
||||
return do_test_checked_handler (log_domain, log_level, msg,
|
||||
user_data, FALSE);
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
||||
Reference in New Issue
Block a user