Created
April 27, 2015 09:59
-
-
Save gabonator/fa99acc2752ae1e22534 to your computer and use it in GitHub Desktop.
Hopper test pre Auru
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CJsFunctions | |
{ | |
struct TTimer | |
{ | |
INT nShots; | |
CString strCall; | |
INT lLast; | |
INT lInterval; | |
DWORD dwId; | |
}; | |
typedef CSharedPtr<TTimer> STimer; | |
public: | |
static CMap2<DWORD, STimer>& GetTimers() { static CMap2<DWORD, STimer> mapTimers; return mapTimers;} | |
static CJavascript** GetJs() { static CJavascript *js = NULL; return &js; } | |
static INT AuraCallNative(LPVOID ctx) | |
{ | |
CJavascript::CContext Context(ctx); | |
CEval::CEvalOperand opAux = CSdkEval::Execute( Context ); | |
if ( opAux.Is( CEval::CEvalOperand::eoNone ) ) | |
return Context.Return; | |
else if ( opAux.Is( CEval::CEvalOperand::eoNumber ) ) | |
return Context.Return.Set( opAux.GetFloat() ); | |
_ASSERT(0); | |
return CJavascript::CContext(ctx).Return.SetFalse(); | |
} | |
static INT CLowGrx_GrxGetAppSize(LPVOID ctx) | |
{ | |
CJavascript::CContext Context(ctx); | |
INT nWidth = 0, nHeight = 0; | |
CLowGrx::GrxGetAppSize( &nWidth, &nHeight ); | |
Context.Return.Set( _T("cx"), nWidth ); | |
Context.Return.Set( _T("cy"), nHeight ); | |
return Context.Return; | |
} | |
static INT CContainer_EnableProcessMessageHandler(LPVOID ctx) | |
{ | |
CJavascript::CContext Context(ctx); | |
_ASSERT( Context.Arguments.GetSize() == 1 && | |
Context.Arguments[0].GetType() == CJavascript::CArgument::TBoolean ); | |
if ( Context.Arguments[0].GetBoolean() ) | |
CContainer::SetProcessMessageHandler( CJsFunctions::WndMessageHandler ); | |
else | |
CContainer::SetProcessMessageHandler( NULL ); | |
return Context.Return; | |
} | |
static INT Include(LPVOID ctx) | |
{ | |
CJavascript::CContext Context(ctx); | |
_ASSERT( Context.Arguments.GetSize() == 1 && | |
Context.Arguments[0].GetType() == CJavascript::CArgument::TString ); | |
CString strPath = CContainer::GetPath( CString( _T("@scripts/") + Context.Arguments[0].GetString() ) ); | |
DWORD dwSize = 0; | |
LPVOID pData = CFile::GetData( (LPCTSTR)strPath, &dwSize ); | |
if ( pData ) | |
{ | |
CString strScript = CString((CHAR*)pData, dwSize); | |
CFile::FreeData( pData ); | |
CJavascript *pJs = *GetJs(); | |
_ASSERT( pJs ); | |
pJs->Compile( (LPCTSTR)strScript ); | |
return Context.Return.SetTrue(); | |
} | |
return Context.Return.SetFalse(); | |
} | |
static INT SetInterval( LPVOID ctx ) | |
{ | |
CJavascript::CContext Context(ctx); | |
_ASSERT( Context.Arguments.GetSize() == 2 && | |
Context.Arguments[0].GetType() == CJavascript::CArgument::TString && | |
Context.Arguments[1].GetType() == CJavascript::CArgument::TNumber ); | |
STimer timer( new TTimer() ); | |
timer->nShots = -1; | |
timer->strCall = Context.Arguments[0].GetString(); | |
timer->lLast = CLowTime::TimeGetTickApp(); | |
timer->lInterval = Context.Arguments[1].GetInteger(); | |
timer->dwId = 1000 + GetTimers().GetCount(); | |
GetTimers().SetAt( timer->dwId, timer ); | |
return Context.Return.Set( (INT)timer->dwId ); | |
} | |
static INT KillInterval( LPVOID ctx ) | |
{ | |
CJavascript::CContext Context(ctx); | |
_ASSERT( Context.Arguments.GetSize() == 1 && | |
Context.Arguments[0].GetType() == CJavascript::CArgument::TNumber); | |
STimer timer; | |
DWORD dwId = (DWORD)(Context.Arguments[0].GetInteger()); | |
GetTimers().Lookup( dwId, timer ); | |
_ASSERT( timer.Get() ); | |
if ( timer.Get() ) | |
GetTimers().RemoveKey( dwId ); | |
return 0; | |
} | |
static INT SetTimeout( LPVOID ctx ) | |
{ | |
CJavascript::CContext Context(ctx); | |
_ASSERT( Context.Arguments.GetSize() == 2 && | |
Context.Arguments[0].GetType() == CJavascript::CArgument::TString && | |
Context.Arguments[1].GetType() == CJavascript::CArgument::TNumber ); | |
STimer timer( new TTimer() ); | |
timer->nShots = 1; | |
timer->strCall = Context.Arguments[0].GetString(); | |
timer->lLast = CLowTime::TimeGetTickApp(); | |
timer->lInterval = Context.Arguments[1].GetInteger(); | |
timer->dwId = 1000 + GetTimers().GetCount(); | |
GetTimers().SetAt( timer->dwId, timer ); | |
return Context.Return.Set( (INT)timer->dwId ); | |
} | |
static void Assign(CJavascript& Js) | |
{ | |
Js.MapFunction( Include, _T("include") ); | |
Js.MapFunction( AuraCallNative, _T("AuraCallNative") ); | |
Js.MapFunction( CLowGrx_GrxGetAppSize, _T("CLowGrx_GrxGetAppSize") ); | |
Js.MapFunction( CContainer_EnableProcessMessageHandler, _T("CContainer_EnableProcessMessageHandler") ); | |
Js.MapFunction( SetInterval, _T("setInterval") ); | |
Js.MapFunction( KillInterval, _T("killInterval") ); | |
Js.MapFunction( SetTimeout, _T("setTimeout") ); | |
Js.MapFunction( KillInterval, _T("killTimeout") ); // killInterval = killTimeout | |
} | |
static void WndMessageHandler( LPMsg pMsg ) | |
{ | |
CJavascript *pJs = *GetJs(); | |
if ( !pMsg || pMsg->message != 0 || !pJs ) | |
return; | |
if ( GetTimers().GetCount() > 0 ) | |
{ | |
POSITION pos = GetTimers().GetStartPosition(); | |
INT lTime = CLowTime::TimeGetTickApp(); | |
while ( pos ) | |
{ | |
DWORD dwId; | |
STimer timer; | |
GetTimers().GetNextAssoc( pos, dwId, timer ); | |
if ( lTime >= timer->lLast + timer->lInterval ) | |
{ | |
pJs->Eval( timer->strCall ); | |
timer->lLast = lTime; | |
if ( timer->nShots > 0 ) | |
timer->nShots--; | |
if ( timer->nShots == 0 ) | |
GetTimers().RemoveKey( dwId ); | |
} | |
} | |
} | |
CString strTest = pJs->Eval( _T("( typeof(Aura) != 'undefined' && typeof(Aura.ProcessAppMessage) == 'function' )") ); | |
if ( strTest == _T("true") ) | |
{ | |
CString strMessage = CString::FormatInline( | |
_T("_temp = {message:%d, wParam:%d, lParam:%d};"), | |
pMsg->message, pMsg->wParam, pMsg->lParam ); | |
pJs->Eval( (LPCTSTR)strMessage ); | |
pJs->Eval( _T("_temp = Aura.ProcessAppMessage(_temp);") ); | |
CString strResult = pJs->Eval( _T("_temp") ); | |
if ( strResult != _T("false") && strResult != _T("undefined") ) | |
{ | |
pMsg->message = CStringConversion::ToInt(pJs->Eval( _T("_temp.message") )); | |
pMsg->lParam = CStringConversion::ToInt(pJs->Eval( _T("_temp.lParam") )); | |
pMsg->wParam = CStringConversion::ToInt(pJs->Eval( _T("_temp.wParam") )); | |
} | |
} | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include("aura.js") | |
//var testDuration = 60; // v sekundach | |
Aura.OnDestroy = OnDestroy; | |
Aura.PostMenuIniLoad = PostMenuIniLoad; | |
Aura.PostInitMainWindow = PostInitMainWindow; | |
Aura.ProcessAppMessage = ProcessAppMessage; | |
function OnDestroy() | |
{ | |
Io.DeleteFile('$(Root)/hopper.txt'); | |
} | |
function PostMenuIniLoad() | |
{ | |
Settings.MenuSet("menu.Main", "menu.Main.exit", "false"); | |
} | |
function PostInitMainWindow() | |
{ | |
Settings.Set('RuntimeSettings.m_strDebugMode', 'hopper'); | |
Settings.Set('RootSettings.m_strLanguage', 'english.lang'); | |
Io.CreateTextFile('$(Root)/hopper.txt', 'Hooper test started'); | |
CContainer.EnableProcessMessageHandler(true); | |
// setTimeout("CWnd.PostQuitMessage()", 10000); | |
} | |
var arrMessages = []; | |
var lLastMessage = 0; | |
var lStarted = 0; | |
function ProcessAppMessage(msg) | |
{ | |
// ak je message platna, nemenime ju | |
if ( msg.message != 0 ) | |
return; | |
// volny cyklus, naplnime msg | |
// mame uz nejake spravy prichystane? | |
if ( arrMessages.length > 0 ) | |
{ | |
var newmsg = arrMessages.pop(); | |
msg.message = newmsg.message; | |
msg.wParam = newmsg.wParam; | |
msg.lParam = newmsg.lParam; | |
return msg; | |
} | |
var lTime = CLowTime.TimeGetTickApp(); | |
/* | |
if ( lStarted == 0 ) | |
lStarted = lTime; | |
if ( lTime - lStarted > testDuration*1000 ) // XX sekund | |
{ | |
arrMessages.push({message:CWnd.WmQuit, wParam:0, lParam:0}); | |
return; | |
} | |
*/ | |
// nova sprava 10x za sekundu | |
if ( lLastMessage == 0 ) | |
lLastMessage = lTime; | |
if ( lTime - lLastMessage < 100 ) | |
return; | |
lLastMessage = lTime; | |
// prichystame spravu | |
var nRandom = CLowMath.MathRandom() % 100; | |
if ( nRandom < 5 ) // 5% - Left action button | |
{ | |
arrMessages.push({message:CWnd.WmKeyDown, wParam:CLowKeyb.VkAction1, lParam:1}); | |
arrMessages.push({message:CWnd.WmKeyUp, wParam:CLowKeyb.VkAction1, lParam:1}); | |
} else if ( nRandom < 7 ) // 2% - Right action button | |
{ | |
arrMessages.push({message:CWnd.WmKeyDown, wParam:CLowKeyb.VkAction2, lParam:1}); | |
arrMessages.push({message:CWnd.WmKeyUp, wParam:CLowKeyb.VkAction2, lParam:1}); | |
} else if ( nRandom < 12 ) // 5% - Mouse wheel | |
arrMessages.push({message:CWnd.WmMouseWheel, wParam:CLowMath.MathRandom()%180-90, lParam:0}); | |
else if ( nRandom < 20 ) | |
{ | |
var szScreen = CLowGrx.GrxGetAppSize(); | |
var cpMouseA = {x: CLowMath.MathRandom() % szScreen.cx, y: CLowMath.MathRandom() % szScreen.cy}; | |
var cpMouseB = {x: CLowMath.MathRandom() % szScreen.cx, y: CLowMath.MathRandom() % szScreen.cy}; | |
var cpMouse = cpMouseA; | |
arrMessages.push({message:CWnd.WmLButtonDown, lParam:MAKELONG(cpMouse.x, cpMouse.y), wParam:1}); | |
for (var i=1; i<10; i++) | |
{ | |
cpMouse.x = cpMouseA.x + (cpMouseB.x - cpMouseA.x)*i/10; | |
cpMouse.y = cpMouseA.y + (cpMouseB.y - cpMouseA.y)*i/10; | |
arrMessages.push({message:CWnd.WmMouseMove, lParam:MAKELONG(cpMouse.x, cpMouse.y), wParam:1}); | |
} | |
cpMouse = cpMouseB; | |
arrMessages.push({message:CWnd.WmLButtonUp, lParam:MAKELONG(cpMouse.x, cpMouse.y), wParam:1}); | |
} | |
else // 88% - Random mouse click | |
{ | |
var szScreen = CLowGrx.GrxGetAppSize(); | |
var cpMouse = {x: CLowMath.MathRandom() % szScreen.cx, y: CLowMath.MathRandom() % szScreen.cy}; | |
arrMessages.push({message:CWnd.WmLButtonDown, lParam:MAKELONG(cpMouse.x, cpMouse.y), wParam:1}); | |
arrMessages.push({message:CWnd.WmLButtonUp, lParam:MAKELONG(cpMouse.x, cpMouse.y), wParam:1}); | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment