doc: update copyright line for 2021
[adg.git] / src / tests / adg-test.h
blobbf69f3c5e55ff163f66ebc2e78aabace3c18d708
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__
24 #include <cairo.h>
25 #include <glib-object.h>
28 G_BEGIN_DECLS
30 /* Some backward compatible macros */
31 #ifndef g_assert_true
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"); \
35 } while (0)
36 #endif
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"); \
42 } while (0)
43 #endif
45 #ifndef g_assert_null
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"); \
49 } while (0)
50 #endif
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"); \
56 } while (0)
57 #endif
59 /**
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
69 * into account.
71 * // This will always fail:
72 * adg_assert_isapprox(G_MAXDOUBLE, G_MAXDOUBLE);
73 **/
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'); \
81 } G_STMT_END
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">
90 * static void
91 * traps_function(gint i)
92 * {
93 * switch (i) {
94 * case 1:
95 * // First code fragment
96 * g_print("This will be successful");
97 * break;
98 * case 2:
99 * // Second code fragment
100 * g_print("This will fail");
101 * break;
102 * default:
103 * // Assertions
104 * g_test_trap_assert_passed();
105 * g_test_trap_assert_stdout("*successful*");
106 * break;
109 * </programlisting></informalexample>
111 typedef void (*AdgTrapsFunc)(gint i);
114 void adg_test_init (int *p_argc,
115 char **p_argv[]);
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);
119 const cairo_path_t *
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,
126 GType type);
127 void adg_test_add_boxed_checks (const gchar *testpath,
128 GType type,
129 gpointer instance);
130 void adg_test_add_object_checks (const gchar *testpath,
131 GType type);
132 void adg_test_add_model_checks (const gchar *testpath,
133 GType type);
134 void adg_test_add_entity_checks (const gchar *testpath,
135 GType type);
136 void adg_test_add_container_checks (const gchar *testpath,
137 GType type);
138 void adg_test_add_global_space_checks(const gchar *testpath,
139 gpointer entity);
140 void adg_test_add_local_space_checks (const gchar *testpath,
141 gpointer entity);
142 void adg_test_add_traps (const gchar *testpath,
143 AdgTrapsFunc func,
144 gint n_fragments);
146 G_END_DECLS
149 #endif /* __ADG_TEST_H__ */