summaryrefslogtreecommitdiff
path: root/tests/dbus/test-log-manager.c
blob: 3a2bf3f0ef267c9e5e7997709a249d0256ea0eb5 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
#include "config.h"

#include "telepathy-logger/log-manager.c"

#include "lib/util.h"
#include "lib/simple-account.h"
#include "lib/simple-account-manager.h"
#include "lib/logger-test-helper.h"

#include "telepathy-logger/debug-internal.h"
#include "telepathy-logger/log-manager-internal.h"
#include "telepathy-logger/log-store-internal.h"
#include <telepathy-logger/text-event.h>
#include <telepathy-logger/client-factory-internal.h>

#include <telepathy-glib/telepathy-glib.h>

/* it was defined in telepathy-logger/log-manager.c */
#undef DEBUG_FLAG
#define DEBUG_FLAG TPL_DEBUG_TESTSUITE

#define ACCOUNT_PATH_JABBER TP_ACCOUNT_OBJECT_PATH_BASE "gabble/jabber/user_40collabora_2eco_2euk"
#define MY_ID "user@collabora.co.uk"
#define ID "user2@collabora.co.uk"

typedef struct
{
  GMainLoop *main_loop;

  TpDBusDaemon *dbus;
  TpAccount *account;
  TpTestsSimpleAccount *account_service;
  TpSimpleClientFactory *factory;

  GList *ret;

  gchar *tmp_basedir;

  TplLogManager *manager;
} TestCaseFixture;



#ifdef ENABLE_DEBUG
static TpDebugSender *debug_sender = NULL;
static gboolean stamp_logs = FALSE;


static void
log_to_debug_sender (const gchar *log_domain,
    GLogLevelFlags log_level,
    const gchar *string)
{
  GTimeVal now;

  g_return_if_fail (TP_IS_DEBUG_SENDER (debug_sender));

  g_get_current_time (&now);

  tp_debug_sender_add_message (debug_sender, &now, log_domain, log_level,
      string);
}


static void
log_handler (const gchar *log_domain,
    GLogLevelFlags log_level,
    const gchar *message,
    gpointer user_data)
{
  if (stamp_logs)
    {
      GTimeVal now;
      gchar now_str[32];
      gchar *tmp;
      struct tm tm;

      g_get_current_time (&now);
      localtime_r (&(now.tv_sec), &tm);
      strftime (now_str, 32, "%Y-%m-%d %H:%M:%S", &tm);
      tmp = g_strdup_printf ("%s.%06ld: %s",
          now_str, now.tv_usec, message);

      g_log_default_handler (log_domain, log_level, tmp, NULL);

      g_free (tmp);
    }
  else
    {
      g_log_default_handler (log_domain, log_level, message, NULL);
    }

  log_to_debug_sender (log_domain, log_level, message);
}
#endif /* ENABLE_DEBUG */


static void
teardown_service (TestCaseFixture* fixture,
    gconstpointer user_data)
{
  GError *error = NULL;

  g_assert (user_data != NULL);

  if (fixture->account != NULL)
    {
      /* FIXME is it useful in this suite */
      tp_tests_proxy_run_until_dbus_queue_processed (fixture->account);

      g_object_unref (fixture->account);
      fixture->account = NULL;
    }

  tp_dbus_daemon_unregister_object (fixture->dbus, fixture->account_service);
  g_object_unref (fixture->account_service);
  fixture->account_service = NULL;

  tp_dbus_daemon_release_name (fixture->dbus, TP_ACCOUNT_MANAGER_BUS_NAME,
      &error);
  g_assert_no_error (error);

  g_object_unref (fixture->dbus);
  fixture->dbus = NULL;

  g_clear_object (&fixture->factory);
}

static void
teardown (TestCaseFixture* fixture,
    gconstpointer user_data)
{
  if (fixture->tmp_basedir != NULL)
    {
      gchar *command = g_strdup_printf ("rm -rf %s", fixture->tmp_basedir);

      if (system (command) == -1)
          g_warning ("Failed to cleanup tempory test log dir: %s",
                  fixture->tmp_basedir);

      g_free (fixture->tmp_basedir);
    }

  g_object_unref (fixture->manager);
  fixture->manager = NULL;

  if (user_data != NULL)
    teardown_service (fixture, user_data);

  g_main_loop_unref (fixture->main_loop);
  fixture->main_loop = NULL;
}


static void
account_prepare_cb (GObject *source,
    GAsyncResult *result,
    gpointer user_data)
{
  TestCaseFixture *fixture = user_data;
  GError *error = NULL;

  tp_proxy_prepare_finish (source, result, &error);
  g_assert_no_error (error);

  g_main_loop_quit (fixture->main_loop);
}


static void
setup_service (TestCaseFixture* fixture,
    gconstpointer user_data)
{
  GQuark account_features[] = { TP_ACCOUNT_FEATURE_CORE, 0 };
  const gchar *account_path;
  GValue *boxed_params;
  GHashTable *params = (GHashTable *) user_data;
  GError *error = NULL;

  g_assert (params != NULL);

  fixture->dbus = tp_tests_dbus_daemon_dup_or_die ();
  g_assert (fixture->dbus != NULL);

  tp_dbus_daemon_request_name (fixture->dbus,
      TP_ACCOUNT_MANAGER_BUS_NAME, FALSE, &error);
  g_assert_no_error (error);

  /* Create service-side Account object with the passed parameters */
  fixture->account_service = g_object_new (TP_TESTS_TYPE_SIMPLE_ACCOUNT,
      NULL);
  g_assert (fixture->account_service != NULL);

  /* account-path will be set-up as parameter as well, this is not an issue */
  account_path = g_value_get_string (
      (const GValue *) g_hash_table_lookup (params, "account-path"));
  g_assert (account_path != NULL);

  boxed_params = tp_g_value_slice_new_boxed (TP_HASH_TYPE_STRING_VARIANT_MAP,
      params);
  g_object_set_property (G_OBJECT (fixture->account_service),
      "parameters", boxed_params);

  tp_dbus_daemon_register_object (fixture->dbus, account_path,
      fixture->account_service);

  fixture->factory = _tpl_client_factory_dup (fixture->dbus);

  fixture->account = tp_simple_client_factory_ensure_account (fixture->factory,
      account_path, NULL, NULL);
  g_assert (fixture->account != NULL);

  tp_proxy_prepare_async (fixture->account, account_features,
      account_prepare_cb, fixture);
  g_main_loop_run (fixture->main_loop);

  g_assert (tp_proxy_is_prepared (fixture->account, TP_ACCOUNT_FEATURE_CORE));

  tp_g_value_slice_free (boxed_params);
}


static void
setup (TestCaseFixture* fixture,
    gconstpointer user_data)
{
  DEBUG ("setting up");

  fixture->main_loop = g_main_loop_new (NULL, FALSE);
  g_assert (fixture->main_loop != NULL);

  fixture->manager = tpl_log_manager_dup_singleton ();

  if (user_data != NULL)
    setup_service (fixture, user_data);

  DEBUG ("set up finished");
}

static void
setup_for_writing (TestCaseFixture *fixture,
    gconstpointer user_data)
{
  gchar *readonly_dir;
  gchar *writable_dir;

  readonly_dir = g_build_path (G_DIR_SEPARATOR_S,
      g_getenv ("TPL_TEST_LOG_DIR"), "TpLogger", "logs", NULL);

  writable_dir = g_build_path (G_DIR_SEPARATOR_S,
      g_get_tmp_dir (), "logger-test-logs", NULL);

  tp_tests_copy_dir (readonly_dir, writable_dir);
  fixture->tmp_basedir = writable_dir;
  g_setenv ("TPL_TEST_LOG_DIR", writable_dir, TRUE);
  g_free (readonly_dir);

  setup (fixture, user_data);
}

static void
setup_debug (void)
{
  tp_debug_divert_messages (g_getenv ("TPL_LOGFILE"));

#ifdef ENABLE_DEBUG
  _tpl_debug_set_flags_from_env ();

  stamp_logs = (g_getenv ("TPL_TIMING") != NULL);
  debug_sender = tp_debug_sender_dup ();

  g_log_set_default_handler (log_handler, NULL);
#endif /* ENABLE_DEBUG */
}


static void
test_exists (TestCaseFixture *fixture,
    gconstpointer user_data)
{
  TplEntity *entity;
  TplEntity *no_entity;

  entity = tpl_entity_new (ID, TPL_ENTITY_CONTACT, NULL, NULL);
  no_entity = tpl_entity_new ("unknown", TPL_ENTITY_CONTACT, NULL, NULL);

  g_assert (tpl_log_manager_exists (fixture->manager, fixture->account,
        entity, TPL_EVENT_MASK_ANY));

  g_assert (!tpl_log_manager_exists (fixture->manager, fixture->account,
        no_entity, TPL_EVENT_MASK_ANY));

  g_object_unref (entity);
  g_object_unref (no_entity);
}


static void
get_dates_async_cb (GObject *object,
    GAsyncResult *result,
    gpointer user_data)
{
  TestCaseFixture *fixture = user_data;
  GError *error = NULL;

  tpl_log_manager_get_dates_finish (TPL_LOG_MANAGER (object),
      result, &fixture->ret, &error);

  g_assert_no_error (error);
  g_main_loop_quit (fixture->main_loop);
}

static void
test_get_dates (TestCaseFixture *fixture,
    gconstpointer user_data)
{
  GList *loc;
  TplEntity *entity;

  entity = tpl_entity_new (ID, TPL_ENTITY_CONTACT, NULL, NULL);

  tpl_log_manager_get_dates_async (fixture->manager,
      fixture->account, entity, TPL_EVENT_MASK_ANY,
      get_dates_async_cb, fixture);
  g_main_loop_run (fixture->main_loop);

  g_object_unref (entity);

  /* it includes 1 date from libpurple logs, 5 from TpLogger. Empathy
   * log-store date are the same of the TpLogger store, and wont' be present,
   * being duplicates */
  g_assert_cmpint (g_list_length (fixture->ret), ==, 6);

  /* we do not want duplicates, dates are suppose to be ordered */
  fixture->ret = g_list_sort (fixture->ret, (GCompareFunc) g_date_compare);
  for (loc = fixture->ret; loc != NULL; loc = g_list_next (loc))
    if (loc->next)
      g_assert (g_date_compare (loc->data, loc->next->data) != 0);

  g_list_foreach (fixture->ret, (GFunc) g_date_free, NULL);
  g_list_free (fixture->ret);
}


static void
get_events_for_date_cb (GObject *object,
    GAsyncResult *result,
    gpointer user_data)
{
  TestCaseFixture *fixture = user_data;
  GError *error = NULL;

  tpl_log_manager_get_events_for_date_finish (TPL_LOG_MANAGER (object),
      result, &fixture->ret, &error);

  g_assert_no_error (error);
  g_main_loop_quit (fixture->main_loop);
}


static void
test_get_events_for_date (TestCaseFixture *fixture,
    gconstpointer user_data)
{
  TplEntity *entity;
  GDate *date;

  entity = tpl_entity_new (ID, TPL_ENTITY_CONTACT, NULL, NULL);
  date = g_date_new_dmy (13, 1, 2010);

  tpl_log_manager_get_events_for_date_async (fixture->manager,
      fixture->account,
      entity,
      TPL_EVENT_MASK_TEXT,
      date,
      get_events_for_date_cb,
      fixture);
  g_main_loop_run (fixture->main_loop);

  g_object_unref (entity);
  g_date_free (date);

  /* We got 6 events in old Empathy and 6 in new TpLogger storage */
  g_assert_cmpint (g_list_length (fixture->ret), ==, 12);

  g_list_foreach (fixture->ret, (GFunc) g_object_unref, NULL);
  g_list_free (fixture->ret);
}

static void
test_get_events_for_date_account_unprepared (TestCaseFixture *fixture,
    gconstpointer user_data)
{
  GHashTable *params = (GHashTable *) user_data;
  TplEntity *entity;
  GDate *date;
  TpAccount *account;
  const gchar *account_path;

  g_clear_object (&fixture->account);

  account_path = g_value_get_string (
      (const GValue *) g_hash_table_lookup (params, "account-path"));

  account = tp_simple_client_factory_ensure_account (fixture->factory,
      account_path, NULL, NULL);
  g_assert (!tp_proxy_is_prepared (account, TP_ACCOUNT_FEATURE_CORE));

  entity = tpl_entity_new (ID, TPL_ENTITY_CONTACT, NULL, NULL);
  date = g_date_new_dmy (13, 1, 2010);

  tpl_log_manager_get_events_for_date_async (fixture->manager,
      account,
      entity,
      TPL_EVENT_MASK_TEXT,
      date,
      get_events_for_date_cb,
      fixture);
  g_main_loop_run (fixture->main_loop);

  g_object_unref (entity);
  g_date_free (date);

  /* We got 6 events in old Empathy and 6 in new TpLogger storage */
  g_assert_cmpint (g_list_length (fixture->ret), ==, 12);

  g_list_foreach (fixture->ret, (GFunc) g_object_unref, NULL);
  g_list_free (fixture->ret);
  g_object_unref (account);
}

static void
get_filtered_events_cb (GObject *object,
    GAsyncResult *result,
    gpointer user_data)
{
  TestCaseFixture *fixture = user_data;
  GError *error = NULL;

  tpl_log_manager_get_filtered_events_finish (TPL_LOG_MANAGER (object),
      result, &fixture->ret, &error);

  g_assert_no_error (error);
  g_main_loop_quit (fixture->main_loop);
}


static gboolean
events_filter (TplEvent *event,
  gpointer user_data)
{
  gboolean keep;
  GDateTime *timestamp;
  GDate *date = user_data;

  timestamp = g_date_time_new_from_unix_utc (tpl_event_get_timestamp (event));

  keep = g_date_time_get_year (timestamp) == g_date_get_year (date)
    && g_date_time_get_month (timestamp) == (gint) g_date_get_month (date)
    && g_date_time_get_day_of_month (timestamp) == g_date_get_day (date);

  g_date_time_unref (timestamp);

  return keep;
}


static void
test_get_filtered_events (TestCaseFixture *fixture,
    gconstpointer user_data)
{
  TplEntity *entity;
  GDate *date;

  entity = tpl_entity_new (ID, TPL_ENTITY_CONTACT, NULL, NULL);
  date = g_date_new_dmy (13, 1, 2010);

  tpl_log_manager_get_filtered_events_async (fixture->manager,
      fixture->account,
      entity,
      TPL_EVENT_MASK_TEXT,
      11,
      events_filter,
      date,
      get_filtered_events_cb,
      fixture);
  g_main_loop_run (fixture->main_loop);

  g_object_unref (entity);
  g_date_free (date);

  /* We got 6 events in old Empathy and 6 in new TpLogger storage,
   * but we limited to 11 */
  g_assert_cmpint (g_list_length (fixture->ret), ==, 11);

  g_list_foreach (fixture->ret, (GFunc) g_object_unref, NULL);
  g_list_free (fixture->ret);
}


static void
get_entities_37288_cb (GObject *object,
    GAsyncResult *result,
    gpointer user_data)
{
  TestCaseFixture *fixture = user_data;
  GError *error = NULL;

  tpl_log_manager_get_entities_finish (TPL_LOG_MANAGER (object), result,
      NULL, &error);

  g_assert_no_error (error);
  g_main_loop_quit (fixture->main_loop);
}


static void
get_entities_cb (GObject *object,
    GAsyncResult *result,
    gpointer user_data)
{
  TestCaseFixture *fixture = user_data;
  GError *error = NULL;

  tpl_log_manager_get_entities_finish (TPL_LOG_MANAGER (object), result,
      &fixture->ret, &error);

  g_assert_no_error (error);
  g_main_loop_quit (fixture->main_loop);
}


static void
test_get_entities (TestCaseFixture *fixture,
    gconstpointer user_data)
{
  GList *loc;

  tpl_log_manager_get_entities_async (fixture->manager, fixture->account,
      get_entities_cb, fixture);
  g_main_loop_run (fixture->main_loop);

  g_assert_cmpint (g_list_length (fixture->ret), ==, 5);

  /* we do not want duplicates */
  fixture->ret = g_list_sort (fixture->ret, (GCompareFunc) _tpl_entity_compare);
  for (loc = fixture->ret; loc != NULL; loc = g_list_next (loc))
    if (loc->next)
      g_assert (_tpl_entity_compare (loc->data, loc->next->data) != 0);

  g_list_foreach (fixture->ret, (GFunc) g_object_unref, NULL);
  g_list_free (fixture->ret);

  /* Check that the GSimpleAsyncResult res_gpointer's GDestroyNotify func
   * is the appropriate one.
   * Reproduces: https://bugs.freedesktop.org/show_bug.cgi?id=37288 */
  tpl_log_manager_get_entities_async (fixture->manager, fixture->account,
      get_entities_37288_cb, fixture);
  g_main_loop_run (fixture->main_loop);
}


static void
search_cb (GObject *object,
    GAsyncResult *result,
    gpointer user_data)
{
  TestCaseFixture *fixture = user_data;
  GError *error = NULL;

  tpl_log_manager_search_finish (TPL_LOG_MANAGER (object),
      result, &fixture->ret, &error);

  g_assert_no_error (error);
  g_main_loop_quit (fixture->main_loop);
}


static void
test_search (TestCaseFixture *fixture,
    gconstpointer user_data)
{
  tpl_log_manager_search_async (fixture->manager,
      "user2@collabora.co.uk",
      TPL_EVENT_MASK_TEXT,
      search_cb,
      fixture);
  g_main_loop_run (fixture->main_loop);

  /* We got 4 events in old Empathy, 4 in new TpLogger and
   * 2 in Pidgin storage */
  g_assert_cmpint (g_list_length (fixture->ret), ==, 10);

  tpl_log_manager_search_free (fixture->ret);
  fixture->ret = NULL;
}

static gboolean
check_ignored_messages (TestCaseFixture *fixture,
    TplTextEvent *event,
    gboolean should_exist)
{
  TplEntity *entity;
  GList *iter;
  GDate *date;

  g_object_get (event, "sender", &entity, NULL);
  date = g_date_new_dmy (1, 1, 1970);
  tpl_log_manager_get_events_for_date_async (
      fixture->manager,
      fixture->account,
      entity,
      TPL_EVENT_MASK_ANY,
      date,
      get_events_for_date_cb,
      fixture);
  g_main_loop_run (fixture->main_loop);

  for (iter = fixture->ret; iter; iter = g_list_next (iter)) {
      TplEvent *found_event = iter->data;
      gchar *result_token, *ref_token;
      gboolean exists;

      g_object_get (G_OBJECT (found_event), "message-token", &result_token, NULL);
      g_object_get (G_OBJECT (event), "message-token", &ref_token, NULL);
      exists = (g_strcmp0 (result_token, ref_token) == 0);

      if (should_exist != exists) {
        g_list_free_full (fixture->ret, g_object_unref);
        return FALSE;
      }
  }

  g_list_free_full (fixture->ret, g_object_unref);

  return TRUE;
}

static void
test_ignorelist (TestCaseFixture *fixture,
    gconstpointer user_data)
{
  TplTextEvent *event1, *event2;
  TplEntity *receiver, *sender;
  TplConf *conf;
  gboolean passed;

  receiver = tpl_entity_new ("ignoreduser1@collabora.co.uk", TPL_ENTITY_CONTACT, "Me", "no-avatar");
  sender = tpl_entity_new ("ignoreduser2@collabora.co.uk", TPL_ENTITY_CONTACT, "Someone Else", "no-avatar");

  event1 = g_object_new (TPL_TYPE_TEXT_EVENT,
    "account", fixture->account,
    "channel-path", "org.freedesktop.Telepathy.channel.path",
    "receiver", receiver,
    "sender", sender,
    "timestamp", (gint64) 1,
    "message-token", "1234",
    "supersedes-token", "5678",
    "edit-timestamp", 0,
    "message-type", TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
    "message", "Test 1",
    NULL);

  event2 = g_object_new (TPL_TYPE_TEXT_EVENT,
    "account", fixture->account,
    "channel-path", "org.freedesktop.Telepathy.channel.path",
    "receiver", sender,
    "sender", receiver,
    "timestamp", (gint64) 2,
    "message-token", "5678",
    "supersedes-token", "9012",
    "edit-timestamp", 0,
    "message-type", TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
    "message", "Test 2",
    NULL);

  conf = _tpl_conf_dup ();

  /* Ignore messages from both */
  tpl_log_manager_disable_for_entity (fixture->manager, fixture->account, receiver);
  tpl_log_manager_disable_for_entity (fixture->manager, fixture->account, sender);
  g_assert (tpl_log_manager_is_disabled_for_entity (fixture->manager, fixture->account, receiver));
  g_assert (tpl_log_manager_is_disabled_for_entity (fixture->manager, fixture->account, sender));

  _tpl_log_manager_add_event (fixture->manager, TPL_EVENT (event1), NULL);
  _tpl_log_manager_add_event (fixture->manager, TPL_EVENT (event2), NULL);

  passed = check_ignored_messages (fixture, event1, FALSE);
  if (!passed) {
    _tpl_log_manager_clear_entity (fixture->manager, fixture->account, sender);
    _tpl_log_manager_clear_entity (fixture->manager, fixture->account, receiver);
    g_assert (passed);
  }

  passed = check_ignored_messages (fixture, event2, FALSE);
  _tpl_log_manager_clear_entity (fixture->manager, fixture->account, sender);
  _tpl_log_manager_clear_entity (fixture->manager, fixture->account, receiver);
  if (!passed) {
    g_assert (passed);
  }

  /* Ignore message only from ignoreduser1 */
  tpl_log_manager_enable_for_entity (fixture->manager, fixture->account, sender);
  g_assert (!tpl_log_manager_is_disabled_for_entity (fixture->manager, fixture->account, sender));
  g_assert (tpl_log_manager_is_disabled_for_entity (fixture->manager, fixture->account, receiver));
  _tpl_log_manager_add_event (fixture->manager, TPL_EVENT (event1), NULL);
  _tpl_log_manager_add_event (fixture->manager, TPL_EVENT (event2), NULL);

  passed = check_ignored_messages (fixture, event1, FALSE);
  if (!passed) {
    _tpl_log_manager_clear_entity (fixture->manager, fixture->account, sender);
    _tpl_log_manager_clear_entity (fixture->manager, fixture->account, receiver);
    g_assert (passed);
  }

  passed = check_ignored_messages (fixture, event2, TRUE);
  _tpl_log_manager_clear_entity (fixture->manager, fixture->account, sender);
  _tpl_log_manager_clear_entity (fixture->manager, fixture->account, receiver);
  if (!passed) {
    g_assert (passed);
  }

  /* Don't ignore any message */
  tpl_log_manager_enable_for_entity (fixture->manager, fixture->account, receiver);
  g_assert (!tpl_log_manager_is_disabled_for_entity (fixture->manager, fixture->account, sender));
  g_assert (!tpl_log_manager_is_disabled_for_entity (fixture->manager, fixture->account, receiver));
  _tpl_log_manager_add_event (fixture->manager, TPL_EVENT (event1), NULL);

  passed = check_ignored_messages (fixture, event1, TRUE);
  _tpl_log_manager_clear_entity (fixture->manager, fixture->account, sender);
  _tpl_log_manager_clear_entity (fixture->manager, fixture->account, receiver);
  if (!passed) {
    g_assert (passed);
  }

  g_object_unref (conf);
  g_object_unref (event1);
  g_object_unref (event2);
  g_object_unref (sender);
  g_object_unref (receiver);
}

int
main (int argc, char **argv)
{
  GHashTable *params = NULL;
  GList *l = NULL;
  int retval;

  g_type_init ();

  setup_debug ();

  /* no account tests */
  g_test_init (&argc, &argv, NULL);
  g_test_bug_base ("http://bugs.freedesktop.org/show_bug.cgi?id=");

  /* account related tests */
  params = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
      (GDestroyNotify) tp_g_value_slice_free);
  g_assert (params != NULL);

  l = g_list_prepend (l, params);

  g_hash_table_insert (params, "account",
      tp_g_value_slice_new_static_string (MY_ID));
  g_hash_table_insert (params, "account-path",
      tp_g_value_slice_new_static_string (ACCOUNT_PATH_JABBER));

  g_test_add ("/log-manager/exists",
      TestCaseFixture, params,
      setup, test_exists, teardown);

  g_test_add ("/log-manager/get-dates",
      TestCaseFixture, params,
      setup, test_get_dates, teardown);

  g_test_add ("/log-manager/get-events-for-date",
      TestCaseFixture, params,
      setup, test_get_events_for_date, teardown);

  g_test_add ("/log-manager/get-events-for-date-account-unprepared",
      TestCaseFixture, params,
      setup, test_get_events_for_date_account_unprepared, teardown);

  g_test_add ("/log-manager/get-filtered-events",
      TestCaseFixture, params,
      setup, test_get_filtered_events, teardown);

  g_test_add ("/log-manager/get-entities",
      TestCaseFixture, params,
      setup, test_get_entities, teardown);

  g_test_add ("/log-manager/search",
      TestCaseFixture, params,
      setup, test_search, teardown);

  g_test_add ("/log-manager/ignorelist",
      TestCaseFixture, params,
      setup_for_writing, test_ignorelist, teardown);

  retval = g_test_run ();

  g_list_foreach (l, (GFunc) g_hash_table_unref, NULL);

  return retval;
}