diff tests/test-event.c @ 953:ab43ba409f9d

irccd: add SSL, and cleanup events
author David Demelier <markand@malikania.fr>
date Wed, 20 Jan 2021 12:32:59 +0100
parents
children bbb3d3075ec2
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-event.c	Wed Jan 20 12:32:59 2021 +0100
@@ -0,0 +1,75 @@
+/*
+ * test-event.c -- test event.h functions
+ *
+ * Copyright (c) 2013-2021 David Demelier <markand@malikania.fr>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#define GREATEST_USE_ABBREVS 0
+#include <greatest.h>
+
+#include <irccd/event.h>
+#include <irccd/server.h>
+
+GREATEST_TEST
+basics_parse_simple(void)
+{
+	/* This is a TOPIC message. */
+	char str[] = ":malikania.fr 332 boris #test :Welcome to #test :: a testing channel";
+	struct irc_event_msg msg;
+
+	irc_event_parse(&msg, str);
+
+	GREATEST_ASSERT_STR_EQ("malikania.fr", msg.prefix);
+	GREATEST_ASSERT_STR_EQ("332", msg.cmd);
+	GREATEST_ASSERT_STR_EQ("boris", msg.args[0]);
+	GREATEST_ASSERT_STR_EQ("#test", msg.args[1]);
+	GREATEST_ASSERT_STR_EQ("Welcome to #test :: a testing channel", msg.args[2]);
+
+	GREATEST_PASS();
+}
+
+GREATEST_TEST
+basics_parse_noprefix(void)
+{
+	/* Ping messages usually don't have a prefix. */
+	char str[] = "PING :malikania.fr";
+	struct irc_event_msg msg;
+
+	irc_event_parse(&msg, str);
+
+	GREATEST_ASSERT(!msg.prefix);
+	GREATEST_ASSERT_STR_EQ("PING", msg.cmd);
+	GREATEST_ASSERT_STR_EQ("malikania.fr", msg.args[0]);
+
+	GREATEST_PASS();
+}
+
+GREATEST_SUITE(suite_basics)
+{
+	GREATEST_RUN_TEST(basics_parse_simple);
+	GREATEST_RUN_TEST(basics_parse_noprefix);
+}
+
+GREATEST_MAIN_DEFS();
+
+int
+main(int argc, char **argv)
+{
+	GREATEST_MAIN_BEGIN();
+	GREATEST_RUN_SUITE(suite_basics);
+	GREATEST_MAIN_END();
+
+	return 0;
+}