From 86f6dbe43f371257ab81087738f034d1fb764bdd Mon Sep 17 00:00:00 2001 From: Alex Denes Date: Tue, 1 Sep 2020 11:49:37 +0200 Subject: [PATCH] Add tag helpers, timestamp assembler, use system defined paths for tests and add timestamp tests --- CMakeLists.txt | 2 +- include/helpers.h | 5 ++++- src/assemblers.h | 1 + src/helpers.c | 1 + src/helpers.h | 1 + src/taghelpers.c | 24 ++++++++++++++++++++++++ src/taghelpers.h | 30 ++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 9 +++++++++ tests/msgassm.c | 6 +++--- tests/notrail.c | 6 +++--- tests/numericmds.c | 6 +++--- tests/overflow.c | 6 +++--- tests/prefixassm.c | 6 +++--- tests/spacedargs.c | 6 +++--- tests/tagassm.c | 6 +++--- tests/tagtok.c | 6 +++--- tests/timestamp.c | 14 ++++++++++++++ tests/tokenizer.c | 6 +++--- 18 files changed, 112 insertions(+), 29 deletions(-) create mode 100644 src/taghelpers.c create mode 100644 src/taghelpers.h create mode 100644 tests/timestamp.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 58e624e..183cc28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ set(build_FILES ) if ( BUILD_HELPERS ) message("Helper functions are going to be built.") - set(build_FILES ${build_FILES} src/helpers.c) + set(build_FILES ${build_FILES} src/helpers.c src/taghelpers.c) endif() add_library(uirc SHARED ${build_FILES}) set_property(TARGET uirc PROPERTY C_STANDARD 99) diff --git a/include/helpers.h b/include/helpers.h index 07952b8..f30077d 100644 --- a/include/helpers.h +++ b/include/helpers.h @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . */ -#include #include "types.h" +#include +#include #ifdef UIRC_HELPERS #ifndef _UIRC_INCLUDED_HELPERS @@ -83,5 +84,7 @@ extern IRC_Message* Assm_cmd_ISON(char* users[]); extern void Tok_cmd_PING(IRC_Message* mesg, char* source, char* target); extern void Tok_FArgOpt(IRC_Message* mesg, char** optarg, char** reqarg); + +extern size_t Assm_tag_timestamp(char* buf, size_t len, time_t time); #endif #endif diff --git a/src/assemblers.h b/src/assemblers.h index 1a02570..d2dc3bd 100644 --- a/src/assemblers.h +++ b/src/assemblers.h @@ -20,6 +20,7 @@ #include "misc.h" #include #include +#include #ifndef _UIRC_INCLUDED_ASSM #define _UIRC_INCLUDED_ASSM diff --git a/src/helpers.c b/src/helpers.c index a013a49..3e99de6 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -149,6 +149,7 @@ IRC_Message* Assm_cmd_ISON(char* users[]) imassm_mesg.cmd = ISON; return &imassm_mesg; } + void Tok_cmd_PING(IRC_Message* mesg, char** source, char** target) { *source = (mesg->args[0] == NULL && mesg->trailing) ? mesg->args[2] : (mesg->args[1] != NULL) ? mesg->args[0] : NULL; diff --git a/src/helpers.h b/src/helpers.h index e459e06..1eab37d 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -22,6 +22,7 @@ #include #include #include +#include #ifndef _UIRC_INCLUDED_ASSM #define _UIRC_INCLUDED_ASSM diff --git a/src/taghelpers.c b/src/taghelpers.c new file mode 100644 index 0000000..410afcc --- /dev/null +++ b/src/taghelpers.c @@ -0,0 +1,24 @@ +/* + * 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 . +*/ + +#include "taghelpers.h" + +size_t Assm_tag_timestamp(char* buf, size_t len, time_t time) +{ + return strftime(buf, len, "%Y-%m-%dT%H:%M:%S.000Z", gmtime(&time)); +} diff --git a/src/taghelpers.h b/src/taghelpers.h new file mode 100644 index 0000000..d33ac9e --- /dev/null +++ b/src/taghelpers.h @@ -0,0 +1,30 @@ +/* + * 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 . +*/ + +#define _XOPEN_SOURCE +#include +#include +#include +#include +#include + +#ifndef _UIRC_INCLUDED_TAGASSM +#define _UIRC_INCLUDED_TAGASSM +size_t Assm_tag_timestamp(char* buf, size_t len, time_t time); +int Tok_tag_timestamp(char* timestamp, time_t* time); +#endif diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2aed495..cecd777 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -27,10 +27,19 @@ add_test(NAME SpacedArguments COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/spacedar if ( IRCV3 ) add_executable(tagtok tagtok.c) add_executable(tagassm tagassm.c) +if ( BUILD_HELPERS ) +add_executable(timestamp timestamp.c) +endif() target_link_libraries(tagtok uirc) target_link_libraries(tagassm uirc) +if ( BUILD_HELPERS ) +target_link_libraries(timestamp uirc) +endif() add_test(NAME TagParser COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tagtok) add_test(NAME TagAssembler COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tagassm) +if ( BUILD_HELPERS ) +add_test(NAME TimestampAssembly COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/timestamp) +endif() endif() diff --git a/tests/msgassm.c b/tests/msgassm.c index 7c52502..7903ae1 100644 --- a/tests/msgassm.c +++ b/tests/msgassm.c @@ -1,7 +1,7 @@ #include "../include/uirc.h" -#include "stdio.h" -#include "stdlib.h" -#include "string.h" +#include +#include +#include int main(void) { diff --git a/tests/notrail.c b/tests/notrail.c index 6f3d1b0..a9ab680 100644 --- a/tests/notrail.c +++ b/tests/notrail.c @@ -1,7 +1,7 @@ #include "../include/uirc.h" -#include "stdio.h" -#include "stdlib.h" -#include "string.h" +#include +#include +#include int main(void) { diff --git a/tests/numericmds.c b/tests/numericmds.c index 9ad05d2..f326707 100644 --- a/tests/numericmds.c +++ b/tests/numericmds.c @@ -1,7 +1,7 @@ #include "../include/uirc.h" -#include "stdio.h" -#include "stdlib.h" -#include "string.h" +#include +#include +#include int main(void) { diff --git a/tests/overflow.c b/tests/overflow.c index bfdc0ca..b1948f8 100644 --- a/tests/overflow.c +++ b/tests/overflow.c @@ -1,7 +1,7 @@ #include "../include/uirc.h" -#include "stdio.h" -#include "stdlib.h" -#include "string.h" +#include +#include +#include int main(void) { diff --git a/tests/prefixassm.c b/tests/prefixassm.c index 05fede3..9ca1b8b 100644 --- a/tests/prefixassm.c +++ b/tests/prefixassm.c @@ -1,7 +1,7 @@ #include "../include/uirc.h" -#include "stdio.h" -#include "stdlib.h" -#include "string.h" +#include +#include +#include int main(void) { diff --git a/tests/spacedargs.c b/tests/spacedargs.c index 2d95ec6..a7511fd 100644 --- a/tests/spacedargs.c +++ b/tests/spacedargs.c @@ -1,7 +1,7 @@ #include "../include/uirc.h" -#include "stdio.h" -#include "stdlib.h" -#include "string.h" +#include +#include +#include #define cmd "QUIT" #define arg1 "arg1" diff --git a/tests/tagassm.c b/tests/tagassm.c index 2f1546b..4f703da 100644 --- a/tests/tagassm.c +++ b/tests/tagassm.c @@ -2,9 +2,9 @@ #define UIRC_IRCV3 #endif #include "../include/uirc.h" -#include "stdio.h" -#include "stdlib.h" -#include "string.h" +#include +#include +#include int main(void) { diff --git a/tests/tagtok.c b/tests/tagtok.c index beae6fc..779cc72 100644 --- a/tests/tagtok.c +++ b/tests/tagtok.c @@ -2,9 +2,9 @@ #define UIRC_IRCV3 #endif #include "../include/uirc.h" -#include "stdio.h" -#include "stdlib.h" -#include "string.h" +#include +#include +#include int main(void) { diff --git a/tests/timestamp.c b/tests/timestamp.c new file mode 100644 index 0000000..822c328 --- /dev/null +++ b/tests/timestamp.c @@ -0,0 +1,14 @@ +#define UIRC_HELPERS +#include "../include/uirc.h" +#include +#include +#include + +int main(void) +{ + char buffer[26]; + time_t res = 1130620230; + if (Assm_tag_timestamp(buffer, sizeof(buffer), res)) + printf("Time is: %s\n", buffer); + return EXIT_SUCCESS; +} diff --git a/tests/tokenizer.c b/tests/tokenizer.c index e195b5f..77b209f 100644 --- a/tests/tokenizer.c +++ b/tests/tokenizer.c @@ -1,7 +1,7 @@ #include "../include/uirc.h" -#include "stdio.h" -#include "stdlib.h" -#include "string.h" +#include +#include +#include int main(void) {