summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2017-11-26 21:10:49 +0100
committerailin-nemui <ailin-nemui@users.noreply.github.com>2017-12-07 12:06:20 +0100
commitd932e6e4b78383e0874721a76a8480a9a7e03667 (patch)
tree42f5e3cbafafcf2ae33f0843f8079aad4d0e820b /tests
parent43d06369bf8e5c5e470dc2b00656ddcdb9ee0480 (diff)
downloadirssi-d932e6e4b78383e0874721a76a8480a9a7e03667.zip
add test case for format_real_length
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am2
-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
4 files changed, 80 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 58c348df..e16d190e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1 +1 @@
-SUBDIRS = irc
+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;
+}