commit a2a3cd3a8cd4e537fbbc8e072428b621c2683027
parent d2578e05a36023a2838ea07e27f3e6959bdfcbfc
Author: Jacki <jacki@thejackimonster.de>
Date: Sat, 5 Oct 2024 23:16:44 +0200
Adjust test cases to make them more sensitive regarding event order
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
8 files changed, 178 insertions(+), 32 deletions(-)
diff --git a/tests/attribute/test_gnunet_chat_attribute_check.c b/tests/attribute/test_gnunet_chat_attribute_check.c
@@ -55,6 +55,8 @@ on_gnunet_chat_attribute_check_msg(void *cls,
struct GNUNET_CHAT_Context *context,
struct GNUNET_CHAT_Message *message)
{
+ static unsigned int attribute_stage = 0;
+
struct GNUNET_CHAT_Handle *handle = *(
(struct GNUNET_CHAT_Handle**) cls
);
@@ -76,25 +78,34 @@ on_gnunet_chat_attribute_check_msg(void *cls,
ck_assert_ptr_null(context);
ck_assert_ptr_null(account);
- account = GNUNET_CHAT_find_account(handle, TEST_CHECK_ID);
+ if (attribute_stage == 0)
+ {
+ account = GNUNET_CHAT_find_account(handle, TEST_CHECK_ID);
- ck_assert_ptr_nonnull(account);
+ ck_assert_ptr_nonnull(account);
+
+ GNUNET_CHAT_connect(handle, account);
+ attribute_stage = 1;
+ }
- GNUNET_CHAT_connect(handle, account);
break;
case GNUNET_CHAT_KIND_LOGIN:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);
+ ck_assert_uint_eq(attribute_stage, 1);
GNUNET_CHAT_set_attribute(
handle,
TEST_CHECK_NAME,
TEST_CHECK_VALUE
);
+
+ attribute_stage = 2;
break;
case GNUNET_CHAT_KIND_LOGOUT:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);
+ ck_assert_uint_eq(attribute_stage, 4);
GNUNET_CHAT_stop(handle);
break;
@@ -109,16 +120,25 @@ on_gnunet_chat_attribute_check_msg(void *cls,
if (text)
{
ck_assert_str_eq(text, TEST_CHECK_NAME);
+ ck_assert_uint_eq(attribute_stage, 2);
GNUNET_CHAT_get_attributes(
handle,
on_gnunet_chat_attribute_check_attr,
NULL
);
+
+ attribute_stage = 3;
}
else
+ {
+ ck_assert_uint_eq(attribute_stage, 3);
+
GNUNET_CHAT_disconnect(handle);
+ attribute_stage = 4;
+ }
+
break;
default:
ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message));
diff --git a/tests/attribute/test_gnunet_chat_attribute_share.c b/tests/attribute/test_gnunet_chat_attribute_share.c
@@ -93,17 +93,16 @@ on_gnunet_chat_attribute_share_msg(void *cls,
ck_assert_ptr_null(context);
ck_assert_ptr_null(account);
- if (GNUNET_CHAT_get_connected(handle))
- break;
-
- ck_assert_uint_eq(share_stage, 0);
+ if (share_stage == 0)
+ {
+ account = GNUNET_CHAT_find_account(handle, TEST_SHARE_ID_A);
- account = GNUNET_CHAT_find_account(handle, TEST_SHARE_ID_A);
+ ck_assert_ptr_nonnull(account);
- ck_assert_ptr_nonnull(account);
+ GNUNET_CHAT_connect(handle, account);
+ share_stage = 1;
+ }
- GNUNET_CHAT_connect(handle, account);
- share_stage = 1;
break;
case GNUNET_CHAT_KIND_LOGIN:
ck_assert_ptr_null(context);
@@ -126,13 +125,16 @@ on_gnunet_chat_attribute_share_msg(void *cls,
share_stage = 5;
}
+ else
+ {
+ ck_assert_uint_eq(share_stage, 1);
+
+ share_stage = 2;
+ }
ck_assert_ptr_nonnull(GNUNET_CHAT_group_create(
handle, TEST_SHARE_GROUP
));
-
- if (share_stage < 2)
- share_stage = 2;
break;
case GNUNET_CHAT_KIND_LOGOUT:
ck_assert_ptr_null(context);
diff --git a/tests/discourse/test_gnunet_chat_discourse_open.c b/tests/discourse/test_gnunet_chat_discourse_open.c
@@ -33,6 +33,8 @@ on_gnunet_chat_discourse_open_msg(void *cls,
struct GNUNET_CHAT_Context *context,
struct GNUNET_CHAT_Message *message)
{
+ static unsigned int discourse_stage = 0;
+
struct GNUNET_CHAT_Handle *handle = *(
(struct GNUNET_CHAT_Handle**) cls
);
@@ -58,23 +60,31 @@ on_gnunet_chat_discourse_open_msg(void *cls,
ck_assert_ptr_null(context);
ck_assert_ptr_null(account);
- account = GNUNET_CHAT_find_account(handle, TEST_OPEN_ID);
+ if (discourse_stage == 0)
+ {
+ account = GNUNET_CHAT_find_account(handle, TEST_OPEN_ID);
- ck_assert_ptr_nonnull(account);
+ ck_assert_ptr_nonnull(account);
+
+ GNUNET_CHAT_connect(handle, account);
+ discourse_stage = 1;
+ }
- GNUNET_CHAT_connect(handle, account);
break;
case GNUNET_CHAT_KIND_LOGIN:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);
ck_assert_ptr_nonnull(name);
ck_assert_str_eq(name, TEST_OPEN_ID);
+ ck_assert_uint_eq(discourse_stage, 1);
GNUNET_CHAT_group_create(handle, TEST_OPEN_GROUP);
+ discourse_stage = 2;
break;
case GNUNET_CHAT_KIND_LOGOUT:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);
+ ck_assert_uint_eq(discourse_stage, 5);
GNUNET_CHAT_stop(handle);
break;
@@ -85,6 +95,7 @@ on_gnunet_chat_discourse_open_msg(void *cls,
case GNUNET_CHAT_KIND_JOIN:
ck_assert_ptr_nonnull(context);
ck_assert_ptr_null(discourse);
+ ck_assert_uint_eq(discourse_stage, 2);
GNUNET_memcpy(
&discourse_id,
@@ -99,6 +110,8 @@ on_gnunet_chat_discourse_open_msg(void *cls,
ck_assert_ptr_nonnull(discourse);
ck_assert_int_eq(GNUNET_CHAT_discourse_is_open(discourse), GNUNET_NO);
+
+ discourse_stage = 3;
break;
case GNUNET_CHAT_KIND_CONTACT:
break;
@@ -107,9 +120,20 @@ on_gnunet_chat_discourse_open_msg(void *cls,
ck_assert_ptr_nonnull(discourse);
if (GNUNET_YES == GNUNET_CHAT_discourse_is_open(discourse))
+ {
+ ck_assert_uint_eq(discourse_stage, 3);
+
GNUNET_CHAT_discourse_close(discourse);
+ discourse_stage = 4;
+ }
else
+ {
+ ck_assert_uint_eq(discourse_stage, 4);
+
GNUNET_CHAT_disconnect(handle);
+ discourse_stage = 5;
+ }
+
break;
default:
ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message));
diff --git a/tests/discourse/test_gnunet_chat_discourse_write.c b/tests/discourse/test_gnunet_chat_discourse_write.c
@@ -33,6 +33,8 @@ on_gnunet_chat_discourse_write_msg(void *cls,
struct GNUNET_CHAT_Context *context,
struct GNUNET_CHAT_Message *message)
{
+ static unsigned int discourse_stage = 0;
+
struct GNUNET_CHAT_Handle *handle = *(
(struct GNUNET_CHAT_Handle**) cls
);
@@ -58,23 +60,31 @@ on_gnunet_chat_discourse_write_msg(void *cls,
ck_assert_ptr_null(context);
ck_assert_ptr_null(account);
- account = GNUNET_CHAT_find_account(handle, TEST_WRITE_ID);
+ if (discourse_stage == 0)
+ {
+ account = GNUNET_CHAT_find_account(handle, TEST_WRITE_ID);
- ck_assert_ptr_nonnull(account);
+ ck_assert_ptr_nonnull(account);
+
+ GNUNET_CHAT_connect(handle, account);
+ discourse_stage = 1;
+ }
- GNUNET_CHAT_connect(handle, account);
break;
case GNUNET_CHAT_KIND_LOGIN:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);
ck_assert_ptr_nonnull(name);
ck_assert_str_eq(name, TEST_WRITE_ID);
+ ck_assert_uint_eq(discourse_stage, 1);
GNUNET_CHAT_group_create(handle, TEST_WRITE_GROUP);
+ discourse_stage = 2;
break;
case GNUNET_CHAT_KIND_LOGOUT:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);
+ ck_assert_uint_eq(discourse_stage, 6);
GNUNET_CHAT_stop(handle);
break;
@@ -85,6 +95,7 @@ on_gnunet_chat_discourse_write_msg(void *cls,
case GNUNET_CHAT_KIND_JOIN:
ck_assert_ptr_nonnull(context);
ck_assert_ptr_null(discourse);
+ ck_assert_uint_eq(discourse_stage, 2);
GNUNET_memcpy(
&discourse_id,
@@ -99,6 +110,8 @@ on_gnunet_chat_discourse_write_msg(void *cls,
ck_assert_ptr_nonnull(discourse);
ck_assert_int_eq(GNUNET_CHAT_discourse_is_open(discourse), GNUNET_NO);
+
+ discourse_stage = 3;
break;
case GNUNET_CHAT_KIND_CONTACT:
break;
@@ -113,6 +126,9 @@ on_gnunet_chat_discourse_write_msg(void *cls,
);
if (GNUNET_YES == GNUNET_CHAT_discourse_is_open(discourse))
+ {
+ ck_assert_uint_eq(discourse_stage, 3);
+
ck_assert_int_eq(
GNUNET_CHAT_discourse_write(
discourse,
@@ -121,12 +137,23 @@ on_gnunet_chat_discourse_write_msg(void *cls,
),
GNUNET_OK
);
+
+ discourse_stage = 4;
+ }
else
+ {
+ ck_assert_uint_eq(discourse_stage, 5);
+
GNUNET_CHAT_disconnect(handle);
+
+ discourse_stage = 6;
+ }
+
break;
case GNUNET_CHAT_KIND_DATA:
ck_assert_ptr_nonnull(context);
ck_assert_ptr_nonnull(discourse);
+ ck_assert_uint_eq(discourse_stage, 4);
ck_assert_uint_eq(
GNUNET_CHAT_message_available(message),
@@ -149,6 +176,7 @@ on_gnunet_chat_discourse_write_msg(void *cls,
);
GNUNET_CHAT_discourse_close(discourse);
+ discourse_stage = 5;
break;
default:
ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message));
diff --git a/tests/file/test_gnunet_chat_file_send.c b/tests/file/test_gnunet_chat_file_send.c
@@ -76,6 +76,7 @@ on_gnunet_chat_file_send_msg(void *cls,
struct GNUNET_CHAT_Context *context,
struct GNUNET_CHAT_Message *message)
{
+ static unsigned int file_stage = 0;
static char *filename = NULL;
struct GNUNET_CHAT_Handle *handle = *(
@@ -100,14 +101,20 @@ on_gnunet_chat_file_send_msg(void *cls,
ck_assert_ptr_null(context);
ck_assert_ptr_null(account);
- account = GNUNET_CHAT_find_account(handle, TEST_SEND_ID);
+ if (file_stage == 0)
+ {
+ account = GNUNET_CHAT_find_account(handle, TEST_SEND_ID);
- ck_assert_ptr_nonnull(account);
+ ck_assert_ptr_nonnull(account);
+
+ GNUNET_CHAT_connect(handle, account);
+ file_stage = 1;
+ }
- GNUNET_CHAT_connect(handle, account);
break;
case GNUNET_CHAT_KIND_LOGIN:
ck_assert_ptr_null(context);
+ ck_assert_uint_eq(file_stage, 1);
group = GNUNET_CHAT_group_create(
handle, TEST_SEND_GROUP
@@ -132,10 +139,15 @@ on_gnunet_chat_file_send_msg(void *cls,
);
ck_assert_ptr_nonnull(file);
+
+ file_stage = 2;
break;
case GNUNET_CHAT_KIND_LOGOUT:
ck_assert_ptr_null(context);
ck_assert_ptr_null(filename);
+ ck_assert_uint_eq(file_stage, 4);
+
+ GNUNET_CHAT_stop(handle);
break;
case GNUNET_CHAT_KIND_UPDATE_ACCOUNT:
ck_assert_ptr_null(context);
@@ -149,6 +161,7 @@ on_gnunet_chat_file_send_msg(void *cls,
case GNUNET_CHAT_KIND_TEXT:
ck_assert_ptr_nonnull(context);
ck_assert_ptr_nonnull(filename);
+ ck_assert_uint_eq(file_stage, 3);
remove(filename);
GNUNET_free(filename);
@@ -158,11 +171,13 @@ on_gnunet_chat_file_send_msg(void *cls,
ck_assert_ptr_nonnull(text);
ck_assert_str_eq(text, TEST_SEND_TEXT);
-
- GNUNET_CHAT_stop(handle);
+
+ GNUNET_CHAT_disconnect(handle);
+ file_stage = 4;
break;
case GNUNET_CHAT_KIND_FILE:
ck_assert_ptr_nonnull(context);
+ ck_assert_uint_eq(file_stage, 2);
file = GNUNET_CHAT_message_get_file(message);
@@ -172,6 +187,8 @@ on_gnunet_chat_file_send_msg(void *cls,
on_gnunet_chat_file_send_unindex,
context
), GNUNET_OK);
+
+ file_stage = 3;
break;
default:
ck_abort();
diff --git a/tests/group/test_gnunet_chat_group_open.c b/tests/group/test_gnunet_chat_group_open.c
@@ -32,6 +32,8 @@ on_gnunet_chat_group_open_msg(void *cls,
struct GNUNET_CHAT_Context *context,
struct GNUNET_CHAT_Message *message)
{
+ static unsigned int group_stage = 0;
+
struct GNUNET_CHAT_Handle *handle = *(
(struct GNUNET_CHAT_Handle**) cls
);
@@ -56,11 +58,16 @@ on_gnunet_chat_group_open_msg(void *cls,
ck_assert_ptr_null(context);
ck_assert_ptr_null(account);
- account = GNUNET_CHAT_find_account(handle, TEST_OPEN_ID);
+ if (group_stage == 0)
+ {
+ account = GNUNET_CHAT_find_account(handle, TEST_OPEN_ID);
- ck_assert_ptr_nonnull(account);
+ ck_assert_ptr_nonnull(account);
+
+ GNUNET_CHAT_connect(handle, account);
+ group_stage = 1;
+ }
- GNUNET_CHAT_connect(handle, account);
break;
case GNUNET_CHAT_KIND_LOGIN:
ck_assert_ptr_null(context);
@@ -68,33 +75,47 @@ on_gnunet_chat_group_open_msg(void *cls,
ck_assert_ptr_nonnull(name);
ck_assert_str_eq(name, TEST_OPEN_ID);
ck_assert_ptr_null(group);
+ ck_assert_uint_eq(group_stage, 1);
group = GNUNET_CHAT_group_create(handle, TEST_OPEN_GROUP);
ck_assert_ptr_nonnull(group);
+
+ group_stage = 2;
break;
case GNUNET_CHAT_KIND_LOGOUT:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);
ck_assert_ptr_null(group);
+ ck_assert_uint_eq(group_stage, 4);
GNUNET_CHAT_stop(handle);
break;
case GNUNET_CHAT_KIND_UPDATE_ACCOUNT:
+ ck_assert_ptr_nonnull(account);
break;
case GNUNET_CHAT_KIND_UPDATE_CONTEXT:
+ ck_assert_ptr_nonnull(context);
break;
case GNUNET_CHAT_KIND_JOIN:
ck_assert_ptr_nonnull(context);
ck_assert_ptr_nonnull(group);
+ ck_assert_uint_eq(group_stage, 2);
+
+ ck_assert_int_eq(
+ GNUNET_CHAT_group_leave(group),
+ GNUNET_OK
+ );
- ck_assert_int_eq(GNUNET_CHAT_group_leave(group), GNUNET_OK);
+ group_stage = 3;
break;
case GNUNET_CHAT_KIND_LEAVE:
ck_assert_ptr_nonnull(context);
ck_assert_ptr_null(group);
+ ck_assert_uint_eq(group_stage, 3);
GNUNET_CHAT_disconnect(handle);
+ group_stage = 4;
break;
case GNUNET_CHAT_KIND_CONTACT:
break;
diff --git a/tests/handle/test_gnunet_chat_handle_rename.c b/tests/handle/test_gnunet_chat_handle_rename.c
@@ -32,6 +32,8 @@ on_gnunet_chat_handle_rename_msg(void *cls,
struct GNUNET_CHAT_Context *context,
struct GNUNET_CHAT_Message *message)
{
+ static unsigned int rename_stage = 0;
+
struct GNUNET_CHAT_Handle *handle = *(
(struct GNUNET_CHAT_Handle**) cls
);
@@ -52,12 +54,14 @@ on_gnunet_chat_handle_rename_msg(void *cls,
ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message));
break;
case GNUNET_CHAT_KIND_REFRESH:
+ ck_assert_ptr_null(account);
break;
case GNUNET_CHAT_KIND_LOGIN:
ck_assert_ptr_nonnull(account);
ck_assert_ptr_nonnull(name);
ck_assert_ptr_null(dup);
ck_assert_str_eq(name, TEST_RENAME_ID_A);
+ ck_assert_uint_eq(rename_stage, 1);
dup = GNUNET_strdup(name);
@@ -70,21 +74,30 @@ on_gnunet_chat_handle_rename_msg(void *cls,
handle,
TEST_RENAME_ID_B
), GNUNET_YES);
+
+ rename_stage = 2;
break;
case GNUNET_CHAT_KIND_LOGOUT:
ck_assert_ptr_nonnull(account);
+ ck_assert_uint_eq(rename_stage, 3);
+
ck_assert_int_eq(GNUNET_CHAT_account_delete(
handle,
TEST_RENAME_ID_B
), GNUNET_OK);
+
+ rename_stage = 4;
break;
case GNUNET_CHAT_KIND_CREATED_ACCOUNT:
ck_assert_ptr_nonnull(account);
+ ck_assert_uint_eq(rename_stage, 0);
GNUNET_CHAT_connect(handle, account);
+ rename_stage = 1;
break;
case GNUNET_CHAT_KIND_DELETED_ACCOUNT:
ck_assert_ptr_nonnull(account);
+ ck_assert_uint_eq(rename_stage, 4);
GNUNET_CHAT_stop(handle);
break;
@@ -95,10 +108,12 @@ on_gnunet_chat_handle_rename_msg(void *cls,
ck_assert_str_ne(name, dup);
ck_assert_str_eq(name, TEST_RENAME_ID_B);
ck_assert_str_eq(dup, TEST_RENAME_ID_A);
+ ck_assert_uint_eq(rename_stage, 2);
GNUNET_free(dup);
GNUNET_CHAT_disconnect(handle);
+ rename_stage = 3;
break;
default:
ck_abort();
diff --git a/tests/message/test_gnunet_chat_message_text.c b/tests/message/test_gnunet_chat_message_text.c
@@ -33,6 +33,8 @@ on_gnunet_chat_message_text_msg(void *cls,
struct GNUNET_CHAT_Context *context,
struct GNUNET_CHAT_Message *message)
{
+ static unsigned int text_stage = 0;
+
struct GNUNET_CHAT_Handle *handle = *(
(struct GNUNET_CHAT_Handle**) cls
);
@@ -55,23 +57,32 @@ on_gnunet_chat_message_text_msg(void *cls,
ck_assert_ptr_null(context);
ck_assert_ptr_null(account);
- account = GNUNET_CHAT_find_account(handle, TEST_TEXT_ID);
+ if (text_stage == 0)
+ {
+ account = GNUNET_CHAT_find_account(handle, TEST_TEXT_ID);
- ck_assert_ptr_nonnull(account);
+ ck_assert_ptr_nonnull(account);
+
+ GNUNET_CHAT_connect(handle, account);
+ text_stage = 1;
+ }
- GNUNET_CHAT_connect(handle, account);
break;
case GNUNET_CHAT_KIND_LOGIN:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);
+ ck_assert_uint_eq(text_stage, 1);
group = GNUNET_CHAT_group_create(handle, TEST_TEXT_GROUP);
ck_assert_ptr_nonnull(group);
+
+ text_stage = 2;
break;
case GNUNET_CHAT_KIND_LOGOUT:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);
+ ck_assert_uint_eq(text_stage, 5);
GNUNET_CHAT_stop(handle);
break;
@@ -83,21 +94,27 @@ on_gnunet_chat_message_text_msg(void *cls,
break;
case GNUNET_CHAT_KIND_JOIN:
ck_assert_ptr_nonnull(context);
+ ck_assert_uint_eq(text_stage, 2);
ck_assert_int_eq(GNUNET_CHAT_context_send_text(
context, TEST_TEXT_MSG
), GNUNET_OK);
+
+ text_stage = 3;
break;
case GNUNET_CHAT_KIND_LEAVE:
ck_assert_ptr_nonnull(context);
+ ck_assert_uint_eq(text_stage, 4);
GNUNET_CHAT_disconnect(handle);
+ text_stage = 5;
break;
case GNUNET_CHAT_KIND_CONTACT:
ck_assert_ptr_nonnull(context);
break;
case GNUNET_CHAT_KIND_TEXT:
ck_assert_ptr_nonnull(context);
+ ck_assert_uint_eq(text_stage, 3);
group = GNUNET_CHAT_context_get_group(context);
@@ -107,6 +124,8 @@ on_gnunet_chat_message_text_msg(void *cls,
ck_assert_str_eq(text, TEST_TEXT_MSG);
ck_assert_int_eq(GNUNET_CHAT_group_leave(group), GNUNET_OK);
+
+ text_stage = 4;
break;
default:
ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message));