Add test for GSecretService singleton, and make it work

This commit is contained in:
Stef Walter 2011-11-06 08:59:20 +01:00 committed by Stef Walter
parent 7ac228b62f
commit 76ae17b24f
2 changed files with 48 additions and 1 deletions

View File

@ -120,11 +120,21 @@ GSecretService *
_gsecret_service_bare_instance (GDBusConnection *connection, _gsecret_service_bare_instance (GDBusConnection *connection,
const gchar *bus_name) const gchar *bus_name)
{ {
GSecretService *service; GSecretService *service = NULL;
GError *error = NULL; GError *error = NULL;
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL); g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
G_LOCK (service_instance);
if (service_instance != NULL)
service = g_object_ref (service_instance);
G_UNLOCK (service_instance);
if (service != NULL)
return service;
/* Alternate bus name is only used for testing */ /* Alternate bus name is only used for testing */
if (bus_name == NULL) if (bus_name == NULL)
bus_name = GSECRET_SERVICE_BUS_NAME; bus_name = GSECRET_SERVICE_BUS_NAME;

View File

@ -66,6 +66,42 @@ teardown (Test *test,
g_spawn_close_pid (test->pid); g_spawn_close_pid (test->pid);
} }
static void
test_instance (void)
{
GSecretService *service1;
GSecretService *service2;
GSecretService *service3;
GError *error = NULL;
GDBusConnection *connection;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error (error);
/* Both these sohuld point to the same thing */
service1 = _gsecret_service_bare_instance (connection, MOCK_NAME);
service2 = _gsecret_service_bare_instance (connection, MOCK_NAME);
g_assert (GSECRET_IS_SERVICE (service1));
g_assert (service1 == service2);
g_object_unref (service1);
g_assert (GSECRET_IS_SERVICE (service1));
g_object_unref (service2);
g_assert (!GSECRET_IS_SERVICE (service2));
/* Services were unreffed, so this should create a new one */
service3 = _gsecret_service_bare_instance (connection, MOCK_NAME);
g_assert (GSECRET_IS_SERVICE (service3));
g_object_unref (service3);
g_assert (!GSECRET_IS_SERVICE (service3));
g_object_unref (connection);
}
static void static void
test_search_paths (Test *test, test_search_paths (Test *test,
gconstpointer used) gconstpointer used)
@ -103,6 +139,7 @@ main (int argc, char **argv)
g_set_prgname ("test-service"); g_set_prgname ("test-service");
g_type_init (); g_type_init ();
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);
return egg_tests_run_in_thread_with_loop (); return egg_tests_run_in_thread_with_loop ();