moving 1.4 to trunk

This commit is contained in:
Nick Bolton
2012-06-10 16:50:54 +00:00
parent cdeb3a7824
commit 488241850c
1291 changed files with 425650 additions and 12 deletions

View File

@@ -0,0 +1,79 @@
# synergy -- mouse and keyboard sharing utility
# Copyright (C) 2009 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
#
# 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 COPYING 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/>.
set(src
Main.cpp
)
if (WIN32)
# windows
list(APPEND src
platform/CMSWindowsClipboardTests.cpp
platform/CMSWindowsKeyStateTests.cpp
)
elseif (APPLE)
# mac
list(APPEND src
platform/COSXClipboardTests.cpp
platform/COSXKeyStateTests.cpp
)
elseif (UNIX)
# unix/linux
list(APPEND src
platform/CXWindowsClipboardTests.cpp
platform/CXWindowsKeyStateTests.cpp
platform/CXWindowsScreenTests.cpp
platform/CXWindowsScreenSaverTests.cpp
)
endif()
set(inc
../../lib/arch
../../lib/base
../../lib/client
../../lib/common
../../lib/io
../../lib/mt
../../lib/net
../../lib/platform
../../lib/synergy
../../../tools/gtest-1.6.0/include
../../../tools/gmock-1.6.0/include
../unittests
../unittests/synergy
)
if (UNIX)
list(APPEND inc
../../..
)
endif()
if (WIN32)
if (GAME_DEVICE_SUPPORT)
link_directories("$ENV{DXSDK_DIR}/Lib/x86")
endif()
endif()
include_directories(${inc})
add_executable(integtests ${src})
target_link_libraries(integtests
arch base client common io mt net platform server synergy gtest gmock ${libs})

View File

@@ -0,0 +1,96 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2011 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
*
* 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 COPYING 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 <iostream>
#include <fstream>
#include <gtest/gtest.h>
#include "CArch.h"
#include "CLog.h"
#if SYSAPI_WIN32
#include "CArchMiscWindows.h"
#endif
#define LOCK_TIMEOUT 30
using namespace std;
void lock(string lockFile);
void unlock(string lockFile);
int
main(int argc, char **argv)
{
#if SYSAPI_WIN32
// record window instance for tray icon, etc
CArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
#endif
string lockFile;
for (int i = 0; i < argc; i++) {
if (string(argv[i]).compare("--lock-file") == 0) {
lockFile = argv[i + 1];
}
}
if (!lockFile.empty()) {
lock(lockFile);
}
CLOG->setFilter(kDEBUG2);
testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS();
if (!lockFile.empty()) {
unlock(lockFile);
}
return result;
}
void
lock(string lockFile)
{
double start = ARCH->time();
// keep checking until timeout is reached.
while ((ARCH->time() - start) < LOCK_TIMEOUT) {
ifstream is(lockFile.c_str());
bool noLock = !is;
is.close();
if (noLock) {
break;
}
// check every second if file has gone.
ARCH->sleep(1);
}
// write empty lock file.
ofstream os(lockFile.c_str());
os.close();
}
void
unlock(string lockFile)
{
remove(lockFile.c_str());
}

View File

@@ -0,0 +1,227 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2011 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
*
* 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 COPYING 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 <gtest/gtest.h>
#include <gmock/gmock.h>
#include "CMSWindowsClipboard.h"
#include "IMSWindowsClipboardFacade.h"
class CMSWindowsClipboardTests : public ::testing::Test
{
protected:
virtual void SetUp()
{
emptyClipboard();
}
virtual void TearDown()
{
emptyClipboard();
}
private:
void emptyClipboard()
{
CMSWindowsClipboard clipboard(NULL);
clipboard.open(0);
clipboard.empty();
}
};
class MockFacade : public IMSWindowsClipboardFacade
{
public:
MOCK_METHOD2(write, void(HANDLE, UINT));
};
TEST_F(CMSWindowsClipboardTests, emptyUnowned_openCalled_returnsTrue)
{
CMSWindowsClipboard clipboard(NULL);
clipboard.open(0);
bool actual = clipboard.emptyUnowned();
EXPECT_EQ(true, actual);
}
TEST_F(CMSWindowsClipboardTests, empty_openCalled_returnsTrue)
{
CMSWindowsClipboard clipboard(NULL);
clipboard.open(0);
bool actual = clipboard.empty();
EXPECT_EQ(true, actual);
}
TEST_F(CMSWindowsClipboardTests, empty_singleFormat_hasReturnsFalse)
{
CMSWindowsClipboard clipboard(NULL);
clipboard.open(0);
clipboard.add(CMSWindowsClipboard::kText, "synergy rocks!");
clipboard.empty();
bool actual = clipboard.has(CMSWindowsClipboard::kText);
EXPECT_EQ(false, actual);
}
TEST_F(CMSWindowsClipboardTests, add_newValue_valueWasStored)
{
CMSWindowsClipboard clipboard(NULL);
clipboard.open(0);
clipboard.add(IClipboard::kText, "synergy rocks!");
CString actual = clipboard.get(IClipboard::kText);
EXPECT_EQ("synergy rocks!", actual);
}
TEST_F(CMSWindowsClipboardTests, add_newValue_writeWasCalled)
{
MockFacade facade;
EXPECT_CALL(facade, write(testing::_, testing::_));
CMSWindowsClipboard clipboard(NULL);
clipboard.setFacade(facade);
clipboard.open(0);
clipboard.add(IClipboard::kText, "synergy rocks!");
}
TEST_F(CMSWindowsClipboardTests, add_replaceValue_valueWasReplaced)
{
CMSWindowsClipboard clipboard(NULL);
clipboard.open(0);
clipboard.add(IClipboard::kText, "synergy rocks!");
clipboard.add(IClipboard::kText, "maxivista sucks"); // haha, just kidding.
CString actual = clipboard.get(IClipboard::kText);
EXPECT_EQ("maxivista sucks", actual);
}
TEST_F(CMSWindowsClipboardTests, open_timeIsZero_returnsTrue)
{
CMSWindowsClipboard clipboard(NULL);
bool actual = clipboard.open(0);
EXPECT_EQ(true, actual);
}
TEST_F(CMSWindowsClipboardTests, open_timeIsOne_returnsTrue)
{
CMSWindowsClipboard clipboard(NULL);
bool actual = clipboard.open(1);
EXPECT_EQ(true, actual);
}
TEST_F(CMSWindowsClipboardTests, close_isOpen_noErrors)
{
CMSWindowsClipboard clipboard(NULL);
clipboard.open(0);
clipboard.close();
// can't assert anything
}
// looks like this test may fail intermittently:
// * http://buildbot.synergy-foss.org:8000/builders/trunk-win32/builds/246/steps/shell_3/logs/stdio
/*TEST_F(CMSWindowsClipboardTests, getTime_openWithNoEmpty_returnsOne)
{
CMSWindowsClipboard clipboard(NULL);
clipboard.open(1);
CMSWindowsClipboard::Time actual = clipboard.getTime();
// this behavior is different to that of CClipboard which only
// returns the value passed into open(t) after empty() is called.
EXPECT_EQ(1, actual);
}*/
// this also fails intermittently:
// http://buildbot.synergy-foss.org:8000/builders/trunk-win32/builds/266/steps/shell_3/logs/stdio
/*TEST_F(CMSWindowsClipboardTests, getTime_openAndEmpty_returnsOne)
{
CMSWindowsClipboard clipboard(NULL);
clipboard.open(1);
clipboard.empty();
CMSWindowsClipboard::Time actual = clipboard.getTime();
EXPECT_EQ(1, actual);
}*/
TEST_F(CMSWindowsClipboardTests, has_withFormatAdded_returnsTrue)
{
CMSWindowsClipboard clipboard(NULL);
clipboard.open(0);
clipboard.empty();
clipboard.add(IClipboard::kText, "synergy rocks!");
bool actual = clipboard.has(IClipboard::kText);
EXPECT_EQ(true, actual);
}
TEST_F(CMSWindowsClipboardTests, has_withNoFormats_returnsFalse)
{
CMSWindowsClipboard clipboard(NULL);
clipboard.open(0);
clipboard.empty();
bool actual = clipboard.has(IClipboard::kText);
EXPECT_EQ(false, actual);
}
TEST_F(CMSWindowsClipboardTests, get_withNoFormats_returnsEmpty)
{
CMSWindowsClipboard clipboard(NULL);
clipboard.open(0);
clipboard.empty();
CString actual = clipboard.get(IClipboard::kText);
EXPECT_EQ("", actual);
}
TEST_F(CMSWindowsClipboardTests, get_withFormatAdded_returnsExpected)
{
CMSWindowsClipboard clipboard(NULL);
clipboard.open(0);
clipboard.empty();
clipboard.add(IClipboard::kText, "synergy rocks!");
CString actual = clipboard.get(IClipboard::kText);
EXPECT_EQ("synergy rocks!", actual);
}
TEST_F(CMSWindowsClipboardTests, isOwnedBySynergy_defaultState_noError)
{
CMSWindowsClipboard clipboard(NULL);
clipboard.open(0);
bool actual = clipboard.isOwnedBySynergy();
EXPECT_EQ(true, actual);
}

View File

@@ -0,0 +1,134 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2011 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
*
* 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 COPYING 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 <gtest/gtest.h>
#include <gmock/gmock.h>
#include "CMSWindowsKeyState.h"
#include "CMSWindowsDesks.h"
#include "CMSWindowsScreen.h"
#include "CMSWindowsScreenSaver.h"
#include "TMethodJob.h"
#include "CMockEventQueue.h"
#include "CMockKeyMap.h"
// wParam = flags, HIBYTE(lParam) = virtual key, LOBYTE(lParam) = scan code
#define SYNERGY_MSG_FAKE_KEY SYNERGY_HOOK_LAST_MSG + 4
using ::testing::_;
using ::testing::NiceMock;
class CMSWindowsKeyStateTests : public ::testing::Test
{
protected:
virtual void SetUp()
{
// load synrgyhk.dll
m_hookLibrary = m_hookLibraryLoader.openHookLibrary("synrgyhk");
m_screensaver = new CMSWindowsScreenSaver();
m_desks = new CMSWindowsDesks(
true, false, m_hookLibrary, m_screensaver,
new TMethodJob<CMSWindowsKeyStateTests>(
this, &CMSWindowsKeyStateTests::updateKeysCB));
}
virtual void TearDown()
{
delete m_screensaver;
delete m_desks;
}
CMSWindowsDesks* getDesks() const
{
return m_desks;
}
void* getEventTarget() const
{
return const_cast<CMSWindowsKeyStateTests*>(this);
}
private:
void updateKeysCB(void*) { }
HINSTANCE m_hookLibrary;
IScreenSaver* m_screensaver;
CMSWindowsDesks* m_desks;
CMSWindowsHookLibraryLoader m_hookLibraryLoader;
};
TEST_F(CMSWindowsKeyStateTests, disable_nonWin95OS_eventQueueNotUsed)
{
NiceMock<CMockEventQueue> eventQueue;
CMockKeyMap keyMap;
CMSWindowsKeyState keyState(getDesks(), getEventTarget(), eventQueue, keyMap);
// in anything above win95-family, event handler should not be called.
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(0);
keyState.disable();
}
TEST_F(CMSWindowsKeyStateTests, testAutoRepeat_noRepeatAndButtonIsZero_resultIsTrue)
{
NiceMock<CMockEventQueue> eventQueue;
CMockKeyMap keyMap;
CMSWindowsKeyState keyState(getDesks(), getEventTarget(), eventQueue, keyMap);
keyState.setLastDown(1);
bool actual = keyState.testAutoRepeat(true, false, 1);
ASSERT_TRUE(actual);
}
TEST_F(CMSWindowsKeyStateTests, testAutoRepeat_pressFalse_lastDownIsZero)
{
NiceMock<CMockEventQueue> eventQueue;
CMockKeyMap keyMap;
CMSWindowsKeyState keyState(getDesks(), getEventTarget(), eventQueue, keyMap);
keyState.setLastDown(1);
keyState.testAutoRepeat(false, false, 1);
ASSERT_EQ(0, keyState.getLastDown());
}
TEST_F(CMSWindowsKeyStateTests, saveModifiers_noModifiers_savedModifiers0)
{
NiceMock<CMockEventQueue> eventQueue;
CMockKeyMap keyMap;
CMSWindowsKeyState keyState(getDesks(), getEventTarget(), eventQueue, keyMap);
keyState.saveModifiers();
ASSERT_EQ(0, keyState.getSavedModifiers());
}
/*
// TODO: fix Assertion failed: s_instance != NULL,
// file ..\..\..\..\src\lib\base\IEventQueue.cpp, line 37
TEST_F(CMSWindowsKeyStateTests, saveModifiers_shiftKeyDown_savedModifiers4)
{
NiceMock<CMockEventQueue> eventQueue;
CMockKeyMap keyMap;
CMSWindowsKeyState keyState(getDesks(), getEventTarget(), eventQueue, keyMap);
getDesks()->enable();
getDesks()->fakeKeyEvent(1, 1, true, false);
keyState.saveModifiers();
ASSERT_EQ(1, keyState.getSavedModifiers());
}
*/

View File

@@ -0,0 +1,162 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2011 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
*
* 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 COPYING 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 <iostream>
#include <gtest/gtest.h>
#include "COSXClipboard.h"
TEST(COSXClipboardTests, empty_openCalled_returnsTrue)
{
COSXClipboard clipboard;
clipboard.open(0);
bool actual = clipboard.empty();
EXPECT_EQ(true, actual);
}
TEST(COSXClipboardTests, empty_singleFormat_hasReturnsFalse)
{
COSXClipboard clipboard;
clipboard.open(0);
clipboard.add(COSXClipboard::kText, "synergy rocks!");
clipboard.empty();
bool actual = clipboard.has(COSXClipboard::kText);
EXPECT_EQ(false, actual);
}
TEST(COSXClipboardTests, add_newValue_valueWasStored)
{
COSXClipboard clipboard;
clipboard.open(0);
clipboard.add(IClipboard::kText, "synergy rocks!");
CString actual = clipboard.get(IClipboard::kText);
EXPECT_EQ("synergy rocks!", actual);
}
TEST(COSXClipboardTests, add_replaceValue_valueWasReplaced)
{
COSXClipboard clipboard;
clipboard.open(0);
clipboard.add(IClipboard::kText, "synergy rocks!");
clipboard.add(IClipboard::kText, "maxivista sucks"); // haha, just kidding.
CString actual = clipboard.get(IClipboard::kText);
EXPECT_EQ("maxivista sucks", actual);
}
TEST(COSXClipboardTests, open_timeIsZero_returnsTrue)
{
COSXClipboard clipboard;
bool actual = clipboard.open(0);
EXPECT_EQ(true, actual);
}
TEST(COSXClipboardTests, open_timeIsOne_returnsTrue)
{
COSXClipboard clipboard;
bool actual = clipboard.open(1);
EXPECT_EQ(true, actual);
}
TEST(COSXClipboardTests, close_isOpen_noErrors)
{
COSXClipboard clipboard;
clipboard.open(0);
clipboard.close();
// can't assert anything
}
TEST(COSXClipboardTests, getTime_openWithNoEmpty_returnsOne)
{
COSXClipboard clipboard;
clipboard.open(1);
COSXClipboard::Time actual = clipboard.getTime();
// this behavior is different to that of CClipboard which only
// returns the value passed into open(t) after empty() is called.
EXPECT_EQ((UInt32)1, actual);
}
TEST(COSXClipboardTests, getTime_openAndEmpty_returnsOne)
{
COSXClipboard clipboard;
clipboard.open(1);
clipboard.empty();
COSXClipboard::Time actual = clipboard.getTime();
EXPECT_EQ((UInt32)1, actual);
}
TEST(COSXClipboardTests, has_withFormatAdded_returnsTrue)
{
COSXClipboard clipboard;
clipboard.open(0);
clipboard.empty();
clipboard.add(IClipboard::kText, "synergy rocks!");
bool actual = clipboard.has(IClipboard::kText);
EXPECT_EQ(true, actual);
}
TEST(COSXClipboardTests, has_withNoFormats_returnsFalse)
{
COSXClipboard clipboard;
clipboard.open(0);
clipboard.empty();
bool actual = clipboard.has(IClipboard::kText);
EXPECT_EQ(false, actual);
}
TEST(COSXClipboardTests, get_withNoFormats_returnsEmpty)
{
COSXClipboard clipboard;
clipboard.open(0);
clipboard.empty();
CString actual = clipboard.get(IClipboard::kText);
EXPECT_EQ("", actual);
}
TEST(COSXClipboardTests, get_withFormatAdded_returnsExpected)
{
COSXClipboard clipboard;
clipboard.open(0);
clipboard.empty();
clipboard.add(IClipboard::kText, "synergy rocks!");
CString actual = clipboard.get(IClipboard::kText);
EXPECT_EQ("synergy rocks!", actual);
}

View File

@@ -0,0 +1,98 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2011 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
*
* 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 COPYING 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 <gtest/gtest.h>
#include <gmock/gmock.h>
#include "COSXKeyState.h"
#include "CMockKeyMap.h"
#include "CMockEventQueue.h"
CGKeyCode escKeyCode = 53;
CGKeyCode shiftKeyCode = 56;
CGKeyCode controlKeyCode = 59;
// TODO: make pollActiveModifiers tests work reliably.
/*
TEST(COSXKeyStateTests, pollActiveModifiers_shiftKeyDownThenUp_masksAreCorrect)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
COSXKeyState keyState((IEventQueue&)keyMap, (CKeyMap&)eventQueue);
// fake shift key down (without using synergy). this is a bit weird;
// looks like you need to create a shift down event *and* set the
// shift modifier.
CGEventRef shiftDown = CGEventCreateKeyboardEvent(NULL, shiftKeyCode, true);
CGEventSetFlags(shiftDown, kCGEventFlagMaskShift);
CGEventPost(kCGHIDEventTap, shiftDown);
CFRelease(shiftDown);
// function under test (1st call)
KeyModifierMask downMask = keyState.pollActiveModifiers();
// fake shift key up (without using synergy). also as weird as the
// shift down; use a non-shift key down and reset the pressed modifiers.
CGEventRef shiftUp = CGEventCreateKeyboardEvent(NULL, escKeyCode, true);
CGEventSetFlags(shiftUp, 0);
CGEventPost(kCGHIDEventTap, shiftUp);
CFRelease(shiftUp);
// function under test (2nd call)
KeyModifierMask upMask = keyState.pollActiveModifiers();
EXPECT_TRUE((downMask & KeyModifierShift) == KeyModifierShift)
<< "shift key not in mask (" << downMask << ") - key was not pressed";
EXPECT_TRUE((upMask & KeyModifierShift) == 0)
<< "shift key still in mask (" << upMask << ") - make sure no keys are being held down";
}
TEST(COSXKeyStateTests, pollActiveModifiers_controlKeyDownThenUp_masksAreCorrect)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
COSXKeyState keyState((IEventQueue&)keyMap, (CKeyMap&)eventQueue);
// fake control key down (without using synergy). this is a bit weird;
// looks like you need to create a shift down event *and* set the
// shift modifier.
CGEventRef controlDown = CGEventCreateKeyboardEvent(NULL, controlKeyCode, true);
CGEventSetFlags(controlDown, kCGEventFlagMaskControl);
CGEventPost(kCGHIDEventTap, controlDown);
CFRelease(controlDown);
// function under test (1st call)
KeyModifierMask downMask = keyState.pollActiveModifiers();
// fake control key up (without using synergy). also as weird as the
// shift down; use a non-shift key down and reset the pressed modifiers.
CGEventRef controlUp = CGEventCreateKeyboardEvent(NULL, escKeyCode, true);
CGEventSetFlags(controlUp, 0);
CGEventPost(kCGHIDEventTap, controlUp);
CFRelease(controlUp);
// function under test (2nd call)
KeyModifierMask upMask = keyState.pollActiveModifiers();
EXPECT_TRUE((downMask & KeyModifierControl) == KeyModifierControl)
<< "control key not in mask (" << downMask << ") - key was not pressed";
EXPECT_TRUE((upMask & KeyModifierControl) == 0)
<< "control key still in mask (" << upMask << ") - make sure no keys are being held down";
}
*/

View File

@@ -0,0 +1,150 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2011 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
*
* 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 COPYING 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 <iostream>
#include <gtest/gtest.h>
#include "CXWindowsClipboard.h"
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, "synergy 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, "synergy rocks!");
CString actual = clipboard.get(IClipboard::kText);
EXPECT_EQ("synergy rocks!", actual);
}
TEST_F(CXWindowsClipboardTests, add_replaceValue_valueWasReplaced)
{
CXWindowsClipboard clipboard = createClipboard();
clipboard.add(IClipboard::kText, "synergy rocks!");
clipboard.add(IClipboard::kText, "maxivista sucks"); // haha, just kidding.
CString 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, "synergy 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();
CString actual = clipboard.get(IClipboard::kText);
EXPECT_EQ("", actual);
}
TEST_F(CXWindowsClipboardTests, get_withFormatAdded_returnsExpected)
{
CXWindowsClipboard clipboard = createClipboard();
clipboard.add(IClipboard::kText, "synergy rocks!");
CString actual = clipboard.get(IClipboard::kText);
EXPECT_EQ("synergy rocks!", actual);
}

View File

@@ -0,0 +1,234 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2011 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
*
* 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 COPYING 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 <gtest/gtest.h>
#include <gmock/gmock.h>
#define TEST_ENV
#include "Global.h"
#include "CMockKeyMap.h"
#include "CMockEventQueue.h"
#include "CXWindowsKeyState.h"
#include "CLog.h"
#include <errno.h>
#define XK_LATIN1
#define XK_MISCELLANY
#include "X11/keysymdef.h"
#if HAVE_XKB_EXTENSION
# include <X11/XKBlib.h>
#endif
class CXWindowsKeyStateTests : public ::testing::Test
{
protected:
CXWindowsKeyStateTests() :
m_display(NULL)
{
}
~CXWindowsKeyStateTests()
{
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(CXWindowsKeyStateTests, setActiveGroup_pollAndSet_groupIsZero)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CXWindowsKeyState keyState(m_display, true, eventQueue, keyMap);
keyState.setActiveGroup(CXWindowsKeyState::kGroupPollAndSet);
ASSERT_EQ(0, keyState.m_group);
}
TEST_F(CXWindowsKeyStateTests, setActiveGroup_poll_groupIsNotSet)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CXWindowsKeyState keyState(m_display, true, eventQueue, keyMap);
keyState.setActiveGroup(CXWindowsKeyState::kGroupPoll);
ASSERT_LE(-1, keyState.m_group);
}
TEST_F(CXWindowsKeyStateTests, setActiveGroup_customGroup_groupWasSet)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CXWindowsKeyState keyState(m_display, true, eventQueue, keyMap);
keyState.setActiveGroup(1);
ASSERT_EQ(1, keyState.m_group);
}
TEST_F(CXWindowsKeyStateTests, mapModifiersFromX_zeroState_zeroMask)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CXWindowsKeyState keyState(m_display, true, eventQueue, keyMap);
int mask = keyState.mapModifiersFromX(0);
ASSERT_EQ(0, mask);
}
TEST_F(CXWindowsKeyStateTests, mapModifiersToX_zeroMask_resultIsTrue)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CXWindowsKeyState keyState(m_display, true, eventQueue, keyMap);
unsigned int modifiers = 0;
bool result = keyState.mapModifiersToX(0, modifiers);
ASSERT_TRUE(result);
}
TEST_F(CXWindowsKeyStateTests, fakeCtrlAltDel_default_returnsFalse)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CXWindowsKeyState keyState(m_display, true, eventQueue, keyMap);
bool result = keyState.fakeCtrlAltDel();
ASSERT_FALSE(result);
}
TEST_F(CXWindowsKeyStateTests, pollActiveModifiers_defaultState_returnsZero)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CXWindowsKeyState keyState(m_display, true, eventQueue, keyMap);
KeyModifierMask actual = keyState.pollActiveModifiers();
ASSERT_EQ(0, actual);
}
TEST_F(CXWindowsKeyStateTests, pollActiveModifiers_shiftKeyDownThenUp_masksAreCorrect)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CXWindowsKeyState keyState(m_display, true, eventQueue, keyMap);
// set mock modifier mapping
std::fill(
keyState.m_modifierFromX.begin(), keyState.m_modifierFromX.end(), 0);
keyState.m_modifierFromX[ShiftMapIndex] = KeyModifierShift;
KeyCode key = XKeysymToKeycode(m_display, XK_Shift_L);
// fake shift key down (without using synergy)
XTestFakeKeyEvent(m_display, key, true, CurrentTime);
// function under test (1st call)
KeyModifierMask modDown = keyState.pollActiveModifiers();
// fake shift key up (without using synergy)
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";
}
TEST_F(CXWindowsKeyStateTests, pollActiveGroup_defaultState_returnsZero)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CXWindowsKeyState keyState(m_display, true, eventQueue, keyMap);
SInt32 actual = keyState.pollActiveGroup();
ASSERT_EQ(0, actual);
}
TEST_F(CXWindowsKeyStateTests, pollActiveGroup_positiveGroup_returnsGroup)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CXWindowsKeyState keyState(m_display, true, eventQueue, keyMap);
keyState.m_group = 3;
SInt32 actual = keyState.pollActiveGroup();
ASSERT_EQ(3, actual);
}
TEST_F(CXWindowsKeyStateTests, pollActiveGroup_xkb_areEqual)
{
#if HAVE_XKB_EXTENSION
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CXWindowsKeyState keyState(m_display, true, eventQueue, keyMap);
// reset the group
keyState.m_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
}

View File

@@ -0,0 +1,43 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2011 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
*
* 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 COPYING 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 <gtest/gtest.h>
#include "CXWindowsScreenSaver.h"
#include "CMockEventQueue.h"
#include <X11/Xlib.h>
using ::testing::_;
// TODO: not working on build machine for some reason
#if 0
TEST(CXWindowsScreenSaverTests, activate_defaultScreen_todo)
{
Display* display = XOpenDisplay(":0.0");
Window window = DefaultRootWindow(display);
CMockEventQueue 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

View File

@@ -0,0 +1,38 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2011 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
*
* 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 COPYING 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 <gtest/gtest.h>
#include "CXWindowsScreen.h"
#include "CMockEventQueue.h"
using ::testing::_;
TEST(CXWindowsScreenTests, fakeMouseMove_nonPrimary_getCursorPosValuesCorrect)
{
CMockEventQueue eventQueue;
EXPECT_CALL(eventQueue, adoptHandler(_, _, _)).Times(2);
EXPECT_CALL(eventQueue, adoptBuffer(_)).Times(2);
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(2);
CXWindowsScreen 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);
}