diff options
author | Andris Zeila <andris.zeila@zabbix.com> | 2021-11-10 15:16:37 +0300 |
---|---|---|
committer | Andris Zeila <andris.zeila@zabbix.com> | 2021-11-10 15:16:37 +0300 |
commit | 062b6e88c5bfca072ec2603cb2b2def7d9f9a85a (patch) | |
tree | be6fc05d49505e934ee6c0a529276114bca12a21 /tests/libs/zbxtrends | |
parent | f73c1677e4efd6d38d45fd56b3ab85d35b4a4d47 (diff) |
........S. [ZBXNEXT-2579] fixed zbx_tm_sub/add to check month days when used with month/year units.
Diffstat (limited to 'tests/libs/zbxtrends')
-rw-r--r-- | tests/libs/zbxtrends/zbx_baseline_season_diff.c | 102 | ||||
-rw-r--r-- | tests/libs/zbxtrends/zbx_baseline_season_diff.yaml | 211 |
2 files changed, 0 insertions, 313 deletions
diff --git a/tests/libs/zbxtrends/zbx_baseline_season_diff.c b/tests/libs/zbxtrends/zbx_baseline_season_diff.c deleted file mode 100644 index 9b158d8e014..00000000000 --- a/tests/libs/zbxtrends/zbx_baseline_season_diff.c +++ /dev/null @@ -1,102 +0,0 @@ -/* -** Zabbix -** Copyright (C) 2001-2021 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. -**/ - -#include "zbxmocktest.h" -#include "zbxmockdata.h" -#include "zbxmockassert.h" -#include "zbxmockutil.h" - -#include "common.h" -#include "zbxtrends.h" -#include "log.h" - -static zbx_time_unit_t mock_get_time_unit(const char *path) -{ - const char *unit; - - unit = zbx_mock_get_parameter_string(path); - - switch (*unit) - { - case 'w': - return ZBX_TIME_UNIT_WEEK; - case 'Y': - return ZBX_TIME_UNIT_ISOYEAR; - case 'y': - return ZBX_TIME_UNIT_YEAR; - case 'm': - return ZBX_TIME_UNIT_MONTH; - case 'd': - return ZBX_TIME_UNIT_DAY; - case 'h': - return ZBX_TIME_UNIT_HOUR; - default: - return ZBX_TIME_UNIT_UNKNOWN; - } -} - -static int mock_get_int(const char *path) -{ - const char *value; - zbx_mock_handle_t handle; - - if (ZBX_MOCK_SUCCESS != zbx_mock_parameter(path, &handle)) - return 0; - - if (ZBX_MOCK_SUCCESS != zbx_mock_string(handle, &value)) - fail_msg("invalid value at %s", path); - - return atoi(value); -} - -void zbx_mock_test_entry(void **state) -{ - zbx_timespec_t ts; - struct tm tm_season, tm_period; - time_t time_tmp; - zbx_time_unit_t season_unit; - zbx_tm_diff_t diff; - - ZBX_UNUSED(state); - - if (0 != setenv("TZ", zbx_mock_get_parameter_string("in.timezone"), 1)) - fail_msg("Cannot set 'TZ' environment variable: %s", zbx_strerror(errno)); - - tzset(); - - if (ZBX_MOCK_SUCCESS != zbx_strtime_to_timespec(zbx_mock_get_parameter_string("in.season.start"), &ts)) - fail_msg("Invalid input time format"); - - time_tmp = (time_t)ts.sec; - tm_season = *localtime(&time_tmp); - season_unit = mock_get_time_unit("in.season.unit"); - - if (ZBX_MOCK_SUCCESS != zbx_strtime_to_timespec(zbx_mock_get_parameter_string("in.period.start"), &ts)) - fail_msg("Invalid input time format"); - - time_tmp = (time_t)ts.sec; - tm_period = *localtime(&time_tmp); - - zbx_baseline_season_diff(&tm_season, season_unit, &tm_period, &diff); - - zbx_mock_assert_int_eq("weeks from season start", mock_get_int("out.weeks"), diff.weeks); - zbx_mock_assert_int_eq("months from season start", mock_get_int("out.months"), diff.months); - zbx_mock_assert_int_eq("days from season start", mock_get_int("out.days"), diff.days); - zbx_mock_assert_int_eq("hours from season start", mock_get_int("out.hours"), diff.hours); -} diff --git a/tests/libs/zbxtrends/zbx_baseline_season_diff.yaml b/tests/libs/zbxtrends/zbx_baseline_season_diff.yaml deleted file mode 100644 index 1d3db705910..00000000000 --- a/tests/libs/zbxtrends/zbx_baseline_season_diff.yaml +++ /dev/null @@ -1,211 +0,0 @@ ---- -test case: Hour period in Hour season (1) -in: - timezone: :Europe/Riga - season: - start: 2020-09-01 12:00:00 +03:00 - unit: h - period: - start: 2020-09-01 12:00:00 +03:00 - unit: h -out: - weeks: 0 - months: 0 - days: 0 - hours: 0 ---- -test case: Day period in day season (1) -in: - timezone: :Europe/Riga - season: - start: 2020-09-01 12:00:00 +03:00 - unit: d - period: - start: 2020-09-01 12:00:00 +03:00 - unit: d -out: - weeks: 0 - months: 0 - days: 0 - hours: 0 ---- -test case: Hour period in day season (1) -in: - timezone: :Europe/Riga - season: - start: 2020-09-01 00:00:00 +03:00 - unit: d - period: - start: 2020-09-01 00:00:00 +03:00 - unit: h -out: - weeks: 0 - months: 0 - days: 0 - hours: 0 ---- -test case: Hour period in day season (2) -in: - timezone: :Europe/Riga - season: - start: 2020-09-01 00:00:00 +03:00 - unit: d - period: - start: 2020-09-01 01:00:00 +03:00 - unit: h -out: - weeks: 0 - months: 0 - days: 0 - hours: 1 ---- -test case: Hour period in day season (3) -in: - timezone: :Europe/Riga - season: - start: 2020-09-01 00:00:00 +03:00 - unit: d - period: - start: 2020-09-01 23:00:00 +03:00 - unit: h -out: - weeks: 0 - months: 0 - days: 0 - hours: 23 ---- -test case: Day period in week season (1) -in: - timezone: :Europe/Riga - season: - start: 2021-11-08 00:00:00 +03:00 - unit: w - period: - start: 2021-11-08 00:00:00 +03:00 - unit: d -out: - weeks: 0 - months: 0 - days: 0 - hours: 0 ---- -test case: Day period in week season (2) -in: - timezone: :Europe/Riga - season: - start: 2021-11-08 00:00:00 +03:00 - unit: w - period: - start: 2021-11-09 00:00:00 +03:00 - unit: d -out: - weeks: 0 - months: 0 - days: 1 - hours: 0 ---- -test case: Day period in week season (3) -in: - timezone: :Europe/Riga - season: - start: 2021-11-08 00:00:00 +03:00 - unit: w - period: - start: 2021-11-14 00:00:00 +03:00 - unit: d -out: - weeks: 0 - months: 0 - days: 6 - hours: 0 ---- -test case: Hour period in week season (1) -in: - timezone: :Europe/Riga - season: - start: 2021-11-08 00:00:00 +02:00 - unit: w - period: - start: 2021-11-10 12:00:00 +02:00 - unit: h -out: - weeks: 0 - months: 0 - days: 2 - hours: 12 ---- -test case: Day period in month season (1) -in: - timezone: :Europe/Riga - season: - start: 2021-11-01 00:00:00 +02:00 - unit: m - period: - start: 2021-11-14 00:00:00 +02:00 - unit: d -out: - weeks: 0 - months: 0 - days: 13 - hours: 0 ---- -test case: Hour period in month season (1) -in: - timezone: :Europe/Riga - season: - start: 2021-11-01 00:00:00 +02:00 - unit: m - period: - start: 2021-11-14 12:00:00 +02:00 - unit: h -out: - weeks: 0 - months: 0 - days: 13 - hours: 12 ---- -test case: Hour period in year season (1) -in: - timezone: :Europe/Riga - season: - start: 2021-01-01 00:00:00 +02:00 - unit: y - period: - start: 2021-11-14 12:00:00 +02:00 - unit: h -out: - weeks: 0 - months: 10 - days: 13 - hours: 12 ---- -test case: Week period in year season (1) -in: - timezone: :Europe/Riga - season: - start: 2021-01-01 00:00:00 +02:00 - unit: y - period: - start: 2021-11-08 00:00:00 +02:00 - unit: w -out: - weeks: 45 - months: 0 - days: 0 - hours: 0 ---- -test case: Week period in year season (2) -in: - timezone: :Europe/Riga - season: - start: 2021-01-01 00:00:00 +02:00 - unit: y - period: - start: 2021-11-09 00:00:00 +02:00 - unit: w -out: - weeks: 45 - months: 0 - days: 1 - hours: 0 -... |