Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DBselect_uint64.c « zbxdbhigh « libs « tests - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d710b462c8b255a3ecffa3af0cd5c7489b5e2cf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
** Zabbix
** Copyright (C) 2001-2018 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 "zbxmockdb.h"

#include "common.h"
#include "zbxalgo.h"
#include "db.h"

void	zbx_mock_test_entry(void **state)
{
	zbx_mock_error_t	error;
	zbx_mock_handle_t	in_sql, expected_results, expected_result;
	const char		*sql;
	zbx_vector_uint64_t	actual_results;
	int			i;

	ZBX_UNUSED(state);

	zbx_mockdb_init();

	if (ZBX_MOCK_SUCCESS != (error = zbx_mock_in_parameter("sql", &in_sql)) ||
			ZBX_MOCK_SUCCESS != (error = zbx_mock_string(in_sql, &sql)))
	{
		fail_msg("Cannot get SQL query from test case data: %s", zbx_mock_error_string(error));
	}

	if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("uint64", &expected_results)))
		fail_msg("Cannot get expected results from test case data: %s", zbx_mock_error_string(error));

	zbx_vector_uint64_create(&actual_results);
	DBselect_uint64(sql, &actual_results);

	for (i = 0; ZBX_MOCK_SUCCESS == (error = zbx_mock_vector_element(expected_results, &expected_result)); i++)
	{
		const char	*expected_result_string;
		zbx_uint64_t	expected_result_uint64;

		if (ZBX_MOCK_SUCCESS != (error = zbx_mock_string(expected_result, &expected_result_string)))
			break;

		if (SUCCEED != is_uint64(expected_result_string, &expected_result_uint64))
			fail_msg("Cannot convert expected result #%d to unsigned 64 bit integer.", i + 1);

		if (i >= actual_results.values_num)
			fail_msg("There are fewer actual results (%d) than expected.", actual_results.values_num);

		if (expected_result_uint64 != actual_results.values[i])
		{
			fail_msg("Unexpected result #%d: " ZBX_FS_UI64 " instead of " ZBX_FS_UI64 ".", i + 1,
					actual_results.values[i], expected_result_uint64);
		}
	}

	if (ZBX_MOCK_END_OF_VECTOR != error)
		fail_msg("Cannot get expected result #%d from test case data: %s", i + 1, zbx_mock_error_string(error));

	if (i < actual_results.values_num)
		fail_msg("There are more actual results (%d) than expected (%d).", i, actual_results.values_num);

	zbx_vector_uint64_destroy(&actual_results);

	zbx_mockdb_destroy();
}