5 #include "test-helper.h"
7 #include <libempathy/empathy-chatroom.h>
10 static EmpathyChatroom
*
11 create_chatroom (void)
13 EmpathyAccount
*account
;
14 EmpathyChatroom
*chatroom
;
16 account
= get_test_account ();
17 chatroom
= empathy_chatroom_new (account
);
18 fail_if (chatroom
== NULL
);
23 START_TEST (test_empathy_chatroom_new
)
25 EmpathyChatroom
*chatroom
;
26 gboolean auto_connect
, favorite
;
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
,
34 fail_if (auto_connect
);
37 g_object_unref (empathy_chatroom_get_account (chatroom
));
38 g_object_unref (chatroom
);
42 START_TEST (test_favorite_and_auto_connect
)
44 /* auto connect implies favorite */
45 EmpathyChatroom
*chatroom
;
46 gboolean auto_connect
, favorite
;
48 chatroom
= create_chatroom ();
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
,
57 fail_if (!auto_connect
);
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
,
67 fail_if (auto_connect
);
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
,
77 fail_if (auto_connect
);
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
,
87 fail_if (auto_connect
);
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
,
97 fail_if (!auto_connect
);
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
,
107 fail_if (auto_connect
);
110 g_object_unref (empathy_chatroom_get_account (chatroom
));
111 g_object_unref (chatroom
);
116 favorite_changed (EmpathyChatroom
*chatroom
,
123 START_TEST (test_change_favorite
)
125 EmpathyChatroom
*chatroom
;
126 gboolean changed
= FALSE
;
128 chatroom
= create_chatroom ();
130 g_signal_connect (chatroom
, "notify::favorite", G_CALLBACK (favorite_changed
),
133 /* change favorite to TRUE */
134 g_object_set (chatroom
, "favorite", TRUE
, NULL
);
139 /* change favorite to FALSE */
140 g_object_set (chatroom
, "favorite", FALSE
, NULL
);
152 test_init (argc
, argv
);
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
);
161 result
= g_test_run ();