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 #ifndef __CLUTTER_TEST_UTILS_H__ 23 #define __CLUTTER_TEST_UTILS_H__ 24 25 #if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) 26 #error "Only <clutter/clutter.h> can be included directly." 27 #endif 28 29 #include <clutter/clutter-types.h> 30 #include <clutter/clutter-actor.h> 31 #include <clutter/clutter-color.h> 32 33 G_BEGIN_DECLS 34 35 /** 36 * CLUTTER_TEST_UNIT: 37 * @path: the GTest path for the test function 38 * @func: the GTestFunc function 39 * 40 * Adds @func at the given @path in the test suite. 41 * 42 * Since: 1.18 43 */ 44 #define CLUTTER_TEST_UNIT(path,func) \ 45 clutter_test_add (path, func); 46 47 /** 48 * CLUTTER_TEST_SUITE: 49 * @units: a list of %CLUTTER_TEST_UNIT definitions 50 * 51 * Defines the entry point and initializes a Clutter test unit, e.g.: 52 * 53 * |[ 54 * CLUTTER_TEST_SUITE ( 55 * CLUTTER_TEST_UNIT ("/foobarize", foobarize) 56 * CLUTTER_TEST_UNIT ("/bar-enabled", bar_enabled) 57 * ) 58 * ]| 59 * 60 * Expands to: 61 * 62 * |[ 63 * int 64 * main (int argc, 65 * char *argv[]) 66 * { 67 * clutter_test_init (&argc, &argv); 68 * 69 * clutter_test_add ("/foobarize", foobarize); 70 * clutter_test_add ("/bar-enabled", bar_enabled); 71 * 72 * return clutter_test_run (); 73 * } 74 * ]| 75 * 76 * Since: 1.18 77 */ 78 #define CLUTTER_TEST_SUITE(units) \ 79 int \ 80 main (int argc, char *argv[]) \ 81 { \ 82 clutter_test_init (&argc, &argv); \ 83 \ 84 { \ 85 units \ 86 } \ 87 \ 88 return clutter_test_run (); \ 89 } 90 91 CLUTTER_AVAILABLE_IN_1_18 92 void clutter_test_init (int *argc, 93 char ***argv); 94 CLUTTER_AVAILABLE_IN_1_18 95 int clutter_test_run (void); 96 97 CLUTTER_AVAILABLE_IN_1_18 98 void clutter_test_add (const char *test_path, 99 GTestFunc test_func); 100 CLUTTER_AVAILABLE_IN_1_18 101 void clutter_test_add_data (const char *test_path, 102 GTestDataFunc test_func, 103 gpointer test_data); 104 CLUTTER_AVAILABLE_IN_1_18 105 void clutter_test_add_data_full (const char *test_path, 106 GTestDataFunc test_func, 107 gpointer test_data, 108 GDestroyNotify test_notify); 109 110 CLUTTER_AVAILABLE_IN_1_18 111 ClutterActor * clutter_test_get_stage (void); 112 113 #define clutter_test_assert_actor_at_point(stage,point,actor) \ 114 G_STMT_START { \ 115 const ClutterPoint *__p = (point); \ 116 ClutterActor *__actor = (actor); \ 117 ClutterActor *__stage = (stage); \ 118 ClutterActor *__res; \ 119 if (clutter_test_check_actor_at_point (__stage, __p, actor, &__res)) ; else { \ 120 const char *__str1 = clutter_actor_get_name (__actor) != NULL \ 121 ? clutter_actor_get_name (__actor) \ 122 : G_OBJECT_TYPE_NAME (__actor); \ 123 const char *__str2 = clutter_actor_get_name (__res) != NULL \ 124 ? clutter_actor_get_name (__res) \ 125 : G_OBJECT_TYPE_NAME (__res); \ 126 char *__msg = g_strdup_printf ("assertion failed (actor %s at %.2f,%.2f): found actor %s", \ 127 __str1, __p->x, __p->y, __str2); \ 128 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \ 129 free (__msg); \ 130 } \ 131 } G_STMT_END 132 133 #define clutter_test_assert_color_at_point(stage,point,color) \ 134 G_STMT_START { \ 135 const ClutterPoint *__p = (point); \ 136 const ClutterColor *__c = (color); \ 137 ClutterActor *__stage = (stage); \ 138 ClutterColor __res; \ 139 if (clutter_test_check_color_at_point (__stage, __p, __c, &__res)) ; else { \ 140 char *__str1 = clutter_color_to_string (__c); \ 141 char *__str2 = clutter_color_to_string (&__res); \ 142 char *__msg = g_strdup_printf ("assertion failed (color %s at %.2f,%.2f): found color %s", \ 143 __str1, __p->x, __p->y, __str2); \ 144 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \ 145 free (__msg); \ 146 free (__str1); \ 147 free (__str2); \ 148 } \ 149 } G_STMT_END 150 151 CLUTTER_AVAILABLE_IN_1_18 152 gboolean clutter_test_check_actor_at_point (ClutterActor *stage, 153 const ClutterPoint *point, 154 ClutterActor *actor, 155 ClutterActor **result); 156 CLUTTER_AVAILABLE_IN_1_18 157 gboolean clutter_test_check_color_at_point (ClutterActor *stage, 158 const ClutterPoint *point, 159 const ClutterColor *color, 160 ClutterColor *result); 161 162 G_END_DECLS 163 164 #endif /* __CLUTTER_TEST_UTILS_H__ */ 165