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