Tests for password functionality

This commit is contained in:
Stef Walter 2012-01-30 18:11:53 +01:00
parent d797ef2ba3
commit 075ca76cc0
2 changed files with 128 additions and 5 deletions

View File

@ -336,6 +336,7 @@ gsecret_password_lookupv (GHashTable *attributes,
gsecret_password_lookupv);
closure = g_slice_new0 (LookupClosure);
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
closure->attributes = g_hash_table_ref (attributes);
g_simple_async_result_set_op_res_gpointer (res, closure, lookup_closure_free);
gsecret_service_get (GSECRET_SERVICE_OPEN_SESSION, cancellable,
@ -411,7 +412,7 @@ gsecret_password_lookupv_sync (GHashTable *attributes,
sync = _gsecret_sync_new ();
g_main_context_push_thread_default (sync->context);
gsecret_password_removev (attributes, cancellable,
gsecret_password_lookupv (attributes, cancellable,
_gsecret_sync_on_result, sync);
g_main_loop_run (sync->loop);

View File

@ -26,8 +26,8 @@
#include <errno.h>
#include <stdlib.h>
static const GSecretSchema DELETE_SCHEMA = {
"org.mock.schema.Delete",
static const GSecretSchema PASSWORD_SCHEMA = {
"org.mock.schema.Password",
{
{ "number", GSECRET_ATTRIBUTE_INTEGER },
{ "string", GSECRET_ATTRIBUTE_STRING },
@ -69,6 +69,114 @@ on_complete_get_result (GObject *source,
egg_test_wait_stop ();
}
static void
test_lookup_sync (Test *test,
gconstpointer used)
{
gchar *password;
GError *error = NULL;
password = gsecret_password_lookup_sync (&PASSWORD_SCHEMA, NULL, &error,
"even", FALSE,
"string", "one",
"number", 1,
NULL);
g_assert_no_error (error);
g_assert_cmpstr (password, ==, "111");
gsecret_password_free (password);
}
static void
test_lookup_async (Test *test,
gconstpointer used)
{
GAsyncResult *result = NULL;
GError *error = NULL;
gchar *password;
gsecret_password_lookup (&PASSWORD_SCHEMA, NULL, on_complete_get_result, &result,
"even", FALSE,
"string", "one",
"number", 1,
NULL);
g_assert (result == NULL);
egg_test_wait ();
password = gsecret_password_lookup_finish (result, &error);
g_assert_no_error (error);
g_object_unref (result);
g_assert_cmpstr (password, ==, "111");
gsecret_password_free (password);
}
static void
test_store_sync (Test *test,
gconstpointer used)
{
const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
GError *error = NULL;
gchar *password;
gboolean ret;
ret = gsecret_password_store_sync (&PASSWORD_SCHEMA, collection_path,
"Label here", "the password", NULL, &error,
"even", TRUE,
"string", "twelve",
"number", 12,
NULL);
g_assert_no_error (error);
g_assert (ret == TRUE);
password = gsecret_password_lookup_sync (&PASSWORD_SCHEMA, NULL, &error,
"string", "twelve",
NULL);
g_assert_no_error (error);
g_assert_cmpstr (password, ==, "the password");
gsecret_password_free (password);
}
static void
test_store_async (Test *test,
gconstpointer used)
{
const gchar *collection_path = "/org/freedesktop/secrets/collection/english";
GAsyncResult *result = NULL;
GError *error = NULL;
gchar *password;
gboolean ret;
gsecret_password_store (&PASSWORD_SCHEMA, collection_path, "Label here",
"the password", NULL, on_complete_get_result, &result,
"even", TRUE,
"string", "twelve",
"number", 12,
NULL);
g_assert (result == NULL);
egg_test_wait ();
ret = gsecret_password_store_finish (result, &error);
g_assert_no_error (error);
g_assert (ret == TRUE);
g_object_unref (result);
password = gsecret_password_lookup_sync (&PASSWORD_SCHEMA, NULL, &error,
"string", "twelve",
NULL);
g_assert_no_error (error);
g_assert_cmpstr (password, ==, "the password");
gsecret_password_free (password);
}
static void
test_delete_sync (Test *test,
gconstpointer used)
@ -76,7 +184,7 @@ test_delete_sync (Test *test,
GError *error = NULL;
gboolean ret;
ret = gsecret_password_remove_sync (&DELETE_SCHEMA, NULL, &error,
ret = gsecret_password_remove_sync (&PASSWORD_SCHEMA, NULL, &error,
"even", FALSE,
"string", "one",
"number", 1,
@ -94,7 +202,7 @@ test_delete_async (Test *test,
GAsyncResult *result = NULL;
gboolean ret;
gsecret_password_remove (&DELETE_SCHEMA, NULL,
gsecret_password_remove (&PASSWORD_SCHEMA, NULL,
on_complete_get_result, &result,
"even", FALSE,
"string", "one",
@ -112,6 +220,12 @@ test_delete_async (Test *test,
g_object_unref (result);
}
static void
test_password_free_null (void)
{
gsecret_password_free (NULL);
}
int
main (int argc, char **argv)
{
@ -119,8 +233,16 @@ main (int argc, char **argv)
g_set_prgname ("test-password");
g_type_init ();
g_test_add ("/password/lookup-sync", Test, "mock-service-normal.py", setup, test_lookup_sync, teardown);
g_test_add ("/password/lookup-async", Test, "mock-service-normal.py", setup, test_lookup_async, teardown);
g_test_add ("/password/store-sync", Test, "mock-service-normal.py", setup, test_store_sync, teardown);
g_test_add ("/password/store-async", Test, "mock-service-normal.py", setup, test_store_async, teardown);
g_test_add ("/password/delete-sync", Test, "mock-service-delete.py", setup, test_delete_sync, teardown);
g_test_add ("/password/delete-async", Test, "mock-service-delete.py", setup, test_delete_async, teardown);
g_test_add_func ("/password/free-null", test_password_free_null);
return egg_tests_run_with_loop ();
}