diff options
Diffstat (limited to 'src/test/integtests/platform')
| -rw-r--r-- | src/test/integtests/platform/MSWindowsClipboardTests.cpp | 229 | ||||
| -rw-r--r-- | src/test/integtests/platform/MSWindowsKeyStateTests.cpp | 144 | ||||
| -rw-r--r-- | src/test/integtests/platform/OSXClipboardTests.cpp | 164 | ||||
| -rw-r--r-- | src/test/integtests/platform/OSXKeyStateTests.cpp | 119 | ||||
| -rw-r--r-- | src/test/integtests/platform/OSXScreenTests.cpp | 51 | ||||
| -rw-r--r-- | src/test/integtests/platform/XWindowsClipboardTests.cpp | 157 | ||||
| -rw-r--r-- | src/test/integtests/platform/XWindowsKeyStateTests.cpp | 246 | ||||
| -rw-r--r-- | src/test/integtests/platform/XWindowsScreenSaverTests.cpp | 48 | ||||
| -rw-r--r-- | src/test/integtests/platform/XWindowsScreenTests.cpp | 41 |
9 files changed, 1199 insertions, 0 deletions
diff --git a/src/test/integtests/platform/MSWindowsClipboardTests.cpp b/src/test/integtests/platform/MSWindowsClipboardTests.cpp new file mode 100644 index 0000000..f9d09d1 --- /dev/null +++ b/src/test/integtests/platform/MSWindowsClipboardTests.cpp @@ -0,0 +1,229 @@ +/* + * 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/>. + */ + +#include "platform/MSWindowsClipboard.h" +#include "platform/IMSWindowsClipboardFacade.h" + +#include "test/global/gmock.h" +#include "test/global/gtest.h" + +class MSWindowsClipboardTests : public ::testing::Test +{ +protected: + virtual void SetUp() + { + emptyClipboard(); + } + + virtual void TearDown() + { + emptyClipboard(); + } + +private: + void emptyClipboard() + { + MSWindowsClipboard clipboard(NULL); + clipboard.open(0); + clipboard.empty(); + } +}; + +class MockFacade : public IMSWindowsClipboardFacade +{ +public: + MOCK_METHOD2(write, void(HANDLE, UINT)); +}; + +TEST_F(MSWindowsClipboardTests, emptyUnowned_openCalled_returnsTrue) +{ + MSWindowsClipboard clipboard(NULL); + clipboard.open(0); + + bool actual = clipboard.emptyUnowned(); + + EXPECT_EQ(true, actual); +} + +TEST_F(MSWindowsClipboardTests, empty_openCalled_returnsTrue) +{ + MSWindowsClipboard clipboard(NULL); + clipboard.open(0); + + bool actual = clipboard.empty(); + + EXPECT_EQ(true, actual); +} + +TEST_F(MSWindowsClipboardTests, empty_singleFormat_hasReturnsFalse) +{ + MSWindowsClipboard clipboard(NULL); + clipboard.open(0); + clipboard.add(MSWindowsClipboard::kText, "barrier rocks!"); + + clipboard.empty(); + + bool actual = clipboard.has(MSWindowsClipboard::kText); + EXPECT_EQ(false, actual); +} + +TEST_F(MSWindowsClipboardTests, add_newValue_valueWasStored) +{ + MSWindowsClipboard clipboard(NULL); + clipboard.open(0); + + clipboard.add(IClipboard::kText, "barrier rocks!"); + + String actual = clipboard.get(IClipboard::kText); + EXPECT_EQ("barrier rocks!", actual); +} + +TEST_F(MSWindowsClipboardTests, add_newValue_writeWasCalled) +{ + MockFacade facade; + EXPECT_CALL(facade, write(testing::_, testing::_)); + + MSWindowsClipboard clipboard(NULL); + clipboard.setFacade(facade); + clipboard.open(0); + + clipboard.add(IClipboard::kText, "barrier rocks!"); +} + +TEST_F(MSWindowsClipboardTests, add_replaceValue_valueWasReplaced) +{ + MSWindowsClipboard clipboard(NULL); + clipboard.open(0); + + clipboard.add(IClipboard::kText, "barrier rocks!"); + clipboard.add(IClipboard::kText, "maxivista sucks"); // haha, just kidding. + + String actual = clipboard.get(IClipboard::kText); + EXPECT_EQ("maxivista sucks", actual); +} + +TEST_F(MSWindowsClipboardTests, open_timeIsZero_returnsTrue) +{ + MSWindowsClipboard clipboard(NULL); + + bool actual = clipboard.open(0); + + EXPECT_EQ(true, actual); +} + +TEST_F(MSWindowsClipboardTests, open_timeIsOne_returnsTrue) +{ + MSWindowsClipboard clipboard(NULL); + + bool actual = clipboard.open(1); + + EXPECT_EQ(true, actual); +} + +TEST_F(MSWindowsClipboardTests, close_isOpen_noErrors) +{ + MSWindowsClipboard clipboard(NULL); + clipboard.open(0); + + clipboard.close(); + + // can't assert anything +} + +// looks like this test may fail intermittently: +// * http://buildbot.symless.com:8000/builders/trunk-win32/builds/246/steps/shell_3/logs/stdio +/*TEST_F(MSWindowsClipboardTests, getTime_openWithNoEmpty_returnsOne) +{ + MSWindowsClipboard clipboard(NULL); + clipboard.open(1); + + MSWindowsClipboard::Time actual = clipboard.getTime(); + + // this behavior is different to that of Clipboard which only + // returns the value passed into open(t) after empty() is called. + EXPECT_EQ(1, actual); +}*/ + +// this also fails intermittently: +// http://buildbot.symless.com:8000/builders/trunk-win32/builds/266/steps/shell_3/logs/stdio +/*TEST_F(MSWindowsClipboardTests, getTime_openAndEmpty_returnsOne) +{ + MSWindowsClipboard clipboard(NULL); + clipboard.open(1); + clipboard.empty(); + + MSWindowsClipboard::Time actual = clipboard.getTime(); + + EXPECT_EQ(1, actual); +}*/ + +TEST_F(MSWindowsClipboardTests, has_withFormatAdded_returnsTrue) +{ + MSWindowsClipboard clipboard(NULL); + clipboard.open(0); + clipboard.empty(); + clipboard.add(IClipboard::kText, "barrier rocks!"); + + bool actual = clipboard.has(IClipboard::kText); + + EXPECT_EQ(true, actual); +} + +TEST_F(MSWindowsClipboardTests, has_withNoFormats_returnsFalse) +{ + MSWindowsClipboard clipboard(NULL); + clipboard.open(0); + clipboard.empty(); + + bool actual = clipboard.has(IClipboard::kText); + + EXPECT_EQ(false, actual); +} + +TEST_F(MSWindowsClipboardTests, get_withNoFormats_returnsEmpty) +{ + MSWindowsClipboard clipboard(NULL); + clipboard.open(0); + clipboard.empty(); + + String actual = clipboard.get(IClipboard::kText); + + EXPECT_EQ("", actual); +} + +TEST_F(MSWindowsClipboardTests, get_withFormatAdded_returnsExpected) +{ + MSWindowsClipboard clipboard(NULL); + clipboard.open(0); + clipboard.empty(); + clipboard.add(IClipboard::kText, "barrier rocks!"); + + String actual = clipboard.get(IClipboard::kText); + + EXPECT_EQ("barrier rocks!", actual); +} + +TEST_F(MSWindowsClipboardTests, isOwnedByBarrier_defaultState_noError) +{ + MSWindowsClipboard clipboard(NULL); + clipboard.open(0); + + bool actual = clipboard.isOwnedByBarrier(); + + EXPECT_EQ(true, actual); +} diff --git a/src/test/integtests/platform/MSWindowsKeyStateTests.cpp b/src/test/integtests/platform/MSWindowsKeyStateTests.cpp new file mode 100644 index 0000000..f3f9e32 --- /dev/null +++ b/src/test/integtests/platform/MSWindowsKeyStateTests.cpp @@ -0,0 +1,144 @@ +/* + * 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/>. + */ + +#define TEST_ENV + +#include "test/mock/barrier/MockEventQueue.h" +#include "test/mock/barrier/MockKeyMap.h" +#include "platform/MSWindowsKeyState.h" +#include "platform/MSWindowsDesks.h" +#include "platform/MSWindowsScreen.h" +#include "platform/MSWindowsScreenSaver.h" +#include "base/TMethodJob.h" + +#include "test/global/gtest.h" +#include "test/global/gmock.h" + +// wParam = flags, HIBYTE(lParam) = virtual key, LOBYTE(lParam) = scan code +#define BARRIER_MSG_FAKE_KEY BARRIER_HOOK_LAST_MSG + 4 + +using ::testing::_; +using ::testing::NiceMock; + +class MSWindowsKeyStateTests : public ::testing::Test +{ +protected: + virtual void SetUp() + { + m_hook.loadLibrary(); + m_screensaver = new MSWindowsScreenSaver(); + } + + virtual void TearDown() + { + delete m_screensaver; + } + + MSWindowsDesks* newDesks(IEventQueue* eventQueue) + { + return new MSWindowsDesks( + true, false, m_screensaver, eventQueue, + new TMethodJob<MSWindowsKeyStateTests>( + this, &MSWindowsKeyStateTests::updateKeysCB), false); + } + + void* getEventTarget() const + { + return const_cast<MSWindowsKeyStateTests*>(this); + } + +private: + void updateKeysCB(void*) { } + IScreenSaver* m_screensaver; + MSWindowsHook m_hook; +}; + +TEST_F(MSWindowsKeyStateTests, disable_eventQueueNotUsed) +{ + NiceMock<MockEventQueue> eventQueue; + MSWindowsDesks* desks = newDesks(&eventQueue); + MockKeyMap keyMap; + MSWindowsKeyState keyState(desks, getEventTarget(), &eventQueue, keyMap); + + EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(0); + + keyState.disable(); + delete desks; +} + +TEST_F(MSWindowsKeyStateTests, testAutoRepeat_noRepeatAndButtonIsZero_resultIsTrue) +{ + NiceMock<MockEventQueue> eventQueue; + MSWindowsDesks* desks = newDesks(&eventQueue); + MockKeyMap keyMap; + MSWindowsKeyState keyState(desks, getEventTarget(), &eventQueue, keyMap); + keyState.setLastDown(1); + + bool actual = keyState.testAutoRepeat(true, false, 1); + + ASSERT_TRUE(actual); + delete desks; +} + +TEST_F(MSWindowsKeyStateTests, testAutoRepeat_pressFalse_lastDownIsZero) +{ + NiceMock<MockEventQueue> eventQueue; + MSWindowsDesks* desks = newDesks(&eventQueue); + MockKeyMap keyMap; + MSWindowsKeyState keyState(desks, getEventTarget(), &eventQueue, keyMap); + keyState.setLastDown(1); + + keyState.testAutoRepeat(false, false, 1); + + ASSERT_EQ(0, keyState.getLastDown()); + delete desks; +} + +TEST_F(MSWindowsKeyStateTests, saveModifiers_noModifiers_savedModifiers0) +{ + NiceMock<MockEventQueue> eventQueue; + MSWindowsDesks* desks = newDesks(&eventQueue); + MockKeyMap keyMap; + MSWindowsKeyState keyState(desks, getEventTarget(), &eventQueue, keyMap); + + keyState.saveModifiers(); + + ASSERT_EQ(0, keyState.getSavedModifiers()); + delete desks; +} + +TEST_F(MSWindowsKeyStateTests, testKoreanLocale_inputModeKey_resultCorrectKeyID) +{ + NiceMock<MockEventQueue> eventQueue; + MSWindowsDesks* desks = newDesks(&eventQueue); + MockKeyMap keyMap; + MSWindowsKeyState keyState(desks, getEventTarget(), &eventQueue, keyMap); + + keyState.setKeyLayout((HKL)0x00000412u); // for ko-KR local ID + ASSERT_EQ(0xEF31, keyState.getKeyID(0x15u, 0x1f2u)); // VK_HANGUL from Hangul key + ASSERT_EQ(0xEF34, keyState.getKeyID(0x19u, 0x1f1u)); // VK_HANJA from Hanja key + ASSERT_EQ(0xEF31, keyState.getKeyID(0x15u, 0x11du)); // VK_HANGUL from R-Alt key + ASSERT_EQ(0xEF34, keyState.getKeyID(0x19u, 0x138u)); // VK_HANJA from R-Ctrl key + + keyState.setKeyLayout((HKL)0x00000411); // for ja-jp locale ID + ASSERT_EQ(0xEF26, keyState.getKeyID(0x15u, 0x1du)); // VK_KANA + ASSERT_EQ(0xEF2A, keyState.getKeyID(0x19u, 0x38u)); // VK_KANJI + + delete desks; +} + diff --git a/src/test/integtests/platform/OSXClipboardTests.cpp b/src/test/integtests/platform/OSXClipboardTests.cpp new file mode 100644 index 0000000..45b73bd --- /dev/null +++ b/src/test/integtests/platform/OSXClipboardTests.cpp @@ -0,0 +1,164 @@ +/* + * 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/>. + */ + +#include "platform/OSXClipboard.h" + +#include "test/global/gtest.h" +#include <iostream> + +TEST(OSXClipboardTests, empty_openCalled_returnsTrue) +{ + OSXClipboard clipboard; + clipboard.open(0); + + bool actual = clipboard.empty(); + + EXPECT_EQ(true, actual); +} + +TEST(OSXClipboardTests, empty_singleFormat_hasReturnsFalse) +{ + OSXClipboard clipboard; + clipboard.open(0); + clipboard.add(OSXClipboard::kText, "barrier rocks!"); + + clipboard.empty(); + + bool actual = clipboard.has(OSXClipboard::kText); + EXPECT_EQ(false, actual); +} + +TEST(OSXClipboardTests, add_newValue_valueWasStored) +{ + OSXClipboard clipboard; + clipboard.open(0); + + clipboard.add(IClipboard::kText, "barrier rocks!"); + + String actual = clipboard.get(IClipboard::kText); + EXPECT_EQ("barrier rocks!", actual); +} + +TEST(OSXClipboardTests, add_replaceValue_valueWasReplaced) +{ + OSXClipboard clipboard; + clipboard.open(0); + + clipboard.add(IClipboard::kText, "barrier rocks!"); + clipboard.add(IClipboard::kText, "maxivista sucks"); // haha, just kidding. + + String actual = clipboard.get(IClipboard::kText); + EXPECT_EQ("maxivista sucks", actual); +} + +TEST(OSXClipboardTests, open_timeIsZero_returnsTrue) +{ + OSXClipboard clipboard; + + bool actual = clipboard.open(0); + + EXPECT_EQ(true, actual); +} + +TEST(OSXClipboardTests, open_timeIsOne_returnsTrue) +{ + OSXClipboard clipboard; + + bool actual = clipboard.open(1); + + EXPECT_EQ(true, actual); +} + +TEST(OSXClipboardTests, close_isOpen_noErrors) +{ + OSXClipboard clipboard; + clipboard.open(0); + + clipboard.close(); + + // can't assert anything +} + +TEST(OSXClipboardTests, getTime_openWithNoEmpty_returnsOne) +{ + OSXClipboard clipboard; + clipboard.open(1); + + OSXClipboard::Time actual = clipboard.getTime(); + + // this behavior is different to that of Clipboard which only + // returns the value passed into open(t) after empty() is called. + EXPECT_EQ((UInt32)1, actual); +} + +TEST(OSXClipboardTests, getTime_openAndEmpty_returnsOne) +{ + OSXClipboard clipboard; + clipboard.open(1); + clipboard.empty(); + + OSXClipboard::Time actual = clipboard.getTime(); + + EXPECT_EQ((UInt32)1, actual); +} + +TEST(OSXClipboardTests, has_withFormatAdded_returnsTrue) +{ + OSXClipboard clipboard; + clipboard.open(0); + clipboard.empty(); + clipboard.add(IClipboard::kText, "barrier rocks!"); + + bool actual = clipboard.has(IClipboard::kText); + + EXPECT_EQ(true, actual); +} + +TEST(OSXClipboardTests, has_withNoFormats_returnsFalse) +{ + OSXClipboard clipboard; + clipboard.open(0); + clipboard.empty(); + + bool actual = clipboard.has(IClipboard::kText); + + EXPECT_EQ(false, actual); +} + +TEST(OSXClipboardTests, get_withNoFormats_returnsEmpty) +{ + OSXClipboard clipboard; + clipboard.open(0); + clipboard.empty(); + + String actual = clipboard.get(IClipboard::kText); + + EXPECT_EQ("", actual); +} + +TEST(OSXClipboardTests, get_withFormatAdded_returnsExpected) +{ + OSXClipboard clipboard; + clipboard.open(0); + clipboard.empty(); + clipboard.add(IClipboard::kText, "barrier rocks!"); + + String actual = clipboard.get(IClipboard::kText); + + EXPECT_EQ("barrier rocks!", actual); +} diff --git a/src/test/integtests/platform/OSXKeyStateTests.cpp b/src/test/integtests/platform/OSXKeyStateTests.cpp new file mode 100644 index 0000000..4957aaa --- /dev/null +++ b/src/test/integtests/platform/OSXKeyStateTests.cpp @@ -0,0 +1,119 @@ +/* + * 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/>. + */ + +#include "test/mock/barrier/MockKeyMap.h" +#include "test/mock/barrier/MockEventQueue.h" +#include "platform/OSXKeyState.h" +#include "base/Log.h" + +#include "test/global/gtest.h" +#include "test/global/gmock.h" + +#define SHIFT_ID_L kKeyShift_L +#define SHIFT_ID_R kKeyShift_R +#define SHIFT_BUTTON 57 +#define A_CHAR_ID 0x00000061 +#define A_CHAR_BUTTON 001 + +class OSXKeyStateTests : public ::testing::Test { +public: + static bool isKeyPressed(const OSXKeyState& keyState, KeyButton button); +}; + +// fakeAndPoll_shift seems to always fail on osx10.6 +#if __MAC_OS_X_VERSION_MIN_REQUIRED > 1060 + +TEST_F(OSXKeyStateTests, fakeAndPoll_shift) +{ + barrier::KeyMap keyMap; + MockEventQueue eventQueue; + OSXKeyState keyState(&eventQueue, keyMap); + keyState.updateKeyMap(); + + keyState.fakeKeyDown(SHIFT_ID_L, 0, 1); + EXPECT_TRUE(isKeyPressed(keyState, SHIFT_BUTTON)); + + keyState.fakeKeyUp(1); + EXPECT_TRUE(!isKeyPressed(keyState, SHIFT_BUTTON)); + + keyState.fakeKeyDown(SHIFT_ID_R, 0, 2); + EXPECT_TRUE(isKeyPressed(keyState, SHIFT_BUTTON)); + + keyState.fakeKeyUp(2); + EXPECT_TRUE(!isKeyPressed(keyState, SHIFT_BUTTON)); +} + +TEST_F(OSXKeyStateTests, fakeAndPoll_charKey) +{ + barrier::KeyMap keyMap; + MockEventQueue eventQueue; + OSXKeyState keyState(&eventQueue, keyMap); + keyState.updateKeyMap(); + + keyState.fakeKeyDown(A_CHAR_ID, 0, 1); + EXPECT_TRUE(isKeyPressed(keyState, A_CHAR_BUTTON)); + + keyState.fakeKeyUp(1); + EXPECT_TRUE(!isKeyPressed(keyState, A_CHAR_BUTTON)); + + // HACK: delete the key in case it was typed into a text editor. + // we should really set focus to an invisible window. + keyState.fakeKeyDown(kKeyBackSpace, 0, 2); + keyState.fakeKeyUp(2); +} + +TEST_F(OSXKeyStateTests, fakeAndPoll_charKeyAndModifier) +{ + barrier::KeyMap keyMap; + MockEventQueue eventQueue; + OSXKeyState keyState(&eventQueue, keyMap); + keyState.updateKeyMap(); + + keyState.fakeKeyDown(A_CHAR_ID, KeyModifierShift, 1); + EXPECT_TRUE(isKeyPressed(keyState, A_CHAR_BUTTON)); + + keyState.fakeKeyUp(1); + EXPECT_TRUE(!isKeyPressed(keyState, A_CHAR_BUTTON)); + + // HACK: delete the key in case it was typed into a text editor. + // we should really set focus to an invisible window. + keyState.fakeKeyDown(kKeyBackSpace, 0, 2); + keyState.fakeKeyUp(2); +} + +bool +OSXKeyStateTests::isKeyPressed(const OSXKeyState& keyState, KeyButton button) +{ + // HACK: allow os to realize key state changes. + ARCH->sleep(.2); + + IKeyState::KeyButtonSet pressed; + keyState.pollPressedKeys(pressed); + + IKeyState::KeyButtonSet::const_iterator it; + for (it = pressed.begin(); it != pressed.end(); ++it) { + LOG((CLOG_DEBUG "checking key %d", *it)); + if (*it == button) { + return true; + } + } + return false; +} + +#endif + diff --git a/src/test/integtests/platform/OSXScreenTests.cpp b/src/test/integtests/platform/OSXScreenTests.cpp new file mode 100644 index 0000000..96beb4d --- /dev/null +++ b/src/test/integtests/platform/OSXScreenTests.cpp @@ -0,0 +1,51 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2012-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/>. + */ + +#include "platform/OSXScreen.h" +#include "arch/Arch.h" +#include "base/EventQueue.h" + +#include "test/global/gtest.h" + +// disabling these tests - the return value of CGCursorIsVisible is unreliable. +/* +TEST(OSXScreenTests, hideCursor_notPrimary) +{ + EventQueue queue; + OSXScreen screen(true, false); + + screen.hideCursor(); + + EXPECT_EQ(false, CGCursorIsVisible()); + + // workaround for screen class race condition. + ARCH->sleep(.1f); +} + +TEST(OSXScreenTests, showCursor_notPrimary) +{ + EventQueue queue; + OSXScreen screen(false, false); + + screen.showCursor(); + + EXPECT_EQ(true, CGCursorIsVisible()); + + // workaround for screen class race condition. + ARCH->sleep(.1f); +} +*/ diff --git a/src/test/integtests/platform/XWindowsClipboardTests.cpp b/src/test/integtests/platform/XWindowsClipboardTests.cpp new file mode 100644 index 0000000..652ee5e --- /dev/null +++ b/src/test/integtests/platform/XWindowsClipboardTests.cpp @@ -0,0 +1,157 @@ +/* + * 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/>. + */ + +// TODO: fix tests - compile error on linux +#if 0 + +#include "platform/XWindowsClipboard.h" + +#include "test/global/gtest.h" +#include <iostream> + +class CXWindowsClipboardTests : public ::testing::Test +{ +protected: + virtual void + SetUp() + { + m_display = XOpenDisplay(NULL); + int screen = DefaultScreen(m_display); + Window root = XRootWindow(m_display, screen); + + XSetWindowAttributes attr; + attr.do_not_propagate_mask = 0; + attr.override_redirect = True; + attr.cursor = Cursor(); + + m_window = XCreateWindow( + m_display, root, 0, 0, 1, 1, 0, 0, + InputOnly, CopyFromParent, 0, &attr); + } + + virtual void + TearDown() + { + XDestroyWindow(m_display, m_window); + XCloseDisplay(m_display); + } + + CXWindowsClipboard& + createClipboard() + { + CXWindowsClipboard* clipboard; + clipboard = new CXWindowsClipboard(m_display, m_window, 0); + clipboard->open(0); // needed to empty the clipboard + clipboard->empty(); // needed to own the clipboard + return *clipboard; + } + + Display* m_display; + Window m_window; +}; + +TEST_F(CXWindowsClipboardTests, empty_openCalled_returnsTrue) +{ + CXWindowsClipboard clipboard = createClipboard(); + + bool actual = clipboard.empty(); + + EXPECT_EQ(true, actual); +} + +TEST_F(CXWindowsClipboardTests, empty_singleFormat_hasReturnsFalse) +{ + CXWindowsClipboard clipboard = createClipboard(); + clipboard.add(CXWindowsClipboard::kText, "barrier rocks!"); + + clipboard.empty(); + + bool actual = clipboard.has(CXWindowsClipboard::kText); + EXPECT_FALSE(actual); +} + +TEST_F(CXWindowsClipboardTests, add_newValue_valueWasStored) +{ + CXWindowsClipboard clipboard = createClipboard(); + + clipboard.add(IClipboard::kText, "barrier rocks!"); + + String actual = clipboard.get(IClipboard::kText); + EXPECT_EQ("barrier rocks!", actual); +} + +TEST_F(CXWindowsClipboardTests, add_replaceValue_valueWasReplaced) +{ + CXWindowsClipboard clipboard = createClipboard(); + + clipboard.add(IClipboard::kText, "barrier rocks!"); + clipboard.add(IClipboard::kText, "maxivista sucks"); // haha, just kidding. + + String actual = clipboard.get(IClipboard::kText); + EXPECT_EQ("maxivista sucks", actual); +} + +TEST_F(CXWindowsClipboardTests, close_isOpen_noErrors) +{ + CXWindowsClipboard clipboard = createClipboard(); + + // clipboard opened in createClipboard() + clipboard.close(); + + // can't assert anything +} + +TEST_F(CXWindowsClipboardTests, has_withFormatAdded_returnsTrue) +{ + CXWindowsClipboard clipboard = createClipboard(); + clipboard.add(IClipboard::kText, "barrier rocks!"); + + bool actual = clipboard.has(IClipboard::kText); + + EXPECT_EQ(true, actual); +} + +TEST_F(CXWindowsClipboardTests, has_withNoFormats_returnsFalse) +{ + CXWindowsClipboard clipboard = createClipboard(); + + bool actual = clipboard.has(IClipboard::kText); + + EXPECT_FALSE(actual); +} + +TEST_F(CXWindowsClipboardTests, get_withNoFormats_returnsEmpty) +{ + CXWindowsClipboard clipboard = createClipboard(); + + String actual = clipboard.get(IClipboard::kText); + + EXPECT_EQ("", actual); +} + +TEST_F(CXWindowsClipboardTests, get_withFormatAdded_returnsExpected) +{ + CXWindowsClipboard clipboard = createClipboard(); + clipboard.add(IClipboard::kText, "barrier rocks!"); + + String actual = clipboard.get(IClipboard::kText); + + EXPECT_EQ("barrier rocks!", actual); +} + +#endif diff --git a/src/test/integtests/platform/XWindowsKeyStateTests.cpp b/src/test/integtests/platform/XWindowsKeyStateTests.cpp new file mode 100644 index 0000000..ea8ce44 --- /dev/null +++ b/src/test/integtests/platform/XWindowsKeyStateTests.cpp @@ -0,0 +1,246 @@ +/* + * 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/>. + */ + +#define TEST_ENV + +#include "test/mock/barrier/MockKeyMap.h" +#include "test/mock/barrier/MockEventQueue.h" +#include "platform/XWindowsKeyState.h" +#include "base/Log.h" + +#define XK_LATIN1 +#define XK_MISCELLANY +#include <X11/keysymdef.h> + +#if HAVE_XKB_EXTENSION +# include <X11/XKBlib.h> +#endif + +#include "test/global/gtest.h" +#include "test/global/gmock.h" +#include <errno.h> + +class XWindowsKeyStateTests : public ::testing::Test +{ +protected: + XWindowsKeyStateTests() : + m_display(NULL) + { + } + + ~XWindowsKeyStateTests() + { + if (m_display != NULL) { + LOG((CLOG_DEBUG "closing display")); + XCloseDisplay(m_display); + } + } + + virtual void + SetUp() + { + // open the display only once for the entire test suite + if (this->m_display == NULL) { + LOG((CLOG_DEBUG "opening display")); + this->m_display = XOpenDisplay(NULL); + + ASSERT_TRUE(this->m_display != NULL) + << "unable to open display: " << errno; + } + } + + virtual void + TearDown() + { + } + + Display* m_display; +}; + +TEST_F(XWindowsKeyStateTests, setActiveGroup_pollAndSet_groupIsZero) +{ + MockKeyMap keyMap; + MockEventQueue eventQueue; + XWindowsKeyState keyState( + m_display, true, &eventQueue, keyMap); + + keyState.setActiveGroup(XWindowsKeyState::kGroupPollAndSet); + + ASSERT_EQ(0, keyState.group()); +} + +TEST_F(XWindowsKeyStateTests, setActiveGroup_poll_groupIsNotSet) +{ + MockKeyMap keyMap; + MockEventQueue eventQueue; + XWindowsKeyState keyState( + m_display, true, &eventQueue, keyMap); + + keyState.setActiveGroup(XWindowsKeyState::kGroupPoll); + + ASSERT_LE(-1, keyState.group()); +} + +TEST_F(XWindowsKeyStateTests, setActiveGroup_customGroup_groupWasSet) +{ + MockKeyMap keyMap; + MockEventQueue eventQueue; + XWindowsKeyState keyState( + m_display, true, &eventQueue, keyMap); + + keyState.setActiveGroup(1); + + ASSERT_EQ(1, keyState.group()); +} + +TEST_F(XWindowsKeyStateTests, mapModifiersFromX_zeroState_zeroMask) +{ + MockKeyMap keyMap; + MockEventQueue eventQueue; + XWindowsKeyState keyState( + m_display, true, &eventQueue, keyMap); + + int mask = keyState.mapModifiersFromX(0); + + ASSERT_EQ(0, mask); +} + +TEST_F(XWindowsKeyStateTests, mapModifiersToX_zeroMask_resultIsTrue) +{ + MockKeyMap keyMap; + MockEventQueue eventQueue; + XWindowsKeyState keyState( + m_display, true, &eventQueue, keyMap); + + unsigned int modifiers = 0; + bool result = keyState.mapModifiersToX(0, modifiers); + + ASSERT_TRUE(result); +} + +TEST_F(XWindowsKeyStateTests, fakeCtrlAltDel_default_returnsFalse) +{ + MockKeyMap keyMap; + MockEventQueue eventQueue; + XWindowsKeyState keyState( + m_display, true, &eventQueue, keyMap); + + bool result = keyState.fakeCtrlAltDel(); + + ASSERT_FALSE(result); +} + +TEST_F(XWindowsKeyStateTests, pollActiveModifiers_defaultState_returnsZero) +{ + MockKeyMap keyMap; + MockEventQueue eventQueue; + XWindowsKeyState keyState( + m_display, true, &eventQueue, keyMap); + + KeyModifierMask actual = keyState.pollActiveModifiers(); + + ASSERT_EQ(0, actual); +} + +#if 0 // TODO: fix, causes sigsegv +TEST_F(XWindowsKeyStateTests, pollActiveModifiers_shiftKeyDownThenUp_masksAreCorrect) +{ + MockKeyMap keyMap; + MockEventQueue eventQueue; + XWindowsKeyState keyState( + m_display, true, &eventQueue, keyMap); + + // set mock modifier mapping + std::fill(keyState.modifierFromX().begin(), keyState.modifierFromX().end(), 0); + keyState.modifierFromX()[ShiftMapIndex] = KeyModifierShift; + + KeyCode key = XKeysymToKeycode(m_display, XK_Shift_L); + + // fake shift key down (without using barrier) + XTestFakeKeyEvent(m_display, key, true, CurrentTime); + + // function under test (1st call) + KeyModifierMask modDown = keyState.pollActiveModifiers(); + + // fake shift key up (without using barrier) + XTestFakeKeyEvent(m_display, key, false, CurrentTime); + + // function under test (2nd call) + KeyModifierMask modUp = keyState.pollActiveModifiers(); + + EXPECT_TRUE((modDown & KeyModifierShift) == KeyModifierShift) + << "shift key not in mask - key was not pressed"; + + EXPECT_TRUE((modUp & KeyModifierShift) == 0) + << "shift key still in mask - make sure no keys are being held down"; +} +#endif + +TEST_F(XWindowsKeyStateTests, pollActiveGroup_defaultState_returnsZero) +{ + MockKeyMap keyMap; + MockEventQueue eventQueue; + XWindowsKeyState keyState( + m_display, true, &eventQueue, keyMap); + + SInt32 actual = keyState.pollActiveGroup(); + + ASSERT_EQ(0, actual); +} + +TEST_F(XWindowsKeyStateTests, pollActiveGroup_positiveGroup_returnsGroup) +{ + MockKeyMap keyMap; + MockEventQueue eventQueue; + XWindowsKeyState keyState( + m_display, true, &eventQueue, keyMap); + + keyState.group(3); + + SInt32 actual = keyState.pollActiveGroup(); + + ASSERT_EQ(3, actual); +} + +TEST_F(XWindowsKeyStateTests, pollActiveGroup_xkb_areEqual) +{ +#if HAVE_XKB_EXTENSION + MockKeyMap keyMap; + MockEventQueue eventQueue; + XWindowsKeyState keyState( + m_display, true, &eventQueue, keyMap); + + // reset the group + keyState.group(-1); + + XkbStateRec state; + + // compare pollActiveGroup() with XkbGetState() + if (XkbGetState(m_display, XkbUseCoreKbd, &state) == Success) { + SInt32 actual = keyState.pollActiveGroup(); + + ASSERT_EQ(state.group, actual); + } + else { + FAIL() << "XkbGetState() returned error " << errno; + } +#else + SUCCEED() << "Xkb extension not installed"; +#endif +} + diff --git a/src/test/integtests/platform/XWindowsScreenSaverTests.cpp b/src/test/integtests/platform/XWindowsScreenSaverTests.cpp new file mode 100644 index 0000000..c6a2710 --- /dev/null +++ b/src/test/integtests/platform/XWindowsScreenSaverTests.cpp @@ -0,0 +1,48 @@ +/* + * 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/>. + */ + +// TODO: fix tests +#if 0 + +#include "test/mock/barrier/MockEventQueue.h" +#include "platform/XWindowsScreenSaver.h" + +#include "test/global/gtest.h" +#include <X11/Xlib.h> + +using ::testing::_; + +// TODO: not working on build machine for some reason +TEST(CXWindowsScreenSaverTests, activate_defaultScreen_todo) +{ + Display* display = XOpenDisplay(":0.0"); + Window window = DefaultRootWindow(display); + MockEventQueue eventQueue; + EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(1); + CXWindowsScreenSaver screenSaver( + display, window, NULL, &eventQueue); + + screenSaver.activate(); + + bool isActive = screenSaver.isActive(); + + screenSaver.deactivate(); + + ASSERT_EQ(true, isActive); +} +#endif diff --git a/src/test/integtests/platform/XWindowsScreenTests.cpp b/src/test/integtests/platform/XWindowsScreenTests.cpp new file mode 100644 index 0000000..b74599c --- /dev/null +++ b/src/test/integtests/platform/XWindowsScreenTests.cpp @@ -0,0 +1,41 @@ +/* + * 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/>. + */ + +#include "test/mock/barrier/MockEventQueue.h" +#include "platform/XWindowsScreen.h" + +#include "test/global/gtest.h" + +using ::testing::_; + +TEST(CXWindowsScreenTests, fakeMouseMove_nonPrimary_getCursorPosValuesCorrect) +{ + MockEventQueue eventQueue; + EXPECT_CALL(eventQueue, adoptHandler(_, _, _)).Times(2); + EXPECT_CALL(eventQueue, adoptBuffer(_)).Times(2); + EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(2); + XWindowsScreen screen( + ":0.0", false, false, 0, &eventQueue); + + screen.fakeMouseMove(10, 20); + + int x, y; + screen.getCursorPos(x, y); + ASSERT_EQ(10, x); + ASSERT_EQ(20, y); +} |
