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/tests/allocs.c

77 lines
2.4 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" // expect() print_irc_message()
#include "uirc.h" // uirc_* IRC_*
#include <stdbool.h> // true
#include <stdio.h> // fprintf()
#include <stdlib.h> // EXIT_*
#include <string.h> // strcmp()
#define NICKN "nick"
#define USERN "someuser"
#define HOSTN "pop.com"
#define TAGKEY "time"
#define TAGVAL "2020-09-02T20:10:30.000Z"
#define CMD "NOTICE"
#define ARG1 "*"
#define ARG2 "piss off"
int
main(void)
{
IRC_Modes modes;
uirc_mode_toggle('a', modes);
IRC_User* u = uirc_struct_assm_user(false, &modes, NICKN, USERN, NULL, HOSTN);
if (u == NULL) {
fprintf(stderr, "Memory allocation failed\n");
return EXIT_FAILURE;
}
if (strcmp(NICKN, u->nick) != 0 || strcmp(USERN, u->user) != 0 || strcmp(HOSTN, u->host) != 0) {
fprintf(stderr, "User allocator returned unexpected results\n");
return EXIT_FAILURE;
}
if (!uirc_mode_fetch('a', u->modes)) {
fprintf(stderr, "Modes weren't copied correctly\n");
return EXIT_FAILURE;
}
uirc_struct_free(u, IRC_STRUCT_USER);
free(u);
#ifdef UIRC_FEATURE_IRCV3
IRC_Tag* t = uirc_struct_assm_tag(false, TAGKEY, TAGVAL);
if (strcmp(TAGKEY, t->key) != 0 || strcmp(TAGVAL, t->value) != 0) {
fprintf(stderr, "Tag allocator returned unexpected results\n");
return EXIT_FAILURE;
}
uirc_struct_free(t, IRC_STRUCT_TAG);
free(t);
#endif /* UIRC_FEATURE_IRCV3 */
IRC_Message* m = uirc_struct_assm_message(CMD, true, 2, ARG1, ARG2);
if (strcmp(m->command, CMD) != 0 || strcmp(m->args[0], ARG1) != 0 || strcmp(m->args[1], ARG2) != 0) {
fprintf(stderr, "Message allocator returned unexpected results\n");
return EXIT_FAILURE;
}
uirc_struct_free(m, IRC_STRUCT_MESSAGE);
free(m);
return EXIT_SUCCESS;
}