[telepathy-gabble/master] Add a simple test for gabble_set_tp_error_from_wocky()
Simon McVittie
simon.mcvittie at collabora.co.uk
Mon Jan 11 12:35:53 PST 2010
---
.gitignore | 1 +
tests/Makefile.am | 8 ++++-
tests/tp-error-from-wocky.c | 66 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 73 insertions(+), 2 deletions(-)
create mode 100644 tests/tp-error-from-wocky.c
diff --git a/.gitignore b/.gitignore
index 5d28dd5..662e698 100644
--- a/.gitignore
+++ b/.gitignore
@@ -78,6 +78,7 @@ cscope.out
/tests/test-jid-decode
/tests/test-parse-message
/tests/test-presence
+/tests/test-tp-error-from-wocky
/tests/twisted/config.py
/tests/twisted/telepathy-gabble-debug
/tests/twisted/tools/core.*
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2592436..ae2e3f3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -11,7 +11,8 @@ noinst_PROGRAMS = \
test-handles \
test-jid-decode \
test-parse-message \
- test-presence
+ test-presence \
+ test-tp-error-from-wocky
LDADD = $(top_builddir)/src/libgabble-convenience.la
@@ -47,7 +48,10 @@ check_c_sources = \
test-presence.c \
test-jid-decode.c \
test-handles.c \
- test-parse-message.c
+ test-parse-message.c \
+ tp-error-from-wocky.c
+
+test_tp_error_from_wocky_SOURCES = tp-error-from-wocky.c
include $(top_srcdir)/tools/check-coding-style.mk
check-local: check-coding-style
diff --git a/tests/tp-error-from-wocky.c b/tests/tp-error-from-wocky.c
new file mode 100644
index 0000000..3099e5e
--- /dev/null
+++ b/tests/tp-error-from-wocky.c
@@ -0,0 +1,66 @@
+#include "config.h"
+
+#include <gabble/gabble.h>
+
+static void
+test_remap (GQuark domain,
+ gint code,
+ const gchar *message,
+ gint exp_code,
+ const gchar *exp_message)
+{
+ GError *error = NULL;
+ GError wocky_error = { domain, code, (gchar *) message };
+
+ gabble_set_tp_error_from_wocky (&wocky_error, &error);
+ g_assert (error != NULL);
+ g_assert_cmpstr (g_quark_to_string (error->domain), ==,
+ g_quark_to_string (TP_ERRORS));
+ g_assert_cmpint (error->code, ==, exp_code);
+
+ if (exp_message != NULL)
+ g_assert_cmpstr (error->message, ==, exp_message);
+
+ g_error_free (error);
+}
+
+#define TEST_XMPP(nick, n, message, exp_code) \
+ test_remap (WOCKY_XMPP_ERROR, WOCKY_XMPP_ERROR_ ## nick, message, \
+ exp_code, \
+ "WOCKY_XMPP_ERROR_" #nick " (#" #n "): " \
+ message)
+
+int
+main (void)
+{
+ g_type_init ();
+
+ test_remap (WOCKY_XMPP_ERROR, WOCKY_XMPP_ERROR_FORBIDDEN, "computer says no",
+ TP_ERROR_PERMISSION_DENIED,
+ "WOCKY_XMPP_ERROR_FORBIDDEN (#8): computer says no");
+ /* shorthand version of the above */
+ TEST_XMPP (FORBIDDEN, 8, "computer says no", TP_ERROR_PERMISSION_DENIED);
+
+ /* more mappings */
+ TEST_XMPP (RESOURCE_CONSTRAINT, 19, "shut up!", TP_ERROR_SERVICE_BUSY);
+ TEST_XMPP (FEATURE_NOT_IMPLEMENTED, 20, "what?", TP_ERROR_NOT_AVAILABLE);
+
+ /* out-of-range is handled gracefully */
+ test_remap (WOCKY_XMPP_ERROR, 12345678, "lalala I am broken",
+ TP_ERROR_NOT_AVAILABLE,
+ "unknown WockyXmppError code (#12345678): lalala I am broken");
+
+ /* GIOError is NetworkError, for now */
+ test_remap (G_IO_ERROR, G_IO_ERROR_TIMED_OUT, "network fail",
+ TP_ERROR_NETWORK_ERROR,
+ "G_IO_ERROR_TIMED_OUT (#24): network fail");
+
+ /* other domains do something basically sane (the message will be something
+ * vaguely helpful) */
+ test_remap (G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE,
+ "what's this doing here?",
+ TP_ERROR_NOT_AVAILABLE, NULL);
+
+ return 0;
+}
+
--
1.5.6.5
More information about the telepathy-commits
mailing list