1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2021 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #ifndef __ADG_TEST_H__
22 #define __ADG_TEST_H__
25 #include <glib-object.h>
30 /* Some backward compatible macros */
32 #define g_assert_true(expr) do { if G_LIKELY (expr) ; else \
33 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
34 "'" #expr "' should be TRUE"); \
38 #ifndef g_assert_false
39 #define g_assert_false(expr) do { if G_LIKELY (!(expr)) ; else \
40 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
41 "'" #expr "' should be FALSE"); \
46 #define g_assert_null(expr) do { if G_LIKELY ((expr) == NULL) ; else \
47 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
48 "'" #expr "' should be NULL"); \
52 #ifndef g_assert_nonnull
53 #define g_assert_nonnull(expr) do { if G_LIKELY ((expr) != NULL) ; else \
54 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
55 "'" #expr "' should not be NULL"); \
60 * Check if a pair of numbers are approximately equals.
61 * @n1: (type gdouble): First value to compare
62 * @n2: (type gdouble): Second value to compare
64 * This macro is similar to g_assert_cmpfloat with the == operator but
65 * considers only the first 3 decimal digits. This can be used instead of
66 * the strict equality to avoid some false assertions due to rounding problems.
68 * WARNING: the implementation is quite naive and do not take overflow
71 * // This will always fail:
72 * adg_assert_isapprox(G_MAXDOUBLE, G_MAXDOUBLE);
74 #define adg_assert_isapprox(n1,n2) G_STMT_START { \
75 long double __n3 = (n1), __n4 = (n2); \
76 gint64 __n1 = __n3 * 1000 + (__n3 > 0 ? +0.5 : -0.5), \
77 __n2 = __n4 * 1000 + (__n4 > 0 ? +0.5 : -0.5); \
78 if (__n1 == __n2) ; else \
79 g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
80 #n1 " is not approximately equal to " #n2, __n3, "~=", __n4, 'f'); \
84 /* The following type is used by adg_test_add_traps() to handle
85 * in a consistent way trap assertions. The AdgTrapsFunc function
86 * must implement one or more code fragments and a serie of
87 * assertions to be applied on all those fragments, e.g.:
89 * <informalexample><programlisting language="C">
91 * traps_function(gint i)
95 * // First code fragment
96 * g_print("This will be successful");
99 * // Second code fragment
100 * g_print("This will fail");
104 * g_test_trap_assert_passed();
105 * g_test_trap_assert_stdout("*successful*");
109 * </programlisting></informalexample>
111 typedef void (*AdgTrapsFunc
)(gint i
);
114 void adg_test_init (int *p_argc
,
116 const gpointer
adg_test_invalid_pointer (void);
117 cairo_t
* adg_test_cairo_context (void);
118 int adg_test_cairo_num_data (cairo_t
*cr
);
120 adg_test_path (void);
121 gpointer
adg_test_canvas (void);
122 void adg_test_signal (gpointer instance
,
123 const gchar
*detailed_signal
);
124 gboolean
adg_test_signal_check (gboolean disconnect
);
125 void adg_test_add_enum_checks (const gchar
*testpath
,
127 void adg_test_add_boxed_checks (const gchar
*testpath
,
130 void adg_test_add_object_checks (const gchar
*testpath
,
132 void adg_test_add_model_checks (const gchar
*testpath
,
134 void adg_test_add_entity_checks (const gchar
*testpath
,
136 void adg_test_add_container_checks (const gchar
*testpath
,
138 void adg_test_add_global_space_checks(const gchar
*testpath
,
140 void adg_test_add_local_space_checks (const gchar
*testpath
,
142 void adg_test_add_traps (const gchar
*testpath
,
149 #endif /* __ADG_TEST_H__ */