From 081821c8bc65ca788bffd9b4151e2289d1bb3eca Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 10 Jul 2020 18:03:26 +0200 Subject: [PATCH] Add few tests --- tests/tagassm.c | 22 ++++++++++++++++++++++ tests/tagtok.c | 24 ++++++++++++++++++++++++ tests/tokenizer.c | 16 ++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 tests/tagassm.c create mode 100644 tests/tagtok.c create mode 100644 tests/tokenizer.c diff --git a/tests/tagassm.c b/tests/tagassm.c new file mode 100644 index 0000000..99b5844 --- /dev/null +++ b/tests/tagassm.c @@ -0,0 +1,22 @@ +#include "../include/uirc.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" + +int main(void) +{ + char mesg[513] = {0}; + IRC_Tags input = { + .time = {.value = "now", .clientbound = true}, + .msgid = {.value = "", .clientbound = false}}; + int res = 0; + if ((res = Assm_tags(mesg, &input)) <= 0) { + printf("String could not be assembled. %i\n", res); + return EXIT_FAILURE; + } + if (strcmp(mesg, "@+time=now;msgid") && strcmp(mesg, "@msgid;+time=now")) { + printf("String was not assembled properly. Have %s\n", mesg); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/tests/tagtok.c b/tests/tagtok.c new file mode 100644 index 0000000..ed9e2f9 --- /dev/null +++ b/tests/tagtok.c @@ -0,0 +1,24 @@ +#include "../include/uirc.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" + +int main(void) +{ + char mesg[513] = "@msgid=1s32;+time QUIT"; + IRC_Message parseout; + int res = 0; + if ((res = Tok_mesg(mesg, &parseout)) <= 0) { + printf("String could not be tokenized. %i\n", res); + return EXIT_FAILURE; + } + if (parseout.tags.msgid.value == NULL || strcmp(parseout.tags.msgid.value, "1s32")) { + printf("Message ID was not properly parsed.\n"); + return EXIT_FAILURE; + } + if (parseout.tags.time.value == NULL || *parseout.tags.time.value != '\0' || !parseout.tags.time.clientbound) { + printf("Time was not properly parsed.\n"); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/tests/tokenizer.c b/tests/tokenizer.c new file mode 100644 index 0000000..3072859 --- /dev/null +++ b/tests/tokenizer.c @@ -0,0 +1,16 @@ +#include "../include/uirc.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" + +int main(void) +{ + char mesg[513] = "@+msgid=1s32;time;+reply;account=x :nick!user@host QUIT :Finished!"; + IRC_Message parseout; + int res = 0; + if ((res = Tok_mesg(mesg, &parseout)) <= 0) { + printf("String could not be tokenized. %i\n", res); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +}