mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2024-12-22 04:38:55 +00:00
Add more coverage testing for search paths
This commit is contained in:
parent
9a319cb767
commit
09a9d856d2
2
.gitignore
vendored
2
.gitignore
vendored
@ -29,7 +29,7 @@ stamp*
|
|||||||
.project
|
.project
|
||||||
.cproject
|
.cproject
|
||||||
|
|
||||||
/build/coverage
|
/build/coverage*
|
||||||
/build/m4
|
/build/m4
|
||||||
/build/valgrind-built.supp
|
/build/valgrind-built.supp
|
||||||
|
|
||||||
|
@ -31,9 +31,9 @@ check-memory:
|
|||||||
|
|
||||||
if WITH_COVERAGE
|
if WITH_COVERAGE
|
||||||
coverage:
|
coverage:
|
||||||
mkdir -p build/coverage
|
mkdir -p $(builddir)/build/coverage
|
||||||
$(LCOV) --directory . --capture --output-file build/coverage/coverage.info
|
$(LCOV) --directory . --capture --output-file $(builddir)/build/coverage.info
|
||||||
$(GENHTML) --output-directory coverage build/coverage/coverage.info
|
$(GENHTML) --output-directory $(builddir)/build/coverage $(builddir)/build/coverage.info
|
||||||
$(LCOV) --directory . --zerocounters
|
$(LCOV) --directory . --zerocounters
|
||||||
@echo "file://$(abs_top_builddir)/build/coverage/index.html"
|
@echo "file://$(abs_top_builddir)/build/coverage/index.html"
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ noinst_PROGRAMS = \
|
|||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
test: $(TEST_PROGS)
|
test: $(TEST_PROGS)
|
||||||
gtester -k --verbose $(TEST_PROGS)
|
gtester --verbose -m $(TEST_MODE) --g-fatal-warnings $(TEST_PROGS)
|
||||||
|
|
||||||
all-local: $(check_PROGRAMS)
|
all-local: $(check_PROGRAMS)
|
||||||
|
|
||||||
|
@ -75,10 +75,11 @@ class SecretSession(dbus.service.Object):
|
|||||||
|
|
||||||
|
|
||||||
class SecretItem(dbus.service.Object):
|
class SecretItem(dbus.service.Object):
|
||||||
def __init__(self, collection, identifier, label="Item", attributes={ }):
|
def __init__(self, collection, identifier, label="Item", attributes={ }, secret=""):
|
||||||
self.collection = collection
|
self.collection = collection
|
||||||
self.identifier = identifier
|
self.identifier = identifier
|
||||||
self.label = label
|
self.label = label
|
||||||
|
self.secret = secret
|
||||||
self.attributes = attributes
|
self.attributes = attributes
|
||||||
self.path = "/org/freedesktop/secrets/collection/%s/%s" % (collection.identifier, identifier)
|
self.path = "/org/freedesktop/secrets/collection/%s/%s" % (collection.identifier, identifier)
|
||||||
dbus.service.Object.__init__(self, collection.service.bus_name, self.path)
|
dbus.service.Object.__init__(self, collection.service.bus_name, self.path)
|
||||||
|
@ -68,6 +68,18 @@ teardown (Test *test,
|
|||||||
g_spawn_close_pid (test->pid);
|
g_spawn_close_pid (test->pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_complete_get_result (GObject *source,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GAsyncResult **ret = user_data;
|
||||||
|
g_assert (ret != NULL);
|
||||||
|
g_assert (*ret == NULL);
|
||||||
|
*ret = g_object_ref (result);
|
||||||
|
egg_test_wait_stop ();
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_instance (void)
|
test_instance (void)
|
||||||
{
|
{
|
||||||
@ -134,6 +146,117 @@ test_search_paths (Test *test,
|
|||||||
g_hash_table_unref (attributes);
|
g_hash_table_unref (attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_search_paths_async (Test *test,
|
||||||
|
gconstpointer used)
|
||||||
|
{
|
||||||
|
GAsyncResult *result = NULL;
|
||||||
|
GHashTable *attributes;
|
||||||
|
gboolean ret;
|
||||||
|
gchar **locked;
|
||||||
|
gchar **unlocked;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
|
g_hash_table_insert (attributes, "number", "1");
|
||||||
|
|
||||||
|
gsecret_service_search_paths (test->service, attributes, NULL,
|
||||||
|
on_complete_get_result, &result);
|
||||||
|
egg_test_wait ();
|
||||||
|
|
||||||
|
g_assert (G_IS_ASYNC_RESULT (result));
|
||||||
|
ret = gsecret_service_search_paths_finish (test->service, result,
|
||||||
|
&unlocked, &locked,
|
||||||
|
&error);
|
||||||
|
g_assert_no_error (error);
|
||||||
|
g_assert (ret == TRUE);
|
||||||
|
|
||||||
|
g_assert (locked);
|
||||||
|
g_assert_cmpstr (locked[0], ==, "/org/freedesktop/secrets/collection/second/item_one");
|
||||||
|
|
||||||
|
g_assert (unlocked);
|
||||||
|
g_assert_cmpstr (unlocked[0], ==, "/org/freedesktop/secrets/collection/collection/item_one");
|
||||||
|
|
||||||
|
g_strfreev (unlocked);
|
||||||
|
g_strfreev (locked);
|
||||||
|
g_object_unref (result);
|
||||||
|
|
||||||
|
g_hash_table_unref (attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_search_paths_nulls (Test *test,
|
||||||
|
gconstpointer used)
|
||||||
|
{
|
||||||
|
GAsyncResult *result = NULL;
|
||||||
|
GHashTable *attributes;
|
||||||
|
gboolean ret;
|
||||||
|
gchar **paths;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
attributes = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
|
g_hash_table_insert (attributes, "number", "1");
|
||||||
|
|
||||||
|
ret = gsecret_service_search_paths_sync (test->service, attributes, NULL,
|
||||||
|
&paths, NULL, &error);
|
||||||
|
g_assert_no_error (error);
|
||||||
|
g_assert (ret == TRUE);
|
||||||
|
g_assert (paths != NULL);
|
||||||
|
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/collection/item_one");
|
||||||
|
g_strfreev (paths);
|
||||||
|
|
||||||
|
ret = gsecret_service_search_paths_sync (test->service, attributes, NULL,
|
||||||
|
NULL, &paths, &error);
|
||||||
|
g_assert_no_error (error);
|
||||||
|
g_assert (ret == TRUE);
|
||||||
|
g_assert (paths != NULL);
|
||||||
|
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/second/item_one");
|
||||||
|
g_strfreev (paths);
|
||||||
|
|
||||||
|
ret = gsecret_service_search_paths_sync (test->service, attributes, NULL,
|
||||||
|
NULL, NULL, &error);
|
||||||
|
g_assert_no_error (error);
|
||||||
|
g_assert (ret == TRUE);
|
||||||
|
|
||||||
|
gsecret_service_search_paths (test->service, attributes, NULL,
|
||||||
|
on_complete_get_result, &result);
|
||||||
|
egg_test_wait ();
|
||||||
|
g_assert (G_IS_ASYNC_RESULT (result));
|
||||||
|
ret = gsecret_service_search_paths_finish (test->service, result,
|
||||||
|
&paths, NULL, &error);
|
||||||
|
g_assert_no_error (error);
|
||||||
|
g_assert (ret == TRUE);
|
||||||
|
g_assert (paths != NULL);
|
||||||
|
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/collection/item_one");
|
||||||
|
g_strfreev (paths);
|
||||||
|
g_clear_object (&result);
|
||||||
|
|
||||||
|
gsecret_service_search_paths (test->service, attributes, NULL,
|
||||||
|
on_complete_get_result, &result);
|
||||||
|
egg_test_wait ();
|
||||||
|
g_assert (G_IS_ASYNC_RESULT (result));
|
||||||
|
ret = gsecret_service_search_paths_finish (test->service, result,
|
||||||
|
NULL, &paths, &error);
|
||||||
|
g_assert_no_error (error);
|
||||||
|
g_assert (ret == TRUE);
|
||||||
|
g_assert (paths != NULL);
|
||||||
|
g_assert_cmpstr (paths[0], ==, "/org/freedesktop/secrets/collection/second/item_one");
|
||||||
|
g_strfreev (paths);
|
||||||
|
g_clear_object (&result);
|
||||||
|
|
||||||
|
gsecret_service_search_paths (test->service, attributes, NULL,
|
||||||
|
on_complete_get_result, &result);
|
||||||
|
egg_test_wait ();
|
||||||
|
g_assert (G_IS_ASYNC_RESULT (result));
|
||||||
|
ret = gsecret_service_search_paths_finish (test->service, result,
|
||||||
|
NULL, NULL, &error);
|
||||||
|
g_assert_no_error (error);
|
||||||
|
g_assert (ret == TRUE);
|
||||||
|
g_clear_object (&result);
|
||||||
|
|
||||||
|
g_hash_table_unref (attributes);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -143,6 +266,8 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
g_test_add_func ("/service/instance", test_instance);
|
g_test_add_func ("/service/instance", test_instance);
|
||||||
g_test_add ("/service/search-paths", Test, "mock-service-normal.py", setup, test_search_paths, teardown);
|
g_test_add ("/service/search-paths", Test, "mock-service-normal.py", setup, test_search_paths, teardown);
|
||||||
|
g_test_add ("/service/search-paths-async", Test, "mock-service-normal.py", setup, test_search_paths_async, teardown);
|
||||||
|
g_test_add ("/service/search-paths-nulls", Test, "mock-service-normal.py", setup, test_search_paths_nulls, teardown);
|
||||||
|
|
||||||
return egg_tests_run_with_loop ();
|
return egg_tests_run_with_loop ();
|
||||||
}
|
}
|
||||||
|
@ -139,6 +139,7 @@ on_complete_get_result (GObject *source,
|
|||||||
g_assert (ret != NULL);
|
g_assert (ret != NULL);
|
||||||
g_assert (*ret == NULL);
|
g_assert (*ret == NULL);
|
||||||
*ret = g_object_ref (result);
|
*ret = g_object_ref (result);
|
||||||
|
egg_test_wait_stop ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -150,7 +151,7 @@ test_ensure_async_plain (Test *test,
|
|||||||
const gchar *path;
|
const gchar *path;
|
||||||
|
|
||||||
gsecret_service_ensure_session (test->service, NULL, on_complete_get_result, &result);
|
gsecret_service_ensure_session (test->service, NULL, on_complete_get_result, &result);
|
||||||
egg_test_wait_until (500);
|
egg_test_wait ();
|
||||||
|
|
||||||
g_assert (G_IS_ASYNC_RESULT (result));
|
g_assert (G_IS_ASYNC_RESULT (result));
|
||||||
path = gsecret_service_ensure_session_finish (test->service, result, &error);
|
path = gsecret_service_ensure_session_finish (test->service, result, &error);
|
||||||
|
Loading…
Reference in New Issue
Block a user