]> git.0d.be Git - empathy.git/blob - tests/check-empathy-chatroom.c
add remove_account_from_gconf to check-helpers
[empathy.git] / tests / check-empathy-chatroom.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4
5 #include <check.h>
6 #include "check-helpers.h"
7 #include "check-libempathy.h"
8
9 #include <libempathy/empathy-chatroom.h>
10
11 static EmpathyChatroom *
12 create_chatroom (void)
13 {
14   McProfile *profile;
15   McAccount *account;
16   EmpathyChatroom *chatroom;
17
18   profile = mc_profile_lookup ("test");
19   account = mc_account_create (profile);
20   chatroom = empathy_chatroom_new (account);
21   fail_if (chatroom == NULL);
22
23   /* destroy the account as we don't have to add it to the accounts
24    * configuration */
25   /* FIXME: the account is not really removed */
26   mc_account_delete (account);
27   g_object_unref (profile);
28   g_object_unref (account);
29
30   return chatroom;
31 }
32
33 START_TEST (test_empathy_chatroom_new)
34 {
35   EmpathyChatroom *chatroom;
36   gboolean auto_connect, favorite;
37
38   chatroom = create_chatroom ();
39   fail_if (empathy_chatroom_get_auto_connect (chatroom));
40   g_object_get (chatroom,
41       "auto_connect", &auto_connect,
42       "favorite", &favorite,
43       NULL);
44   fail_if (auto_connect);
45   fail_if (favorite);
46
47   g_object_unref (chatroom);
48 }
49 END_TEST
50
51 START_TEST (test_favorite_and_auto_connect)
52 {
53   /* auto connect implies favorite */
54   EmpathyChatroom *chatroom;
55   gboolean auto_connect, favorite;
56
57   chatroom = create_chatroom ();
58
59   /* set auto_connect so favorite as a side effect */
60   empathy_chatroom_set_auto_connect (chatroom, TRUE);
61   fail_if (!empathy_chatroom_get_auto_connect (chatroom));
62   g_object_get (chatroom,
63       "auto_connect", &auto_connect,
64       "favorite", &favorite,
65       NULL);
66   fail_if (!auto_connect);
67   fail_if (!favorite);
68
69   /* Remove auto_connect. Chatroom is still favorite */
70   empathy_chatroom_set_auto_connect (chatroom, FALSE);
71   fail_if (empathy_chatroom_get_auto_connect (chatroom));
72   g_object_get (chatroom,
73       "auto_connect", &auto_connect,
74       "favorite", &favorite,
75       NULL);
76   fail_if (auto_connect);
77   fail_if (!favorite);
78
79   /* Remove favorite too now */
80   g_object_set (chatroom, "favorite", FALSE, NULL);
81   fail_if (empathy_chatroom_get_auto_connect (chatroom));
82   g_object_get (chatroom,
83       "auto_connect", &auto_connect,
84       "favorite", &favorite,
85       NULL);
86   fail_if (auto_connect);
87   fail_if (favorite);
88
89   /* Just add favorite but not auto-connect */
90   g_object_set (chatroom, "favorite", TRUE, NULL);
91   fail_if (empathy_chatroom_get_auto_connect (chatroom));
92   g_object_get (chatroom,
93       "auto_connect", &auto_connect,
94       "favorite", &favorite,
95       NULL);
96   fail_if (auto_connect);
97   fail_if (!favorite);
98
99   /* ... and re-add auto_connect */
100   g_object_set (chatroom, "auto_connect", TRUE, NULL);
101   fail_if (!empathy_chatroom_get_auto_connect (chatroom));
102   g_object_get (chatroom,
103       "auto_connect", &auto_connect,
104       "favorite", &favorite,
105       NULL);
106   fail_if (!auto_connect);
107   fail_if (!favorite);
108
109   /* Remove favorite remove auto_connect too */
110   g_object_set (chatroom, "favorite", FALSE, NULL);
111   fail_if (empathy_chatroom_get_auto_connect (chatroom));
112   g_object_get (chatroom,
113       "auto_connect", &auto_connect,
114       "favorite", &favorite,
115       NULL);
116   fail_if (auto_connect);
117   fail_if (favorite);
118
119   g_object_unref (chatroom);
120 }
121 END_TEST
122
123 TCase *
124 make_empathy_chatroom_tcase (void)
125 {
126     TCase *tc = tcase_create ("empathy-chatroom");
127     tcase_add_test (tc, test_empathy_chatroom_new);
128     tcase_add_test (tc, test_favorite_and_auto_connect);
129     return tc;
130 }