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  = GTestDBus.html
27  * outPack = gio
28  * outFile = TestDBus
29  * strct   = GTestDBus
30  * realStrct=
31  * ctorStrct=
32  * clss    = TestDBus
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_test_dbus_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * structWrap:
48  * module aliases:
49  * local aliases:
50  * overrides:
51  */
52 
53 module gio.TestDBus;
54 
55 public  import gtkc.giotypes;
56 
57 private import gtkc.gio;
58 private import glib.ConstructionException;
59 private import gobject.ObjectG;
60 
61 private import glib.Str;
62 
63 
64 private import gobject.ObjectG;
65 
66 /**
67  * A helper class for testing code which uses D-Bus without touching the user's
68  * session bus.
69  *
70  * Creating unit tests using GTestDBus
71  *
72  *  Testing of D-Bus services can be tricky because normally we only ever run
73  *  D-Bus services over an existing instance of the D-Bus daemon thus we
74  *  usually don't activate D-Bus services that are not yet installed into the
75  *  target system. The GTestDBus object makes this easier for us by taking care
76  *  of the lower level tasks such as running a private D-Bus daemon and looking
77  *  up uninstalled services in customizable locations, typically in your source code tree.
78  *
79  *  The first thing you will need is a separate service description file for the
80  *  D-Bus daemon. Typically a 'services' subdirectory of your 'tests' directory
81  *  is a good place to put this file.
82  *
83  *  The service file should list your service along with an absolute path to the
84  *  uninstalled service executable in your source tree. Using autotools we would
85  *  achieve this by adding a file such as 'my-server.service.in' in the services
86  *  directory and have it processed by configure.
87  *
88  * $(DDOC_COMMENT example)
89  *
90  *  You will also need to indicate this service directory in your test
91  *  fixtures, so you will need to pass the path while compiling your
92  *  test cases. Typically this is done with autotools with an added
93  *  preprocessor flag specified to compile your tests such as:
94  *
95  * $(DDOC_COMMENT example)
96  *
97  *  Once you have a service definition file which is local to your source tree,
98  *  you can proceed to setup a GTest fixture using the GTestDBus scaffolding.
99  *
100  * $(DDOC_COMMENT example)
101  *
102  *  Note that these examples only deal with isolating the D-Bus aspect of your
103  *  service. To successfully run isolated unit tests on your service you may need
104  *  some additional modifications to your test case fixture. For example; if your
105  *  service uses GSettings and installs a schema then it is important that your test service
106  *  not load the schema in the ordinary installed location (chances are that your service
107  *  and schema files are not yet installed, or worse; there is an older version of the
108  *  schema file sitting in the install location).
109  *
110  *  Most of the time we can work around these obstacles using the environment. Since the
111  *  environment is inherited by the D-Bus daemon created by GTestDBus and then in turn
112  *  inherited by any services the D-Bus daemon activates, using the setup routine for your
113  *  fixture is a practical place to help sandbox your runtime environment. For the rather
114  *  typical GSettings case we can work around this by setting GSETTINGS_SCHEMA_DIR to the
115  *  in tree directory holding your schemas in the above fixture_setup() routine.
116  *
117  *  The GSettings schemas need to be locally pre-compiled for this to work. This can be achieved
118  *  by compiling the schemas locally as a step before running test cases, an autotools setup might
119  *  do the following in the directory holding schemas:
120  *
121  * $(DDOC_COMMENT example)
122  */
123 public class TestDBus : ObjectG
124 {
125 	
126 	/** the main Gtk struct */
127 	protected GTestDBus* gTestDBus;
128 	
129 	
130 	/** Get the main Gtk struct */
131 	public GTestDBus* getTestDBusStruct()
132 	{
133 		return gTestDBus;
134 	}
135 	
136 	
137 	/** the main Gtk struct as a void* */
138 	protected override void* getStruct()
139 	{
140 		return cast(void*)gTestDBus;
141 	}
142 	
143 	/**
144 	 * Sets our main struct and passes it to the parent class
145 	 */
146 	public this (GTestDBus* gTestDBus)
147 	{
148 		super(cast(GObject*)gTestDBus);
149 		this.gTestDBus = gTestDBus;
150 	}
151 	
152 	protected override void setStruct(GObject* obj)
153 	{
154 		super.setStruct(obj);
155 		gTestDBus = cast(GTestDBus*)obj;
156 	}
157 	
158 	/**
159 	 */
160 	
161 	/**
162 	 * Create a new GTestDBus object.
163 	 * Params:
164 	 * flags = a GTestDBusFlags
165 	 * Throws: ConstructionException GTK+ fails to create the object.
166 	 */
167 	public this (GTestDBusFlags flags)
168 	{
169 		// GTestDBus * g_test_dbus_new (GTestDBusFlags flags);
170 		auto p = g_test_dbus_new(flags);
171 		if(p is null)
172 		{
173 			throw new ConstructionException("null returned by g_test_dbus_new(flags)");
174 		}
175 		this(cast(GTestDBus*) p);
176 	}
177 	
178 	/**
179 	 * Gets the flags of the GTestDBus object.
180 	 * Returns: the value of "flags" property
181 	 */
182 	public GTestDBusFlags getFlags()
183 	{
184 		// GTestDBusFlags g_test_dbus_get_flags (GTestDBus *self);
185 		return g_test_dbus_get_flags(gTestDBus);
186 	}
187 	
188 	/**
189 	 * Get the address on which dbus-daemon is running. if g_test_dbus_up() has not
190 	 * been called yet, NULL is returned. This can be used with
191 	 * g_dbus_connection_new_for_address()
192 	 * Returns: the address of the bus, or NULL.
193 	 */
194 	public string getBusAddress()
195 	{
196 		// const gchar * g_test_dbus_get_bus_address (GTestDBus *self);
197 		return Str.toString(g_test_dbus_get_bus_address(gTestDBus));
198 	}
199 	
200 	/**
201 	 * Add a path where dbus-daemon will lookup for .services files. This can't be
202 	 * called after g_test_dbus_up().
203 	 * Params:
204 	 * path = path to a directory containing .service files
205 	 */
206 	public void addServiceDir(string path)
207 	{
208 		// void g_test_dbus_add_service_dir (GTestDBus *self,  const gchar *path);
209 		g_test_dbus_add_service_dir(gTestDBus, Str.toStringz(path));
210 	}
211 	
212 	/**
213 	 * Start a dbus-daemon instance and set DBUS_SESSION_BUS_ADDRESS. After this
214 	 * call, it is safe for unit tests to start sending messages on the session bus.
215 	 * If this function is called from setup callback of g_test_add(),
216 	 * g_test_dbus_down() must be called in its teardown callback.
217 	 * If this function is called from unit test's main(), then g_test_dbus_down()
218 	 * must be called after g_test_run().
219 	 */
220 	public void up()
221 	{
222 		// void g_test_dbus_up (GTestDBus *self);
223 		g_test_dbus_up(gTestDBus);
224 	}
225 	
226 	/**
227 	 * Stop the session bus started by g_test_dbus_up().
228 	 * Unlike g_test_dbus_down(), this won't verify the GDBusConnection
229 	 * singleton returned by g_bus_get() or g_bus_get_sync() is destroyed. Unit
230 	 * tests wanting to verify behaviour after the session bus has been stopped
231 	 * can use this function but should still call g_test_dbus_down() when done.
232 	 */
233 	public void stop()
234 	{
235 		// void g_test_dbus_stop (GTestDBus *self);
236 		g_test_dbus_stop(gTestDBus);
237 	}
238 	
239 	/**
240 	 * Stop the session bus started by g_test_dbus_up().
241 	 * This will wait for the singleton returned by g_bus_get() or g_bus_get_sync()
242 	 * is destroyed. This is done to ensure that the next unit test won't get a
243 	 * leaked singleton from this test.
244 	 */
245 	public void down()
246 	{
247 		// void g_test_dbus_down (GTestDBus *self);
248 		g_test_dbus_down(gTestDBus);
249 	}
250 	
251 	/**
252 	 * Unset DISPLAY and DBUS_SESSION_BUS_ADDRESS env variables to ensure the test
253 	 * won't use user's session bus.
254 	 * This is useful for unit tests that want to verify behaviour when no session
255 	 * bus is running. It is not necessary to call this if unit test already calls
256 	 * g_test_dbus_up() before acquiring the session bus.
257 	 */
258 	public static void unset()
259 	{
260 		// void g_test_dbus_unset (void);
261 		g_test_dbus_unset();
262 	}
263 }