summaryrefslogtreecommitdiff
path: root/tests/lib/simple-account-manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/simple-account-manager.c')
-rw-r--r--tests/lib/simple-account-manager.c143
1 files changed, 103 insertions, 40 deletions
diff --git a/tests/lib/simple-account-manager.c b/tests/lib/simple-account-manager.c
index a56c96e..e5bddbc 100644
--- a/tests/lib/simple-account-manager.c
+++ b/tests/lib/simple-account-manager.c
@@ -1,7 +1,7 @@
/*
* simple-account-manager.c - a simple account manager service.
*
- * Copyright (C) 2007-2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2007-2012 Collabora Ltd. <http://www.collabora.co.uk/>
* Copyright (C) 2007-2008 Nokia Corporation
*
* Copying and distribution of this file, with or without modification,
@@ -9,6 +9,8 @@
* notice and this notice are preserved.
*/
+#include "config.h"
+
#include "simple-account-manager.h"
#include <telepathy-glib/telepathy-glib.h>
@@ -29,29 +31,22 @@ G_DEFINE_TYPE_WITH_CODE (TpTestsSimpleAccountManager,
/* TP_IFACE_ACCOUNT_MANAGER is implied */
static const char *ACCOUNT_MANAGER_INTERFACES[] = { NULL };
-static gchar *VALID_ACCOUNTS[] = {
- "/org/freedesktop/Telepathy/Account/fakecm/fakeproto/validaccount",
- NULL };
-
-static gchar *INVALID_ACCOUNTS[] = {
- "/org/freedesktop/Telepathy/Account/fakecm/fakeproto/invalidaccount",
- NULL };
-
enum
{
PROP_0,
PROP_INTERFACES,
- PROP_VALID_ACCOUNTS,
- PROP_INVALID_ACCOUNTS,
+ PROP_USABLE_ACCOUNTS,
+ PROP_UNUSABLE_ACCOUNTS,
};
struct _TpTestsSimpleAccountManagerPrivate
{
- int dummy;
+ GPtrArray *usable_accounts;
+ GPtrArray *unusable_accounts;
};
static void
-tp_tests_simple_account_manager_create_account (TpSvcAccountManager *self,
+tp_tests_simple_account_manager_create_account (TpSvcAccountManager *svc,
const gchar *in_Connection_Manager,
const gchar *in_Protocol,
const gchar *in_Display_Name,
@@ -59,9 +54,24 @@ tp_tests_simple_account_manager_create_account (TpSvcAccountManager *self,
GHashTable *in_Properties,
DBusGMethodInvocation *context)
{
- const gchar *out_Account = "/some/fake/account/i/think";
-
- tp_svc_account_manager_return_from_create_account (context, out_Account);
+ TpTestsSimpleAccountManager *self = (TpTestsSimpleAccountManager *) svc;
+ const gchar *out = TP_ACCOUNT_OBJECT_PATH_BASE "gabble/jabber/lospolloshermanos";
+
+ /* if we have fail=yes as a parameter, make the call fail */
+ if (!tp_strdiff (tp_asv_get_string (in_Parameters, "fail"), "yes"))
+ {
+ GError e = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT, "loldongs" };
+ dbus_g_method_return_error (context, &e);
+ return;
+ }
+
+ self->create_cm = g_strdup (in_Connection_Manager);
+ self->create_protocol = g_strdup (in_Protocol);
+ self->create_display_name = g_strdup (in_Display_Name);
+ self->create_parameters = g_hash_table_ref (in_Parameters);
+ self->create_properties = g_hash_table_ref (in_Properties);
+
+ tp_svc_account_manager_return_from_create_account (context, out);
}
static void
@@ -80,6 +90,9 @@ tp_tests_simple_account_manager_init (TpTestsSimpleAccountManager *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
TP_TESTS_TYPE_SIMPLE_ACCOUNT_MANAGER, TpTestsSimpleAccountManagerPrivate);
+
+ self->priv->usable_accounts = g_ptr_array_new_with_free_func (g_free);
+ self->priv->unusable_accounts = g_ptr_array_new_with_free_func (g_free);
}
static void
@@ -88,30 +101,19 @@ tp_tests_simple_account_manager_get_property (GObject *object,
GValue *value,
GParamSpec *spec)
{
- GPtrArray *accounts;
- guint i = 0;
+ TpTestsSimpleAccountManager *self = SIMPLE_ACCOUNT_MANAGER (object);
switch (property_id) {
case PROP_INTERFACES:
g_value_set_boxed (value, ACCOUNT_MANAGER_INTERFACES);
break;
- case PROP_VALID_ACCOUNTS:
- accounts = g_ptr_array_new ();
-
- for (i=0; VALID_ACCOUNTS[i] != NULL; i++)
- g_ptr_array_add (accounts, g_strdup (VALID_ACCOUNTS[i]));
-
- g_value_take_boxed (value, accounts);
+ case PROP_USABLE_ACCOUNTS:
+ g_value_set_boxed (value, self->priv->usable_accounts);
break;
- case PROP_INVALID_ACCOUNTS:
- accounts = g_ptr_array_new ();
-
- for (i=0; INVALID_ACCOUNTS[i] != NULL; i++)
- g_ptr_array_add (accounts, g_strdup (VALID_ACCOUNTS[i]));
-
- g_value_take_boxed (value, accounts);
+ case PROP_UNUSABLE_ACCOUNTS:
+ g_value_set_boxed (value, self->priv->unusable_accounts);
break;
default:
@@ -120,6 +122,24 @@ tp_tests_simple_account_manager_get_property (GObject *object,
}
}
+static void
+tp_tests_simple_account_manager_finalize (GObject *object)
+{
+ TpTestsSimpleAccountManager *self = SIMPLE_ACCOUNT_MANAGER (object);
+
+ g_ptr_array_unref (self->priv->usable_accounts);
+ g_ptr_array_unref (self->priv->unusable_accounts);
+
+ tp_clear_pointer (&self->create_cm, g_free);
+ tp_clear_pointer (&self->create_protocol, g_free);
+ tp_clear_pointer (&self->create_display_name, g_free);
+ tp_clear_pointer (&self->create_parameters, g_hash_table_unref);
+ tp_clear_pointer (&self->create_properties, g_hash_table_unref);
+
+ G_OBJECT_CLASS (tp_tests_simple_account_manager_parent_class)->finalize (
+ object);
+}
+
/**
* This class currently only provides the minimum for
* tp_account_manager_prepare to succeed. This turns out to be only a working
@@ -136,8 +156,8 @@ tp_tests_simple_account_manager_class_init (
static TpDBusPropertiesMixinPropImpl am_props[] = {
{ "Interfaces", "interfaces", NULL },
- { "ValidAccounts", "valid-accounts", NULL },
- { "InvalidAccounts", "invalid-accounts", NULL },
+ { "UsableAccounts", "usable-accounts", NULL },
+ { "UnusableAccounts", "unusable-accounts", NULL },
/*
{ "SupportedAccountProperties", "supported-account-properties", NULL },
*/
@@ -154,6 +174,7 @@ tp_tests_simple_account_manager_class_init (
};
g_type_class_add_private (klass, sizeof (TpTestsSimpleAccountManagerPrivate));
+ object_class->finalize = tp_tests_simple_account_manager_finalize;
object_class->get_property = tp_tests_simple_account_manager_get_property;
param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces",
@@ -161,18 +182,60 @@ tp_tests_simple_account_manager_class_init (
G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_INTERFACES, param_spec);
- param_spec = g_param_spec_boxed ("valid-accounts", "Valid accounts",
- "The accounts which are valid on this account. This may be a lie.",
+ param_spec = g_param_spec_boxed ("usable-accounts", "Usable accounts",
+ "The accounts which are usable on this account manager. This may be a lie.",
TP_ARRAY_TYPE_OBJECT_PATH_LIST,
G_PARAM_READABLE);
- g_object_class_install_property (object_class, PROP_VALID_ACCOUNTS, param_spec);
- param_spec = g_param_spec_boxed ("invalid-accounts", "Invalid accounts",
- "The accounts which are invalid on this account. This may be a lie.",
+ g_object_class_install_property (object_class, PROP_USABLE_ACCOUNTS, param_spec);
+ param_spec = g_param_spec_boxed ("unusable-accounts", "Unusable accounts",
+ "The accounts which are unusable on this account manager. This may be a lie.",
TP_ARRAY_TYPE_OBJECT_PATH_LIST,
G_PARAM_READABLE);
- g_object_class_install_property (object_class, PROP_INVALID_ACCOUNTS, param_spec);
+ g_object_class_install_property (object_class, PROP_UNUSABLE_ACCOUNTS, param_spec);
klass->dbus_props_class.interfaces = prop_interfaces;
tp_dbus_properties_mixin_class_init (object_class,
G_STRUCT_OFFSET (TpTestsSimpleAccountManagerClass, dbus_props_class));
}
+
+static void
+remove_from_array (GPtrArray *array, const gchar *str)
+{
+ guint i;
+
+ for (i = 0; i < array->len; i++)
+ if (!tp_strdiff (str, g_ptr_array_index (array, i)))
+ {
+ g_ptr_array_remove_index_fast (array, i);
+ return;
+ }
+}
+
+void
+tp_tests_simple_account_manager_add_account (
+ TpTestsSimpleAccountManager *self,
+ const gchar *object_path,
+ gboolean usable)
+{
+ remove_from_array (self->priv->usable_accounts, object_path);
+ remove_from_array (self->priv->unusable_accounts, object_path);
+
+ if (usable)
+ g_ptr_array_add (self->priv->usable_accounts, g_strdup (object_path));
+ else
+ g_ptr_array_add (self->priv->unusable_accounts, g_strdup (object_path));
+
+ tp_svc_account_manager_emit_account_usability_changed (self, object_path,
+ usable);
+}
+
+void
+tp_tests_simple_account_manager_remove_account (
+ TpTestsSimpleAccountManager *self,
+ const gchar *object_path)
+{
+ remove_from_array (self->priv->usable_accounts, object_path);
+ remove_from_array (self->priv->unusable_accounts, object_path);
+
+ tp_svc_account_manager_emit_account_removed (self, object_path);
+}