/pidgin/main: a265dfe49fcb: Add a header file with some utils fo...

Gary Kramlich grim at reaperworld.com
Wed Mar 30 19:25:28 EDT 2016


Changeset: a265dfe49fcb71e7a8a5d04bedcafbe6b2a96dd5
Author:	 Gary Kramlich <grim at reaperworld.com>
Date:	 2016-03-20 15:59 -0500
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/a265dfe49fcb

Description:

Add a header file with some utils for testing

diffstat:

 libpurple/protocols/jabber/tests/test_jabber_jutil.c |  45 ++-----------
 libpurple/tests.h                                    |  64 ++++++++++++++++++++
 2 files changed, 73 insertions(+), 36 deletions(-)

diffs (168 lines):

diff --git a/libpurple/protocols/jabber/tests/test_jabber_jutil.c b/libpurple/protocols/jabber/tests/test_jabber_jutil.c
--- a/libpurple/protocols/jabber/tests/test_jabber_jutil.c
+++ b/libpurple/protocols/jabber/tests/test_jabber_jutil.c
@@ -5,38 +5,11 @@
 #include "xmlnode.h"
 #include "protocols/jabber/jutil.h"
 
-typedef struct {
-	const gchar *input;
-	const gchar *output;
-} TestStringData;
-
-typedef const gchar *(*test_string_func)(const gchar *);
-typedef gchar *(*test_string_free_func)(const gchar *);
-
-static void
-_test_string_compare_func(TestStringData data[], test_string_func func) {
-	gint i;
-
-	for(i = 0; data[i].input; i++)
-		g_assert_cmpstr(data[i].output, ==, func(data[i].input));
-}
-
-static void
-_test_string_compare_func_free(TestStringData data[], test_string_free_func func) {
-	gint i;
-
-	for(i = 0; data[i].input; i++) {
-		gchar *got = func(data[i].input);
-
-		g_assert_cmpstr(data[i].output, ==, got);
-
-		g_free(got);
-	}
-}
+#include "tests.h"
 
 static void
 test_jabber_util_get_resource_exists(void) {
-	TestStringData data[] = {
+	PurpleTestStringData data[] = {
 		{ "foo at bar/baz", "baz" },
 		{ "bar/baz", "baz" },
 		{ "foo at bar/baz/bat", "baz/bat" },
@@ -44,23 +17,23 @@ test_jabber_util_get_resource_exists(voi
 		{ NULL, NULL },
 	};
 
-	_test_string_compare_func_free(data, jabber_get_resource);
+	purple_test_string_compare_free(jabber_get_resource, data);
 }
 
 static void
 test_jabber_util_get_resource_none(void) {
-	TestStringData data[] = {
+	PurpleTestStringData data[] = {
 		{ "foo at bar", NULL },
 		{ "bar", NULL },
 		{ NULL, NULL },
 	};
 
-	_test_string_compare_func_free(data, jabber_get_resource);
+	purple_test_string_compare_free(jabber_get_resource, data);
 }
 
 static void
 test_jabber_util_get_bare_jid(void) {
-	TestStringData data[] = {
+	PurpleTestStringData data[] = {
 		{ "foo at bar", "foo at bar" },
 		{ "foo at bar/baz", "foo at bar" },
 		{ "bar", "bar" },
@@ -68,7 +41,7 @@ test_jabber_util_get_bare_jid(void) {
 		{ NULL, NULL },
 	};
 
-	_test_string_compare_func_free(data, jabber_get_bare_jid);
+	purple_test_string_compare_free(jabber_get_bare_jid, data);
 }
 
 static void
@@ -243,7 +216,7 @@ partial_jabber_normalize(const gchar *st
 
 static void
 test_jabber_util_jabber_normalize(void) {
-	TestStringData data[] = {
+	PurpleTestStringData data[] = {
 		{
 			"PaUL at DaRkRain42.org",
 			"paul at darkrain42.org",
@@ -259,7 +232,7 @@ test_jabber_util_jabber_normalize(void) 
 		}
 	};
 
-	_test_string_compare_func(data, partial_jabber_normalize);
+	purple_test_string_compare(partial_jabber_normalize, data);
 }
 
 gint
diff --git a/libpurple/tests.h b/libpurple/tests.h
new file mode 100644
--- /dev/null
+++ b/libpurple/tests.h
@@ -0,0 +1,64 @@
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+#ifndef PURPLE_TESTS_H
+#define PURPLE_TESTS_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct {
+	const gchar *input;
+	const gchar *output;
+} PurpleTestStringData;
+
+typedef const gchar *(*PurpleTestStringFunc)(const gchar *);
+typedef gchar *(*PurpleTestStringFreeFunc)(const gchar *);
+
+inline void
+purple_test_string_compare(PurpleTestStringFunc func,
+                           PurpleTestStringData data[])
+{
+	gint i;
+
+	for(i = 0; data[i].input; i++)
+		g_assert_cmpstr(data[i].output, ==, func(data[i].input));
+}
+
+inline void
+purple_test_string_compare_free(PurpleTestStringFreeFunc func,
+                                PurpleTestStringData data[])
+{
+	gint i;
+
+	for(i = 0; data[i].input; i++) {
+		gchar *got = func(data[i].input);
+
+		g_assert_cmpstr(data[i].output, ==, got);
+
+		g_free(got);
+	}
+}
+
+
+G_END_DECLS
+
+#endif /* PURPLE_TESTS_H */



More information about the Commits mailing list