Update python binding
[empathy.git] / tests / check-empathy-chatroom.c
bloba4adf6ce1be62aa7f93c936bf89bce147df7e49f
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
5 #include <check.h>
6 #include "check-helpers.h"
7 #include "check-libempathy.h"
8 #include "check-empathy-helpers.h"
10 #include <libempathy/empathy-chatroom.h>
12 static EmpathyChatroom *
13 create_chatroom (void)
15 McAccount *account;
16 EmpathyChatroom *chatroom;
18 account = get_test_account ();
19 chatroom = empathy_chatroom_new (account);
20 fail_if (chatroom == NULL);
22 return chatroom;
25 START_TEST (test_empathy_chatroom_new)
27 EmpathyChatroom *chatroom;
28 gboolean auto_connect, favorite;
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);
39 g_object_unref (empathy_chatroom_get_account (chatroom));
40 g_object_unref (chatroom);
42 END_TEST
44 START_TEST (test_favorite_and_auto_connect)
46 /* auto connect implies favorite */
47 EmpathyChatroom *chatroom;
48 gboolean auto_connect, favorite;
50 chatroom = create_chatroom ();
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);
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);
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);
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);
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);
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);
112 g_object_unref (empathy_chatroom_get_account (chatroom));
113 g_object_unref (chatroom);
115 END_TEST
117 static void
118 favorite_changed (EmpathyChatroom *chatroom,
119 GParamSpec *spec,
120 gboolean *changed)
122 *changed = TRUE;
125 START_TEST (test_change_favorite)
127 EmpathyChatroom *chatroom;
128 gboolean changed = FALSE;
130 chatroom = create_chatroom ();
132 g_signal_connect (chatroom, "notify::favorite", G_CALLBACK (favorite_changed),
133 &changed);
135 /* change favorite to TRUE */
136 g_object_set (chatroom, "favorite", TRUE, NULL);
137 fail_if (!changed);
139 changed = FALSE;
141 /* change favorite to FALSE */
142 g_object_set (chatroom, "favorite", FALSE, NULL);
143 fail_if (!changed);
145 END_TEST
147 TCase *
148 make_empathy_chatroom_tcase (void)
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;