mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
move fixtures to outer scope
This commit is contained in:
parent
c20eddeb38
commit
43d06369bf
@ -1,5 +1,7 @@
|
|||||||
include $(top_srcdir)/utils/glib-tap.mk
|
include $(top_srcdir)/utils/glib-tap.mk
|
||||||
|
|
||||||
|
PACKAGE_STRING=irc/core
|
||||||
|
|
||||||
AM_CPPFLAGS = \
|
AM_CPPFLAGS = \
|
||||||
-I$(top_srcdir)/src \
|
-I$(top_srcdir)/src \
|
||||||
-I$(top_srcdir)/src/core \
|
-I$(top_srcdir)/src/core \
|
||||||
@ -17,21 +19,11 @@ test_irc_DEPENDENCIES = \
|
|||||||
../../../src/lib-config/libirssi_config.a
|
../../../src/lib-config/libirssi_config.a
|
||||||
|
|
||||||
test_irc_LDADD = \
|
test_irc_LDADD = \
|
||||||
|
../../../src/irc/core/libirc_core.a \
|
||||||
../../../src/core/libcore.a \
|
../../../src/core/libcore.a \
|
||||||
../../../src/lib-config/libirssi_config.a \
|
../../../src/lib-config/libirssi_config.a \
|
||||||
@GLIB_LIBS@ \
|
@GLIB_LIBS@ \
|
||||||
@OPENSSL_LIBS@
|
@OPENSSL_LIBS@
|
||||||
|
|
||||||
test_irc_SOURCES = \
|
test_irc_SOURCES = \
|
||||||
test-irc.c \
|
test-irc.c
|
||||||
../../../src/irc/core/irc-cap.c \
|
|
||||||
../../../src/irc/core/irc-nicklist.c \
|
|
||||||
../../../src/irc/core/irc-queries.c \
|
|
||||||
../../../src/irc/core/irc-servers-reconnect.c \
|
|
||||||
../../../src/irc/core/irc-servers-setup.c \
|
|
||||||
../../../src/irc/core/irc-servers.c \
|
|
||||||
../../../src/irc/core/irc.c \
|
|
||||||
../../../src/irc/core/mode-lists.c \
|
|
||||||
../../../src/irc/core/modes.c \
|
|
||||||
../../../src/irc/core/servers-idle.c \
|
|
||||||
../../../src/irc/core/servers-redirect.c
|
|
||||||
|
@ -22,210 +22,210 @@
|
|||||||
#include <irc.h>
|
#include <irc.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static void test_event_get_param(void);
|
typedef struct {
|
||||||
static void test_event_get_params(void);
|
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 main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
g_test_init(&argc, &argv, NULL);
|
g_test_init(&argc, &argv, NULL);
|
||||||
|
|
||||||
g_test_add_func("/test/event_get_param", test_event_get_param);
|
for (i = 0; i < G_N_ELEMENTS(event_get_param_fixtures); i++) {
|
||||||
g_test_add_func("/test/event_get_params", test_event_get_params);
|
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();
|
g_test_set_nonfatal_assertions();
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_event_get_param(void)
|
static void test_event_get_param(const event_get_param_test_case *test)
|
||||||
{
|
{
|
||||||
struct test_case {
|
char *buf, *input, *output;
|
||||||
char const *const description;
|
|
||||||
char const *const input;
|
|
||||||
char const *const input_after;
|
|
||||||
char const *const output;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct test_case const tests[] = {
|
input = buf = g_strdup(test->input);
|
||||||
{
|
output = event_get_param(&input);
|
||||||
.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 = "",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
char *buf = g_malloc0(1024);
|
g_assert_cmpstr(input, ==, test->input_after);
|
||||||
|
g_assert_cmpstr(output, ==, test->output);
|
||||||
int i = 0;
|
|
||||||
for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
|
|
||||||
struct test_case const test = tests[i];
|
|
||||||
|
|
||||||
memcpy(buf, test.input, strlen(test.input)+1);
|
|
||||||
char *input = buf;
|
|
||||||
|
|
||||||
char *const output = event_get_param(&input);
|
|
||||||
|
|
||||||
g_assert_cmpstr(input, ==, test.input_after);
|
|
||||||
g_assert_cmpstr(output, ==, test.output);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free(buf);
|
g_free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_event_get_params(void)
|
static void test_event_get_params(const event_get_params_test_case *test)
|
||||||
{
|
{
|
||||||
struct test_case {
|
char *output0, *output1, *params;
|
||||||
char const *const description;
|
output0 = NULL;
|
||||||
char const *const input;
|
output1 = NULL;
|
||||||
char const *const output0;
|
params = event_get_params(test->input, 2 | PARAM_FLAG_GETREST,
|
||||||
char const *const output1;
|
&output0, &output1);
|
||||||
};
|
|
||||||
|
|
||||||
struct test_case const tests[] = {
|
/* params happens to always point at the first output */
|
||||||
{
|
g_assert_cmpstr(params, ==, test->output0);
|
||||||
.description = "Only a channel",
|
g_assert_cmpstr(output0, ==, test->output0);
|
||||||
.input = "#test",
|
g_assert_cmpstr(output1, ==, test->output1);
|
||||||
.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",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
int i = 0;
|
g_free(params);
|
||||||
for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
|
|
||||||
struct test_case const test = tests[i];
|
|
||||||
|
|
||||||
char *output0 = NULL;
|
|
||||||
char *output1 = NULL;
|
|
||||||
char *const 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user