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"
29
PyMODINIT_FUNC initdbus_py_test(void);
33
# define UNUSED __attribute__((__unused__))
35
# define UNUSED /*nothing*/
38
# define UNUSED /*nothing*/
42
dbus_py_test_set_up_conn(DBusConnection *conn UNUSED, void *data UNUSED)
44
PyErr_SetString(PyExc_ValueError, "Dummy error from UnusableMainLoop");
49
dbus_py_test_set_up_srv(DBusServer *srv UNUSED, void *data UNUSED)
51
PyErr_SetString(PyExc_ValueError, "Dummy error from UnusableMainLoop");
56
dbus_py_test_free(void *data UNUSED)
61
dbus_test_native_mainloop(void)
63
PyObject *loop = DBusPyNativeMainLoop_New4(dbus_py_test_set_up_conn,
64
dbus_py_test_set_up_srv,
71
UnusableMainLoop (PyObject *always_null UNUSED, PyObject *args, PyObject *kwargs)
73
PyObject *mainloop, *function, *result;
74
int set_as_default = 0;
75
static char *argnames[] = {"set_as_default", NULL};
77
if (PyTuple_Size(args) != 0) {
78
PyErr_SetString(PyExc_TypeError, "UnusableMainLoop() takes no "
79
"positional arguments");
82
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", argnames,
87
mainloop = dbus_test_native_mainloop();
88
if (mainloop && set_as_default) {
89
if (!_dbus_bindings_module) {
90
PyErr_SetString(PyExc_ImportError, "_dbus_bindings not imported");
94
function = PyObject_GetAttrString(_dbus_bindings_module,
95
"set_default_main_loop");
100
result = PyObject_CallFunctionObjArgs(function, mainloop, NULL);
110
static PyMethodDef module_functions[] = {
111
{"UnusableMainLoop", (PyCFunction)UnusableMainLoop,
112
METH_VARARGS|METH_KEYWORDS, "Return a main loop that fails to attach"},
113
{NULL, NULL, 0, NULL}
117
initdbus_py_test(void)
119
PyObject *this_module;
121
if (import_dbus_bindings("dbus_py_test") < 0) return;
122
this_module = Py_InitModule3 ("dbus_py_test", module_functions, "");
123
if (!this_module) return;
126
/* vim:set ft=c cino< sw=4 sts=4 et: */