libpurple/tests/test_conversation_member.c

changeset 42113
393c2ea6b399
parent 42080
df47db24cee6
child 42779
365eaa9d46f8
equal deleted inserted replaced
42112:86e0a26348a1 42113:393c2ea6b399
42 test_purple_conversation_member_properties(void) { 42 test_purple_conversation_member_properties(void) {
43 PurpleContactInfo *info = NULL; 43 PurpleContactInfo *info = NULL;
44 PurpleContactInfo *info1 = NULL; 44 PurpleContactInfo *info1 = NULL;
45 PurpleConversationMember *member = NULL; 45 PurpleConversationMember *member = NULL;
46 PurpleTags *tags = NULL; 46 PurpleTags *tags = NULL;
47 PurpleTypingState typing_state = PURPLE_TYPING_STATE_NONE;
47 48
48 info = purple_contact_info_new("abc123"); 49 info = purple_contact_info_new("abc123");
49 50
50 /* Use g_object_new so we can test setting properties by name. All of them 51 /* Use g_object_new so we can test setting properties by name. All of them
51 * call the setter methods, so by doing it this way we exercise more of the 52 * call the setter methods, so by doing it this way we exercise more of the
52 * code. 53 * code.
53 */ 54 */
54 member = g_object_new( 55 member = g_object_new(
55 PURPLE_TYPE_CONVERSATION_MEMBER, 56 PURPLE_TYPE_CONVERSATION_MEMBER,
56 "contact-info", info, 57 "contact-info", info,
58 "typing-state", PURPLE_TYPING_STATE_TYPING,
57 NULL); 59 NULL);
58 60
59 /* Now use g_object_get to read all of the properties. */ 61 /* Now use g_object_get to read all of the properties. */
60 g_object_get(member, 62 g_object_get(member,
61 "contact-info", &info1, 63 "contact-info", &info1,
62 "tags", &tags, 64 "tags", &tags,
65 "typing-state", &typing_state,
63 NULL); 66 NULL);
64 67
65 /* Compare all the things. */ 68 /* Compare all the things. */
66 g_assert_true(info1 == info); 69 g_assert_true(info1 == info);
67 g_assert_true(PURPLE_IS_TAGS(tags)); 70 g_assert_true(PURPLE_IS_TAGS(tags));
71 g_assert_cmpint(typing_state, ==, PURPLE_TYPING_STATE_TYPING);
68 72
69 /* Free/unref all the things. */ 73 /* Free/unref all the things. */
70 g_clear_object(&info1); 74 g_clear_object(&info1);
71 g_clear_object(&tags); 75 g_clear_object(&tags);
72 76
77 g_clear_object(&info);
78 g_clear_object(&member);
79 }
80
81 /******************************************************************************
82 * Typing State Timeout
83 *****************************************************************************/
84 static void
85 test_purple_conversation_manager_timeout_notify(G_GNUC_UNUSED GObject *obj,
86 G_GNUC_UNUSED GParamSpec *pspec,
87 gpointer data)
88 {
89 GMainLoop *loop = data;
90 static guint count = 0;
91
92 /* Increment count each time we're called. We're expecting to be called
93 * twice, so after that quit the main loop.
94 */
95 count++;
96 if(count >= 2) {
97 g_main_loop_quit(loop);
98 }
99 }
100
101 static gboolean
102 test_purple_conversation_manager_timeout_fail_safe(gpointer data) {
103 GMainLoop *loop = data;
104
105 g_warning("fail safe triggered");
106
107 g_main_loop_quit(loop);
108
109 return G_SOURCE_REMOVE;
110 }
111
112 static void
113 test_purple_conversation_member_typing_state_timeout(void) {
114 PurpleContactInfo *info = NULL;
115 PurpleConversationMember *member = NULL;
116 PurpleTypingState typing_state = PURPLE_TYPING_STATE_TYPING;
117 GMainLoop *loop = NULL;
118
119 /* Create the main loop as we'll need it to let the timeout fire. */
120 loop = g_main_loop_new(NULL, FALSE);
121
122 /* Create the member and add a notify callback on the typing-state property
123 * so we can check it and exit the main loop.
124 */
125 info = purple_contact_info_new(NULL);
126 member = purple_conversation_member_new(info);
127 g_signal_connect(member, "notify::typing-state",
128 G_CALLBACK(test_purple_conversation_manager_timeout_notify),
129 loop);
130
131 /* Set the state to typing with a timeout of 1 second. */
132 purple_conversation_member_set_typing_state(member,
133 PURPLE_TYPING_STATE_TYPING, 1);
134
135 /* Add a fail safe timeout at 2 seconds to make sure the test won't get
136 * stuck waiting forever.
137 */
138 g_timeout_add_seconds(2,
139 test_purple_conversation_manager_timeout_fail_safe,
140 loop);
141
142 /* Run the main loop and let the timeouts fire. */
143 g_main_loop_run(loop);
144
145 /* Verify that our state got reset back to PURPLE_TYPING_STATE_NONE. */
146 typing_state = purple_conversation_member_get_typing_state(member);
147 g_assert_cmpint(typing_state, ==, PURPLE_TYPING_STATE_NONE);
148
149 /* Clean everything up. */
73 g_clear_object(&info); 150 g_clear_object(&info);
74 g_clear_object(&member); 151 g_clear_object(&member);
75 } 152 }
76 153
77 /****************************************************************************** 154 /******************************************************************************
84 g_test_add_func("/conversation-member/new", 161 g_test_add_func("/conversation-member/new",
85 test_purple_conversation_member_new); 162 test_purple_conversation_member_new);
86 g_test_add_func("/conversation-member/properties", 163 g_test_add_func("/conversation-member/properties",
87 test_purple_conversation_member_properties); 164 test_purple_conversation_member_properties);
88 165
166 g_test_add_func("/conversation-member/typing-state/timeout",
167 test_purple_conversation_member_typing_state_timeout);
168
89 return g_test_run(); 169 return g_test_run();
90 } 170 }

mercurial