mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-20 19:16:22 +00:00
Added missing files, refactored ui_switch_win to check win exists
This commit is contained in:
39
tests/test_cmd_win.c
Normal file
39
tests/test_cmd_win.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <stdlib.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "ui/ui.h"
|
||||
#include "ui/mock_ui.h"
|
||||
|
||||
#include "command/commands.h"
|
||||
|
||||
void cmd_win_shows_message_when_win_doesnt_exist(void **state)
|
||||
{
|
||||
mock_cons_show();
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "3", NULL };
|
||||
|
||||
ui_switch_win_expect_and_return(3, FALSE);
|
||||
expect_cons_show("Window 3 does not exist.");
|
||||
|
||||
gboolean result = cmd_win(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
|
||||
void cmd_win_switches_to_given_win_when_exists(void **state)
|
||||
{
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "12", NULL };
|
||||
|
||||
ui_switch_win_expect_and_return(12, TRUE);
|
||||
|
||||
gboolean result = cmd_win(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
}
|
||||
2
tests/test_cmd_win.h
Normal file
2
tests/test_cmd_win.h
Normal file
@@ -0,0 +1,2 @@
|
||||
void cmd_win_shows_message_when_win_doesnt_exist(void **state);
|
||||
void cmd_win_switches_to_given_win_when_exists(void **state);
|
||||
@@ -178,16 +178,10 @@ void _mock_cons_show_roster(GSList *list)
|
||||
}
|
||||
|
||||
static
|
||||
gboolean _mock_ui_win_exists(int index)
|
||||
{
|
||||
check_expected(index);
|
||||
return (gboolean)mock();
|
||||
}
|
||||
|
||||
static
|
||||
void _mock_ui_switch_win(const int i)
|
||||
gboolean _mock_ui_switch_win(const int i)
|
||||
{
|
||||
check_expected(i);
|
||||
return (gboolean)mock();
|
||||
}
|
||||
|
||||
// bind mocks and stubs
|
||||
@@ -300,12 +294,6 @@ mock_cons_show_roster(void)
|
||||
cons_show_roster = _mock_cons_show_roster;
|
||||
}
|
||||
|
||||
void
|
||||
mock_ui_win_exists(void)
|
||||
{
|
||||
ui_win_exists = _mock_ui_win_exists;
|
||||
}
|
||||
|
||||
// expectations
|
||||
|
||||
void
|
||||
@@ -458,15 +446,9 @@ cons_show_roster_expect(GSList *list)
|
||||
}
|
||||
|
||||
void
|
||||
ui_win_exists_expect_and_return(int given_index, gboolean result)
|
||||
{
|
||||
expect_value(_mock_ui_win_exists, index, given_index);
|
||||
will_return(_mock_ui_win_exists, result);
|
||||
}
|
||||
|
||||
void
|
||||
ui_switch_win_expect(int given_i)
|
||||
ui_switch_win_expect_and_return(int given_i, gboolean result)
|
||||
{
|
||||
ui_switch_win = _mock_ui_switch_win;
|
||||
expect_value(_mock_ui_switch_win, i, given_i);
|
||||
will_return(_mock_ui_switch_win, result);
|
||||
}
|
||||
|
||||
@@ -64,9 +64,6 @@ void ui_room_join_expect(char *room);
|
||||
void mock_cons_show_roster(void);
|
||||
void cons_show_roster_expect(GSList *list);
|
||||
|
||||
void mock_ui_win_exists(void);
|
||||
void ui_win_exists_expect_and_return(int given_index, gboolean result);
|
||||
|
||||
void ui_switch_win_expect(int given_i);
|
||||
void ui_switch_win_expect_and_return(int given_i, gboolean result);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user