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 	 * Params:
180 	 *     nTypes = location to store number of types
181 	 *
182 	 * Return: 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 	 * Params:
215 	 *     widget = valid widget pointer.
216 	 *
217 	 * Return: gtk_adjustment_get_value (adjustment) for an adjustment belonging to @widget.
218 	 *
219 	 * Since: 2.14
220 	 */
221 	public static double sliderGetValue(Widget widget)
222 	{
223 		return gtk_test_slider_get_value((widget is null) ? null : widget.getWidgetStruct());
224 	}
225 
226 	/**
227 	 * This function will adjust the slider position of all GtkRange
228 	 * based widgets, such as scrollbars or scales, it’ll also adjust
229 	 * spin buttons. The adjustment value of these widgets is set to
230 	 * a value between the lower and upper limits, according to the
231 	 * @percentage argument.
232 	 *
233 	 * Params:
234 	 *     widget = valid widget pointer.
235 	 *     percentage = value between 0 and 100.
236 	 *
237 	 * Since: 2.14
238 	 */
239 	public static void sliderSetPerc(Widget widget, double percentage)
240 	{
241 		gtk_test_slider_set_perc((widget is null) ? null : widget.getWidgetStruct(), percentage);
242 	}
243 
244 	/**
245 	 * This function will generate a @button click in the upwards or downwards
246 	 * spin button arrow areas, usually leading to an increase or decrease of
247 	 * spin button’s value.
248 	 *
249 	 * Params:
250 	 *     spinner = valid GtkSpinButton widget.
251 	 *     button = Number of the pointer button for the event, usually 1, 2 or 3.
252 	 *     upwards = %TRUE for upwards arrow click, %FALSE for downwards arrow click.
253 	 *
254 	 * Return: whether all actions neccessary for the button click simulation were carried out successfully.
255 	 *
256 	 * Since: 2.14
257 	 */
258 	public static bool spinButtonClick(SpinButton spinner, uint button, bool upwards)
259 	{
260 		return gtk_test_spin_button_click((spinner is null) ? null : spinner.getSpinButtonStruct(), button, upwards) != 0;
261 	}
262 
263 	/**
264 	 * Retrive the text string of @widget if it is a GtkLabel,
265 	 * GtkEditable (entry and text widgets) or GtkTextView.
266 	 *
267 	 * Params:
268 	 *     widget = valid widget pointer.
269 	 *
270 	 * Return: new 0-terminated C string, needs to be released with g_free().
271 	 *
272 	 * Since: 2.14
273 	 */
274 	public static string textGet(Widget widget)
275 	{
276 		return Str.toString(gtk_test_text_get((widget is null) ? null : widget.getWidgetStruct()));
277 	}
278 
279 	/**
280 	 * Set the text string of @widget to @string if it is a GtkLabel,
281 	 * GtkEditable (entry and text widgets) or GtkTextView.
282 	 *
283 	 * Params:
284 	 *     widget = valid widget pointer.
285 	 *     str = a 0-terminated C string
286 	 *
287 	 * Since: 2.14
288 	 */
289 	public static void textSet(Widget widget, string str)
290 	{
291 		gtk_test_text_set((widget is null) ? null : widget.getWidgetStruct(), Str.toStringz(str));
292 	}
293 
294 	/**
295 	 * This function will generate a @button click (button press and button
296 	 * release event) in the middle of the first GdkWindow found that belongs
297 	 * to @widget.
298 	 * For windowless widgets like #GtkButton (which returns %FALSE from
299 	 * gtk_widget_get_has_window()), this will often be an
300 	 * input-only event window. For other widgets, this is usually widget->window.
301 	 * Certain caveats should be considered when using this function, in
302 	 * particular because the mouse pointer is warped to the button click
303 	 * location, see gdk_test_simulate_button() for details.
304 	 *
305 	 * Params:
306 	 *     widget = Widget to generate a button click on.
307 	 *     button = Number of the pointer button for the event, usually 1, 2 or 3.
308 	 *     modifiers = Keyboard modifiers the event is setup with.
309 	 *
310 	 * Return: whether all actions neccessary for the button click simulation were carried out successfully.
311 	 *
312 	 * Since: 2.14
313 	 */
314 	public static bool widgetClick(Widget widget, uint button, GdkModifierType modifiers)
315 	{
316 		return gtk_test_widget_click((widget is null) ? null : widget.getWidgetStruct(), button, modifiers) != 0;
317 	}
318 
319 	/**
320 	 * This function will generate keyboard press and release events in
321 	 * the middle of the first GdkWindow found that belongs to @widget.
322 	 * For windowless widgets like #GtkButton (which returns %FALSE from
323 	 * gtk_widget_get_has_window()), 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 key press
327 	 * location, see gdk_test_simulate_key() for details.
328 	 *
329 	 * Params:
330 	 *     widget = Widget to generate a key press and release on.
331 	 *     keyval = A Gdk keyboard value.
332 	 *     modifiers = Keyboard modifiers the event is setup with.
333 	 *
334 	 * Return: whether all actions neccessary for the key event simulation were carried out successfully.
335 	 *
336 	 * Since: 2.14
337 	 */
338 	public static bool widgetSendKey(Widget widget, uint keyval, GdkModifierType modifiers)
339 	{
340 		return gtk_test_widget_send_key((widget is null) ? null : widget.getWidgetStruct(), keyval, modifiers) != 0;
341 	}
342 
343 	/**
344 	 * Enters the main loop and waits for @widget to be “drawn”. In this
345 	 * context that means it waits for the frame clock of @widget to have
346 	 * run a full styling, layout and drawing cycle.
347 	 *
348 	 * This function is intended to be used for syncing with actions that
349 	 * depend on @widget relayouting or on interaction with the display
350 	 * server.
351 	 *
352 	 * Params:
353 	 *     widget = the widget to wait for
354 	 *
355 	 * Since: 3.10
356 	 */
357 	public static void widgetWaitForDraw(Widget widget)
358 	{
359 		gtk_test_widget_wait_for_draw((widget is null) ? null : widget.getWidgetStruct());
360 	}
361 }