Skip to content

Commit

Permalink
Update tests with setup and cleanup per test case
Browse files Browse the repository at this point in the history
Signed-off-by: Jacki <[email protected]>
  • Loading branch information
TheJackiMonster committed Aug 26, 2024
1 parent 6e32f4c commit bfea527
Show file tree
Hide file tree
Showing 14 changed files with 397 additions and 272 deletions.
29 changes: 11 additions & 18 deletions tests/attribute/test_gnunet_chat_attribute_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ on_gnunet_chat_attribute_check_msg(void *cls,
ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message));
break;
case GNUNET_CHAT_KIND_REFRESH:
ck_assert_ptr_null(context);
ck_assert_ptr_null(account);

account = GNUNET_CHAT_find_account(handle, TEST_CHECK_ID);

ck_assert_ptr_nonnull(account);

GNUNET_CHAT_connect(handle, account);
break;
case GNUNET_CHAT_KIND_LOGIN:
ck_assert_ptr_null(context);
Expand All @@ -89,19 +97,6 @@ on_gnunet_chat_attribute_check_msg(void *cls,
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);

ck_assert_int_eq(GNUNET_CHAT_account_delete(
handle,
TEST_CHECK_ID
), GNUNET_OK);
break;
case GNUNET_CHAT_KIND_CREATED_ACCOUNT:
ck_assert_ptr_nonnull(account);

GNUNET_CHAT_connect(handle, account);
break;
case GNUNET_CHAT_KIND_DELETED_ACCOUNT:
ck_assert_ptr_nonnull(account);

GNUNET_CHAT_stop(handle);
break;
case GNUNET_CHAT_KIND_UPDATE_ACCOUNT:
Expand Down Expand Up @@ -134,20 +129,18 @@ on_gnunet_chat_attribute_check_msg(void *cls,
return GNUNET_YES;
}

REQUIRE_GNUNET_CHAT_ACCOUNT(gnunet_chat_attribute_check, TEST_CHECK_ID)

void
call_gnunet_chat_attribute_check(const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static struct GNUNET_CHAT_Handle *handle = NULL;
handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_attribute_check_msg, &handle);

ck_assert_ptr_nonnull(handle);
ck_assert_int_eq(GNUNET_CHAT_account_create(
handle,
TEST_CHECK_ID
), GNUNET_OK);
}

CREATE_GNUNET_TEST(test_gnunet_chat_attribute_check, call_gnunet_chat_attribute_check)
CREATE_GNUNET_TEST(test_gnunet_chat_attribute_check, gnunet_chat_attribute_check)

START_SUITE(handle_suite, "Attribute")
ADD_TEST_TO_SUITE(test_gnunet_chat_attribute_check, "Check")
Expand Down
99 changes: 64 additions & 35 deletions tests/attribute/test_gnunet_chat_attribute_share.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ on_gnunet_chat_attribute_share_msg(void *cls,
struct GNUNET_CHAT_Context *context,
const struct GNUNET_CHAT_Message *message)
{
static unsigned int share_stage = 0;

struct GNUNET_CHAT_Handle *handle = *(
(struct GNUNET_CHAT_Handle**) cls
);
Expand All @@ -88,6 +90,20 @@ on_gnunet_chat_attribute_share_msg(void *cls,
ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message));
break;
case GNUNET_CHAT_KIND_REFRESH:
ck_assert_ptr_null(context);
ck_assert_ptr_null(account);

if (GNUNET_CHAT_get_connected(handle))
break;

ck_assert_uint_eq(share_stage, 0);

account = GNUNET_CHAT_find_account(handle, TEST_SHARE_ID_A);

ck_assert_ptr_nonnull(account);

GNUNET_CHAT_connect(handle, account);
share_stage = 1;
break;
case GNUNET_CHAT_KIND_LOGIN:
ck_assert_ptr_null(context);
Expand All @@ -96,55 +112,47 @@ on_gnunet_chat_attribute_share_msg(void *cls,
name = GNUNET_CHAT_account_get_name(account);

ck_assert_ptr_nonnull(name);
ck_assert_uint_ge(share_stage, 1);

if (0 == strcmp(name, TEST_SHARE_ID_B))
{
ck_assert_uint_eq(share_stage, 4);

GNUNET_CHAT_set_attribute(
handle,
TEST_SHARE_NAME,
TEST_SHARE_VALUE,
GNUNET_TIME_relative_get_forever_()
);

share_stage = 5;
}

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);
ck_assert_ptr_nonnull(account);
ck_assert_uint_ge(share_stage, 3);

name = GNUNET_CHAT_account_get_name(account);

ck_assert_ptr_nonnull(name);

if (share_stage < 4)
share_stage = 4;

if (0 == strcmp(name, TEST_SHARE_ID_A))
break;

ck_assert_int_eq(GNUNET_CHAT_account_delete(
handle, TEST_SHARE_ID_A
), GNUNET_OK);
break;
case GNUNET_CHAT_KIND_CREATED_ACCOUNT:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);

GNUNET_CHAT_connect(handle, account);
break;
case GNUNET_CHAT_KIND_DELETED_ACCOUNT:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);

name = GNUNET_CHAT_account_get_name(account);

ck_assert_ptr_nonnull(name);

if (0 == strcmp(name, TEST_SHARE_ID_A))
ck_assert_int_eq(GNUNET_CHAT_account_delete(
handle, TEST_SHARE_ID_B
), GNUNET_OK);
else
GNUNET_CHAT_stop(handle);
ck_assert_uint_eq(share_stage, 7);

GNUNET_CHAT_stop(handle);
break;
case GNUNET_CHAT_KIND_UPDATE_ACCOUNT:
ck_assert_ptr_nonnull(account);
Expand All @@ -161,29 +169,45 @@ on_gnunet_chat_attribute_share_msg(void *cls,

ck_assert_ptr_nonnull(name);

if (0 == strcmp(name, TEST_SHARE_ID_A))
ck_assert_int_eq(GNUNET_CHAT_account_create(
handle,
TEST_SHARE_ID_B
), GNUNET_OK);
else if (GNUNET_YES != GNUNET_CHAT_message_is_sent(message))
if ((0 == strcmp(name, TEST_SHARE_ID_A)) &&
(GNUNET_YES == GNUNET_CHAT_message_is_sent(message)))
{
ck_assert_uint_eq(share_stage, 2);

GNUNET_CHAT_connect(
handle,
GNUNET_CHAT_find_account(handle, TEST_SHARE_ID_B)
);

share_stage = 3;
}
else if ((GNUNET_YES != GNUNET_CHAT_message_is_sent(message)) &&
(share_stage == 5))
{
GNUNET_CHAT_share_attribute_with(handle, sender, TEST_SHARE_NAME);
share_stage = 6;
}

break;
case GNUNET_CHAT_KIND_CONTACT:
ck_assert_ptr_nonnull(context);
ck_assert_ptr_nonnull(sender);
break;
case GNUNET_CHAT_KIND_ATTRIBUTES:
ck_assert_ptr_null(context);
ck_assert_uint_ge(share_stage, 5);
break;
case GNUNET_CHAT_KIND_SHARED_ATTRIBUTES:
ck_assert_uint_ge(share_stage, 6);

if (!context)
{
ck_assert_ptr_null(account);
ck_assert_ptr_null(sender);
ck_assert_ptr_null(recipient);

GNUNET_CHAT_disconnect(handle);
share_stage = 7;
}
else if (GNUNET_YES == GNUNET_CHAT_message_is_sent(message))
{
Expand All @@ -208,20 +232,25 @@ on_gnunet_chat_attribute_share_msg(void *cls,
return GNUNET_YES;
}

const char *TEST_SHARE_IDS [] = {
TEST_SHARE_ID_A,
TEST_SHARE_ID_B,
NULL
};

SETUP_GNUNET_CHAT_ACCOUNTS(gnunet_chat_attribute_share, TEST_SHARE_IDS)
CLEANUP_GNUNET_CHAT_ACCOUNTS(gnunet_chat_attribute_share, TEST_SHARE_IDS)

void
call_gnunet_chat_attribute_share(const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static struct GNUNET_CHAT_Handle *handle = NULL;
handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_attribute_share_msg, &handle);

ck_assert_ptr_nonnull(handle);
ck_assert_int_eq(GNUNET_CHAT_account_create(
handle,
TEST_SHARE_ID_A
), GNUNET_OK);
}

CREATE_GNUNET_TEST(test_gnunet_chat_attribute_share, call_gnunet_chat_attribute_share)
CREATE_GNUNET_TEST(test_gnunet_chat_attribute_share, gnunet_chat_attribute_share)

START_SUITE(handle_suite, "Attribute")
ADD_TEST_TO_SUITE(test_gnunet_chat_attribute_share, "Share")
Expand Down
31 changes: 12 additions & 19 deletions tests/discourse/test_gnunet_chat_discourse_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ on_gnunet_chat_discourse_open_msg(void *cls,
ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message));
break;
case GNUNET_CHAT_KIND_REFRESH:
ck_assert_ptr_null(context);
ck_assert_ptr_null(account);

account = GNUNET_CHAT_find_account(handle, TEST_OPEN_ID);

ck_assert_ptr_nonnull(account);

GNUNET_CHAT_connect(handle, account);
break;
case GNUNET_CHAT_KIND_LOGIN:
ck_assert_ptr_null(context);
Expand All @@ -67,21 +75,7 @@ on_gnunet_chat_discourse_open_msg(void *cls,
case GNUNET_CHAT_KIND_LOGOUT:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);
ck_assert_int_eq(GNUNET_CHAT_account_delete(
handle,
TEST_OPEN_ID
), GNUNET_OK);
break;
case GNUNET_CHAT_KIND_CREATED_ACCOUNT:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);

GNUNET_CHAT_connect(handle, account);
break;
case GNUNET_CHAT_KIND_DELETED_ACCOUNT:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);


GNUNET_CHAT_stop(handle);
break;
case GNUNET_CHAT_KIND_UPDATE_ACCOUNT:
Expand Down Expand Up @@ -126,19 +120,18 @@ on_gnunet_chat_discourse_open_msg(void *cls,
return GNUNET_YES;
}

REQUIRE_GNUNET_CHAT_ACCOUNT(gnunet_chat_discourse_open, TEST_OPEN_ID)

void
call_gnunet_chat_discourse_open(const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static struct GNUNET_CHAT_Handle *handle = NULL;
handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_discourse_open_msg, &handle);

ck_assert_ptr_nonnull(handle);
ck_assert_int_eq(GNUNET_CHAT_account_create(
handle, TEST_OPEN_ID
), GNUNET_OK);
}

CREATE_GNUNET_TEST(test_gnunet_chat_discourse_open, call_gnunet_chat_discourse_open)
CREATE_GNUNET_TEST(test_gnunet_chat_discourse_open, gnunet_chat_discourse_open)

START_SUITE(handle_suite, "Handle")
ADD_TEST_TO_SUITE(test_gnunet_chat_discourse_open, "Open/Close")
Expand Down
31 changes: 12 additions & 19 deletions tests/discourse/test_gnunet_chat_discourse_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ on_gnunet_chat_discourse_write_msg(void *cls,
ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message));
break;
case GNUNET_CHAT_KIND_REFRESH:
ck_assert_ptr_null(context);
ck_assert_ptr_null(account);

account = GNUNET_CHAT_find_account(handle, TEST_WRITE_ID);

ck_assert_ptr_nonnull(account);

GNUNET_CHAT_connect(handle, account);
break;
case GNUNET_CHAT_KIND_LOGIN:
ck_assert_ptr_null(context);
Expand All @@ -67,21 +75,7 @@ on_gnunet_chat_discourse_write_msg(void *cls,
case GNUNET_CHAT_KIND_LOGOUT:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);
ck_assert_int_eq(GNUNET_CHAT_account_delete(
handle,
TEST_WRITE_ID
), GNUNET_OK);
break;
case GNUNET_CHAT_KIND_CREATED_ACCOUNT:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);

GNUNET_CHAT_connect(handle, account);
break;
case GNUNET_CHAT_KIND_DELETED_ACCOUNT:
ck_assert_ptr_null(context);
ck_assert_ptr_nonnull(account);


GNUNET_CHAT_stop(handle);
break;
case GNUNET_CHAT_KIND_UPDATE_ACCOUNT:
Expand Down Expand Up @@ -165,19 +159,18 @@ on_gnunet_chat_discourse_write_msg(void *cls,
return GNUNET_YES;
}

REQUIRE_GNUNET_CHAT_ACCOUNT(gnunet_chat_discourse_write, TEST_WRITE_ID)

void
call_gnunet_chat_discourse_write(const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static struct GNUNET_CHAT_Handle *handle = NULL;
handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_discourse_write_msg, &handle);

ck_assert_ptr_nonnull(handle);
ck_assert_int_eq(GNUNET_CHAT_account_create(
handle, TEST_WRITE_ID
), GNUNET_OK);
}

CREATE_GNUNET_TEST(test_gnunet_chat_discourse_write, call_gnunet_chat_discourse_write)
CREATE_GNUNET_TEST(test_gnunet_chat_discourse_write, gnunet_chat_discourse_write)

START_SUITE(handle_suite, "Handle")
ADD_TEST_TO_SUITE(test_gnunet_chat_discourse_write, "Talk")
Expand Down
Loading

0 comments on commit bfea527

Please sign in to comment.