1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.Testing; 26 27 private import glib.Str; 28 private import gobject.ObjectG; 29 private import gtk.SpinButton; 30 private import gtk.Widget; 31 private import gtk.c.functions; 32 public import gtk.c.types; 33 public import gtkc.gtktypes; 34 35 36 /** */ 37 public struct Testing 38 { 39 /** 40 * This function is used to initialize a GTK+ test program. 41 * It will in turn call testInit() and init() to 42 * properly initialize the testing framework and graphical toolkit. 43 * It'll also set the program's locale to "C" and prevent loading of 44 * rc files and Gtk+ modules. This is done to make the test program environments as deterministic as possible. 45 * Like init() any known arguments will be processed and stripped from and argv. 46 * Params: 47 * argv = The argv parameter of main(). Any parameters understood by testInit() or init() are stripped before return. 48 */ 49 public static void testInit(ref string[] argv) 50 { 51 // void gtk_test_init(int *argcp, char ***argvp, ...); 52 char** outargv = Str.toStringzArray(argv); 53 int argc = cast(int) argv.length; 54 55 gtk_test_init(&argc, &outargv, null); 56 57 argv = Str.toStringArray(outargv); 58 } 59 60 /** 61 */ 62 63 /** 64 * Create a simple window with window title @window_title and 65 * text contents @dialog_text. 66 * The window will quit any running gtk_main()-loop when destroyed, and it 67 * will automatically be destroyed upon test function teardown. 68 * 69 * Deprecated: This testing infrastructure is phased out in favor of reftests. 70 * 71 * Params: 72 * windowTitle = Title of the window to be displayed. 73 * dialogText = Text inside the window to be displayed. 74 * 75 * Returns: a widget pointer to the newly created GtkWindow. 76 * 77 * Since: 2.14 78 */ 79 public static Widget createSimpleWindow(string windowTitle, string dialogText) 80 { 81 auto p = gtk_test_create_simple_window(Str.toStringz(windowTitle), Str.toStringz(dialogText)); 82 83 if(p is null) 84 { 85 return null; 86 } 87 88 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 89 } 90 91 /** 92 * This function will search @widget and all its descendants for a GtkLabel 93 * widget with a text string matching @label_pattern. 94 * The @label_pattern may contain asterisks “*” and question marks “?” as 95 * placeholders, g_pattern_match() is used for the matching. 96 * Note that locales other than "C“ tend to alter (translate” label strings, 97 * so this function is genrally only useful in test programs with 98 * predetermined locales, see gtk_test_init() for more details. 99 * 100 * Params: 101 * widget = Valid label or container widget. 102 * labelPattern = Shell-glob pattern to match a label string. 103 * 104 * Returns: a GtkLabel widget if any is found. 105 * 106 * Since: 2.14 107 */ 108 public static Widget findLabel(Widget widget, string labelPattern) 109 { 110 auto p = gtk_test_find_label((widget is null) ? null : widget.getWidgetStruct(), Str.toStringz(labelPattern)); 111 112 if(p is null) 113 { 114 return null; 115 } 116 117 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 118 } 119 120 /** 121 * This function will search siblings of @base_widget and siblings of its 122 * ancestors for all widgets matching @widget_type. 123 * Of the matching widgets, the one that is geometrically closest to 124 * @base_widget will be returned. 125 * The general purpose of this function is to find the most likely “action” 126 * widget, relative to another labeling widget. Such as finding a 127 * button or text entry widget, given its corresponding label widget. 128 * 129 * Params: 130 * baseWidget = Valid widget, part of a widget hierarchy 131 * widgetType = Type of a aearched for sibling widget 132 * 133 * Returns: a widget of type @widget_type if any is found. 134 * 135 * Since: 2.14 136 */ 137 public static Widget findSibling(Widget baseWidget, GType widgetType) 138 { 139 auto p = gtk_test_find_sibling((baseWidget is null) ? null : baseWidget.getWidgetStruct(), widgetType); 140 141 if(p is null) 142 { 143 return null; 144 } 145 146 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 147 } 148 149 /** 150 * This function will search the descendants of @widget for a widget 151 * of type @widget_type that has a label matching @label_pattern next 152 * to it. This is most useful for automated GUI testing, e.g. to find 153 * the “OK” button in a dialog and synthesize clicks on it. 154 * However see gtk_test_find_label(), gtk_test_find_sibling() and 155 * gtk_test_widget_click() for possible caveats involving the search of 156 * such widgets and synthesizing widget events. 157 * 158 * Params: 159 * widget = Container widget, usually a GtkWindow. 160 * labelPattern = Shell-glob pattern to match a label string. 161 * widgetType = Type of a aearched for label sibling widget. 162 * 163 * Returns: a valid widget if any is found or %NULL. 164 * 165 * Since: 2.14 166 */ 167 public static Widget findWidget(Widget widget, string labelPattern, GType widgetType) 168 { 169 auto p = gtk_test_find_widget((widget is null) ? null : widget.getWidgetStruct(), Str.toStringz(labelPattern), widgetType); 170 171 if(p is null) 172 { 173 return null; 174 } 175 176 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 177 } 178 179 /** 180 * Return the type ids that have been registered after 181 * calling gtk_test_register_all_types(). 182 * 183 * Returns: 0-terminated array of type ids 184 * 185 * Since: 2.14 186 */ 187 public static GType[] listAllTypes() 188 { 189 uint nTypes; 190 191 auto p = gtk_test_list_all_types(&nTypes); 192 193 return p[0 .. nTypes]; 194 } 195 196 /** 197 * Force registration of all core Gtk+ and Gdk object types. 198 * This allowes to refer to any of those object types via 199 * g_type_from_name() after calling this function. 200 * 201 * Since: 2.14 202 */ 203 public static void registerAllTypes() 204 { 205 gtk_test_register_all_types(); 206 } 207 208 /** 209 * Retrive the literal adjustment value for GtkRange based 210 * widgets and spin buttons. Note that the value returned by 211 * this function is anything between the lower and upper bounds 212 * of the adjustment belonging to @widget, and is not a percentage 213 * as passed in to gtk_test_slider_set_perc(). 214 * 215 * Deprecated: This testing infrastructure is phased out in favor of reftests. 216 * 217 * Params: 218 * widget = valid widget pointer. 219 * 220 * Returns: gtk_adjustment_get_value (adjustment) for an adjustment belonging to @widget. 221 * 222 * Since: 2.14 223 */ 224 public static double sliderGetValue(Widget widget) 225 { 226 return gtk_test_slider_get_value((widget is null) ? null : widget.getWidgetStruct()); 227 } 228 229 /** 230 * This function will adjust the slider position of all GtkRange 231 * based widgets, such as scrollbars or scales, it’ll also adjust 232 * spin buttons. The adjustment value of these widgets is set to 233 * a value between the lower and upper limits, according to the 234 * @percentage argument. 235 * 236 * Deprecated: This testing infrastructure is phased out in favor of reftests. 237 * 238 * Params: 239 * widget = valid widget pointer. 240 * percentage = value between 0 and 100. 241 * 242 * Since: 2.14 243 */ 244 public static void sliderSetPerc(Widget widget, double percentage) 245 { 246 gtk_test_slider_set_perc((widget is null) ? null : widget.getWidgetStruct(), percentage); 247 } 248 249 /** 250 * This function will generate a @button click in the upwards or downwards 251 * spin button arrow areas, usually leading to an increase or decrease of 252 * spin button’s value. 253 * 254 * Deprecated: This testing infrastructure is phased out in favor of reftests. 255 * 256 * Params: 257 * spinner = valid GtkSpinButton widget. 258 * button = Number of the pointer button for the event, usually 1, 2 or 3. 259 * upwards = %TRUE for upwards arrow click, %FALSE for downwards arrow click. 260 * 261 * Returns: whether all actions neccessary for the button click simulation were carried out successfully. 262 * 263 * Since: 2.14 264 */ 265 public static bool spinButtonClick(SpinButton spinner, uint button, bool upwards) 266 { 267 return gtk_test_spin_button_click((spinner is null) ? null : spinner.getSpinButtonStruct(), button, upwards) != 0; 268 } 269 270 /** 271 * Retrive the text string of @widget if it is a GtkLabel, 272 * GtkEditable (entry and text widgets) or GtkTextView. 273 * 274 * Deprecated: This testing infrastructure is phased out in favor of reftests. 275 * 276 * Params: 277 * widget = valid widget pointer. 278 * 279 * Returns: new 0-terminated C string, needs to be released with g_free(). 280 * 281 * Since: 2.14 282 */ 283 public static string textGet(Widget widget) 284 { 285 auto retStr = gtk_test_text_get((widget is null) ? null : widget.getWidgetStruct()); 286 287 scope(exit) Str.freeString(retStr); 288 return Str.toString(retStr); 289 } 290 291 /** 292 * Set the text string of @widget to @string if it is a GtkLabel, 293 * GtkEditable (entry and text widgets) or GtkTextView. 294 * 295 * Deprecated: This testing infrastructure is phased out in favor of reftests. 296 * 297 * Params: 298 * widget = valid widget pointer. 299 * str = a 0-terminated C string 300 * 301 * Since: 2.14 302 */ 303 public static void textSet(Widget widget, string str) 304 { 305 gtk_test_text_set((widget is null) ? null : widget.getWidgetStruct(), Str.toStringz(str)); 306 } 307 308 /** 309 * This function will generate a @button click (button press and button 310 * release event) in the middle of the first GdkWindow found that belongs 311 * to @widget. 312 * For windowless widgets like #GtkButton (which returns %FALSE from 313 * gtk_widget_get_has_window()), this will often be an 314 * input-only event window. For other widgets, this is usually widget->window. 315 * Certain caveats should be considered when using this function, in 316 * particular because the mouse pointer is warped to the button click 317 * location, see gdk_test_simulate_button() for details. 318 * 319 * Deprecated: This testing infrastructure is phased out in favor of reftests. 320 * 321 * Params: 322 * widget = Widget to generate a button click on. 323 * button = Number of the pointer button for the event, usually 1, 2 or 3. 324 * modifiers = Keyboard modifiers the event is setup with. 325 * 326 * Returns: whether all actions neccessary for the button click simulation were carried out successfully. 327 * 328 * Since: 2.14 329 */ 330 public static bool widgetClick(Widget widget, uint button, GdkModifierType modifiers) 331 { 332 return gtk_test_widget_click((widget is null) ? null : widget.getWidgetStruct(), button, modifiers) != 0; 333 } 334 335 /** 336 * This function will generate keyboard press and release events in 337 * the middle of the first GdkWindow found that belongs to @widget. 338 * For windowless widgets like #GtkButton (which returns %FALSE from 339 * gtk_widget_get_has_window()), this will often be an 340 * input-only event window. For other widgets, this is usually widget->window. 341 * Certain caveats should be considered when using this function, in 342 * particular because the mouse pointer is warped to the key press 343 * location, see gdk_test_simulate_key() for details. 344 * 345 * Params: 346 * widget = Widget to generate a key press and release on. 347 * keyval = A Gdk keyboard value. 348 * modifiers = Keyboard modifiers the event is setup with. 349 * 350 * Returns: whether all actions neccessary for the key event simulation were carried out successfully. 351 * 352 * Since: 2.14 353 */ 354 public static bool widgetSendKey(Widget widget, uint keyval, GdkModifierType modifiers) 355 { 356 return gtk_test_widget_send_key((widget is null) ? null : widget.getWidgetStruct(), keyval, modifiers) != 0; 357 } 358 359 /** 360 * Enters the main loop and waits for @widget to be “drawn”. In this 361 * context that means it waits for the frame clock of @widget to have 362 * run a full styling, layout and drawing cycle. 363 * 364 * This function is intended to be used for syncing with actions that 365 * depend on @widget relayouting or on interaction with the display 366 * server. 367 * 368 * Params: 369 * widget = the widget to wait for 370 * 371 * Since: 3.10 372 */ 373 public static void widgetWaitForDraw(Widget widget) 374 { 375 gtk_test_widget_wait_for_draw((widget is null) ? null : widget.getWidgetStruct()); 376 } 377 }