Files
cproof/tests/functionaltests/test_chat_session.c
Michael Vetter 9cb11bdec2 tests: Reenable functional tests
They were disabled in 171b6e73c9.

Enable the functional test suite and replaces the
dependency on libexpect with a custom solution.

The native solution allows for specific optimizations like automatic
ANSI code stripping, which is essential for reliable pattern matching in
an ncurses interface.

Custom PTY management via libutil provides full control over the process
lifecycle, resolving issues where tests would hang indefinitely.
We use forkpty from libutil.

Addiiotnally this commit implements automatic ANSI escape sequence
filtering to improve matching consistency.
This will get rid of the colors in matches. It's still something that we
need to think about more since basically we will not test out
color/theme system this way.

We also add non-blocking poll() and SIGKILL based teardown logic to
ensure clean test termination.

We added the functional tests to both autotools and meson.
They are only build when tests are enabled and stabber + libutil are
present.
Meson will print this out nicely in the summary.

Regards https://github.com/profanity-im/profanity/issues/789
2026-03-04 22:32:38 +01:00

182 lines
5.5 KiB
C

#include <glib.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <stabber.h>
#include "proftest.h"
void
sends_message_to_barejid_when_contact_offline(void** state)
{
prof_connect();
prof_input("/msg buddy1@localhost Hi there");
assert_true(stbbr_received(
"<message id='*' to='buddy1@localhost' type='chat'>"
"<body>Hi there</body>"
"</message>"));
}
void
sends_message_to_barejid_when_contact_online(void** state)
{
prof_connect();
stbbr_send(
"<presence to='stabber@localhost/profanity' from='buddy1@localhost/mobile'>"
"<priority>10</priority>"
"</presence>");
assert_true(prof_output_exact("Buddy1 (mobile) is online"));
prof_input("/msg buddy1@localhost Hi there");
assert_true(stbbr_received(
"<message id='*' to='buddy1@localhost' type='chat'>"
"<body>Hi there</body>"
"</message>"));
}
void
sends_message_to_fulljid_when_received_from_fulljid(void** state)
{
prof_connect();
stbbr_send(
"<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
"<priority>10</priority>"
"</presence>");
assert_true(prof_output_exact("Buddy1 (mobile) is online"));
stbbr_send(
"<message id='message1' to='stabber@localhost' from='buddy1@localhost/mobile' type='chat'>"
"<body>First message</body>"
"</message>");
assert_true(prof_output_exact("<< chat message: Buddy1/mobile (win 2)"));
prof_input("/msg buddy1@localhost Hi there");
assert_true(stbbr_received(
"<message id='*' to='buddy1@localhost/mobile' type='chat'>"
"<body>Hi there</body>"
"</message>"));
}
void
sends_subsequent_messages_to_fulljid(void** state)
{
prof_connect();
stbbr_send(
"<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
"<priority>10</priority>"
"</presence>");
assert_true(prof_output_exact("Buddy1 (mobile) is online"));
stbbr_send(
"<message id='message1' to='stabber@localhost' from='buddy1@localhost/mobile' type='chat'>"
"<body>First message</body>"
"</message>");
assert_true(prof_output_exact("<< chat message: Buddy1/mobile (win 2)"));
prof_input("/msg buddy1@localhost Outgoing 1");
assert_true(stbbr_received(
"<message id='*' to='buddy1@localhost/mobile' type='chat'>"
"<body>Outgoing 1</body>"
"</message>"));
prof_input("/msg buddy1@localhost Outgoing 2");
assert_true(stbbr_received(
"<message id='*' to='buddy1@localhost/mobile' type='chat'>"
"<body>Outgoing 2</body>"
"</message>"));
prof_input("/msg buddy1@localhost Outgoing 3");
assert_true(stbbr_received(
"<message id='*' to='buddy1@localhost/mobile' type='chat'>"
"<body>Outgoing 3</body>"
"</message>"));
}
void
resets_to_barejid_after_presence_received(void** state)
{
prof_connect();
stbbr_send(
"<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
"<priority>10</priority>"
"</presence>");
assert_true(prof_output_exact("Buddy1 (mobile) is online"));
stbbr_send(
"<message id='message1' to='stabber@localhost' from='buddy1@localhost/mobile' type='chat'>"
"<body>First message</body>"
"</message>");
assert_true(prof_output_exact("<< chat message: Buddy1/mobile (win 2)"));
prof_input("/msg buddy1@localhost Outgoing 1");
assert_true(stbbr_received(
"<message id='*' to='buddy1@localhost/mobile' type='chat'>"
"<body>Outgoing 1</body>"
"</message>"));
stbbr_send(
"<presence to='stabber@localhost' from='buddy1@localhost/laptop'>"
"<priority>5</priority>"
"<show>dnd</show>"
"</presence>");
assert_true(prof_output_exact("Buddy1 (laptop) is dnd"));
prof_input("/msg buddy1@localhost Outgoing 2");
assert_true(stbbr_received(
"<message id='*' to='buddy1@localhost' type='chat'>"
"<body>Outgoing 2</body>"
"</message>"));
}
void
new_session_when_message_received_from_different_fulljid(void** state)
{
prof_connect();
stbbr_send(
"<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
"<priority>10</priority>"
"</presence>");
assert_true(prof_output_exact("Buddy1 (mobile) is online"));
stbbr_send(
"<presence to='stabber@localhost' from='buddy1@localhost/laptop'>"
"<priority>8</priority>"
"<show>away</show>"
"</presence>");
assert_true(prof_output_exact("Buddy1 (laptop) is away"));
stbbr_send(
"<message id='message1' to='stabber@localhost' from='buddy1@localhost/mobile' type='chat'>"
"<body>From first resource</body>"
"</message>");
assert_true(prof_output_exact("<< chat message: Buddy1/mobile (win 2)"));
prof_input("/msg buddy1@localhost Outgoing 1");
assert_true(stbbr_received(
"<message id='*' to='buddy1@localhost/mobile' type='chat'>"
"<body>Outgoing 1</body>"
"</message>"));
stbbr_send(
"<message id='message1' to='stabber@localhost' from='buddy1@localhost/laptop' type='chat'>"
"<body>From second resource</body>"
"</message>");
assert_true(prof_output_regex("Buddy1/laptop:.+From second resource"));
prof_input("/msg buddy1@localhost Outgoing 2");
assert_true(stbbr_received(
"<message id='*' to='buddy1@localhost/laptop' type='chat'>"
"<body>Outgoing 2</body>"
"</message>"));
}