MXS-1461 Add mock classes Session and Dcb

This commit is contained in:
Johan Wikman
2017-11-14 13:40:26 +02:00
parent 65cf491350
commit 531a8bafbd
4 changed files with 205 additions and 0 deletions

View 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;
};
}
}

View File

@ -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;
};
}
}

View 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()
{
}
}
}

View 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()
{
}
}
}