/pidgin/main: 599b01f2f5a7: This should do it for the jabber tests

Gary Kramlich <[email protected]>
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: 599b01f2f5a752a384d41eeb71da62fba52a30c5
Author:	 Gary Kramlich <[email protected]>
Date:	 2016-03-13 17:08 -0500
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/599b01f2f5a7

Description:

This should do it for the jabber tests

diffstat:

 .hgignore                                                 |    1 +
 configure.ac                                              |    1 +
 libpurple/protocols/jabber/Makefile.am                    |    2 +
 libpurple/protocols/jabber/tests/.hgignore                |   10 +
 libpurple/protocols/jabber/tests/Makefile.am              |   37 +
 libpurple/protocols/jabber/tests/test_jabber_caps.c       |   79 +-
 libpurple/protocols/jabber/tests/test_jabber_digest_md5.c |   75 +-
 libpurple/protocols/jabber/tests/test_jabber_jutil.c      |  374 ++++++++-----
 libpurple/protocols/jabber/tests/test_jabber_scram.c      |    0 
 9 files changed, 352 insertions(+), 227 deletions(-)

diffs (truncated from 722 to 300 lines):

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -150,6 +150,7 @@ stamp-h1
 test-driver
 win32-install-dir(\.release)?
 
+subinclude:libpurple/protocols/jabber/tests/.hgignore
 subinclude:libpurple/protocols/oscar/tests/.hgignore
 subinclude:libpurple/protocols/yahoo/tests/.hgignore
 subinclude:libpurple/tests/.hgignore
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -2255,6 +2255,7 @@ AC_CONFIG_FILES([Makefile
 		   libpurple/protocols/gg/Makefile
 		   libpurple/protocols/irc/Makefile
 		   libpurple/protocols/jabber/Makefile
+		   libpurple/protocols/jabber/tests/Makefile
 		   libpurple/protocols/msn/Makefile
 		   libpurple/protocols/mxit/Makefile
 		   libpurple/protocols/novell/Makefile
diff --git a/libpurple/protocols/jabber/Makefile.am b/libpurple/protocols/jabber/Makefile.am
--- a/libpurple/protocols/jabber/Makefile.am
+++ b/libpurple/protocols/jabber/Makefile.am
@@ -137,3 +137,5 @@ AM_CPPFLAGS = \
 	$(LIBXML_CFLAGS) \
 	$(FARSTREAM_CFLAGS) \
 	$(GSTREAMER_CFLAGS)
+
+SUBDIRS = tests
diff --git a/libpurple/protocols/jabber/tests/.hgignore b/libpurple/protocols/jabber/tests/.hgignore
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/jabber/tests/.hgignore
@@ -0,0 +1,10 @@
+syntax: regexp
+^test_jabber_caps$
+^test_jabber_digest_md5$
+^test_jabber_jutil$
+^test_jabber_scram$
+
+syntax: glob
+*.log
+*.trs
+
diff --git a/libpurple/protocols/jabber/tests/Makefile.am b/libpurple/protocols/jabber/tests/Makefile.am
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/jabber/tests/Makefile.am
@@ -0,0 +1,37 @@
+include $(top_srcdir)/glib-tap.mk
+
+COMMON_LIBS=\
+	$(top_builddir)/libpurple/libpurple.la \
+	$(top_builddir)/libpurple/protocols/jabber/libjabber.la \
+	$(GLIB_LIBS) \
+	$(GPLUGIN_LIBS) \
+	$(LIBXML_LIBS)
+
+test_programs=\
+	test_jabber_caps \
+	test_jabber_digest_md5 \
+	test_jabber_jutil
+	test_jabber_scram
+
+test_jabber_caps_SOURCES=test_jabber_caps.c
+test_jabber_caps_LDADD=$(COMMON_LIBS)
+
+test_jabber_digest_md5_SOURCES=test_jabber_digest_md5.c
+test_jabber_digest_md5_LDADD=$(COMMON_LIBS)
+
+test_jabber_jutil_SOURCES=test_jabber_jutil.c
+test_jabber_jutil_LDADD=$(COMMON_LIBS)
+
+test_jabber_scram_SOURCES=test_jabber_scram.c
+test_jabber_scram_LDADD=$(COMMON_LIBS)
+
+AM_CPPFLAGS = \
+	-I$(top_srcdir)/libpurple \
+	-I$(top_builddir)/libpurple \
+	$(DEBUG_CFLAGS) \
+	$(GLIB_CFLAGS) \
+	$(GPLUGIN_CFLAGS) \
+	$(PLUGIN_CFLAGS) \
+	$(DBUS_CFLAGS) \
+	$(LIBXML_CFLAGS) \
+	$(NSS_CFLAGS)
diff --git a/libpurple/tests/test_jabber_caps.c b/libpurple/protocols/jabber/tests/test_jabber_caps.c
rename from libpurple/tests/test_jabber_caps.c
rename to libpurple/protocols/jabber/tests/test_jabber_caps.c
--- a/libpurple/tests/test_jabber_caps.c
+++ b/libpurple/protocols/jabber/tests/test_jabber_caps.c
@@ -1,64 +1,59 @@
-#include <string.h>
+#include <glib.h>
 
-#include "tests.h"
-#include "../xmlnode.h"
-#include "../protocols/jabber/caps.h"
-#include "../ciphers/md5hash.h"
-#include "../ciphers/sha1hash.h"
+#include "xmlnode.h"
+#include "ciphers/sha1hash.h"
+#include "protocols/jabber/caps.h"
 
-START_TEST(test_parse_invalid)
-{
+static void
+test_jabber_caps_parse_invalid_nodes(void) {
 	PurpleXmlNode *query;
 
-	fail_unless(NULL == jabber_caps_parse_client_info(NULL));
+	g_assert_null(jabber_caps_parse_client_info(NULL));
 
 	/* Something other than a disco#info query */
 	query = purple_xmlnode_new("foo");
-	fail_unless(NULL == jabber_caps_parse_client_info(query));
+	g_assert_null(jabber_caps_parse_client_info(query));
 	purple_xmlnode_free(query);
 
 	query = purple_xmlnode_new("query");
-	fail_unless(NULL == jabber_caps_parse_client_info(query));
+	g_assert_null(jabber_caps_parse_client_info(query));
+
 	purple_xmlnode_set_namespace(query, "jabber:iq:last");
-	fail_unless(NULL == jabber_caps_parse_client_info(query));
+	g_assert_null(jabber_caps_parse_client_info(query));
 	purple_xmlnode_free(query);
 }
-END_TEST
 
-#define assert_caps_calculate_match(hash_func, hash, str) { \
-	PurpleXmlNode *query = purple_xmlnode_from_str((str), -1); \
-	PurpleHash *hasher = NULL; \
-	JabberCapsClientInfo *info = jabber_caps_parse_client_info(query); \
-	gchar *got_hash; \
-	if (g_str_equal(hash_func, "sha-1")) { \
-		hasher = purple_sha1_hash_new(); \
-	} else if (g_str_equal(hash_func, "md5")) { \
-		hasher = purple_md5_hash_new(); \
-	} \
-	got_hash = jabber_caps_calculate_hash(info, hasher); \
-	g_object_unref(hasher); \
-	assert_string_equal_free((hash), got_hash); \
+static void
+_test_jabber_caps_match(PurpleHash *hash, const gchar *in, const gchar *expected) {
+	PurpleXmlNode *query = purple_xmlnode_from_str(in, -1);
+	JabberCapsClientInfo *info = jabber_caps_parse_client_info(query);
+	gchar *got = NULL;
+
+	got = jabber_caps_calculate_hash(info, hash);
+	g_object_unref(G_OBJECT(hash));
+
+	g_assert_cmpstr(expected, ==, got);
+	g_free(got);
 }
 
-START_TEST(test_calculate_caps)
-{
-	assert_caps_calculate_match("sha-1", "GNjxthSckUNvAIoCCJFttjl6VL8=",
-	"<query xmlns='http://jabber.org/protocol/disco#info' node='http://tkabber.jabber.ru/#GNjxthSckUNvAIoCCJFttjl6VL8='><identity category='client' type='pc' name='Tkabber'/><x xmlns='jabber:x:data' type='result'><field var='FORM_TYPE' type='hidden'><value>urn:xmpp:dataforms:softwareinfo</value></field><field var='software'><value>Tkabber</value></field><field var='software_version'><value> ( 8.5.5 )</value></field><field var='os'><value>ATmega640-16AU</value></field><field var='os_version'><value/></field></x><feature var='games:board'/><feature var='google:mail:notify'/><feature var='http://jabber.org/protocol/activity'/><feature var='http://jabber.org/protocol/bytestreams'/><feature var='http://jabber.org/protocol/chatstates'/><feature var='http://jabber.org/protocol/commands'/><feature var='http://jabber.org/protocol/commands'/><feature var='http://jabber.org/protocol/disco#info'/><feature var='http://jabber.org/protocol/disco#items'/><feature var='http://jabber.org/protocol/feature-neg'/><feature var='http://jabber.org/protocol/geoloc'/><feature var='http://jabber.org/protocol/ibb'/><feature var='http://jabber.org/protocol/iqibb'/><feature var='http://jabber.org/protocol/mood'/><feature var='http://jabber.org/protocol/muc'/><feature var='http://jabber.org/protocol/mute#ancestor'/><feature var='http://jabber.org/protocol/mute#editor'/><feature var='http://jabber.org/protocol/rosterx'/><feature var='http://jabber.org/protocol/si'/><feature var='http://jabber.org/protocol/si/profile/file-transfer'/><feature var='http://jabber.org/protocol/tune'/><feature var='jabber:iq:avatar'/><feature var='jabber:iq:browse'/><feature var='jabber:iq:dtcp'/><feature var='jabber:iq:filexfer'/><feature var='jabber:iq:ibb'/><feature var='jabber:iq:inband'/><feature var='jabber:iq:jidlink'/><feature var='jabber:iq:last'/><feature var='jabber:iq:oob'/><feature var='jabber:iq:privacy'/><feature var='jabber:iq:time'/><feature var='jabber:iq:version'/><feature var='jabber:x:data'/><feature var='jabber:x:event'/><feature var='jabber:x:oob'/><feature var='urn:xmpp:ping'/><feature var='urn:xmpp:receipts'/><feature var='urn:xmpp:time'/></query>");
+static void
+test_jabber_caps_calculate_from_xmlnode(void) {
+	_test_jabber_caps_match(
+		purple_sha1_hash_new(),
+		"<query xmlns='http://jabber.org/protocol/disco#info' node='http://tkabber.jabber.ru/#GNjxthSckUNvAIoCCJFttjl6VL8='><identity category='client' type='pc' name='Tkabber'/><x xmlns='jabber:x:data' type='result'><field var='FORM_TYPE' type='hidden'><value>urn:xmpp:dataforms:softwareinfo</value></field><field var='software'><value>Tkabber</value></field><field var='software_version'><value> ( 8.5.5 )</value></field><field var='os'><value>ATmega640-16AU</value></field><field var='os_version'><value/></field></x><feature var='games:board'/><feature var='google:mail:notify'/><feature var='http://jabber.org/protocol/activity'/><feature var='http://jabber.org/protocol/bytestreams'/><feature var='http://jabber.org/protocol/chatstates'/><feature var='http://jabber.org/protocol/commands'/><feature var='http://jabber.org/protocol/commands'/><feature var='http://jabber.org/protocol/disco#info'/><feature var='http://jabber.org/protocol/disco#items'/><feature var='http://jabber.org/protocol/feature-neg'/><feature var='http://jabber.org/protocol/geoloc'/><feature var='http://jabber.org/protocol/ibb'/><feature var='http://jabber.org/protocol/iqibb'/><feature var='http://jabber.org/protocol/mood'/><feature var='http://jabber.org/protocol/muc'/><feature var='http://jabber.org/protocol/mute#ancestor'/><feature var='http://jabber.org/protocol/mute#editor'/><feature var='http://jabber.org/protocol/rosterx'/><feature var='http://jabber.org/protocol/si'/><feature var='http://jabber.org/protocol/si/profile/file-transfer'/><feature var='http://jabber.org/protocol/tune'/><feature var='jabber:iq:avatar'/><feature var='jabber:iq:browse'/><feature var='jabber:iq:dtcp'/><feature var='jabber:iq:filexfer'/><feature var='jabber:iq:ibb'/><feature var='jabber:iq:inband'/><feature var='jabber:iq:jidlink'/><feature var='jabber:iq:last'/><feature var='jabber:iq:oob'/><feature var='jabber:iq:privacy'/><feature var='jabber:iq:time'/><feature var='jabber:iq:version'/><feature var='jabber:x:data'/><feature var='jabber:x:event'/><feature var='jabber:x:oob'/><feature var='urn:xmpp:ping'/><feature var='urn:xmpp:receipts'/><feature var='urn:xmpp:time'/></query>",
+		"GNjxthSckUNvAIoCCJFttjl6VL8="
+	);
 }
-END_TEST
 
-Suite *
-jabber_caps_suite(void)
-{
-	Suite *s = suite_create("Jabber Caps Functions");
+gint
+main(gint argc, gchar **argv) {
+	g_test_init(&argc, &argv, NULL);
 
-	TCase *tc = tcase_create("Parsing invalid ndoes");
-	tcase_add_test(tc, test_parse_invalid);
-	suite_add_tcase(s, tc);
+	g_test_add_func("/jabber/caps/parse invalid nodes",
+	                test_jabber_caps_parse_invalid_nodes);
 
-	tc = tcase_create("Calculating from XMLnode");
-	tcase_add_test(tc, test_calculate_caps);
-	suite_add_tcase(s, tc);
+	g_test_add_func("/jabber/caps/calulate from xmlnode",
+	                test_jabber_caps_calculate_from_xmlnode);
 
-	return s;
+	return g_test_run();
 }
diff --git a/libpurple/tests/test_jabber_digest_md5.c b/libpurple/protocols/jabber/tests/test_jabber_digest_md5.c
rename from libpurple/tests/test_jabber_digest_md5.c
rename to libpurple/protocols/jabber/tests/test_jabber_digest_md5.c
--- a/libpurple/tests/test_jabber_digest_md5.c
+++ b/libpurple/protocols/jabber/tests/test_jabber_digest_md5.c
@@ -1,59 +1,50 @@
-#include <string.h>
+#include <glib.h>
 
-#include "tests.h"
-#include "../util.h"
-#include "../protocols/jabber/auth_digest_md5.h"
-#include "../protocols/jabber/jutil.h"
+#include "util.h"
+#include "protocols/jabber/auth_digest_md5.h"
+#include "protocols/jabber/jutil.h"
 
-START_TEST(test_parsing)
-{
+static void
+test_jabber_digest_md5_parsing(void) {
 	GHashTable *table;
+	const gchar *value = NULL;
+
+	#define check_value(name, expected) G_STMT_START {\
+		value = g_hash_table_lookup(table, (name)); \
+		g_assert_nonnull(value); \
+		g_assert_cmpstr((expected), ==, value); \
+	} G_STMT_END
 
 	table = jabber_auth_digest_md5_parse("r=\"realm\",token=   \"   asdf\"");
-	fail_if(g_hash_table_lookup(table, "r") == NULL);
-	assert_string_equal("realm", g_hash_table_lookup(table, "r"));
-	fail_if(g_hash_table_lookup(table, "token") == NULL);
-	assert_string_equal("asdf", g_hash_table_lookup(table, "token"));
+	check_value("r", "realm");
+	check_value("token", "asdf");
 	g_hash_table_destroy(table);
 
 	table = jabber_auth_digest_md5_parse("r=\"a\", token=   \"   asdf\"");
-	fail_if(g_hash_table_lookup(table, "r") == NULL);
-	assert_string_equal("a", g_hash_table_lookup(table, "r"));
-	fail_if(g_hash_table_lookup(table, "token") == NULL);
-	assert_string_equal("asdf", g_hash_table_lookup(table, "token"));
+	check_value("r", "a");
+	check_value("token", "asdf");
 	g_hash_table_destroy(table);
 
 	table = jabber_auth_digest_md5_parse("r=\"\", token=   \"   asdf\"");
-	fail_if(g_hash_table_lookup(table, "r") == NULL);
-	assert_string_equal("", g_hash_table_lookup(table, "r"));
-	fail_if(g_hash_table_lookup(table, "token") == NULL);
-	assert_string_equal("asdf", g_hash_table_lookup(table, "token"));
+	check_value("r", "");
+	check_value("token", "asdf");
 	g_hash_table_destroy(table);
 
 	table = jabber_auth_digest_md5_parse("realm=\"somerealm\",nonce=\"OA6MG9tEQGm2hh\",qop=\"auth\",charset=utf-8,algorithm=md5-sess");
-	fail_if(g_hash_table_lookup(table, "realm") == NULL);
-	assert_string_equal("somerealm", g_hash_table_lookup(table, "realm"));
-	fail_if(g_hash_table_lookup(table, "nonce") == NULL);
-	assert_string_equal("OA6MG9tEQGm2hh", g_hash_table_lookup(table, "nonce"));
-	fail_if(g_hash_table_lookup(table, "qop") == NULL);
-	assert_string_equal("auth", g_hash_table_lookup(table, "qop"));
-	fail_if(g_hash_table_lookup(table, "charset") == NULL);
-	assert_string_equal("utf-8", g_hash_table_lookup(table, "charset"));
-	fail_if(g_hash_table_lookup(table, "algorithm") == NULL);
-	assert_string_equal("md5-sess", g_hash_table_lookup(table, "algorithm"));
+	check_value("realm", "somerealm");
+	check_value("nonce", "OA6MG9tEQGm2hh");
+	check_value("qop", "auth");
+	check_value("charset", "utf-8");
+	check_value("algorithm", "md5-sess");
+	g_hash_table_destroy(table);
+}
 
-	g_hash_table_destroy(table);
+gint
+main(gint argc, gchar **argv) {
+	g_test_init(&argc, &argv, NULL);
 
+	g_test_add_func("/jabber/digest/md5/parsing",
+	                test_jabber_digest_md5_parsing);
+
+	return g_test_run();
 }
-END_TEST
-
-Suite *
-jabber_digest_md5_suite(void)
-{
-	Suite *s = suite_create("Jabber SASL DIGEST-MD5 functions");
-
-	TCase *tc = tcase_create("Parsing Functionality");
-	tcase_add_test(tc, test_parsing);
-	suite_add_tcase(s, tc);
-	return s;
-}
diff --git a/libpurple/tests/test_jabber_jutil.c b/libpurple/protocols/jabber/tests/test_jabber_jutil.c
rename from libpurple/tests/test_jabber_jutil.c
rename to libpurple/protocols/jabber/tests/test_jabber_jutil.c
--- a/libpurple/tests/test_jabber_jutil.c
+++ b/libpurple/protocols/jabber/tests/test_jabber_jutil.c
@@ -1,151 +1,215 @@
-#include <string.h>

_______________________________________________
Commits mailing list
[email protected]
https://pidgin.im/cgi-bin/mailman/listinfo/commits
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.