]> git.0d.be Git - empathy.git/blob - tests/check-empathy-chatroom-manager.c
factor out check_chatroom
[empathy.git] / tests / check-empathy-chatroom-manager.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <glib/gstdio.h>
5
6 #include <gconf/gconf.h>
7 #include <gconf/gconf-client.h>
8 #include <telepathy-glib/util.h>
9 #include <check.h>
10
11 #include "check-helpers.h"
12 #include "check-libempathy.h"
13 #include "check-empathy-helpers.h"
14
15 #include <libempathy/empathy-chatroom-manager.h>
16
17 #define CHATROOM_SAMPLE "chatrooms-sample.xml"
18 #define CHATROOM_FILE "chatrooms.xml"
19
20 static void
21 check_chatroom (EmpathyChatroom *chatroom,
22                 const gchar *name,
23                 const gchar *room,
24                 gboolean auto_connect,
25                 gboolean favorite)
26 {
27   gboolean _favorite;
28
29   fail_if (tp_strdiff (empathy_chatroom_get_name (chatroom), name));
30   fail_if (tp_strdiff (empathy_chatroom_get_room (chatroom), room));
31   fail_if (empathy_chatroom_get_auto_connect (chatroom) != auto_connect);
32   g_object_get (chatroom, "favorite", &_favorite, NULL);
33   fail_if (favorite != _favorite);
34 }
35
36 START_TEST (test_empathy_chatroom_manager_new)
37 {
38   EmpathyChatroomManager *mgr;
39   gchar *cmd;
40   gchar *file;
41   McAccount *account;
42   GList *chatrooms, *l;
43   gboolean room1_found, room2_found;
44
45   account = create_test_account ();
46
47   copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
48
49   file = get_user_xml_file (CHATROOM_FILE);
50   /* change the chatrooms XML file to use the account we just created */
51   cmd = g_strdup_printf ("sed -i 's/CHANGE_ME/%s/' %s",
52       mc_account_get_unique_name (account), file);
53   system (cmd);
54   g_free (cmd);
55
56   mgr = empathy_chatroom_manager_new (file);
57
58   fail_if (empathy_chatroom_manager_get_count (mgr, account) != 2);
59
60   chatrooms = empathy_chatroom_manager_get_chatrooms (mgr, account);
61   fail_if (g_list_length (chatrooms) != 2);
62
63   room1_found = room2_found = FALSE;
64   for (l = chatrooms; l != NULL; l = g_list_next (l))
65     {
66       EmpathyChatroom *chatroom = l->data;
67
68       if (!tp_strdiff (empathy_chatroom_get_room (chatroom), "room1"))
69         {
70           room1_found = TRUE;
71           check_chatroom (chatroom, "name1", "room1", TRUE, TRUE);
72         }
73       else if (!tp_strdiff (empathy_chatroom_get_room (chatroom), "room2"))
74         {
75           room2_found = TRUE;
76           check_chatroom (chatroom, "name2", "room2", FALSE, TRUE);
77         }
78       else
79         {
80           g_assert_not_reached ();
81         }
82     }
83
84   fail_if (!room1_found || !room2_found);
85
86   g_free (file);
87   g_object_unref (mgr);
88   destroy_test_account (account);
89 }
90 END_TEST
91
92 TCase *
93 make_empathy_chatroom_manager_tcase (void)
94 {
95     TCase *tc = tcase_create ("empathy-chatroom-manager");
96     tcase_add_test (tc, test_empathy_chatroom_manager_new);
97     return tc;
98 }