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