summaryrefslogtreecommitdiff
path: root/libsecret
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@src.gnome.org>2019-06-29 09:55:01 +0200
committerDaiki Ueno <ueno@gnu.org>2019-07-18 13:54:12 +0000
commit2ae6ec89f43f076d622658275bd24c57996c18c5 (patch)
treedf15afe56e642c3e712697ef26f8d91c40926793 /libsecret
parent29c1460fd73c4ee7dc4bb9c7d30dcf5b525d0314 (diff)
downloadlibsecret-2ae6ec89f43f076d622658275bd24c57996c18c5.tar.gz
tests: Add tests for binary variant of secret_{lookup,store}
Diffstat (limited to 'libsecret')
-rw-r--r--libsecret/test-password.c73
1 files changed, 73 insertions, 0 deletions
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
@@ -441,6 +441,76 @@ test_search_no_name (Test *test,
}
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)
{
secret_password_free (NULL);
@@ -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 ();