]> git.0d.be Git - empathy.git/blob - tests/check-empathy-chatroom.c
Updated Basque translation.
[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 #include "check-empathy-helpers.h"
9
10 #include <libempathy/empathy-chatroom.h>
11
12 static EmpathyChatroom *
13 create_chatroom (void)
14 {
15   McAccount *account;
16   EmpathyChatroom *chatroom;
17
18   account = get_test_account ();
19   chatroom = empathy_chatroom_new (account);
20   fail_if (chatroom == NULL);
21
22   return chatroom;
23 }
24
25 START_TEST (test_empathy_chatroom_new)
26 {
27   EmpathyChatroom *chatroom;
28   gboolean auto_connect, favorite;
29
30   chatroom = create_chatroom ();
31   fail_if (empathy_chatroom_get_auto_connect (chatroom));
32   g_object_get (chatroom,
33       "auto_connect", &auto_connect,
34       "favorite", &favorite,
35       NULL);
36   fail_if (auto_connect);
37   fail_if (favorite);
38
39   g_object_unref (empathy_chatroom_get_account (chatroom));
40   g_object_unref (chatroom);
41 }
42 END_TEST
43
44 START_TEST (test_favorite_and_auto_connect)
45 {
46   /* auto connect implies favorite */
47   EmpathyChatroom *chatroom;
48   gboolean auto_connect, favorite;
49
50   chatroom = create_chatroom ();
51
52   /* set auto_connect so favorite as a side effect */
53   empathy_chatroom_set_auto_connect (chatroom, TRUE);
54   fail_if (!empathy_chatroom_get_auto_connect (chatroom));
55   g_object_get (chatroom,
56       "auto_connect", &auto_connect,
57       "favorite", &favorite,
58       NULL);
59   fail_if (!auto_connect);
60   fail_if (!favorite);
61
62   /* Remove auto_connect. Chatroom is still favorite */
63   empathy_chatroom_set_auto_connect (chatroom, FALSE);
64   fail_if (empathy_chatroom_get_auto_connect (chatroom));
65   g_object_get (chatroom,
66       "auto_connect", &auto_connect,
67       "favorite", &favorite,
68       NULL);
69   fail_if (auto_connect);
70   fail_if (!favorite);
71
72   /* Remove favorite too now */
73   g_object_set (chatroom, "favorite", FALSE, NULL);
74   fail_if (empathy_chatroom_get_auto_connect (chatroom));
75   g_object_get (chatroom,
76       "auto_connect", &auto_connect,
77       "favorite", &favorite,
78       NULL);
79   fail_if (auto_connect);
80   fail_if (favorite);
81
82   /* Just add favorite but not auto-connect */
83   g_object_set (chatroom, "favorite", TRUE, NULL);
84   fail_if (empathy_chatroom_get_auto_connect (chatroom));
85   g_object_get (chatroom,
86       "auto_connect", &auto_connect,
87       "favorite", &favorite,
88       NULL);
89   fail_if (auto_connect);
90   fail_if (!favorite);
91
92   /* ... and re-add auto_connect */
93   g_object_set (chatroom, "auto_connect", TRUE, NULL);
94   fail_if (!empathy_chatroom_get_auto_connect (chatroom));
95   g_object_get (chatroom,
96       "auto_connect", &auto_connect,
97       "favorite", &favorite,
98       NULL);
99   fail_if (!auto_connect);
100   fail_if (!favorite);
101
102   /* Remove favorite remove auto_connect too */
103   g_object_set (chatroom, "favorite", FALSE, NULL);
104   fail_if (empathy_chatroom_get_auto_connect (chatroom));
105   g_object_get (chatroom,
106       "auto_connect", &auto_connect,
107       "favorite", &favorite,
108       NULL);
109   fail_if (auto_connect);
110   fail_if (favorite);
111
112   g_object_unref (empathy_chatroom_get_account (chatroom));
113   g_object_unref (chatroom);
114 }
115 END_TEST
116
117 static void
118 favorite_changed (EmpathyChatroom *chatroom,
119                   GParamSpec *spec,
120                   gboolean *changed)
121 {
122   *changed = TRUE;
123 }
124
125 START_TEST (test_change_favorite)
126 {
127   EmpathyChatroom *chatroom;
128   gboolean changed = FALSE;
129
130   chatroom = create_chatroom ();
131
132   g_signal_connect (chatroom, "notify::favorite", G_CALLBACK (favorite_changed),
133       &changed);
134
135   /* change favorite to TRUE */
136   g_object_set (chatroom, "favorite", TRUE, NULL);
137   fail_if (!changed);
138
139   changed = FALSE;
140
141   /* change favorite to FALSE */
142   g_object_set (chatroom, "favorite", FALSE, NULL);
143   fail_if (!changed);
144 }
145 END_TEST
146
147 TCase *
148 make_empathy_chatroom_tcase (void)
149 {
150     TCase *tc = tcase_create ("empathy-chatroom");
151     tcase_add_test (tc, test_empathy_chatroom_new);
152     tcase_add_test (tc, test_favorite_and_auto_connect);
153     tcase_add_test (tc, test_change_favorite);
154     return tc;
155 }