diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/Makefile | 2 | ||||
| -rw-r--r-- | tests/check.c | 4 | ||||
| -rw-r--r-- | tests/check_arc.c | 95 | ||||
| -rw-r--r-- | tests/check_util.c | 58 | 
4 files changed, 158 insertions, 1 deletions
| diff --git a/tests/Makefile b/tests/Makefile index 4d4ed8d3..5bc3fbde 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -12,7 +12,7 @@ distclean: clean  main_objs = account.o bitlbee.o conf.o crypting.o help.o ipc.o irc.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o storage_xml.o storage_text.o user.o  -test_objs = check.o check_util.o check_nick.o check_md5.o check_irc.o check_help.o check_user.o check_crypting.o check_set.o +test_objs = check.o check_util.o check_nick.o check_md5.o check_arc.o check_irc.o check_help.o check_user.o check_crypting.o check_set.o  check: $(test_objs) $(addprefix ../, $(main_objs)) ../protocols/protocols.o ../lib/lib.o  	@echo '*' Linking $@ diff --git a/tests/check.c b/tests/check.c index 488d9608..043889d6 100644 --- a/tests/check.c +++ b/tests/check.c @@ -47,6 +47,9 @@ Suite *nick_suite(void);  /* From check_md5.c */  Suite *md5_suite(void); +/* From check_arc.c */ +Suite *arc_suite(void); +  /* From check_irc.c */  Suite *irc_suite(void); @@ -101,6 +104,7 @@ int main (int argc, char **argv)  	sr = srunner_create(util_suite());  	srunner_add_suite(sr, nick_suite());  	srunner_add_suite(sr, md5_suite()); +	srunner_add_suite(sr, arc_suite());  	srunner_add_suite(sr, irc_suite());  	srunner_add_suite(sr, help_suite());  	srunner_add_suite(sr, user_suite()); diff --git a/tests/check_arc.c b/tests/check_arc.c new file mode 100644 index 00000000..989a0a66 --- /dev/null +++ b/tests/check_arc.c @@ -0,0 +1,95 @@ +#include <stdlib.h> +#include <glib.h> +#include <gmodule.h> +#include <check.h> +#include <string.h> +#include <stdio.h> +#include "arc.h" + +char *password = "TotT"; + +char *clear_tests[] = +{ +	"Wie dit leest is gek :-)", +	"ItllBeBitlBee", +	"One more boring password", +	NULL +}; + +static void check_codec(int l) +{ +	int i; +	 +	for( i = 0; clear_tests[i]; i++ ) +	{ +  		tcase_fn_start (clear_tests[i], __FILE__, __LINE__); +		unsigned char *crypted; +		char *decrypted; +		int len; +		 +		len = arc_encode( clear_tests[i], 0, &crypted, password ); +		len = arc_decode( crypted, len, &decrypted, password ); +		 +		fail_if( strcmp( clear_tests[i], decrypted ) != 0, +		         "%s didn't decrypt back properly", clear_tests[i] ); +		 +		g_free( crypted ); +		g_free( decrypted ); +	} +} + +struct +{ +	unsigned char crypted[24]; +	int len; +	char *decrypted; +} decrypt_tests[] = { +	{ +		{ +			0xc3, 0x0d, 0x43, 0xc3, 0xee, 0x80, 0xe2, 0x8c, 0x0b, 0x29, 0x32, 0x7e, +			0x38, 0x05, 0x82, 0x10, 0x21, 0x1c, 0x4a, 0x00, 0x2c +		}, 21, "Debugging sucks" +	}, +	{ +		{ +			0xb0, 0x00, 0x57, 0x0d, 0x0d, 0x0d, 0x70, 0xe1, 0xc0, 0x00, 0xa4, 0x25, +			0x7d, 0xbe, 0x03, 0xcc, 0x24, 0xd1, 0x0c +		}, 19, "Testing rocks" +	}, +	{ +		{ +			0xb6, 0x92, 0x59, 0xe4, 0xf9, 0xc1, 0x7a, 0xf6, 0xf3, 0x18, 0xea, 0x28, +			0x73, 0x6d, 0xb3, 0x0a, 0x6f, 0x0a, 0x2b, 0x43, 0x57, 0xe9, 0x3e, 0x63 +		}, 24, "OSCAR is creepy..." +	} +}; + +static void check_decod(int l) +{ +	int i; +	 +	for( i = 0; clear_tests[i]; i++ ) +	{ +  		tcase_fn_start (decrypt_tests[i].decrypted, __FILE__, __LINE__); +		char *decrypted; +		int len; +		 +		len = arc_decode( decrypt_tests[i].crypted, decrypt_tests[i].len, +		                  &decrypted, password ); +		 +		fail_if( strcmp( decrypt_tests[i].decrypted, decrypted ) != 0, +		         "%s didn't decrypt properly", clear_tests[i] ); +		 +		g_free( decrypted ); +	} +} + +Suite *arc_suite (void) +{ +	Suite *s = suite_create("ArcFour"); +	TCase *tc_core = tcase_create("Core"); +	suite_add_tcase (s, tc_core); +	tcase_add_test (tc_core, check_codec); +	tcase_add_test (tc_core, check_decod); +	return s; +} 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;  } | 
