mirror of
https://github.com/solemnwarning/ipxwrapper
synced 2024-12-30 16:45:37 +01:00
Fix test suite build issues.
This commit is contained in:
parent
46fc990971
commit
b987f7abc1
@ -1,5 +1,5 @@
|
|||||||
/* IPXWrapper - Address cache
|
/* IPXWrapper - Address cache
|
||||||
* Copyright (C) 2008-2012 Daniel Collins <solemnwarning@solemnwarning.net>
|
* Copyright (C) 2008-2023 Daniel Collins <solemnwarning@solemnwarning.net>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* 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
|
* under the terms of the GNU General Public License version 2 as published by
|
||||||
@ -44,6 +44,15 @@ struct host_table {
|
|||||||
size_t addrlen;
|
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 host_table_t;
|
||||||
typedef struct host_table_key host_table_key_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);
|
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);
|
memcpy(addr, &(host->addr), host->addrlen);
|
||||||
*addrlen = 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);
|
memcpy(&(host->addr), addr, addrlen);
|
||||||
host->addrlen = addrlen;
|
host->addrlen = addrlen;
|
||||||
|
|
||||||
host->time = time(NULL);
|
host->time = addrcache_time();
|
||||||
|
|
||||||
host_table_unlock();
|
host_table_unlock();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* IPXWrapper test suite
|
/* IPXWrapper test suite
|
||||||
* Copyright (C) 2014 Daniel Collins <solemnwarning@solemnwarning.net>
|
* Copyright (C) 2014-2023 Daniel Collins <solemnwarning@solemnwarning.net>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* 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
|
* under the terms of the GNU General Public License version 2 as published by
|
||||||
@ -18,8 +18,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tests/tap/basic.h"
|
#include "tap/basic.h"
|
||||||
#include "src/addr.h"
|
#include "../src/addr.h"
|
||||||
|
|
||||||
static char *dump32(const void *p)
|
static char *dump32(const void *p)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* IPXWrapper test suite
|
/* IPXWrapper test suite
|
||||||
* Copyright (C) 2017 Daniel Collins <solemnwarning@solemnwarning.net>
|
* Copyright (C) 2017-2023 Daniel Collins <solemnwarning@solemnwarning.net>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* 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
|
* under the terms of the GNU General Public License version 2 as published by
|
||||||
@ -19,22 +19,17 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "src/addr.h"
|
#include "../src/addr.h"
|
||||||
#include "src/addrcache.h"
|
#include "../src/addrcache.h"
|
||||||
#include "src/common.h"
|
#include "../src/common.h"
|
||||||
#include "tests/tap/basic.h"
|
#include "tap/basic.h"
|
||||||
|
|
||||||
/* Mock time() so we can test timing out of address cache records */
|
/* Mock time() so we can test timing out of address cache records */
|
||||||
|
|
||||||
static time_t now = 0;
|
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;
|
return now;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,6 +56,9 @@ const char *w32_error(DWORD errnum) {
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
extern time_t (*addrcache_time)(void);
|
||||||
|
addrcache_time = &mock_time;
|
||||||
|
|
||||||
plan_lazy();
|
plan_lazy();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* IPXWrapper test suite
|
/* IPXWrapper test suite
|
||||||
* Copyright (C) 2017 Daniel Collins <solemnwarning@solemnwarning.net>
|
* Copyright (C) 2017-2023 Daniel Collins <solemnwarning@solemnwarning.net>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* 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
|
* under the terms of the GNU General Public License version 2 as published by
|
||||||
@ -20,8 +20,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tests/tap/basic.h"
|
#include "tap/basic.h"
|
||||||
#include "src/ethernet.h"
|
#include "../src/ethernet.h"
|
||||||
|
|
||||||
#define CHECK_FRAME_SIZE(func, input, output) \
|
#define CHECK_FRAME_SIZE(func, input, output) \
|
||||||
is_int((output), func(input), #func "(" #input ") returns " #output)
|
is_int((output), func(input), #func "(" #input ") returns " #output)
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <tests/tap/basic.h>
|
#include "basic.h"
|
||||||
|
|
||||||
/* Windows provides mkdir and rmdir under different names. */
|
/* Windows provides mkdir and rmdir under different names. */
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
#ifndef TAP_BASIC_H
|
#ifndef TAP_BASIC_H
|
||||||
#define TAP_BASIC_H 1
|
#define TAP_BASIC_H 1
|
||||||
|
|
||||||
#include <tests/tap/macros.h>
|
#include "macros.h"
|
||||||
#include <stdarg.h> /* va_list */
|
#include <stdarg.h> /* va_list */
|
||||||
#include <stddef.h> /* size_t */
|
#include <stddef.h> /* size_t */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user