<div dir="ltr"><div dir="ltr">Without the call to g_test_init, the check in test-qofinstance.cpp<br>fails on: EXPECT_STREQ( error_message, "[qof_commit_edit()] unbalanced<br>call - resetting (was -2)" ). The error message is set in the local<br>fatal_handler which is set in the test with<br>g_test_log_set_fatal_handler.<br><br>The same test also does the g_log_set_handler. to the<br>test_checked_handler method which is in unittest-support.c.  It sets<br>this up to print out the error, but ignore it (if it does NOT match<br>the way that test_error_struct is setup).  But the way it is setup<br>does not match, because it is setup with level of critical or fatal,<br>which does not match critical.<br><br>Conclusion: The g_test_log_set_fatal_handler only does something when<br>g_test_init is called.  Conversely, g_log_set_handler only does<br>something when g_test_init is not called.  So, the test code should<br>never use both, and only one or the other depending on if it is a<br>google test or glib test.<br><br>To fix the code for the conversion to google test I am doing:<br>1. Remove the g_test_init. (per recomendation)<br>2. Remove the local fatal_handler, and error_message.  (It had been<br>   referenced in one other test, but not used.)<br>3. Remove the check from the (now unused) error_message, and add the<br>   check for number of hits to the test_error_struct.<br>4. Fix the log level to just be the expected G_LOG_LEVEL_CRITICAL<br>   (removing the or fatal.)<br><br>This now passes and does the same checks as before.<br><br><br><br>When I debug, I like to use a 3 step method:<br>1. Fix the issue (which is the above)<br>2. Now that I know this was a problem, find and fix all similar<br>   problems. (Below.)<br>   a) Looking for other loglevel = with combined levels --> I have<br>      found many. At least some of which are part of glibtest,<br>      possibly all, possibly only in libgnucash/engine.<br>   b) Looking for g_log_set_handler I found many, but suspect ones are<br>      in libgnucash/engine.<br>   c) There are multiple places that call both<br>      g_test_log_set_fatal_handler and<br>      g_test_log_set_fatal_handler. Maybe my interpretation above is<br>      wrong, but I tested in the one case above.  If I am right this<br>      code is extra in one way or another.<br>3. Think about what went wrong and keep it for getting this far.<br>   a) g_log_set_handler should assert/fail if it is called after<br>      g_test_init.  This is difficult since we don't want to change<br>      glib.  The other solution is to replace g_log_set_handler with a<br>      macro that asserts on the check for g_test_init having been<br>      called, and then calls g_log_set_handler.<br>   b) g_test_log_set_fatal_handler should assert if it is called<br>      without calling g_test_init first.<br><br><br>I'm not sure how to proceed with steps 2 and 3.<br><br>Both 3a and 3b would only affect test code, so this may be a good<br>idea.  But, this will inject a bunch of errors into the tests.  Those<br>would have to be fixed as part of this commit.  Those fixed would<br>remove code that is closer for google test instead of closer to glib<br>test.<br><br>Maybe my approach should be as follows:<br>1. convert all existing test_qof (glib) to google test without adding<br>   more coverage.<br>2. convert all the test-engine tests to google without adding more<br>   coverage.<br>3. (Possibly) change the engine tests that use do_test mechanism tests<br>   to google test without adding more coverage.<br>4. The remaining glib tests are outside of engine.<br>   import-export/aqb/test/test-aqb<br>   import-export/test/test-import-pending-matches<br>   register/ledger-core/test/test-split-register<br>   backend/dbi/test/test-backend-dbi backend/sql/test/test-sqlbe<br>   core-utils/test/test-gnc-glib-utils<br><br>    I'm not sure if converting these, or fixing these for step 3a, 3b<br>   above, or ignoring this is the right step.<br>5. Adding more coverage to engine.<br><br></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Thu, Jan 22, 2026 at 7:46 PM John Ralls <<a href="mailto:jralls@ceridwen.us">jralls@ceridwen.us</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
> On Jan 22, 2026, at 5:44 AM, Stefan Koch <<a href="mailto:stefan.koch.micro@gmail.com" target="_blank">stefan.koch.micro@gmail.com</a>> wrote:<br>
> <br>
> I think the g_test_init is necessary mainly for the g_test_log_set_fatal_handler and/or the g_log_set_handler. So, I think I will need it even after I replace the glib random numbers.  <br>
> <br>
<br>
Stefan,<br>
<br>
No, they’re both implemented in glib/gmessages.c with no reference to the test system. In fact you might not need to set the fatal handler if you don’t call g_test_init: The first thing it does is set the fatal mask to CRITICAL, ERROR, an WARNING. Normally only CRITICAL is fatal.<br>
<br>
For an example that uses g_log_set_handler without g_test_init see <a href="https://github.com/Gnucash/gnucash/blob/stable/libgnucash/backend/xml/test/gtest-load-save-files.cpp" rel="noreferrer" target="_blank">https://github.com/Gnucash/gnucash/blob/stable/libgnucash/backend/xml/test/gtest-load-save-files.cpp</a><br>
<br>
Regards,<br>
John Ralls<br>
<br>
<br>
</blockquote></div></div>