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