Skip to content

Commit

Permalink
Merge pull request #1908 from ike08/improvement/cmocka-test-runner
Browse files Browse the repository at this point in the history
Refactor tests to use the new cmocka test runner
  • Loading branch information
jubalh authored Nov 2, 2023
2 parents 21fc8f6 + d35a7a7 commit 11e78e0
Show file tree
Hide file tree
Showing 8 changed files with 594 additions and 586 deletions.
6 changes: 3 additions & 3 deletions tests/functionaltests/functionaltests.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
#include "test_muc.h"
#include "test_disconnect.h"

#define PROF_FUNC_TEST(test) unit_test_setup_teardown(test, init_prof_test, close_prof_test)
#define PROF_FUNC_TEST(test) cmocka_unit_test_setup_teardown(test, init_prof_test, close_prof_test)

int main(int argc, char* argv[]) {

const UnitTest all_tests[] = {
const struct CMUnitTest all_tests[] = {

PROF_FUNC_TEST(connect_jid_requests_roster),
PROF_FUNC_TEST(connect_jid_sends_presence_after_receiving_roster),
Expand Down Expand Up @@ -111,5 +111,5 @@ int main(int argc, char* argv[]) {
PROF_FUNC_TEST(disconnect_ends_session),
};

return run_tests(all_tests);
return cmocka_run_group_tests(all_tests, NULL, NULL);
}
8 changes: 5 additions & 3 deletions tests/functionaltests/proftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ prof_start(void)
setbuf(fp, (char *)0);
}

void
int
init_prof_test(void **state)
{
if (stbbr_start(STBBR_LOGDEBUG ,5230, 0) != 0) {
assert_true(FALSE);
return;
return -1;
}

config_orig = getenv("XDG_CONFIG_HOME");
Expand Down Expand Up @@ -190,9 +190,10 @@ init_prof_test(void **state)
assert_true(prof_output_exact("Private chat time display disabled."));
prof_input("/time xml off");
assert_true(prof_output_exact("XML Console time display disabled."));
return 0;
}

void
int
close_prof_test(void **state)
{
prof_input("/quit");
Expand All @@ -203,6 +204,7 @@ close_prof_test(void **state)
setenv("XDG_DATA_HOME", data_orig, 1);

stbbr_stop();
return 0;
}

void
Expand Down
4 changes: 2 additions & 2 deletions tests/functionaltests/proftest.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#define XDG_CONFIG_HOME "./tests/functionaltests/files/xdg_config_home"
#define XDG_DATA_HOME "./tests/functionaltests/files/xdg_data_home"

void init_prof_test(void **state);
void close_prof_test(void **state);
int init_prof_test(void **state);
int close_prof_test(void **state);

void prof_start(void);
void prof_connect(void);
Expand Down
12 changes: 8 additions & 4 deletions tests/unittests/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ remove_data_dir(void** state)
rmdir("./tests/files/xdg_data_home");
}

void
int
load_preferences(void** state)
{
create_config_dir(state);
Expand All @@ -53,29 +53,33 @@ load_preferences(void** state)
prefs_load(NULL);
}
fclose(f);
return 0;
}

void
int
close_preferences(void** state)
{
prefs_close();
remove("./tests/files/xdg_config_home/profanity/profrc");
remove_config_dir(state);
rmdir("./tests/files");
return 0;
}

void
int
init_chat_sessions(void** state)
{
load_preferences(NULL);
chat_sessions_init();
return 0;
}

void
int
close_chat_sessions(void** state)
{
chat_sessions_clear();
close_preferences(NULL);
return 0;
}

int
Expand Down
8 changes: 4 additions & 4 deletions tests/unittests/helpers.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "glib.h"

void load_preferences(void** state);
void close_preferences(void** state);
int load_preferences(void** state);
int close_preferences(void** state);

void init_chat_sessions(void** state);
void close_chat_sessions(void** state);
int init_chat_sessions(void** state);
int close_chat_sessions(void** state);

int utf8_pos_to_col(char* str, int utf8_pos);

Expand Down
6 changes: 4 additions & 2 deletions tests/unittests/test_muc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@

#include "xmpp/muc.h"

void
int
muc_before_test(void** state)
{
muc_init();
return 0;
}

void
int
muc_after_test(void** state)
{
muc_close();
return 0;
}

void
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/test_muc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
void muc_before_test(void** state);
void muc_after_test(void** state);
int muc_before_test(void** state);
int muc_after_test(void** state);

void test_muc_invites_add(void** state);
void test_muc_remove_invite(void** state);
Expand Down
Loading

0 comments on commit 11e78e0

Please sign in to comment.