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