mirror of
https://github.com/weechat/weechat.git
synced 2026-07-04 16:53:14 +02:00
tests: check displayed message/error for all simulated IRC commands received
This commit is contained in:
+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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user