pidgin: 936206d0: Add a test for qq's qq_encrypt function....
markdoliner at pidgin.im
markdoliner at pidgin.im
Fri Sep 4 02:25:54 EDT 2009
-----------------------------------------------------------------
Revision: 936206d091ff3e9c3debe99371832583696d47e0
Ancestor: 46d8a163dc067c160f9b228f09d409766d8d1304
Author: markdoliner at pidgin.im
Date: 2009-09-04T06:23:41
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/936206d091ff3e9c3debe99371832583696d47e0
Added files:
libpurple/tests/test_qq.c
Modified files:
libpurple/tests/Makefile.am
libpurple/tests/check_libpurple.c libpurple/tests/tests.h
ChangeLog:
Add a test for qq's qq_encrypt function. Refs #10191. The string of
length 7 demonstrates the bug: 7+16=23, but the qq_encrypt function
at least thinks that it is writing 24 bytes
-------------- next part --------------
============================================================
--- libpurple/tests/test_qq.c 12499f23e7bec479cb06e97c8eb5c462d89f61b4
+++ libpurple/tests/test_qq.c 12499f23e7bec479cb06e97c8eb5c462d89f61b4
@@ -0,0 +1,105 @@
+#include <string.h>
+
+#include "tests.h"
+#include "../protocols/qq/qq_crypt.h"
+
+START_TEST(test_qq_encrypt)
+{
+ const guint8 * const key = (guint8 *)"hamburger";
+ guint8 crypted[80];
+ gint ret;
+
+ ret = qq_encrypt(crypted, (const guint8 * const)"a", 1, key);
+ assert_int_equal(16, ret);
+
+ ret = qq_encrypt(crypted, (const guint8 * const)"aa", 2, key);
+ assert_int_equal(16, ret);
+
+ ret = qq_encrypt(crypted, (const guint8 * const)"aaa", 3, key);
+ assert_int_equal(16, ret);
+
+ ret = qq_encrypt(crypted, (const guint8 * const)"aaaa", 4, key);
+ assert_int_equal(16, ret);
+
+ ret = qq_encrypt(crypted, (const guint8 * const)"aaaaa", 5, key);
+ assert_int_equal(16, ret);
+
+ ret = qq_encrypt(crypted, (const guint8 * const)"aaaaaa", 6, key);
+ assert_int_equal(16, ret);
+
+ ret = qq_encrypt(crypted, (const guint8 * const)"aaaaaaa", 7, key);
+ assert_int_equal(24, ret);
+
+ ret = qq_encrypt(crypted, (const guint8 * const)"aaaaaaaa", 8, key);
+ assert_int_equal(24, ret);
+
+ ret = qq_encrypt(crypted, (const guint8 * const)"aaaaaaaaa", 9, key);
+ assert_int_equal(24, ret);
+
+ ret = qq_encrypt(crypted, (const guint8 * const)"aaaaaaaaaa", 10, key);
+ assert_int_equal(24, ret);
+
+ ret = qq_encrypt(crypted,
+ (const guint8 * const)"aaaaaaaaaaa", 11, key);
+ assert_int_equal(24, ret);
+
+ ret = qq_encrypt(crypted,
+ (const guint8 * const)"aaaaaaaaaaaa", 12, key);
+ assert_int_equal(24, ret);
+
+ ret = qq_encrypt(crypted,
+ (const guint8 * const)"aaaaaaaaaaaaa", 13, key);
+ assert_int_equal(24, ret);
+
+ ret = qq_encrypt(crypted,
+ (const guint8 * const)"aaaaaaaaaaaaaa", 14, key);
+ assert_int_equal(24, ret);
+
+ ret = qq_encrypt(crypted,
+ (const guint8 * const)"aaaaaaaaaaaaaaa", 15, key);
+ assert_int_equal(32, ret);
+
+ ret = qq_encrypt(crypted,
+ (const guint8 * const)"aaaaaaaaaaaaaaaa", 16, key);
+ assert_int_equal(32, ret);
+
+ ret = qq_encrypt(crypted,
+ (const guint8 * const)"aaaaaaaaaaaaaaaaa", 17, key);
+ assert_int_equal(32, ret);
+
+ ret = qq_encrypt(crypted,
+ (const guint8 * const)"aaaaaaaaaaaaaaaaaa", 18, key);
+ assert_int_equal(32, ret);
+
+ ret = qq_encrypt(crypted,
+ (const guint8 * const)"aaaaaaaaaaaaaaaaaaa", 19, key);
+ assert_int_equal(32, ret);
+
+ /*
+ fprintf(stderr, "crypted=%s\n", crypted);
+ assert_string_equal_free("plain",
+ yahoo_codes_to_html("plain"));
+ */
+}
+END_TEST
+
+START_TEST(test_qq_decrypt)
+{
+}
+END_TEST
+
+Suite *
+qq_suite(void)
+{
+ Suite *s;
+ TCase *tc;
+
+ s = suite_create("QQ");
+
+ tc = tcase_create("QQ Crypt Functions");
+ tcase_add_test(tc, test_qq_encrypt);
+ tcase_add_test(tc, test_qq_decrypt);
+ suite_add_tcase(s, tc);
+
+ return s;
+}
============================================================
--- libpurple/tests/Makefile.am 3c59fdff6f6f75ee99c6fedaf880b9be325714e6
+++ libpurple/tests/Makefile.am 1e1c9f89bba8bae601564b5c3db440527eb2ce6a
@@ -11,6 +11,7 @@ check_libpurple_SOURCES=\
tests.h \
test_cipher.c \
test_jabber_jutil.c \
+ test_qq.c \
test_yahoo_util.c \
test_util.c \
$(top_builddir)/libpurple/util.h
@@ -28,6 +29,7 @@ check_libpurple_LDADD=\
@CHECK_LIBS@ \
$(GLIB_LIBS) \
$(top_builddir)/libpurple/protocols/jabber/libjabber.la \
+ $(top_builddir)/libpurple/protocols/qq/libqq.la \
$(top_builddir)/libpurple/protocols/yahoo/libymsg.la \
$(top_builddir)/libpurple/libpurple.la
============================================================
--- libpurple/tests/check_libpurple.c 732ebd80ea0834cd08e7af27d4e595ea52e2ea9f
+++ libpurple/tests/check_libpurple.c 6fac9c92eda65248d2db68ccb7aeb47e74304132
@@ -76,6 +76,7 @@ int main(void)
srunner_add_suite(sr, cipher_suite());
srunner_add_suite(sr, jabber_jutil_suite());
+ srunner_add_suite(sr, qq_suite());
srunner_add_suite(sr, yahoo_util_suite());
srunner_add_suite(sr, util_suite());
============================================================
--- libpurple/tests/tests.h 44fe168b2432ff2dee4157c3be7b891a4203e635
+++ libpurple/tests/tests.h 908fb55f70ed86007d8b1ae085b353048aa8c6bd
@@ -10,10 +10,15 @@ Suite * jabber_jutil_suite(void);
Suite * master_suite(void);
Suite * cipher_suite(void);
Suite * jabber_jutil_suite(void);
+Suite * qq_suite(void);
Suite * yahoo_util_suite(void);
Suite * util_suite(void);
/* helper macros */
+#define assert_int_equal(expected, actual) { \
+ fail_if(expected != actual, "Expecting '%d' but got '%d'", expected, actual); \
+}
+
#define assert_string_equal(expected, actual) { \
const gchar *a = actual; \
fail_unless(strcmp(expected, a) == 0, "Expecting '%s' but got '%s'", expected, a); \
More information about the Commits
mailing list