1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-30 06:46:38 +02:00

tests: separate prefix from message in recorded messages

The record functions are moved to tests-record.cpp.
This commit is contained in:
Sébastien Helleu
2023-05-21 14:54:02 +02:00
parent 126d3559ca
commit eb7435f8b9
11 changed files with 909 additions and 733 deletions
+3 -125
View File
@@ -28,6 +28,8 @@
#include <sys/stat.h>
#include <sys/types.h>
#include "tests-record.h"
extern "C"
{
#ifndef HAVE_CONFIG_H
@@ -93,10 +95,6 @@ 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).
@@ -120,9 +118,6 @@ 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;
@@ -133,21 +128,8 @@ test_print_cb (const void *pointer, void *data, struct t_gui_buffer *buffer,
(void) displayed;
(void) highlight;
buffer_full_name = gui_buffer_get_string (buffer, "full_name");
if (record_messages)
{
snprintf (str_recorded, sizeof (str_recorded),
"%s: \"%s%s%s\"",
buffer_full_name,
(prefix && prefix[0]) ? prefix : "",
(prefix && prefix[0] && message && message[0]) ? " " : "",
(message && message[0]) ? message : "");
arraylist_add (recorded_messages, strdup (str_recorded));
}
/* keep only messages displayed on core buffer */
if (strcmp (buffer_full_name, "core.weechat") == 0)
if (strcmp (gui_buffer_get_string (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 : "",
@@ -158,110 +140,6 @@ test_print_cb (const void *pointer, void *data, struct t_gui_buffer *buffer,
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 index of message displayed (≥ 0), -1 if message has NOT been
* displayed.
*/
int
record_search (const char *buffer, const char *message)
{
char str_message[8192];
int index;
snprintf (str_message, sizeof (str_message),
"%s: \"%s\"",
buffer, message);
arraylist_search (recorded_messages, str_message, &index, NULL);
return index;
}
/*
* 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.
*/