]> git.0d.be Git - empathy.git/blob - tests/check-empathy-chatroom-manager.c
test chatroom xml parsing
[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 START_TEST (test_empathy_chatroom_manager_new)
21 {
22   EmpathyChatroomManager *mgr;
23   gchar *cmd;
24   gchar *file;
25   McAccount *account;
26   GList *chatrooms, *l;
27   gboolean room1_found, room2_found;
28
29   account = create_test_account ();
30
31   copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
32
33   file = get_user_xml_file (CHATROOM_FILE);
34   /* change the chatrooms XML file to use the account we just created */
35   cmd = g_strdup_printf ("sed -i 's/CHANGE_ME/%s/' %s",
36       mc_account_get_unique_name (account), file);
37   system (cmd);
38   g_free (cmd);
39
40   mgr = empathy_chatroom_manager_new (file);
41
42   fail_if (empathy_chatroom_manager_get_count (mgr, account) != 2);
43
44   chatrooms = empathy_chatroom_manager_get_chatrooms (mgr, account);
45   fail_if (g_list_length (chatrooms) != 2);
46
47   room1_found = room2_found = FALSE;
48   for (l = chatrooms; l != NULL; l = g_list_next (l))
49     {
50       EmpathyChatroom *chatroom = l->data;
51       gboolean favorite;
52
53       if (!tp_strdiff (empathy_chatroom_get_room (chatroom), "room1"))
54         {
55           room1_found = TRUE;
56           fail_if (tp_strdiff (empathy_chatroom_get_name (chatroom), "name1"));
57           fail_if (!empathy_chatroom_get_auto_connect (chatroom));
58           g_object_get (chatroom, "favorite", &favorite, NULL);
59           fail_if (!favorite);
60         }
61       else if (!tp_strdiff (empathy_chatroom_get_room (chatroom), "room2"))
62         {
63           room2_found = TRUE;
64           fail_if (tp_strdiff (empathy_chatroom_get_name (chatroom), "name2"));
65           fail_if (empathy_chatroom_get_auto_connect (chatroom));
66           g_object_get (chatroom, "favorite", &favorite, NULL);
67           fail_if (!favorite);
68         }
69       else
70         {
71           g_assert_not_reached ();
72         }
73     }
74
75   fail_if (!room1_found || !room2_found);
76
77   g_free (file);
78   g_object_unref (mgr);
79   destroy_test_account (account);
80 }
81 END_TEST
82
83 TCase *
84 make_empathy_chatroom_manager_tcase (void)
85 {
86     TCase *tc = tcase_create ("empathy-chatroom-manager");
87     tcase_add_test (tc, test_empathy_chatroom_manager_new);
88     return tc;
89 }