/* * This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC) * Copyright (c) 2019-2021 Alex-David Denes * * uIRC 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 3 of the License, or * any later version. * * uIRC 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 uIRC. If not, see . */ #include "common.h" // expect() print_irc_message() #include "uirc.h" // uirc_* IRC_* #include // assert() #include // printf() #include // EXIT_SUCCESS #include // strlen() int main(void) { const char* str[] = { ":buddy@hostnet.com PRIVMSG #general :login hunter12\r\n", "NOTICE * :nice cock bro\r\n", "@day=13;willtolive=0 PRIVMSG you :helo\r\n", ":mom!mother@localhost NOTICE #netadmin :johnny, your pizza is done\r\n", "NOTICE after 14 arguments the trailing starts early so there's no need for a colon hmm interesting really\r\n" }; for (unsigned long i = 0; i < sizeof(str) / sizeof(*str); i++) { IRC_Message* m = NULL; if ((m = uirc_tokenizer_message(str[i])) == NULL) { fprintf(stderr, "Failed to convert string to IRC_Message struct.\n"); return EXIT_FAILURE; } print_irc_message(m); ssize_t ret; char buf[513]; if ((ret = uirc_assembler_message(buf, m, sizeof(buf) / sizeof(char))) <= 0) { fprintf(stderr, "Failed to convert IRC_Message struct to a string. (%li)\n", ret); return EXIT_FAILURE; } size_t s1 = strlen(str[i]), s2 = strlen(buf); if (s1 != s2) { fprintf(stderr, "String lenght doesn't match after parsing and assembly. Expected %li but got %li\n", s1, s2); fprintf(stderr, "%s\n", buf); return EXIT_FAILURE; } expect(buf, str[i]); uirc_struct_free(m, IRC_STRUCT_MESSAGE); free(m); } return EXIT_SUCCESS; }