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