diff --git a/server/modules/filter/dbfwfilter/test/maxscale/mock/dcb.hh b/server/modules/filter/dbfwfilter/test/maxscale/mock/dcb.hh new file mode 100644 index 000000000..5834d0463 --- /dev/null +++ b/server/modules/filter/dbfwfilter/test/maxscale/mock/dcb.hh @@ -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 +#include + +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; +}; + +} + +} diff --git a/server/modules/filter/dbfwfilter/test/maxscale/mock/session.hh b/server/modules/filter/dbfwfilter/test/maxscale/mock/session.hh new file mode 100644 index 000000000..ea622505b --- /dev/null +++ b/server/modules/filter/dbfwfilter/test/maxscale/mock/session.hh @@ -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 +#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; +}; + +} + +} diff --git a/server/modules/filter/dbfwfilter/test/mock_dcb.cc b/server/modules/filter/dbfwfilter/test/mock_dcb.cc new file mode 100644 index 000000000..9d561ae58 --- /dev/null +++ b/server/modules/filter/dbfwfilter/test/mock_dcb.cc @@ -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(zHost); + pDcb->user = const_cast(zUser); +} + +Dcb::~Dcb() +{ +} + +} + +} diff --git a/server/modules/filter/dbfwfilter/test/mock_session.cc b/server/modules/filter/dbfwfilter/test/mock_session.cc new file mode 100644 index 000000000..7d14439d7 --- /dev/null +++ b/server/modules/filter/dbfwfilter/test/mock_session.cc @@ -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() +{ +} + +} + +}