MXS-1461 Add mock classes Session and Dcb
This commit is contained in:
53
server/modules/filter/dbfwfilter/test/maxscale/mock/dcb.hh
Normal file
53
server/modules/filter/dbfwfilter/test/maxscale/mock/dcb.hh
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#pragma once
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||||
|
*
|
||||||
|
* Use of this software is governed by the Business Source License included
|
||||||
|
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||||
|
*
|
||||||
|
* Change Date: 2020-01-01
|
||||||
|
*
|
||||||
|
* On the date above, in accordance with the Business Source License, use
|
||||||
|
* of this software will be governed by version 2 or later of the General
|
||||||
|
* Public License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mock.hh"
|
||||||
|
#include <maxscale/dcb.h>
|
||||||
|
#include <maxscale/session.h>
|
||||||
|
|
||||||
|
namespace maxscale
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace mock
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The class Dcb provides a mock DCB that can be used when testing.
|
||||||
|
*/
|
||||||
|
class Dcb : public DCB
|
||||||
|
{
|
||||||
|
Dcb(const Dcb&);
|
||||||
|
Dcb& operator = (const Dcb&);
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param pSession The session object of the DCB.
|
||||||
|
* @param zUser The client of the connection.
|
||||||
|
* @param zHost The host of the connection.
|
||||||
|
*/
|
||||||
|
Dcb(MXS_SESSION* pSession,
|
||||||
|
const char* zUser,
|
||||||
|
const char* zHost);
|
||||||
|
~Dcb();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_user;
|
||||||
|
std::string m_host;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
#pragma once
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||||
|
*
|
||||||
|
* Use of this software is governed by the Business Source License included
|
||||||
|
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||||
|
*
|
||||||
|
* Change Date: 2020-01-01
|
||||||
|
*
|
||||||
|
* On the date above, in accordance with the Business Source License, use
|
||||||
|
* of this software will be governed by version 2 or later of the General
|
||||||
|
* Public License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mock.hh"
|
||||||
|
#include <maxscale/session.h>
|
||||||
|
#include "dcb.hh"
|
||||||
|
|
||||||
|
namespace maxscale
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace mock
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The class Session provides a mock MXS_SESSION that can be used when
|
||||||
|
* testing.
|
||||||
|
*/
|
||||||
|
class Session : public MXS_SESSION
|
||||||
|
{
|
||||||
|
Session(const Session&);
|
||||||
|
Session& operator = (Session&);
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param zUser The client of the session,
|
||||||
|
* @param zHost The host of the client.
|
||||||
|
*/
|
||||||
|
Session(const char* zUser,
|
||||||
|
const char* zHost = "127.0.0.1");
|
||||||
|
~Session();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Dcb m_client_dcb;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
58
server/modules/filter/dbfwfilter/test/mock_dcb.cc
Normal file
58
server/modules/filter/dbfwfilter/test/mock_dcb.cc
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||||
|
*
|
||||||
|
* Use of this software is governed by the Business Source License included
|
||||||
|
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||||
|
*
|
||||||
|
* Change Date: 2020-01-01
|
||||||
|
*
|
||||||
|
* On the date above, in accordance with the Business Source License, use
|
||||||
|
* of this software will be governed by version 2 or later of the General
|
||||||
|
* Public License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "maxscale/mock/dcb.hh"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
void initialize_dcb(DCB* pDcb)
|
||||||
|
{
|
||||||
|
memset(pDcb, 0, sizeof(DCB));
|
||||||
|
|
||||||
|
pDcb->dcb_chk_top = CHK_NUM_DCB;
|
||||||
|
pDcb->fd = DCBFD_CLOSED;
|
||||||
|
pDcb->state = DCB_STATE_ALLOC;
|
||||||
|
pDcb->ssl_state = SSL_HANDSHAKE_UNKNOWN;
|
||||||
|
pDcb->dcb_chk_tail = CHK_NUM_DCB;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace maxscale
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace mock
|
||||||
|
{
|
||||||
|
|
||||||
|
Dcb::Dcb(MXS_SESSION* pSession,
|
||||||
|
const char* zUser,
|
||||||
|
const char* zHost)
|
||||||
|
: m_user(zUser)
|
||||||
|
, m_host(zHost)
|
||||||
|
{
|
||||||
|
DCB* pDcb = this;
|
||||||
|
initialize_dcb(this);
|
||||||
|
|
||||||
|
pDcb->session = pSession;
|
||||||
|
pDcb->remote = const_cast<char*>(zHost);
|
||||||
|
pDcb->user = const_cast<char*>(zUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
Dcb::~Dcb()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
43
server/modules/filter/dbfwfilter/test/mock_session.cc
Normal file
43
server/modules/filter/dbfwfilter/test/mock_session.cc
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||||
|
*
|
||||||
|
* Use of this software is governed by the Business Source License included
|
||||||
|
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||||
|
*
|
||||||
|
* Change Date: 2020-01-01
|
||||||
|
*
|
||||||
|
* On the date above, in accordance with the Business Source License, use
|
||||||
|
* of this software will be governed by version 2 or later of the General
|
||||||
|
* Public License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "maxscale/mock/session.hh"
|
||||||
|
|
||||||
|
namespace maxscale
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace mock
|
||||||
|
{
|
||||||
|
|
||||||
|
Session::Session(const char* zUser,
|
||||||
|
const char* zHost)
|
||||||
|
: m_client_dcb(this, zUser, zHost)
|
||||||
|
{
|
||||||
|
MXS_SESSION* pSession = this;
|
||||||
|
|
||||||
|
memset(pSession, 0, sizeof(MXS_SESSION));
|
||||||
|
|
||||||
|
pSession->ses_chk_top = CHK_NUM_SESSION;
|
||||||
|
pSession->state = SESSION_STATE_ALLOC;
|
||||||
|
pSession->ses_chk_tail = CHK_NUM_SESSION;
|
||||||
|
|
||||||
|
pSession->client_dcb = &m_client_dcb;
|
||||||
|
}
|
||||||
|
|
||||||
|
Session::~Session()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user