v0.2.2 9100209

gtestdbus.go RawHistoryFolder

1// Package gio was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gio
3
4import (
5	"github.com/ebitengine/purego"
6
7	"github.com/bnema/puregotk/pkg/core"
8	"github.com/bnema/puregotk/v4/gobject"
9	"github.com/bnema/puregotk/v4/gobject/types"
10)
11
12// A helper class for testing code which uses D-Bus without touching the user’s
13// session bus.
14//
15// Note that `GTestDBus` modifies the user’s environment, calling
16// [`setenv()`](man:setenv(3)). This is not thread-safe, so all `GTestDBus`
17// calls should be completed before threads are spawned, or should have
18// appropriate locking to ensure no access conflicts to environment variables
19// shared between `GTestDBus` and other threads.
20//
21// ## Creating unit tests using `GTestDBus`
22//
23// Testing of D-Bus services can be tricky because normally we only ever run
24// D-Bus services over an existing instance of the D-Bus daemon thus we
25// usually don’t activate D-Bus services that are not yet installed into the
26// target system. The `GTestDBus` object makes this easier for us by taking care
27// of the lower level tasks such as running a private D-Bus daemon and looking
28// up uninstalled services in customizable locations, typically in your source
29// code tree.
30//
31// The first thing you will need is a separate service description file for the
32// D-Bus daemon. Typically a `services` subdirectory of your `tests` directory
33// is a good place to put this file.
34//
35// The service file should list your service along with an absolute path to the
36// uninstalled service executable in your source tree. Using autotools we would
37// achieve this by adding a file such as `my-server.service.in` in the services
38// directory and have it processed by configure.
39//
40// ```
41// [D-BUS Service]
42// Name=org.gtk.GDBus.Examples.ObjectManager
43// Exec=@abs_top_builddir@/gio/tests/gdbus-example-objectmanager-server
44// ```
45//
46// You will also need to indicate this service directory in your test
47// fixtures, so you will need to pass the path while compiling your
48// test cases. Typically this is done with autotools with an added
49// preprocessor flag specified to compile your tests such as:
50//
51// ```
52// -DTEST_SERVICES=\""$(abs_top_builddir)/tests/services"\"
53// ```
54//
55// Once you have a service definition file which is local to your source tree,
56// you can proceed to set up a GTest fixture using the `GTestDBus` scaffolding.
57//
58// An example of a test fixture for D-Bus services can be found
59// here:
60// [gdbus-test-fixture.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gdbus-test-fixture.c)
61//
62// Note that these examples only deal with isolating the D-Bus aspect of your
63// service. To successfully run isolated unit tests on your service you may need
64// some additional modifications to your test case fixture. For example; if your
65// service uses [class@Gio.Settings] and installs a schema then it is important
66// that your test service not load the schema in the ordinary installed location
67// (chances are that your service and schema files are not yet installed, or
68// worse; there is an older version of the schema file sitting in the install
69// location).
70//
71// Most of the time we can work around these obstacles using the
72// environment. Since the environment is inherited by the D-Bus daemon
73// created by `GTestDBus` and then in turn inherited by any services the
74// D-Bus daemon activates, using the setup routine for your fixture is
75// a practical place to help sandbox your runtime environment. For the
76// rather typical GSettings case we can work around this by setting
77// `GSETTINGS_SCHEMA_DIR` to the in tree directory holding your schemas
78// in the above `fixture_setup()` routine.
79//
80// The GSettings schemas need to be locally pre-compiled for this to work. This
81// can be achieved by compiling the schemas locally as a step before running
82// test cases, an autotools setup might do the following in the directory
83// holding schemas:
84//
85// ```
86//
87//	all-am:
88//	        $(GLIB_COMPILE_SCHEMAS) .
89//
90//	CLEANFILES += gschemas.compiled
91//
92// ```
93type TestDBus struct {
94	gobject.Object
95}
96
97var xTestDBusGLibType func() types.GType
98
99func TestDBusGLibType() types.GType {
100	return xTestDBusGLibType()
101}
102
103func TestDBusNewFromInternalPtr(ptr uintptr) *TestDBus {
104	cls := &TestDBus{}
105	cls.Ptr = ptr
106	return cls
107}
108
109var xNewTestDBus func(TestDBusFlags) uintptr
110
111// Create a new #GTestDBus object.
112func NewTestDBus(FlagsVar TestDBusFlags) *TestDBus {
113	var cls *TestDBus
114
115	cret := xNewTestDBus(FlagsVar)
116
117	if cret == 0 {
118		return nil
119	}
120	cls = &TestDBus{}
121	cls.Ptr = cret
122	return cls
123}
124
125var xTestDBusAddServiceDir func(uintptr, string)
126
127// Add a path where dbus-daemon will look up .service files. This can't be
128// called after g_test_dbus_up().
129func (x *TestDBus) AddServiceDir(PathVar string) {
130
131	xTestDBusAddServiceDir(x.GoPointer(), PathVar)
132
133}
134
135var xTestDBusDown func(uintptr)
136
137// Stop the session bus started by g_test_dbus_up().
138//
139// This will wait for the singleton returned by g_bus_get() or g_bus_get_sync()
140// to be destroyed. This is done to ensure that the next unit test won't get a
141// leaked singleton from this test.
142func (x *TestDBus) Down() {
143
144	xTestDBusDown(x.GoPointer())
145
146}
147
148var xTestDBusGetBusAddress func(uintptr) string
149
150// Get the address on which dbus-daemon is running. If g_test_dbus_up() has not
151// been called yet, %NULL is returned. This can be used with
152// g_dbus_connection_new_for_address().
153func (x *TestDBus) GetBusAddress() string {
154
155	cret := xTestDBusGetBusAddress(x.GoPointer())
156	return cret
157}
158
159var xTestDBusGetFlags func(uintptr) TestDBusFlags
160
161// Get the flags of the #GTestDBus object.
162func (x *TestDBus) GetFlags() TestDBusFlags {
163
164	cret := xTestDBusGetFlags(x.GoPointer())
165	return cret
166}
167
168var xTestDBusStop func(uintptr)
169
170// Stop the session bus started by g_test_dbus_up().
171//
172// Unlike g_test_dbus_down(), this won't verify the #GDBusConnection
173// singleton returned by g_bus_get() or g_bus_get_sync() is destroyed. Unit
174// tests wanting to verify behaviour after the session bus has been stopped
175// can use this function but should still call g_test_dbus_down() when done.
176func (x *TestDBus) Stop() {
177
178	xTestDBusStop(x.GoPointer())
179
180}
181
182var xTestDBusUp func(uintptr)
183
184// Start a dbus-daemon instance and set DBUS_SESSION_BUS_ADDRESS. After this
185// call, it is safe for unit tests to start sending messages on the session bus.
186//
187// If this function is called from setup callback of g_test_add(),
188// g_test_dbus_down() must be called in its teardown callback.
189//
190// If this function is called from unit test's main(), then g_test_dbus_down()
191// must be called after g_test_run().
192func (x *TestDBus) Up() {
193
194	xTestDBusUp(x.GoPointer())
195
196}
197
198func (c *TestDBus) GoPointer() uintptr {
199	if c == nil {
200		return 0
201	}
202	return c.Ptr
203}
204
205func (c *TestDBus) SetGoPointer(ptr uintptr) {
206	c.Ptr = ptr
207}
208
209var xTestDBusUnset func()
210
211// Unset DISPLAY and DBUS_SESSION_BUS_ADDRESS env variables to ensure the test
212// won't use user's session bus.
213//
214// This is useful for unit tests that want to verify behaviour when no session
215// bus is running. It is not necessary to call this if unit test already calls
216// g_test_dbus_up() before acquiring the session bus.
217func TestDBusUnset() {
218
219	xTestDBusUnset()
220
221}
222
223func init() {
224	core.SetPackageName("GIO", "gio-2.0")
225	core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
226	var libs []uintptr
227	for _, libPath := range core.GetPaths("GIO") {
228		lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
229		if err != nil {
230			panic(err)
231		}
232		libs = append(libs, lib)
233	}
234
235	core.PuregoSafeRegister(&xTestDBusGLibType, libs, "g_test_dbus_get_type")
236
237	core.PuregoSafeRegister(&xNewTestDBus, libs, "g_test_dbus_new")
238
239	core.PuregoSafeRegister(&xTestDBusAddServiceDir, libs, "g_test_dbus_add_service_dir")
240	core.PuregoSafeRegister(&xTestDBusDown, libs, "g_test_dbus_down")
241	core.PuregoSafeRegister(&xTestDBusGetBusAddress, libs, "g_test_dbus_get_bus_address")
242	core.PuregoSafeRegister(&xTestDBusGetFlags, libs, "g_test_dbus_get_flags")
243	core.PuregoSafeRegister(&xTestDBusStop, libs, "g_test_dbus_stop")
244	core.PuregoSafeRegister(&xTestDBusUp, libs, "g_test_dbus_up")
245
246	core.PuregoSafeRegister(&xTestDBusUnset, libs, "g_test_dbus_unset")
247
248}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close