1
#include "egg-task-cache.h"
3
static GMainLoop *main_loop;
4
static EggTaskCache *cache;
8
populate_callback (EggTaskCache *self,
13
foo = g_object_new (G_TYPE_OBJECT, NULL);
14
g_object_add_weak_pointer (G_OBJECT (foo), (gpointer *)&foo);
15
g_task_return_pointer (task, foo, g_object_unref);
19
get_foo_cb (GObject *object,
26
ret = egg_task_cache_get_finish (cache, result, &error);
27
g_assert_no_error (error);
28
g_assert (ret != NULL);
29
g_assert (ret == foo);
31
g_assert (egg_task_cache_evict (cache, "foo"));
34
g_main_loop_quit (main_loop);
38
test_task_cache (void)
40
main_loop = g_main_loop_new (NULL, FALSE);
41
cache = egg_task_cache_new (g_str_hash,
43
(GBoxedCopyFunc)g_strdup,
44
(GBoxedFreeFunc)g_free,
48
populate_callback, NULL, NULL);
50
g_assert (!egg_task_cache_peek (cache, "foo"));
51
g_assert (!egg_task_cache_evict (cache, "foo"));
53
egg_task_cache_get_async (cache, "foo", TRUE, NULL, get_foo_cb, NULL);
55
g_main_loop_run (main_loop);
56
g_main_loop_unref (main_loop);
58
g_assert (foo == NULL);
65
g_test_init (&argc, &argv, NULL);
66
g_test_add_func ("/Egg/TaskCache/basic", test_task_cache);