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