diff options
Diffstat (limited to 'src/test/mock')
| -rw-r--r-- | src/test/mock/barrier/MockApp.h | 44 | ||||
| -rw-r--r-- | src/test/mock/barrier/MockArgParser.h | 33 | ||||
| -rw-r--r-- | src/test/mock/barrier/MockEventQueue.h | 67 | ||||
| -rw-r--r-- | src/test/mock/barrier/MockKeyMap.h | 36 | ||||
| -rw-r--r-- | src/test/mock/barrier/MockKeyState.h | 57 | ||||
| -rw-r--r-- | src/test/mock/barrier/MockScreen.h | 36 | ||||
| -rw-r--r-- | src/test/mock/io/MockStream.h | 44 | ||||
| -rw-r--r-- | src/test/mock/ipc/MockIpcServer.h | 68 | ||||
| -rw-r--r-- | src/test/mock/server/MockConfig.h | 32 | ||||
| -rw-r--r-- | src/test/mock/server/MockInputFilter.h | 30 | ||||
| -rw-r--r-- | src/test/mock/server/MockPrimaryClient.h | 41 | ||||
| -rw-r--r-- | src/test/mock/server/MockServer.h | 32 |
12 files changed, 520 insertions, 0 deletions
diff --git a/src/test/mock/barrier/MockApp.h b/src/test/mock/barrier/MockApp.h new file mode 100644 index 0000000..91745d3 --- /dev/null +++ b/src/test/mock/barrier/MockApp.h @@ -0,0 +1,44 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2014-2016 Symless Ltd. + * + * 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 + +#define TEST_ENV + +#include "barrier/App.h" + +#include "test/global/gmock.h" + +class MockApp : public App +{ +public: + MockApp() : App(NULL, NULL, NULL) { } + + MOCK_METHOD0(help, void()); + MOCK_METHOD0(loadConfig, void()); + MOCK_METHOD1(loadConfig, bool(const String&)); + MOCK_CONST_METHOD0(daemonInfo, const char*()); + MOCK_CONST_METHOD0(daemonName, const char*()); + MOCK_METHOD2(parseArgs, void(int, const char* const*)); + MOCK_METHOD0(version, void()); + MOCK_METHOD2(standardStartup, int(int, char**)); + MOCK_METHOD4(runInner, int(int, char**, ILogOutputter*, StartupFunc)); + MOCK_METHOD0(startNode, void()); + MOCK_METHOD0(mainLoop, int()); + MOCK_METHOD2(foregroundStartup, int(int, char**)); + MOCK_METHOD0(createScreen, barrier::Screen*()); +}; diff --git a/src/test/mock/barrier/MockArgParser.h b/src/test/mock/barrier/MockArgParser.h new file mode 100644 index 0000000..b1dc07c --- /dev/null +++ b/src/test/mock/barrier/MockArgParser.h @@ -0,0 +1,33 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2014-2016 Symless Ltd. + * + * 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 + +#define TEST_ENV + +#include "barrier/ArgParser.h" + +#include "test/global/gmock.h" + +class MockArgParser : public ArgParser +{ +public: + MockArgParser() : ArgParser(NULL) { } + + MOCK_METHOD3(parseGenericArgs, bool(int, const char* const*, int&)); + MOCK_METHOD0(checkUnexpectedArgs, bool()); +}; diff --git a/src/test/mock/barrier/MockEventQueue.h b/src/test/mock/barrier/MockEventQueue.h new file mode 100644 index 0000000..f273736 --- /dev/null +++ b/src/test/mock/barrier/MockEventQueue.h @@ -0,0 +1,67 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2012-2016 Symless Ltd. + * Copyright (C) 2011 Nick Bolton + * + * 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 + +#include "base/IEventQueue.h" + +#include "test/global/gmock.h" + +class MockEventQueue : public IEventQueue +{ +public: + MOCK_METHOD0(loop, void()); + MOCK_METHOD2(newOneShotTimer, EventQueueTimer*(double, void*)); + MOCK_METHOD2(newTimer, EventQueueTimer*(double, void*)); + MOCK_METHOD2(getEvent, bool(Event&, double)); + MOCK_METHOD1(adoptBuffer, void(IEventQueueBuffer*)); + MOCK_METHOD2(registerTypeOnce, Event::Type(Event::Type&, const char*)); + MOCK_METHOD1(removeHandlers, void(void*)); + MOCK_METHOD1(registerType, Event::Type(const char*)); + MOCK_CONST_METHOD0(isEmpty, bool()); + MOCK_METHOD3(adoptHandler, void(Event::Type, void*, IEventJob*)); + MOCK_METHOD1(getTypeName, const char*(Event::Type)); + MOCK_METHOD1(addEvent, void(const Event&)); + MOCK_METHOD2(removeHandler, void(Event::Type, void*)); + MOCK_METHOD1(dispatchEvent, bool(const Event&)); + MOCK_CONST_METHOD2(getHandler, IEventJob*(Event::Type, void*)); + MOCK_METHOD1(deleteTimer, void(EventQueueTimer*)); + MOCK_CONST_METHOD1(getRegisteredType, Event::Type(const String&)); + MOCK_METHOD0(getSystemTarget, void*()); + MOCK_METHOD0(forClient, ClientEvents&()); + MOCK_METHOD0(forIStream, IStreamEvents&()); + MOCK_METHOD0(forIpcClient, IpcClientEvents&()); + MOCK_METHOD0(forIpcClientProxy, IpcClientProxyEvents&()); + MOCK_METHOD0(forIpcServer, IpcServerEvents&()); + MOCK_METHOD0(forIpcServerProxy, IpcServerProxyEvents&()); + MOCK_METHOD0(forIDataSocket, IDataSocketEvents&()); + MOCK_METHOD0(forIListenSocket, IListenSocketEvents&()); + MOCK_METHOD0(forISocket, ISocketEvents&()); + MOCK_METHOD0(forOSXScreen, OSXScreenEvents&()); + MOCK_METHOD0(forClientListener, ClientListenerEvents&()); + MOCK_METHOD0(forClientProxy, ClientProxyEvents&()); + MOCK_METHOD0(forClientProxyUnknown, ClientProxyUnknownEvents&()); + MOCK_METHOD0(forServer, ServerEvents&()); + MOCK_METHOD0(forServerApp, ServerAppEvents&()); + MOCK_METHOD0(forIKeyState, IKeyStateEvents&()); + MOCK_METHOD0(forIPrimaryScreen, IPrimaryScreenEvents&()); + MOCK_METHOD0(forIScreen, IScreenEvents&()); + MOCK_METHOD0(forClipboard, ClipboardEvents&()); + MOCK_METHOD0(forFile, FileEvents&()); + MOCK_CONST_METHOD0(waitForReady, void()); +}; diff --git a/src/test/mock/barrier/MockKeyMap.h b/src/test/mock/barrier/MockKeyMap.h new file mode 100644 index 0000000..ef711a5 --- /dev/null +++ b/src/test/mock/barrier/MockKeyMap.h @@ -0,0 +1,36 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2012-2016 Symless Ltd. + * Copyright (C) 2011 Nick Bolton + * + * 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 + +#include "barrier/KeyMap.h" + +#include "test/global/gmock.h" + +class MockKeyMap : public barrier::KeyMap +{ +public: + MOCK_METHOD1(swap, void(KeyMap&)); + MOCK_METHOD0(finish, void()); + MOCK_METHOD2(foreachKey, void(ForeachKeyCallback, void*)); + MOCK_METHOD1(addHalfDuplexModifier, void(KeyID)); + MOCK_CONST_METHOD2(isHalfDuplex, bool(KeyID, KeyButton)); + MOCK_CONST_METHOD7(mapKey, const KeyMap::KeyItem*( + Keystrokes&, KeyID, SInt32, ModifierToKeys&, KeyModifierMask&, + KeyModifierMask, bool)); +}; diff --git a/src/test/mock/barrier/MockKeyState.h b/src/test/mock/barrier/MockKeyState.h new file mode 100644 index 0000000..308e90a --- /dev/null +++ b/src/test/mock/barrier/MockKeyState.h @@ -0,0 +1,57 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2012-2016 Symless Ltd. + * Copyright (C) 2011 Nick Bolton + * + * 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 + +#include "barrier/KeyState.h" + +#include "test/global/gmock.h" + +class MockKeyMap; +class MockEventQueue; + +// NOTE: do not mock methods that are not pure virtual. this mock exists only +// to provide an implementation of the KeyState abstract class. +class MockKeyState : public KeyState +{ +public: + MockKeyState(const MockEventQueue& eventQueue) : + KeyState((IEventQueue*)&eventQueue) + { + } + + MockKeyState(const MockEventQueue& eventQueue, const MockKeyMap& keyMap) : + KeyState((IEventQueue*)&eventQueue, (barrier::KeyMap&)keyMap) + { + } + + MOCK_CONST_METHOD0(pollActiveGroup, SInt32()); + MOCK_CONST_METHOD0(pollActiveModifiers, KeyModifierMask()); + MOCK_METHOD0(fakeCtrlAltDel, bool()); + MOCK_METHOD1(getKeyMap, void(barrier::KeyMap&)); + MOCK_METHOD1(fakeKey, void(const Keystroke&)); + MOCK_METHOD1(fakeMediaKey, bool(KeyID)); + MOCK_CONST_METHOD1(pollPressedKeys, void(KeyButtonSet&)); +}; + +typedef ::testing::NiceMock<MockKeyState> KeyStateImpl; + +typedef UInt32 KeyID; + +typedef void (*ForeachKeyCallback)( + KeyID, SInt32 group, barrier::KeyMap::KeyItem&, void* userData); diff --git a/src/test/mock/barrier/MockScreen.h b/src/test/mock/barrier/MockScreen.h new file mode 100644 index 0000000..78c195a --- /dev/null +++ b/src/test/mock/barrier/MockScreen.h @@ -0,0 +1,36 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2013-2016 Symless Ltd. + * + * 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 + +#define TEST_ENV + +#include "barrier/Screen.h" + +#include "test/global/gmock.h" + +class MockScreen : public barrier::Screen +{ +public: + MockScreen() : barrier::Screen() { } + MOCK_METHOD0(disable, void()); + MOCK_CONST_METHOD4(getShape, void(SInt32&, SInt32&, SInt32&, SInt32&)); + MOCK_CONST_METHOD2(getCursorPos, void(SInt32&, SInt32&)); + MOCK_METHOD0(resetOptions, void()); + MOCK_METHOD1(setOptions, void(const OptionsList&)); + MOCK_METHOD0(enable, void()); +}; diff --git a/src/test/mock/io/MockStream.h b/src/test/mock/io/MockStream.h new file mode 100644 index 0000000..bd12739 --- /dev/null +++ b/src/test/mock/io/MockStream.h @@ -0,0 +1,44 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2012-2016 Symless Ltd. + * Copyright (C) 2011 Nick Bolton + * + * 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 + +#include "io/IStream.h" + +#include "test/global/gmock.h" + +class IEventQueue; + +class MockStream : public barrier::IStream +{ +public: + MockStream() { } + MOCK_METHOD0(close, void()); + MOCK_METHOD2(read, UInt32(void*, UInt32)); + MOCK_METHOD2(write, void(const void*, UInt32)); + MOCK_METHOD0(flush, void()); + MOCK_METHOD0(shutdownInput, void()); + MOCK_METHOD0(shutdownOutput, void()); + MOCK_METHOD0(getInputReadyEvent, Event::Type()); + MOCK_METHOD0(getOutputErrorEvent, Event::Type()); + MOCK_METHOD0(getInputShutdownEvent, Event::Type()); + MOCK_METHOD0(getOutputShutdownEvent, Event::Type()); + MOCK_CONST_METHOD0(getEventTarget, void*()); + MOCK_CONST_METHOD0(isReady, bool()); + MOCK_CONST_METHOD0(getSize, UInt32()); +}; diff --git a/src/test/mock/ipc/MockIpcServer.h b/src/test/mock/ipc/MockIpcServer.h new file mode 100644 index 0000000..4124b41 --- /dev/null +++ b/src/test/mock/ipc/MockIpcServer.h @@ -0,0 +1,68 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2015-2016 Symless Ltd. + * + * 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 + +#include "ipc/IpcServer.h" +#include "ipc/IpcMessage.h" +#include "arch/Arch.h" + +#include "test/global/gmock.h" + +using ::testing::_; +using ::testing::Invoke; + +class IEventQueue; + +class MockIpcServer : public IpcServer +{ +public: + MockIpcServer() : + m_sendCond(ARCH->newCondVar()), + m_sendMutex(ARCH->newMutex()) { } + + ~MockIpcServer() { + if (m_sendCond != NULL) { + ARCH->closeCondVar(m_sendCond); + } + + if (m_sendMutex != NULL) { + ARCH->closeMutex(m_sendMutex); + } + } + + MOCK_METHOD0(listen, void()); + MOCK_METHOD2(send, void(const IpcMessage&, EIpcClientType)); + MOCK_CONST_METHOD1(hasClients, bool(EIpcClientType)); + + void delegateToFake() { + ON_CALL(*this, send(_, _)).WillByDefault(Invoke(this, &MockIpcServer::mockSend)); + } + + void waitForSend() { + ARCH->waitCondVar(m_sendCond, m_sendMutex, 5); + } + +private: + void mockSend(const IpcMessage&, EIpcClientType) { + ArchMutexLock lock(m_sendMutex); + ARCH->broadcastCondVar(m_sendCond); + } + + ArchCond m_sendCond; + ArchMutex m_sendMutex; +}; diff --git a/src/test/mock/server/MockConfig.h b/src/test/mock/server/MockConfig.h new file mode 100644 index 0000000..4161de0 --- /dev/null +++ b/src/test/mock/server/MockConfig.h @@ -0,0 +1,32 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2013-2016 Symless Ltd. + * + * 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 + +#define TEST_ENV + +#include "server/Config.h" + +#include "test/global/gmock.h" + +class MockConfig : public Config +{ +public: + MockConfig() : Config() { } + MOCK_METHOD0(getInputFilter, InputFilter*()); + MOCK_CONST_METHOD1(isScreen, bool(const String&)); +}; diff --git a/src/test/mock/server/MockInputFilter.h b/src/test/mock/server/MockInputFilter.h new file mode 100644 index 0000000..edf6de1 --- /dev/null +++ b/src/test/mock/server/MockInputFilter.h @@ -0,0 +1,30 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2013-2016 Symless Ltd. + * + * 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 + +#define TEST_ENV + +#include "server/InputFilter.h" + +#include "test/global/gmock.h" + +class MockInputFilter : public InputFilter +{ +public: + MOCK_METHOD1(setPrimaryClient, void(PrimaryClient*)); +}; diff --git a/src/test/mock/server/MockPrimaryClient.h b/src/test/mock/server/MockPrimaryClient.h new file mode 100644 index 0000000..80f18a1 --- /dev/null +++ b/src/test/mock/server/MockPrimaryClient.h @@ -0,0 +1,41 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2013-2016 Symless Ltd. + * + * 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 + +#define TEST_ENV + +#include "server/PrimaryClient.h" +#include "base/String.h" + +#include "test/global/gmock.h" + +class MockPrimaryClient : public PrimaryClient +{ +public: + MOCK_CONST_METHOD0(getEventTarget, void*()); + MOCK_CONST_METHOD2(getCursorPos, void(SInt32&, SInt32&)); + MOCK_CONST_METHOD2(setJumpCursorPos, void(SInt32, SInt32)); + MOCK_METHOD1(reconfigure, void(UInt32)); + MOCK_METHOD0(resetOptions, void()); + MOCK_METHOD1(setOptions, void(const OptionsList&)); + MOCK_METHOD0(enable, void()); + MOCK_METHOD0(disable, void()); + MOCK_METHOD2(registerHotKey, UInt32(KeyID, KeyModifierMask)); + MOCK_CONST_METHOD0(getToggleMask, KeyModifierMask()); + MOCK_METHOD1(unregisterHotKey, void(UInt32)); +}; diff --git a/src/test/mock/server/MockServer.h b/src/test/mock/server/MockServer.h new file mode 100644 index 0000000..a45ee08 --- /dev/null +++ b/src/test/mock/server/MockServer.h @@ -0,0 +1,32 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2013-2016 Symless Ltd. + * + * 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 + +#define TEST_ENV + +#include "server/Server.h" + +#include "test/global/gmock.h" + +class IEventQueue; + +class MockServer : public Server +{ +public: + MockServer() : Server() { } +}; |
