1 /*
2  * Clutter.
3  *
4  * An OpenGL based 'interactive canvas' library.
5  *
6  * Copyright (C) 2013  Emmanuele Bassi <ebassi@gnome.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "config.h"
23 
24 #ifndef __CLUTTER_TEST_UTILS_H__
25 #define __CLUTTER_TEST_UTILS_H__
26 
27 #define __CLUTTER_H_INSIDE__
28 
29 #include "clutter/clutter-types.h"
30 #include "clutter/clutter-actor.h"
31 #include "clutter/clutter-color.h"
32 #include "clutter/clutter-private.h"
33 #include "meta/common.h"
34 #include "meta-test/meta-context-test.h"
35 
36 G_BEGIN_DECLS
37 
38 /**
39  * CLUTTER_TEST_UNIT:
40  * @path: the GTest path for the test function
41  * @func: the GTestFunc function
42  *
43  * Adds @func at the given @path in the test suite.
44  *
45  * Since: 1.18
46  */
47 #define CLUTTER_TEST_UNIT(path,func) \
48   clutter_test_add (path, func);
49 
50 /**
51  * CLUTTER_TEST_SUITE:
52  * @units: a list of %CLUTTER_TEST_UNIT definitions
53  *
54  * Defines the entry point and initializes a Clutter test unit, e.g.:
55  *
56  * |[
57  * CLUTTER_TEST_SUITE (
58  *   CLUTTER_TEST_UNIT ("/foobarize", foobarize)
59  *   CLUTTER_TEST_UNIT ("/bar-enabled", bar_enabled)
60  * )
61  * ]|
62  *
63  * Expands to:
64  *
65  * |[
66  * int
67  * main (int   argc,
68  *       char *argv[])
69  * {
70  *   clutter_test_init (&argc, &argv);
71  *
72  *   clutter_test_add ("/foobarize", foobarize);
73  *   clutter_test_add ("/bar-enabled", bar_enabled);
74  *
75  *   return clutter_test_run ();
76  * }
77  * ]|
78  *
79  * Since: 1.18
80  */
81 #define CLUTTER_TEST_SUITE(units) \
82 int \
83 main (int argc, char *argv[]) \
84 { \
85   clutter_test_init (&argc, &argv); \
86 \
87   { \
88     units \
89   } \
90 \
91   return clutter_test_run (); \
92 }
93 
94 CLUTTER_EXPORT
95 void            clutter_test_init               (int            *argc,
96                                                  char         ***argv);
97 
98 CLUTTER_EXPORT
99 int             clutter_test_run                (void);
100 
101 CLUTTER_EXPORT
102 void            clutter_test_main               (void);
103 
104 CLUTTER_EXPORT
105 void            clutter_test_quit               (void);
106 
107 CLUTTER_EXPORT
108 void            clutter_test_add                (const char     *test_path,
109                                                  GTestFunc       test_func);
110 CLUTTER_EXPORT
111 void            clutter_test_add_data           (const char     *test_path,
112                                                  GTestDataFunc   test_func,
113                                                  gpointer        test_data);
114 CLUTTER_EXPORT
115 void            clutter_test_add_data_full      (const char     *test_path,
116                                                  GTestDataFunc   test_func,
117                                                  gpointer        test_data,
118                                                  GDestroyNotify  test_notify);
119 
120 CLUTTER_EXPORT
121 ClutterActor *  clutter_test_get_stage          (void);
122 
123 #define clutter_test_assert_actor_at_point(stage,point,actor) \
124 G_STMT_START { \
125   const graphene_point_t *__p = (point); \
126   ClutterActor *__actor = (actor); \
127   ClutterActor *__stage = (stage); \
128   ClutterActor *__res; \
129   if (clutter_test_check_actor_at_point (__stage, __p, actor, &__res)) ; else { \
130     const char *__str1 = clutter_actor_get_name (__actor) != NULL \
131                        ? clutter_actor_get_name (__actor) \
132                        : G_OBJECT_TYPE_NAME (__actor); \
133     const char *__str2 = clutter_actor_get_name (__res) != NULL \
134                        ? clutter_actor_get_name (__res) \
135                        : G_OBJECT_TYPE_NAME (__res); \
136     char *__msg = g_strdup_printf ("assertion failed (actor %s at %.2f,%.2f): found actor %s", \
137                                    __str1, __p->x, __p->y, __str2); \
138     g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \
139     g_free (__msg); \
140   } \
141 } G_STMT_END
142 
143 #define clutter_test_assert_color_at_point(stage,point,color) \
144 G_STMT_START { \
145   const graphene_point_t *__p = (point); \
146   const ClutterColor *__c = (color); \
147   ClutterActor *__stage = (stage); \
148   ClutterColor __res; \
149   if (clutter_test_check_color_at_point (__stage, __p, __c, &__res)) ; else { \
150     char *__str1 = clutter_color_to_string (__c); \
151     char *__str2 = clutter_color_to_string (&__res); \
152     char *__msg = g_strdup_printf ("assertion failed (color %s at %.2f,%.2f): found color %s", \
153                                    __str1, __p->x, __p->y, __str2); \
154     g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \
155     g_free (__msg); \
156     g_free (__str1); \
157     g_free (__str2); \
158   } \
159 } G_STMT_END
160 
161 CLUTTER_EXPORT
162 gboolean        clutter_test_check_actor_at_point       (ClutterActor            *stage,
163                                                          const graphene_point_t  *point,
164                                                          ClutterActor            *actor,
165                                                          ClutterActor           **result);
166 CLUTTER_EXPORT
167 gboolean        clutter_test_check_color_at_point       (ClutterActor           *stage,
168                                                          const graphene_point_t *point,
169                                                          const ClutterColor     *color,
170                                                          ClutterColor           *result);
171 
172 G_END_DECLS
173 
174 #endif /* __CLUTTER_TEST_UTILS_H__ */
175