From b987f7abc1e654c4f0a609e000cf26fcb65733a9 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Sat, 2 Sep 2023 15:07:28 +0100 Subject: [PATCH] Fix test suite build issues. --- src/addrcache.c | 15 ++++++++++++--- tests/addr.c | 6 +++--- tests/addrcache.c | 20 +++++++++----------- tests/ethernet.c | 6 +++--- tests/tap/basic.c | 2 +- tests/tap/basic.h | 2 +- 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/addrcache.c b/src/addrcache.c index e7e2b2a..122b2e8 100644 --- a/src/addrcache.c +++ b/src/addrcache.c @@ -1,5 +1,5 @@ /* IPXWrapper - Address cache - * Copyright (C) 2008-2012 Daniel Collins + * Copyright (C) 2008-2023 Daniel Collins * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published by @@ -44,6 +44,15 @@ struct host_table { size_t addrlen; }; +/* time() wrapper function to enable the unit tests to mock it. */ + +static time_t addrcache_time_impl(void) +{ + return time(NULL); +} + +time_t (*addrcache_time)(void) = &addrcache_time_impl; + typedef struct host_table host_table_t; typedef struct host_table_key host_table_key_t; @@ -127,7 +136,7 @@ int addr_cache_get(SOCKADDR_STORAGE *addr, size_t *addrlen, addr32_t net, addr48 host_table_t *host = host_table_find(net, node, sock); - if(host && time(NULL) < host->time + ADDR_CACHE_TTL) + if(host && addrcache_time() < host->time + ADDR_CACHE_TTL) { memcpy(addr, &(host->addr), host->addrlen); *addrlen = host->addrlen; @@ -181,7 +190,7 @@ void addr_cache_set(const struct sockaddr *addr, size_t addrlen, addr32_t net, a memcpy(&(host->addr), addr, addrlen); host->addrlen = addrlen; - host->time = time(NULL); + host->time = addrcache_time(); host_table_unlock(); } diff --git a/tests/addr.c b/tests/addr.c index 6e3dc4d..e70ccd2 100644 --- a/tests/addr.c +++ b/tests/addr.c @@ -1,5 +1,5 @@ /* IPXWrapper test suite - * Copyright (C) 2014 Daniel Collins + * Copyright (C) 2014-2023 Daniel Collins * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published by @@ -18,8 +18,8 @@ #include #include -#include "tests/tap/basic.h" -#include "src/addr.h" +#include "tap/basic.h" +#include "../src/addr.h" static char *dump32(const void *p) { diff --git a/tests/addrcache.c b/tests/addrcache.c index 2783fdf..d05549a 100644 --- a/tests/addrcache.c +++ b/tests/addrcache.c @@ -1,5 +1,5 @@ /* IPXWrapper test suite - * Copyright (C) 2017 Daniel Collins + * Copyright (C) 2017-2023 Daniel Collins * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published by @@ -19,22 +19,17 @@ #include #include -#include "src/addr.h" -#include "src/addrcache.h" -#include "src/common.h" -#include "tests/tap/basic.h" +#include "../src/addr.h" +#include "../src/addrcache.h" +#include "../src/common.h" +#include "tap/basic.h" /* Mock time() so we can test timing out of address cache records */ static time_t now = 0; -time_t __cdecl time(time_t *_Time) +static time_t mock_time(void) { - if(_Time != NULL) - { - *_Time = now; - } - return now; } @@ -61,6 +56,9 @@ const char *w32_error(DWORD errnum) { int main() { + extern time_t (*addrcache_time)(void); + addrcache_time = &mock_time; + plan_lazy(); { diff --git a/tests/ethernet.c b/tests/ethernet.c index cb43fc0..67d493b 100644 --- a/tests/ethernet.c +++ b/tests/ethernet.c @@ -1,5 +1,5 @@ /* IPXWrapper test suite - * Copyright (C) 2017 Daniel Collins + * Copyright (C) 2017-2023 Daniel Collins * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published by @@ -20,8 +20,8 @@ #include #include -#include "tests/tap/basic.h" -#include "src/ethernet.h" +#include "tap/basic.h" +#include "../src/ethernet.h" #define CHECK_FRAME_SIZE(func, input, output) \ is_int((output), func(input), #func "(" #input ") returns " #output) diff --git a/tests/tap/basic.c b/tests/tap/basic.c index 45b664c..345d6a0 100644 --- a/tests/tap/basic.c +++ b/tests/tap/basic.c @@ -49,7 +49,7 @@ #include #include -#include +#include "basic.h" /* Windows provides mkdir and rmdir under different names. */ #ifdef _WIN32 diff --git a/tests/tap/basic.h b/tests/tap/basic.h index a32eb2e..84b405b 100644 --- a/tests/tap/basic.h +++ b/tests/tap/basic.h @@ -30,7 +30,7 @@ #ifndef TAP_BASIC_H #define TAP_BASIC_H 1 -#include +#include "macros.h" #include /* va_list */ #include /* size_t */