diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2014-05-08 21:59:45 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2014-05-22 09:48:20 +0100 |
commit | 344dc7fd0684acc31f4c18e99e65bfa6700c9c64 (patch) | |
tree | ed1e284ac71d0b9214b4d04b8d4b956740733dd3 | |
parent | 45935fc3fed0a215e93de20c28933bf318f618cd (diff) |
Make the inserted text more European and sensible for now.
Change-Id: I8b2ecef11362c0fc1dc2b76780140881e769bb89
-rw-r--r-- | include/vcl/debugevent.hxx | 2 | ||||
-rw-r--r-- | vcl/source/window/debugevent.cxx | 53 |
2 files changed, 39 insertions, 16 deletions
diff --git a/include/vcl/debugevent.hxx b/include/vcl/debugevent.hxx index ce3157055b68..270032497905 100644 --- a/include/vcl/debugevent.hxx +++ b/include/vcl/debugevent.hxx @@ -20,7 +20,7 @@ class VCL_DLLPUBLIC DebugEventInjector : Timer { DebugEventInjector( sal_uInt32 nMaxEvents ); Window *ChooseWindow(); - void InjectKeyEvent(); + void InjectTextEvent(); void InjectMenuEvent(); void InjectMouseEvent(); void InjectEvent(); diff --git a/vcl/source/window/debugevent.cxx b/vcl/source/window/debugevent.cxx index 37ca7169f71b..e83909e04f2a 100644 --- a/vcl/source/window/debugevent.cxx +++ b/vcl/source/window/debugevent.cxx @@ -7,7 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <stdio.h> +// #include <stdio.h> #include <rtl/math.hxx> #include <rtl/string.hxx> #include <tools/time.hxx> @@ -110,11 +110,11 @@ void DebugEventInjector::InjectMenuEvent() SalMenuEvent aEvent = aIds[ getRandom() * aIds.size() ]; bool bHandled = ImplWindowFrameProc( pSysWin, NULL, nEvent, &aEvent); - fprintf( stderr, "Injected menu event %p (%d) '%s' -> %d\n", +/* fprintf( stderr, "Injected menu event %p (%d) '%s' -> %d\n", aEvent.mpMenu, aEvent.mnId, OUStringToOString( ((Menu *)aEvent.mpMenu)->GetItemText( aEvent.mnId ), RTL_TEXTENCODING_UTF8 ).getStr(), - (int)bHandled); + (int)bHandled); */ } static void InitKeyEvent( SalKeyEvent &rKeyEvent ) @@ -131,22 +131,43 @@ static void InitKeyEvent( SalKeyEvent &rKeyEvent ) rKeyEvent.mnRepeat = 0; } -void DebugEventInjector::InjectKeyEvent() +void DebugEventInjector::InjectTextEvent() { SalKeyEvent aKeyEvent; Window *pWindow = ChooseWindow(); InitKeyEvent( aKeyEvent ); - sal_uInt16 nCode = getRandom() * KEY_CODE; - if( getRandom() < 0.05 ) // modifier - nCode |= (sal_uInt16)( getRandom() * KEY_MODTYPE ) & KEY_MODTYPE; - aKeyEvent.mnCode = nCode; - aKeyEvent.mnCharCode = getRandom() * 0xffff; + if (getRandom() < 0.10) // Occasionally a truly random event + { + aKeyEvent.mnCode = getRandom() * KEY_CODE; + aKeyEvent.mnCharCode = getRandom() * 0xffff; + } + else + { + struct { + sal_uInt16 nCodeStart, nCodeEnd; + char aCharStart; + } nTextCodes[] = { + { KEY_0, KEY_9, '0' }, + { KEY_A, KEY_Z, 'a' } + }; + + size_t i = getRandom() * SAL_N_ELEMENTS( nTextCodes ); + int offset = trunc( getRandom() * ( nTextCodes[i].nCodeEnd - nTextCodes[i].nCodeStart ) ); + aKeyEvent.mnCode = nTextCodes[i].nCodeStart + offset; + aKeyEvent.mnCharCode = nTextCodes[i].aCharStart + offset; +// fprintf( stderr, "Char '%c' offset %d into record %d base '%c'\n", +// aKeyEvent.mnCharCode, offset, (int)i, nTextCodes[i].aCharStart ); + } + + if( getRandom() < 0.05 ) // modifier + aKeyEvent.mnCode |= (sal_uInt16)( getRandom() * KEY_MODTYPE ) & KEY_MODTYPE; bool bHandled = ImplWindowFrameProc( pWindow, NULL, SALEVENT_KEYINPUT, &aKeyEvent); - fprintf (stderr, "Injected key 0x%x -> %d win %p\n", - (int) aKeyEvent.mnCode, (int)bHandled, pWindow); +// fprintf( stderr, "Injected key 0x%x -> %d win %p\n", +// (int) aKeyEvent.mnCode, (int)bHandled, pWindow ); + ImplWindowFrameProc( pWindow, NULL, SALEVENT_KEYUP, &aKeyEvent ); } /* @@ -155,12 +176,14 @@ void DebugEventInjector::InjectKeyEvent() */ void DebugEventInjector::InjectEvent() { +// fprintf( stderr, "%6d - ", (int)mnEventsLeft ); + double nRand = getRandom(); - if (nRand < 0.50) + if (nRand < 0.30) { int nEvents = getRandom() * 10; for (int i = 0; i < nEvents; i++) - InjectKeyEvent(); + InjectTextEvent(); } else if (nRand < 0.60) InjectKeyNavEdit(); @@ -222,8 +245,8 @@ void DebugEventInjector::InjectKeyNavEdit() aKeyEvent.mnCharCode = 0x0; // hopefully unused. bool bHandled = ImplWindowFrameProc( pWindow, NULL, SALEVENT_KEYINPUT, &aKeyEvent ); - fprintf( stderr, "Injected edit / move key 0x%x -> %d win %p\n", - (int) aKeyEvent.mnCode, (int)bHandled, pWindow ); +// fprintf( stderr, "Injected edit / move key 0x%x -> %d win %p\n", +// (int) aKeyEvent.mnCode, (int)bHandled, pWindow ); ImplWindowFrameProc( pWindow, NULL, SALEVENT_KEYUP, &aKeyEvent ); } |