summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/fe-common/Makefile.am1
-rw-r--r--tests/fe-common/core/Makefile.am28
-rw-r--r--tests/fe-common/core/test-formats.c50
-rw-r--r--tests/irc/Makefile.am1
-rw-r--r--tests/irc/core/Makefile.am29
-rw-r--r--tests/irc/core/test-irc.c231
7 files changed, 341 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 00000000..e16d190e
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = fe-common irc
diff --git a/tests/fe-common/Makefile.am b/tests/fe-common/Makefile.am
new file mode 100644
index 00000000..52770885
--- /dev/null
+++ b/tests/fe-common/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = core
diff --git a/tests/fe-common/core/Makefile.am b/tests/fe-common/core/Makefile.am
new file mode 100644
index 00000000..070b6052
--- /dev/null
+++ b/tests/fe-common/core/Makefile.am
@@ -0,0 +1,28 @@
+include $(top_srcdir)/utils/glib-tap.mk
+
+PACKAGE_STRING=fe-common/core
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/src \
+ -I$(top_srcdir)/src/core \
+ $(GLIB_CFLAGS)
+
+test_programs = test-formats
+
+test_formats_CPPFLAGS = \
+ -I$(top_srcdir)/src/fe-common/core \
+ $(AM_CPPFLAGS)
+
+test_formats_DEPENDENCIES = \
+ ../../../src/core/libcore.a \
+ ../../../src/lib-config/libirssi_config.a
+
+test_formats_LDADD = \
+ ../../../src/fe-common/core/libfe_common_core.a \
+ ../../../src/core/libcore.a \
+ ../../../src/lib-config/libirssi_config.a \
+ @GLIB_LIBS@ \
+ @OPENSSL_LIBS@
+
+test_formats_SOURCES = \
+ test-formats.c
diff --git a/tests/fe-common/core/test-formats.c b/tests/fe-common/core/test-formats.c
new file mode 100644
index 00000000..9ef23fd6
--- /dev/null
+++ b/tests/fe-common/core/test-formats.c
@@ -0,0 +1,50 @@
+#include "common.h"
+#include "formats.h"
+
+#define MAX_LENGTH 5
+
+typedef struct {
+ char const *const description;
+ char const *const input;
+ int const result[ MAX_LENGTH ];
+} format_real_length_test_case;
+
+static void test_format_real_length(const format_real_length_test_case *test);
+
+format_real_length_test_case const format_real_length_fixtures[] = {
+ {
+ .description = "",
+ .input = "%4%w ",
+ .result = { 0, 5, 5, -1 },
+ },
+};
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ g_test_init(&argc, &argv, NULL);
+
+ for (i = 0; i < G_N_ELEMENTS(format_real_length_fixtures); i++) {
+ char *name = g_strdup_printf("/test/format_real_length/%d", i);
+ g_test_add_data_func(name, &format_real_length_fixtures[i], (GTestDataFunc)test_format_real_length);
+ g_free(name);
+ }
+
+ g_test_set_nonfatal_assertions();
+ return g_test_run();
+}
+
+static void test_format_real_length(const format_real_length_test_case *test)
+{
+ int j, len;
+
+ g_test_message("Testing format %s", test->input);
+
+ for (j = 0; test->result[j] != -1; j++) {
+ len = format_real_length(test->input, j);
+ g_assert_cmpint(len, ==, test->result[j]);
+ }
+
+ return;
+}
diff --git a/tests/irc/Makefile.am b/tests/irc/Makefile.am
new file mode 100644
index 00000000..52770885
--- /dev/null
+++ b/tests/irc/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = core
diff --git a/tests/irc/core/Makefile.am b/tests/irc/core/Makefile.am
new file mode 100644
index 00000000..ccc6aa97
--- /dev/null
+++ b/tests/irc/core/Makefile.am
@@ -0,0 +1,29 @@
+include $(top_srcdir)/utils/glib-tap.mk
+
+PACKAGE_STRING=irc/core
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/src \
+ -I$(top_srcdir)/src/core \
+ -DSYSCONFDIR=\""$(sysconfdir)"\" \
+ $(GLIB_CFLAGS)
+
+test_programs = test-irc
+
+test_irc_CPPFLAGS = \
+ -I$(top_srcdir)/src/irc/core \
+ $(AM_CPPFLAGS)
+
+test_irc_DEPENDENCIES = \
+ ../../../src/core/libcore.a \
+ ../../../src/lib-config/libirssi_config.a
+
+test_irc_LDADD = \
+ ../../../src/irc/core/libirc_core.a \
+ ../../../src/core/libcore.a \
+ ../../../src/lib-config/libirssi_config.a \
+ @GLIB_LIBS@ \
+ @OPENSSL_LIBS@
+
+test_irc_SOURCES = \
+ test-irc.c
diff --git a/tests/irc/core/test-irc.c b/tests/irc/core/test-irc.c
new file mode 100644
index 00000000..c96956df
--- /dev/null
+++ b/tests/irc/core/test-irc.c
@@ -0,0 +1,231 @@
+/*
+ test-irc.c : irssi
+
+ Copyright (C) 2017 Will Storey
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include <glib.h>
+#include <irc.h>
+#include <string.h>
+
+typedef struct {
+ char const *const description;
+ char const *const input;
+ char const *const input_after;
+ char const *const output;
+} event_get_param_test_case;
+
+event_get_param_test_case const event_get_param_fixtures[] = {
+ {
+ .description = "Zero parameters",
+ .input = "",
+ .input_after = "",
+ .output = "",
+ },
+ {
+ .description = "One parameter",
+ .input = "#test",
+ .input_after = "",
+ .output = "#test",
+ },
+ {
+ .description = "One parameter, trailing space",
+ .input = "#test ",
+ .input_after = "",
+ .output = "#test",
+ },
+ {
+ .description = "One parameter, more trailing space",
+ .input = "#test ",
+ .input_after = " ",
+ .output = "#test",
+ },
+ {
+ .description = "Two parameters",
+ .input = "#test +o",
+ .input_after = "+o",
+ .output = "#test",
+ },
+ {
+ .description = "Two parameters continued",
+ .input = "+o",
+ .input_after = "",
+ .output = "+o",
+ },
+ {
+ .description = "Two parameters with trailing space",
+ .input = "#test +o ",
+ .input_after = "+o ",
+ .output = "#test",
+ },
+ {
+ .description = "Two parameters with trailing space continued",
+ .input = "+o ",
+ .input_after = "",
+ .output = "+o",
+ },
+ {
+ .description = "Two parameters with inline and trailing space",
+ .input = "#test +o ",
+ .input_after = " +o ",
+ .output = "#test",
+ },
+ /* TODO: It seems not ideal that the caller has to deal with inline space.
+ */
+ {
+ .description = "Two parameters with inline and trailing space continued",
+ .input = " +o ",
+ .input_after = "+o ",
+ .output = "",
+ },
+};
+
+static void test_event_get_param(const event_get_param_test_case *test);
+
+typedef struct {
+ char const *const description;
+ char const *const input;
+ char const *const output0;
+ char const *const output1;
+} event_get_params_test_case;
+
+event_get_params_test_case const event_get_params_fixtures[] = {
+ {
+ .description = "Only a channel",
+ .input = "#test",
+ .output0 = "#test",
+ .output1 = "",
+ },
+ {
+ .description = "Only a channel with trailing space",
+ .input = "#test ",
+ .output0 = "#test",
+ .output1 = "",
+ },
+ {
+ .description = "No :<trailing>, channel mode with one parameter after channel name",
+ .input = "#test +i",
+ .output0 = "#test",
+ .output1 = "+i",
+ },
+ {
+ .description = "No :<trailing>, channel mode with two parameters after channel name",
+ .input = "#test +o tester",
+ .output0 = "#test",
+ .output1 = "+o tester",
+ },
+ {
+ .description = "No :<trailing>, channel mode with three parameters afer channel name",
+ .input = "#test +ov tester tester2",
+ .output0 = "#test",
+ .output1 = "+ov tester tester2",
+ },
+ {
+ .description = "No :<trailing>, channel mode with three parameters afer channel name, bunch of extra space",
+ .input = "#test +ov tester tester2 ",
+ .output0 = "#test",
+ .output1 = " +ov tester tester2 ",
+ },
+ {
+ .description = "Channel mode with one parameter after channel name, :<trailing> at the start of modes",
+ .input = "#test :+i",
+ .output0 = "#test",
+ .output1 = "+i",
+ },
+ {
+ .description = "Channel mode with two parameters after channel name, :<trailing> at the start of modes",
+ .input = "#test :+o tester",
+ .output0 = "#test",
+ .output1 = "+o tester",
+ },
+ {
+ .description = "Channel mode with three parameters after channel name, :<trailing> at the start of modes",
+ .input = "#test :+ov tester tester2",
+ .output0 = "#test",
+ .output1 = "+ov tester tester2",
+ },
+ {
+ .description = "Channel mode with two parameters after channel name, :<trailing> on the final parameter",
+ .input = "#test +o :tester",
+ .output0 = "#test",
+ .output1 = "+o tester",
+ },
+ {
+ .description = "Channel mode with three parameters after channel name, :<trailing> on the final parameter",
+ .input = "#test +ov tester :tester2",
+ .output0 = "#test",
+ .output1 = "+ov tester tester2",
+ },
+ {
+ .description = "Channel mode with three parameters after channel name, :<trailing> on the final parameter, also a second : present",
+ .input = "#test +ov tester :tester2 hi:there",
+ .output0 = "#test",
+ .output1 = "+ov tester tester2 hi:there",
+ },
+};
+
+static void test_event_get_params(const event_get_params_test_case *test);
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ g_test_init(&argc, &argv, NULL);
+
+ for (i = 0; i < G_N_ELEMENTS(event_get_params_fixtures); i++) {
+ char *name = g_strdup_printf("/test/event_get_params/%d", i);
+ g_test_add_data_func(name, &event_get_params_fixtures[i], (GTestDataFunc)test_event_get_params);
+ g_free(name);
+ }
+ for (i = 0; i < G_N_ELEMENTS(event_get_param_fixtures); i++) {
+ char *name = g_strdup_printf("/test/event_get_param/%d", i);
+ g_test_add_data_func(name, &event_get_param_fixtures[i], (GTestDataFunc)test_event_get_param);
+ g_free(name);
+ }
+
+ g_test_set_nonfatal_assertions();
+ return g_test_run();
+}
+
+static void test_event_get_param(const event_get_param_test_case *test)
+{
+ char *buf, *input, *output;
+
+ input = buf = g_strdup(test->input);
+ output = event_get_param(&input);
+
+ g_assert_cmpstr(input, ==, test->input_after);
+ g_assert_cmpstr(output, ==, test->output);
+
+ g_free(buf);
+}
+
+static void test_event_get_params(const event_get_params_test_case *test)
+{
+ char *output0, *output1, *params;
+ output0 = NULL;
+ output1 = NULL;
+ params = event_get_params(test->input, 2 | PARAM_FLAG_GETREST,
+ &output0, &output1);
+
+ /* params happens to always point at the first output */
+ g_assert_cmpstr(params, ==, test->output0);
+ g_assert_cmpstr(output0, ==, test->output0);
+ g_assert_cmpstr(output1, ==, test->output1);
+
+ g_free(params);
+}