1
0
mirror of https://gitlab.gnome.org/GNOME/glib.git synced 2025-10-22 13:11:25 +02:00
Files
build
docs
gio
completion
fam
gdbus-2.0
gvdb
inotify
kqueue
tests
cert-tests
de
desktop-files
gdbus-object-manager-example
modules
schema-tests
services
thumbnails
x-content
.gitignore
Makefile.am
actions.c
appinfo-test-actions.desktop
appinfo-test-gnome.desktop
appinfo-test-notgnome.desktop
appinfo-test.c
appinfo-test.desktop
appinfo-test2.desktop
appinfo.c
appmonitor.c
apps.c
async-close-output-stream.c
async-splice-output-stream.c
autoptr.c
basic-application.c
buffered-input-stream.c
buffered-output-stream.c
cancellable.c
contenttype.c
contexts.c
converter-stream.c
credentials.c
data-input-stream.c
data-output-stream.c
dbus-appinfo.c
dbus-launch.c
de.po
defaultvalue.c
desktop-app-info.c
echo-server.c
enums.xml.template
file.c
fileattributematcher.c
filter-cat.c
filter-streams.c
g-file-info-filesystem-readonly.c
g-file-info.c
g-file.c
g-icon.c
gapplication-example-actions.c
gapplication-example-cmdline.c
gapplication-example-cmdline2.c
gapplication-example-cmdline3.c
gapplication-example-dbushooks.c
gapplication-example-open.c
gapplication.c
gdbus-addresses.c
gdbus-auth.c
gdbus-bz627724.c
gdbus-close-pending.c
gdbus-connection-flush-helper.c
gdbus-connection-flush.c
gdbus-connection-loss.c
gdbus-connection-slow.c
gdbus-connection.c
gdbus-daemon.c
gdbus-error.c
gdbus-example-export.c
gdbus-example-objectmanager-client.c
gdbus-example-objectmanager-server.c
gdbus-example-own-name.c
gdbus-example-peer.c
gdbus-example-proxy-subclass.c
gdbus-example-server.c
gdbus-example-subtree.c
gdbus-example-unix-fd-client.c
gdbus-example-watch-name.c
gdbus-example-watch-proxy.c
gdbus-exit-on-close.c
gdbus-export.c
gdbus-introspection.c
gdbus-message.c
gdbus-names.c
gdbus-non-socket.c
gdbus-overflow.c
gdbus-peer-object-manager.c
gdbus-peer.c
gdbus-proxy-threads.c
gdbus-proxy-well-known-name.c
gdbus-proxy.c
gdbus-serialization.c
gdbus-sessionbus.c
gdbus-sessionbus.h
gdbus-test-codegen.c
gdbus-test-fixture.c
gdbus-tests.c
gdbus-tests.h
gdbus-testserver.c
gdbus-threading.c
gdbus-unix-addresses.c
gengiotypefuncs.py
gio-du.c
giomodule.c
glistmodel.c
gmenumodel.c
gnotification-server.c
gnotification-server.h
gnotification.c
gschema-compile.c
gsettings.c
gsubprocess-testprog.c
gsubprocess.c
gtesttlsbackend.c
gtesttlsbackend.h
gtlsconsoleinteraction.c
gtlsconsoleinteraction.h
httpd.c
inet-address.c
io-stream.c
live-g-file.c
live-g-file.txt
memory-input-stream.c
memory-output-stream.c
meson.build
mimeapps.c
monitor.c
network-address.c
network-monitor.c
org.gtk.schemasourcecheck.gschema.xml
org.gtk.test.dbusappinfo.desktop
org.gtk.test.gschema.xml.orig
permission.c
pollable.c
proxy-test.c
proxy.c
readwrite.c
resolver.c
resourceplugin.c
resources.c
send-data.c
simple-async-result.c
simple-proxy.c
sleepy-stream.c
socket-address.c
socket-client.c
socket-common.c
socket-listener.c
socket-server.c
socket-service.c
socket.c
srvtarget.c
stream-rw_all.c
task.c
test-codegen.xml
test-io-stream.c
test-io-stream.h
test-pipe-unix.c
test-pipe-unix.h
test.gresource.xml
test1.txt
test2.gresource.xml
test2.txt
test3.gresource.xml
test3.txt
test4.gresource.xml
testenum.h
testfilemonitor.c
thumbnail-verification.c
tls-certificate.c
tls-interaction.c
unix-fd.c
unix-mounts.c
unix-streams.c
vfs.c
volumemonitor.c
win32-streams.c
win32
xdgmime
.gitignore
ChangeLog
Makefile.am
data-to-c.py
dbus-daemon.xml
gaction.c
gaction.h
gactiongroup.c
gactiongroup.h
gactiongroupexporter.c
gactiongroupexporter.h
gactionmap.c
gactionmap.h
gappinfo.c
gappinfo.h
gappinfoprivate.h
gapplication-tool.c
gapplication.c
gapplication.h
gapplicationcommandline.c
gapplicationcommandline.h
gapplicationimpl-dbus.c
gapplicationimpl.h
gasynchelper.c
gasynchelper.h
gasyncinitable.c
gasyncinitable.h
gasyncresult.c
gasyncresult.h
gbufferedinputstream.c
gbufferedinputstream.h
gbufferedoutputstream.c
gbufferedoutputstream.h
gbytesicon.c
gbytesicon.h
gcancellable.c
gcancellable.h
gcharsetconverter.c
gcharsetconverter.h
gcocoanotificationbackend.c
gcontenttype-win32.c
gcontenttype.c
gcontenttype.h
gcontenttypeprivate.h
gcontextspecificgroup.c
gcontextspecificgroup.h
gconverter.c
gconverter.h
gconverterinputstream.c
gconverterinputstream.h
gconverteroutputstream.c
gconverteroutputstream.h
gcredentials.c
gcredentials.h
gcredentialsprivate.h
gdatagrambased.c
gdatagrambased.h
gdatainputstream.c
gdatainputstream.h
gdataoutputstream.c
gdataoutputstream.h
gdbus-tool.c
gdbusactiongroup-private.h
gdbusactiongroup.c
gdbusactiongroup.h
gdbusaddress.c
gdbusaddress.h
gdbusauth.c
gdbusauth.h
gdbusauthmechanism.c
gdbusauthmechanism.h
gdbusauthmechanismanon.c
gdbusauthmechanismanon.h
gdbusauthmechanismexternal.c
gdbusauthmechanismexternal.h
gdbusauthmechanismsha1.c
gdbusauthmechanismsha1.h
gdbusauthobserver.c
gdbusauthobserver.h
gdbusconnection.c
gdbusconnection.h
gdbusdaemon.c
gdbusdaemon.h
gdbuserror.c
gdbuserror.h
gdbusinterface.c
gdbusinterface.h
gdbusinterfaceskeleton.c
gdbusinterfaceskeleton.h
gdbusintrospection.c
gdbusintrospection.h
gdbusmenumodel.c
gdbusmenumodel.h
gdbusmessage.c
gdbusmessage.h
gdbusmethodinvocation.c
gdbusmethodinvocation.h
gdbusnameowning.c
gdbusnameowning.h
gdbusnamewatching.c
gdbusnamewatching.h
gdbusobject.c
gdbusobject.h
gdbusobjectmanager.c
gdbusobjectmanager.h
gdbusobjectmanagerclient.c
gdbusobjectmanagerclient.h
gdbusobjectmanagerserver.c
gdbusobjectmanagerserver.h
gdbusobjectproxy.c
gdbusobjectproxy.h
gdbusobjectskeleton.c
gdbusobjectskeleton.h
gdbusprivate.c
gdbusprivate.h
gdbusproxy.c
gdbusproxy.h
gdbusserver.c
gdbusserver.h
gdbusutils.c
gdbusutils.h
gdelayedsettingsbackend.c
gdelayedsettingsbackend.h
gdesktopappinfo.c
gdesktopappinfo.h
gdocumentportal.c
gdocumentportal.h
gdrive.c
gdrive.h
gdtlsclientconnection.c
gdtlsclientconnection.h
gdtlsconnection.c
gdtlsconnection.h
gdtlsserverconnection.c
gdtlsserverconnection.h
gdummyfile.c
gdummyfile.h
gdummyproxyresolver.c
gdummyproxyresolver.h
gdummytlsbackend.c
gdummytlsbackend.h
gemblem.c
gemblem.h
gemblemedicon.c
gemblemedicon.h
gfdonotificationbackend.c
gfile.c
gfile.h
gfileattribute-priv.h
gfileattribute.c
gfileattribute.h
gfiledescriptorbased.c
gfiledescriptorbased.h
gfileenumerator.c
gfileenumerator.h
gfileicon.c
gfileicon.h
gfileinfo-priv.h
gfileinfo.c
gfileinfo.h
gfileinputstream.c
gfileinputstream.h
gfileiostream.c
gfileiostream.h
gfilemonitor.c
gfilemonitor.h
gfilenamecompleter.c
gfilenamecompleter.h
gfileoutputstream.c
gfileoutputstream.h
gfilterinputstream.c
gfilterinputstream.h
gfilteroutputstream.c
gfilteroutputstream.h
ggtknotificationbackend.c
ghttpproxy.c
ghttpproxy.h
gicon.c
gicon.h
ginetaddress.c
ginetaddress.h
ginetaddressmask.c
ginetaddressmask.h
ginetsocketaddress.c
ginetsocketaddress.h
ginitable.c
ginitable.h
ginputstream.c
ginputstream.h
gio-autocleanups.h
gio-querymodules.c
gio-tool-cat.c
gio-tool-copy.c
gio-tool-info.c
gio-tool-list.c
gio-tool-mime.c
gio-tool-mkdir.c
gio-tool-monitor.c
gio-tool-mount.c
gio-tool-move.c
gio-tool-open.c
gio-tool-remove.c
gio-tool-rename.c
gio-tool-save.c
gio-tool-set.c
gio-tool-trash.c
gio-tool-tree.c
gio-tool.c
gio-tool.h
gio.h
gio.rc.in
gio.stp.in
gio_probes.d
gio_trace.h
gioenums.h
gioenumtypes.c.template
gioenumtypes.h.template
gioerror.c
gioerror.h
giomodule-priv.h
giomodule.c
giomodule.h
gioprivate.h
gioscheduler.c
gioscheduler.h
giostream.c
giostream.h
giotypes.h
giowin32-priv.h
gkeyfilesettingsbackend.c
glib-compile-resources.c
glib-compile-schemas.c
glistmodel.c
glistmodel.h
gliststore.c
gliststore.h
gloadableicon.c
gloadableicon.h
glocalfile.c
glocalfile.h
glocalfileenumerator.c
glocalfileenumerator.h
glocalfileinfo.c
glocalfileinfo.h
glocalfileinputstream.c
glocalfileinputstream.h
glocalfileiostream.c
glocalfileiostream.h
glocalfilemonitor.c
glocalfilemonitor.h
glocalfileoutputstream.c
glocalfileoutputstream.h
glocalfileprivate.h
glocalvfs.c
glocalvfs.h
gmemoryinputstream.c
gmemoryinputstream.h
gmemoryoutputstream.c
gmemoryoutputstream.h
gmemorysettingsbackend.c
gmenu.c
gmenu.h
gmenuexporter.c
gmenuexporter.h
gmenumodel.c
gmenumodel.h
gmount.c
gmount.h
gmountoperation.c
gmountoperation.h
gmountprivate.h
gnativesocketaddress.c
gnativesocketaddress.h
gnativevolumemonitor.c
gnativevolumemonitor.h
gnetworkaddress.c
gnetworkaddress.h
gnetworking.c
gnetworking.h.in
gnetworking.h.win32
gnetworkingprivate.h
gnetworkmonitor.c
gnetworkmonitor.h
gnetworkmonitorbase.c
gnetworkmonitorbase.h
gnetworkmonitornetlink.c
gnetworkmonitornetlink.h
gnetworkmonitornm.c
gnetworkmonitornm.h
gnetworkmonitorportal.c
gnetworkmonitorportal.h
gnetworkservice.c
gnetworkservice.h
gnextstepsettingsbackend.c
gnotification-private.h
gnotification.c
gnotification.h
gnotificationbackend.c
gnotificationbackend.h
gnullsettingsbackend.c
gopenuriportal.c
gopenuriportal.h
gosxappinfo.c
gosxappinfo.h
gosxcontenttype.c
goutputstream.c
goutputstream.h
gpermission.c
gpermission.h
gpollableinputstream.c
gpollableinputstream.h
gpollableoutputstream.c
gpollableoutputstream.h
gpollableutils.c
gpollableutils.h
gpollfilemonitor.c
gpollfilemonitor.h
gportalnotificationbackend.c
gportalsupport.c
gportalsupport.h
gpropertyaction.c
gpropertyaction.h
gproxy.c
gproxy.h
gproxyaddress.c
gproxyaddress.h
gproxyaddressenumerator.c
gproxyaddressenumerator.h
gproxyresolver.c
gproxyresolver.h
gproxyresolverportal.c
gproxyresolverportal.h
gregistrysettingsbackend.c
gregistrysettingsbackend.h
gremoteactiongroup.c
gremoteactiongroup.h
gresolver.c
gresolver.h
gresource-tool.c
gresource.c
gresource.h
gresourcefile.c
gresourcefile.h
gschema.dtd
gschema.its
gschema.loc
gseekable.c
gseekable.h
gsettings-mapping.c
gsettings-mapping.h
gsettings-tool.c
gsettings.c
gsettings.h
gsettingsbackend.c
gsettingsbackend.h
gsettingsbackendinternal.h
gsettingsschema-internal.h
gsettingsschema.c
gsettingsschema.h
gsimpleaction.c
gsimpleaction.h
gsimpleactiongroup.c
gsimpleactiongroup.h
gsimpleasyncresult.c
gsimpleasyncresult.h
gsimpleiostream.c
gsimpleiostream.h
gsimplepermission.c
gsimplepermission.h
gsimpleproxyresolver.c
gsimpleproxyresolver.h
gsocket.c
gsocket.h
gsocketaddress.c
gsocketaddress.h
gsocketaddressenumerator.c
gsocketaddressenumerator.h
gsocketclient.c
gsocketclient.h
gsocketconnectable.c
gsocketconnectable.h
gsocketconnection.c
gsocketconnection.h
gsocketcontrolmessage.c
gsocketcontrolmessage.h
gsocketinputstream.c
gsocketinputstream.h
gsocketlistener.c
gsocketlistener.h
gsocketoutputstream.c
gsocketoutputstream.h
gsocketservice.c
gsocketservice.h
gsocks4aproxy.c
gsocks4aproxy.h
gsocks4proxy.c
gsocks4proxy.h
gsocks5proxy.c
gsocks5proxy.h
gsrvtarget.c
gsrvtarget.h
gsubprocess.c
gsubprocess.h
gsubprocesslauncher-private.h
gsubprocesslauncher.c
gsubprocesslauncher.h
gtask.c
gtask.h
gtcpconnection.c
gtcpconnection.h
gtcpwrapperconnection.c
gtcpwrapperconnection.h
gtestdbus.c
gtestdbus.h
gthemedicon.c
gthemedicon.h
gthreadedresolver.c
gthreadedresolver.h
gthreadedsocketservice.c
gthreadedsocketservice.h
gtlsbackend.c
gtlsbackend.h
gtlscertificate.c
gtlscertificate.h
gtlsclientconnection.c
gtlsclientconnection.h
gtlsconnection.c
gtlsconnection.h
gtlsdatabase.c
gtlsdatabase.h
gtlsfiledatabase.c
gtlsfiledatabase.h
gtlsinteraction.c
gtlsinteraction.h
gtlspassword.c
gtlspassword.h
gtlsserverconnection.c
gtlsserverconnection.h
gunionvolumemonitor.c
gunionvolumemonitor.h
gunixconnection.c
gunixconnection.h
gunixcredentialsmessage.c
gunixcredentialsmessage.h
gunixfdlist.c
gunixfdlist.h
gunixfdmessage.c
gunixfdmessage.h
gunixinputstream.c
gunixinputstream.h
gunixmount.c
gunixmount.h
gunixmounts.c
gunixmounts.h
gunixoutputstream.c
gunixoutputstream.h
gunixsocketaddress.c
gunixsocketaddress.h
gunixvolume.c
gunixvolume.h
gunixvolumemonitor.c
gunixvolumemonitor.h
gvfs.c
gvfs.h
gvolume.c
gvolume.h
gvolumemonitor.c
gvolumemonitor.h
gwin32appinfo.c
gwin32appinfo.h
gwin32inputstream.c
gwin32inputstream.h
gwin32mount.c
gwin32mount.h
gwin32networking.h
gwin32outputstream.c
gwin32outputstream.h
gwin32registrykey.c
gwin32registrykey.h
gwin32volumemonitor.c
gwin32volumemonitor.h
gzlibcompressor.c
gzlibcompressor.h
gzlibdecompressor.c
gzlibdecompressor.h
meson.build
org.freedesktop.portal.Documents.xml
org.freedesktop.portal.NetworkMonitor.xml
org.freedesktop.portal.OpenURI.xml
org.freedesktop.portal.ProxyResolver.xml
strinfo.c
thumbnail-verify.c
thumbnail-verify.h
glib
gmodule
gobject
gthread
m4macros
po
subprojects
tests
win32
.dir-locals.el
.gitattributes
.gitignore
AUTHORS
COPYING
ChangeLog.pre-1-2
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-14
ChangeLog.pre-2-16
ChangeLog.pre-2-18
ChangeLog.pre-2-2
ChangeLog.pre-2-20
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
HACKING
INSTALL.in
Makefile.am
NEWS
NEWS.pre-1-3
README.commits
README.in
README.rationale
README.win32
acglib.m4
acinclude.m4
autogen.sh
check-abis.sh
config.h.meson
config.h.win32.in
configure.ac
gio-2.0.pc.in
gio-unix-2.0.pc.in
gio-windows-2.0.pc.in
glib-2.0.pc.in
glib-gettextize.in
glib-tap.mk
glib-zip.in
glib.doap
glib.mk
glib.supp
gmodule-2.0.pc.in
gmodule-export-2.0.pc.in
gmodule-no-export-2.0.pc.in
gobject-2.0.pc.in
gthread-2.0.pc.in
meson.build
meson_options.txt
msvc_recommended_pragmas.h
sanity_check
tap-driver.sh
tap-test
glib/gio/tests/gdbus-export.c
Sébastien Wilmet d9a44b66af gio/tests/: LGPLv2+ -> LGPLv2.1+
A lot of tests in gio/tests/ don't have a license header.

https://bugzilla.gnome.org/show_bug.cgi?id=776504
2017-05-29 19:53:34 +02:00

1797 lines
64 KiB
C

/* GLib testing framework examples and tests
*
* Copyright (C) 2008-2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
* Author: David Zeuthen <davidz@redhat.com>
*/
#include <gio/gio.h>
#include <unistd.h>
#include <string.h>
#include "gdbus-tests.h"
/* all tests rely on a shared mainloop */
static GMainLoop *loop = NULL;
static GDBusConnection *c = NULL;
/* ---------------------------------------------------------------------------------------------------- */
/* Test that we can export objects, the hierarchy is correct and the right handlers are invoked */
/* ---------------------------------------------------------------------------------------------------- */
static const GDBusArgInfo foo_method1_in_args =
{
-1,
"an_input_string",
"s",
NULL
};
static const GDBusArgInfo * const foo_method1_in_arg_pointers[] = {&foo_method1_in_args, NULL};
static const GDBusArgInfo foo_method1_out_args =
{
-1,
"an_output_string",
"s",
NULL
};
static const GDBusArgInfo * const foo_method1_out_arg_pointers[] = {&foo_method1_out_args, NULL};
static const GDBusMethodInfo foo_method_info_method1 =
{
-1,
"Method1",
(GDBusArgInfo **) &foo_method1_in_arg_pointers,
(GDBusArgInfo **) &foo_method1_out_arg_pointers,
NULL
};
static const GDBusMethodInfo foo_method_info_method2 =
{
-1,
"Method2",
NULL,
NULL,
NULL
};
static const GDBusMethodInfo * const foo_method_info_pointers[] = {&foo_method_info_method1, &foo_method_info_method2, NULL};
static const GDBusSignalInfo foo_signal_info =
{
-1,
"SignalAlpha",
NULL,
NULL
};
static const GDBusSignalInfo * const foo_signal_info_pointers[] = {&foo_signal_info, NULL};
static const GDBusPropertyInfo foo_property_info[] =
{
{
-1,
"PropertyUno",
"s",
G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE,
NULL
},
{
-1,
"NotWritable",
"s",
G_DBUS_PROPERTY_INFO_FLAGS_READABLE,
NULL
},
{
-1,
"NotReadable",
"s",
G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE,
NULL
}
};
static const GDBusPropertyInfo * const foo_property_info_pointers[] =
{
&foo_property_info[0],
&foo_property_info[1],
&foo_property_info[2],
NULL
};
static const GDBusInterfaceInfo foo_interface_info =
{
-1,
"org.example.Foo",
(GDBusMethodInfo **) &foo_method_info_pointers,
(GDBusSignalInfo **) &foo_signal_info_pointers,
(GDBusPropertyInfo **)&foo_property_info_pointers,
NULL,
};
/* Foo2 is just Foo without the properties */
static const GDBusInterfaceInfo foo2_interface_info =
{
-1,
"org.example.Foo2",
(GDBusMethodInfo **) &foo_method_info_pointers,
(GDBusSignalInfo **) &foo_signal_info_pointers,
};
static void
foo_method_call (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *method_name,
GVariant *parameters,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
if (g_strcmp0 (method_name, "Method1") == 0)
{
const gchar *input;
gchar *output;
g_variant_get (parameters, "(&s)", &input);
output = g_strdup_printf ("You passed the string '%s'. Jolly good!", input);
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", output));
g_free (output);
}
else
{
g_dbus_method_invocation_return_dbus_error (invocation,
"org.example.SomeError",
"How do you like them apples, buddy!");
}
}
static GVariant *
foo_get_property (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *property_name,
GError **error,
gpointer user_data)
{
GVariant *ret;
gchar *s;
s = g_strdup_printf ("Property '%s' Is What It Is!", property_name);
ret = g_variant_new_string (s);
g_free (s);
return ret;
}
static gboolean
foo_set_property (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *property_name,
GVariant *value,
GError **error,
gpointer user_data)
{
gchar *s;
s = g_variant_print (value, TRUE);
g_set_error (error,
G_DBUS_ERROR,
G_DBUS_ERROR_SPAWN_FILE_INVALID,
"Returning some error instead of writing the value '%s' to the property '%s'",
property_name, s);
g_free (s);
return FALSE;
}
static const GDBusInterfaceVTable foo_vtable =
{
foo_method_call,
foo_get_property,
foo_set_property
};
/* -------------------- */
static const GDBusMethodInfo bar_method_info[] =
{
{
-1,
"MethodA",
NULL,
NULL,
NULL
},
{
-1,
"MethodB",
NULL,
NULL,
NULL
}
};
static const GDBusMethodInfo * const bar_method_info_pointers[] = {&bar_method_info[0], &bar_method_info[1], NULL};
static const GDBusSignalInfo bar_signal_info[] =
{
{
-1,
"SignalMars",
NULL,
NULL
}
};
static const GDBusSignalInfo * const bar_signal_info_pointers[] = {&bar_signal_info[0], NULL};
static const GDBusPropertyInfo bar_property_info[] =
{
{
-1,
"PropertyDuo",
"s",
G_DBUS_PROPERTY_INFO_FLAGS_READABLE,
NULL
}
};
static const GDBusPropertyInfo * const bar_property_info_pointers[] = {&bar_property_info[0], NULL};
static const GDBusInterfaceInfo bar_interface_info =
{
-1,
"org.example.Bar",
(GDBusMethodInfo **) bar_method_info_pointers,
(GDBusSignalInfo **) bar_signal_info_pointers,
(GDBusPropertyInfo **) bar_property_info_pointers,
NULL,
};
/* -------------------- */
static const GDBusMethodInfo dyna_method_info[] =
{
{
-1,
"DynaCyber",
NULL,
NULL,
NULL
}
};
static const GDBusMethodInfo * const dyna_method_info_pointers[] = {&dyna_method_info[0], NULL};
static const GDBusInterfaceInfo dyna_interface_info =
{
-1,
"org.example.Dyna",
(GDBusMethodInfo **) dyna_method_info_pointers,
NULL, /* no signals */
NULL, /* no properties */
NULL,
};
static void
dyna_cyber (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *method_name,
GVariant *parameters,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
GPtrArray *data = user_data;
gchar *node_name;
guint n;
node_name = strrchr (object_path, '/') + 1;
/* Add new node if it is not already known */
for (n = 0; n < data->len ; n++)
{
if (g_strcmp0 (g_ptr_array_index (data, n), node_name) == 0)
goto out;
}
g_ptr_array_add (data, g_strdup(node_name));
out:
g_dbus_method_invocation_return_value (invocation, NULL);
}
static const GDBusInterfaceVTable dyna_interface_vtable =
{
dyna_cyber,
NULL,
NULL
};
/* ---------------------------------------------------------------------------------------------------- */
static void
introspect_callback (GDBusProxy *proxy,
GAsyncResult *res,
gpointer user_data)
{
gchar **xml_data = user_data;
GVariant *result;
GError *error;
error = NULL;
result = g_dbus_proxy_call_finish (proxy,
res,
&error);
g_assert_no_error (error);
g_assert (result != NULL);
g_variant_get (result, "(s)", xml_data);
g_variant_unref (result);
g_main_loop_quit (loop);
}
static gchar **
get_nodes_at (GDBusConnection *c,
const gchar *object_path)
{
GError *error;
GDBusProxy *proxy;
gchar *xml_data;
GPtrArray *p;
GDBusNodeInfo *node_info;
guint n;
error = NULL;
proxy = g_dbus_proxy_new_sync (c,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
NULL,
g_dbus_connection_get_unique_name (c),
object_path,
"org.freedesktop.DBus.Introspectable",
NULL,
&error);
g_assert_no_error (error);
g_assert (proxy != NULL);
/* do this async to avoid libdbus-1 deadlocks */
xml_data = NULL;
g_dbus_proxy_call (proxy,
"Introspect",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
(GAsyncReadyCallback) introspect_callback,
&xml_data);
g_main_loop_run (loop);
g_assert (xml_data != NULL);
node_info = g_dbus_node_info_new_for_xml (xml_data, &error);
g_assert_no_error (error);
g_assert (node_info != NULL);
p = g_ptr_array_new ();
for (n = 0; node_info->nodes != NULL && node_info->nodes[n] != NULL; n++)
{
const GDBusNodeInfo *sub_node_info = node_info->nodes[n];
g_ptr_array_add (p, g_strdup (sub_node_info->path));
}
g_ptr_array_add (p, NULL);
g_object_unref (proxy);
g_free (xml_data);
g_dbus_node_info_unref (node_info);
return (gchar **) g_ptr_array_free (p, FALSE);
}
static gboolean
has_interface (GDBusConnection *c,
const gchar *object_path,
const gchar *interface_name)
{
GError *error;
GDBusProxy *proxy;
gchar *xml_data;
GDBusNodeInfo *node_info;
gboolean ret;
error = NULL;
proxy = g_dbus_proxy_new_sync (c,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
NULL,
g_dbus_connection_get_unique_name (c),
object_path,
"org.freedesktop.DBus.Introspectable",
NULL,
&error);
g_assert_no_error (error);
g_assert (proxy != NULL);
/* do this async to avoid libdbus-1 deadlocks */
xml_data = NULL;
g_dbus_proxy_call (proxy,
"Introspect",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
(GAsyncReadyCallback) introspect_callback,
&xml_data);
g_main_loop_run (loop);
g_assert (xml_data != NULL);
node_info = g_dbus_node_info_new_for_xml (xml_data, &error);
g_assert_no_error (error);
g_assert (node_info != NULL);
ret = (g_dbus_node_info_lookup_interface (node_info, interface_name) != NULL);
g_object_unref (proxy);
g_free (xml_data);
g_dbus_node_info_unref (node_info);
return ret;
}
static guint
count_interfaces (GDBusConnection *c,
const gchar *object_path)
{
GError *error;
GDBusProxy *proxy;
gchar *xml_data;
GDBusNodeInfo *node_info;
guint ret;
error = NULL;
proxy = g_dbus_proxy_new_sync (c,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
NULL,
g_dbus_connection_get_unique_name (c),
object_path,
"org.freedesktop.DBus.Introspectable",
NULL,
&error);
g_assert_no_error (error);
g_assert (proxy != NULL);
/* do this async to avoid libdbus-1 deadlocks */
xml_data = NULL;
g_dbus_proxy_call (proxy,
"Introspect",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
(GAsyncReadyCallback) introspect_callback,
&xml_data);
g_main_loop_run (loop);
g_assert (xml_data != NULL);
node_info = g_dbus_node_info_new_for_xml (xml_data, &error);
g_assert_no_error (error);
g_assert (node_info != NULL);
ret = 0;
while (node_info->interfaces != NULL && node_info->interfaces[ret] != NULL)
ret++;
g_object_unref (proxy);
g_free (xml_data);
g_dbus_node_info_unref (node_info);
return ret;
}
static void
dyna_create_callback (GDBusProxy *proxy,
GAsyncResult *res,
gpointer user_data)
{
GVariant *result;
GError *error;
error = NULL;
result = g_dbus_proxy_call_finish (proxy,
res,
&error);
g_assert_no_error (error);
g_assert (result != NULL);
g_variant_unref (result);
g_main_loop_quit (loop);
}
/* Dynamically create @object_name under /foo/dyna */
static void
dyna_create (GDBusConnection *c,
const gchar *object_name)
{
GError *error;
GDBusProxy *proxy;
gchar *object_path;
object_path = g_strconcat ("/foo/dyna/", object_name, NULL);
error = NULL;
proxy = g_dbus_proxy_new_sync (c,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
NULL,
g_dbus_connection_get_unique_name (c),
object_path,
"org.example.Dyna",
NULL,
&error);
g_assert_no_error (error);
g_assert (proxy != NULL);
/* do this async to avoid libdbus-1 deadlocks */
g_dbus_proxy_call (proxy,
"DynaCyber",
g_variant_new ("()"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
(GAsyncReadyCallback) dyna_create_callback,
NULL);
g_main_loop_run (loop);
g_assert_no_error (error);
g_object_unref (proxy);
g_free (object_path);
return;
}
typedef struct
{
guint num_unregistered_calls;
guint num_unregistered_subtree_calls;
guint num_subtree_nodes;
} ObjectRegistrationData;
static void
on_object_unregistered (gpointer user_data)
{
ObjectRegistrationData *data = user_data;
data->num_unregistered_calls++;
}
static void
on_subtree_unregistered (gpointer user_data)
{
ObjectRegistrationData *data = user_data;
data->num_unregistered_subtree_calls++;
}
static gboolean
_g_strv_has_string (const gchar* const * haystack,
const gchar *needle)
{
guint n;
for (n = 0; haystack != NULL && haystack[n] != NULL; n++)
{
if (g_strcmp0 (haystack[n], needle) == 0)
return TRUE;
}
return FALSE;
}
/* -------------------- */
static gchar **
subtree_enumerate (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
gpointer user_data)
{
ObjectRegistrationData *data = user_data;
GPtrArray *p;
gchar **nodes;
guint n;
p = g_ptr_array_new ();
for (n = 0; n < data->num_subtree_nodes; n++)
{
g_ptr_array_add (p, g_strdup_printf ("vp%d", n));
g_ptr_array_add (p, g_strdup_printf ("evp%d", n));
}
g_ptr_array_add (p, NULL);
nodes = (gchar **) g_ptr_array_free (p, FALSE);
return nodes;
}
/* Only allows certain objects, and aborts on unknowns */
static GDBusInterfaceInfo **
subtree_introspect (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *node,
gpointer user_data)
{
const GDBusInterfaceInfo *interfaces[2] = {
NULL /* filled in below */, NULL
};
/* VPs implement the Foo interface, EVPs implement the Bar interface. The root
* does not implement any interfaces
*/
if (node == NULL)
{
return NULL;
}
else if (g_str_has_prefix (node, "vp"))
{
interfaces[0] = &foo_interface_info;
}
else if (g_str_has_prefix (node, "evp"))
{
interfaces[0] = &bar_interface_info;
}
else
{
g_assert_not_reached ();
}
return g_memdup (interfaces, 2 * sizeof (void *));
}
static const GDBusInterfaceVTable *
subtree_dispatch (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *node,
gpointer *out_user_data,
gpointer user_data)
{
if (g_strcmp0 (interface_name, "org.example.Foo") == 0)
return &foo_vtable;
else
return NULL;
}
static const GDBusSubtreeVTable subtree_vtable =
{
subtree_enumerate,
subtree_introspect,
subtree_dispatch
};
/* -------------------- */
static gchar **
dynamic_subtree_enumerate (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
gpointer user_data)
{
GPtrArray *data = user_data;
gchar **nodes = g_new (gchar*, data->len + 1);
guint n;
for (n = 0; n < data->len; n++)
{
nodes[n] = g_strdup (g_ptr_array_index (data, n));
}
nodes[data->len] = NULL;
return nodes;
}
/* Allow all objects to be introspected */
static GDBusInterfaceInfo **
dynamic_subtree_introspect (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *node,
gpointer user_data)
{
const GDBusInterfaceInfo *interfaces[2] = { &dyna_interface_info, NULL };
return g_memdup (interfaces, 2 * sizeof (void *));
}
static const GDBusInterfaceVTable *
dynamic_subtree_dispatch (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *node,
gpointer *out_user_data,
gpointer user_data)
{
*out_user_data = user_data;
return &dyna_interface_vtable;
}
static const GDBusSubtreeVTable dynamic_subtree_vtable =
{
dynamic_subtree_enumerate,
dynamic_subtree_introspect,
dynamic_subtree_dispatch
};
/* -------------------- */
typedef struct
{
const gchar *object_path;
gboolean check_remote_errors;
} TestDispatchThreadFuncArgs;
static gpointer
test_dispatch_thread_func (gpointer user_data)
{
TestDispatchThreadFuncArgs *args = user_data;
const gchar *object_path = args->object_path;
GDBusProxy *foo_proxy;
GVariant *value;
GVariant *inner;
GError *error;
gchar *s;
const gchar *value_str;
foo_proxy = g_dbus_proxy_new_sync (c,
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
NULL,
g_dbus_connection_get_unique_name (c),
object_path,
"org.example.Foo",
NULL,
&error);
g_assert (foo_proxy != NULL);
/* generic interfaces */
error = NULL;
value = g_dbus_proxy_call_sync (foo_proxy,
"org.freedesktop.DBus.Peer.Ping",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
g_assert_no_error (error);
g_assert (value != NULL);
g_variant_unref (value);
/* user methods */
error = NULL;
value = g_dbus_proxy_call_sync (foo_proxy,
"Method1",
g_variant_new ("(s)", "winwinwin"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
g_assert_no_error (error);
g_assert (value != NULL);
g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("(s)")));
g_variant_get (value, "(&s)", &value_str);
g_assert_cmpstr (value_str, ==, "You passed the string 'winwinwin'. Jolly good!");
g_variant_unref (value);
error = NULL;
value = g_dbus_proxy_call_sync (foo_proxy,
"Method2",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR);
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.example.SomeError: How do you like them apples, buddy!");
g_error_free (error);
g_assert (value == NULL);
error = NULL;
value = g_dbus_proxy_call_sync (foo_proxy,
"Method2",
g_variant_new ("(s)", "failfailfail"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Type of message, '(s)', does not match expected type '()'");
g_error_free (error);
g_assert (value == NULL);
error = NULL;
value = g_dbus_proxy_call_sync (foo_proxy,
"NonExistantMethod",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such method 'NonExistantMethod'");
g_error_free (error);
g_assert (value == NULL);
error = NULL;
value = g_dbus_proxy_call_sync (foo_proxy,
"org.example.FooXYZ.NonExistant",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
g_error_free (error);
g_assert (value == NULL);
/* user properties */
error = NULL;
value = g_dbus_proxy_call_sync (foo_proxy,
"org.freedesktop.DBus.Properties.Get",
g_variant_new ("(ss)",
"org.example.Foo",
"PropertyUno"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
g_assert_no_error (error);
g_assert (value != NULL);
g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("(v)")));
g_variant_get (value, "(v)", &inner);
g_assert (g_variant_is_of_type (inner, G_VARIANT_TYPE_STRING));
g_assert_cmpstr (g_variant_get_string (inner, NULL), ==, "Property 'PropertyUno' Is What It Is!");
g_variant_unref (value);
g_variant_unref (inner);
error = NULL;
value = g_dbus_proxy_call_sync (foo_proxy,
"org.freedesktop.DBus.Properties.Get",
g_variant_new ("(ss)",
"org.example.Foo",
"ThisDoesntExist"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
g_assert (value == NULL);
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: No such property 'ThisDoesntExist'");
g_error_free (error);
error = NULL;
value = g_dbus_proxy_call_sync (foo_proxy,
"org.freedesktop.DBus.Properties.Get",
g_variant_new ("(ss)",
"org.example.Foo",
"NotReadable"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
g_assert (value == NULL);
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Property 'NotReadable' is not readable");
g_error_free (error);
error = NULL;
value = g_dbus_proxy_call_sync (foo_proxy,
"org.freedesktop.DBus.Properties.Set",
g_variant_new ("(ssv)",
"org.example.Foo",
"NotReadable",
g_variant_new_string ("But Writable you are!")),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
g_assert (value == NULL);
if (args->check_remote_errors)
{
/* _with_closures variant doesn't support customizing error data. */
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_FILE_INVALID);
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.Spawn.FileInvalid: Returning some error instead of writing the value 'NotReadable' to the property ''But Writable you are!''");
}
g_assert (error != NULL && error->domain == G_DBUS_ERROR);
g_error_free (error);
error = NULL;
value = g_dbus_proxy_call_sync (foo_proxy,
"org.freedesktop.DBus.Properties.Set",
g_variant_new ("(ssv)",
"org.example.Foo",
"NotWritable",
g_variant_new_uint32 (42)),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
g_assert (value == NULL);
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
g_assert_cmpstr (error->message, ==, "GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: Property 'NotWritable' is not writable");
g_error_free (error);
error = NULL;
value = g_dbus_proxy_call_sync (foo_proxy,
"org.freedesktop.DBus.Properties.GetAll",
g_variant_new ("(s)",
"org.example.Foo"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
g_assert_no_error (error);
g_assert (value != NULL);
g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE ("(a{sv})")));
s = g_variant_print (value, TRUE);
g_assert_cmpstr (s, ==, "({'PropertyUno': <\"Property 'PropertyUno' Is What It Is!\">, 'NotWritable': <\"Property 'NotWritable' Is What It Is!\">},)");
g_free (s);
g_variant_unref (value);
g_object_unref (foo_proxy);
g_main_loop_quit (loop);
return NULL;
}
static void
test_dispatch (const gchar *object_path,
gboolean check_remote_errors)
{
GThread *thread;
TestDispatchThreadFuncArgs args = {object_path, check_remote_errors};
/* run this in a thread to avoid deadlocks */
thread = g_thread_new ("test_dispatch",
test_dispatch_thread_func,
(gpointer) &args);
g_main_loop_run (loop);
g_thread_join (thread);
}
static void
test_object_registration (void)
{
GError *error;
ObjectRegistrationData data;
GPtrArray *dyna_data;
gchar **nodes;
guint boss_foo_reg_id;
guint boss_bar_reg_id;
guint worker1_foo_reg_id;
guint worker1p1_foo_reg_id;
guint worker2_bar_reg_id;
guint intern1_foo_reg_id;
guint intern2_bar_reg_id;
guint intern2_foo_reg_id;
guint intern3_bar_reg_id;
guint registration_id;
guint subtree_registration_id;
guint non_subtree_object_path_foo_reg_id;
guint non_subtree_object_path_bar_reg_id;
guint dyna_subtree_registration_id;
guint num_successful_registrations;
data.num_unregistered_calls = 0;
data.num_unregistered_subtree_calls = 0;
data.num_subtree_nodes = 0;
num_successful_registrations = 0;
error = NULL;
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error (error);
g_assert (c != NULL);
registration_id = g_dbus_connection_register_object (c,
"/foo/boss",
(GDBusInterfaceInfo *) &foo_interface_info,
&foo_vtable,
&data,
on_object_unregistered,
&error);
g_assert_no_error (error);
g_assert (registration_id > 0);
boss_foo_reg_id = registration_id;
num_successful_registrations++;
registration_id = g_dbus_connection_register_object (c,
"/foo/boss",
(GDBusInterfaceInfo *) &bar_interface_info,
NULL,
&data,
on_object_unregistered,
&error);
g_assert_no_error (error);
g_assert (registration_id > 0);
boss_bar_reg_id = registration_id;
num_successful_registrations++;
registration_id = g_dbus_connection_register_object (c,
"/foo/boss/worker1",
(GDBusInterfaceInfo *) &foo_interface_info,
NULL,
&data,
on_object_unregistered,
&error);
g_assert_no_error (error);
g_assert (registration_id > 0);
worker1_foo_reg_id = registration_id;
num_successful_registrations++;
registration_id = g_dbus_connection_register_object (c,
"/foo/boss/worker1p1",
(GDBusInterfaceInfo *) &foo_interface_info,
NULL,
&data,
on_object_unregistered,
&error);
g_assert_no_error (error);
g_assert (registration_id > 0);
worker1p1_foo_reg_id = registration_id;
num_successful_registrations++;
registration_id = g_dbus_connection_register_object (c,
"/foo/boss/worker2",
(GDBusInterfaceInfo *) &bar_interface_info,
NULL,
&data,
on_object_unregistered,
&error);
g_assert_no_error (error);
g_assert (registration_id > 0);
worker2_bar_reg_id = registration_id;
num_successful_registrations++;
registration_id = g_dbus_connection_register_object (c,
"/foo/boss/interns/intern1",
(GDBusInterfaceInfo *) &foo_interface_info,
NULL,
&data,
on_object_unregistered,
&error);
g_assert_no_error (error);
g_assert (registration_id > 0);
intern1_foo_reg_id = registration_id;
num_successful_registrations++;
/* ... and try again at another path */
registration_id = g_dbus_connection_register_object (c,
"/foo/boss/interns/intern2",
(GDBusInterfaceInfo *) &bar_interface_info,
NULL,
&data,
on_object_unregistered,
&error);
g_assert_no_error (error);
g_assert (registration_id > 0);
intern2_bar_reg_id = registration_id;
num_successful_registrations++;
/* register at the same path/interface - this should fail */
registration_id = g_dbus_connection_register_object (c,
"/foo/boss/interns/intern2",
(GDBusInterfaceInfo *) &bar_interface_info,
NULL,
&data,
on_object_unregistered,
&error);
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS);
g_assert (!g_dbus_error_is_remote_error (error));
g_error_free (error);
error = NULL;
g_assert (registration_id == 0);
/* register at different interface - shouldn't fail */
registration_id = g_dbus_connection_register_object (c,
"/foo/boss/interns/intern2",
(GDBusInterfaceInfo *) &foo_interface_info,
NULL,
&data,
on_object_unregistered,
&error);
g_assert_no_error (error);
g_assert (registration_id > 0);
intern2_foo_reg_id = registration_id;
num_successful_registrations++;
/* unregister it via the id */
g_assert (g_dbus_connection_unregister_object (c, registration_id));
g_main_context_iteration (NULL, FALSE);
g_assert_cmpint (data.num_unregistered_calls, ==, 1);
intern2_foo_reg_id = 0;
/* register it back */
registration_id = g_dbus_connection_register_object (c,
"/foo/boss/interns/intern2",
(GDBusInterfaceInfo *) &foo_interface_info,
NULL,
&data,
on_object_unregistered,
&error);
g_assert_no_error (error);
g_assert (registration_id > 0);
intern2_foo_reg_id = registration_id;
num_successful_registrations++;
registration_id = g_dbus_connection_register_object (c,
"/foo/boss/interns/intern3",
(GDBusInterfaceInfo *) &bar_interface_info,
NULL,
&data,
on_object_unregistered,
&error);
g_assert_no_error (error);
g_assert (registration_id > 0);
intern3_bar_reg_id = registration_id;
num_successful_registrations++;
/* now register a whole subtree at /foo/boss/executives */
subtree_registration_id = g_dbus_connection_register_subtree (c,
"/foo/boss/executives",
&subtree_vtable,
G_DBUS_SUBTREE_FLAGS_NONE,
&data,
on_subtree_unregistered,
&error);
g_assert_no_error (error);
g_assert (subtree_registration_id > 0);
/* try registering it again.. this should fail */
registration_id = g_dbus_connection_register_subtree (c,
"/foo/boss/executives",
&subtree_vtable,
G_DBUS_SUBTREE_FLAGS_NONE,
&data,
on_subtree_unregistered,
&error);
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS);
g_assert (!g_dbus_error_is_remote_error (error));
g_error_free (error);
error = NULL;
g_assert (registration_id == 0);
/* unregister it, then register it again */
g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 0);
g_assert (g_dbus_connection_unregister_subtree (c, subtree_registration_id));
g_main_context_iteration (NULL, FALSE);
g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 1);
subtree_registration_id = g_dbus_connection_register_subtree (c,
"/foo/boss/executives",
&subtree_vtable,
G_DBUS_SUBTREE_FLAGS_NONE,
&data,
on_subtree_unregistered,
&error);
g_assert_no_error (error);
g_assert (subtree_registration_id > 0);
/* try to register something under /foo/boss/executives - this should work
* because registered subtrees and registered objects can coexist.
*
* Make the exported object implement *two* interfaces so we can check
* that the right introspection handler is invoked.
*/
registration_id = g_dbus_connection_register_object (c,
"/foo/boss/executives/non_subtree_object",
(GDBusInterfaceInfo *) &bar_interface_info,
NULL,
&data,
on_object_unregistered,
&error);
g_assert_no_error (error);
g_assert (registration_id > 0);
non_subtree_object_path_bar_reg_id = registration_id;
num_successful_registrations++;
registration_id = g_dbus_connection_register_object (c,
"/foo/boss/executives/non_subtree_object",
(GDBusInterfaceInfo *) &foo_interface_info,
NULL,
&data,
on_object_unregistered,
&error);
g_assert_no_error (error);
g_assert (registration_id > 0);
non_subtree_object_path_foo_reg_id = registration_id;
num_successful_registrations++;
/* now register a dynamic subtree, spawning objects as they are called */
dyna_data = g_ptr_array_new_with_free_func (g_free);
dyna_subtree_registration_id = g_dbus_connection_register_subtree (c,
"/foo/dyna",
&dynamic_subtree_vtable,
G_DBUS_SUBTREE_FLAGS_DISPATCH_TO_UNENUMERATED_NODES,
dyna_data,
(GDestroyNotify)g_ptr_array_unref,
&error);
g_assert_no_error (error);
g_assert (dyna_subtree_registration_id > 0);
/* First assert that we have no nodes in the dynamic subtree */
nodes = get_nodes_at (c, "/foo/dyna");
g_assert (nodes != NULL);
g_assert_cmpint (g_strv_length (nodes), ==, 0);
g_strfreev (nodes);
g_assert_cmpint (count_interfaces (c, "/foo/dyna"), ==, 4);
/* Install three nodes in the dynamic subtree via the dyna_data backdoor and
* assert that they show up correctly in the introspection data */
g_ptr_array_add (dyna_data, g_strdup ("lol"));
g_ptr_array_add (dyna_data, g_strdup ("cat"));
g_ptr_array_add (dyna_data, g_strdup ("cheezburger"));
nodes = get_nodes_at (c, "/foo/dyna");
g_assert (nodes != NULL);
g_assert_cmpint (g_strv_length (nodes), ==, 3);
g_assert_cmpstr (nodes[0], ==, "lol");
g_assert_cmpstr (nodes[1], ==, "cat");
g_assert_cmpstr (nodes[2], ==, "cheezburger");
g_strfreev (nodes);
g_assert_cmpint (count_interfaces (c, "/foo/dyna/lol"), ==, 4);
g_assert_cmpint (count_interfaces (c, "/foo/dyna/cat"), ==, 4);
g_assert_cmpint (count_interfaces (c, "/foo/dyna/cheezburger"), ==, 4);
/* Call a non-existing object path and assert that it has been created */
dyna_create (c, "dynamicallycreated");
nodes = get_nodes_at (c, "/foo/dyna");
g_assert (nodes != NULL);
g_assert_cmpint (g_strv_length (nodes), ==, 4);
g_assert_cmpstr (nodes[0], ==, "lol");
g_assert_cmpstr (nodes[1], ==, "cat");
g_assert_cmpstr (nodes[2], ==, "cheezburger");
g_assert_cmpstr (nodes[3], ==, "dynamicallycreated");
g_strfreev (nodes);
g_assert_cmpint (count_interfaces (c, "/foo/dyna/dynamicallycreated"), ==, 4);
/* now check that the object hierarachy is properly generated... yes, it's a bit
* perverse that we round-trip to the bus to introspect ourselves ;-)
*/
nodes = get_nodes_at (c, "/");
g_assert (nodes != NULL);
g_assert_cmpint (g_strv_length (nodes), ==, 1);
g_assert_cmpstr (nodes[0], ==, "foo");
g_strfreev (nodes);
g_assert_cmpint (count_interfaces (c, "/"), ==, 0);
nodes = get_nodes_at (c, "/foo");
g_assert (nodes != NULL);
g_assert_cmpint (g_strv_length (nodes), ==, 2);
g_assert_cmpstr (nodes[0], ==, "boss");
g_assert_cmpstr (nodes[1], ==, "dyna");
g_strfreev (nodes);
g_assert_cmpint (count_interfaces (c, "/foo"), ==, 0);
nodes = get_nodes_at (c, "/foo/boss");
g_assert (nodes != NULL);
g_assert_cmpint (g_strv_length (nodes), ==, 5);
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "worker1"));
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "worker1p1"));
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "worker2"));
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "interns"));
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "executives"));
g_strfreev (nodes);
/* any registered object always implement org.freedesktop.DBus.[Peer,Introspectable,Properties] */
g_assert_cmpint (count_interfaces (c, "/foo/boss"), ==, 5);
g_assert (has_interface (c, "/foo/boss", foo_interface_info.name));
g_assert (has_interface (c, "/foo/boss", bar_interface_info.name));
/* check subtree nodes - we should have only non_subtree_object in /foo/boss/executives
* because data.num_subtree_nodes is 0
*/
nodes = get_nodes_at (c, "/foo/boss/executives");
g_assert (nodes != NULL);
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "non_subtree_object"));
g_assert_cmpint (g_strv_length (nodes), ==, 1);
g_strfreev (nodes);
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives"), ==, 0);
/* now change data.num_subtree_nodes and check */
data.num_subtree_nodes = 2;
nodes = get_nodes_at (c, "/foo/boss/executives");
g_assert (nodes != NULL);
g_assert_cmpint (g_strv_length (nodes), ==, 5);
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "non_subtree_object"));
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "vp0"));
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "vp1"));
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "evp0"));
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "evp1"));
/* check that /foo/boss/executives/non_subtree_object is not handled by the
* subtree handlers - we can do this because objects from subtree handlers
* has exactly one interface and non_subtree_object has two
*/
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/non_subtree_object"), ==, 5);
g_assert (has_interface (c, "/foo/boss/executives/non_subtree_object", foo_interface_info.name));
g_assert (has_interface (c, "/foo/boss/executives/non_subtree_object", bar_interface_info.name));
/* check that the vp and evp objects are handled by the subtree handlers */
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/vp0"), ==, 4);
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/vp1"), ==, 4);
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/evp0"), ==, 4);
g_assert_cmpint (count_interfaces (c, "/foo/boss/executives/evp1"), ==, 4);
g_assert (has_interface (c, "/foo/boss/executives/vp0", foo_interface_info.name));
g_assert (has_interface (c, "/foo/boss/executives/vp1", foo_interface_info.name));
g_assert (has_interface (c, "/foo/boss/executives/evp0", bar_interface_info.name));
g_assert (has_interface (c, "/foo/boss/executives/evp1", bar_interface_info.name));
g_strfreev (nodes);
data.num_subtree_nodes = 3;
nodes = get_nodes_at (c, "/foo/boss/executives");
g_assert (nodes != NULL);
g_assert_cmpint (g_strv_length (nodes), ==, 7);
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "non_subtree_object"));
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "vp0"));
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "vp1"));
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "vp2"));
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "evp0"));
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "evp1"));
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "evp2"));
g_strfreev (nodes);
/* This is to check that a bug (rather, class of bugs) in gdbusconnection.c's
*
* g_dbus_connection_list_registered_unlocked()
*
* where /foo/boss/worker1 reported a child '1', is now fixed.
*/
nodes = get_nodes_at (c, "/foo/boss/worker1");
g_assert (nodes != NULL);
g_assert_cmpint (g_strv_length (nodes), ==, 0);
g_strfreev (nodes);
/* check that calls are properly dispatched to the functions in foo_vtable for objects
* implementing the org.example.Foo interface
*
* We do this for both a regular registered object (/foo/boss) and also for an object
* registered through the subtree mechanism.
*/
test_dispatch ("/foo/boss", TRUE);
test_dispatch ("/foo/boss/executives/vp0", TRUE);
/* To prevent from exiting and attaching a D-Bus tool like D-Feet; uncomment: */
#if 0
g_debug ("Point D-feet or other tool at: %s", g_test_dbus_get_temporary_address());
g_main_loop_run (loop);
#endif
/* check that unregistering the subtree handler works */
g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 1);
g_assert (g_dbus_connection_unregister_subtree (c, subtree_registration_id));
g_main_context_iteration (NULL, FALSE);
g_assert_cmpint (data.num_unregistered_subtree_calls, ==, 2);
nodes = get_nodes_at (c, "/foo/boss/executives");
g_assert (nodes != NULL);
g_assert_cmpint (g_strv_length (nodes), ==, 1);
g_assert (_g_strv_has_string ((const gchar* const *) nodes, "non_subtree_object"));
g_strfreev (nodes);
g_assert (g_dbus_connection_unregister_object (c, boss_foo_reg_id));
g_assert (g_dbus_connection_unregister_object (c, boss_bar_reg_id));
g_assert (g_dbus_connection_unregister_object (c, worker1_foo_reg_id));
g_assert (g_dbus_connection_unregister_object (c, worker1p1_foo_reg_id));
g_assert (g_dbus_connection_unregister_object (c, worker2_bar_reg_id));
g_assert (g_dbus_connection_unregister_object (c, intern1_foo_reg_id));
g_assert (g_dbus_connection_unregister_object (c, intern2_bar_reg_id));
g_assert (g_dbus_connection_unregister_object (c, intern2_foo_reg_id));
g_assert (g_dbus_connection_unregister_object (c, intern3_bar_reg_id));
g_assert (g_dbus_connection_unregister_object (c, non_subtree_object_path_bar_reg_id));
g_assert (g_dbus_connection_unregister_object (c, non_subtree_object_path_foo_reg_id));
g_main_context_iteration (NULL, FALSE);
g_assert_cmpint (data.num_unregistered_calls, ==, num_successful_registrations);
/* check that we no longer export any objects - TODO: it looks like there's a bug in
* libdbus-1 here: libdbus still reports the '/foo' object; so disable the test for now
*/
#if 0
nodes = get_nodes_at (c, "/");
g_assert (nodes != NULL);
g_assert_cmpint (g_strv_length (nodes), ==, 0);
g_strfreev (nodes);
#endif
g_object_unref (c);
}
static void
test_object_registration_with_closures (void)
{
GError *error;
guint registration_id;
error = NULL;
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error (error);
g_assert (c != NULL);
registration_id = g_dbus_connection_register_object_with_closures (c,
"/foo/boss",
(GDBusInterfaceInfo *) &foo_interface_info,
g_cclosure_new (G_CALLBACK (foo_method_call), NULL, NULL),
g_cclosure_new (G_CALLBACK (foo_get_property), NULL, NULL),
g_cclosure_new (G_CALLBACK (foo_set_property), NULL, NULL),
&error);
g_assert_no_error (error);
g_assert (registration_id > 0);
test_dispatch ("/foo/boss", FALSE);
g_assert (g_dbus_connection_unregister_object (c, registration_id));
g_object_unref (c);
}
static const GDBusInterfaceInfo test_interface_info1 =
{
-1,
"org.example.Foo",
(GDBusMethodInfo **) NULL,
(GDBusSignalInfo **) NULL,
(GDBusPropertyInfo **) NULL,
NULL,
};
static const GDBusInterfaceInfo test_interface_info2 =
{
-1,
"org.freedesktop.DBus.Properties",
(GDBusMethodInfo **) NULL,
(GDBusSignalInfo **) NULL,
(GDBusPropertyInfo **) NULL,
NULL,
};
static void
check_interfaces (GDBusConnection *c,
const gchar *object_path,
const gchar **interfaces)
{
GError *error;
GDBusProxy *proxy;
gchar *xml_data;
GDBusNodeInfo *node_info;
gint i, j;
error = NULL;
proxy = g_dbus_proxy_new_sync (c,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
NULL,
g_dbus_connection_get_unique_name (c),
object_path,
"org.freedesktop.DBus.Introspectable",
NULL,
&error);
g_assert_no_error (error);
g_assert (proxy != NULL);
/* do this async to avoid libdbus-1 deadlocks */
xml_data = NULL;
g_dbus_proxy_call (proxy,
"Introspect",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
(GAsyncReadyCallback) introspect_callback,
&xml_data);
g_main_loop_run (loop);
g_assert (xml_data != NULL);
node_info = g_dbus_node_info_new_for_xml (xml_data, &error);
g_assert_no_error (error);
g_assert (node_info != NULL);
g_assert (node_info->interfaces != NULL);
for (i = 0; node_info->interfaces[i]; i++) ;
#if 0
if (g_strv_length ((gchar**)interfaces) != i - 1)
{
g_printerr ("expected ");
for (i = 0; interfaces[i]; i++)
g_printerr ("%s ", interfaces[i]);
g_printerr ("\ngot ");
for (i = 0; node_info->interfaces[i]; i++)
g_printerr ("%s ", node_info->interfaces[i]->name);
g_printerr ("\n");
}
#endif
g_assert_cmpint (g_strv_length ((gchar**)interfaces), ==, i - 1);
for (i = 0; interfaces[i]; i++)
{
for (j = 0; node_info->interfaces[j]; j++)
{
if (strcmp (interfaces[i], node_info->interfaces[j]->name) == 0)
goto found;
}
g_assert_not_reached ();
found: ;
}
g_object_unref (proxy);
g_free (xml_data);
g_dbus_node_info_unref (node_info);
}
static void
test_registered_interfaces (void)
{
GError *error;
guint id1, id2;
const gchar *interfaces[] = {
"org.example.Foo",
"org.freedesktop.DBus.Properties",
"org.freedesktop.DBus.Introspectable",
NULL,
};
error = NULL;
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error (error);
g_assert (c != NULL);
id1 = g_dbus_connection_register_object (c,
"/test",
(GDBusInterfaceInfo *) &test_interface_info1,
NULL,
NULL,
NULL,
&error);
g_assert_no_error (error);
g_assert (id1 > 0);
id2 = g_dbus_connection_register_object (c,
"/test",
(GDBusInterfaceInfo *) &test_interface_info2,
NULL,
NULL,
NULL,
&error);
g_assert_no_error (error);
g_assert (id2 > 0);
check_interfaces (c, "/test", interfaces);
g_assert (g_dbus_connection_unregister_object (c, id1));
g_assert (g_dbus_connection_unregister_object (c, id2));
g_object_unref (c);
}
/* ---------------------------------------------------------------------------------------------------- */
static void
test_async_method_call (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *method_name,
GVariant *parameters,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
const GDBusPropertyInfo *property;
/* Strictly speaking, this function should also expect to receive
* method calls not on the org.freedesktop.DBus.Properties interface,
* but we don't do any during this testcase, so assert that.
*/
g_assert_cmpstr (interface_name, ==, "org.freedesktop.DBus.Properties");
g_assert (g_dbus_method_invocation_get_method_info (invocation) == NULL);
property = g_dbus_method_invocation_get_property_info (invocation);
/* We should never be seeing any property calls on the com.example.Bar
* interface because it doesn't export any properties.
*
* In each case below make sure the interface is org.example.Foo.
*/
/* Do a whole lot of asserts to make sure that invalid calls are still
* getting properly rejected by GDBusConnection and that our
* environment is as we expect it to be.
*/
if (g_str_equal (method_name, "Get"))
{
const gchar *iface_name, *prop_name;
g_variant_get (parameters, "(&s&s)", &iface_name, &prop_name);
g_assert_cmpstr (iface_name, ==, "org.example.Foo");
g_assert (property != NULL);
g_assert_cmpstr (prop_name, ==, property->name);
g_assert (property->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE);
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(v)", g_variant_new_string (prop_name)));
}
else if (g_str_equal (method_name, "Set"))
{
const gchar *iface_name, *prop_name;
GVariant *value;
g_variant_get (parameters, "(&s&sv)", &iface_name, &prop_name, &value);
g_assert_cmpstr (iface_name, ==, "org.example.Foo");
g_assert (property != NULL);
g_assert_cmpstr (prop_name, ==, property->name);
g_assert (property->flags & G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE);
g_assert (g_variant_is_of_type (value, G_VARIANT_TYPE (property->signature)));
g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
g_variant_unref (value);
}
else if (g_str_equal (method_name, "GetAll"))
{
const gchar *iface_name;
g_variant_get (parameters, "(&s)", &iface_name);
g_assert_cmpstr (iface_name, ==, "org.example.Foo");
g_assert (property == NULL);
g_dbus_method_invocation_return_value (invocation,
g_variant_new_parsed ("({ 'PropertyUno': < 'uno' >,"
" 'NotWritable': < 'notwrite' > },)"));
}
else
g_assert_not_reached ();
}
static gint outstanding_cases;
static void
ensure_result_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
GDBusConnection *connection = G_DBUS_CONNECTION (source);
GVariant *reply;
reply = g_dbus_connection_call_finish (connection, result, NULL);
if (user_data == NULL)
{
/* Expected an error */
g_assert (reply == NULL);
}
else
{
/* Expected a reply of a particular format. */
gchar *str;
g_assert (reply != NULL);
str = g_variant_print (reply, TRUE);
g_assert_cmpstr (str, ==, (const gchar *) user_data);
g_free (str);
g_variant_unref (reply);
}
g_assert_cmpint (outstanding_cases, >, 0);
outstanding_cases--;
}
static void
test_async_case (GDBusConnection *connection,
const gchar *expected_reply,
const gchar *method,
const gchar *format_string,
...)
{
va_list ap;
va_start (ap, format_string);
g_dbus_connection_call (connection, g_dbus_connection_get_unique_name (connection), "/foo",
"org.freedesktop.DBus.Properties", method, g_variant_new_va (format_string, NULL, &ap),
NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, ensure_result_cb, (gpointer) expected_reply);
va_end (ap);
outstanding_cases++;
}
static void
test_async_properties (void)
{
GError *error = NULL;
guint registration_id, registration_id2;
static const GDBusInterfaceVTable vtable = {
test_async_method_call, NULL, NULL
};
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error (error);
g_assert (c != NULL);
registration_id = g_dbus_connection_register_object (c,
"/foo",
(GDBusInterfaceInfo *) &foo_interface_info,
&vtable, NULL, NULL, &error);
g_assert_no_error (error);
g_assert (registration_id);
registration_id2 = g_dbus_connection_register_object (c,
"/foo",
(GDBusInterfaceInfo *) &foo2_interface_info,
&vtable, NULL, NULL, &error);
g_assert_no_error (error);
g_assert (registration_id);
test_async_case (c, NULL, "random", "()");
/* Test a variety of error cases */
test_async_case (c, NULL, "Get", "(si)", "wrong signature", 5);
test_async_case (c, NULL, "Get", "(ss)", "org.example.WrongInterface", "zzz");
test_async_case (c, NULL, "Get", "(ss)", "org.example.Foo", "NoSuchProperty");
test_async_case (c, NULL, "Get", "(ss)", "org.example.Foo", "NotReadable");
test_async_case (c, NULL, "Set", "(si)", "wrong signature", 5);
test_async_case (c, NULL, "Set", "(ssv)", "org.example.WrongInterface", "zzz", g_variant_new_string (""));
test_async_case (c, NULL, "Set", "(ssv)", "org.example.Foo", "NoSuchProperty", g_variant_new_string (""));
test_async_case (c, NULL, "Set", "(ssv)", "org.example.Foo", "NotWritable", g_variant_new_string (""));
test_async_case (c, NULL, "Set", "(ssv)", "org.example.Foo", "PropertyUno", g_variant_new_object_path ("/wrong"));
test_async_case (c, NULL, "GetAll", "(si)", "wrong signature", 5);
test_async_case (c, NULL, "GetAll", "(s)", "org.example.WrongInterface");
/* Make sure that we get no unexpected async property calls for com.example.Foo2 */
test_async_case (c, NULL, "Get", "(ss)", "org.example.Foo2", "zzz");
test_async_case (c, NULL, "Set", "(ssv)", "org.example.Foo2", "zzz", g_variant_new_string (""));
test_async_case (c, "(@a{sv} {},)", "GetAll", "(s)", "org.example.Foo2");
/* Now do the proper things */
test_async_case (c, "(<'PropertyUno'>,)", "Get", "(ss)", "org.example.Foo", "PropertyUno");
test_async_case (c, "(<'NotWritable'>,)", "Get", "(ss)", "org.example.Foo", "NotWritable");
test_async_case (c, "()", "Set", "(ssv)", "org.example.Foo", "PropertyUno", g_variant_new_string (""));
test_async_case (c, "()", "Set", "(ssv)", "org.example.Foo", "NotReadable", g_variant_new_string (""));
test_async_case (c, "({'PropertyUno': <'uno'>, 'NotWritable': <'notwrite'>},)", "GetAll", "(s)", "org.example.Foo");
while (outstanding_cases)
g_main_context_iteration (NULL, TRUE);
g_dbus_connection_unregister_object (c, registration_id);
g_dbus_connection_unregister_object (c, registration_id2);
g_object_unref (c);
}
/* ---------------------------------------------------------------------------------------------------- */
int
main (int argc,
char *argv[])
{
gint ret;
g_test_init (&argc, &argv, NULL);
/* all the tests rely on a shared main loop */
loop = g_main_loop_new (NULL, FALSE);
g_test_add_func ("/gdbus/object-registration", test_object_registration);
g_test_add_func ("/gdbus/object-registration-with-closures", test_object_registration_with_closures);
g_test_add_func ("/gdbus/registered-interfaces", test_registered_interfaces);
g_test_add_func ("/gdbus/async-properties", test_async_properties);
/* TODO: check that we spit out correct introspection data */
/* TODO: check that registering a whole subtree works */
ret = session_bus_run ();
g_main_loop_unref (loop);
return ret;
}