]> git.0d.be Git - empathy.git/blob - tests/check-empathy-chatroom-manager.c
factor out check_chatrooms_list
[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 struct chatroom_t
37 {
38   gchar *name;
39   gchar *room;
40   gboolean auto_connect;
41   gboolean favorite;
42 };
43
44 static void
45 check_chatrooms_list (EmpathyChatroomManager *mgr,
46                       McAccount *account,
47                       struct chatroom_t *_chatrooms,
48                       guint nb_chatrooms)
49 {
50   GList *chatrooms, *l;
51   guint i;
52
53   fail_if (empathy_chatroom_manager_get_count (mgr, account) != nb_chatrooms);
54
55   chatrooms = empathy_chatroom_manager_get_chatrooms (mgr, account);
56   fail_if (g_list_length (chatrooms) != nb_chatrooms);
57
58   for (l = chatrooms, i = 0; l != NULL; l = g_list_next (l), i++)
59     {
60       EmpathyChatroom *chatroom = l->data;
61
62       check_chatroom (chatroom, _chatrooms[i].name, _chatrooms[i].room,
63           _chatrooms[i].auto_connect, _chatrooms[i].favorite);
64     }
65 }
66
67 START_TEST (test_empathy_chatroom_manager_new)
68 {
69   EmpathyChatroomManager *mgr;
70   gchar *cmd;
71   gchar *file;
72   McAccount *account;
73   struct chatroom_t chatrooms[] = {
74         { "name2", "room2", FALSE, TRUE },
75         { "name1", "room1", TRUE, TRUE }};
76
77   account = create_test_account ();
78
79   copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
80
81   file = get_user_xml_file (CHATROOM_FILE);
82   /* change the chatrooms XML file to use the account we just created */
83   cmd = g_strdup_printf ("sed -i 's/CHANGE_ME/%s/' %s",
84       mc_account_get_unique_name (account), file);
85   system (cmd);
86   g_free (cmd);
87
88   mgr = empathy_chatroom_manager_new (file);
89   check_chatrooms_list (mgr, account, chatrooms, 2);
90
91   g_free (file);
92   g_object_unref (mgr);
93   destroy_test_account (account);
94 }
95 END_TEST
96
97 TCase *
98 make_empathy_chatroom_manager_tcase (void)
99 {
100     TCase *tc = tcase_create ("empathy-chatroom-manager");
101     tcase_add_test (tc, test_empathy_chatroom_manager_new);
102     return tc;
103 }