summaryrefslogtreecommitdiff
path: root/libpurple
diff options
context:
space:
mode:
authorGary Kramlich <grim@reaperworld.com>2023-02-23 22:45:08 -0600
committerGary Kramlich <grim@reaperworld.com>2023-02-23 22:45:08 -0600
commit2a5def05de9885ae3a651ee397f0dc79a7780c74 (patch)
treeed98486aa0e1cf9d0f83c75b49fcb04e0dd266ad /libpurple
parent450b4e947d107d7c8479e1935363ff0937338766 (diff)
downloadpidgin-2a5def05de9885ae3a651ee397f0dc79a7780c74.tar.gz
Add a unit test to make sure the IRCv3 parser propagates errors to the caller
Testing Done: Ran the unit tests Reviewed at https://reviews.imfreedom.org/r/2263/
Diffstat (limited to 'libpurple')
-rw-r--r--libpurple/protocols/ircv3/tests/test_ircv3_parser.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/libpurple/protocols/ircv3/tests/test_ircv3_parser.c b/libpurple/protocols/ircv3/tests/test_ircv3_parser.c
index 8fae4ef72f..dd93079fd9 100644
--- a/libpurple/protocols/ircv3/tests/test_ircv3_parser.c
+++ b/libpurple/protocols/ircv3/tests/test_ircv3_parser.c
@@ -22,6 +22,8 @@
#include "../purpleircv3parser.h"
+#define TEST_IRCV3_PARSER_DOMAIN (g_quark_from_static_string("test-ircv3-parser"))
+
typedef struct {
GHashTable *tags;
gchar *source;
@@ -36,7 +38,8 @@ typedef struct {
static gboolean
test_purple_ircv3_test_handler(GHashTable *tags, const gchar *source,
const gchar *command, guint n_params,
- GStrv params, GError **error, gpointer data)
+ GStrv params, G_GNUC_UNUSED GError **error,
+ gpointer data)
{
TestPurpleIRCv3ParserData *d = data;
GHashTableIter iter;
@@ -99,6 +102,20 @@ test_purple_ircv3_test_handler(GHashTable *tags, const gchar *source,
return TRUE;
}
+static gboolean
+test_purple_ircv3_test_handler_error(G_GNUC_UNUSED GHashTable *tags,
+ G_GNUC_UNUSED const gchar *source,
+ G_GNUC_UNUSED const gchar *command,
+ G_GNUC_UNUSED guint n_params,
+ G_GNUC_UNUSED GStrv params,
+ GError **error,
+ G_GNUC_UNUSED gpointer data)
+{
+ g_set_error(error, TEST_IRCV3_PARSER_DOMAIN, 0, "test error");
+
+ return FALSE;
+}
+
/******************************************************************************
* Helpers
*****************************************************************************/
@@ -123,6 +140,24 @@ test_purple_ircv3_parser(const gchar *source, TestPurpleIRCv3ParserData *d) {
* Tests
*****************************************************************************/
static void
+test_purple_ircv3_parser_propagates_errors(void) {
+ PurpleIRCv3Parser *parser = purple_ircv3_parser_new();
+ GError *error = NULL;
+ gboolean result = FALSE;
+
+ purple_ircv3_parser_set_fallback_handler(parser,
+ test_purple_ircv3_test_handler_error);
+
+ result = purple_ircv3_parser_parse(parser, "COMMAND", &error, NULL);
+ g_assert_error(error, TEST_IRCV3_PARSER_DOMAIN, 0);
+ g_clear_error(&error);
+
+ g_assert_false(result);
+
+ g_clear_object(&parser);
+}
+
+static void
test_purple_ircv3_parser_simple(void) {
TestPurpleIRCv3ParserData data = {
.command = "foo",
@@ -679,6 +714,12 @@ gint
main(gint argc, gchar *argv[]) {
g_test_init(&argc, &argv, NULL);
+ /* Make sure an error in the handler is propagated back up to the calling
+ * function.
+ */
+ g_test_add_func("/ircv3/parser/propagates-errors",
+ test_purple_ircv3_parser_propagates_errors);
+
/* These tests are based on the msg-split tests from
* https://github.com/ircdocs/parser-tests/blob/master/tests/msg-split.yaml
*/