[Libreoffice-commits] core.git: Branch 'feature/debugevent' - 2 commits - include/vcl vcl/source

Michael Meeks michael.meeks at collabora.com
Thu May 8 14:00:15 PDT 2014


 include/vcl/debugevent.hxx       |    2 -
 vcl/source/window/debugevent.cxx |   56 ++++++++++++++++++++++++++++-----------
 2 files changed, 42 insertions(+), 16 deletions(-)

New commits:
commit 4b74bdd3a2122e64fe43aabb02341a454db77b73
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Thu May 8 21:59:45 2014 +0100

    Make the inserted text more European and sensible for now.
    
    Change-Id: I8b2ecef11362c0fc1dc2b76780140881e769bb89

diff --git a/include/vcl/debugevent.hxx b/include/vcl/debugevent.hxx
index ce31570..2700324 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 37ca716..4bd54ed 100644
--- a/vcl/source/window/debugevent.cxx
+++ b/vcl/source/window/debugevent.cxx
@@ -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();
commit ade994548c593ea1185711a3e226f51a99fbb660
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Thu May 8 21:43:46 2014 +0100

    quit after emitting all the events to allow valgrinding.
    
    Change-Id: Ibee9d8f00008dd0a266db276772d48deb0bd9d18

diff --git a/vcl/source/window/debugevent.cxx b/vcl/source/window/debugevent.cxx
index 2f37678..37ca716 100644
--- a/vcl/source/window/debugevent.cxx
+++ b/vcl/source/window/debugevent.cxx
@@ -120,7 +120,7 @@ void DebugEventInjector::InjectMenuEvent()
 static void InitKeyEvent( SalKeyEvent &rKeyEvent )
 {
     double nRand = getRandom();
-    if (nRand < 0.01)
+    if (nRand < 0.001)
         rKeyEvent.mnTime = getRandom() * ULONG_MAX;
     else
         rKeyEvent.mnTime = Time::GetSystemTicks();
@@ -216,14 +216,15 @@ void DebugEventInjector::InjectKeyNavEdit()
     InitKeyEvent( aKeyEvent );
     aKeyEvent.mnCode = nKey;
 
-    if (getRandom() < 0.10) // modifier
+    if (getRandom() < 0.15) // modifier
         aKeyEvent.mnCode |= (sal_uInt16)(getRandom() * KEY_MODTYPE) & KEY_MODTYPE;
 
     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);
+    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 );
+    ImplWindowFrameProc( pWindow, NULL, SALEVENT_KEYUP, &aKeyEvent );
 }
 
 void DebugEventInjector::Timeout()
@@ -235,6 +236,8 @@ void DebugEventInjector::Timeout()
         SetTimeout( 1 );
         Start();
     }
+    else
+        Application::Quit();
 }
 
 DebugEventInjector *DebugEventInjector::getCreate()


More information about the Libreoffice-commits mailing list