1 /* Test fixtures for dbus-python, based on _dbus_glib_bindings.
3 * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
27 #include "dbus-python.h"
31 # define UNUSED __attribute__((__unused__))
33 # define UNUSED /*nothing*/
36 # define UNUSED /*nothing*/
40 dbus_py_test_set_up_conn(DBusConnection
*conn UNUSED
, void *data UNUSED
)
42 PyErr_SetString(PyExc_ValueError
, "Dummy error from UnusableMainLoop");
47 dbus_py_test_set_up_srv(DBusServer
*srv UNUSED
, void *data UNUSED
)
49 PyErr_SetString(PyExc_ValueError
, "Dummy error from UnusableMainLoop");
54 dbus_py_test_free(void *data UNUSED
)
59 dbus_test_native_mainloop(void)
61 PyObject
*loop
= DBusPyNativeMainLoop_New4(dbus_py_test_set_up_conn
,
62 dbus_py_test_set_up_srv
,
69 UnusableMainLoop (PyObject
*always_null UNUSED
, PyObject
*args
, PyObject
*kwargs
)
71 PyObject
*mainloop
, *function
, *result
;
72 int set_as_default
= 0;
73 static char *argnames
[] = {"set_as_default", NULL
};
75 if (PyTuple_Size(args
) != 0) {
76 PyErr_SetString(PyExc_TypeError
, "UnusableMainLoop() takes no "
77 "positional arguments");
80 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|i", argnames
,
85 mainloop
= dbus_test_native_mainloop();
86 if (mainloop
&& set_as_default
) {
87 if (!_dbus_bindings_module
) {
88 PyErr_SetString(PyExc_ImportError
, "_dbus_bindings not imported");
92 function
= PyObject_GetAttrString(_dbus_bindings_module
,
93 "set_default_main_loop");
98 result
= PyObject_CallFunctionObjArgs(function
, mainloop
, NULL
);
108 static PyMethodDef module_functions
[] = {
109 {"UnusableMainLoop", (PyCFunction
)UnusableMainLoop
,
110 METH_VARARGS
|METH_KEYWORDS
, "Return a main loop that fails to attach"},
111 {NULL
, NULL
, 0, NULL
}
115 initdbus_py_test(void)
117 PyObject
*this_module
;
119 if (import_dbus_bindings("dbus_py_test") < 0) return;
120 this_module
= Py_InitModule3 ("dbus_py_test", module_functions
, "");
121 if (!this_module
) return;
124 /* vim:set ft=c cino< sw=4 sts=4 et: */