Source
/*
** Zabbix
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program 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 2 of the License, or
** (at your option) any later version.
**
** This program 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 this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/* Length of datetime like "2017-12-18,14:06:09.123,+02:30" */
/* Length of datetime like "2017-12-18,14:06:09" */
static zbx_timespec_t timespec;
time_t __wrap_time(time_t *seconds);
int __wrap_gettimeofday(struct timeval *__restrict tv, void *tz);
static void zbx_mock_time(void)
{
static int time_parsed = 0;
zbx_mock_error_t error;
zbx_mock_handle_t param_handle;
const char *timestamp;
struct tm tm;
int ms, hour, min;
char sign, tmp[16];
size_t length;
if (0 != time_parsed)
return; /* timestamp param was already parsed */
memset(&tm, 0, sizeof(tm));
memset(×pec, 0, sizeof(timespec));
if (ZBX_MOCK_SUCCESS != (error = zbx_mock_in_parameter("timestamp", ¶m_handle)) ||
ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, ×tamp)))
{
fail_msg("Cannot get expected 'timestamp' parameter from test case data: %s",
zbx_mock_error_string(error));
}
length = strlen(timestamp);
if (SHORT_DATETIME_LENGTH == length || LONG_DATETIME_LENGTH == length)
{
if (6 != sscanf(timestamp, "%04d-%02d-%02d,%02d:%02d:%02d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
&tm.tm_hour, &tm.tm_min, &tm.tm_sec) || 1900 > tm.tm_year || 1 > tm.tm_mon ||