From 777074f482b6055164b007749182d0c1d65f0319 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 24 Mar 2012 22:20:08 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22113 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/test-core/test-stuff.c | 8 +++++--- src/test-core/test-stuff.h | 15 +++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/test-core/test-stuff.c b/src/test-core/test-stuff.c index 6e4ef920fa..28b776d8d1 100644 --- a/src/test-core/test-stuff.c +++ b/src/test-core/test-stuff.c @@ -541,9 +541,11 @@ test_signal_free (TestSignal sigp) 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; +} + } diff --git a/src/test-core/test-stuff.h b/src/test-core/test-stuff.h index 748b4d6d96..288309f491 100644 --- a/src/test-core/test-stuff.h +++ b/src/test-core/test-stuff.h @@ -268,11 +268,18 @@ const char* get_random_string_in_array(const char* str_list[]); 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: