summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2013-11-15 13:40:52 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2014-01-29 19:28:31 +0000
commiteb7dc4a25c602de15f87fc63f56610ba5a7a05f8 (patch)
tree9a0ec02ba728cd56562cf6e9add828c99ae5a7f8
parent1bdae99f8cd780caa7fdf3aa7f72ac7c853ef2a6 (diff)
dbus-account-plugin: fail tests on various invalid method calls
Methods that act on a single account should always be called on an account that exists (if it doesn't, where did you get its name from?), so treat it as an error if they are called with a nonexistent account. commit() has a dual role here: the method that takes a non-NULL account (which acts on a single account, as described), and the method that takes a NULL account name (which is OK to call at any time, to commit all of our 0-or-more accounts). While we are not active, we don't claim to have any accounts at all, so treat it as an error if any method is called with a non-NULL account name while inactive. I've temporarily made an exception for delete_async(), although that exception is removed in a later patch on this branch. It's less bad if delete_async() is called on an account that doesn't exist, because if you do, the desired state ("account X doesn't exist") has already been reached. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=27727
-rw-r--r--tests/twisted/dbus-account-plugin.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/tests/twisted/dbus-account-plugin.c b/tests/twisted/dbus-account-plugin.c
index 493df5aa..455095fa 100644
--- a/tests/twisted/dbus-account-plugin.c
+++ b/tests/twisted/dbus-account-plugin.c
@@ -972,8 +972,8 @@ test_dbus_account_plugin_get_attribute (McpAccountStorage *storage,
if (flags != NULL)
*flags = 0;
- if (!self->active || account == NULL)
- return NULL;
+ g_return_val_if_fail (self->active, NULL);
+ g_return_val_if_fail (account != NULL, NULL);
v = g_hash_table_lookup (account->attributes, attribute);
@@ -1008,8 +1008,8 @@ test_dbus_account_plugin_get_parameter (McpAccountStorage *storage,
if (flags != NULL)
*flags = 0;
- if (!self->active || account == NULL)
- return NULL;
+ g_return_val_if_fail (self->active, NULL);
+ g_return_val_if_fail (account != NULL, NULL);
g_dbus_connection_emit_signal (self->bus, NULL,
TEST_DBUS_ACCOUNT_PLUGIN_PATH, TEST_DBUS_ACCOUNT_PLUGIN_IFACE,
@@ -1052,8 +1052,8 @@ test_dbus_account_plugin_set_attribute (McpAccountStorage *storage,
DEBUG ("%s of %s", attribute, account_name);
- if (!self->active || account == NULL)
- return MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED;
+ g_return_val_if_fail (self->active, MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED);
+ g_return_val_if_fail (account != NULL, MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED);
if (value == NULL)
{
@@ -1112,8 +1112,8 @@ test_dbus_account_plugin_set_parameter (McpAccountStorage *storage,
DEBUG ("%s of %s", parameter, account_name);
- if (!self->active || account == NULL)
- return MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED;
+ g_return_val_if_fail (self->active, MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED);
+ g_return_val_if_fail (account != NULL, MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED);
if (value == NULL)
{
@@ -1342,8 +1342,8 @@ test_dbus_account_plugin_commit (const McpAccountStorage *storage,
account = lookup_account (self, account_name);
- if (!self->active || account == NULL)
- return FALSE;
+ g_return_val_if_fail (self->active, FALSE);
+ g_return_val_if_fail (account != NULL, FALSE);
g_dbus_connection_emit_signal (self->bus, NULL,
TEST_DBUS_ACCOUNT_PLUGIN_PATH, TEST_DBUS_ACCOUNT_PLUGIN_IFACE,
@@ -1484,8 +1484,8 @@ test_dbus_account_plugin_get_identifier (const McpAccountStorage *storage,
DEBUG ("%s", account_name);
- if (!self->active || account == NULL)
- return;
+ g_return_if_fail (self->active);
+ g_return_if_fail (account != NULL);
/* Our "library-specific unique identifier" is just the object-path
* as a string. */
@@ -1503,8 +1503,8 @@ test_dbus_account_plugin_get_additional_info (const McpAccountStorage *storage,
DEBUG ("%s", account_name);
- if (!self->active || account == NULL)
- return NULL;
+ g_return_val_if_fail (self->active, NULL);
+ g_return_val_if_fail (account != NULL, NULL);
ret = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, (GDestroyNotify) tp_g_value_slice_free);
@@ -1523,8 +1523,8 @@ test_dbus_account_plugin_get_restrictions (const McpAccountStorage *storage,
DEBUG ("%s", account_name);
- if (!self->active || account == NULL)
- return 0;
+ g_return_val_if_fail (self->active, 0);
+ g_return_val_if_fail (account != NULL, 0);
return account->restrictions;
}