28 #include <glib/gstdio.h>
32 #include "../gnc-xml-helper.h"
33 #include "../gnc-xml.h"
35 #include <cashobjects.h>
36 #include "../sixtp-parsers.h"
37 #include "../sixtp-dom-parsers.h"
39 #include <test-stuff.h>
41 #include <test-file-stuff.h>
42 #include <unittest-support.h>
50 node_and_account_equal(xmlNodePtr node,
Account *act)
54 while (g_strcmp0 ((
char*)node->name,
"text") == 0)
59 if (!check_dom_tree_version(node,
"2.0.0"))
61 return g_strdup(
"version wrong. Not 2.0.0 or not there");
64 if (!node->name || g_strcmp0((
char*)node->name,
"gnc:account"))
66 return g_strdup(
"Name of toplevel node is bad");
69 for (mark = node->xmlChildrenNode; mark; mark = mark->next)
71 if (g_strcmp0((
char*)mark->name,
"text") == 0)
74 else if (g_strcmp0((
char*)mark->name,
"act:name") == 0)
78 return g_strdup(
"names differ");
81 else if (g_strcmp0((
char*)mark->name,
"act:id") == 0)
85 return g_strdup(
"ids differ");
88 else if (g_strcmp0((
char*)mark->name,
"act:type") == 0)
93 txt = dom_tree_to_text(mark);
97 return g_strdup(
"couldn't get type string");
102 return g_strdup(
"couldn't convert type string to int");
107 return g_strdup(
"types differ");
114 else if (g_strcmp0((
char*)mark->name,
"act:commodity") == 0)
121 if (!equals_node_val_vs_commodity(
123 gnc_account_get_book(act)))
125 return g_strdup(
"commodities differ");
128 else if (g_strcmp0((
char*)mark->name,
"act:code") == 0)
132 return g_strdup(
"codes differ");
135 else if (g_strcmp0((
char*)mark->name,
"act:description") == 0)
137 if (!equals_node_val_vs_string(
140 return g_strdup(
"descriptions differ");
143 else if (g_strcmp0((
char*)mark->name,
"act:slots") == 0)
147 if (!equals_node_val_vs_kvp_frame(mark, qof_instance_get_slots(QOF_INSTANCE (act))))
149 return g_strdup(
"slots differ");
152 else if (g_strcmp0((
char*)mark->name,
"act:parent") == 0)
154 if (!equals_node_val_vs_guid(
157 return g_strdup(
"parent ids differ");
160 else if (g_strcmp0((
char*)mark->name,
"act:commodity-scu") == 0)
164 return g_strdup(
"commodity scus differ");
167 else if (g_strcmp0((
char*)mark->name,
"act:hidden") == 0)
171 return g_strdup(
"Hidden flags differ");
174 else if (g_strcmp0((
char*)mark->name,
"act:placeholder") == 0)
178 return g_strdup(
"Placeholder flags differ");
181 else if (g_strcmp0((
char*)mark->name,
"act:security") == 0)
187 return g_strdup_printf(
"unknown node in dom tree: %s", mark->name);
195 delete_random_account(
Account *act)
209 test_add_account(
const char *tag, gpointer globaldata, gpointer data)
221 new_com = gnc_commodity_table_lookup (t,
232 "gnc_account_sixtp_parser_create",
233 __FILE__, __LINE__,
"%d", gdata->value );
239 test_account(
int i,
Account *test_act)
241 xmlNodePtr test_node;
246 test_node = gnc_account_dom_tree_create(test_act, FALSE, TRUE);
250 failure_args(
"account_xml", __FILE__, __LINE__,
251 "gnc_account_dom_tree_create returned NULL");
255 if ((compare_msg = node_and_account_equal(test_node, test_act)) != NULL)
257 failure_args(
"account_xml", __FILE__, __LINE__,
258 "node and account were not equal: %s", compare_msg);
259 xmlElemDump(stdout, NULL, test_node);
260 fprintf(stdout,
"\n");
261 xmlFreeNode(test_node);
267 success(
"account_xml");
270 filename1 = g_strdup_printf(
"test_file_XXXXXX");
272 fd = g_mkstemp(filename1);
274 write_dom_node_to_file(test_node, fd);
285 parser = gnc_account_sixtp_parser_create();
287 if (!gnc_xml_parse_file(parser, filename1, test_add_account,
290 failure_args(
"gnc_xml_parse_file returned FALSE",
291 __FILE__, __LINE__,
"%d", i);
301 xmlFreeNode(test_node);
309 for (i = 0; i < 20; i++)
313 ran_act = get_random_account(sixbook);
315 test_account(i, ran_act);
317 delete_random_account(ran_act);
323 gchar *msg =
"xaccAccountSetCommodity: assertion `GNC_IS_COMMODITY(com)' failed";
324 gchar *logdomain =
"gnc.engine";
325 guint loglevel = G_LOG_LEVEL_CRITICAL;
327 g_log_set_handler (logdomain, loglevel,
328 (GLogFunc)test_checked_handler, &check);
330 act = get_random_account(sixbook);
337 test_account(-1, act);
339 delete_random_account(act);
361 test_real_account(
const char *tag, gpointer global_data, gpointer data)
371 msg = node_and_account_equal((xmlNodePtr)global_data, act);
372 do_test_args(msg == NULL,
"test_real_account",
373 __FILE__, __LINE__, msg);
380 main (
int argc,
char ** argv)
385 cashobjects_register();
386 session = qof_session_new();
390 test_files_in_dir(argc, argv, test_real_account,
391 gnc_account_sixtp_parser_create(),
392 "gnc:account", sixbook);
399 qof_session_destroy(session);
400 print_test_results();
Account * gnc_account_get_parent(const Account *acc)
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
void gnc_account_append_child(Account *new_parent, Account *child)
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
GNCAccountType xaccAccountGetType(const Account *acc)
int xaccAccountGetCommoditySCU(const Account *acc)
const char * xaccAccountGetCode(const Account *acc)
void xaccAccountSetCode(Account *acc, const char *str)
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
void xaccAccountDestroy(Account *acc)
#define xaccAccountGetGUID(X)
convert single-entry accounts to clean double-entry
QofBook * qof_session_get_book(const QofSession *session)
Account handling public routines.
const char * xaccAccountGetDescription(const Account *acc)
gboolean xaccAccountStringToType(const char *str, GNCAccountType *type)
gboolean xaccAccountEqual(const Account *aa, const Account *ab, gboolean check_guids)
All type declarations for the whole Gnucash engine.
gboolean xaccAccountGetHidden(const Account *acc)
void qof_close(void)
Safely close down the Query Object Framework.
void xaccAccountBeginEdit(Account *acc)
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
gboolean xaccAccountGetPlaceholder(const Account *acc)
void xaccAccountSetDescription(Account *acc, const char *str)
const char * xaccAccountGetName(const Account *acc)
void qof_init(void)
Initialise the Query Object Framework.
void xaccAccountSetCommodity(Account *acc, gnc_commodity *com)