Add tag helpers, timestamp assembler, use system defined paths for tests and add timestamp tests

This commit is contained in:
Alex D. 2020-09-01 11:49:37 +02:00
parent 5f19f7a4c1
commit 86f6dbe43f
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
18 changed files with 112 additions and 29 deletions

View File

@ -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)

View File

@ -15,8 +15,9 @@
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include "types.h"
#include <stdbool.h>
#include <time.h>
#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

View File

@ -20,6 +20,7 @@
#include "misc.h"
#include <stdio.h>
#include <string.h>
#include <time.h>
#ifndef _UIRC_INCLUDED_ASSM
#define _UIRC_INCLUDED_ASSM

View File

@ -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;

View File

@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifndef _UIRC_INCLUDED_ASSM
#define _UIRC_INCLUDED_ASSM

24
src/taghelpers.c Normal file
View File

@ -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 <https://www.gnu.org/licenses/>.
*/
#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));
}

30
src/taghelpers.h Normal file
View File

@ -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 <https://www.gnu.org/licenses/>.
*/
#define _XOPEN_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#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

View File

@ -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()

View File

@ -1,7 +1,7 @@
#include "../include/uirc.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{

View File

@ -1,7 +1,7 @@
#include "../include/uirc.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{

View File

@ -1,7 +1,7 @@
#include "../include/uirc.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{

View File

@ -1,7 +1,7 @@
#include "../include/uirc.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{

View File

@ -1,7 +1,7 @@
#include "../include/uirc.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{

View File

@ -1,7 +1,7 @@
#include "../include/uirc.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define cmd "QUIT"
#define arg1 "arg1"

View File

@ -2,9 +2,9 @@
#define UIRC_IRCV3
#endif
#include "../include/uirc.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{

View File

@ -2,9 +2,9 @@
#define UIRC_IRCV3
#endif
#include "../include/uirc.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{

14
tests/timestamp.c Normal file
View File

@ -0,0 +1,14 @@
#define UIRC_HELPERS
#include "../include/uirc.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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;
}

View File

@ -1,7 +1,7 @@
#include "../include/uirc.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{