From c2fa8279933a103d6576d891e85c1801d90c65ef Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 16 Jun 2006 13:48:52 +0200 Subject: Add unit testing infrastructure. --- tests/check_util.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/check_util.c (limited to 'tests/check_util.c') diff --git a/tests/check_util.c b/tests/check_util.c new file mode 100644 index 00000000..52e8174c --- /dev/null +++ b/tests/check_util.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include +#include "irc.h" +#include "set.h" +#include "util.h" + +START_TEST(test_strip_linefeed) +{ + int i; + const char *get[] = { "Test", "Test\r", "Test\rX\r", NULL }; + const char *expected[] = { "Test", "Test", "TestX", NULL }; + + for (i = 0; get[i]; i++) { + char copy[20]; + strcpy(copy, get[i]); + strip_linefeed(copy); + fail_unless (strcmp(copy, expected[i]) == 0, + "(%d) strip_linefeed broken: %s -> %s (expected: %s)", + i, get[i], copy, expected[i]); + } +} +END_TEST + +Suite *util_suite (void) +{ + Suite *s = suite_create("Util"); + TCase *tc_core = tcase_create("Core"); + suite_add_tcase (s, tc_core); + tcase_add_test (tc_core, test_strip_linefeed); + return s; +} -- cgit v1.2.3 From 1fc2958b1e503b782081692c1a503bc7bba19fe1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 16 Jun 2006 14:07:51 +0200 Subject: Add checks for nick functions as well, fix bug where nick lengths weren't being honored. --- tests/check_util.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/check_util.c') diff --git a/tests/check_util.c b/tests/check_util.c index 52e8174c..e771238f 100644 --- a/tests/check_util.c +++ b/tests/check_util.c @@ -24,11 +24,30 @@ START_TEST(test_strip_linefeed) } END_TEST +START_TEST(test_strip_newlines) +{ + int i; + const char *get[] = { "Test", "Test\r\n", "Test\nX\n", NULL }; + const char *expected[] = { "Test", "Test ", "Test X ", NULL }; + + for (i = 0; get[i]; i++) { + char copy[20], *ret; + strcpy(copy, get[i]); + ret = strip_newlines(copy); + fail_unless (strcmp(copy, expected[i]) == 0, + "(%d) strip_newlines broken: %s -> %s (expected: %s)", + i, get[i], copy, expected[i]); + fail_unless (copy == ret, "Original string not returned"); + } +} +END_TEST + Suite *util_suite (void) { Suite *s = suite_create("Util"); TCase *tc_core = tcase_create("Core"); suite_add_tcase (s, tc_core); tcase_add_test (tc_core, test_strip_linefeed); + tcase_add_test (tc_core, test_strip_newlines); return s; } -- cgit v1.2.3 From 2c7df621d2337437a46b0ccee6a7801bc04db8f4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 6 Dec 2006 13:15:09 +0100 Subject: Fix testsuite. --- tests/check_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/check_util.c') diff --git a/tests/check_util.c b/tests/check_util.c index e771238f..ee365735 100644 --- a/tests/check_util.c +++ b/tests/check_util.c @@ -5,7 +5,7 @@ #include #include "irc.h" #include "set.h" -#include "util.h" +#include "misc.h" START_TEST(test_strip_linefeed) { -- cgit v1.2.3 From 7bee5af91e56f1e58232b895fd40c367aec67e8a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 24 Dec 2006 22:47:18 +0100 Subject: Add tests for set_url(). Fixed a bug where the default port wasn't set when socks5 was used. --- tests/check_util.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'tests/check_util.c') diff --git a/tests/check_util.c b/tests/check_util.c index ee365735..284ddba3 100644 --- a/tests/check_util.c +++ b/tests/check_util.c @@ -6,6 +6,7 @@ #include "irc.h" #include "set.h" #include "misc.h" +#include "url.h" START_TEST(test_strip_linefeed) { @@ -42,6 +43,66 @@ START_TEST(test_strip_newlines) } END_TEST +START_TEST(test_set_url_http) + url_t url; + + fail_if (0 == url_set(&url, "http://host/")); + fail_unless (!strcmp(url.host, "host")); + fail_unless (!strcmp(url.file, "/")); + fail_unless (!strcmp(url.user, "")); + fail_unless (!strcmp(url.pass, "")); + fail_unless (url.proto == PROTO_HTTP); + fail_unless (url.port == 80); +END_TEST + +START_TEST(test_set_url_https) + url_t url; + + fail_if (0 == url_set(&url, "https://ahost/AimeeMann")); + fail_unless (!strcmp(url.host, "ahost")); + fail_unless (!strcmp(url.file, "/AimeeMann")); + fail_unless (!strcmp(url.user, "")); + fail_unless (!strcmp(url.pass, "")); + fail_unless (url.proto == PROTO_HTTPS); + fail_unless (url.port == 443); +END_TEST + +START_TEST(test_set_url_port) + url_t url; + + fail_if (0 == url_set(&url, "https://ahost:200/Lost/In/Space")); + fail_unless (!strcmp(url.host, "ahost")); + fail_unless (!strcmp(url.file, "/Lost/In/Space")); + fail_unless (!strcmp(url.user, "")); + fail_unless (!strcmp(url.pass, "")); + fail_unless (url.proto == PROTO_HTTPS); + fail_unless (url.port == 200); +END_TEST + +START_TEST(test_set_url_username) + url_t url; + + fail_if (0 == url_set(&url, "socks4://user@ahost/Space")); + fail_unless (!strcmp(url.host, "ahost")); + fail_unless (!strcmp(url.file, "/Space")); + fail_unless (!strcmp(url.user, "user")); + fail_unless (!strcmp(url.pass, "")); + fail_unless (url.proto == PROTO_SOCKS4); + fail_unless (url.port == 1080); +END_TEST + +START_TEST(test_set_url_username_pwd) + url_t url; + + fail_if (0 == url_set(&url, "socks5://user:pass@ahost/")); + fail_unless (!strcmp(url.host, "ahost")); + fail_unless (!strcmp(url.file, "/")); + fail_unless (!strcmp(url.user, "user")); + fail_unless (!strcmp(url.pass, "pass")); + fail_unless (url.proto == PROTO_SOCKS5); + fail_unless (url.port == 1080); +END_TEST + Suite *util_suite (void) { Suite *s = suite_create("Util"); @@ -49,5 +110,10 @@ Suite *util_suite (void) suite_add_tcase (s, tc_core); tcase_add_test (tc_core, test_strip_linefeed); tcase_add_test (tc_core, test_strip_newlines); + tcase_add_test (tc_core, test_set_url_http); + tcase_add_test (tc_core, test_set_url_https); + tcase_add_test (tc_core, test_set_url_port); + tcase_add_test (tc_core, test_set_url_username); + tcase_add_test (tc_core, test_set_url_username_pwd); return s; } -- cgit v1.2.3 From d444c09e6c7ac6fc3c1686af0e63c09805d8cd00 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Fri, 12 Oct 2007 01:06:50 +0100 Subject: Added word_wrap() function to misc.c and using it at the right places so that long messages in groupchats also get wrapped properly (instead of truncated). --- tests/check_util.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'tests/check_util.c') diff --git a/tests/check_util.c b/tests/check_util.c index 284ddba3..b00d645b 100644 --- a/tests/check_util.c +++ b/tests/check_util.c @@ -103,6 +103,63 @@ START_TEST(test_set_url_username_pwd) fail_unless (url.port == 1080); END_TEST +struct +{ + char *orig; + int line_len; + char *wrapped; +} word_wrap_tests[] = { + { + "Line-wrapping is not as easy as it seems?", + 16, + "Line-wrapping is\nnot as easy as\nit seems?" + }, + { + "Line-wrapping is not as easy as it seems?", + 8, + "Line-\nwrapping\nis not\nas easy\nas it\nseems?" + }, + { + "Line-wrapping is\nnot as easy as it seems?", + 8, + "Line-\nwrapping\nis\nnot as\neasy as\nit\nseems?" + }, + { + "a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa", + 5, + "a aa\naaa\naaaa\naaaaa\naaaaa\na\naaaaa\naa\naaaaa\naaa", + }, + { + "aaaaaaaa aaaaaaa aaaaaa aaaaa aaaa aaa aa a", + 5, + "aaaaa\naaa\naaaaa\naa\naaaaa\na\naaaaa\naaaa\naaa\naa a", + }, + { + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + 5, + "aaaaa\naaaaa\naaaaa\naaaaa\naaaaa\naaaaa\naaaaa\na", + }, + { + NULL + } +}; + +START_TEST(test_word_wrap) + int i; + + for( i = 0; word_wrap_tests[i].orig && *word_wrap_tests[i].orig; i ++ ) + { + char *wrapped = word_wrap( word_wrap_tests[i].orig, word_wrap_tests[i].line_len ); + + fail_unless( strcmp( word_wrap_tests[i].wrapped, wrapped ) == 0, + "%s (line_len = %d) should wrap to `%s', not to `%s'", + word_wrap_tests[i].orig, word_wrap_tests[i].line_len, + word_wrap_tests[i].wrapped, wrapped ); + + g_free( wrapped ); + } +END_TEST + Suite *util_suite (void) { Suite *s = suite_create("Util"); @@ -115,5 +172,6 @@ Suite *util_suite (void) tcase_add_test (tc_core, test_set_url_port); tcase_add_test (tc_core, test_set_url_username); tcase_add_test (tc_core, test_set_url_username_pwd); + tcase_add_test (tc_core, test_word_wrap); return s; } -- cgit v1.2.3