#include "zbxmocktest.h"
#include "zbxmockdata.h"
#include "zbxmockdb.h"
#define zbx_db_vselect __wrap_zbx_db_vselect
#define zbx_db_fetch_basic __wrap_zbx_db_fetch_basic
#define zbx_db_fetch __wrap_zbx_db_fetch_basic
#define zbx_db_free_result __wrap_zbx_db_free_result
#include "zbxdb.h"
#undef zbx_db_vselect
#undef zbx_db_fetch_basic
#undef zbx_db_fetch
#undef zbx_db_free_result
#define __zbx_db_execute __wrap___zbx_db_execute
#define zbx_db_execute_multiple_query __wrap_zbx_db_execute_multiple_query
#define zbx_db_begin __wrap_zbx_db_begin
#define zbx_db_commit __wrap_xbc_db_commit
#include "zbxdbhigh.h"
#undef __zbx_db_execute
#undef zbx_db_execute_multiple_query
#undef zbx_db_begin
#undef zbx_db_commit
#define ZBX_MOCK_DB_RESULT_COLUMNS_MAX 128
typedef struct
{
char *data_source;
int num;
}
zbx_mockdb_query_t;
typedef struct
{
zbx_hashset_t queries;
}
zbx_mockdb_t;
static zbx_mockdb_t mockdb;
struct zbx_db_result
{
zbx_db_row_t row;
char *data_source;
zbx_mock_handle_t rows;
int row_to_fetch;
int columns;
};
zbx_db_result_t __fwd_zbx_db_select(const char *fmt, ...);
zbx_db_result_t __wrap_zbx_db_select_n_basic(const char *query, int n);
int __wrap___zbx_db_execute(const char *fmt, ...);
int __wrap_zbx_db_commit(void);
static zbx_hash_t mockdb_query_hash(const void *data)
{
const zbx_mockdb_query_t *query = (const zbx_mockdb_query_t *)data;
return ZBX_DEFAULT_STRING_HASH_FUNC(query->data_source);
}
static int mockdb_query_compare(const void *d1, const void *d2)
{
const zbx_mockdb_query_t *q1 = (const zbx_mockdb_query_t *)d1;
const zbx_mockdb_query_t *q2 = (const zbx_mockdb_query_t *)d2;
return strcmp(q1->data_source, q2->data_source);
}