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/assemblers/message.c

63 lines
2.1 KiB
C

/*
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
* Copyright (c) 2019, 2020 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 "../../assemblers/assemblers.h" // Assm_mesg()
#include "../../types.h" // IRC_*
#include "../common.h" // expect()
#include <assert.h> // assert()
#include <stdbool.h> // bool
#include <stdlib.h> // EXIT_SUCCESS
#define KEY1 "msgid"
#define VAL1 "lol"
#define KEY2 "wow"
#define NICK "bazinga"
#define HOST "monke.uk"
#define COMMAND "NOTICE"
#define ARG1 "urmomgay"
#define TRAILING "what's up retard"
int
main(void)
{
IRC_Message m[] = {
{ .command = COMMAND, .args = { ARG1, TRAILING, NULL }, .trailing = true },
{ .tag_list = &(llist_t) { .content = &(IRC_Tag) { .key = KEY1, .value = VAL1, .clientbound = true },
.next = &(llist_t) { .content = &(IRC_Tag) { .key = KEY2 } } },
.source = &(IRC_User) { .nick = NICK, .host = HOST },
.command = COMMAND,
.args = { ARG1, TRAILING, NULL },
.trailing = true },
};
const char* str[] = { COMMAND " " ARG1 " :" TRAILING, "@+" KEY1 "=" VAL1 ";" KEY2 " :" NICK "@" HOST " " COMMAND " " ARG1 " :" TRAILING };
char buf[513];
signed long ret;
for (unsigned long i = 0; i < sizeof(str) / sizeof(*str); i++) {
if ((ret = uirc_assembler_message(buf, &m[i], sizeof(buf) / sizeof(char))) <= 0) {
printf("Failed to convert IRC_User struct to a string. %li\n", ret);
return EXIT_FAILURE;
}
expect(buf, str[i]);
print_irc_message(&m[i]);
}
return EXIT_SUCCESS;
}