~ubuntu-branches/debian/stretch/gnome-builder/stretch

« back to all changes in this revision

Viewing changes to tests/test-egg-cache.c

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson
  • Date: 2015-10-11 12:38:45 UTC
  • Revision ID: package-import@ubuntu.com-20151011123845-a0hvkz01se0p1p5a
Tags: upstream-3.16.3
ImportĀ upstreamĀ versionĀ 3.16.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "egg-task-cache.h"
 
2
 
 
3
static GMainLoop *main_loop;
 
4
static EggTaskCache *cache;
 
5
static GObject *foo;
 
6
 
 
7
static void
 
8
populate_callback (EggTaskCache  *self,
 
9
                   gconstpointer  key,
 
10
                   GTask         *task,
 
11
                   gpointer       user_data)
 
12
{
 
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);
 
16
}
 
17
 
 
18
static void
 
19
get_foo_cb (GObject      *object,
 
20
            GAsyncResult *result,
 
21
            gpointer      user_data)
 
22
{
 
23
  GError *error = NULL;
 
24
  GObject *ret;
 
25
 
 
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);
 
30
 
 
31
  g_assert (egg_task_cache_evict (cache, "foo"));
 
32
  g_object_unref (ret);
 
33
 
 
34
  g_main_loop_quit (main_loop);
 
35
}
 
36
 
 
37
static void
 
38
test_task_cache (void)
 
39
{
 
40
  main_loop = g_main_loop_new (NULL, FALSE);
 
41
  cache = egg_task_cache_new (g_str_hash,
 
42
                              g_str_equal,
 
43
                              (GBoxedCopyFunc)g_strdup,
 
44
                              (GBoxedFreeFunc)g_free,
 
45
                              g_object_ref,
 
46
                              g_object_unref,
 
47
                              100 /* msec */,
 
48
                              populate_callback, NULL, NULL);
 
49
 
 
50
  g_assert (!egg_task_cache_peek (cache, "foo"));
 
51
  g_assert (!egg_task_cache_evict (cache, "foo"));
 
52
 
 
53
  egg_task_cache_get_async (cache, "foo", TRUE, NULL, get_foo_cb, NULL);
 
54
 
 
55
  g_main_loop_run (main_loop);
 
56
  g_main_loop_unref (main_loop);
 
57
 
 
58
  g_assert (foo == NULL);
 
59
}
 
60
 
 
61
gint
 
62
main (gint   argc,
 
63
      gchar *argv[])
 
64
{
 
65
  g_test_init (&argc, &argv, NULL);
 
66
  g_test_add_func ("/Egg/TaskCache/basic", test_task_cache);
 
67
  return g_test_run ();
 
68
}