r21702 - gnucash/trunk/src/libqof/qof/test - [Testing] Stifle error messages from QOF testing.

John Ralls jralls at code.gnucash.org
Fri Dec 9 18:50:04 EST 2011


Author: jralls
Date: 2011-12-09 18:50:03 -0500 (Fri, 09 Dec 2011)
New Revision: 21702
Trac: http://svn.gnucash.org/trac/changeset/21702

Modified:
   gnucash/trunk/src/libqof/qof/test/Makefile.am
   gnucash/trunk/src/libqof/qof/test/test-qofbook.c
   gnucash/trunk/src/libqof/qof/test/test-qofinstance.c
Log:
[Testing] Stifle error messages from QOF testing.

Modified: gnucash/trunk/src/libqof/qof/test/Makefile.am
===================================================================
--- gnucash/trunk/src/libqof/qof/test/Makefile.am	2011-12-09 23:49:50 UTC (rev 21701)
+++ gnucash/trunk/src/libqof/qof/test/Makefile.am	2011-12-09 23:50:03 UTC (rev 21702)
@@ -31,7 +31,10 @@
 
 #The tests might require more libraries, but try to keep them
 #as independent as possible.
-test_qof_LDADD = ${top_builddir}/${MODULEPATH}/libgnc-qof.la $(GLIB_LIBS)
+test_qof_LDADD = \
+	${top_builddir}/${MODULEPATH}/libgnc-qof.la \
+	${top_builddir}/src/test-core/.libs/libtest-core.la \
+	$(GLIB_LIBS)
 
 test_qof_CFLAGS = \
 	${DEFAULT_INCLUDES} \

Modified: gnucash/trunk/src/libqof/qof/test/test-qofbook.c
===================================================================
--- gnucash/trunk/src/libqof/qof/test/test-qofbook.c	2011-12-09 23:49:50 UTC (rev 21701)
+++ gnucash/trunk/src/libqof/qof/test/test-qofbook.c	2011-12-09 23:50:03 UTC (rev 21702)
@@ -550,9 +550,19 @@
     QofCollection *m_col, *m_col2;
     QofIdType my_type = "my_type", my_type2 = "my_type2";
     guint param = (guint) g_test_rand_int();
+    gchar *msg1 = "qof_book_foreach_collection: assertion `book' failed";
+    gchar *msg2 = "qof_book_foreach_collection: assertion `cb' failed";
+    gchar *log_domain = "qof";
+    guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL, hdlr;
+    TestErrorStruct check1 = { loglevel, log_domain, msg1 };
+    TestErrorStruct check2 = { loglevel, log_domain, msg2 };
 
     /* need this as long as we have fatal warnings enabled */
     g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )handle_faults, NULL );
+    test_add_error (&check1);
+    test_add_error (&check2);
+    hdlr = g_log_set_handler (log_domain, loglevel,
+			      (GLogFunc)test_list_handler, NULL);
 
     g_test_message( "Testing when book is null" );
     m_col = qof_book_get_collection( fixture->book, my_type );
@@ -574,6 +584,8 @@
     g_assert( !col_struct.col2_called );
     g_assert_cmpstr( test_struct.msg, == , "qof_book_foreach_collection: assertion `cb' failed" );
     g_free( test_struct.msg );
+    g_log_remove_handler (log_domain, hdlr);
+    test_clear_error_list ();
 
     g_test_message( "Testing when book and cb not null, user_data provided" );
     /* both cols have to be called */

Modified: gnucash/trunk/src/libqof/qof/test/test-qofinstance.c
===================================================================
--- gnucash/trunk/src/libqof/qof/test/test-qofinstance.c	2011-12-09 23:49:50 UTC (rev 21701)
+++ gnucash/trunk/src/libqof/qof/test/test-qofinstance.c	2011-12-09 23:50:03 UTC (rev 21702)
@@ -116,6 +116,13 @@
     QofInstanceClass *klass;
     /* test var */
     Timespec *timespec_priv;
+    gchar *msg1 = "qof_instance_get_collection: assertion `QOF_IS_INSTANCE(ptr)' failed";
+    gchar *msg2 = "qof_instance_get_editlevel: assertion `QOF_IS_INSTANCE(ptr)' failed";
+    gchar *msg3 = "qof_instance_get_destroying: assertion `QOF_IS_INSTANCE(ptr)' failed";
+    gchar *msg4 = "qof_instance_get_dirty_flag: assertion `QOF_IS_INSTANCE(ptr)' failed";
+    gchar *log_domain = "qof";
+    guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL, hdlr;
+    TestErrorStruct check = { loglevel, log_domain, msg1 };
 
     g_test_message( "Testing qofinstance object initialization" );
     inst = g_object_new(QOF_TYPE_INSTANCE, NULL);
@@ -149,21 +156,27 @@
     g_assert( !QOF_IS_INSTANCE( inst ) );
     /* set fatal handler */
     g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )fatal_handler, NULL );
+    hdlr = g_log_set_handler (log_domain, loglevel,
+			      (GLogFunc)test_checked_handler, &check);
     g_assert( qof_instance_get_collection( inst ) == NULL );
     g_assert( g_strrstr( error_message, "assertion `QOF_IS_INSTANCE(ptr)' failed" ) != NULL );
     g_free( error_message );
 
+    check.msg = msg2;
     g_assert_cmpint( qof_instance_get_editlevel( inst ), == , 0 );
     g_assert( g_strrstr( error_message, "assertion `QOF_IS_INSTANCE(ptr)' failed" ) != NULL );
     g_free( error_message );
 
+    check.msg = msg3;
     g_assert( !qof_instance_get_destroying( inst ) );
     g_assert( g_strrstr( error_message, "assertion `QOF_IS_INSTANCE(ptr)' failed" ) != NULL );
     g_free( error_message );
 
+    check.msg = msg4;
     g_assert( !qof_instance_get_dirty_flag( inst ) );
     g_assert( g_strrstr( error_message, "assertion `QOF_IS_INSTANCE(ptr)' failed" ) != NULL );
     g_free( error_message );
+    g_log_remove_handler (log_domain, hdlr);
 }
 
 static void
@@ -479,6 +492,10 @@
 test_instance_commit_edit( Fixture *fixture, gconstpointer pData )
 {
     gboolean result;
+    gchar *msg = "[qof_commit_edit()] unbalanced call - resetting (was -2)";
+    gchar *log_domain = "qof.engine";
+    guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL, hdlr;
+    TestErrorStruct check = { loglevel, log_domain, msg };
 
     g_test_message( "Test when instance set to null" );
     result = qof_commit_edit( NULL );
@@ -499,12 +516,15 @@
 
     g_test_message( "Test when instance's editlevel < 0" );
     g_test_log_set_fatal_handler ( ( GTestLogFatalFunc )fatal_handler, NULL );
+    hdlr = g_log_set_handler (log_domain, loglevel,
+			      (GLogFunc)test_checked_handler, &check);
     qof_instance_decrease_editlevel( fixture->inst );
     g_assert_cmpint( qof_instance_get_editlevel( fixture->inst ), == , -1 );
     result = qof_commit_edit( fixture->inst );
     g_assert_cmpint( qof_instance_get_editlevel( fixture->inst ), == , 0 );
     g_assert_cmpstr( error_message, == , "[qof_commit_edit()] unbalanced call - resetting (was -2)" );
     g_free( error_message );
+    g_log_remove_handler (log_domain, hdlr);
 }
 
 /* backend commit test start */



More information about the gnucash-changes mailing list