summaryrefslogtreecommitdiff
path: root/cogl/tests/conform/test-object.c
blob: 01e1788b845fbd4756a37e75e061b3829a44b331 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include <string.h>

#include "test-conform-common.h"

CoglUserDataKey private_key0;
CoglUserDataKey private_key1;
CoglUserDataKey private_key2;

static int user_data0;
static int user_data1;
static int user_data2;

static int destroy0_count = 0;
static int destroy1_count = 0;
static int destroy2_count = 0;

static void
destroy0_cb (void *user_data)
{
  g_assert (user_data == &user_data0);
  destroy0_count++;
}

static void
destroy1_cb (void *user_data)
{
  g_assert (user_data == &user_data1);
  destroy1_count++;
}

static void
destroy2_cb (void *user_data)
{
  g_assert (user_data == &user_data2);
  destroy2_count++;
}

void
test_object (TestUtilsGTestFixture *fixture,
                  void *data)
{
  CoglPipeline *pipeline;

  /* Assuming that COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES == 2
   * test associating 2 pointers to private data with an object */
  cogl_pipeline_new ();
  pipeline = cogl_pipeline_path ();

  cogl_object_set_user_data (COGL_OBJECT (pipeline),
                             &private_key0,
                             &user_data0,
                             destroy0_cb);

  cogl_object_set_user_data (COGL_OBJECT (pipeline),
                             &private_key1,
                             &user_data1,
                             destroy1_cb);

  cogl_object_set_user_data (COGL_OBJECT (pipeline),
                             &private_key2,
                             &user_data2,
                             destroy2_cb);

  cogl_object_set_user_data (COGL_OBJECT (pipeline),
                             &private_key1,
                             NULL,
                             destroy1_cb);

  cogl_object_set_user_data (COGL_OBJECT (pipeline),
                             &private_key1,
                             &user_data1,
                             destroy1_cb);

  cogl_object_unref (pipeline);

  g_assert_cmpint (destroy0_count, ==, 1);
  g_assert_cmpint (destroy1_count, ==, 2);
  g_assert_cmpint (destroy2_count, ==, 1);

  if (cogl_test_verbose ())
    g_print ("OK\n");
}