1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-10-27 20:30:13 -04:00

Added regex output matcher, presence test

This commit is contained in:
James Booth 2015-05-29 01:01:34 +01:00
parent f17afcf5d4
commit a522d0225d
9 changed files with 80 additions and 15 deletions

View File

@ -99,6 +99,7 @@ functionaltest_sources = \
functionaltests/test_connect.c functionaltests/test_connect.h \
functionaltests/test_ping.c functionaltests/test_ping.h \
functionaltests/test_rooms.c functionaltests/test_rooms.h \
functionaltests/test_presence.c functionaltests/test_presence.h \
functionaltests/functionaltests.c
main_source = src/main.c

View File

@ -13,6 +13,7 @@
#include "test_connect.h"
#include "test_ping.h"
#include "test_rooms.h"
#include "test_presence.h"
int main(int argc, char* argv[]) {
@ -47,6 +48,13 @@ int main(int argc, char* argv[]) {
unit_test_setup_teardown(rooms_query,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(presence_away,
init_prof_test,
close_prof_test),
unit_test_setup_teardown(presence_away_with_message,
init_prof_test,
close_prof_test),
};
return run_tests(all_tests);

View File

@ -178,11 +178,17 @@ prof_input(char *input)
}
int
prof_output(char *text)
prof_output_exact(char *text)
{
return (1 == exp_expectl(fd, exp_exact, text, 1, exp_end));
}
int
prof_output_regex(char *text)
{
return (1 == exp_expectl(fd, exp_regexp, text, 1, exp_end));
}
void
prof_connect(char *jid, char *password)
{

View File

@ -7,10 +7,11 @@
void init_prof_test(void **state);
void close_prof_test(void **state);
void prof_start(void);
void prof_connect(char *jid, char *password);
void prof_input(char *input);
int prof_output(char *text);
int prof_output_exact(char *text);
int prof_output_regex(char *text);
#endif

View File

@ -16,8 +16,8 @@ connect_jid(void **state)
{
prof_connect("stabber@localhost", "password");
assert_true(prof_output("Connecting as stabber@localhost"));
assert_true(prof_output("stabber@localhost logged in successfully"));
assert_true(prof_output_exact("Connecting as stabber@localhost"));
assert_true(prof_output_regex("stabber@localhost logged in successfully, .+online.+ \\(priority 0\\)\\."));
}
void
@ -70,7 +70,7 @@ connect_bad_password(void **state)
{
prof_connect("stabber@localhost", "badpassword");
assert_true(prof_output("Login failed."));
assert_true(prof_output_exact("Login failed."));
}
void
@ -102,9 +102,9 @@ connect_shows_presence_updates(void **state)
prof_connect("stabber@localhost", "password");
assert_true(prof_output("Buddy1 (mobile) is dnd, \"busy!\""));
assert_true(prof_output("Buddy1 (laptop) is chat, \"Talk to me!\""));
assert_true(prof_output("Buddy2 (work) is away, \"Out of office\""));
assert_true(prof_output_exact("Buddy1 (mobile) is dnd, \"busy!\""));
assert_true(prof_output_exact("Buddy1 (laptop) is chat, \"Talk to me!\""));
assert_true(prof_output_exact("Buddy2 (work) is away, \"Out of office\""));
stbbr_send(
"<presence to=\"stabber@localhost\" from=\"buddy1@localhost/mobile\">"
@ -113,5 +113,5 @@ connect_shows_presence_updates(void **state)
"</presence>"
);
assert_true(prof_output("Buddy1 (mobile) is xa, \"Gone :(\""));
assert_true(prof_output_exact("Buddy1 (mobile) is xa, \"Gone :(\""));
}

View File

@ -29,7 +29,7 @@ ping_multiple(void **state)
"<ping xmlns=\"urn:xmpp:ping\"/>"
"</iq>"
));
assert_true(prof_output("Ping response from server"));
assert_true(prof_output_exact("Ping response from server"));
prof_input("/ping");
assert_true(stbbr_received(
@ -37,7 +37,7 @@ ping_multiple(void **state)
"<ping xmlns=\"urn:xmpp:ping\"/>"
"</iq>"
));
assert_true(prof_output("Ping response from server"));
assert_true(prof_output_exact("Ping response from server"));
}
void
@ -45,7 +45,7 @@ ping_responds(void **state)
{
prof_connect("stabber@localhost", "password");
assert_true(prof_output("stabber@localhost logged in successfully"));
assert_true(prof_output_exact("stabber@localhost logged in successfully"));
stbbr_send(
"<iq id=\"pingtest1\" type=\"get\" to=\"stabber@localhost/profanity\" from=\"localhost\">"

View File

@ -0,0 +1,47 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <stabber.h>
#include <expect.h>
#include "proftest.h"
void
presence_away(void **state)
{
prof_connect("stabber@localhost", "password");
prof_input("/away");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<show>away</show>"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
assert_true(prof_output_exact("Status set to away (priority 0)"));
}
void
presence_away_with_message(void **state)
{
prof_connect("stabber@localhost", "password");
prof_input("/away \"I'm not here for a bit\"");
assert_true(stbbr_received(
"<presence id=\"*\">"
"<show>away</show>"
"<status>I'm not here for a bit</status>"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
"</presence>"
));
assert_true(prof_output_exact("Status set to away (priority 0), \"I'm not here for a bit\"."));
}

View File

@ -0,0 +1,2 @@
void presence_away(void **state);
void presence_away_with_message(void **state);

View File

@ -33,6 +33,6 @@ rooms_query(void **state)
"</iq>"
));
assert_true(prof_output("chatroom@conference.localhost, (A chat room)"));
assert_true(prof_output("hangout@conference.localhost, (Another chat room)"));
assert_true(prof_output_exact("chatroom@conference.localhost, (A chat room)"));
assert_true(prof_output_exact("hangout@conference.localhost, (Another chat room)"));
}