Add earlytrail test

This commit is contained in:
Alex D. 2021-03-05 17:16:26 +00:00
parent 7109ae6b70
commit f0f0d95078
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
3 changed files with 51 additions and 0 deletions

View File

@ -91,6 +91,7 @@ if (BUILD_TESTS)
add_subdirectory(tests)
enable_testing()
add_test(NAME "FullLoop" COMMAND "fullloop")
add_test(NAME "EarlyTrail" COMMAND "earlytrail")
endif()
add_library(uirc ${UIRC_SOURCE})

View File

@ -1,5 +1,9 @@
cmake_minimum_required(VERSION 3.16)
include_directories(${uIRC_SOURCE_DIR}/include)
add_executable(fullloop fullloop.c common.c)
target_link_libraries(fullloop uirc)
add_executable(earlytrail earlytrail.c common.c)
target_link_libraries(earlytrail uirc)

46
tests/earlytrail.c Normal file
View File

@ -0,0 +1,46 @@
/*
* 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 "common.h" // expect() print_irc_message()
#include "uirc.h" // uirc_* IRC_*
#include <stdio.h> // fprintf()
#include <stdlib.h> // EXIT_*
#include <string.h> // strcmp()
#define TRAILING "random stuff here"
int
main(void)
{
const char* str = "NOTICE 0 1 2 3 4 5 6 7 8 9 10 11 12 13 " TRAILING "\r\n";
IRC_Message* m = NULL;
if ((m = uirc_tokenizer_message(str)) == NULL) {
fprintf(stderr, "Failed to convert string to IRC_Message struct.\n");
return EXIT_FAILURE;
}
if (strcmp(m->args[IRC_MAXARGS - 1], TRAILING) != 0) {
fprintf(stderr, "Trailing was parsed incorrectly, got %s instead of %s\n", m->args[IRC_MAXARGS - 1], TRAILING);
return EXIT_FAILURE;
}
uirc_free_message(m);
free(m);
return EXIT_SUCCESS;
}