diff --git a/src/backend/sql/test/utest-gnc-backend-sql.c b/src/backend/sql/test/utest-gnc-backend-sql.c index 6b4fdb2189..54b419da5a 100644 --- a/src/backend/sql/test/utest-gnc-backend-sql.c +++ b/src/backend/sql/test/utest-gnc-backend-sql.c @@ -199,8 +199,8 @@ test_gnc_sql_commit_edit (void) gchar *msg2 = "[gnc_sql_commit_edit()] gnc_sql_commit_edit(): Unknown object type 'Book'\n"; guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; gchar *logdomain = "gnc.backend.sql"; - TestErrorStruct check1 = { loglevel, logdomain, msg1 }; - TestErrorStruct check2 = { loglevel, logdomain, msg2 }; + TestErrorStruct check1 = { loglevel, logdomain, msg1, 0 }; + TestErrorStruct check2 = { loglevel, logdomain, msg2, 0 }; guint hdlr1; test_add_error (&check1); @@ -229,6 +229,8 @@ test_gnc_sql_commit_edit (void) g_assert (!qof_instance_get_dirty_flag (inst)); g_assert (!qof_book_session_not_saved (be.book)); g_assert_cmpint (dirty_called, == , 0); + g_assert_cmpint (check1.hits, ==, 2); + g_assert_cmpint (check2.hits, ==, 0); qof_book_mark_session_dirty (be.book); @@ -239,6 +241,8 @@ test_gnc_sql_commit_edit (void) g_assert (!qof_instance_get_dirty_flag (QOF_INSTANCE (be.book))); g_assert (qof_book_session_not_saved (be.book)); g_assert_cmpint (dirty_called, == , 1); + g_assert_cmpint (check1.hits, ==, 2); + g_assert_cmpint (check2.hits, ==, 0); qof_instance_set_dirty_flag (QOF_INSTANCE (be.book), TRUE); @@ -249,6 +253,8 @@ test_gnc_sql_commit_edit (void) g_assert (!qof_instance_get_dirty_flag (QOF_INSTANCE (be.book))); g_assert (!qof_book_session_not_saved (be.book)); g_assert_cmpint (dirty_called, == , 0); + g_assert_cmpint (check1.hits, ==, 2); + g_assert_cmpint (check2.hits, ==, 2); g_log_remove_handler (logdomain, hdlr1); g_object_unref (inst); diff --git a/src/engine/test/utest-Account.c b/src/engine/test/utest-Account.c index dd3826bed9..be8517e6b8 100644 --- a/src/engine/test/utest-Account.c +++ b/src/engine/test/utest-Account.c @@ -454,7 +454,7 @@ GList *gnc_account_list_name_violations (QofBook *book, const gchar *separator)/ static void test_gnc_account_list_name_violations (Fixture *fixture, gconstpointer pData) { - TestErrorStruct quiet = { 0, NULL, NULL }; + TestErrorStruct quiet = { 0, NULL, NULL, 0 }; GList *results, *res_iter; gchar *sep = ":"; QofBook *book = gnc_account_get_book (fixture->acct); @@ -639,7 +639,7 @@ static void test_gnc_book_set_get_root_account (Fixture *fixture, gconstpointer pData) { gchar *msg = "[gnc_book_set_root_account()] cannot mix and match books freely!"; - TestErrorStruct quiet = { 0, NULL, msg }; + TestErrorStruct quiet = { 0, NULL, msg, 0 }; Account *acc1, *acc2; QofBook* book1 = qof_book_new (); GLogFunc oldlogger; @@ -728,7 +728,7 @@ test_xaccCloneAccount (Fixture *fixture, gconstpointer pData) Account *clone; QofBook *book = gnc_account_get_book (fixture->acct); guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - TestErrorStruct quiet = { loglevel, "gnc.engine", NULL }; + TestErrorStruct quiet = { loglevel, "gnc.engine", NULL, 0 }; GLogFunc oldlogger; AccountPrivate *acct_p, *clone_p; oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, &quiet); @@ -822,8 +822,8 @@ test_xaccFreeAccount (Fixture *fixture, gconstpointer pData) " xaccAccountBeginEdit(); xaccAccountDestroy(); \n"; gchar *msg2 = "xaccTransGetSplitIndex: assertion `trans && split' failed"; guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - TestErrorStruct check1 = { loglevel, "gnc.account", msg1 }; - TestErrorStruct check2 = { loglevel, "gnc.engine", msg2 }; + TestErrorStruct check1 = { loglevel, "gnc.account", msg1, 0 }; + TestErrorStruct check2 = { loglevel, "gnc.engine", msg2, 0 }; GLogLevelFlags oldmask1, oldmask2; QofBook *book = gnc_account_get_book (fixture->acct); Account *parent = gnc_account_get_parent (fixture->acct); @@ -853,6 +853,8 @@ test_xaccFreeAccount (Fixture *fixture, gconstpointer pData) g_assert (p_priv->splits != NULL); g_assert (p_priv->parent != NULL); g_assert (p_priv->commodity != NULL); + g_assert_cmpint (check1.hits, ==, 0); + g_assert_cmpint (check2.hits, ==, 0); /* Now set the other private parts to something so that they can be set back */ p_priv->cleared_balance = gnc_numeric_create ( 5, 12); p_priv->reconciled_balance = gnc_numeric_create ( 5, 12); @@ -860,6 +862,8 @@ test_xaccFreeAccount (Fixture *fixture, gconstpointer pData) p_priv->balance_dirty = TRUE; p_priv->sort_dirty = TRUE; fixture->func->xaccFreeAccount (parent); + g_assert_cmpint (check1.hits, ==, 6); + g_assert_cmpint (check2.hits, ==, 6); /* cleanup what's left */ g_log_remove_handler ("gnc.account", hdlr1); g_log_remove_handler ("gnc.engine", hdlr2); @@ -927,8 +931,8 @@ test_xaccAccountCommitEdit (Fixture *fixture, gconstpointer pData) " xaccAccountBeginEdit(); xaccAccountDestroy(); \n"; gchar *msg2 = "xaccTransGetSplitIndex: assertion `trans && split' failed"; guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - TestErrorStruct check1 = { loglevel, "gnc.account", msg1 }; - TestErrorStruct check2 = { loglevel, "gnc.engine", msg2 }; + TestErrorStruct check1 = { loglevel, "gnc.account", msg1, 0 }; + TestErrorStruct check2 = { loglevel, "gnc.engine", msg2, 0 }; guint hdlr1, hdlr2; TestSignal sig1, sig2; QofBook *book = gnc_account_get_book (fixture->acct); @@ -958,6 +962,8 @@ test_xaccAccountCommitEdit (Fixture *fixture, gconstpointer pData) g_assert (p_priv->splits != NULL); g_assert (p_priv->parent != NULL); g_assert (p_priv->commodity != NULL); + g_assert_cmpint (check1.hits, ==, 0); + g_assert_cmpint (check2.hits, ==, 0); sig1 = test_signal_new (&parent->inst, QOF_EVENT_MODIFY, NULL); sig2 = test_signal_new (&parent->inst, QOF_EVENT_DESTROY, NULL); @@ -972,6 +978,8 @@ test_xaccAccountCommitEdit (Fixture *fixture, gconstpointer pData) g_assert (p_priv->splits != NULL); g_assert (p_priv->parent != NULL); g_assert (p_priv->commodity != NULL); + g_assert_cmpint (check1.hits, ==, 0); + g_assert_cmpint (check2.hits, ==, 0); /* xaccAccountDestroy destroys the account by calling * qof_instance_set_destroying (), then xaccAccountCommitEdit (); */ @@ -980,6 +988,8 @@ test_xaccAccountCommitEdit (Fixture *fixture, gconstpointer pData) /* So this time we make sure that the account is destroyed */ test_signal_assert_hits (sig1, 2); test_signal_assert_hits (sig2, 1); + g_assert_cmpint (check1.hits, ==, 2); + g_assert_cmpint (check2.hits, ==, 12); /* And clean up */ test_signal_free (sig1); test_signal_free (sig2); @@ -1035,9 +1045,9 @@ test_gnc_account_insert_remove_split (Fixture *fixture, gconstpointer pData) gchar *msg2 = "gnc_account_insert_split: assertion `GNC_IS_SPLIT(acc)' failed"; guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; // gchar *log_domain = "gnc.engine"; - TestErrorStruct check1 = { loglevel, "gnc.account", msg1 }; - TestErrorStruct check2 = { loglevel, "gnc.account", msg2 }; - TestErrorStruct check3 = { loglevel, "gnc.engine", NULL }; + TestErrorStruct check1 = { loglevel, "gnc.account", msg1, 0 }; + TestErrorStruct check2 = { loglevel, "gnc.account", msg2, 0 }; + TestErrorStruct check3 = { loglevel, "gnc.engine", NULL, 0 }; guint logger; sig1 = test_signal_new (&fixture->acct->inst, QOF_EVENT_MODIFY, NULL); sig2 = test_signal_new (&fixture->acct->inst, GNC_EVENT_ITEM_ADDED, split1); @@ -1061,6 +1071,9 @@ test_gnc_account_insert_remove_split (Fixture *fixture, gconstpointer pData) test_signal_assert_hits (sig2, 0); g_log_remove_handler ("gnc.engine", logger); test_clear_error_list (); + g_assert_cmpint (check1.hits, ==, 0); + g_assert_cmpint (check2.hits, ==, 0); + g_assert_cmpint (check3.hits, ==, 4); /* Check that it works the first time */ g_assert (gnc_account_insert_split (fixture->acct, split1)); @@ -1069,6 +1082,9 @@ test_gnc_account_insert_remove_split (Fixture *fixture, gconstpointer pData) g_assert (priv->balance_dirty); test_signal_assert_hits (sig1, 1); test_signal_assert_hits (sig2, 1); + g_assert_cmpint (check1.hits, ==, 0); + g_assert_cmpint (check2.hits, ==, 0); + g_assert_cmpint (check3.hits, ==, 4); /* Check that it fails if the split has already been added once */ g_assert (!gnc_account_insert_split (fixture->acct, split1)); /* Free up hdlr2 and set up hdlr2 */ @@ -1081,6 +1097,9 @@ test_gnc_account_insert_remove_split (Fixture *fixture, gconstpointer pData) g_assert (priv->balance_dirty); test_signal_assert_hits (sig1, 2); test_signal_assert_hits (sig3, 1); + g_assert_cmpint (check1.hits, ==, 0); + g_assert_cmpint (check2.hits, ==, 0); + g_assert_cmpint (check3.hits, ==, 4); /* One more add, incrementing the editlevel to get sort_dirty set. */ test_signal_free (sig3); sig3 = test_signal_new (&fixture->acct->inst, GNC_EVENT_ITEM_ADDED, split3); @@ -1092,6 +1111,9 @@ test_gnc_account_insert_remove_split (Fixture *fixture, gconstpointer pData) g_assert (priv->balance_dirty); test_signal_assert_hits (sig1, 3); test_signal_assert_hits (sig3, 1); + g_assert_cmpint (check1.hits, ==, 0); + g_assert_cmpint (check2.hits, ==, 0); + g_assert_cmpint (check3.hits, ==, 4); /* Finally delete a split. It's going to recompute the balance, so * balance_dirty will be false. */ test_signal_free (sig3); @@ -1103,7 +1125,10 @@ test_gnc_account_insert_remove_split (Fixture *fixture, gconstpointer pData) g_assert (!priv->balance_dirty); test_signal_assert_hits (sig1, 4); test_signal_assert_hits (sig3, 1); - /* And do it again to make sure that it fails when the split has + g_assert_cmpint (check1.hits, ==, 0); + g_assert_cmpint (check2.hits, ==, 0); + g_assert_cmpint (check3.hits, ==, 4); + /* And do it again to make sure that it fails when the split has * already been removed */ g_assert (!gnc_account_remove_split (fixture->acct, split3)); g_assert_cmpuint (g_list_length (priv->splits), == , 2); @@ -1111,6 +1136,9 @@ test_gnc_account_insert_remove_split (Fixture *fixture, gconstpointer pData) g_assert (!priv->balance_dirty); test_signal_assert_hits (sig1, 4); test_signal_assert_hits (sig3, 1); + g_assert_cmpint (check1.hits, ==, 0); + g_assert_cmpint (check2.hits, ==, 0); + g_assert_cmpint (check3.hits, ==, 4); /* Clean up the handlers */ test_signal_free (sig3); test_signal_free (sig1); @@ -1400,8 +1428,8 @@ test_gnc_account_append_remove_child (Fixture *fixture, gconstpointer pData) gchar *msg1 = "[gnc_account_append_child()] reparenting accounts across books is not correctly supported\n"; gchar *msg2 = "[gnc_account_remove_child()] account not a child of parent"; guint log_handler = 0; - TestErrorStruct check_warn = {G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL, "gnc.account", msg1 }; - TestErrorStruct check_err = {G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL, "gnc.account", msg2 }; + TestErrorStruct check_warn = {G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL, "gnc.account", msg1, 0 }; + TestErrorStruct check_err = {G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL, "gnc.account", msg2, 0 }; TestSignal sig1, sig2, sig3; AccountTestFunctions *func = _utest_account_fill_functions (); AccountPrivate *frpriv = func->get_private (froot), @@ -1416,6 +1444,8 @@ test_gnc_account_append_remove_child (Fixture *fixture, gconstpointer pData) test_signal_assert_hits (sig1, 1); test_signal_assert_hits (sig2, 0); test_signal_assert_hits (sig3, 0); + g_assert_cmpint (check_warn.hits, ==, 0); + g_assert_cmpint (check_err.hits, ==, 0); g_assert (qof_instance_get_dirty (QOF_INSTANCE (froot))); g_assert (qof_instance_get_dirty (QOF_INSTANCE (account))); g_assert (g_list_find (frpriv->children, account)); @@ -1431,6 +1461,8 @@ test_gnc_account_append_remove_child (Fixture *fixture, gconstpointer pData) test_signal_assert_hits (sig1, 2); test_signal_assert_hits (sig2, 1); test_signal_assert_hits (sig3, 1); + g_assert_cmpint (check_warn.hits, ==, 1); + g_assert_cmpint (check_err.hits, ==, 0); g_assert (!qof_collection_lookup_entity ( qof_book_get_collection (fbook, GNC_ID_ACCOUNT), acct_guid)); @@ -1454,12 +1486,16 @@ test_gnc_account_append_remove_child (Fixture *fixture, gconstpointer pData) test_signal_assert_hits (sig1, 0); test_signal_assert_hits (sig2, 0); + g_assert_cmpint (check_err.hits, ==, 1); + g_assert_cmpint (check_warn.hits, ==, 1); gnc_account_remove_child (fixture->acct, account); g_assert (gnc_account_get_parent (account) == NULL); g_assert (g_list_find (apriv->children, account) == NULL); test_signal_assert_hits (sig1, 1); test_signal_assert_hits (sig2, 1); + g_assert_cmpint (check_warn.hits, ==, 1); + g_assert_cmpint (check_err.hits, ==, 1); test_signal_free (sig1); test_signal_free (sig2); xaccAccountBeginEdit (account); @@ -2039,9 +2075,9 @@ test_xaccAccountType_Stuff (void) gchar *msg2 = "[xaccAccountStringToType()] asked to translate unknown account type string (null).\n"; gchar *msg3 = "[xaccAccountStringToType()] asked to translate unknown account type string LAST.\n"; guint loghandler = 0; - TestErrorStruct check1 = {loglevel, logdomain, msg1}; - TestErrorStruct check2 = {loglevel, logdomain, msg2}; - TestErrorStruct check3 = {loglevel, logdomain, msg3}; + TestErrorStruct check1 = { loglevel, logdomain, msg1, 0 }; + TestErrorStruct check2 = { loglevel, logdomain, msg2, 0 }; + TestErrorStruct check3 = { loglevel, logdomain, msg3, 0 }; Account *acc = g_object_new (GNC_TYPE_ACCOUNT, NULL); for (type = ACCT_TYPE_NONE; type < ACCT_TYPE_LAST; type++) @@ -2093,20 +2129,23 @@ test_xaccAccountType_Stuff (void) (GLogFunc)test_null_handler, &check1); g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check1); g_assert (!xaccAccountTypeEnumAsString (ACCT_TYPE_LAST)); - g_assert_cmpstr (check1.msg, == , msg1); + g_assert_cmpint (check1.hits, ==, 1); + g_log_remove_handler (logdomain, loghandler); g_free (msg1); loghandler = g_log_set_handler (logdomain, loglevel, (GLogFunc)test_null_handler, &check2); g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check2); g_assert (!xaccAccountStringToType (NULL, &type)); - g_assert_cmpstr (check2.msg, == , msg2); + g_assert_cmpint (check2.hits, ==, 1); + g_log_remove_handler (logdomain, loghandler); loghandler = g_log_set_handler (logdomain, loglevel, (GLogFunc)test_null_handler, &check3); g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check3); g_assert (!xaccAccountStringToType ("LAST", &type)); - g_assert_cmpstr (check3.msg, == , msg3); + g_assert_cmpint (check3.hits, ==, 1); + g_log_remove_handler (logdomain, loghandler); @@ -2140,8 +2179,8 @@ test_xaccAccountType_Compatibility (void) gchar *msg2 = g_strdup_printf ("[xaccParentAccountTypesCompatibleWith()] bad account type: %d", ACCT_TYPE_SAVINGS); gchar *logdomain = "gnc.account"; guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - TestErrorStruct check1 = { loglevel, logdomain, msg1 }; - TestErrorStruct check2 = { loglevel, logdomain, msg2 }; + TestErrorStruct check1 = { loglevel, logdomain, msg1, 0 }; + TestErrorStruct check2 = { loglevel, logdomain, msg2, 0 }; gint loghandler; for (type = ACCT_TYPE_BANK; type < NUM_ACCOUNT_TYPES; type++) @@ -2156,7 +2195,7 @@ test_xaccAccountType_Compatibility (void) compat = xaccParentAccountTypesCompatibleWith (type); g_log_remove_handler (logdomain, loghandler); g_assert_cmpint (compat, == , 0); - g_assert_cmpstr (check1.msg, == , msg1); + g_assert_cmpint (check1.hits, ==, 1); g_free (msg1); continue; } @@ -2184,7 +2223,7 @@ test_xaccAccountType_Compatibility (void) compat = xaccParentAccountTypesCompatibleWith (++type); g_log_remove_handler (logdomain, loghandler); g_assert_cmpint (compat, == , 0); - g_assert_cmpstr (check2.msg, == , msg2); + g_assert_cmpint (check2.hits, ==, 1); g_free (msg2); } /* More KVP getters & setters @@ -2290,7 +2329,7 @@ test_gnc_account_merge_children (Fixture *fixture, gconstpointer pData) gchar *logdomain = "gnc.engine"; gint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; gchar *msg = "[xaccSplitCommitEdit ()] Account grabbed split prematurely."; - TestErrorStruct quiet = { loglevel, logdomain, msg }; + TestErrorStruct quiet = { loglevel, logdomain, msg, 0 }; guint hdlr = g_log_set_handler (logdomain, loglevel, (GLogFunc)test_null_handler, &quiet); g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &quiet); diff --git a/src/engine/test/utest-Split.c b/src/engine/test/utest-Split.c index fc700f10fe..c368989078 100644 --- a/src/engine/test/utest-Split.c +++ b/src/engine/test/utest-Split.c @@ -374,7 +374,7 @@ test_xaccSplitEqualCheckBal (Fixture *fixture, gconstpointer pData) { gchar *msg = "[xaccSplitEqualCheckBal()] test balances differ: 123/100 vs 456/100"; guint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL, hdlr; - TestErrorStruct check = { loglevel, "gnc.engine", msg }; + TestErrorStruct check = { loglevel, "gnc.engine", msg, 0 }; GLogFunc oldlogger; gnc_numeric foo = gnc_numeric_create (123, 100); @@ -389,6 +389,7 @@ test_xaccSplitEqualCheckBal (Fixture *fixture, gconstpointer pData) g_assert_cmpint (fixture->func->xaccSplitEqualCheckBal ("test ", foo, foo), ==, TRUE); g_assert_cmpint (fixture->func->xaccSplitEqualCheckBal ("test ", foo, bar), ==, FALSE); + g_assert_cmpint (check.hits, ==, 2); g_log_remove_handler ("gnc.engine", hdlr); test_clear_error_list (); @@ -418,10 +419,10 @@ test_xaccSplitEqual (Fixture *fixture, gconstpointer pData) gchar *msg14 = "[xaccSplitEqualCheckBal()] reconciled balances differ: 321/1000 vs 0/1"; gchar *logdomain = "gnc.engine"; guint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL; - TestErrorStruct checkA = { loglevel, logdomain, msg01 }; - TestErrorStruct checkB = { loglevel, logdomain, msg10 }; - TestErrorStruct checkC = { loglevel, logdomain, msg11 }; - TestErrorStruct checkD = { loglevel, logdomain, msg14 }; + TestErrorStruct checkA = { loglevel, logdomain, msg01, 0 }; + TestErrorStruct checkB = { loglevel, logdomain, msg10, 0 }; + TestErrorStruct checkC = { loglevel, logdomain, msg11, 0 }; + TestErrorStruct checkD = { loglevel, logdomain, msg14, 0 }; guint hdlr; GLogFunc oldlogger; oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, &checkA); @@ -436,6 +437,10 @@ test_xaccSplitEqual (Fixture *fixture, gconstpointer pData) /* Test that a NULL comparison fails */ g_assert (xaccSplitEqual (fixture->split, NULL, TRUE, TRUE, TRUE) == FALSE); g_assert (xaccSplitEqual (NULL, split1, TRUE, TRUE, TRUE) == FALSE); + g_assert_cmpint (checkA.hits, ==, 4); + g_assert_cmpint (checkB.hits, ==, 0); + g_assert_cmpint (checkC.hits, ==, 0); + g_assert_cmpint (checkD.hits, ==, 0); checkA.msg = msg02; /* Clone creates splits with different GUIDs: Make sure that it fails comparison */ g_assert (xaccSplitEqual (fixture->split, split1, TRUE, TRUE, TRUE) == FALSE); @@ -445,6 +450,10 @@ test_xaccSplitEqual (Fixture *fixture, gconstpointer pData) (GLogFunc)test_list_handler, &checkA); g_assert (xaccSplitEqual (fixture->split, split1, FALSE, TRUE, TRUE) == FALSE); /* Now set split1's parent so that it passes -- we're also checking that the GUID check is disabled when we pass FALSE to check_guids */ + g_assert_cmpint (checkA.hits, ==, 6); + g_assert_cmpint (checkB.hits, ==, 2); + g_assert_cmpint (checkC.hits, ==, 2); + g_assert_cmpint (checkD.hits, ==, 0); split1->parent = fixture->split->parent; g_log_remove_handler (logdomain, hdlr); hdlr = g_log_set_handler (logdomain, loglevel, @@ -455,6 +464,10 @@ test_xaccSplitEqual (Fixture *fixture, gconstpointer pData) "guid", qof_instance_get_guid (QOF_INSTANCE(fixture->split)), NULL); g_assert (xaccSplitEqual (fixture->split, split1, TRUE, TRUE, TRUE) == TRUE); + g_assert_cmpint (checkA.hits, ==, 6); + g_assert_cmpint (checkB.hits, ==, 2); + g_assert_cmpint (checkC.hits, ==, 2); + g_assert_cmpint (checkD.hits, ==, 0); /* Change the memo and action and test that each in turn causes the comparison to fail */ split1->memo = "baz"; msg03 = g_strdup_printf ("[xaccSplitEqual()] memos differ: (%p)%s vs (%p)%s", @@ -462,6 +475,10 @@ test_xaccSplitEqual (Fixture *fixture, gconstpointer pData) split1->memo, split1->memo); checkA.msg = msg03; g_assert (xaccSplitEqual (fixture->split, split1, TRUE, TRUE, TRUE) == FALSE); + g_assert_cmpint (checkA.hits, ==, 8); + g_assert_cmpint (checkB.hits, ==, 2); + g_assert_cmpint (checkC.hits, ==, 2); + g_assert_cmpint (checkD.hits, ==, 0); split1->memo = fixture->split->memo; split1->action = "bar"; checkA.msg = msg04; @@ -470,10 +487,18 @@ test_xaccSplitEqual (Fixture *fixture, gconstpointer pData) hdlr = g_log_set_handler (logdomain, loglevel, (GLogFunc)test_list_handler, &checkA); g_assert (xaccSplitEqual (fixture->split, split1, TRUE, TRUE, TRUE) == FALSE); + g_assert_cmpint (checkA.hits, ==, 12); + g_assert_cmpint (checkB.hits, ==, 2); + g_assert_cmpint (checkC.hits, ==, 2); + g_assert_cmpint (checkD.hits, ==, 0); /* Split2 doesn't have balances copied from fixture->split, so the balance test fails */ checkB.msg = msg12; checkC.msg = msg13; g_assert (xaccSplitEqual (fixture->split, split2, TRUE, TRUE, TRUE) == FALSE); + g_assert_cmpint (checkA.hits, ==, 12); + g_assert_cmpint (checkB.hits, ==, 4); + g_assert_cmpint (checkC.hits, ==, 2); + g_assert_cmpint (checkD.hits, ==, 0); test_clear_error_list (); g_assert (xaccSplitEqual (fixture->split, split2, TRUE, FALSE, TRUE) == TRUE); g_object_unref (split1); @@ -514,8 +539,8 @@ test_xaccSplitCommitEdit (Fixture *fixture, gconstpointer pData) gchar *logdomain = "gnc.engine"; guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; guint hdlr; - TestErrorStruct checkA = { loglevel, logdomain, msg1 }; - TestErrorStruct checkB = { loglevel, logdomain, msg2 }; + TestErrorStruct checkA = { loglevel, logdomain, msg1, 0 }; + TestErrorStruct checkB = { loglevel, logdomain, msg2, 0 }; TestSignal sig1, sig2; TestErr error = { 0, ERR_BACKEND_NO_ERR }; Account *oacc = xaccMallocAccount (xaccSplitGetBook (fixture->split)); @@ -551,6 +576,8 @@ test_xaccSplitCommitEdit (Fixture *fixture, gconstpointer pData) g_assert_cmpint (error.lasterr, ==, ERR_BACKEND_NO_ERR); g_assert (fixture->split->orig_acc == fixture->split->acc); g_assert (fixture->split->orig_parent == fixture->split->parent); + g_assert_cmpint (checkA.hits, ==, 4); + g_assert_cmpint (checkB.hits, ==, 2); g_log_remove_handler (logdomain, hdlr); qof_instance_mark_clean (QOF_INSTANCE (fixture->split->parent)); @@ -571,6 +598,8 @@ test_xaccSplitCommitEdit (Fixture *fixture, gconstpointer pData) g_assert (qof_instance_is_dirty (QOF_INSTANCE (fixture->split))); test_signal_assert_hits (sig1, 1); test_signal_assert_hits (sig2, 4); + g_assert_cmpint (checkA.hits, ==, 4); + g_assert_cmpint (checkB.hits, ==, 2); g_assert_cmpint (error.hits, ==, 0); g_assert_cmpint (error.lasterr, ==, ERR_BACKEND_NO_ERR); g_assert (fixture->split->orig_acc == fixture->split->acc); @@ -838,7 +867,7 @@ test_xaccSplitSetBaseValue (Fixture *fixture, gconstpointer pData) "given split currency=%s and commodity=%s\n"; gchar *logdomain = "gnc.engine"; guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - TestErrorStruct check = { loglevel, logdomain, msg1 }; + TestErrorStruct check = { loglevel, logdomain, msg1, 0 }; gnc_numeric value = { 360, 240 }; gnc_numeric old_val = fixture->split->value; gnc_numeric old_amt = fixture->split->amount; @@ -851,6 +880,7 @@ test_xaccSplitSetBaseValue (Fixture *fixture, gconstpointer pData) xaccSplitSetBaseValue (fixture->split, value, fixture->comm); g_assert (!qof_instance_is_dirty (QOF_INSTANCE (fixture->split))); xaccTransRollbackEdit (fixture->split->parent); + g_assert_cmpint (check.hits, ==, 1); /* Base currency == currency, != commodity */ fixture->split->acc = acc; xaccSplitSetBaseValue (fixture->split, value, fixture->curr); @@ -859,6 +889,7 @@ test_xaccSplitSetBaseValue (Fixture *fixture, gconstpointer pData) g_assert_cmpint (fixture->split->amount.num, ==, 321); g_assert_cmpint (fixture->split->amount.denom, ==, 1000); g_assert (qof_instance_is_dirty (QOF_INSTANCE (fixture->split))); + g_assert_cmpint (check.hits, ==, 1); /* Base currency == currency, == commodity */ qof_instance_mark_clean (QOF_INSTANCE (fixture->split)); @@ -872,6 +903,7 @@ test_xaccSplitSetBaseValue (Fixture *fixture, gconstpointer pData) g_assert_cmpint (fixture->split->amount.num, ==, 360); g_assert_cmpint (fixture->split->amount.denom, ==, 240); g_assert (qof_instance_is_dirty (QOF_INSTANCE (fixture->split))); + g_assert_cmpint (check.hits, ==, 1); /* Base currency != currency, == commodity */ qof_instance_mark_clean (QOF_INSTANCE (fixture->split)); fixture->split->value = old_val; @@ -882,6 +914,7 @@ test_xaccSplitSetBaseValue (Fixture *fixture, gconstpointer pData) g_assert_cmpint (fixture->split->amount.num, ==, 1500); g_assert_cmpint (fixture->split->amount.denom, ==, 1000); g_assert (qof_instance_is_dirty (QOF_INSTANCE (fixture->split))); + g_assert_cmpint (check.hits, ==, 1); /* Base currency != currency, != commodity */ check.msg = g_strdup_printf (fmt, gnc_commodity_get_printname (gnaira), @@ -895,6 +928,7 @@ test_xaccSplitSetBaseValue (Fixture *fixture, gconstpointer pData) xaccAccountSetCommodity(fixture->split->acc, fixture->comm); xaccSplitSetBaseValue (fixture->split, value, gnaira); g_assert (!qof_instance_is_dirty (QOF_INSTANCE (fixture->split))); + g_assert_cmpint (check.hits, ==, 2); g_free (check.msg); g_log_set_default_handler (oldlogger, NULL); @@ -933,7 +967,7 @@ test_xaccSplitConvertAmount (void) gchar *logdomain = "gnc.engine"; guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - TestErrorStruct check = { loglevel, logdomain, NULL }; + TestErrorStruct check = { loglevel, logdomain, NULL, 0 }; GLogFunc oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, &check); check.msg = g_strdup_printf ("[xaccSplitConvertAmount()] The split's (%s) amount can't be converted from GNCXX into GNM.", guid_to_string(xaccSplitGetGUID(o_split))); @@ -976,18 +1010,20 @@ test_xaccSplitConvertAmount (void) &check); result = xaccSplitConvertAmount (split, ya_acc); g_assert (gnc_numeric_zero_p (result)); - + g_assert_cmpint (check.hits, ==, 1); /* Transaction isn't balanced, split has 0 value, returns that */ split->value = gnc_numeric_zero (); result = xaccSplitConvertAmount (split, o_acc); g_assert (gnc_numeric_zero_p (result)); + g_assert_cmpint (check.hits, ==, 1); /* Transaction isn't balanced, compute a conversion */ split->value = gnc_numeric_create (71330, 240); result = xaccSplitConvertAmount (split, o_acc); g_assert_cmpint (result.num, ==, -402131); g_assert_cmpint (result.denom, ==, 1000); + g_assert_cmpint (check.hits, ==, 1); test_destroy (split); test_destroy (acc); @@ -1489,7 +1525,7 @@ test_xaccSplitSetParent (Fixture *fixture, gconstpointer pData) /* FIXME: This error doesn't actually stop execution, so we need to test for it happening. */ gchar *msg = "[xaccSplitSetParent()] You may not add the split to more" " than one transaction during the BeginEdit/CommitEdit block."; - TestErrorStruct check = { loglevel, logdomain, msg }; + TestErrorStruct check = { loglevel, logdomain, msg, 0 }; GLogFunc oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, &check); g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check); @@ -1505,6 +1541,7 @@ test_xaccSplitSetParent (Fixture *fixture, gconstpointer pData) test_signal_assert_hits (sig1, 1); test_signal_assert_hits (sig2, 1); g_assert (qof_instance_is_dirty (QOF_INSTANCE (split))); + g_assert_cmpint (check.hits, ==, 1); test_signal_free (sig1); test_signal_free (sig2); @@ -1524,7 +1561,7 @@ test_xaccSplitGetSharePrice (Fixture *fixture, gconstpointer pData) const guint PRICE_SIGFIGS = 6; char *logdomain = "gnc.engine"; guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL; - TestErrorStruct check = { loglevel, logdomain, NULL }; + TestErrorStruct check = { loglevel, logdomain, NULL, 0 }; guint hdlr = g_log_set_handler (logdomain, loglevel, (GLogFunc)test_checked_handler, &check); GLogFunc oldhandler = g_log_set_default_handler ((GLogFunc)test_null_handler, &check); @@ -1541,16 +1578,19 @@ test_xaccSplitGetSharePrice (Fixture *fixture, gconstpointer pData) result = xaccSplitGetSharePrice (split); g_assert (gnc_numeric_equal (result, expected)); + g_assert_cmpint (check.hits, ==, 0); expected = gnc_numeric_create (0, 1); split->amount = gnc_numeric_zero (); result = xaccSplitGetSharePrice (split); g_assert (gnc_numeric_equal (result, expected)); + g_assert_cmpint (check.hits, ==, 0); split->value = gnc_numeric_zero (); expected = gnc_numeric_create (1, 1); result = xaccSplitGetSharePrice (split); g_assert (gnc_numeric_equal (result, expected)); + g_assert_cmpint (check.hits, ==, 0); /* Now invent some value/ammount pairs which cause numeric errors to test the limits */ split->amount = gnc_numeric_create (987654321, 10); @@ -1570,6 +1610,7 @@ test_xaccSplitGetSharePrice (Fixture *fixture, gconstpointer pData) expected = gnc_numeric_create (0, 1); result = xaccSplitGetSharePrice (split); g_assert (gnc_numeric_equal (result, expected)); + g_assert_cmpint (check.hits, ==, 2); g_free (check.msg); split->amount = gnc_numeric_create (987654321, 10); @@ -1589,6 +1630,7 @@ test_xaccSplitGetSharePrice (Fixture *fixture, gconstpointer pData) expected = gnc_numeric_create (0, 1); result = xaccSplitGetSharePrice (split); g_assert (gnc_numeric_equal (result, expected)); + g_assert_cmpint (check.hits, ==, 4); g_free (check.msg); split->amount = gnc_numeric_create (9, 0); @@ -1608,6 +1650,7 @@ test_xaccSplitGetSharePrice (Fixture *fixture, gconstpointer pData) expected = gnc_numeric_create (0, 1); result = xaccSplitGetSharePrice (split); g_assert (gnc_numeric_equal (result, expected)); + g_assert_cmpint (check.hits, ==, 6); g_free (check.msg); g_log_remove_handler (logdomain, hdlr); diff --git a/src/test-core/unittest-support.c b/src/test-core/unittest-support.c index 67edbfcc5a..1e2ece15e3 100644 --- a/src/test-core/unittest-support.c +++ b/src/test-core/unittest-support.c @@ -39,6 +39,7 @@ test_null_handler (const char *log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data ) { //Silent, remember? + return FALSE; } @@ -96,7 +97,10 @@ test_list_handler (const char *log_domain, GLogLevelFlags log_level, if (!g_strcmp0 (log_domain, error->log_domain) && ((log_level | fatal) == (error->log_level | fatal)) && !g_strcmp0 (msg, error->msg)) + { + ++(error->hits); return FALSE; + } list = g_list_next (list); } /* No list or no matches, fall through */ @@ -122,6 +126,7 @@ test_checked_handler (const char *log_domain, GLogLevelFlags log_level, g_assert (log_level ^ G_LOG_FLAG_FATAL); return FALSE; } + ++(tdata->hits); return FALSE; } diff --git a/src/test-core/unittest-support.h b/src/test-core/unittest-support.h index 00e2ebd78f..9253953a4c 100644 --- a/src/test-core/unittest-support.h +++ b/src/test-core/unittest-support.h @@ -74,6 +74,7 @@ typedef struct GLogLevelFlags log_level; gchar *log_domain; gchar *msg; + guint hits; } TestErrorStruct; /**