2005-11-02 03:32:36 +00:00
/***************************************************************************
* test - xml - transaction . c
*
* Fri Oct 7 21 : 26 : 59 2005
* Copyright 2005 Neil Williams
* linux @ codehelp . co . uk
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
2005-11-17 05:35:02 +00:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA
* 02110 - 1301 , USA .
2005-11-02 03:32:36 +00:00
*/
2009-12-29 20:12:48 +00:00
2001-08-07 23:29:04 +00:00
# include "config.h"
# include <glib.h>
2007-01-21 16:38:42 +00:00
# include <glib/gstdio.h>
2001-08-07 23:29:04 +00:00
# include <stdlib.h>
# include <unistd.h>
# include <sys/types.h>
# include <dirent.h>
# include <sys/stat.h>
# include "gnc-xml-helper.h"
# include "gnc-xml.h"
2001-09-29 00:08:44 +00:00
# include "gnc-engine.h"
2005-11-02 03:32:36 +00:00
# include "cashobjects.h"
2001-08-07 23:29:04 +00:00
# include "sixtp-parsers.h"
# include "sixtp-dom-parsers.h"
# include "TransLog.h"
# include "io-gncxml-gen.h"
2001-08-18 20:33:51 +00:00
# include "test-stuff.h"
# include "test-engine-stuff.h"
# include "test-file-stuff.h"
2001-08-07 23:29:04 +00:00
2001-12-06 09:30:25 +00:00
# include "AccountP.h"
2001-08-07 23:29:04 +00:00
# include "Transaction.h"
2002-12-28 21:25:58 +00:00
# include "TransactionP.h"
2001-08-07 23:29:04 +00:00
2005-11-02 03:32:36 +00:00
static QofBook * book ;
2001-08-07 23:29:04 +00:00
2001-12-06 09:30:25 +00:00
extern gboolean gnc_transaction_xml_v2_testing ;
2001-08-07 23:29:04 +00:00
static xmlNodePtr
find_appropriate_node ( xmlNodePtr node , Split * spl )
{
xmlNodePtr mark ;
2009-12-29 20:12:48 +00:00
for ( mark = node - > xmlChildrenNode ; mark ; mark = mark - > next )
2001-08-07 23:29:04 +00:00
{
gboolean account_guid_good = FALSE ;
gboolean amount_good = FALSE ;
xmlNodePtr mark2 ;
2009-12-29 20:12:48 +00:00
for ( mark2 = mark - > xmlChildrenNode ; mark2 ; mark2 = mark2 - > next )
2001-08-07 23:29:04 +00:00
{
2009-12-29 20:12:48 +00:00
if ( safe_strcmp ( ( char * ) mark2 - > name , " split:value " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
gnc_numeric * num = dom_tree_to_gnc_numeric ( mark2 ) ;
2009-12-29 20:12:48 +00:00
if ( gnc_numeric_equal ( * num , xaccSplitGetValue ( spl ) ) )
2001-08-07 23:29:04 +00:00
{
amount_good = TRUE ;
}
g_free ( num ) ;
}
2009-12-29 20:12:48 +00:00
else if ( safe_strcmp ( ( char * ) mark2 - > name , " split:account " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
2010-03-27 21:01:21 +00:00
GncGUID * accid = dom_tree_to_guid ( mark2 ) ;
2001-12-06 09:30:25 +00:00
Account * account = xaccSplitGetAccount ( spl ) ;
2001-08-07 23:29:04 +00:00
2009-12-29 20:12:48 +00:00
if ( guid_equal ( accid , xaccAccountGetGUID ( account ) ) )
2001-08-07 23:29:04 +00:00
{
account_guid_good = TRUE ;
}
g_free ( accid ) ;
}
2009-12-29 20:12:48 +00:00
if ( account_guid_good & & amount_good )
2001-08-07 23:29:04 +00:00
{
return mark ;
}
}
}
2009-12-29 20:12:48 +00:00
2001-08-07 23:29:04 +00:00
return NULL ;
}
2002-06-18 21:38:35 +00:00
static char *
2001-08-07 23:29:04 +00:00
equals_node_val_vs_split_internal ( xmlNodePtr node , Split * spl )
{
xmlNodePtr mark ;
2009-12-29 20:12:48 +00:00
for ( mark = node - > children ; mark ! = NULL ; mark = mark - > next )
2001-08-07 23:29:04 +00:00
{
2009-12-29 20:12:48 +00:00
if ( safe_strcmp ( ( char * ) mark - > name , " split:id " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
2010-03-27 21:01:21 +00:00
GncGUID * id = dom_tree_to_guid ( mark ) ;
2001-08-07 23:29:04 +00:00
2009-12-29 20:12:48 +00:00
if ( ! guid_equal ( id , xaccSplitGetGUID ( spl ) ) )
2001-08-07 23:29:04 +00:00
{
g_free ( id ) ;
2002-06-18 21:38:35 +00:00
return " ids differ " ;
2001-08-07 23:29:04 +00:00
}
g_free ( id ) ;
}
2009-12-29 20:12:48 +00:00
else if ( safe_strcmp ( ( char * ) mark - > name , " split:memo " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
char * memo = dom_tree_to_text ( mark ) ;
2009-12-29 20:12:48 +00:00
if ( safe_strcmp ( memo , xaccSplitGetMemo ( spl ) ) ! = 0 )
2001-08-07 23:29:04 +00:00
{
g_free ( memo ) ;
2002-06-18 21:38:35 +00:00
return " memos differ " ;
2001-08-07 23:29:04 +00:00
}
g_free ( memo ) ;
}
2009-12-29 20:12:48 +00:00
else if ( safe_strcmp ( ( char * ) mark - > name , " split:reconciled-state " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
char * rs = dom_tree_to_text ( mark ) ;
2009-12-29 20:12:48 +00:00
if ( rs [ 0 ] ! = xaccSplitGetReconcile ( spl ) )
2001-08-07 23:29:04 +00:00
{
g_free ( rs ) ;
2002-06-18 21:38:35 +00:00
return " states differ " ;
2001-08-07 23:29:04 +00:00
}
g_free ( rs ) ;
}
2009-12-29 20:12:48 +00:00
else if ( safe_strcmp ( ( char * ) mark - > name , " split:value " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
gnc_numeric * num = dom_tree_to_gnc_numeric ( mark ) ;
2003-09-01 15:08:26 +00:00
gnc_numeric val = xaccSplitGetValue ( spl ) ;
2001-08-07 23:29:04 +00:00
2009-12-29 20:12:48 +00:00
if ( ! gnc_numeric_equal ( * num , val ) )
2001-08-07 23:29:04 +00:00
{
g_free ( num ) ;
2005-11-02 03:32:36 +00:00
return g_strdup_printf ( " values differ: % " G_GINT64_FORMAT " /% "
2009-12-29 20:12:48 +00:00
G_GINT64_FORMAT " v % " G_GINT64_FORMAT
" /% " G_GINT64_FORMAT ,
2003-09-01 15:08:26 +00:00
( * num ) . num , ( * num ) . denom ,
val . num , val . denom ) ;
2001-08-07 23:29:04 +00:00
}
g_free ( num ) ;
}
2009-12-29 20:12:48 +00:00
else if ( safe_strcmp ( ( char * ) mark - > name , " split:quantity " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
gnc_numeric * num = dom_tree_to_gnc_numeric ( mark ) ;
2003-09-01 15:08:26 +00:00
gnc_numeric val = xaccSplitGetAmount ( spl ) ;
2001-08-07 23:29:04 +00:00
2009-12-29 20:12:48 +00:00
if ( ! gnc_numeric_equal ( * num , val ) )
{
return g_strdup_printf ( " quantities differ under _equal: % "
G_GINT64_FORMAT " /% " G_GINT64_FORMAT
" v % " G_GINT64_FORMAT " /% "
G_GINT64_FORMAT ,
( * num ) . num , ( * num ) . denom ,
val . num , val . denom ) ;
2002-10-06 22:31:05 +00:00
}
2009-12-29 20:12:48 +00:00
if ( ! gnc_numeric_equal ( * num , val ) )
2001-08-07 23:29:04 +00:00
{
g_free ( num ) ;
2005-11-02 03:32:36 +00:00
return g_strdup_printf ( " quantities differ: % " G_GINT64_FORMAT
2009-12-29 20:12:48 +00:00
" /% " G_GINT64_FORMAT " v % "
G_GINT64_FORMAT " /% " G_GINT64_FORMAT ,
2003-09-01 15:08:26 +00:00
( * num ) . num , ( * num ) . denom ,
val . num , val . denom ) ;
2001-08-07 23:29:04 +00:00
}
g_free ( num ) ;
}
2009-12-29 20:12:48 +00:00
else if ( safe_strcmp ( ( char * ) mark - > name , " split:account " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
2010-03-27 21:01:21 +00:00
GncGUID * id = dom_tree_to_guid ( mark ) ;
2001-12-06 09:30:25 +00:00
Account * account = xaccSplitGetAccount ( spl ) ;
2001-08-07 23:29:04 +00:00
2009-12-29 20:12:48 +00:00
if ( ! guid_equal ( id , xaccAccountGetGUID ( account ) ) )
2001-08-07 23:29:04 +00:00
{
g_free ( id ) ;
2002-06-18 21:38:35 +00:00
return " accounts differ " ;
2001-08-07 23:29:04 +00:00
}
g_free ( id ) ;
}
}
2002-06-18 21:38:35 +00:00
return NULL ;
2001-08-07 23:29:04 +00:00
}
2002-06-18 21:38:35 +00:00
static char *
2001-08-07 23:29:04 +00:00
equals_node_val_vs_splits ( xmlNodePtr node , const Transaction * trn )
{
xmlNodePtr spl_node ;
Split * spl_mark ;
2002-06-18 21:38:35 +00:00
char * msg ;
2001-08-07 23:29:04 +00:00
int i ;
g_return_val_if_fail ( node , FALSE ) ;
g_return_val_if_fail ( node - > xmlChildrenNode , FALSE ) ;
2009-12-29 20:12:48 +00:00
for ( i = 0 , spl_mark = xaccTransGetSplit ( ( Transaction * ) trn , i ) ;
spl_mark ;
i + + , spl_mark = xaccTransGetSplit ( ( Transaction * ) trn , i ) )
2001-08-07 23:29:04 +00:00
{
spl_node = find_appropriate_node ( node , spl_mark ) ;
2009-12-29 20:12:48 +00:00
if ( ! spl_node )
2001-08-07 23:29:04 +00:00
{
2010-11-02 23:07:48 +00:00
g_print ( " Split GUID %s " , guid_to_string ( xaccSplitGetGUID ( spl_mark ) ) ) ;
return " no matching split found " ;
2001-08-07 23:29:04 +00:00
}
2003-09-01 15:08:26 +00:00
msg = equals_node_val_vs_split_internal ( spl_node , spl_mark ) ;
2009-12-29 20:12:48 +00:00
if ( msg ! = NULL )
2001-08-07 23:29:04 +00:00
{
2002-06-18 21:38:35 +00:00
return msg ;
2001-08-07 23:29:04 +00:00
}
}
2009-12-29 20:12:48 +00:00
2002-06-18 21:38:35 +00:00
return NULL ;
2001-08-07 23:29:04 +00:00
}
static gchar *
node_and_transaction_equal ( xmlNodePtr node , Transaction * trn )
{
xmlNodePtr mark ;
2009-12-29 20:12:48 +00:00
2005-11-02 03:32:36 +00:00
while ( safe_strcmp ( ( char * ) node - > name , " text " ) = = 0 )
2009-12-29 20:12:48 +00:00
node = node - > next ;
2001-10-11 11:35:50 +00:00
2009-12-29 20:12:48 +00:00
if ( ! check_dom_tree_version ( node , " 2.0.0 " ) )
2001-08-07 23:29:04 +00:00
{
return " version wrong. Not 2.0.0 or not there " ;
}
2009-12-29 20:12:48 +00:00
if ( ! node - > name | | safe_strcmp ( ( char * ) node - > name , " gnc:transaction " ) )
2001-08-07 23:29:04 +00:00
{
return " Name of toplevel node is bad " ;
}
2009-12-29 20:12:48 +00:00
for ( mark = node - > xmlChildrenNode ; mark ; mark = mark - > next )
2001-08-07 23:29:04 +00:00
{
2009-12-29 20:12:48 +00:00
if ( safe_strcmp ( ( char * ) mark - > name , " text " ) = = 0 )
2001-10-11 11:35:50 +00:00
{
}
2009-12-29 20:12:48 +00:00
else if ( safe_strcmp ( ( char * ) mark - > name , " trn:id " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
2009-12-29 20:12:48 +00:00
if ( ! equals_node_val_vs_guid ( mark , xaccTransGetGUID ( trn ) ) )
2001-08-07 23:29:04 +00:00
{
return " ids differ " ;
}
}
2010-11-02 23:07:48 +00:00
/* This test will fail for many splits where the transaction has
* splits in different commodities - - eg , buying or selling a
* stock . jralls 2010 - 11 - 02 */
2009-12-29 20:12:48 +00:00
else if ( safe_strcmp ( ( char * ) mark - > name , " trn:currency " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
2010-11-02 23:07:48 +00:00
#if 0
2009-12-29 20:12:48 +00:00
if ( ! equals_node_val_vs_commodity (
mark , xaccTransGetCurrency ( trn ) , xaccTransGetBook ( trn ) ) )
2001-08-07 23:29:04 +00:00
{
return g_strdup ( " currencies differ " ) ;
}
2010-11-02 23:07:48 +00:00
# endif
2001-08-07 23:29:04 +00:00
}
2009-12-29 20:12:48 +00:00
else if ( safe_strcmp ( ( char * ) mark - > name , " trn:num " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
2009-12-29 20:12:48 +00:00
if ( ! equals_node_val_vs_string ( mark , xaccTransGetNum ( trn ) ) )
2001-08-07 23:29:04 +00:00
{
return " nums differ " ;
}
}
2009-12-29 20:12:48 +00:00
else if ( safe_strcmp ( ( char * ) mark - > name , " trn:date-posted " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
2009-12-29 20:12:48 +00:00
if ( ! equals_node_val_vs_date ( mark , xaccTransRetDatePostedTS ( trn ) ) )
2001-08-07 23:29:04 +00:00
{
return " posted dates differ " ;
}
}
2009-12-29 20:12:48 +00:00
else if ( safe_strcmp ( ( char * ) mark - > name , " trn:date-entered " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
2009-12-29 20:12:48 +00:00
if ( ! equals_node_val_vs_date ( mark , xaccTransRetDateEnteredTS ( trn ) ) )
2001-08-07 23:29:04 +00:00
{
return " entered dates differ " ;
}
}
2009-12-29 20:12:48 +00:00
else if ( safe_strcmp ( ( char * ) mark - > name , " trn:description " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
2009-12-29 20:12:48 +00:00
if ( ! equals_node_val_vs_string ( mark , xaccTransGetDescription ( trn ) ) )
2001-08-07 23:29:04 +00:00
{
return " descriptions differ " ;
}
}
2009-12-29 20:12:48 +00:00
else if ( safe_strcmp ( ( char * ) mark - > name , " trn:slots " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
2009-12-29 20:12:48 +00:00
if ( ! equals_node_val_vs_kvp_frame ( mark , xaccTransGetSlots ( trn ) ) )
2001-08-07 23:29:04 +00:00
{
return " slots differ " ;
}
}
2009-12-29 20:12:48 +00:00
else if ( safe_strcmp ( ( char * ) mark - > name , " trn:splits " ) = = 0 )
2001-08-07 23:29:04 +00:00
{
2003-09-01 15:08:26 +00:00
char * msg = equals_node_val_vs_splits ( mark , trn ) ;
2009-12-29 20:12:48 +00:00
if ( msg ! = NULL )
2001-08-07 23:29:04 +00:00
{
2003-09-01 15:08:26 +00:00
return msg ;
2001-08-07 23:29:04 +00:00
}
}
else
{
return " unknown node " ;
}
}
2009-12-29 20:12:48 +00:00
2001-08-07 23:29:04 +00:00
return NULL ;
}
static void
really_get_rid_of_transaction ( Transaction * trn )
{
xaccTransBeginEdit ( trn ) ;
xaccTransDestroy ( trn ) ;
xaccTransCommitEdit ( trn ) ;
}
struct tran_data_struct
{
Transaction * trn ;
2001-10-11 11:35:50 +00:00
Transaction * new_trn ;
2001-09-29 00:08:44 +00:00
gnc_commodity * com ;
2001-08-07 23:29:04 +00:00
int value ;
} ;
typedef struct tran_data_struct tran_data ;
static gboolean
test_add_transaction ( const char * tag , gpointer globaldata , gpointer data )
{
2001-09-29 00:08:44 +00:00
Transaction * trans = data ;
2001-08-07 23:29:04 +00:00
tran_data * gdata = ( tran_data * ) globaldata ;
2001-09-29 00:08:44 +00:00
xaccTransBeginEdit ( trans ) ;
xaccTransSetCurrency ( trans , gdata - > com ) ;
xaccTransCommitEdit ( trans ) ;
2003-06-16 03:51:01 +00:00
if ( ! do_test_args ( xaccTransEqual ( gdata - > trn , trans , TRUE , TRUE , TRUE , FALSE ) ,
2003-09-01 15:08:26 +00:00
" gnc_transaction_sixtp_parser_create " ,
__FILE__ , __LINE__ ,
" %d " , gdata - > value ) )
2009-12-29 20:12:48 +00:00
return FALSE ;
2001-09-29 00:08:44 +00:00
2001-10-11 11:35:50 +00:00
gdata - > new_trn = trans ;
2001-09-29 00:08:44 +00:00
2001-08-07 23:29:04 +00:00
return TRUE ;
}
static void
test_transaction ( void )
{
int i ;
2001-10-11 11:35:50 +00:00
2009-12-29 20:12:48 +00:00
for ( i = 0 ; i < 50 ; i + + )
2001-08-07 23:29:04 +00:00
{
Transaction * ran_trn ;
2007-02-23 01:23:31 +00:00
Account * root ;
2001-08-07 23:29:04 +00:00
xmlNodePtr test_node ;
2010-11-02 23:07:48 +00:00
gnc_commodity * com , * new_com ;
2001-09-29 00:08:44 +00:00
gchar * compare_msg ;
2001-08-07 23:29:04 +00:00
gchar * filename1 ;
int fd ;
2009-12-29 20:12:48 +00:00
/* The next line exists for its side effect of creating the
* account tree . */
root = get_random_account_tree ( book ) ;
2001-11-24 12:10:42 +00:00
ran_trn = get_random_transaction ( book ) ;
2010-11-02 23:07:48 +00:00
new_com = get_random_commodity ( book ) ;
2009-12-29 20:12:48 +00:00
if ( ! ran_trn )
2005-11-02 03:32:36 +00:00
{
failure_args ( " transaction_xml " , __FILE__ , __LINE__ ,
" get_random_transaction returned NULL " ) ;
return ;
2009-12-29 20:12:48 +00:00
}
2001-08-07 23:29:04 +00:00
2001-12-06 09:30:25 +00:00
{
2009-12-29 20:12:48 +00:00
/* xaccAccountInsertSplit can reorder the splits. */
GList * list = g_list_copy ( xaccTransGetSplitList ( ran_trn ) ) ;
GList * node = list ;
for ( ; node ; node = node - > next )
{
Split * s = node - > data ;
Account * a = xaccMallocAccount ( book ) ;
xaccAccountBeginEdit ( a ) ;
2010-11-02 23:07:48 +00:00
xaccAccountSetCommodity ( a , new_com ) ;
2009-12-29 20:12:48 +00:00
xaccAccountSetCommoditySCU ( a , xaccSplitGetAmount ( s ) . denom ) ;
xaccAccountInsertSplit ( a , s ) ;
xaccAccountCommitEdit ( a ) ;
}
g_list_free ( list ) ;
2001-12-06 09:30:25 +00:00
}
2001-09-29 00:08:44 +00:00
com = xaccTransGetCurrency ( ran_trn ) ;
2001-08-07 23:29:04 +00:00
test_node = gnc_transaction_dom_tree_create ( ran_trn ) ;
2009-12-29 20:12:48 +00:00
if ( ! test_node )
2001-08-07 23:29:04 +00:00
{
failure_args ( " transaction_xml " , __FILE__ , __LINE__ ,
" gnc_transaction_dom_tree_create returned NULL " ) ;
really_get_rid_of_transaction ( ran_trn ) ;
continue ;
}
2009-12-29 20:12:48 +00:00
if ( ( compare_msg = node_and_transaction_equal ( test_node , ran_trn ) ) ! =
NULL )
2001-08-07 23:29:04 +00:00
{
failure_args ( " transaction_xml " , __FILE__ , __LINE__ ,
" node and transaction were not equal: %s " ,
compare_msg ) ;
xmlElemDump ( stdout , NULL , test_node ) ;
printf ( " \n " ) ;
fflush ( stdout ) ;
xmlFreeNode ( test_node ) ;
really_get_rid_of_transaction ( ran_trn ) ;
continue ;
}
else
{
success_args ( " transaction_xml " , __FILE__ , __LINE__ , " %d " , i ) ;
}
2009-12-29 20:12:48 +00:00
2001-08-07 23:29:04 +00:00
filename1 = g_strdup_printf ( " test_file_XXXXXX " ) ;
2009-12-29 20:12:48 +00:00
2006-11-14 20:58:21 +00:00
fd = g_mkstemp ( filename1 ) ;
2009-12-29 20:12:48 +00:00
2001-08-07 23:29:04 +00:00
write_dom_node_to_file ( test_node , fd ) ;
close ( fd ) ;
2009-12-29 20:12:48 +00:00
2001-12-06 09:30:25 +00:00
{
2009-12-29 20:12:48 +00:00
GList * node = xaccTransGetSplitList ( ran_trn ) ;
for ( ; node ; node = node - > next )
{
Split * s = node - > data ;
Account * a1 = xaccSplitGetAccount ( s ) ;
Account * a2 = xaccMallocAccount ( book ) ;
xaccAccountBeginEdit ( a2 ) ;
xaccAccountSetCommoditySCU ( a2 , xaccAccountGetCommoditySCU ( a1 ) ) ;
xaccAccountSetGUID ( a2 , xaccAccountGetGUID ( a1 ) ) ;
xaccAccountCommitEdit ( a2 ) ;
}
2001-12-06 09:30:25 +00:00
}
2001-08-07 23:29:04 +00:00
{
sixtp * parser ;
tran_data data ;
data . trn = ran_trn ;
2001-09-29 00:08:44 +00:00
data . com = com ;
2001-08-07 23:29:04 +00:00
data . value = i ;
2001-12-06 09:30:25 +00:00
2010-11-02 23:07:48 +00:00
g_print ( " There will follow a bunch of CRIT scrub errors about the account not having a commodity. There isn't an account in the XML, so of course not. Ignore the errors \n " ) ;
2001-08-07 23:29:04 +00:00
parser = gnc_transaction_sixtp_parser_create ( ) ;
2009-12-29 20:12:48 +00:00
if ( ! gnc_xml_parse_file ( parser , filename1 , test_add_transaction ,
( gpointer ) & data , book ) )
2001-08-07 23:29:04 +00:00
{
2009-12-29 20:12:48 +00:00
failure_args ( " gnc_xml_parse_file returned FALSE " ,
2003-09-01 15:08:26 +00:00
__FILE__ , __LINE__ , " %d " , i ) ;
2001-08-07 23:29:04 +00:00
}
2001-10-11 11:35:50 +00:00
else
2009-12-29 20:12:48 +00:00
really_get_rid_of_transaction ( data . new_trn ) ;
2001-08-07 23:29:04 +00:00
/* no handling of circular data structures. We'll do that later */
/* sixtp_destroy(parser); */
}
2007-01-21 16:38:42 +00:00
g_unlink ( filename1 ) ;
2001-08-07 23:29:04 +00:00
g_free ( filename1 ) ;
really_get_rid_of_transaction ( ran_trn ) ;
xmlFreeNode ( test_node ) ;
}
}
static gboolean
test_real_transaction ( const char * tag , gpointer global_data , gpointer data )
{
const char * msg ;
msg = node_and_transaction_equal ( ( xmlNodePtr ) global_data ,
( Transaction * ) data ) ;
do_test_args ( msg = = NULL , " test_real_transaction " ,
__FILE__ , __LINE__ , msg ) ;
really_get_rid_of_transaction ( ( Transaction * ) data ) ;
return TRUE ;
}
2005-11-02 03:32:36 +00:00
int
main ( int argc , char * * argv )
2001-08-07 23:29:04 +00:00
{
2005-11-02 03:32:36 +00:00
qof_init ( ) ;
cashobjects_register ( ) ;
2001-08-07 23:29:04 +00:00
xaccLogDisable ( ) ;
2001-10-03 10:07:45 +00:00
2001-12-06 09:30:25 +00:00
gnc_transaction_xml_v2_testing = TRUE ;
2005-11-02 03:32:36 +00:00
book = qof_book_new ( ) ;
2001-10-03 10:07:45 +00:00
2009-12-29 20:12:48 +00:00
if ( argc > 1 )
2001-08-07 23:29:04 +00:00
{
test_files_in_dir ( argc , argv , test_real_transaction ,
gnc_transaction_sixtp_parser_create ( ) ,
2001-11-24 12:10:42 +00:00
" gnc:transaction " , book ) ;
2001-08-07 23:29:04 +00:00
}
else
{
test_transaction ( ) ;
}
2001-10-03 10:07:45 +00:00
2001-08-07 23:29:04 +00:00
print_test_results ( ) ;
2005-11-02 03:32:36 +00:00
qof_close ( ) ;
2007-01-15 20:28:01 +00:00
exit ( get_rv ( ) ) ;
2001-10-03 10:07:45 +00:00
}