2015-05-14 17:01:39 +00:00
|
|
|
/*
|
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2016-09-07 14:24:00 +00:00
|
|
|
* Copyright (C) 2015-2016 Symless Ltd.
|
2015-05-14 17:01:39 +00:00
|
|
|
*
|
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* found in the file LICENSE that should have accompanied this file.
|
|
|
|
|
*
|
|
|
|
|
* This package 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2015-05-20 14:51:07 +00:00
|
|
|
#include "arch/Arch.h"
|
2024-07-02 19:07:06 +00:00
|
|
|
#include "ipc/IpcMessage.h"
|
|
|
|
|
#include "ipc/IpcServer.h"
|
2015-05-14 17:01:39 +00:00
|
|
|
|
2024-07-16 08:30:35 +00:00
|
|
|
#include <gmock/gmock.h>
|
2015-05-14 17:01:39 +00:00
|
|
|
|
2015-05-20 14:51:07 +00:00
|
|
|
using ::testing::_;
|
|
|
|
|
using ::testing::Invoke;
|
|
|
|
|
|
2015-05-14 17:01:39 +00:00
|
|
|
class IEventQueue;
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
class MockIpcServer : public IpcServer {
|
2015-05-14 17:01:39 +00:00
|
|
|
public:
|
2024-07-02 19:07:06 +00:00
|
|
|
MockIpcServer()
|
|
|
|
|
: m_sendCond(ARCH->newCondVar()), m_sendMutex(ARCH->newMutex()) {}
|
2015-07-21 21:10:50 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
~MockIpcServer() {
|
|
|
|
|
if (m_sendCond != NULL) {
|
|
|
|
|
ARCH->closeCondVar(m_sendCond);
|
2016-12-28 11:50:32 +00:00
|
|
|
}
|
2015-05-14 17:01:39 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
if (m_sendMutex != NULL) {
|
|
|
|
|
ARCH->closeMutex(m_sendMutex);
|
2016-12-28 11:50:32 +00:00
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2015-05-20 14:51:07 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
MOCK_METHOD(void, listen, (), (override));
|
|
|
|
|
MOCK_METHOD(void, send, (const IpcMessage &, EIpcClientType), (override));
|
|
|
|
|
MOCK_METHOD(bool, hasClients, (EIpcClientType), (const, override));
|
|
|
|
|
|
|
|
|
|
void delegateToFake() {
|
|
|
|
|
ON_CALL(*this, send(_, _))
|
|
|
|
|
.WillByDefault(Invoke(this, &MockIpcServer::mockSend));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void waitForSend() { ARCH->waitCondVar(m_sendCond, m_sendMutex, 5); }
|
2015-05-20 14:51:07 +00:00
|
|
|
|
|
|
|
|
private:
|
2024-07-02 19:07:06 +00:00
|
|
|
void mockSend(const IpcMessage &, EIpcClientType) {
|
|
|
|
|
ArchMutexLock lock(m_sendMutex);
|
|
|
|
|
ARCH->broadcastCondVar(m_sendCond);
|
|
|
|
|
}
|
2015-05-20 14:51:07 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
ArchCond m_sendCond;
|
|
|
|
|
ArchMutex m_sendMutex;
|
2015-05-14 17:01:39 +00:00
|
|
|
};
|