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/tag.c

53 lines
1.7 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 "../common.h" // expect()
#include <stdlib.h> // EXIT_SUCCESS EXIT_FAILURE
#define key1 "msgid"
#define val1 "30"
#define key2 "time"
#define key3 "x"
#define val3 "spx"
int
main(void)
{
const char* str[] = { "+" key1 "=" val1, key2, key3 "=" val3 };
const IRC_Tag tag[] = { { .key = key1, .value = val1, .clientbound = true }, { .key = key2 }, { .key = key3, .value = val3 } };
char buf[513];
signed long ret;
for (unsigned long i = 0; i < sizeof(str) / sizeof(*str); i++) {
if ((ret = uirc_assembler_tag(buf, &tag[i], sizeof(buf) / sizeof(char))) < 0) {
printf("Failed to convert tag %lu to \"%s\". Error %li\n", i, str[i], ret);
return EXIT_FAILURE;
}
size_t len = strlen(str[i]);
if ((size_t) ret != len) {
printf("String lenght doesn't match with amount of bytes printed. Expected %li but got %li\n", len, ret);
return EXIT_FAILURE;
}
expect(buf, str[i]);
print_irc_tag(&tag[i]);
}
return EXIT_SUCCESS;
}