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