summaryrefslogtreecommitdiff
path: root/tests/test-tpl-observer.c
blob: e26e007a83c5874f72e9c5167f4bb706ea8dcb23 (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
#include "tpl-channel-test.h"

#include <telepathy-logger/channel-factory-internal.h>
#include <telepathy-logger/observer-internal.h>

static gint factory_counter = 0;

static TplChannel *
mock_factory (const gchar *chan_type,
    TpConnection *conn, const gchar *object_path, GHashTable *tp_chan_props,
    TpAccount *tp_acc, GError **error)
{
  factory_counter += 1;
  return NULL;
}



int
main (int argc, char **argv)
{
  TplObserver *obs, *obs2;

  g_type_init ();

  obs = tpl_observer_new ();

  /* TplObserver is a singleton, be sure both references point to the same
   * memory address  */
  obs2 = tpl_observer_new ();
  g_assert (obs == obs2);

  /* unref the second singleton pointer and check that the it is still
   * valid: checking correct object ref-counting after each _dup() call */
  g_object_unref (obs2);
  g_assert (TPL_IS_OBSERVER (obs));

  /* it points to the same mem area, it should be still valid */
  g_assert (TPL_IS_OBSERVER (obs2));

  /* register a ChanFactory and test ObserveChannel() */
  tpl_observer_set_channel_factory (obs, mock_factory);


  /* proper disposal for the singleton when no references are present */
  g_object_unref (obs);
  g_assert (TPL_IS_OBSERVER (obs) == FALSE);

  return 0;
}