Renamed stabbertests -> functionaltests
This commit is contained in:
49
functionaltests/functionaltests.c
Normal file
49
functionaltests/functionaltests.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "proftest.h"
|
||||
#include "test_connect.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
const UnitTest all_tests[] = {
|
||||
|
||||
unit_test_setup_teardown(connect_jid,
|
||||
init_prof_test,
|
||||
close_prof_test),
|
||||
unit_test_setup_teardown(connect_jid_requests_roster,
|
||||
init_prof_test,
|
||||
close_prof_test),
|
||||
unit_test_setup_teardown(connect_jid_sends_presence_after_receiving_roster,
|
||||
init_prof_test,
|
||||
close_prof_test),
|
||||
unit_test_setup_teardown(connect_jid_requests_bookmarks,
|
||||
init_prof_test,
|
||||
close_prof_test),
|
||||
unit_test_setup_teardown(connect_bad_password,
|
||||
init_prof_test,
|
||||
close_prof_test),
|
||||
unit_test_setup_teardown(show_presence_updates,
|
||||
init_prof_test,
|
||||
close_prof_test),
|
||||
unit_test_setup_teardown(sends_rooms_iq,
|
||||
init_prof_test,
|
||||
close_prof_test),
|
||||
unit_test_setup_teardown(multiple_pings,
|
||||
init_prof_test,
|
||||
close_prof_test),
|
||||
unit_test_setup_teardown(responds_to_ping,
|
||||
init_prof_test,
|
||||
close_prof_test),
|
||||
};
|
||||
|
||||
return run_tests(all_tests);
|
||||
}
|
||||
185
functionaltests/proftest.c
Normal file
185
functionaltests/proftest.c
Normal file
@@ -0,0 +1,185 @@
|
||||
#include <sys/stat.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <cmocka.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <stabber.h>
|
||||
#include <expect.h>
|
||||
|
||||
#define XDG_CONFIG_HOME "./stabbertests/files/xdg_config_home"
|
||||
#define XDG_DATA_HOME "./stabbertests/files/xdg_data_home"
|
||||
|
||||
char *config_orig;
|
||||
char *data_orig;
|
||||
|
||||
int fd = 0;
|
||||
|
||||
gboolean
|
||||
_create_dir(char *name)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
if (stat(name, &sb) != 0) {
|
||||
if (errno != ENOENT || mkdir(name, S_IRWXU) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
if ((sb.st_mode & S_IFDIR) != S_IFDIR) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_mkdir_recursive(const char *dir)
|
||||
{
|
||||
int i;
|
||||
gboolean result = TRUE;
|
||||
|
||||
for (i = 1; i <= strlen(dir); i++) {
|
||||
if (dir[i] == '/' || dir[i] == '\0') {
|
||||
gchar *next_dir = g_strndup(dir, i);
|
||||
result = _create_dir(next_dir);
|
||||
g_free(next_dir);
|
||||
if (!result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
_create_config_dir(void)
|
||||
{
|
||||
GString *profanity_dir = g_string_new(XDG_CONFIG_HOME);
|
||||
g_string_append(profanity_dir, "/profanity");
|
||||
|
||||
if (!_mkdir_recursive(profanity_dir->str)) {
|
||||
assert_true(FALSE);
|
||||
}
|
||||
|
||||
g_string_free(profanity_dir, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
_create_data_dir(void)
|
||||
{
|
||||
GString *profanity_dir = g_string_new(XDG_DATA_HOME);
|
||||
g_string_append(profanity_dir, "/profanity");
|
||||
|
||||
if (!_mkdir_recursive(profanity_dir->str)) {
|
||||
assert_true(FALSE);
|
||||
}
|
||||
|
||||
g_string_free(profanity_dir, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
_create_chatlogs_dir(void)
|
||||
{
|
||||
GString *chatlogs_dir = g_string_new(XDG_DATA_HOME);
|
||||
g_string_append(chatlogs_dir, "/profanity/chatlogs");
|
||||
|
||||
if (!_mkdir_recursive(chatlogs_dir->str)) {
|
||||
assert_true(FALSE);
|
||||
}
|
||||
|
||||
g_string_free(chatlogs_dir, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
_create_logs_dir(void)
|
||||
{
|
||||
GString *logs_dir = g_string_new(XDG_DATA_HOME);
|
||||
g_string_append(logs_dir, "/profanity/logs");
|
||||
|
||||
if (!_mkdir_recursive(logs_dir->str)) {
|
||||
assert_true(FALSE);
|
||||
}
|
||||
|
||||
g_string_free(logs_dir, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
_cleanup_dirs(void)
|
||||
{
|
||||
int res = system("rm -rf ./stabbertests/files");
|
||||
if (res == -1) {
|
||||
assert_true(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prof_start(void)
|
||||
{
|
||||
fd = exp_spawnl("./profanity", NULL);
|
||||
FILE *fp = fdopen(fd, "r+");
|
||||
|
||||
if (fp == NULL) {
|
||||
assert_true(FALSE);
|
||||
}
|
||||
|
||||
setbuf(fp, (char *)0);
|
||||
}
|
||||
|
||||
void
|
||||
init_prof_test(void **state)
|
||||
{
|
||||
if (stbbr_start(5230) != 0) {
|
||||
assert_true(FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
config_orig = getenv("XDG_CONFIG_HOME");
|
||||
data_orig = getenv("XDG_DATA_HOME");
|
||||
|
||||
setenv("XDG_CONFIG_HOME", XDG_CONFIG_HOME, 1);
|
||||
setenv("XDG_DATA_HOME", XDG_DATA_HOME, 1);
|
||||
|
||||
_cleanup_dirs();
|
||||
|
||||
_create_config_dir();
|
||||
_create_data_dir();
|
||||
_create_chatlogs_dir();
|
||||
_create_logs_dir();
|
||||
|
||||
prof_start();
|
||||
}
|
||||
|
||||
void
|
||||
close_prof_test(void **state)
|
||||
{
|
||||
_cleanup_dirs();
|
||||
|
||||
setenv("XDG_CONFIG_HOME", config_orig, 1);
|
||||
setenv("XDG_DATA_HOME", data_orig, 1);
|
||||
|
||||
stbbr_stop();
|
||||
}
|
||||
|
||||
void
|
||||
prof_input(char *input)
|
||||
{
|
||||
GString *inp_str = g_string_new(input);
|
||||
g_string_append(inp_str, "\r");
|
||||
write(fd, inp_str->str, inp_str->len);
|
||||
g_string_free(inp_str, TRUE);
|
||||
}
|
||||
|
||||
int
|
||||
prof_output(char *text)
|
||||
{
|
||||
return (1 == exp_expectl(fd, exp_exact, text, 1, exp_end));
|
||||
}
|
||||
14
functionaltests/proftest.h
Normal file
14
functionaltests/proftest.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef __H_PROFTEST
|
||||
#define __H_PROFTEST
|
||||
|
||||
#define XDG_CONFIG_HOME "./stabbertests/files/xdg_config_home"
|
||||
#define XDG_DATA_HOME "./stabbertests/files/xdg_data_home"
|
||||
|
||||
void init_prof_test(void **state);
|
||||
void close_prof_test(void **state);
|
||||
|
||||
void prof_start(void);
|
||||
void prof_input(char *input);
|
||||
int prof_output(char *text);
|
||||
|
||||
#endif
|
||||
195
functionaltests/test_connect.c
Normal file
195
functionaltests/test_connect.c
Normal file
@@ -0,0 +1,195 @@
|
||||
#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
|
||||
connect_jid(void **state)
|
||||
{
|
||||
prof_input("/connect stabber@localhost port 5230");
|
||||
prof_input("password");
|
||||
|
||||
assert_true(prof_output("Connecting as stabber@localhost"));
|
||||
assert_true(prof_output("stabber@localhost logged in successfully"));
|
||||
}
|
||||
|
||||
void
|
||||
connect_jid_requests_roster(void **state)
|
||||
{
|
||||
prof_input("/connect stabber@localhost port 5230");
|
||||
prof_input("password");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<iq id=\"*\" type=\"get\"><query xmlns=\"jabber:iq:roster\"/></iq>"
|
||||
));
|
||||
}
|
||||
|
||||
void
|
||||
connect_jid_sends_presence_after_receiving_roster(void **state)
|
||||
{
|
||||
stbbr_for("roster",
|
||||
"<iq id=\"roster\" type=\"result\" to=\"stabber@localhost/profanity\">"
|
||||
"<query xmlns=\"jabber:iq:roster\" ver=\"362\">"
|
||||
"<item jid=\"buddy1@localhost\" subscription=\"both\" name=\"Buddy1\"/>"
|
||||
"<item jid=\"buddy2@localhost\" subscription=\"both\" name=\"Buddy2\"/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_input("/connect stabber@localhost port 5230");
|
||||
prof_input("password");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<presence id=\"*\">"
|
||||
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
|
||||
void
|
||||
connect_jid_requests_bookmarks(void **state)
|
||||
{
|
||||
prof_input("/connect stabber@localhost port 5230");
|
||||
prof_input("password");
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<iq id=\"*\" type=\"get\">"
|
||||
"<query xmlns=\"jabber:iq:private\">"
|
||||
"<storage xmlns=\"storage:bookmarks\"/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
));
|
||||
}
|
||||
|
||||
void
|
||||
connect_bad_password(void **state)
|
||||
{
|
||||
prof_input("/connect stabber@localhost port 5230");
|
||||
prof_input("badpassword");
|
||||
|
||||
assert_true(prof_output("Login failed."));
|
||||
}
|
||||
|
||||
void
|
||||
show_presence_updates(void **state)
|
||||
{
|
||||
stbbr_for("roster",
|
||||
"<iq id=\"roster\" type=\"result\" to=\"stabber@localhost/profanity\">"
|
||||
"<query xmlns=\"jabber:iq:roster\" ver=\"362\">"
|
||||
"<item jid=\"buddy1@localhost\" subscription=\"both\" name=\"Buddy1\"/>"
|
||||
"<item jid=\"buddy2@localhost\" subscription=\"both\" name=\"Buddy2\"/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
stbbr_for("prof_presence_1",
|
||||
"<presence to=\"stabber@localhost\" from=\"buddy1@localhost/mobile\">"
|
||||
"<show>dnd</show>"
|
||||
"<status>busy!</status>"
|
||||
"</presence>"
|
||||
"<presence to=\"stabber@localhost\" from=\"buddy1@localhost/laptop\">"
|
||||
"<show>chat</show>"
|
||||
"<status>Talk to me!</status>"
|
||||
"</presence>"
|
||||
"<presence to=\"stabber@localhost\" from=\"buddy2@localhost/work\">"
|
||||
"<show>away</show>"
|
||||
"<status>Out of office</status>"
|
||||
"</presence>"
|
||||
);
|
||||
|
||||
prof_input("/connect stabber@localhost port 5230");
|
||||
prof_input("password");
|
||||
|
||||
assert_true(prof_output("Buddy1 (mobile) is dnd"));
|
||||
assert_true(prof_output("Buddy1 (laptop) is chat"));
|
||||
assert_true(prof_output("Buddy2 (work) is away"));
|
||||
|
||||
stbbr_send(
|
||||
"<presence to=\"stabber@localhost\" from=\"buddy1@localhost/mobile\">"
|
||||
"<show>xa</show>"
|
||||
"<status>Gone :(</status>"
|
||||
"</presence>"
|
||||
);
|
||||
|
||||
assert_true(prof_output("Buddy1 (mobile) is xa"));
|
||||
}
|
||||
|
||||
void
|
||||
sends_rooms_iq(void **state)
|
||||
{
|
||||
stbbr_for("confreq",
|
||||
"<iq id=\"confreq\" type=\"result\" to=\"stabber@localhost/profanity\" from=\"conference.localhost\">"
|
||||
"<query xmlns=\"http://jabber.org/protocol/disco#items\">"
|
||||
"<item jid=\"chatroom@conference.localhost\" name=\"A chat room\"/>"
|
||||
"<item jid=\"hangout@conference.localhost\" name=\"Another chat room\"/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_input("/connect stabber@localhost port 5230");
|
||||
prof_input("password");
|
||||
prof_input("/rooms");
|
||||
|
||||
assert_true(stbbr_last_received(
|
||||
"<iq id=\"confreq\" to=\"conference.localhost\" type=\"get\">"
|
||||
"<query xmlns=\"http://jabber.org/protocol/disco#items\"/>"
|
||||
"</iq>"
|
||||
));
|
||||
}
|
||||
|
||||
void
|
||||
multiple_pings(void **state)
|
||||
{
|
||||
stbbr_for("prof_ping_1",
|
||||
"<iq id=\"prof_ping_1\" type=\"result\" to=\"stabber@localhost/profanity\"/>"
|
||||
);
|
||||
stbbr_for("prof_ping_2",
|
||||
"<iq id=\"prof_ping_2\" type=\"result\" to=\"stabber@localhost/profanity\"/>"
|
||||
);
|
||||
|
||||
prof_input("/connect stabber@localhost port 5230");
|
||||
prof_input("password");
|
||||
|
||||
prof_input("/ping");
|
||||
assert_true(stbbr_received(
|
||||
"<iq id=\"prof_ping_1\" type=\"get\">"
|
||||
"<ping xmlns=\"urn:xmpp:ping\"/>"
|
||||
"</iq>"
|
||||
));
|
||||
assert_true(prof_output("Ping response from server"));
|
||||
|
||||
prof_input("/ping");
|
||||
assert_true(stbbr_received(
|
||||
"<iq id=\"prof_ping_2\" type=\"get\">"
|
||||
"<ping xmlns=\"urn:xmpp:ping\"/>"
|
||||
"</iq>"
|
||||
));
|
||||
assert_true(prof_output("Ping response from server"));
|
||||
}
|
||||
|
||||
void
|
||||
responds_to_ping(void **state)
|
||||
{
|
||||
prof_input("/connect stabber@localhost port 5230");
|
||||
prof_input("password");
|
||||
|
||||
assert_true(prof_output("stabber@localhost logged in successfully"));
|
||||
|
||||
stbbr_send(
|
||||
"<iq id=\"pingtest1\" type=\"get\" to=\"stabber@localhost/profanity\" from=\"localhost\">"
|
||||
"<ping xmlns=\"urn:xmpp:ping\"/>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<iq id=\"pingtest1\" type=\"result\" from=\"stabber@localhost/profanity\" to=\"localhost\"/>"
|
||||
));
|
||||
}
|
||||
9
functionaltests/test_connect.h
Normal file
9
functionaltests/test_connect.h
Normal file
@@ -0,0 +1,9 @@
|
||||
void connect_jid(void **state);
|
||||
void connect_jid_requests_roster(void **state);
|
||||
void connect_jid_sends_presence_after_receiving_roster(void **state);
|
||||
void connect_jid_requests_bookmarks(void **state);
|
||||
void connect_bad_password(void **state);
|
||||
void show_presence_updates(void **state);
|
||||
void sends_rooms_iq(void **state);
|
||||
void multiple_pings(void **state);
|
||||
void responds_to_ping(void **state);
|
||||
Reference in New Issue
Block a user