[telepathy-glib/master] Simple account manager service for use in tests.
David Laban
david.laban at collabora.co.uk
Wed Nov 4 10:33:32 PST 2009
This service does only the bare minimum. Current limitations are:
* Only provides a single property: just enough to get prepare to succeed.
* Tests are responsible for acquiring the well-known name, and registering the object
* Calling prepare on the result of ensure_account will fail, as accounts are not implemented.
---
tests/lib/Makefile.am | 2 +
tests/lib/simple-account-manager.c | 109 ++++++++++++++++++++++++++++++++++++
tests/lib/simple-account-manager.h | 58 +++++++++++++++++++
3 files changed, 169 insertions(+), 0 deletions(-)
create mode 100644 tests/lib/simple-account-manager.c
create mode 100644 tests/lib/simple-account-manager.h
diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am
index 064dcfc..6d7f03e 100644
--- a/tests/lib/Makefile.am
+++ b/tests/lib/Makefile.am
@@ -11,6 +11,8 @@ libtp_glib_tests_la_SOURCES = \
myassert.h \
params-cm.h \
params-cm.c \
+ simple-account-manager.c\
+ simple-account-manager.h\
simple-conn.c \
simple-conn.h \
simple-manager.c \
diff --git a/tests/lib/simple-account-manager.c b/tests/lib/simple-account-manager.c
new file mode 100644
index 0000000..a888f5a
--- /dev/null
+++ b/tests/lib/simple-account-manager.c
@@ -0,0 +1,109 @@
+/*
+ * simple-account-manager.c - a simple account manager service.
+ *
+ * Copyright (C) 2007-2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2007-2008 Nokia Corporation
+ *
+ * Copying and distribution of this file, with or without modification,
+ * are permitted in any medium without royalty provided the copyright
+ * notice and this notice are preserved.
+ */
+
+#include "simple-account-manager.h"
+
+#include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/svc-generic.h>
+
+G_DEFINE_TYPE_WITH_CODE (SimpleAccountManager,
+ simple_account_manager,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
+ tp_dbus_properties_mixin_iface_init)
+ )
+
+/* type definition stuff */
+
+/* TP_IFACE_ACCOUNT_MANAGER is implied */
+static const char *ACCOUNT_MANAGER_INTERFACES[] = { NULL };
+
+enum
+{
+ PROP_0,
+ PROP_INTERFACES,
+};
+
+struct _SimpleAccountManagerPrivate
+{
+ int dummy;
+};
+
+static void
+simple_account_manager_init (SimpleAccountManager *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, SIMPLE_TYPE_ACCOUNT_MANAGER,
+ SimpleAccountManagerPrivate);
+}
+
+static void
+simple_account_manager_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *spec)
+{
+ switch (property_id) {
+ case PROP_INTERFACES:
+ g_value_set_boxed (value, ACCOUNT_MANAGER_INTERFACES);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec);
+ break;
+ }
+}
+
+/**
+ * This class currently only provides the minimum for
+ * tp_account_manager_prepare to succeed. This turns out to be only a working
+ * Properties.GetAll(). If we wanted later to check the case where
+ * tp_account_prepare succeeds, we would need to implement an account object
+ * too. In that case, it might be worth using TpSvcAccountManager
+ * as well as/instead of TpDBusPropertiesMixinPropImpl.
+ */
+static void
+simple_account_manager_class_init (SimpleAccountManagerClass *klass)
+{
+ GObjectClass *object_class = (GObjectClass *) klass;
+ GParamSpec *param_spec;
+
+ static TpDBusPropertiesMixinPropImpl am_props[] = {
+ { "Interfaces", "interfaces", NULL },
+ /*
+ { "ValidAccounts", "interfaces", NULL },
+ { "InvalidAccounts", "invalid-accounts", NULL },
+ { "SupportedAccountProperties", "supported-account-properties", NULL },
+ */
+ { NULL }
+ };
+
+ static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
+ { NULL },
+ { TP_IFACE_ACCOUNT_MANAGER,
+ tp_dbus_properties_mixin_getter_gobject_properties,
+ NULL,
+ am_props
+ },
+ { NULL },
+ };
+
+ g_type_class_add_private (klass, sizeof (SimpleAccountManagerPrivate));
+ object_class->get_property = simple_account_manager_get_property;
+
+ param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces",
+ "In this case we only implement AccountManager, so none.",
+ G_TYPE_STRV,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_INTERFACES, param_spec);
+ klass->dbus_props_class.interfaces = prop_interfaces;
+ tp_dbus_properties_mixin_class_init (object_class,
+ G_STRUCT_OFFSET (SimpleAccountManagerClass, dbus_props_class));
+}
diff --git a/tests/lib/simple-account-manager.h b/tests/lib/simple-account-manager.h
new file mode 100644
index 0000000..8e15c20
--- /dev/null
+++ b/tests/lib/simple-account-manager.h
@@ -0,0 +1,58 @@
+/*
+ * simple-account-manager.h - header for a simple account manager service.
+ *
+ * Copyright (C) 2007-2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2007-2008 Nokia Corporation
+ *
+ * Copying and distribution of this file, with or without modification,
+ * are permitted in any medium without royalty provided the copyright
+ * notice and this notice are preserved.
+ */
+
+#ifndef __SIMPLE_ACCOUNT_MANAGER_H__
+#define __SIMPLE_ACCOUNT_MANAGER_H__
+
+#include <glib-object.h>
+#include <telepathy-glib/dbus-properties-mixin.h>
+
+
+G_BEGIN_DECLS
+
+typedef struct _SimpleAccountManager SimpleAccountManager;
+typedef struct _SimpleAccountManagerClass SimpleAccountManagerClass;
+typedef struct _SimpleAccountManagerPrivate SimpleAccountManagerPrivate;
+
+struct _SimpleAccountManagerClass {
+ GObjectClass parent_class;
+ TpDBusPropertiesMixinClass dbus_props_class;
+};
+
+struct _SimpleAccountManager {
+ GObject parent;
+
+ SimpleAccountManagerPrivate *priv;
+};
+
+GType simple_account_manager_get_type (void);
+
+/* TYPE MACROS */
+#define SIMPLE_TYPE_ACCOUNT_MANAGER \
+ (simple_account_manager_get_type ())
+#define SIMPLE_ACCOUNT_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), SIMPLE_TYPE_ACCOUNT_MANAGER, \
+ SimpleAccountManager))
+#define SIMPLE_ACCOUNT_MANAGER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), SIMPLE_TYPE_ACCOUNT_MANAGER, \
+ SimpleAccountManagerClass))
+#define SIMPLE_IS_ACCOUNT_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), SIMPLE_TYPE_ACCOUNT_MANAGER))
+#define SIMPLE_IS_ACCOUNT_MANAGER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), SIMPLE_TYPE_ACCOUNT_MANAGER))
+#define SIMPLE_ACCOUNT_MANAGER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), SIMPLE_TYPE_ACCOUNT_MANAGER, \
+ SimpleAccountManagerClass))
+
+
+G_END_DECLS
+
+#endif /* #ifndef __SIMPLE_ACCOUNT_MANAGER_H__ */
--
1.5.6.5
More information about the telepathy-commits
mailing list