From 2ae6ec89f43f076d622658275bd24c57996c18c5 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Sat, 29 Jun 2019 09:55:01 +0200 Subject: [PATCH] tests: Add tests for binary variant of secret_{lookup,store} --- libsecret/test-password.c | 73 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/libsecret/test-password.c b/libsecret/test-password.c index 01053eb..f20a31b 100644 --- a/libsecret/test-password.c +++ b/libsecret/test-password.c @@ -440,6 +440,76 @@ test_search_no_name (Test *test, g_list_free (items); } +static void +test_binary_sync (Test *test, + gconstpointer used) +{ + const gchar *collection_path = "/org/freedesktop/secrets/collection/english"; + GError *error = NULL; + SecretValue *value; + gboolean ret; + + value = secret_value_new ("the password", -1, "text/plain"); + ret = secret_password_store_binary_sync (&MOCK_SCHEMA, collection_path, + "Label here", value, NULL, &error, + "even", TRUE, + "string", "twelve", + "number", 12, + NULL); + + g_assert_no_error (error); + g_assert_true (ret); + secret_value_unref (value); + + value = secret_password_lookup_binary_sync (&MOCK_SCHEMA, NULL, &error, + "string", "twelve", + NULL); + + g_assert_no_error (error); + g_assert_cmpstr (secret_value_get_text (value), ==, "the password"); + + secret_value_unref (value); +} + +static void +test_binary_async (Test *test, + gconstpointer used) +{ + const gchar *collection_path = "/org/freedesktop/secrets/collection/english"; + GAsyncResult *result = NULL; + GError *error = NULL; + SecretValue *value; + gboolean ret; + + value = secret_value_new ("the password", -1, "text/plain"); + secret_password_store_binary (&MOCK_SCHEMA, collection_path, "Label here", + value, NULL, on_complete_get_result, &result, + "even", TRUE, + "string", "twelve", + "number", 12, + NULL); + g_assert_null (result); + secret_value_unref (value); + + egg_test_wait (); + + ret = secret_password_store_finish (result, &error); + g_assert_no_error (error); + g_assert_true (ret); + g_object_unref (result); + + value = secret_password_lookup_binary_sync (&MOCK_SCHEMA, NULL, &error, + "string", "twelve", + NULL); + + g_assert_no_error (error); + g_assert_nonnull (value); + + g_assert_cmpstr (secret_value_get_text (value), ==, "the password"); + + secret_value_unref (value); +} + static void test_password_free_null (void) { @@ -468,6 +538,9 @@ main (int argc, char **argv) g_test_add ("/password/search-async", Test, "mock-service-normal.py", setup, test_search_async, teardown); g_test_add ("/password/search-no-name", Test, "mock-service-normal.py", setup, test_search_no_name, teardown); + g_test_add ("/password/binary-sync", Test, "mock-service-normal.py", setup, test_binary_sync, teardown); + g_test_add ("/password/binary-async", Test, "mock-service-normal.py", setup, test_binary_async, teardown); + g_test_add_func ("/password/free-null", test_password_free_null); return egg_tests_run_with_loop ();