mirror of
https://github.com/debauchee/barrier.git
synced 2024-12-19 08:51:41 +03:00
added failing unit test and event queue DI to ms desks class.
This commit is contained in:
parent
34a87502f6
commit
de30d04c72
@ -29,6 +29,7 @@
|
||||
#include "TMethodJob.h"
|
||||
#include "CArchMiscWindows.h"
|
||||
#include <malloc.h>
|
||||
#include "IEventQueue.h"
|
||||
|
||||
// these are only defined when WINVER >= 0x0500
|
||||
#if !defined(SPI_GETMOUSESPEED)
|
||||
@ -89,8 +90,9 @@
|
||||
//
|
||||
|
||||
CMSWindowsDesks::CMSWindowsDesks(
|
||||
bool isPrimary, bool noHooks, HINSTANCE hookLibrary,
|
||||
const IScreenSaver* screensaver, IJob* updateKeys) :
|
||||
bool isPrimary, bool noHooks, HINSTANCE hookLibrary,
|
||||
const IScreenSaver* screensaver, IEventQueue& eventQueue,
|
||||
IJob* updateKeys) :
|
||||
m_isPrimary(isPrimary),
|
||||
m_noHooks(noHooks),
|
||||
m_is95Family(CArchMiscWindows::isWindows95Family()),
|
||||
@ -107,7 +109,8 @@ CMSWindowsDesks::CMSWindowsDesks(
|
||||
m_activeDeskName(),
|
||||
m_mutex(),
|
||||
m_deskReady(&m_mutex, false),
|
||||
m_updateKeys(updateKeys)
|
||||
m_updateKeys(updateKeys),
|
||||
m_eventQueue(eventQueue)
|
||||
{
|
||||
if (hookLibrary != NULL)
|
||||
queryHookLibrary(hookLibrary);
|
||||
@ -138,8 +141,8 @@ CMSWindowsDesks::enable()
|
||||
// which desk is active and reinstalls the hooks as necessary.
|
||||
// we wouldn't need this if windows notified us of a desktop
|
||||
// change but as far as i can tell it doesn't.
|
||||
m_timer = EVENTQUEUE->newTimer(0.2, NULL);
|
||||
EVENTQUEUE->adoptHandler(CEvent::kTimer, m_timer,
|
||||
m_timer = m_eventQueue.newTimer(0.2, NULL);
|
||||
m_eventQueue.adoptHandler(CEvent::kTimer, m_timer,
|
||||
new TMethodEventJob<CMSWindowsDesks>(
|
||||
this, &CMSWindowsDesks::handleCheckDesk));
|
||||
|
||||
@ -151,8 +154,8 @@ CMSWindowsDesks::disable()
|
||||
{
|
||||
// remove timer
|
||||
if (m_timer != NULL) {
|
||||
EVENTQUEUE->removeHandler(CEvent::kTimer, m_timer);
|
||||
EVENTQUEUE->deleteTimer(m_timer);
|
||||
m_eventQueue.removeHandler(CEvent::kTimer, m_timer);
|
||||
m_eventQueue.deleteTimer(m_timer);
|
||||
m_timer = NULL;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ class CEventQueueTimer;
|
||||
class CThread;
|
||||
class IJob;
|
||||
class IScreenSaver;
|
||||
class IEventQueue;
|
||||
|
||||
//! Microsoft Windows desk handling
|
||||
/*!
|
||||
@ -62,8 +63,10 @@ public:
|
||||
updated in a thread attached to the current desk.
|
||||
\p hookLibrary must be a handle to the hook library.
|
||||
*/
|
||||
CMSWindowsDesks(bool isPrimary, bool noHooks, HINSTANCE hookLibrary,
|
||||
const IScreenSaver* screensaver, IJob* updateKeys);
|
||||
CMSWindowsDesks(
|
||||
bool isPrimary, bool noHooks, HINSTANCE hookLibrary,
|
||||
const IScreenSaver* screensaver, IEventQueue& eventQueue,
|
||||
IJob* updateKeys);
|
||||
~CMSWindowsDesks();
|
||||
|
||||
//! @name manipulators
|
||||
@ -289,8 +292,10 @@ private:
|
||||
// hook library stuff
|
||||
InstallFunc m_install;
|
||||
UninstallFunc m_uninstall;
|
||||
InstallScreenSaverFunc m_installScreensaver;
|
||||
UninstallScreenSaverFunc m_uninstallScreensaver;
|
||||
InstallScreenSaverFunc
|
||||
m_installScreensaver;
|
||||
UninstallScreenSaverFunc
|
||||
m_uninstallScreensaver;
|
||||
|
||||
// keyboard stuff
|
||||
IJob* m_updateKeys;
|
||||
@ -298,6 +303,8 @@ private:
|
||||
|
||||
// options
|
||||
bool m_leaveForegroundOption;
|
||||
|
||||
IEventQueue& m_eventQueue;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -122,6 +122,7 @@ CMSWindowsScreen::CMSWindowsScreen(bool isPrimary, bool noHooks, const CGameDevi
|
||||
m_desks = new CMSWindowsDesks(
|
||||
m_isPrimary, m_noHooks,
|
||||
m_hookLibrary, m_screensaver,
|
||||
*EVENTQUEUE,
|
||||
new TMethodJob<CMSWindowsScreen>(this,
|
||||
&CMSWindowsScreen::updateKeysCB));
|
||||
m_keyState = new CMSWindowsKeyState(m_desks, getEventTarget());
|
||||
|
@ -17,6 +17,10 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#define TEST_ENV
|
||||
#include "Global.h"
|
||||
|
||||
#include "CMSWindowsKeyState.h"
|
||||
#include "CMSWindowsDesks.h"
|
||||
#include "CMSWindowsScreen.h"
|
||||
@ -39,21 +43,19 @@ protected:
|
||||
// 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
|
||||
CMSWindowsDesks* newDesks(IEventQueue& eventQueue)
|
||||
{
|
||||
return m_desks;
|
||||
return new CMSWindowsDesks(
|
||||
true, false, m_hookLibrary, m_screensaver, eventQueue,
|
||||
new TMethodJob<CMSWindowsKeyStateTests>(
|
||||
this, &CMSWindowsKeyStateTests::updateKeysCB));
|
||||
}
|
||||
|
||||
void* getEventTarget() const
|
||||
@ -65,70 +67,75 @@ 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;
|
||||
CMSWindowsDesks* desks = newDesks(eventQueue);
|
||||
CMockKeyMap keyMap;
|
||||
CMSWindowsKeyState keyState(getDesks(), getEventTarget(), eventQueue, keyMap);
|
||||
CMSWindowsKeyState keyState(desks, getEventTarget(), eventQueue, keyMap);
|
||||
|
||||
// in anything above win95-family, event handler should not be called.
|
||||
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(0);
|
||||
|
||||
keyState.disable();
|
||||
delete desks;
|
||||
}
|
||||
|
||||
TEST_F(CMSWindowsKeyStateTests, testAutoRepeat_noRepeatAndButtonIsZero_resultIsTrue)
|
||||
{
|
||||
NiceMock<CMockEventQueue> eventQueue;
|
||||
CMSWindowsDesks* desks = newDesks(eventQueue);
|
||||
CMockKeyMap keyMap;
|
||||
CMSWindowsKeyState keyState(getDesks(), getEventTarget(), eventQueue, keyMap);
|
||||
CMSWindowsKeyState keyState(desks, getEventTarget(), eventQueue, keyMap);
|
||||
keyState.setLastDown(1);
|
||||
|
||||
bool actual = keyState.testAutoRepeat(true, false, 1);
|
||||
|
||||
ASSERT_TRUE(actual);
|
||||
delete desks;
|
||||
}
|
||||
|
||||
TEST_F(CMSWindowsKeyStateTests, testAutoRepeat_pressFalse_lastDownIsZero)
|
||||
{
|
||||
NiceMock<CMockEventQueue> eventQueue;
|
||||
CMSWindowsDesks* desks = newDesks(eventQueue);
|
||||
CMockKeyMap keyMap;
|
||||
CMSWindowsKeyState keyState(getDesks(), getEventTarget(), eventQueue, keyMap);
|
||||
CMSWindowsKeyState keyState(desks, getEventTarget(), eventQueue, keyMap);
|
||||
keyState.setLastDown(1);
|
||||
|
||||
keyState.testAutoRepeat(false, false, 1);
|
||||
|
||||
ASSERT_EQ(0, keyState.getLastDown());
|
||||
delete desks;
|
||||
}
|
||||
|
||||
TEST_F(CMSWindowsKeyStateTests, saveModifiers_noModifiers_savedModifiers0)
|
||||
{
|
||||
NiceMock<CMockEventQueue> eventQueue;
|
||||
CMSWindowsDesks* desks = newDesks(eventQueue);
|
||||
CMockKeyMap keyMap;
|
||||
CMSWindowsKeyState keyState(getDesks(), getEventTarget(), eventQueue, keyMap);
|
||||
CMSWindowsKeyState keyState(desks, getEventTarget(), eventQueue, keyMap);
|
||||
|
||||
keyState.saveModifiers();
|
||||
|
||||
ASSERT_EQ(0, keyState.getSavedModifiers());
|
||||
delete desks;
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO: fix Assertion failed: s_instance != NULL,
|
||||
// file ..\..\..\..\src\lib\base\IEventQueue.cpp, line 37
|
||||
|
||||
TEST_F(CMSWindowsKeyStateTests, saveModifiers_shiftKeyDown_savedModifiers4)
|
||||
{
|
||||
NiceMock<CMockEventQueue> eventQueue;
|
||||
CMSWindowsDesks* desks = newDesks(eventQueue);
|
||||
CMockKeyMap keyMap;
|
||||
CMSWindowsKeyState keyState(getDesks(), getEventTarget(), eventQueue, keyMap);
|
||||
getDesks()->enable();
|
||||
getDesks()->fakeKeyEvent(1, 1, true, false);
|
||||
CMSWindowsKeyState keyState(desks, getEventTarget(), eventQueue, keyMap);
|
||||
desks->enable();
|
||||
desks->fakeKeyEvent(1, 1, true, false);
|
||||
|
||||
keyState.saveModifiers();
|
||||
|
||||
ASSERT_EQ(1, keyState.getSavedModifiers());
|
||||
delete desks;
|
||||
}
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user