r22113 - gnucash/trunk/src/test-core - Testing: Rewrite test_signal_assert_hits as a function/macro combination

John Ralls jralls at code.gnucash.org
Sat Mar 24 18:20:08 EDT 2012


Author: jralls
Date: 2012-03-24 18:20:08 -0400 (Sat, 24 Mar 2012)
New Revision: 22113
Trac: http://svn.gnucash.org/trac/changeset/22113

Modified:
   gnucash/trunk/src/test-core/test-stuff.c
   gnucash/trunk/src/test-core/test-stuff.h
Log:
Testing: Rewrite test_signal_assert_hits as a function/macro combination

Now the assert reports the location in the test program where it fails instead of inside test-stuff.c.

Modified: gnucash/trunk/src/test-core/test-stuff.c
===================================================================
--- gnucash/trunk/src/test-core/test-stuff.c	2012-03-24 22:19:58 UTC (rev 22112)
+++ gnucash/trunk/src/test-core/test-stuff.c	2012-03-24 22:20:08 UTC (rev 22113)
@@ -541,9 +541,11 @@
     g_slice_free (_TestSignal, sig);
 }
 
-void
-test_signal_assert_hits (TestSignal sigp, guint hits)
+guint
+test_signal_return_hits (TestSignal sigp)
 {
     _TestSignal *sig = (_TestSignal *)sigp;
-    g_assert_cmpint (sig->hits, == , hits);
+    return sig->hits;
 }
+
+}

Modified: gnucash/trunk/src/test-core/test-stuff.h
===================================================================
--- gnucash/trunk/src/test-core/test-stuff.h	2012-03-24 22:19:58 UTC (rev 22112)
+++ gnucash/trunk/src/test-core/test-stuff.h	2012-03-24 22:20:08 UTC (rev 22113)
@@ -268,11 +268,18 @@
 typedef gpointer TestSignal;
 TestSignal test_signal_new (QofInstance *entity, QofEventId eventType,
                             gpointer event_data);
-/* test_signal_assert_hits calls g_assert_cmpuint with an ==
- * operator. Use it in a test program to see if a TestSignal has been
- * emitted the number of times you expect.
+/* test_signal_return_hits gets the number of times the TestSignal has
+ * been called.
  */
-void test_signal_assert_hits (TestSignal sig, guint hits);
+guint test_signal_return_hits (TestSignal sig);
+
+/* test_signal_assert_hits is a convenience macro which wraps
+ * test_signal_return_hits with and equality assertion.
+ */
+
+#define test_signal_assert_hits(sig, hits) \
+    g_assert_cmpint (test_signal_return_hits (sig), ==, hits)
+
 void test_signal_free (TestSignal sig);
 
 /* For Scheme testing access:



More information about the gnucash-changes mailing list