merged 1.4 r1007:1008 into trunk

This commit is contained in:
Nick Bolton
2011-05-21 00:30:08 +00:00
parent bebf8c2c2c
commit 5a315324ca
39 changed files with 808 additions and 2854 deletions

View File

@@ -13,7 +13,14 @@
# 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(h
synergy/CKeyStateImpl.h
synergy/CMockEventQueue.h
synergy/CMockKeyMap.h
)
set(src
${h}
Main.cpp
synergy/CClipboardTests.cpp
synergy/CKeyStateTests.cpp
@@ -29,7 +36,7 @@ set(inc
../../lib/net
../../lib/platform
../../lib/synergy
../../../tools/gtest-1.6.0/include
../../../tools/gtest-1.6.0/include
../../../tools/gmock-1.6.0/include
)

View File

@@ -20,24 +20,24 @@
TEST(CClipboardTests, empty_openCalled_returnsTrue)
{
CClipboard clipboard;
clipboard.open(0);
bool actual = clipboard.empty();
CClipboard clipboard;
clipboard.open(0);
bool actual = clipboard.empty();
EXPECT_EQ(true, actual);
}
TEST(CClipboardTests, empty_singleFormat_hasReturnsFalse)
{
CClipboard clipboard;
clipboard.open(0);
clipboard.add(CClipboard::kText, "synergy rocks!");
clipboard.empty();
bool actual = clipboard.has(CClipboard::kText);
EXPECT_EQ(false, actual);
CClipboard clipboard;
clipboard.open(0);
clipboard.add(CClipboard::kText, "synergy rocks!");
clipboard.empty();
bool actual = clipboard.has(CClipboard::kText);
EXPECT_FALSE(actual);
}
TEST(CClipboardTests, add_newValue_valueWasStored)
@@ -65,19 +65,19 @@ TEST(CClipboardTests, add_replaceValue_valueWasReplaced)
TEST(CClipboardTests, open_timeIsZero_returnsTrue)
{
CClipboard clipboard;
bool actual = clipboard.open(0);
CClipboard clipboard;
bool actual = clipboard.open(0);
EXPECT_EQ(true, actual);
}
TEST(CClipboardTests, open_timeIsOne_returnsTrue)
{
CClipboard clipboard;
bool actual = clipboard.open(1);
CClipboard clipboard;
bool actual = clipboard.open(1);
EXPECT_EQ(true, actual);
}
@@ -93,22 +93,22 @@ TEST(CClipboardTests, close_isOpen_noErrors)
TEST(CClipboardTests, getTime_openWithNoEmpty_returnsZero)
{
CClipboard clipboard;
clipboard.open(1);
CClipboard::Time actual = clipboard.getTime();
CClipboard clipboard;
clipboard.open(1);
CClipboard::Time actual = clipboard.getTime();
EXPECT_EQ(0, actual);
}
TEST(CClipboardTests, getTime_openAndEmpty_returnsOne)
{
CClipboard clipboard;
clipboard.open(1);
clipboard.empty();
CClipboard::Time actual = clipboard.getTime();
CClipboard clipboard;
clipboard.open(1);
clipboard.empty();
CClipboard::Time actual = clipboard.getTime();
EXPECT_EQ(1, actual);
}
@@ -130,7 +130,7 @@ TEST(CClipboardTests, has_withNoFormats_returnsFalse)
bool actual = clipboard.has(IClipboard::kText);
EXPECT_EQ(false, actual);
EXPECT_FALSE(actual);
}
TEST(CClipboardTests, get_withNoFormats_returnsEmpty)
@@ -281,7 +281,7 @@ TEST(CClipboardTests, unmarshall_emptyData_hasTextIsFalse)
clipboard.open(0);
bool actual = clipboard.has(IClipboard::kText);
EXPECT_EQ(false, actual);
EXPECT_FALSE(actual);
}
TEST(CClipboardTests, unmarshall_withTextSize285_getTextIsValid)

View File

@@ -0,0 +1,60 @@
/*
* 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/>.
*/
#ifndef CKEYSTATEIMPL_H
#define CKEYSTATEIMPL_H
#include "CKeyState.h"
#include "gmock/gmock.h"
class CMockKeyMap;
class CMockEventQueue;
// while the class name indicates that this is actually a mock, we use a
// typedef later to rename it (so the name matches the compilation unit)
// so the tests are less confusing.
class CMockKeyState : public CKeyState
{
public:
CMockKeyState() : CKeyState()
{
}
CMockKeyState(const CMockEventQueue& eventQueue, const CMockKeyMap& keyMap) :
CKeyState((IEventQueue&)eventQueue, (CKeyMap&)keyMap)
{
}
MOCK_CONST_METHOD0(pollActiveGroup, SInt32());
MOCK_CONST_METHOD0(pollActiveModifiers, KeyModifierMask());
MOCK_METHOD0(fakeCtrlAltDel, bool());
MOCK_METHOD1(getKeyMap, void(CKeyMap&));
MOCK_METHOD1(fakeKey, void(const Keystroke&));
MOCK_CONST_METHOD1(pollPressedKeys, void(KeyButtonSet&));
};
// hide that we're actually testing a mock to make the unit tests less
// confusing. use NiceMock so that we don't get warnings for unexpected
// calls.
typedef ::testing::NiceMock<CMockKeyState> CKeyStateImpl;
typedef UInt32 KeyID;
typedef void (*ForeachKeyCallback)(
KeyID, SInt32 group, CKeyMap::KeyItem&, void* userData);
#endif

View File

@@ -16,66 +16,205 @@
*/
#include <gtest/gtest.h>
#include "CKeyState.h"
#include <gmock/gmock.h>
#include "CKeyStateImpl.h"
#include "CMockEventQueue.h"
#include "CMockKeyMap.h"
using ::testing::_;
using ::testing::NiceMock;
using ::testing::Invoke;
using ::testing::Return;
using ::testing::SaveArg;
enum {
kAKey = 30
};
class CKeyStateImpl : public CKeyState
TEST(CKeyStateTests, onKey_aKeyDown_keyStateOne)
{
protected:
virtual SInt32 pollActiveGroup() const
{
return 0;
}
virtual KeyModifierMask pollActiveModifiers() const
{
return 0;
}
virtual bool fakeCtrlAltDel()
{
return false;
}
virtual void getKeyMap(CKeyMap& keyMap)
{
}
virtual void fakeKey(const Keystroke& keystroke)
{
}
virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const
{
}
};
TEST(CKeyStateTests, onKey_aKeyPressed_keyStateOne)
{
CKeyStateImpl keyState;
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CKeyStateImpl keyState(eventQueue, keyMap);
keyState.onKey(kAKey, true, KeyModifierAlt);
EXPECT_EQ(1, keyState.getKeyState(kAKey));
}
TEST(CKeyStateTests, onKey_validButtonUp_keyStateZero)
TEST(CKeyStateTests, onKey_aKeyUp_keyStateZero)
{
CKeyStateImpl keyState;
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CKeyStateImpl keyState(eventQueue, keyMap);
keyState.onKey(kAKey, false, KeyModifierAlt);
EXPECT_EQ(0, keyState.getKeyState(kAKey));
}
TEST(CKeyStateTests, onKey_invalidKey_keyStateZero)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CKeyStateImpl keyState(eventQueue, keyMap);
keyState.onKey(0, true, KeyModifierAlt);
EXPECT_EQ(0, keyState.getKeyState(0));
}
TEST(CKeyStateTests, onKey_bogusButtonDown_keyStateZero)
TEST(CKeyStateTests, sendKeyEvent_halfDuplexAndRepeat_addEventNotCalled)
{
CKeyStateImpl keyState;
NiceMock<CMockKeyMap> keyMap;
NiceMock<CMockEventQueue> eventQueue;
CKeyStateImpl keyState(eventQueue, keyMap);
ON_CALL(keyMap, isHalfDuplex(_, _)).WillByDefault(Return(true));
keyState.onKey(0, true, KeyModifierAlt);
EXPECT_CALL(eventQueue, addEvent(_)).Times(0);
EXPECT_EQ(0, keyState.getKeyState(0));
keyState.sendKeyEvent(NULL, false, true, kKeyCapsLock, 0, 0, 0);
}
TEST(CKeyStateTests, sendKeyEvent_halfDuplex_addEventCalledTwice)
{
CMockKeyMap keyMap;
NiceMock<CMockEventQueue> eventQueue;
CKeyStateImpl keyState(eventQueue, keyMap);
ON_CALL(keyMap, isHalfDuplex(_, _)).WillByDefault(Return(true));
EXPECT_CALL(eventQueue, addEvent(_)).Times(2);
keyState.sendKeyEvent(NULL, false, false, kKeyCapsLock, 0, 0, 0);
}
TEST(CKeyStateTests, sendKeyEvent_keyRepeat_addEventCalledOnce)
{
CMockKeyMap keyMap;
NiceMock<CMockEventQueue> eventQueue;
CKeyStateImpl keyState(eventQueue, keyMap);
EXPECT_CALL(eventQueue, addEvent(_)).Times(1);
keyState.sendKeyEvent(NULL, false, true, kAKey, 0, 0, 0);
}
TEST(CKeyStateTests, sendKeyEvent_keyDown_addEventCalledOnce)
{
CMockKeyMap keyMap;
NiceMock<CMockEventQueue> eventQueue;
CKeyStateImpl keyState(eventQueue, keyMap);
EXPECT_CALL(eventQueue, addEvent(_)).Times(1);
keyState.sendKeyEvent(NULL, true, false, kAKey, 0, 0, 0);
}
TEST(CKeyStateTests, sendKeyEvent_keyUp_addEventCalledOnce)
{
CMockKeyMap keyMap;
NiceMock<CMockEventQueue> eventQueue;
CKeyStateImpl keyState(eventQueue, keyMap);
EXPECT_CALL(eventQueue, addEvent(_)).Times(1);
keyState.sendKeyEvent(NULL, false, false, kAKey, 0, 0, 0);
}
TEST(CKeyStateTests, updateKeyMap_mockKeyMap_keyMapGotMock)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CKeyStateImpl keyState(eventQueue, keyMap);
EXPECT_CALL(keyMap, swap(_));
EXPECT_CALL(keyMap, finish());
keyState.updateKeyMap();
}
void
stubPollPressedKeys(IKeyState::KeyButtonSet& pressedKeys)
{
pressedKeys.insert(kAKey);
}
TEST(CKeyStateTests, updateKeyState_pollInsertsSingleKey_keyIsDown)
{
NiceMock<CMockKeyMap> keyMap;
CMockEventQueue eventQueue;
CKeyStateImpl keyState(eventQueue, keyMap);
ON_CALL(keyState, pollPressedKeys(_)).WillByDefault(Invoke(stubPollPressedKeys));
keyState.updateKeyState();
bool actual = keyState.isKeyDown(kAKey);
ASSERT_TRUE(actual);
}
TEST(CKeyStateTests, updateKeyState_pollDoesNothing_keyNotSet)
{
NiceMock<CMockKeyMap> keyMap;
CMockEventQueue eventQueue;
CKeyStateImpl keyState(eventQueue, keyMap);
keyState.updateKeyState();
bool actual = keyState.isKeyDown(kAKey);
ASSERT_FALSE(actual);
}
TEST(CKeyStateTests, updateKeyState_activeModifiers_maskSet)
{
NiceMock<CMockKeyMap> keyMap;
CMockEventQueue eventQueue;
CKeyStateImpl keyState(eventQueue, keyMap);
ON_CALL(keyState, pollActiveModifiers()).WillByDefault(Return(KeyModifierAlt));
keyState.updateKeyState();
KeyModifierMask actual = keyState.getActiveModifiers();
ASSERT_EQ(KeyModifierAlt, actual);
}
TEST(CKeyStateTests, updateKeyState_activeModifiers_maskNotSet)
{
NiceMock<CMockKeyMap> keyMap;
CMockEventQueue eventQueue;
CKeyStateImpl keyState(eventQueue, keyMap);
keyState.updateKeyState();
KeyModifierMask actual = keyState.getActiveModifiers();
ASSERT_EQ(0, actual);
}
void
assertMaskIsOne(ForeachKeyCallback cb, void* userData)
{
ASSERT_EQ(1, ((CKeyState::CAddActiveModifierContext*)userData)->m_mask);
}
TEST(CKeyStateTests, updateKeyState_activeModifiers_keyMapGotModifers)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CKeyStateImpl keyState(eventQueue, keyMap);
EXPECT_CALL(keyMap, foreachKey(_, _));
ON_CALL(keyState, pollActiveModifiers()).WillByDefault(Return(1));
ON_CALL(keyMap, foreachKey(_, _)).WillByDefault(Invoke(assertMaskIsOne));
keyState.updateKeyState();
}
TEST(CKeyStateTests, setHalfDuplexMask_capsLock_halfDuplexCapsLockAdded)
{
CMockKeyMap keyMap;
CMockEventQueue eventQueue;
CKeyStateImpl keyState(eventQueue, keyMap);
EXPECT_CALL(keyMap, addHalfDuplexModifier(kKeyCapsLock));
keyState.setHalfDuplexMask(KeyModifierCapsLock);
}

View File

@@ -0,0 +1,44 @@
/*
* 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/>.
*/
#ifndef CMOCKEVENTQUEUE_H
#define CMOCKEVENTQUEUE_H
#include <gmock/gmock.h>
#include "IEventQueue.h"
class CMockEventQueue : public IEventQueue
{
public:
MOCK_METHOD2(newOneShotTimer, CEventQueueTimer*(double, void*));
MOCK_METHOD2(newTimer, CEventQueueTimer*(double, void*));
MOCK_METHOD2(getEvent, bool(CEvent&, double));
MOCK_METHOD1(adoptBuffer, void(IEventQueueBuffer*));
MOCK_METHOD2(registerTypeOnce, CEvent::Type(CEvent::Type&, const char*));
MOCK_METHOD1(removeHandlers, void(void*));
MOCK_METHOD1(registerType, CEvent::Type(const char*));
MOCK_CONST_METHOD0(isEmpty, bool());
MOCK_METHOD3(adoptHandler, void(CEvent::Type, void*, IEventJob*));
MOCK_METHOD1(getTypeName, const char*(CEvent::Type));
MOCK_METHOD1(addEvent, void(const CEvent&));
MOCK_METHOD2(removeHandler, void(CEvent::Type, void*));
MOCK_METHOD1(dispatchEvent, bool(const CEvent&));
MOCK_CONST_METHOD2(getHandler, IEventJob*(CEvent::Type, void*));
MOCK_METHOD1(deleteTimer, void(CEventQueueTimer*));
};
#endif

View File

@@ -0,0 +1,34 @@
/*
* 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/>.
*/
#ifndef CMOCKKEYMAP_H
#define CMOCKKEYMAP_H
#include <gmock/gmock.h>
#include "CKeyMap.h"
class CMockKeyMap : public CKeyMap
{
public:
MOCK_METHOD1(swap, void(CKeyMap&));
MOCK_METHOD0(finish, void());
MOCK_METHOD2(foreachKey, void(ForeachKeyCallback, void*));
MOCK_METHOD1(addHalfDuplexModifier, void(KeyID));
MOCK_CONST_METHOD2(isHalfDuplex, bool(KeyID, KeyButton));
};
#endif