Add some tests for message callbacks, and fix all the things.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3688 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2021-11-17 23:47:55 +00:00
parent 9e1bab03eb
commit 00c1ec660e
3 changed files with 38 additions and 6 deletions

View File

@ -69,6 +69,11 @@ static int _ssb_test_count_messages(tf_ssb_t* ssb)
return count;
}
static void _message_added(tf_ssb_t* ssb, const char* id, void* user_data)
{
++*(int*)user_data;
}
void tf_ssb_test_ssb(const tf_test_options_t* options)
{
printf("Testing SSB.\n");
@ -153,6 +158,25 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
{
uv_run(&loop, UV_RUN_ONCE);
}
printf("Waiting for message to self.\n");
int count0 = 0;
int count1 = 0;
tf_ssb_add_message_added_callback(ssb0, _message_added, NULL, &count0);
tf_ssb_add_message_added_callback(ssb1, _message_added, NULL, &count1);
tf_ssb_append_post(ssb0, "Message to self.");
while (count0 == 0)
{
uv_run(&loop, UV_RUN_ONCE);
}
tf_ssb_remove_message_added_callback(ssb0, _message_added, &count0);
printf("Waiting for message from other.\n");
while (count1 == 0)
{
uv_run(&loop, UV_RUN_ONCE);
}
tf_ssb_remove_message_added_callback(ssb1, _message_added, &count1);
printf("done\n");
tf_ssb_send_close(ssb1);