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