aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2007-10-07 22:45:41 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2007-10-07 22:45:41 +0100
commit2305488d0a81193648dec7304f5a6a768e0c926b (patch)
tree4e6d1662e9ae974f32c8c759e62ed053d9ab3e8c /tests
parenta7b59252ddd85810c3b14357fd43602c800b9cb6 (diff)
Adding test for arc.c so that I can now safely replace the RC4 code with a
(compatible) ArcFour implementation.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile2
-rw-r--r--tests/check.c4
-rw-r--r--tests/check_arc.c95
3 files changed, 100 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..a9bc2770
--- /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
+{
+ const 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;
+}