27 #include <unittest-support.h>
29 #include "../Transaction.h"
30 #include "../TransactionP.h"
32 #include "../Account.h"
33 #include "../gnc-lot.h"
34 #include "../gnc-event.h"
43 #if defined(__clang__) && (__clang_major__ == 5 || (__clang_major__ == 3 && __clang_minor__ < 5))
44 #define USE_CLANG_FUNC_SIG 1
47 static const gchar *suitename =
"/engine/Transaction";
48 void test_suite_transaction (
void );
53 static const char *trans_notes_str =
"notes";
54 static const char *void_reason_str =
"void-reason";
55 static const char *void_time_str =
"void-time";
56 static const char *void_former_notes_str =
"void-former-notes";
57 const char *trans_is_closing_str =
"book_closing";
58 #define TRANS_DATE_DUE_KVP "trans-date-due"
59 #define TRANS_TXN_TYPE_KVP "trans-txn-type"
60 #define TRANS_READ_ONLY_REASON "trans-read-only"
61 #define TRANS_REVERSED_BY "reversed-by"
63 #define ISO_DATELENGTH 32
94 mbe->result_err = err;
101 g_strlcpy (mbe->last_call,
"rollback", sizeof (mbe->last_call));
102 mbe->be.last_err = mbe->result_err;
106 mock_backend_new (
void)
109 mbe->be.rollback = mock_backend_rollback;
110 memset (mbe->last_call, 0, sizeof (mbe->last_call));
115 setup (
Fixture *fixture, gconstpointer pData)
119 Split *split1 = NULL, *split2 = NULL;
125 qof_book_set_backend (book, (
QofBackend*)mbe);
130 fixture->curr =
gnc_commodity_new (book,
"Gnu Rand",
"CURRENCY",
"GNR",
"", 240);
131 fixture->comm =
gnc_commodity_new (book,
"Wildebeest Fund",
"FUND",
"WBFXX",
"", 1000);
136 txn->date_posted.tv_sec = posted.tv_sec;
137 txn->date_posted.tv_nsec = posted.tv_nsec;
138 txn->date_entered.tv_sec = entered.tv_sec;
139 txn->date_entered.tv_nsec = entered.tv_nsec;
140 split1->memo = CACHE_INSERT (
"foo");
141 split1->action = CACHE_INSERT (
"bar");
142 split1->amount = gnc_numeric_create (100000, 1000);
143 split1->value = gnc_numeric_create (3200, 240);
144 split2->amount = gnc_numeric_create (-3200, 240);
145 split2->value = gnc_numeric_create (-3200, 240);
146 split1->acc = fixture->acc1;
147 split2->acc = fixture->acc2;
148 txn->num = CACHE_INSERT (
"123");
149 txn->description = CACHE_INSERT (
"Waldo Pepper");
153 xaccSplitSetParent (split1, txn);
154 xaccSplitSetParent (split2, txn);
157 qof_instance_set_slots (QOF_INSTANCE (txn), frame);
164 qof_instance_mark_clean (QOF_INSTANCE (split1));
165 qof_instance_mark_clean (QOF_INSTANCE (split2));
166 qof_instance_mark_clean (QOF_INSTANCE (txn));
167 fixture->func = _utest_trans_fill_functions();
168 fixture->hdlrs = NULL;
172 setup_with_gains (
GainsFixture *fixture, gconstpointer pData)
175 Fixture *base = &(fixture->base);
176 Split *gains_split1 = NULL, *gains_split2 = NULL;
177 Split *base_split = NULL;
187 gains_split1->acc = base->acc1;
188 gains_split2->acc = fixture->gains_acc;
189 gains_split1->amount = gnc_numeric_create (30, 240);
190 gains_split1->value = gnc_numeric_create (30, 240);
191 gains_split2->amount = gnc_numeric_create (-30, 240);
192 gains_split2->value = gnc_numeric_create (-30, 240);
196 xaccSplitSetParent (gains_split1, fixture->gains_txn);
197 xaccSplitSetParent (gains_split2, fixture->gains_txn);
200 base_split = g_list_nth_data (base->txn->splits, 1);
201 base_split->gains_split = gains_split1;
209 teardown (
Fixture *fixture, gconstpointer pData)
214 test_destroy (fixture->txn);
215 test_destroy (fixture->acc1);
216 test_destroy (fixture->acc2);
217 test_destroy (fixture->curr);
218 test_destroy (fixture->comm);
221 g_slist_free_full (fixture->hdlrs, test_free_log_handler);
222 test_clear_error_list();
226 teardown_with_gains (
GainsFixture *fixture, gconstpointer pData)
228 Fixture *base = &(fixture->base);
229 test_destroy (fixture->gains_acc);
230 teardown (base, NULL);
237 test_check_open (
Fixture *fixture, gconstpointer pData)
239 gchar *msg = g_strdup_printf (
"[check_open()] transaction %p not open for editing", fixture->txn);
240 GLogLevelFlags loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
241 TestErrorStruct *check = test_error_struct_new (
"gnc.engine", loglevel,
244 fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check,
245 (GLogFunc)test_checked_handler);
246 check_open (fixture->txn);
247 g_assert_cmpint (check->hits, ==, 1);
249 check_open (fixture->txn);
250 g_assert_cmpint (check->hits, ==, 1);
259 test_xaccTransStillHasSplit (
Fixture *fixture, gconstpointer pData)
263 g_assert (!xaccTransStillHasSplit (fixture->txn, split));
264 xaccSplitSetParent (split, fixture->txn);
265 g_assert (xaccTransStillHasSplit (fixture->txn, split));
266 qof_instance_set_destroying (split, TRUE);
267 g_assert (!xaccTransStillHasSplit (fixture->txn, split));
268 qof_instance_set_destroying (split, FALSE);
269 g_assert (xaccTransStillHasSplit (fixture->txn, split));
270 xaccSplitSetParent (split, NULL);
271 g_assert (!xaccTransStillHasSplit (fixture->txn, split));
273 test_destroy (split);
279 #define check_split_dirty(xsplit, test) \
281 gboolean sort_dirty, balance_dirty; \
282 Split *split = xsplit; \
283 g_object_get (split->acc, \
284 "sort-dirty", &sort_dirty, \
285 "balance-dirty", &balance_dirty, \
287 g_assert_cmpint (sort_dirty, ==, test); \
288 g_assert_cmpint (balance_dirty, ==, test); \
292 test_mark_trans (
Fixture *fixture, gconstpointer pData)
294 gboolean dirty_split = FALSE;
295 GList *splits = NULL;
297 for (splits = (fixture->txn)->splits; splits; splits = splits->next)
299 if (!splits->data)
continue;
301 check_split_dirty (splits->data, FALSE);
303 fixture->func->mark_trans (fixture->txn);
305 for (splits = (fixture->txn)->splits; splits; splits = splits->next)
307 if (!splits->data)
continue;
309 check_split_dirty (splits->data, TRUE);
316 test_gen_event_trans (
Fixture *fixture, gconstpointer pData)
318 Split *split = fixture->txn->splits->data;
320 TestSignal sig1 = test_signal_new (QOF_INSTANCE (fixture->acc1),
321 GNC_EVENT_ITEM_CHANGED, split);
322 TestSignal sig2 = test_signal_new (QOF_INSTANCE (lot),
323 QOF_EVENT_MODIFY, NULL);
325 test_signal_assert_hits (sig1, 1);
326 test_signal_assert_hits (sig2, 3);
327 fixture->func->gen_event_trans (fixture->txn);
328 test_signal_assert_hits (sig1, 2);
329 test_signal_assert_hits (sig2, 4);
331 test_signal_free (sig1);
332 test_signal_free (sig2);
340 test_gnc_transaction_init ()
342 Transaction *txn = g_object_new (GNC_TYPE_TRANSACTION, NULL);
343 g_assert_cmpstr (txn->num, ==,
"");
344 g_assert_cmpstr (txn->description, ==,
"");
345 g_assert (txn->common_currency == NULL);
346 g_assert (txn->splits == NULL);
347 g_assert_cmpint (txn->date_entered.tv_sec, ==, 0);
348 g_assert_cmpint (txn->date_entered.tv_nsec, ==, 0);
349 g_assert_cmpint (txn->date_posted.tv_sec, ==, 0);
350 g_assert_cmpint (txn->date_posted.tv_nsec, ==, 0);
351 g_assert_cmpint (txn->marker, ==, 0);
352 g_assert (txn->orig == NULL);
360 test_gnc_transaction_dispose ()
363 Transaction *txn = g_object_new (GNC_TYPE_TRANSACTION,
"book", book, NULL);
364 Split *split = g_object_new (GNC_TYPE_SPLIT,
"book", book, NULL);
365 Split *s_ref = split;
367 "GNR",
"", 240), *t_curr = NULL;
369 g_object_add_weak_pointer (G_OBJECT (split), (gpointer*) &s_ref);
370 g_object_add_weak_pointer (G_OBJECT (curr), (gpointer*) &c_ref);
371 txn->splits = g_list_append (txn->splits, split);
372 txn->common_currency = curr;
374 g_assert (txn->splits != NULL);
375 g_assert (s_ref != NULL);
376 g_assert (c_ref != NULL);
378 g_object_run_dispose (G_OBJECT (txn));
383 g_assert (txn->splits != NULL);
384 g_assert (txn->common_currency != NULL);
385 g_assert (s_ref != NULL);
386 g_assert (c_ref != NULL);
388 test_destroy (split);
398 test_gnc_transaction_finalize ()
400 Transaction *txn = g_object_new (GNC_TYPE_TRANSACTION, NULL);
408 test_gnc_transaction_set_get_property (
Fixture *fixture, gconstpointer pData)
411 Transaction *txn = g_object_new (GNC_TYPE_TRANSACTION,
"book", book, NULL);
412 gchar *num =
"42", *desc =
"The Answer", *t_num = NULL, *t_desc = NULL, *phony = NULL;
414 "GNR",
"", 240), *t_curr = NULL;
416 time_t secs = (time_t)now.tv_sec;
417 gchar *msg1 =
"g_object_set_valist: object class " _Q
"Transaction' has no property named " _Q
"bogus'";
418 gchar *msg2 = g_strdup_printf (
"[xaccTransSetDateInternal] addr=%p set date to %" G_GUINT64_FORMAT
".%09ld %s",
419 txn, now.tv_sec, now.tv_nsec, ctime (&secs));
420 GLogLevelFlags loglevel1 = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL;
421 GLogLevelFlags loglevel2 = G_LOG_LEVEL_INFO;
427 fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check1,
428 (GLogFunc)test_checked_handler);
429 fixture->hdlrs = test_log_set_handler (fixture->hdlrs, check2,
430 (GLogFunc)test_checked_handler);
431 g_assert_cmpstr (txn->num, ==,
"");
432 g_assert_cmpstr (txn->description, ==,
"");
433 g_assert (txn->common_currency == NULL);
434 g_assert_cmpint (txn->date_entered.tv_sec, ==, 0);
435 g_assert_cmpint (txn->date_entered.tv_nsec, ==, 0);
436 g_assert_cmpint (txn->date_posted.tv_sec, ==, 0);
437 g_assert_cmpint (txn->date_posted.tv_nsec, ==, 0);
440 g_object_set (G_OBJECT (txn),
449 g_assert_cmpstr (txn->num, ==, num);
450 g_assert_cmpstr (txn->description, ==, desc);
451 g_assert (txn->common_currency == curr);
454 g_assert_cmpint (check1->hits, ==, 1);
455 g_assert_cmpint (check2->hits, ==, 2);
457 g_free (check1->msg);
458 check1->msg = g_strdup (
"g_object_get_valist: object class " _Q
"Transaction' has no property named " _Q
"bogus'");
459 g_object_get (G_OBJECT (txn),
461 "description", &t_desc,
463 "post-date", &t_posted,
464 "enter-date", &t_entered,
468 g_assert_cmpstr (t_num, ==, num);
469 g_assert_cmpstr (t_desc, ==, desc);
470 g_assert (t_curr == curr);
473 g_assert_cmpint (check1->hits, ==, 2);
474 g_assert_cmpint (check2->hits, ==, 2);
486 test_xaccMallocTransaction (
Fixture *fixture, gconstpointer pData)
489 TestSignal sig1 = test_signal_new (NULL, QOF_EVENT_CREATE,NULL);
491 #ifdef USE_CLANG_FUNC_SIG
492 #define _func "Transaction *xaccMallocTransaction(QofBook *)"
494 #define _func "xaccMallocTransaction"
496 gchar *msg = _func
": assertion " _Q
"book' failed";
498 gchar *logdomain =
"gnc.engine";
499 guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
500 TestErrorStruct *check = test_error_struct_new (
"gnc.engine", loglevel,
502 fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check,
503 (GLogFunc)test_checked_handler);
504 test_signal_assert_hits (sig1, 0);
506 g_assert (txn == NULL);
507 g_assert_cmpint (check->hits, ==, 1);
508 test_signal_assert_hits (sig1, 0);
511 g_assert (txn != NULL);
512 g_assert_cmpint (check->hits, ==, 1);
513 test_signal_assert_hits (sig1, 1);
517 test_signal_free (sig1);
524 test_xaccTransSortSplits (
Fixture *fixture, gconstpointer pData)
528 Split *split1 = txn->splits->data;
529 Split *split2 = txn->splits->next->data;
535 values[0] = gnc_numeric_create (100, 240);
536 values[1] = gnc_numeric_create (75, 240);
537 values[2] = gnc_numeric_create (-125, 240);
540 for (i = 0; i < G_N_ELEMENTS (split); i++)
543 split[i]->value = values[i];
544 split[i]->acc = fixture->acc1;
545 xaccSplitSetParent (split[i], txn);
549 g_assert (node->data == split1);
550 node = g_list_next (node);
551 g_assert (node->data == split2);
552 node = g_list_next (node);
553 g_assert (node->data == split[0]);
554 node = g_list_next (node);
555 g_assert (node->data == split[1]);
556 node = g_list_next (node);
557 g_assert (node->data == split[2]);
562 g_assert (node->data == split1);
563 node = g_list_next (node);
564 g_assert (node->data == split[0]);
565 node = g_list_next (node);
566 g_assert (node->data == split[1]);
567 node = g_list_next (node);
568 g_assert (node->data == split2);
569 node = g_list_next (node);
570 g_assert (node->data == split[2]);
579 test_dupe_trans (
Fixture *fixture, gconstpointer pData)
583 Transaction *newtxn = NULL, *oldtxn = fixture->txn;
585 GList *newnode, *oldnode = oldtxn->splits;
587 oldtxn->date_posted = posted;
588 oldtxn->date_entered = entered;
590 "The Great Waldo Pepper");
592 newtxn = fixture->func->dupe_trans (oldtxn);
594 g_assert_cmpstr (newtxn->num, ==, oldtxn->num);
595 g_assert_cmpstr (newtxn->description, ==, oldtxn->description);
596 for (newnode = newtxn->splits; newnode && oldnode;
597 newnode = g_list_next (newnode))
601 oldnode = g_list_next (oldnode);
603 g_assert (newnode == NULL);
604 g_assert (oldnode == NULL);
608 QOF_INSTANCE (oldtxn)) == 0);
609 g_assert (newtxn->orig == NULL);
610 g_assert (newtxn->common_currency == fixture->curr);
611 g_assert (newtxn->inst.
e_type == NULL);
615 g_assert (
kvp_frame_compare (oldtxn->inst.kvp_data, newtxn->inst.kvp_data) == 0);
617 test_destroy (newtxn);
624 test_xaccTransClone (
Fixture *fixture, gconstpointer pData)
628 Transaction *newtxn = NULL, *oldtxn = fixture->txn;
630 GList *newnode, *oldnode;
633 oldtxn->date_posted = posted;
634 oldtxn->date_entered = entered;
637 g_assert_cmpstr (newtxn->num, ==, oldtxn->num);
638 g_assert_cmpstr (newtxn->description, ==, oldtxn->description);
646 oldnode = oldtxn->splits;
647 for (newnode = newtxn->splits; newnode && oldnode;
648 newnode = g_list_next (newnode))
651 FALSE, FALSE, FALSE));
652 oldnode = g_list_next (oldnode);
654 g_assert (newnode == NULL);
655 g_assert (oldnode == NULL);
659 QOF_INSTANCE (oldtxn)) == 0);
660 g_assert_cmpint (qof_instance_get_version_check (newtxn), ==,
661 qof_instance_get_version_check (oldtxn));
662 g_assert (newtxn->orig == NULL);
663 g_assert (newtxn->common_currency == fixture->curr);
666 g_assert (
kvp_frame_compare (oldtxn->inst.kvp_data, newtxn->inst.kvp_data) == 0);
668 test_destroy (newtxn);
684 test_xaccTransCopyFromClipBoard (
Fixture *fixture, gconstpointer pData)
692 KvpFrame *to_frame = to_txn->inst.kvp_data;
697 to_txn->common_currency));
699 g_assert (
timespec_equal (&(to_txn->date_posted), &txn->date_posted));
700 g_assert_cmpstr (txn->num, ==, to_txn->num);
711 test_xaccTransCopyFromClipBoard_no_start (
Fixture *fixture, gconstpointer pData)
723 to_txn->common_currency));
726 g_assert_cmpstr (to_txn->num, ==, txn->num);
741 test_xaccFreeTransaction (
Fixture *fixture, gconstpointer pData)
745 Split *split = txn->splits->data;
746 gchar *txn_num =
"321";
747 g_object_add_weak_pointer (G_OBJECT (txn->splits->data), (gpointer)&split);
751 orig->num = CACHE_INSERT (txn_num);
754 fixture->func->xaccFreeTransaction (txn);
756 g_assert (split == NULL);
757 g_assert (txn->splits == NULL);
758 g_assert_cmpint (GPOINTER_TO_INT(txn->num), ==, 1);
759 g_assert (txn->description == NULL);
760 g_assert_cmpint (txn->date_entered.tv_sec, ==, 0);
761 g_assert_cmpint (txn->date_entered.tv_nsec, ==, 0);
762 g_assert_cmpint (txn->date_posted.tv_sec, ==, 0);
763 g_assert_cmpint (txn->date_posted.tv_nsec, ==, 0);
764 g_assert_cmpint (GPOINTER_TO_INT(orig->num), ==, 1);
765 g_assert (txn->orig == NULL);
768 g_test_log_set_fatal_handler ((GTestLogFatalFunc) test_log_handler, NULL);
781 #define DATE_BUF_SIZE 100
783 test_xaccTransEqual (
Fixture *fixture, gconstpointer pData)
792 gchar entered[DATE_BUF_SIZE], posted[DATE_BUF_SIZE];
793 gchar *msg1 =
"[xaccTransEqual] one is NULL";
795 gchar *cleanup_fmt =
"[trans_cleanup_commit] get rid of rollback trans=%p";
798 gchar *logdomain =
"gnc.engine";
799 guint loglevel = G_LOG_LEVEL_INFO;
800 TestErrorStruct *check = test_error_struct_new (logdomain, loglevel, msg1);
803 TestErrorStruct *cleanup = test_error_struct_new (logdomain, loglevel,
"");
806 test_add_error (check);
807 test_add_error (&check2);
808 test_add_error (cleanup);
810 fixture->hdlrs = test_log_set_handler (fixture->hdlrs, check,
811 (GLogFunc)test_list_handler);
819 qof_instance_set_guid (txn1, guid_f_txn);
820 g_assert_cmpint (check->hits, ==, 2);
827 check->msg = g_strdup (
"[xaccTransEqual] GUIDs differ");
829 qof_instance_set_guid (clone, guid_f_txn);
831 g_assert_cmpint (check->hits, ==, 1);
833 cleanup->msg = g_strdup_printf (cleanup_fmt, clone->orig);
837 g_free (cleanup->msg);
840 g_assert (!
xaccTransEqual (clone, txn0, TRUE, FALSE, TRUE, TRUE));
841 g_assert_cmpint (check->hits, ==, 2);
846 cleanup->msg = g_strdup_printf (cleanup_fmt, clone->orig);
849 clone->date_posted.tv_sec = txn0->date_entered.tv_sec;
851 g_free (cleanup->msg);
853 check->msg = g_strdup_printf (
"[xaccTransEqual] date posted differs: '%s' vs '%s'", entered, posted);
854 g_assert (!
xaccTransEqual (clone, txn0, TRUE, FALSE, TRUE, TRUE));
855 g_assert_cmpint (check->hits, ==, 3);
858 cleanup->msg = g_strdup_printf (cleanup_fmt, clone->orig);
859 clone->date_posted.tv_sec = txn0->date_posted.tv_sec;
860 clone->date_entered.tv_sec = txn0->date_posted.tv_sec;
862 g_free (cleanup->msg);
864 check->msg = g_strdup_printf (
"[xaccTransEqual] date entered differs: '%s' vs '%s'", posted, entered);
865 g_assert (!
xaccTransEqual (clone, txn0, TRUE, FALSE, TRUE, TRUE));
866 g_assert_cmpint (check->hits, ==, 4);
869 cleanup->msg = g_strdup_printf (cleanup_fmt, clone->orig);
870 clone->date_entered.tv_sec = txn0->date_entered.tv_sec;
873 g_free (cleanup->msg);
875 check->msg = g_strdup (
"[xaccTransEqual] num differs: 123 vs 123");
876 g_assert (!
xaccTransEqual (clone, txn0, TRUE, FALSE, TRUE, TRUE));
877 g_assert_cmpint (check->hits, ==, 5);
879 g_assert_cmpint (check->hits, ==, 5);
883 check->msg = g_strdup (
"[xaccTransEqual] num differs: 321 vs 123");
885 g_assert_cmpint (check->hits, ==, 6);
887 clone->num = CACHE_INSERT(
"123");
889 clone->description =
"salt pork";
891 check->msg = g_strdup (
"[xaccTransEqual] descriptions differ: salt pork vs Waldo Pepper");
892 g_assert (!
xaccTransEqual (clone, txn0, TRUE, FALSE, TRUE, TRUE));
893 g_assert_cmpint (check->hits, ==, 7);
895 g_assert_cmpint (check->hits, ==, 7);
896 g_assert (!
xaccTransEqual (clone, txn1, TRUE, FALSE, TRUE, TRUE));
897 g_assert_cmpint (check->hits, ==, 8);
900 cleanup->msg = g_strdup_printf (cleanup_fmt, clone->orig);
901 clone->description = CACHE_INSERT (
"Waldo Pepper");
903 "/qux/quux/corge", 654.321);
905 g_free (cleanup->msg);
907 check->msg = g_strdup (
"[xaccTransEqual] kvp frames differ:\n{\n notes => KVP_VALUE_STRING(Salt pork sausage),\n qux => KVP_VALUE_FRAME({\n quux => KVP_VALUE_FRAME({\n corge => KVP_VALUE_DOUBLE(654.321),\n}\n),\n}\n),\n}\n\n\nvs\n\n{\n notes => KVP_VALUE_STRING(Salt pork sausage),\n qux => KVP_VALUE_FRAME({\n quux => KVP_VALUE_FRAME({\n corge => KVP_VALUE_DOUBLE(123.456),\n}\n),\n}\n),\n}\n");
909 g_assert (!
xaccTransEqual (clone, txn0, TRUE, FALSE, TRUE, TRUE));
911 g_assert_cmpint (check->hits, ==, 9);
913 cleanup->msg = g_strdup_printf (cleanup_fmt, clone->orig);
914 clone->description = CACHE_INSERT (
"Waldo Pepper");
916 "/qux/quux/corge", 123.456);
918 g_free (cleanup->msg);
920 check->msg = g_strdup (
"[xaccSplitEqual] GUIDs differ");
924 check2.msg = g_strdup_printf (
925 "[xaccTransEqual] splits %s and %s differ", split_guid1, split_guid0);
928 g_assert (
xaccTransEqual (clone, txn0, FALSE, FALSE, FALSE, TRUE));
929 g_assert_cmpint (check->hits, ==, 10);
930 g_assert_cmpint (check2.hits, ==, 1);
934 check->msg = g_strdup(
"[xaccSplitEqual] amounts differ: 13333/1000 vs 100000/1000");
935 check2.msg = g_strdup_printf (
936 "[xaccTransEqual] splits %s and %s differ", split_guid0, split_guid0);
939 g_assert (
xaccTransEqual (clone, txn0, TRUE, FALSE, FALSE, TRUE));
940 g_assert_cmpint (check->hits, ==, 11);
941 g_assert_cmpint (check2.hits, ==, 2);
957 check->msg = g_strdup_printf(
"[xaccSplitEqualCheckBal] balances differ: %s vs %s", bal10, bal00);
958 check3.msg = g_strdup_printf(
"[xaccSplitEqualCheckBal] balances differ: %s vs %s", bal11, bal01);
960 test_add_error (&check3);
963 g_assert_cmpint (check->hits, ==, 12);
964 g_assert_cmpint (check2.hits, ==, 3);
965 g_assert_cmpint (check3.hits, ==, 0);
967 split10->balance = split00->balance;
968 split11->balance = split01->balance;
986 test_xaccTransLookup (
Fixture *fixture, gconstpointer pData)
998 test_xaccTransGetImbalanceValue (
Fixture *fixture, gconstpointer pData)
1003 gnc_numeric_zero ()));
1004 split1->acc = fixture->acc1;
1005 split1->memo = CACHE_INSERT (
"foo");
1006 split1->action = CACHE_INSERT (
"bar");
1007 split1->amount = gnc_numeric_create (100000, 1000);
1008 split1->value = gnc_numeric_create (3200, 240);
1010 xaccSplitSetParent (split1, fixture->txn);
1021 test_xaccTransGetImbalance (
Fixture *fixture, gconstpointer pData)
1025 MonetaryList *mlist;
1028 g_assert_cmpint (g_list_length (mlist), ==, 0);
1030 split1->acc = fixture->acc1;
1031 split1->memo = CACHE_INSERT (
"foo");
1032 split1->action = CACHE_INSERT (
"bar");
1033 split1->amount = gnc_numeric_create (100000, 1000);
1034 split1->value = gnc_numeric_create (3200, 240);
1036 xaccSplitSetParent (split1, fixture->txn);
1038 g_assert_cmpint (g_list_length (mlist), ==, 1);
1044 test_xaccTransGetImbalance_trading (
Fixture *fixture,
1045 gconstpointer pData)
1053 MonetaryList *mlist;
1054 qof_book_begin_edit (book);
1056 "trading-accts",
"t",
1058 qof_book_commit_edit (book);
1062 g_assert_cmpint (g_list_length (mlist), ==, 2);
1073 split1->memo = CACHE_INSERT (
"foo");
1074 split1->action = CACHE_INSERT (
"bar");
1075 split1->amount = gnc_numeric_create (-10000, 100);
1076 split1->value = gnc_numeric_create (-3200, 240);
1078 split2->memo = CACHE_INSERT (
"foo");
1079 split2->action = CACHE_INSERT (
"bar");
1080 split2->amount = gnc_numeric_create (3000, 240);
1081 split2->value = gnc_numeric_create (3200, 240);
1083 xaccSplitSetParent (split1, fixture->txn);
1085 g_assert_cmpint (g_list_length (mlist), ==, 1);
1087 xaccSplitSetParent (split2, fixture->txn);
1089 g_assert_cmpint (g_list_length (mlist), ==, 1);
1091 split2->amount = gnc_numeric_create (3000, 240);
1092 split2->value = gnc_numeric_create (3000, 240);
1094 g_assert_cmpint (g_list_length (mlist), ==, 1);
1096 split2->amount = gnc_numeric_create (3200, 240);
1097 split2->value = gnc_numeric_create (3200, 240);
1099 g_assert_cmpint (g_list_length (mlist), ==, 0);
1103 test_destroy (acc1);
1104 test_destroy (acc2);
1113 test_xaccTransIsBalanced (
Fixture *fixture, gconstpointer pData)
1120 split1->acc = fixture->acc1;
1121 split1->memo = CACHE_INSERT (
"foo");
1122 split1->action = CACHE_INSERT (
"bar");
1123 split1->amount = gnc_numeric_create (100000, 1000);
1124 split1->value = gnc_numeric_create (3200, 240);
1126 xaccSplitSetParent (split1, fixture->txn);
1133 test_xaccTransIsBalanced_trading (
Fixture *fixture, gconstpointer pData)
1141 qof_book_begin_edit (book);
1143 "trading-accts",
"t",
1145 qof_book_commit_edit (book);
1154 split1->memo = CACHE_INSERT (
"foo");
1155 split1->action = CACHE_INSERT (
"bar");
1156 split1->amount = gnc_numeric_create (3200, 240);
1157 split1->value = gnc_numeric_create (3200, 240);
1159 split2->memo = CACHE_INSERT (
"foo");
1160 split2->action = CACHE_INSERT (
"bar");
1161 split2->amount = gnc_numeric_create (-10000, 100);
1162 split2->value = gnc_numeric_create (-3000, 240);
1164 xaccSplitSetParent (split1, fixture->txn);
1166 xaccSplitSetParent (split2, fixture->txn);
1168 split2->amount = gnc_numeric_create (-11000, 100);
1169 split2->value = gnc_numeric_create (-3200, 240);
1171 split2->amount = gnc_numeric_create (-10000, 100);
1172 split2->value = gnc_numeric_create (-3200, 240);
1176 test_destroy (acc2);
1177 test_destroy (acc1);
1184 test_xaccTransGetAccountValue (
Fixture *fixture, gconstpointer pData)
1186 gnc_numeric val1 = {3200, 240}, val2 = {-3200, 240};
1199 test_xaccTransGetAccountAmount (
Fixture *fixture, gconstpointer pData)
1201 gnc_numeric amt1 = {100000, 1000}, amt2 = {-3200, 240};
1216 test_xaccTransGetRateForCommodity (
Fixture *fixture, gconstpointer pData)
1221 Split *split1 = xaccTransFindSplitByAccount(fixture->txn, fixture->acc1);
1222 g_assert (!xaccTransGetRateForCommodity (NULL, fixture->comm,
1224 g_assert (!xaccTransGetRateForCommodity (fixture->txn, NULL,
1226 g_assert (!xaccTransGetRateForCommodity (fixture->txn, fixture->comm,
1228 g_assert (xaccTransGetRateForCommodity (fixture->txn, fixture->curr,
1231 rate = gnc_numeric_zero ();
1232 g_assert (!xaccTransGetRateForCommodity (fixture->txn, fixture->comm,
1236 g_assert (xaccTransGetRateForCommodity (fixture->txn, fixture->comm,
1246 test_xaccTransGetAccountConvRate (
Fixture *fixture, gconstpointer pData)
1248 gchar *msg1 =
"[xaccTransGetAccountConvRate()] How can amount be nonzero and value be zero?";
1249 guint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL;
1250 TestErrorStruct *check = test_error_struct_new (
"gnc.engine", loglevel,
1252 Split *split1 = xaccTransFindSplitByAccount(fixture->txn, fixture->acc1);
1255 fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check,
1256 (GLogFunc)test_checked_handler);
1260 gnc_numeric_create (1, 1)));
1264 gnc_numeric_create (1800, 240)));
1265 g_assert_cmpint (check->hits, ==, 0);
1266 split1->value = gnc_numeric_zero();
1267 rate = xaccTransGetAccountConvRate (fixture->txn, fixture->acc1);
1269 g_assert_cmpint (check->hits, ==, 1);
1276 test_xaccTransGetAccountBalance (
Fixture *fixture, gconstpointer pData)
1278 #ifdef USE_CLANG_FUNC_SIG
1279 #define _func "gnc_numeric xaccTransGetAccountBalance(const Transaction *, const Account *)"
1281 #define _func "xaccTransGetAccountBalance"
1283 gchar *msg1 = _func
": assertion " _Q
"account && trans' failed";
1285 guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
1286 TestErrorStruct *check = test_error_struct_new (
"gnc.engine", loglevel,
1288 Split *split1 = xaccTransFindSplitByAccount(fixture->txn, fixture->acc1);
1291 fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check,
1292 (GLogFunc)test_checked_handler);
1296 g_assert_cmpint (check->hits, ==, 1);
1300 g_assert_cmpint (check->hits, ==, 2);
1304 g_assert_cmpint (check->hits, ==, 2);
1308 g_assert_cmpint (check->hits, ==, 2);
1321 test_xaccTransSetCurrency (
Fixture *fixture, gconstpointer pData)
1325 Split *split1 = xaccTransFindSplitByAccount (fixture->txn, fixture->acc1);
1330 g_assert (fixture->txn->common_currency == curr);
1334 old_val.num / old_val.denom);
1341 test_xaccTransBeginEdit ()
1346 gchar *msg1 =
"[xaccOpenLog] Attempt to open disabled transaction log";
1347 gchar *msg2 =
"[xaccTransWriteLog] Attempt to write disabled transaction log";
1348 guint loglevel = G_LOG_LEVEL_INFO;
1349 gchar *logdomain =
"gnc.translog";
1350 TestErrorStruct *check1 = test_error_struct_new (logdomain, loglevel, msg1);
1351 TestErrorStruct *check2 = test_error_struct_new (logdomain, loglevel, msg2);
1352 guint hdlr = g_log_set_handler (logdomain, loglevel,
1353 (GLogFunc)test_list_handler, NULL);
1354 test_add_error (check1);
1355 test_add_error (check2);
1358 g_assert_cmpint (0, ==, qof_instance_get_editlevel (QOF_INSTANCE (txn)));
1359 g_assert (txn->orig == NULL);
1361 g_assert_cmpint (1, ==, qof_instance_get_editlevel (QOF_INSTANCE (txn)));
1363 g_assert (txn->orig != NULL);
1364 g_assert_cmpint (1, ==, check1->hits);
1365 g_assert_cmpint (1, ==, check2->hits);
1367 g_assert_cmpint (2, ==, qof_instance_get_editlevel (QOF_INSTANCE (txn)));
1368 g_assert (txn->orig == dupe);
1369 g_assert_cmpint (1, ==, check1->hits);
1370 g_assert_cmpint (1, ==, check2->hits);
1373 g_assert_cmpint (0, ==, qof_instance_get_editlevel (QOF_INSTANCE (txn)));
1374 g_assert (txn->orig == NULL);
1378 g_assert_cmpint (1, ==, qof_instance_get_editlevel (QOF_INSTANCE (txn)));
1379 g_assert (txn->orig == dupe);
1380 g_assert_cmpint (1, ==, check1->hits);
1381 g_assert_cmpint (2, ==, check2->hits);
1383 g_assert_cmpint (0, ==, qof_instance_get_editlevel (QOF_INSTANCE (txn)));
1384 g_assert (txn->orig == NULL);
1387 g_assert_cmpint (1, ==, qof_instance_get_editlevel (QOF_INSTANCE (txn)));
1388 g_assert (txn->orig == NULL);
1389 g_assert_cmpint (1, ==, check1->hits);
1390 g_assert_cmpint (2, ==, check2->hits);
1392 g_log_remove_handler (logdomain, hdlr);
1393 test_clear_error_list ();
1394 test_error_struct_free (check1);
1395 test_error_struct_free (check2);
1404 test_xaccTransDestroy (
Fixture *fixture, gconstpointer pData)
1424 test_destroy (dupe);
1431 test_destroy_gains (
GainsFixture *fixture, gconstpointer pData)
1436 Fixture *base = &(fixture->base);
1437 Split *base_split = g_list_nth_data (base->txn->splits, 1);
1439 base->func->destroy_gains (base->txn);
1441 g_assert (base_split->gains_split == NULL);
1451 test_do_destroy (
GainsFixture *fixture, gconstpointer pData)
1453 Fixture *base = &(fixture->base);
1454 Split *base_split = g_list_nth_data (base->txn->splits, 1);
1456 TestSignal sig = test_signal_new (QOF_INSTANCE (base->txn),
1457 QOF_EVENT_DESTROY, NULL);
1458 g_object_add_weak_pointer (G_OBJECT (base->txn->splits->data),
1459 (gpointer)&base_split);
1460 g_object_ref (base->txn);
1461 g_object_ref (fixture->gains_txn);
1463 base->func->do_destroy (base->txn);
1464 g_assert_cmpint (test_signal_return_hits (sig), ==, 1);
1465 g_assert (base->txn->description == NULL);
1466 g_assert_cmpint (GPOINTER_TO_INT(base->txn->num), ==, 1);
1468 g_assert (base_split == NULL);
1470 test_signal_free (sig);
1480 test_was_trans_emptied (
Fixture *fixture, gconstpointer pData)
1482 GList *list = fixture->txn->splits;
1483 g_assert (!fixture->func->was_trans_emptied (fixture->txn));
1484 fixture->txn->splits = NULL;
1485 g_assert (fixture->func->was_trans_emptied (fixture->txn));
1487 fixture->txn->splits = list;
1497 errorvalue = errcode;
1501 test_trans_on_error (
Fixture *fixture, gconstpointer pData)
1505 "[trans_on_error()] Another user has modified this transaction\n"
1506 "\tjust a moment ago. Please look at their changes,\n"
1507 "\tand try again, if needed.\n";
1508 gchar *logdomain =
"gnc.engine";
1509 guint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL;
1510 TestErrorStruct *check = test_error_struct_new (logdomain, loglevel, msg);
1511 fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check,
1512 (GLogFunc)test_checked_handler);
1515 g_assert_cmpint (qof_instance_get_editlevel (fixture->txn), ==, 1);
1516 fixture->func->trans_on_error (fixture->txn, errcode);
1517 g_assert_cmpint (check->hits, ==, 1);
1518 g_assert_cmpint ((guint)errorvalue, ==, (guint)errcode);
1519 g_assert_cmpint (qof_instance_get_editlevel (fixture->txn), ==, 0);
1526 test_trans_cleanup_commit (
Fixture *fixture, gconstpointer pData)
1531 Split *split0 = fixture->txn->splits->data;
1534 TestSignal *sig_d_remove = test_signal_new (QOF_INSTANCE (destr_split),
1535 QOF_EVENT_REMOVE, NULL);
1536 TestSignal *sig_b_remove = test_signal_new (QOF_INSTANCE (bogus_split),
1537 QOF_EVENT_REMOVE, NULL);
1538 TestSignal *sig_d_destroy = test_signal_new (QOF_INSTANCE (destr_split),
1539 QOF_EVENT_DESTROY, NULL);
1540 TestSignal *sig_b_modify = test_signal_new (QOF_INSTANCE (bogus_split),
1541 QOF_EVENT_MODIFY, NULL);
1542 TestSignal *sig_t_modify = test_signal_new (QOF_INSTANCE (fixture->txn),
1543 QOF_EVENT_MODIFY, NULL);
1544 TestSignal *sig_a_changed = test_signal_new (QOF_INSTANCE (acct0),
1545 GNC_EVENT_ITEM_CHANGED, NULL);
1548 orig = fixture->txn->orig;
1549 g_object_ref (orig);
1551 fixture->txn->splits = g_list_prepend (fixture->txn->splits, destr_split);
1552 fixture->txn->splits = g_list_prepend (fixture->txn->splits, bogus_split);
1553 qof_instance_set_dirty (QOF_INSTANCE (destr_split));
1554 qof_instance_set_dirty (QOF_INSTANCE (bogus_split));
1555 qof_instance_set_destroying (QOF_INSTANCE (destr_split), TRUE);
1557 fixture->txn->splits = g_list_reverse (fixture->txn->splits);
1558 g_assert (fixture->txn->splits->data != split0);
1559 fixture->func->trans_cleanup_commit (fixture->txn);
1561 g_assert_cmpint (test_signal_return_hits (sig_d_remove), ==, 1);
1562 g_assert_cmpint (test_signal_return_hits (sig_b_remove), ==, 1);
1563 g_assert_cmpint (test_signal_return_hits (sig_d_destroy), ==, 0);
1564 g_assert_cmpint (test_signal_return_hits (sig_b_modify), ==, 0);
1565 g_assert_cmpint (test_signal_return_hits (sig_t_modify), ==, 1);
1566 g_assert_cmpint (test_signal_return_hits (sig_a_changed), ==, 1);
1567 g_assert_cmpint (g_list_index (fixture->txn->splits, destr_split), ==, -1);
1568 g_assert_cmpint (g_list_index (fixture->txn->splits, bogus_split), ==, -1);
1569 g_assert (fixture->txn->orig == NULL);
1570 g_assert (fixture->txn->splits->data == split0);
1575 qof_instance_increase_editlevel (fixture->txn);
1576 destr_split->parent = fixture->txn;
1577 bogus_split->parent = fixture->txn;
1578 fixture->txn->splits = g_list_prepend (fixture->txn->splits, destr_split);
1579 fixture->txn->splits = g_list_prepend (fixture->txn->splits, bogus_split);
1581 fixture->txn->orig = orig;
1582 orig->num = fixture->txn->num;
1583 g_object_ref (orig);
1584 fixture->func->trans_cleanup_commit (fixture->txn);
1586 g_assert_cmpint (test_signal_return_hits (sig_d_remove), ==, 2);
1587 g_assert_cmpint (test_signal_return_hits (sig_b_remove), ==, 1);
1588 g_assert_cmpint (test_signal_return_hits (sig_d_destroy), ==, 1);
1589 g_assert_cmpint (test_signal_return_hits (sig_b_modify), ==, 1);
1590 g_assert_cmpint (test_signal_return_hits (sig_t_modify), ==, 2);
1591 g_assert_cmpint (test_signal_return_hits (sig_a_changed), ==, 2);
1592 g_assert_cmpint (g_list_index (fixture->txn->splits, destr_split), ==, -1);
1593 g_assert_cmpint (g_list_index (fixture->txn->splits, bogus_split), ==, 0);
1594 g_assert_cmpint (GPOINTER_TO_INT(orig->num), ==, 1);
1595 test_destroy (orig);
1604 test_xaccTransCommitEdit (
void)
1613 "CURRENCY",
"GNR",
"", 240);
1615 "FUND",
"WBFXX",
"", 1000);
1619 TestSignal *sig_1_modify = test_signal_new (QOF_INSTANCE (split1),
1620 QOF_EVENT_MODIFY, NULL);
1621 TestSignal *sig_2_modify = test_signal_new (QOF_INSTANCE (split2),
1622 QOF_EVENT_MODIFY, NULL);
1623 TestSignal *sig_txn_destroy = test_signal_new (QOF_INSTANCE (txn),
1624 QOF_EVENT_DESTROY, NULL);
1629 txn->date_posted.tv_sec = posted.tv_sec;
1630 txn->date_posted.tv_nsec = posted.tv_nsec;
1631 split1->memo = CACHE_INSERT (
"foo");
1632 split1->action = CACHE_INSERT (
"bar");
1633 split1->amount = gnc_numeric_create (100000, 1000);
1634 split1->value = gnc_numeric_create (3200, 240);
1638 split2->amount = gnc_numeric_create (-3000, 240);
1639 split2->value = gnc_numeric_create (-3000, 240);
1642 txn->num = CACHE_INSERT (
"123");
1643 txn->description = CACHE_INSERT (
"Waldo Pepper");
1647 xaccSplitSetParent (split1, txn);
1648 xaccSplitSetParent (split2, txn);
1653 g_assert_cmpint (txn->date_entered.tv_sec, !=, 0);
1655 g_assert_cmpint (test_signal_return_hits (sig_1_modify), ==, 1);
1656 g_assert_cmpint (test_signal_return_hits (sig_2_modify), ==, 1);
1657 g_assert_cmpint (g_list_length (txn->splits), ==, 3);
1660 g_list_free (txn->splits);
1663 g_assert_cmpint (test_signal_return_hits (sig_txn_destroy), ==, 1);
1665 test_signal_free (sig_1_modify);
1666 test_signal_free (sig_2_modify);
1667 test_signal_free (sig_txn_destroy);
1668 test_destroy (split1);
1669 test_destroy (split2);
1670 test_destroy (acc1);
1671 test_destroy (acc2);
1672 test_destroy (curr);
1673 test_destroy (comm);
1674 test_destroy (book);
1681 test_xaccTransRollbackEdit (
Fixture *fixture, gconstpointer pData)
1688 Timespec orig_post = txn->date_posted;
1689 Timespec orig_entered = txn->date_entered;
1691 TestSignal *sig_account = test_signal_new (QOF_INSTANCE (fixture->acc1),
1692 GNC_EVENT_ITEM_CHANGED, NULL);
1694 Split *split_00 = txn->splits->data, *split_01 = txn->splits->next->data;
1696 Split *split_10 = NULL, *split_11 = NULL;
1699 qof_instance_set_destroying (txn, TRUE);
1701 base_frame = orig->inst.kvp_data;
1702 g_object_ref (orig);
1704 txn->description =
"salt peanuts";
1705 txn->common_currency = NULL;
1706 txn->inst.kvp_data = NULL;
1707 txn->date_entered = new_entered;
1708 txn->date_posted = new_post;
1709 txn->splits->data = split_01;
1710 txn->splits->next->data = split_00;
1711 qof_instance_set_dirty (QOF_INSTANCE (split_01));
1712 xaccSplitSetParent (split_02, txn);
1713 g_object_ref (split_02);
1714 split_10 = xaccDupeSplit(orig->splits->data);
1715 g_object_ref (split_10);
1716 split_11 = xaccDupeSplit(orig->splits->next->data);
1717 g_object_ref (split_11);
1718 qof_instance_increase_editlevel (QOF_INSTANCE (txn));
1720 g_assert (txn->orig == orig);
1721 qof_instance_reset_editlevel (QOF_INSTANCE (txn));
1723 g_assert (txn->orig == orig);
1724 qof_instance_increase_editlevel (QOF_INSTANCE (txn));
1726 g_assert (txn->orig == NULL);
1727 g_assert_cmpstr (txn->num, ==,
"123");
1728 g_assert_cmpint (GPOINTER_TO_INT(orig->num), ==, 1);
1729 g_assert_cmpstr (txn->description, ==,
"Waldo Pepper");
1730 g_assert (txn->inst.kvp_data == base_frame);
1731 g_assert (txn->common_currency == fixture->curr);
1734 g_assert_cmpuint (test_signal_return_hits (sig_account), ==, 1);
1735 g_assert_cmpuint (g_list_length (txn->splits), ==, 2);
1736 g_assert_cmpint (GPOINTER_TO_INT(split_02->memo), ==, 1);
1738 FALSE, FALSE, FALSE));
1740 FALSE, FALSE, FALSE));
1741 g_assert_cmpstr (mbe->last_call, ==,
"rollback");
1742 g_assert_cmpuint (qof_instance_get_editlevel (QOF_INSTANCE (txn)), ==, 0);
1744 test_signal_free (sig_account);
1745 g_object_unref (split_10);
1746 g_object_unref (split_11);
1747 g_object_unref (split_02);
1748 g_object_unref (orig);
1753 test_xaccTransRollbackEdit_BackendErrors (
Fixture *fixture, gconstpointer pData)
1756 guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
1757 gchar *msg =
"[xaccTransRollbackEdit()] Rollback Failed. Ouch!";
1760 fixture->hdlrs = test_log_set_fatal_handler (fixture->hdlrs, check,
1761 (GLogFunc)test_checked_handler);
1762 g_object_ref (fixture->txn);
1766 g_assert_cmpint (check->hits, ==, 1);
1767 g_assert_cmpstr (mbe->last_call, ==,
"rollback");
1768 memset (mbe->last_call, 0, sizeof (mbe->last_call));
1772 g_assert_cmpint (GPOINTER_TO_INT(fixture->txn->num), ==, 1);
1773 g_assert_cmpstr (mbe->last_call, ==,
"rollback");
1787 test_xaccTransOrder_num_action (
Fixture *fixture, gconstpointer pData)
1790 Transaction *txnB = fixture->func->dupe_trans (txnA);
1797 txnB->description = CACHE_INSERT (
"Salt Peanuts");
1799 txnB->date_entered.tv_sec += 1;
1801 txnB->num = CACHE_INSERT (
"101");
1803 txnB->num = CACHE_INSERT (
"one-oh-one");
1806 txnB->date_posted.tv_sec -= 1;
1809 fixture->func->xaccFreeTransaction (txnB);
1869 test_xaccTransVoid (
Fixture *fixture, gconstpointer pData)
1872 KvpFrame *frame = fixture->txn->inst.kvp_data;
1873 gchar *void_reason =
"Voided for Unit Test";
1874 gchar *txn_notes = g_strdup (kvp_frame_get_string (frame, trans_notes_str));
1877 char iso8601_str[ISO_DATELENGTH + 1] =
"";
1878 GList *split = NULL;
1881 g_assert_cmpstr (kvp_frame_get_string (frame, trans_notes_str), ==,
1882 "Voided transaction");
1883 g_assert_cmpstr (kvp_frame_get_string (frame, void_former_notes_str), ==,
1885 g_assert_cmpstr (kvp_frame_get_string (frame, void_reason_str), ==,
1888 g_assert_cmpstr (kvp_frame_get_string (frame, void_time_str), ==,
1890 g_assert_cmpstr (kvp_frame_get_string (frame, TRANS_READ_ONLY_REASON), ==,
1891 "Transaction Voided");
1892 for (split = fixture->txn->splits; split; split=g_list_next (split))
1900 g_assert_cmpstr (kvp_frame_get_string (frame, trans_notes_str), ==,
1902 g_assert (kvp_frame_get_slot (frame, void_former_notes_str) == NULL);
1903 g_assert (kvp_frame_get_slot (frame, void_reason_str) == NULL);
1904 g_assert (kvp_frame_get_slot (frame, void_time_str) == NULL);
1905 g_assert (kvp_frame_get_slot (frame, TRANS_READ_ONLY_REASON) == NULL);
1906 for (split = fixture->txn->splits; split; split=g_list_next (split))
1920 test_xaccTransReverse (
Fixture *fixture, gconstpointer pData)
1923 KvpFrame *frame = fixture->txn->inst.kvp_data;
1924 GList *orig_splits = NULL, *rev_splits = NULL;
1926 g_assert (
guid_equal (kvp_frame_get_guid (frame, TRANS_REVERSED_BY),
1930 g_assert_cmpint (g_list_length (fixture->txn->splits), ==,
1931 g_list_length (rev->splits));
1932 for (orig_splits = fixture->txn->splits,
1933 rev_splits = g_list_reverse (rev->splits);
1934 orig_splits && rev_splits;
1935 orig_splits = g_list_next (orig_splits),
1936 rev_splits = g_list_next (rev_splits))
1938 Split *orig_split = orig_splits->data;
1939 Split *rev_split = rev_splits->data;
1947 fixture->func->xaccFreeTransaction (rev);
1960 test_xaccTransScrubGainsDate_no_dirty (
GainsFixture *fixture,
1961 gconstpointer pData)
1963 Split *base_split = g_list_nth_data (fixture->base.txn->splits, 1);
1964 Split *gains_split = base_split->gains_split;
1966 base_split->gains = GAINS_STATUS_GAINS;
1967 gains_split->gains = GAINS_STATUS_GAINS;
1969 fixture->base.func->xaccTransScrubGainsDate (fixture->base.txn);
1972 &(fixture->gains_txn->date_posted)));
1973 g_assert_cmphex (base_split->gains & GAINS_STATUS_DATE_DIRTY, ==, 0);
1974 g_assert_cmphex (base_split->gains_split->gains & GAINS_STATUS_DATE_DIRTY,
1979 test_xaccTransScrubGainsDate_base_dirty (
GainsFixture *fixture,
1980 gconstpointer pData)
1982 Split *base_split = g_list_nth_data (fixture->base.txn->splits, 1);
1983 Split *gains_split = base_split->gains_split;
1985 base_split->gains = GAINS_STATUS_GAINS | GAINS_STATUS_DATE_DIRTY;
1986 gains_split->gains = GAINS_STATUS_GAINS;
1988 fixture->base.func->xaccTransScrubGainsDate (fixture->base.txn);
1991 &(fixture->gains_txn->date_posted)));
1992 g_assert_cmphex (base_split->gains & GAINS_STATUS_DATE_DIRTY, ==, 0);
1993 g_assert_cmphex (base_split->gains_split->gains & GAINS_STATUS_DATE_DIRTY,
1998 test_xaccTransScrubGainsDate_gains_dirty (
GainsFixture *fixture,
1999 gconstpointer pData)
2001 Split *base_split = g_list_nth_data (fixture->base.txn->splits, 1);
2002 Split *gains_split = base_split->gains_split;
2004 base_split->gains = GAINS_STATUS_GAINS;
2005 gains_split->gains = GAINS_STATUS_GAINS | GAINS_STATUS_DATE_DIRTY;
2007 fixture->base.func->xaccTransScrubGainsDate (fixture->base.txn);
2010 &(fixture->gains_txn->date_posted)));
2011 g_assert_cmphex (base_split->gains & GAINS_STATUS_DATE_DIRTY, ==, 0);
2012 g_assert_cmphex (base_split->gains_split->gains & GAINS_STATUS_DATE_DIRTY,
2030 test_suite_transaction (
void)
2032 GNC_TEST_ADD (suitename,
"check open",
Fixture, NULL, setup, test_check_open, teardown);
2033 GNC_TEST_ADD (suitename,
"xaccTransStillHasSplit",
Fixture, NULL, setup, test_xaccTransStillHasSplit, teardown);
2034 GNC_TEST_ADD (suitename,
"mark trans",
Fixture, NULL, setup, test_mark_trans, teardown);
2035 GNC_TEST_ADD (suitename,
"gen event trans",
Fixture, NULL, setup, test_gen_event_trans, teardown);
2036 GNC_TEST_ADD_FUNC (suitename,
"gnc transaction init", test_gnc_transaction_init);
2037 GNC_TEST_ADD_FUNC (suitename,
"gnc transaction dispose", test_gnc_transaction_dispose);
2038 GNC_TEST_ADD_FUNC (suitename,
"gnc transaction finalize", test_gnc_transaction_finalize);
2039 GNC_TEST_ADD (suitename,
"gnc transaction set/get property",
Fixture, NULL, setup, test_gnc_transaction_set_get_property, teardown);
2040 GNC_TEST_ADD (suitename,
"xaccMallocTransaction",
Fixture, NULL, setup, test_xaccMallocTransaction, teardown);
2041 GNC_TEST_ADD (suitename,
"xaccTransSortSplits",
Fixture, NULL, setup, test_xaccTransSortSplits, teardown);
2042 GNC_TEST_ADD (suitename,
"dupe_trans",
Fixture, NULL, setup, test_dupe_trans, teardown);
2043 GNC_TEST_ADD (suitename,
"xaccTransClone",
Fixture, NULL, setup, test_xaccTransClone, teardown);
2044 GNC_TEST_ADD (suitename,
"xaccTransCopyFromClipBoard",
Fixture, NULL, setup, test_xaccTransCopyFromClipBoard, teardown);
2045 GNC_TEST_ADD (suitename,
"xaccTransCopyFromClipBoard No-Start",
Fixture, NULL, setup, test_xaccTransCopyFromClipBoard_no_start, teardown);
2046 GNC_TEST_ADD (suitename,
"xaccFreeTransaction",
Fixture, NULL, setup, test_xaccFreeTransaction, teardown);
2048 GNC_TEST_ADD (suitename,
"xaccTransEqual",
Fixture, NULL, setup, test_xaccTransEqual, teardown);
2049 GNC_TEST_ADD (suitename,
"xaccTransLookup",
Fixture, NULL, setup, test_xaccTransLookup, teardown);
2050 GNC_TEST_ADD (suitename,
"xaccTransGetImbalanceValue",
Fixture, NULL, setup, test_xaccTransGetImbalanceValue, teardown);
2051 GNC_TEST_ADD (suitename,
"xaccTransGetImbalance",
Fixture, NULL, setup, test_xaccTransGetImbalance, teardown);
2052 GNC_TEST_ADD (suitename,
"xaccTransGetImbalance Trading Accounts",
Fixture, NULL, setup, test_xaccTransGetImbalance_trading, teardown);
2053 GNC_TEST_ADD (suitename,
"xaccTransIsBalanced",
Fixture, NULL, setup, test_xaccTransIsBalanced, teardown);
2054 GNC_TEST_ADD (suitename,
"xaccTransIsBalanced Trading Accounts",
Fixture, NULL, setup, test_xaccTransIsBalanced_trading, teardown);
2055 GNC_TEST_ADD (suitename,
"xaccTransGetAccountValue",
Fixture, NULL, setup, test_xaccTransGetAccountValue, teardown);
2056 GNC_TEST_ADD (suitename,
"xaccTransGetRateForCommodity",
Fixture, NULL, setup, test_xaccTransGetRateForCommodity, teardown);
2057 GNC_TEST_ADD (suitename,
"xaccTransGetAccountAmount",
Fixture, NULL, setup, test_xaccTransGetAccountAmount, teardown);
2058 GNC_TEST_ADD (suitename,
"xaccTransGetAccountConvRate",
Fixture, NULL, setup, test_xaccTransGetAccountConvRate, teardown);
2059 GNC_TEST_ADD (suitename,
"xaccTransGetAccountBalance",
Fixture, NULL, setup, test_xaccTransGetAccountBalance, teardown);
2061 GNC_TEST_ADD (suitename,
"xaccTransSetCurrency",
Fixture, NULL, setup, test_xaccTransSetCurrency, teardown);
2062 GNC_TEST_ADD_FUNC (suitename,
"xaccTransBeginEdit", test_xaccTransBeginEdit);
2063 GNC_TEST_ADD (suitename,
"xaccTransDestroy",
Fixture, NULL, setup, test_xaccTransDestroy, teardown);
2064 GNC_TEST_ADD (suitename,
"destroy gains",
GainsFixture, NULL, setup_with_gains, test_destroy_gains, teardown_with_gains);
2065 GNC_TEST_ADD (suitename,
"do destroy",
GainsFixture, NULL, setup_with_gains, test_do_destroy, teardown_with_gains);
2066 GNC_TEST_ADD (suitename,
"was trans emptied",
Fixture, NULL, setup, test_was_trans_emptied, teardown);
2067 GNC_TEST_ADD (suitename,
"trans on error",
Fixture, NULL, setup, test_trans_on_error, teardown);
2068 GNC_TEST_ADD (suitename,
"trans cleanup commit",
Fixture, NULL, setup, test_trans_cleanup_commit, teardown);
2069 GNC_TEST_ADD_FUNC (suitename,
"xaccTransCommitEdit", test_xaccTransCommitEdit);
2070 GNC_TEST_ADD (suitename,
"xaccTransRollbackEdit",
Fixture, NULL, setup, test_xaccTransRollbackEdit, teardown);
2071 GNC_TEST_ADD (suitename,
"xaccTransRollbackEdit - Backend Errors",
Fixture, NULL, setup, test_xaccTransRollbackEdit_BackendErrors, teardown);
2072 GNC_TEST_ADD (suitename,
"xaccTransOrder_num_action",
Fixture, NULL, setup, test_xaccTransOrder_num_action, teardown);
2073 GNC_TEST_ADD (suitename,
"xaccTransVoid",
Fixture, NULL, setup, test_xaccTransVoid, teardown);
2074 GNC_TEST_ADD (suitename,
"xaccTransReverse",
Fixture, NULL, setup, test_xaccTransReverse, teardown);
2075 GNC_TEST_ADD (suitename,
"xaccTransScrubGainsDate",
GainsFixture, NULL, setup_with_gains, test_xaccTransScrubGainsDate_no_dirty, teardown_with_gains);
2076 GNC_TEST_ADD (suitename,
"xaccTransScrubGainsDate",
GainsFixture, NULL, setup_with_gains, test_xaccTransScrubGainsDate_base_dirty, teardown_with_gains);
2077 GNC_TEST_ADD (suitename,
"xaccTransScrubGainsDate",
GainsFixture, NULL, setup_with_gains, test_xaccTransScrubGainsDate_gains_dirty, teardown_with_gains);
void xaccAccountSetType(Account *acc, GNCAccountType tip)
int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
Transaction * xaccMallocTransaction(QofBook *book)
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
gchar * gnc_timespec_to_iso8601_buff(Timespec ts, gchar *buff)
int gnc_commodity_get_fraction(const gnc_commodity *cm)
const GncGUID * qof_instance_get_guid(gconstpointer)
Split * xaccTransGetSplit(const Transaction *trans, int i)
#define qof_instance_is_dirty
QofBook * qof_instance_get_book(gconstpointer)
gnc_numeric xaccTransGetAccountBalance(const Transaction *trans, const Account *account)
QofBackendError
The errors that can be reported to the GUI & other front-end users.
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Timespec timespecCanonicalDayTime(Timespec t)
gboolean qof_instance_get_destroying(gconstpointer ptr)
void qof_instance_set(QofInstance *inst, const gchar *first_param,...)
Wrapper for g_object_set Group setting multiple parameters in a single begin/commit/rollback.
gint kvp_frame_compare(const KvpFrame *fa, const KvpFrame *fb)
char xaccSplitGetReconcile(const Split *split)
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
void xaccAccountSortSplits(Account *acc, gboolean force)
QofBook * qof_book_new(void)
gboolean timespec_equal(const Timespec *ta, const Timespec *tb)
void gnc_lot_add_split(GNCLot *lot, Split *split)
Use a 64-bit unsigned int timespec.
gboolean gnc_numeric_zero_p(gnc_numeric a)
void gnc_engine_add_commit_error_callback(EngineCommitErrorCallback cb, gpointer data)
void qof_book_mark_readonly(QofBook *book)
gchar * guid_to_string_buff(const GncGUID *guid, gchar *buff)
gboolean xaccTransIsBalanced(const Transaction *trans)
gchar * gnc_numeric_to_string(gnc_numeric n)
Timespec gnc_dmy2timespec(gint day, gint month, gint year)
int xaccTransOrder_num_action(const Transaction *ta, const char *actna, const Transaction *tb, const char *actnb)
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
void xaccTransDestroy(Transaction *trans)
gboolean xaccSplitEqual(const Split *sa, const Split *sb, gboolean check_guids, gboolean check_balances, gboolean check_txn_splits)
const char * xaccTransGetNotes(const Transaction *trans)
Transaction * xaccTransLookup(const GncGUID *guid, QofBook *book)
int xaccTransCountSplits(const Transaction *trans)
gboolean xaccTransEqual(const Transaction *ta, const Transaction *tb, gboolean check_guids, gboolean check_splits, gboolean check_balances, gboolean assume_ordered)
gnc_numeric xaccTransGetImbalanceValue(const Transaction *trans)
void xaccTransVoid(Transaction *trans, const char *reason)
Transaction * xaccTransClone(const Transaction *from)
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
#define GUID_ENCODING_LENGTH
gboolean qof_instance_get_dirty_flag(gconstpointer ptr)
void gnc_monetary_list_free(MonetaryList *list)
gnc_commodity * gnc_commodity_new(QofBook *book, const char *fullname, const char *name_space, const char *mnemonic, const char *cusip, int fraction)
void xaccTransCopyFromClipBoard(const Transaction *from_trans, Transaction *to_trans, const Account *from_acc, Account *to_acc, gboolean no_date)
void xaccAccountRecomputeBalance(Account *acc)
const char * xaccTransGetDescription(const Transaction *trans)
void xaccTransCommitEdit(Transaction *trans)
void xaccTransBeginEdit(Transaction *trans)
void xaccTransUnvoid(Transaction *trans)
gboolean gnc_numeric_eq(gnc_numeric a, gnc_numeric b)
Split * xaccMallocSplit(QofBook *book)
#define xaccTransGetGUID(X)
Transaction * xaccTransReverse(Transaction *orig)
private api for data storage backend
void kvp_frame_set_double(KvpFrame *frame, const gchar *path, double dval)
gnc_numeric xaccSplitGetValue(const Split *split)
const GncGUID * guid_null(void)
void qof_instance_set_book(gconstpointer inst, QofBook *book)
Timespec timespec_now(void)
gint qof_instance_guid_compare(const gconstpointer ptr1, const gconstpointer ptr2)
MonetaryList * xaccTransGetImbalance(const Transaction *trans)
struct KvpFrameImpl KvpFrame
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)
Account * xaccMallocAccount(QofBook *book)
GNCNumericErrorCode gnc_numeric_check(gnc_numeric a)
KvpFrame * kvp_frame_new(void)
QofBackend * qof_book_get_backend(const QofBook *book)
Retrieve the backend used by this book.
void xaccTransSortSplits(Transaction *trans)
void kvp_frame_set_string(KvpFrame *frame, const gchar *path, const gchar *str)
Store a copy of the string at the indicated path.
struct KvpValueImpl KvpValue
void xaccTransRollbackEdit(Transaction *trans)
gnc_numeric xaccTransGetAccountAmount(const Transaction *trans, const Account *acc)
void qof_book_destroy(QofBook *book)
gnc_numeric xaccTransGetAccountValue(const Transaction *trans, const Account *acc)
void xaccAccountSetCommodity(Account *acc, gnc_commodity *com)