1 /* Test fixtures for dbus-python, based on _dbus_glib_bindings. */
4 #include "dbus-python.h"
8 # define UNUSED __attribute__((__unused__))
10 # define UNUSED /*nothing*/
13 # define UNUSED /*nothing*/
17 dbus_py_test_set_up_conn(DBusConnection
*conn UNUSED
, void *data UNUSED
)
19 PyErr_SetString(PyExc_ValueError
, "Dummy error from UnusableMainLoop");
24 dbus_py_test_set_up_srv(DBusServer
*srv UNUSED
, void *data UNUSED
)
26 PyErr_SetString(PyExc_ValueError
, "Dummy error from UnusableMainLoop");
31 dbus_py_test_free(void *data UNUSED
)
36 dbus_test_native_mainloop(void)
38 PyObject
*loop
= DBusPyNativeMainLoop_New4(dbus_py_test_set_up_conn
,
39 dbus_py_test_set_up_srv
,
46 UnusableMainLoop (PyObject
*always_null UNUSED
, PyObject
*args
, PyObject
*kwargs
)
48 PyObject
*mainloop
, *function
, *result
;
49 int set_as_default
= 0;
50 static char *argnames
[] = {"set_as_default", NULL
};
52 if (PyTuple_Size(args
) != 0) {
53 PyErr_SetString(PyExc_TypeError
, "UnusableMainLoop() takes no "
54 "positional arguments");
57 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|i", argnames
,
62 mainloop
= dbus_test_native_mainloop();
63 if (mainloop
&& set_as_default
) {
64 if (!_dbus_bindings_module
) {
65 PyErr_SetString(PyExc_ImportError
, "_dbus_bindings not imported");
69 function
= PyObject_GetAttrString(_dbus_bindings_module
,
70 "set_default_main_loop");
75 result
= PyObject_CallFunctionObjArgs(function
, mainloop
, NULL
);
85 static PyMethodDef module_functions
[] = {
86 {"UnusableMainLoop", (PyCFunction
)UnusableMainLoop
,
87 METH_VARARGS
|METH_KEYWORDS
, "Return a main loop that fails to attach"},
92 initdbus_py_test(void)
94 PyObject
*this_module
;
96 if (import_dbus_bindings("dbus_py_test") < 0) return;
97 this_module
= Py_InitModule3 ("dbus_py_test", module_functions
, "");
98 if (!this_module
) return;
101 /* vim:set ft=c cino< sw=4 sts=4 et: */