GnuCash c935c2f+
Loading...
Searching...
No Matches
unittest-support.h
Go to the documentation of this file.
1/********************************************************************
2 * unittest-support.h: Support structures for GLib Unit Testing *
3 * Copyright 2011-12 John Ralls <jralls@ceridwen.us> *
4 * Copyright 2011 Muslim Chochlov <muslim.chochlov@gmail.com> *
5 * *
6 * This program is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU General Public License as *
8 * published by the Free Software Foundation; either version 2 of *
9 * the License, or (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License*
17 * along with this program; if not, contact: *
18 * *
19 * Free Software Foundation Voice: +1-617-542-5942 *
20 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
21 * Boston, MA 02110-1301, USA gnu@gnu.org *
22********************************************************************/
23#ifndef UNITTEST_SUPPORT_H
24#define UNITTEST_SUPPORT_H
25
26#include <glib.h>
27#include <qof.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
50#define GNC_TEST_ADD( suite, path, fixture, data, setup, test, teardown )\
51{\
52 gchar *testpath = g_strdup_printf( "%s/%s", suite, path );\
53 g_test_add( testpath, fixture, data, setup, test, teardown );\
54 g_free( testpath );\
55}
56
61#define GNC_TEST_ADD_FUNC( suite, path, test )\
62{\
63 gchar *testpath = g_strdup_printf( "%s/%s", suite, path );\
64 g_test_add_func( testpath, test );\
65 g_free( testpath );\
66}
102typedef struct
103{
104 GLogLevelFlags log_level;
105 char *log_domain;
106 char *msg;
107 guint hits;
109
123TestErrorStruct* test_error_struct_new (const char *log_domain,
124 const GLogLevelFlags log_level,
125 const char *msg);
126
132
138typedef struct
139{
140 TestErrorStruct *error;
141 gint handler;
142 gboolean list_handler;
144
145
159GSList *test_log_set_handler (GSList *list, TestErrorStruct *error,
160 GLogFunc handler);
161
178GSList *test_log_set_fatal_handler (GSList *list, TestErrorStruct *error,
179 GLogFunc handler);
180
184void test_free_log_handler (gpointer item);
185
192gboolean test_checked_substring_handler (const char *log_domain, GLogLevelFlags log_level,
193 const gchar *msg, gpointer user_data);
200gboolean test_checked_handler (const char *log_domain, GLogLevelFlags log_level,
201 const gchar *msg, gpointer user_data);
202
209gboolean test_log_handler (const char *log_domain, GLogLevelFlags log_level,
210 const gchar *msg, gpointer user_data);
215gboolean test_null_handler (const char *log_domain, GLogLevelFlags log_level,
216 const gchar *msg, gpointer user_data );
226void test_add_error (TestErrorStruct *error);
227void test_clear_error_list (void);
228
238gboolean test_list_substring_handler (const char *log_domain, GLogLevelFlags log_level,
239 const gchar *msg, gpointer user_data);
240
248gboolean test_list_handler (const char *log_domain,
249 GLogLevelFlags log_level,
250 const gchar *msg, gpointer user_data );
255void test_set_called( const gboolean val );
256
261gboolean test_reset_called( void );
262
267void test_set_data( gpointer data );
268
273gpointer test_reset_data( void );
274
279void test_free( gpointer data );
280
300typedef gpointer TestSignal;
301
311 gpointer event_data);
316
322#define test_signal_assert_hits(sig, hits) \
323 g_assert_cmpint (test_signal_return_hits (sig), ==, hits)
324
329
342gboolean test_object_checked_destroy (GObject *obj);
343
353#define test_destroy(obj) \
354 g_assert_true (obj != NULL && G_IS_OBJECT (obj)); \
355 g_assert_true (test_object_checked_destroy (G_OBJECT (obj)))
356
358/* For Scheme testing access:
359void gnc_log_init_filename_special (gchar *filename);
360void gnc_log_shutdown (void);
361void gnc_log_set_handler (guint logdomain, gchar *logdomain, GLogFunc * func, gpointer data);
362*/
363
364#ifdef __cplusplus
365}
366#endif
367
368#endif /*UNITTEST_SUPPORT_H*/
gint QofEventId
Define the type of events allowed.
Definition qofevent.h:45
Struct to pass as user_data for the handlers.
Holds a handler instance with its TestErrorStruct, handler id, and whether it's a list handler.
gboolean test_object_checked_destroy(GObject *obj)
Unrefs obj and returns true if its finalize method was called.
gpointer TestSignal
TestSignal is an opaque struct used to mock handling signals emitted by functions-under-test.
gboolean test_log_handler(const char *log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data)
Just print the log message.
TestSignal test_signal_new(QofInstance *entity, QofEventId eventType, gpointer event_data)
Create a test signal.
gboolean test_reset_called(void)
Destructively tests (meaning that it resets called to FALSE) and returns the value of called.
void test_add_error(TestErrorStruct *error)
Maintains an internal list of TestErrorStructs which are each checked by the list handler.
guint test_signal_return_hits(TestSignal sig)
gets the number of times the TestSignal has been called.
gboolean test_list_handler(const char *log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data)
Checks received errors against the list created by test_add_error.
void test_set_data(gpointer data)
Set the test data pointer with the what you expect your mock to be called with.
gboolean test_list_substring_handler(const char *log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data)
Checks received errors against the list created by test_add_error.
void test_error_struct_free(TestErrorStruct *)
Free a TestErrorStruct created with test_error_struct_new.
gboolean test_checked_substring_handler(const char *log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data)
Check that the user_data error message is a substring of the actual error otherwise assert.
GSList * test_log_set_handler(GSList *list, TestErrorStruct *error, GLogFunc handler)
Set a log handler and add it to a GList for removal at teardown.
gboolean test_null_handler(const char *log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data)
Just returns FALSE or suppresses the message regardless of what the error is.
void test_signal_free(TestSignal sig)
Free a test signal.
void test_set_called(const gboolean val)
Call this from a mock object to indicate that the mock has in fact been called.
gpointer test_reset_data(void)
Destructively retrieves the test data pointer.
void test_free(gpointer data)
A handy function to use to free memory from lists of simple pointers.
TestErrorStruct * test_error_struct_new(const char *log_domain, const GLogLevelFlags log_level, const char *msg)
Convenience function to create an error struct.
gboolean test_checked_handler(const char *log_domain, GLogLevelFlags log_level, const gchar *msg, gpointer user_data)
Check the user_data against the actual error and assert on any differences.
void test_free_log_handler(gpointer item)
Clears all the log handlers.
GSList * test_log_set_fatal_handler(GSList *list, TestErrorStruct *error, GLogFunc handler)
Set a log handler and add it to a GList for removal at teardown; also set the fatal handler so that t...