This repository has been archived on 2021-04-17. You can view files and clone it, but cannot push or open issues or pull requests.
uIRC/src/test/common.c

83 lines
2.3 KiB
C

/*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "common.h"
#include "uirc/uirc.h" // IRC_Message
#include <stdio.h> // printf()
#include <stdlib.h> // exit()
#include <string.h> // strcmp()
#define DELIMITER "-------------\n"
#define PRINTVARORNULL(VAR) ((VAR != NULL) ? VAR : "NULL")
void
expect(const char* var, const char* exp)
{
if (strcmp(var, exp) != 0) {
printf("Expected \"%s\" but got \"%s\" instead.\n", exp, var);
exit(EXIT_FAILURE);
}
}
void
print_irc_message(const IRC_Message* ptr)
{
#ifdef UIRC_FEATURE_IRCV3
printf(DELIMITER);
llist_t* tmp = ptr->tag_list;
for (; tmp != NULL; tmp = llist_elem_get_next(tmp)) { print_irc_tag((IRC_Tag*) llist_elem_get_cont(tmp)); }
#endif /* UIRC_FEATURE_IRCV3 */
if (ptr->source != NULL) { print_irc_user(ptr->source); }
if (ptr->command != NULL) printf("mc: %s\n", ptr->command);
for (short i = 0; i < IRC_MAXARGS && ptr->args[i] != NULL; i++) { printf("marg[%i]: %s\n", i, ptr->args[i]); }
printf(DELIMITER);
}
#ifdef UIRC_FEATURE_IRCV3
void
print_irc_tag(const IRC_Tag* tag)
{
printf(DELIMITER "tn: %s\n"
"tv: %s\n"
"tc: %i\n" DELIMITER,
PRINTVARORNULL(tag->key),
PRINTVARORNULL(tag->value),
tag->clientbound);
}
#endif /* UIRC_FEATURE_IRCV3 */
void
print_irc_user(const IRC_User* user)
{
printf(DELIMITER "un: %s\n"
"uu: %s\n"
"ur: %s\n"
"uh: %s\n" DELIMITER,
PRINTVARORNULL(user->nick),
PRINTVARORNULL(user->user),
PRINTVARORNULL(user->real),
PRINTVARORNULL(user->host));
}