/pidgin/main: d6c01a08fde7: Add tests for md4 and sha1
Gary Kramlich
grim at reaperworld.com
Wed Mar 30 19:25:27 EDT 2016
Changeset: d6c01a08fde7a3a4c1ca9adaa59c5f35c67dcafb
Author: Gary Kramlich <grim at reaperworld.com>
Date: 2016-03-09 22:19 -0600
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/d6c01a08fde7
Description:
Add tests for md4 and sha1
diffstat:
libpurple/tests/Makefile.am | 10 ++++-
libpurple/tests/test_md4hash.c | 85 +++++++++++++++++++++++++++++++++++++++++
libpurple/tests/test_sha1hash.c | 79 ++++++++++++++++++++++++++++++++++++++
3 files changed, 173 insertions(+), 1 deletions(-)
diffs (198 lines):
diff --git a/libpurple/tests/Makefile.am b/libpurple/tests/Makefile.am
--- a/libpurple/tests/Makefile.am
+++ b/libpurple/tests/Makefile.am
@@ -6,11 +6,19 @@ COMMON_LIBS=\
$(GPLUGIN_LIBS)
test_programs=\
- test_md5hash
+ test_md4hash \
+ test_md5hash \
+ test_sha1hash
+
+test_md4hash_SOURCES=test_md4hash.c
+test_md4hash_LDADD=$(COMMON_LIBS)
test_md5hash_SOURCES=test_md5hash.c
test_md5hash_LDADD=$(COMMON_LIBS)
+test_sha1hash_SOURCES=test_sha1hash.c
+test_sha1hash_LDADD=$(COMMON_LIBS)
+
AM_CPPFLAGS = \
-I$(top_srcdir)/libpurple \
-I$(top_builddir)/libpurple \
diff --git a/libpurple/tests/test_md4hash.c b/libpurple/tests/test_md4hash.c
new file mode 100644
--- /dev/null
+++ b/libpurple/tests/test_md4hash.c
@@ -0,0 +1,85 @@
+#include <glib.h>
+
+#include <purple.h>
+
+#include "ciphers/md4hash.h"
+
+static void
+test_md4hash(gchar *data, gchar *digest) {
+ PurpleHash *hash = NULL;
+ gchar cdigest[33];
+ gboolean ret = FALSE;
+
+ hash = purple_md4_hash_new();
+
+ purple_hash_append(hash, (guchar *)data, strlen(data));
+
+ ret = purple_hash_digest_to_str(hash, cdigest, sizeof(cdigest));
+
+ g_assert(ret);
+ g_assert_cmpstr(digest, ==, cdigest);
+}
+
+static void
+test_md4hash_empty_string(void) {
+ test_md4hash("",
+ "31d6cfe0d16ae931b73c59d7e0c089c0");
+}
+
+static void
+test_md4hash_a(void) {
+ test_md4hash("a",
+ "bde52cb31de33e46245e05fbdbd6fb24");
+}
+
+static void
+test_md4hash_abc(void) {
+ test_md4hash("abc",
+ "a448017aaf21d8525fc10ae87aa6729d");
+}
+
+static void
+test_md4hash_message_digest(void) {
+ test_md4hash("message digest",
+ "d9130a8164549fe818874806e1c7014b");
+}
+
+static void
+test_md4hash_a_to_z(void) {
+ test_md4hash("abcdefghijklmnopqrstuvwxyz",
+ "d79e1c308aa5bbcdeea8ed63df412da9");
+}
+
+static void
+test_md4hash_A_to_Z_a_to_z_0_to_9(void) {
+ test_md4hash("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+ "043f8582f241db351ce627e153e7f0e4");
+}
+
+static void
+test_md4hash_1_to_0_eight_times(void) {
+ test_md4hash("12345678901234567890123456789012345678901234567890123456789012345678901234567890",
+ "e33b4ddc9c38f2199c3e7b164fcc0536");
+}
+
+gint
+main(gint argc, gchar **argv) {
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/hash/md4/empty-string",
+ test_md4hash_empty_string);
+ g_test_add_func("/hash/md4/a",
+ test_md4hash_a);
+ g_test_add_func("/hash/md4/abc",
+ test_md4hash_abc);
+ g_test_add_func("/hash/md4/message digest",
+ test_md4hash_message_digest);
+ g_test_add_func("/hash/md4/a to z",
+ test_md4hash_a_to_z);
+ g_test_add_func("/hash/md4/A to Z, a to z, 0 to 9" ,
+ test_md4hash_A_to_Z_a_to_z_0_to_9);
+ g_test_add_func("/hash/md4/1 to 0 eight times",
+ test_md4hash_1_to_0_eight_times);
+
+ return g_test_run();
+}
diff --git a/libpurple/tests/test_sha1hash.c b/libpurple/tests/test_sha1hash.c
new file mode 100644
--- /dev/null
+++ b/libpurple/tests/test_sha1hash.c
@@ -0,0 +1,79 @@
+#include <glib.h>
+
+#include <purple.h>
+
+#include "ciphers/sha1hash.h"
+
+static void
+test_sha1hash(gchar *data, gchar *digest) {
+ PurpleHash *hash = NULL;
+ gchar cdigest[41];
+ gboolean ret = FALSE;
+
+ hash = purple_sha1_hash_new();
+
+ if(data) {
+ purple_hash_append(hash, (guchar *)data, strlen(data));
+ } else {
+ gint j;
+ guchar buff[1000];
+
+ memset(buff, 'a', 1000);
+
+ for(j = 0; j < 1000; j++)
+ purple_hash_append(hash, buff, 1000);
+ }
+
+ ret = purple_hash_digest_to_str(hash, cdigest, sizeof(cdigest));
+
+ g_assert(ret);
+ g_assert_cmpstr(digest, ==, cdigest);
+}
+
+static void
+test_sha1hash_empty_string(void) {
+ test_sha1hash("",
+ "da39a3ee5e6b4b0d3255bfef95601890afd80709");
+}
+
+static void
+test_sha1hash_a(void) {
+ test_sha1hash("a",
+ "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8");
+}
+
+static void
+test_sha1hash_abc(void) {
+ test_sha1hash("abc",
+ "a9993e364706816aba3e25717850c26c9cd0d89d");
+}
+
+static void
+test_sha1hash_abcd_gibberish(void) {
+ test_sha1hash("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ "84983e441c3bd26ebaae4aa1f95129e5e54670f1");
+}
+
+static void
+test_sha1hash_1000_as_1000_times(void) {
+ test_sha1hash(NULL,
+ "34aa973cd4c4daa4f61eeb2bdbad27316534016f");
+}
+
+gint
+main(gint argc, gchar **argv) {
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/hash/sha1/empty-string",
+ test_sha1hash_empty_string);
+ g_test_add_func("/hash/sha1/a",
+ test_sha1hash_a);
+ g_test_add_func("/hash/sha1/abc",
+ test_sha1hash_abc);
+ g_test_add_func("/hash/sha1/abcd_gibberish",
+ test_sha1hash_abcd_gibberish);
+ g_test_add_func("/hash/sha1/1000 a's 1000 times",
+ test_sha1hash_1000_as_1000_times);
+
+ return g_test_run();
+}
More information about the Commits
mailing list