mirror of
https://github.com/weechat/weechat.git
synced 2026-07-06 17:53:13 +02:00
tests: check displayed message/error for all simulated IRC commands received
This commit is contained in:
@@ -32,12 +32,16 @@ struct t_irc_ctcp_reply
|
||||
};
|
||||
|
||||
extern const char *irc_ctcp_get_default_reply (const char *ctcp);
|
||||
extern const char *irc_ctcp_get_reply (struct t_irc_server *server,
|
||||
const char *ctcp);
|
||||
extern void irc_ctcp_display_reply_from_nick (struct t_irc_server *server,
|
||||
time_t date,
|
||||
const char *command,
|
||||
const char *nick,
|
||||
const char *address,
|
||||
const char *arguments);
|
||||
extern char *irc_ctcp_replace_variables (struct t_irc_server *server,
|
||||
const char *format);
|
||||
extern void irc_ctcp_recv (struct t_irc_server *server, time_t date,
|
||||
const char *command, struct t_irc_channel *channel,
|
||||
const char *address, const char *nick,
|
||||
|
||||
+140
-9
@@ -34,6 +34,7 @@ extern "C"
|
||||
#define HAVE_CONFIG_H
|
||||
#endif
|
||||
#include "src/core/weechat.h"
|
||||
#include "src/core/wee-arraylist.h"
|
||||
#include "src/core/wee-dir.h"
|
||||
#include "src/core/wee-hook.h"
|
||||
#include "src/core/wee-input.h"
|
||||
@@ -86,6 +87,10 @@ IMPORT_TEST_GROUP(Scripts);
|
||||
|
||||
struct t_gui_buffer *ptr_core_buffer = NULL;
|
||||
|
||||
/* recording of messages: to test if a message is actually displayed */
|
||||
int record_messages = 0;
|
||||
struct t_arraylist *recorded_messages = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* Callback for exec_on_files (to remove all files in WeeChat home directory).
|
||||
@@ -101,7 +106,7 @@ exec_on_files_cb (void *data, const char *filename)
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback for any message displayed by WeeChat or a plugin.
|
||||
* Callback for any message displayed by WeeChat or a plugin (colors stripped).
|
||||
*/
|
||||
|
||||
int
|
||||
@@ -109,6 +114,9 @@ test_print_cb (const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
time_t date, int tags_count, const char **tags, int displayed,
|
||||
int highlight, const char *prefix, const char *message)
|
||||
{
|
||||
const char *buffer_full_name;
|
||||
char str_recorded[8192];
|
||||
|
||||
/* make C++ compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
@@ -119,21 +127,134 @@ test_print_cb (const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
(void) displayed;
|
||||
(void) highlight;
|
||||
|
||||
/* keep only messages displayed on core buffer */
|
||||
if (strcmp (gui_buffer_get_string (buffer, "full_name"),
|
||||
"core.weechat") != 0)
|
||||
buffer_full_name = gui_buffer_get_string (buffer, "full_name");
|
||||
|
||||
if (record_messages)
|
||||
{
|
||||
return WEECHAT_RC_OK;
|
||||
snprintf (str_recorded, sizeof (str_recorded),
|
||||
"%s: \"%s%s%s\"",
|
||||
buffer_full_name,
|
||||
(prefix && prefix[0]) ? prefix : "",
|
||||
(prefix && prefix[0]) ? " " : "",
|
||||
(message && message[0]) ? message : "");
|
||||
arraylist_add (recorded_messages, strdup (str_recorded));
|
||||
}
|
||||
|
||||
printf ("%s%s%s\n", /* with color: "\33[34m%s%s%s\33[0m\n" */
|
||||
(prefix && prefix[0]) ? prefix : "",
|
||||
(prefix && prefix[0]) ? " " : "",
|
||||
(message && message[0]) ? message : "");
|
||||
/* keep only messages displayed on core buffer */
|
||||
if (strcmp (buffer_full_name, "core.weechat") == 0)
|
||||
{
|
||||
printf ("%s%s%s\n", /* with color: "\33[34m%s%s%s\33[0m\n" */
|
||||
(prefix && prefix[0]) ? prefix : "",
|
||||
(prefix && prefix[0]) ? " " : "",
|
||||
(message && message[0]) ? message : "");
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback used to compare two recorded messages.
|
||||
*/
|
||||
|
||||
int
|
||||
record_cmp_cb (void *data, struct t_arraylist *arraylist,
|
||||
void *pointer1, void *pointer2)
|
||||
{
|
||||
/* make C++ compiler happy */
|
||||
(void) data;
|
||||
(void) arraylist;
|
||||
|
||||
return strcmp ((char *)pointer1, (char *)pointer2);
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback used to free a recorded message.
|
||||
*/
|
||||
|
||||
void
|
||||
record_free_cb (void *data, struct t_arraylist *arraylist, void *pointer)
|
||||
{
|
||||
/* make C++ compiler happy */
|
||||
(void) data;
|
||||
(void) arraylist;
|
||||
|
||||
free (pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Starts recording of messages displayed.
|
||||
*/
|
||||
|
||||
void
|
||||
record_start ()
|
||||
{
|
||||
record_messages = 1;
|
||||
|
||||
if (recorded_messages)
|
||||
{
|
||||
arraylist_clear (recorded_messages);
|
||||
}
|
||||
else
|
||||
{
|
||||
recorded_messages = arraylist_new (16, 0, 1,
|
||||
&record_cmp_cb, NULL,
|
||||
&record_free_cb, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Stops recording of messages displayed.
|
||||
*/
|
||||
|
||||
void
|
||||
record_stop ()
|
||||
{
|
||||
record_messages = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Searches if a message has been displayed in a buffer.
|
||||
*
|
||||
* The format of "message" argument is: "prefix message" (prefix and message
|
||||
* separated by a space).
|
||||
*
|
||||
* Returns:
|
||||
* 1: message has been displayed
|
||||
* 0: message has NOT been displayed
|
||||
*/
|
||||
|
||||
int
|
||||
record_search (const char *buffer, const char *message)
|
||||
{
|
||||
char str_message[8192];
|
||||
|
||||
snprintf (str_message, sizeof (str_message),
|
||||
"%s: \"%s\"",
|
||||
buffer, message);
|
||||
|
||||
return (arraylist_search (recorded_messages, str_message,
|
||||
NULL, NULL) != NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds all recorded messages to the dynamic string "msg".
|
||||
*/
|
||||
|
||||
void
|
||||
record_dump (char **msg)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < arraylist_size (recorded_messages); i++)
|
||||
{
|
||||
string_dyn_concat (msg, " ", -1);
|
||||
string_dyn_concat (msg,
|
||||
(const char *)arraylist_get (recorded_messages, i),
|
||||
-1);
|
||||
string_dyn_concat (msg, "\n", -1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initializes GUI for tests.
|
||||
*/
|
||||
@@ -172,6 +293,16 @@ run_cmd (const char *command)
|
||||
input_data (ptr_core_buffer, command, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Runs a command on a buffer (do not display the command executed).
|
||||
*/
|
||||
|
||||
void
|
||||
run_cmd_quiet (const char *command)
|
||||
{
|
||||
input_data (ptr_core_buffer, command, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Runs tests in WeeChat environment.
|
||||
*/
|
||||
|
||||
@@ -32,6 +32,14 @@
|
||||
} \
|
||||
free (str);
|
||||
|
||||
extern struct t_arraylist *recorded_messages;
|
||||
|
||||
extern void record_start ();
|
||||
extern void record_stop ();
|
||||
extern int record_search (const char *buffer, const char *message);
|
||||
extern void record_dump (char **msg);
|
||||
|
||||
extern void run_cmd (const char *command);
|
||||
extern void run_cmd_quiet (const char *command);
|
||||
|
||||
#endif /* WEECHAT_TESTS_H */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1050,19 +1050,17 @@ TEST_GROUP(IrcServerConnected)
|
||||
"/command -buffer irc.server." IRC_FAKE_SERVER " irc "
|
||||
"/server fakerecv %s",
|
||||
command);
|
||||
run_cmd (str_command);
|
||||
run_cmd_quiet (str_command);
|
||||
}
|
||||
|
||||
void setup ()
|
||||
{
|
||||
printf ("\n");
|
||||
|
||||
/* create a fake server (no I/O) */
|
||||
run_cmd ("/server add " IRC_FAKE_SERVER " fake:127.0.0.1 "
|
||||
"-nicks=nick1,nick2,nick3");
|
||||
run_cmd_quiet ("/mute /server add " IRC_FAKE_SERVER " fake:127.0.0.1 "
|
||||
"-nicks=nick1,nick2,nick3");
|
||||
|
||||
/* connect to the fake server */
|
||||
run_cmd ("/connect " IRC_FAKE_SERVER);
|
||||
run_cmd_quiet ("/mute /connect " IRC_FAKE_SERVER);
|
||||
|
||||
/* get the server pointer */
|
||||
ptr_server = irc_server_search (IRC_FAKE_SERVER);
|
||||
@@ -1071,8 +1069,8 @@ TEST_GROUP(IrcServerConnected)
|
||||
void teardown ()
|
||||
{
|
||||
/* disconnect and delete the fake server */
|
||||
run_cmd ("/disconnect " IRC_FAKE_SERVER);
|
||||
run_cmd ("/server del " IRC_FAKE_SERVER);
|
||||
run_cmd_quiet ("/mute /disconnect " IRC_FAKE_SERVER);
|
||||
run_cmd_quiet ("/mute /server del " IRC_FAKE_SERVER);
|
||||
ptr_server = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user