diff options
Diffstat (limited to 'automation/source/testtool')
19 files changed, 7009 insertions, 0 deletions
diff --git a/automation/source/testtool/cmdstrm.cxx b/automation/source/testtool/cmdstrm.cxx new file mode 100644 index 000000000000..4f6d413f4280 --- /dev/null +++ b/automation/source/testtool/cmdstrm.cxx @@ -0,0 +1,470 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_automation.hxx" +#ifndef _KEYCOD_HXX //autogen +#include <vcl/keycod.hxx> +#endif +#include <basic/sbx.hxx> +#include <tools/stream.hxx> + +#include "cmdstrm.hxx" +#include "rcontrol.hxx" +#include "objtest.hxx" +#include "sttresid.hxx" +#include "svcommstream.hxx" +#include <basic/testtool.hrc> + +ControlDefLoad __READONLY_DATA CmdStream::arKeyCodes [] = +#include <keycodes.hxx> +CNames *CmdStream::pKeyCodes = NULL; + +ResMgr* SttResId::getSttResMgr() +{ + static ResMgr* pMgr = NULL; + if( ! pMgr ) + pMgr = CREATEVERSIONRESMGR( stt ); + return pMgr; +} + +CmdStream::CmdStream() +{ + pSammel = new SvMemoryStream(); + pCommStream = new SvCommStream( pSammel ); +} + +CmdStream::~CmdStream() +{ + delete pCommStream; + delete pSammel; +} + + +#define PUT_CHAR(ch) \ + USHORT nMCode = nModify + ch; \ + USHORT _Code = 1; \ + if ( (nMCode & 0xFF) == 0 ) \ + _Code |= 2; \ + if ( (nMCode >> 8) == 0 ) \ + _Code |= 4; \ + Result += (char) _Code; \ + Result += (char) ( nMCode & 0xFF ); \ + Result += (char) ( nMCode >> 8 ) + + +String CmdStream::WandleKeyEventString( String aKeys ) +{ + if ( !pKeyCodes ) + ReadFlatArray(arKeyCodes,pKeyCodes); + if ( !pKeyCodes ) + return aKeys; + + xub_StrLen nPos1 = 0; + while ( (nPos1 = aKeys.Search('<',nPos1)) != STRING_NOTFOUND) + { + xub_StrLen nPos2 = aKeys.Search('>',nPos1); + if ( nPos2 != STRING_NOTFOUND ) + { + String Work = aKeys.Copy(nPos1+1,nPos2-nPos1+1-2); + aKeys.Erase(nPos1,nPos2-nPos1+1); // Inclusive Spitze Klammern weg + String Result, Token; + USHORT nModify = 0; + while ( Work.Len() > 0 ) + { + Token = Work.GetToken(0,' '); + Work.Erase(0,Token.Len()+1); + ControlDef WhatName(Token,SmartId()); + USHORT nElement; + if (pKeyCodes->Seek_Entry(&WhatName,&nElement)) + { + USHORT nCode = (USHORT) pKeyCodes->GetObject(nElement)->pData->aUId.GetNum(); + if ( nCode >= KEY_SHIFT ) + nModify ^= nCode; + else + { + if ( ( nModify == 0 ) && + (((nCode & 0xFF00) == KEYGROUP_NUM) || + ((nCode & 0xFF00) == KEYGROUP_ALPHA) || + ( nCode == KEY_SPACE) || + ( nCode == KEY_ADD) || + ( nCode == KEY_SUBTRACT) || + ( nCode == KEY_MULTIPLY) || + ( nCode == KEY_DIVIDE) || + ( nCode == KEY_POINT) || + ( nCode == KEY_COMMA) || + ( nCode == KEY_LESS) || + ( nCode == KEY_GREATER) || + ( nCode == KEY_EQUAL) ) ) + { + switch ( nCode ) + { + case KEY_SPACE: Token = ' '; break; + case KEY_ADD: Token = '+'; break; + case KEY_SUBTRACT: Token = '-'; break; + case KEY_MULTIPLY: Token = '*'; break; + case KEY_DIVIDE: Token = '/'; break; + case KEY_POINT: Token = '.'; break; + case KEY_COMMA: Token = ','; break; + case KEY_LESS: Token = '<'; break; + case KEY_GREATER: Token = '>'; break; + case KEY_EQUAL: Token = '='; break; + default: +// if ( nModify == 0 ) +// Token.ToLower(); +// else +// Token.ToUpper(); + ; + } + Result += Token; + } + else + { + PUT_CHAR (nCode); + } + } + } + else + { + Result += '<'; + Result += Token; + Result += ' '; + Result += String( SttResId( S_INVALID_KEYCODE ) ); + Result += '>'; + } + } + aKeys.Insert(Result,nPos1); + nPos1 = nPos1 + Result.Len(); + } + else + nPos1 = aKeys.Len() + 1; + } + + return aKeys; +} + + +void CmdStream::WriteSortedParams( SbxArray* rPar, BOOL IsKeyString ) +{ + USHORT nParams = PARAM_NONE; + USHORT nNr1=0,nNr2=0,nNr3=0,nNr4=0; + comm_ULONG nLNr1=0; + String aString1,aString2; + BOOL bBool1=FALSE,bBool2=FALSE; + + if ( rPar ) + { + for ( USHORT i = 1; i < rPar->Count() ; i++) + { + switch (rPar->Get( i )->GetType()) + { + case SbxLONG: // alles immer als Short �bertragen + case SbxULONG: + case SbxLONG64: + case SbxULONG64: + case SbxDOUBLE: + case SbxINTEGER: + case SbxBYTE: + case SbxUSHORT: + case SbxINT: + case SbxUINT: + case SbxSINGLE: + if ( (nParams & PARAM_USHORT_1) == 0 ) + { + nParams |= PARAM_USHORT_1; + nNr1 = rPar->Get( i )->GetUShort(); + } + else if ( (nParams & PARAM_USHORT_2) == 0 ) + { + nParams |= PARAM_USHORT_2; + nNr2 = rPar->Get( i )->GetUShort(); + } + else if ( (nParams & PARAM_USHORT_3) == 0 ) + { + nParams |= PARAM_USHORT_3; + nNr3 = rPar->Get( i )->GetUShort(); + } + else if ( (nParams & PARAM_USHORT_4) == 0 ) + { + nParams |= PARAM_USHORT_4; + nNr4 = rPar->Get( i )->GetUShort(); + } + else + SbxBase::SetError( SbxERR_WRONG_ARGS ); + break; + case SbxOBJECT: // whenever a control is passed. TabPage, MenuBar + { + SbxProperty *pMember = NULL; + if ( rPar->Get( i )->ISA( SbxObject ) ) + pMember = ((SbxObject*)rPar->Get( i ))->GetDfltProperty(); + if ( pMember != NULL ) + { + if ( pMember->GetType() == SbxSTRING ) + { + if ( nParams & PARAM_STR_1 ) + if ( nParams & PARAM_STR_2 ) + SbxBase::SetError( SbxERR_WRONG_ARGS ); + else + { + nParams |= PARAM_STR_2; + aString2 = pMember->GetString(); + } + else + { + nParams |= PARAM_STR_1; + aString1 = pMember->GetString(); + } + break; + } + else if ( pMember->GetType() == SbxULONG ) + { + if ( nParams & PARAM_ULONG_1 ) + SbxBase::SetError( SbxERR_WRONG_ARGS ); + else + { + nParams |= PARAM_ULONG_1; + nLNr1 = pMember->GetULong(); + } + } + else + SbxBase::SetError( SbxERR_NAMED_NOT_FOUND ); + } + else + { + SbxBase::SetError( SbxERR_NAMED_NOT_FOUND ); + } + } + break; + case SbxSTRING: + case SbxCHAR: + if ( nParams & PARAM_STR_1 ) + if ( nParams & PARAM_STR_2 ) + SbxBase::SetError( SbxERR_WRONG_ARGS ); + else + { + nParams |= PARAM_STR_2; + aString2 = rPar->Get( i )->GetString(); + } + else + { + nParams |= PARAM_STR_1; + aString1 = rPar->Get( i )->GetString(); + } + break; + case SbxBOOL: + if ( nParams & PARAM_BOOL_1 ) + if ( nParams & PARAM_BOOL_2 ) + SbxBase::SetError( SbxERR_WRONG_ARGS ); + else + { + nParams |= PARAM_BOOL_2; + bBool2 = rPar->Get( i )->GetBool(); + } + else + { + nParams |= PARAM_BOOL_1; + bBool1 = rPar->Get( i )->GetBool(); + } + break; + default: + SbxBase::SetError( SbxERR_WRONG_ARGS ); + break; + } + } + } + Write (nParams); + if( nParams & PARAM_USHORT_1 ) Write( nNr1 ); + if( nParams & PARAM_USHORT_2 ) Write( nNr2 ); + if( nParams & PARAM_USHORT_3 ) Write( nNr3 ); + if( nParams & PARAM_USHORT_4 ) Write( nNr4 ); + if( nParams & PARAM_ULONG_1 ) Write( nLNr1 ); + if( nParams & PARAM_STR_1 ) Write( aString1, IsKeyString ); + if( nParams & PARAM_STR_2 ) Write( aString2, IsKeyString ); + if( nParams & PARAM_BOOL_1 ) Write( bBool1 ); + if( nParams & PARAM_BOOL_2 ) Write( bBool2 ); +} + +void CmdStream::GenCmdCommand( USHORT nNr, SbxArray* rPar ) +{ + Write(USHORT(SICommand)); + Write(nNr); + WriteSortedParams(rPar, (nNr & M_KEY_STRING) != 0 ); +} + +void CmdStream::GenCmdSlot( USHORT nNr, SbxArray* rPar ) +{ + Write(USHORT(SISlot)); + Write(nNr); + if (rPar) + { + USHORT nAnz = (rPar->Count()-1) >> 1; // Geteilt durch 2 + Write(nAnz); + BOOL bWriteUnoSlot = rPar->Get( 1 )->GetType() == SbxSTRING; + + for (USHORT n = 1 ; n <= nAnz ; n++) + { + /// #59513# nicht mehr ben�tigt +// ULONG nUserData = rPar->Get( 2*n-1 )->GetUserData(); +// rPar->Get( 2*n-1 )->SetUserData(ID_DoNothing); // Verhindert Ausf�hrung der Slots, die als Parameter �bergeben sind. + + if ( bWriteUnoSlot ) + Write(rPar->Get( 2*n-1 )->GetString()); + else + Write(rPar->Get( 2*n-1 )->GetUShort()); + switch (rPar->Get( 2*n )->GetType()) + { + case SbxINTEGER: + case SbxBYTE: + case SbxUSHORT: + case SbxINT: + case SbxUINT: + case SbxSINGLE: + if ( !bWriteUnoSlot ) + Write( (USHORT)BinUSHORT ); + Write(rPar->Get( 2*n )->GetUShort()); + break; + case SbxLONG: + case SbxULONG: + case SbxLONG64: + case SbxULONG64: + case SbxDOUBLE: + if ( !bWriteUnoSlot ) + Write( (USHORT)BinULONG ); + Write(rPar->Get( 2*n )->GetULong()); + break; + case SbxSTRING: + case SbxCHAR: + if ( !bWriteUnoSlot ) + Write( (USHORT)BinString); + Write((String)rPar->Get( 2*n )->GetString()); // Cast f�r OS/2 + break; + case SbxBOOL: + if ( !bWriteUnoSlot ) + Write( (USHORT)BinBool); + Write(rPar->Get( 2*n )->GetBool()); + break; + default: + SbxBase::SetError( SbxERR_WRONG_ARGS ); + break; + } + + /// #59513# nicht mehr ben�tigt ( siehe oben ) +// rPar->Get( 2*n-1 )->SetUserData(nUserData); // Und wieder zur�cksetzen, so da� auch alles sauber ist. + } + } + else + Write(USHORT(0)); +} + +void CmdStream::GenCmdUNOSlot( const String &aURL ) +{ + Write( USHORT(SIUnoSlot) ); +/* Write( USHORT(0) ); // Hier wird im Office die SID_OPENURL Eingetragen. + // Dies mu� nat�rlich im Office hart verdratet werden und nicht hier, + // da sich die ID ja mal �ndern kann. + + // Da auch die ID f�r das PoolItem im Office entnommen werden mu� hier also kein PoolItem + // gesendet werden. + + Write( USHORT(0) ); // Anzahl PoolItems + + // Stattdessen wird noch eine extra String gesendet, der dann Officeseitig in ein + // SfxStringItem mit entsprechender ID gewandelt wird. + Write( aURL ); // String f�r das PoolItem*/ + + Write( aURL ); // Die UNO URL eben +} + +void CmdStream::GenCmdControl( comm_ULONG nUId, USHORT nMethodId, SbxArray* rPar ) +{ + Write(USHORT(SIControl)); + Write(nUId); + Write(nMethodId); + WriteSortedParams(rPar, (nMethodId & M_KEY_STRING) != 0 ); +} + +void CmdStream::GenCmdControl( String aUId, USHORT nMethodId, SbxArray* rPar ) +{ + Write(USHORT(SIStringControl)); + Write(aUId); + Write(nMethodId); + WriteSortedParams(rPar, (nMethodId & M_KEY_STRING) != 0 ); +} + +void CmdStream::GenCmdFlow( USHORT nArt ) +{ + Write(USHORT(SIFlow)); + Write(nArt); + Write(USHORT(PARAM_NONE)); // Typ der folgenden Parameter +} + +void CmdStream::GenCmdFlow( USHORT nArt, USHORT nNr1 ) +{ + Write(USHORT(SIFlow)); + Write(nArt); + Write(USHORT(PARAM_USHORT_1)); // Typ der folgenden Parameter + Write(nNr1); +} + +void CmdStream::GenCmdFlow( USHORT nArt, comm_ULONG nNr1 ) +{ + Write(USHORT(SIFlow)); + Write(nArt); + Write(USHORT(PARAM_ULONG_1)); // Typ der folgenden Parameter + Write(nNr1); +} + +void CmdStream::GenCmdFlow( USHORT nArt, String aString1 ) +{ + Write(USHORT(SIFlow)); + Write(nArt); + Write(USHORT(PARAM_STR_1)); // Typ der folgenden Parameter + Write(aString1); +} + +void CmdStream::Write( String aString, BOOL IsKeyString ) +{ + if ( IsKeyString ) + Write( WandleKeyEventString( aString ), FALSE ); + else + Write( aString.GetBuffer(), aString.Len() ); +} + +SvMemoryStream* CmdStream::GetStream() +{ + return pSammel; +} + +void CmdStream::Reset( comm_ULONG nSequence ) +{ + delete pCommStream; + delete pSammel; + pSammel = new SvMemoryStream(); + pCommStream = new SvCommStream( pSammel ); + GenCmdFlow (F_Sequence,nSequence); +} + diff --git a/automation/source/testtool/cmdstrm.hxx b/automation/source/testtool/cmdstrm.hxx new file mode 100644 index 000000000000..857517483280 --- /dev/null +++ b/automation/source/testtool/cmdstrm.hxx @@ -0,0 +1,78 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _CMDSTRM_HXX +#define _CMDSTRM_HXX + +#include <objtest.hxx> +#include <testapp.hxx> +#include "cmdbasestream.hxx" + +class CmdStream : public CmdBaseStream +{ +public: + CmdStream(); + ~CmdStream(); + + void WriteSortedParams( SbxArray* rPar, BOOL IsKeyString = FALSE ); + + void GenCmdCommand( USHORT nNr, SbxArray* rPar ); + + void GenCmdSlot( USHORT nNr, SbxArray* rPar ); + + void GenCmdUNOSlot( const String &aURL ); + + void GenCmdControl( comm_ULONG nUId, USHORT nMethodId, SbxArray* rPar ); + void GenCmdControl( String aUId, USHORT nMethodId, SbxArray* rPar ); + + + void GenCmdFlow( USHORT nArt ); + void GenCmdFlow( USHORT nArt, USHORT nNr1 ); + void GenCmdFlow( USHORT nArt, comm_ULONG nNr1 ); + void GenCmdFlow( USHORT nArt, String aString1 ); + + void Reset(comm_ULONG nSequence); + + SvMemoryStream* GetStream(); + + static CNames *pKeyCodes; // Namen der Sondertasten MOD1, F1, LEFT ... + static ControlDefLoad __READONLY_DATA arKeyCodes []; + +private: + String WandleKeyEventString( String aKeys ); // Nutzt pKeyCodes. <RETURN> <SHIFT LEFT LEFT> + + using CmdBaseStream::Write; + void Write( comm_USHORT nNr ){CmdBaseStream::Write( nNr );} + void Write( comm_ULONG nNr ){CmdBaseStream::Write( nNr );} + void Write( const comm_UniChar* aString, comm_USHORT nLenInChars ){CmdBaseStream::Write( aString, nLenInChars );} + void Write( comm_BOOL bBool ){CmdBaseStream::Write( bBool );} +// new + void Write( String aString, BOOL IsKeyString = FALSE ); + + SvMemoryStream *pSammel; +}; + +#endif diff --git a/automation/source/testtool/comm_bas.cxx b/automation/source/testtool/comm_bas.cxx new file mode 100644 index 000000000000..e35448c012c5 --- /dev/null +++ b/automation/source/testtool/comm_bas.cxx @@ -0,0 +1,442 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_automation.hxx" + +#include "comm_bas.hxx" +#include <tools/errcode.hxx> +#include <basic/sbxobj.hxx> +#include <basic/sbx.hxx> +#ifndef __SBX_SBXVARIABLE_HXX //autogen +#include <basic/sbxvar.hxx> +#endif +#include <vcl/svapp.hxx> +#include <automation/communi.hxx> +#ifndef _BASIC_TTRESHLP_HXX +#include <basic/ttstrhlp.hxx> +#endif + +// Der CommunicationManager hat folgende Elemente: +// 1) Properties: +// Keine +// 2) Methoden: +// CommunicationLink StartCommunication( Host, Port ) +// StopAllCommunication // Alle Kommunikation wird abgebrochen +// BOOL IsCommunicationRunning // Läuft noch irgendwas +// String GetMyName Der eigene Name +// BOOL IsLinkValid( CommunicationLink ) // Ist dieser Link noch gültig +// SetCommunicationEventHandler( String ) // Diese Funktion wird aufgerufen bei jedem Event + +// Der CommunicationLink hat folgende Elemente: +// 1) Properties: +// Keine +// 2) Methoden: +// StopCommunication Die Kommunikation wird abgebrochen +// String GetMyName Der eigene Name +// String GetHostName Der Name des Anderen +// Send(String ) String an den Partner schicken +// String GetString Ergebnis des letzten Empfangs + + +// Diese Implementation ist ein Beispiel fuer eine tabellengesteuerte +// Version, die sehr viele Elemente enthalten kann. Die Elemente werden +// je nach Bedarf aus der Tabelle in das Objekt uebernommen. + +// Das nArgs-Feld eines Tabelleneintrags ist wie folgt verschluesselt: + +#define _ARGSMASK 0x00FF // Bis zu 255 Argumente +#define _RWMASK 0x0F00 // Maske fuer R/W-Bits +#define _TYPEMASK 0xF000 // Maske fuer den Typ des Eintrags + +#define _READ 0x0100 // kann gelesen werden +#define _BWRITE 0x0200 // kann as Lvalue verwendet werden +#define _LVALUE _BWRITE // kann as Lvalue verwendet werden +#define _READWRITE 0x0300 // beides +#define _OPT 0x0400 // TRUE: optionaler Parameter +#define _METHOD 0x1000 // Masken-Bit fuer eine Methode +#define _PROPERTY 0x2000 // Masken-Bit fuer eine Property +#define _COLL 0x4000 // Masken-Bit fuer eine Collection + // Kombination von oberen Bits: +#define _FUNCTION 0x1100 // Maske fuer Function +#define _LFUNCTION 0x1300 // Maske fuer Function, die auch als Lvalue geht +#define _ROPROP 0x2100 // Maske Read Only-Property +#define _WOPROP 0x2200 // Maske Write Only-Property +#define _RWPROP 0x2300 // Maske Read/Write-Property +#define _COLLPROP 0x4100 // Maske Read-Collection-Element + +#define COLLNAME "Elements" // Name der Collection, hier mal hart verdrahtet + + + +CommunicationWrapper::Methods CommunicationWrapper::aManagerMethods[] = { +// Neue Kommunikation aufbauen +{ "StartCommunication", SbxEMPTY, &CommunicationWrapper::MStartCommunication, 2 | _FUNCTION }, + // Zwei Named Parameter + { "Host", SbxSTRING, NULL, 0 }, + { "Port", SbxLONG, NULL, 0 }, +// Alle Kommunikation wird abgebrochen +{ "StopAllCommunication", SbxEMPTY, &CommunicationWrapper::MStopAllCommunication, 0 | _FUNCTION }, +// Läuft noch irgendwas +{ "IsCommunicationRunning", SbxBOOL, &CommunicationWrapper::MIsCommunicationRunning, 0 | _FUNCTION }, +// Hostname als FQDN erfragen +{ "GetMyName", SbxSTRING, &CommunicationWrapper::MGetMyName, 0 | _FUNCTION }, +// Abfragen ob der Link überhaupt noch gültig ist +{ "IsLinkValid", SbxBOOL, &CommunicationWrapper::MIsLinkValid, 1 | _FUNCTION }, + // Ein Named Parameter + { "Link", SbxOBJECT, NULL, 0 }, +// Dieser Handler wird dauernd gerufen +{ "SetCommunicationEventHandler", SbxEMPTY, &CommunicationWrapper::MSetCommunicationEventHandler, 1 | _FUNCTION }, + // Ein Named Parameter + { "FuncName", SbxSTRING, NULL, 0 }, + +{ NULL, SbxNULL, NULL, -1 }}; // Tabellenende + + + + + + +CommunicationWrapper::Methods CommunicationWrapper::aLinkMethods[] = { +// Die Kommunikation wird abgebrochen +{ "StopCommunication", SbxEMPTY, &CommunicationWrapper::LStopCommunication, 0 | _FUNCTION }, +// Der eigene Name +{ "GetMyName", SbxSTRING, &CommunicationWrapper::LGetMyName, 0 | _FUNCTION }, +// Der Name des Anderen +{ "GetHostName", SbxSTRING, &CommunicationWrapper::LGetHostName, 0 | _FUNCTION }, +// String an den Partner schicken +{ "Send", SbxEMPTY, &CommunicationWrapper::LSend, 1 | _FUNCTION }, + // Ein Named Parameter + { "SendString", SbxSTRING, NULL, 0 }, +// Ergebnis des letzten Empfangs +{ "GetString", SbxSTRING, &CommunicationWrapper::LGetString, 0 | _FUNCTION }, + +{ NULL, SbxNULL, NULL, -1 }}; // Tabellenende + + + + + +// Konstruktor für den Manager +CommunicationWrapper::CommunicationWrapper( const String& rClass ) : SbxObject( rClass ) +, m_pLink( NULL ) +, m_bIsManager( TRUE ) +, m_bCatchOpen( FALSE ) +, m_pNewLink( NULL ) +{ +// SetName( CUniString("Manager") ); + m_pMethods = &aManagerMethods[0]; + m_pManager = new CommunicationManagerClientViaSocket; + m_pManager->SetConnectionOpenedHdl( LINK( this, CommunicationWrapper, Open ) ); + m_pManager->SetConnectionClosedHdl( LINK( this, CommunicationWrapper, Close ) ); + m_pManager->SetDataReceivedHdl( LINK( this, CommunicationWrapper, Data ) ); +} + +// Konstruktor für den Link +CommunicationWrapper::CommunicationWrapper( CommunicationLink *pThisLink ) : SbxObject( CUniString("Link") ) +, m_pLink( pThisLink ) +, m_bIsManager( FALSE ) +, m_bCatchOpen( FALSE ) +, m_pNewLink( NULL ) +{ + m_pMethods = &aLinkMethods[0]; + m_pManager = (CommunicationManagerClientViaSocket*)pThisLink->GetCommunicationManager(); +} + +// Destruktor +CommunicationWrapper::~CommunicationWrapper() +{ + if ( m_bIsManager ) + delete m_pManager; +} + + +// Suche nach einem Element: +// Hier wird linear durch die Methodentabelle gegangen, bis eine +// passende Methode gefunden wurde. +// Wenn die Methode/Property nicht gefunden wurde, nur NULL ohne +// Fehlercode zurueckliefern, da so auch eine ganze Chain von +// Objekten nach der Methode/Property befragt werden kann. + +SbxVariable* CommunicationWrapper::Find( const String& rName, SbxClassType t ) +{ + // Ist das Element bereits vorhanden? + SbxVariable* pRes = SbxObject::Find( rName, t ); + if( !pRes && t != SbxCLASS_OBJECT ) + { + // sonst suchen + Methods* p = m_pMethods; + short nIndex = 0; + BOOL bFound = FALSE; + while( p->nArgs != -1 ) + { + if( rName.CompareIgnoreCaseToAscii( p->pName ) == COMPARE_EQUAL ) + { + bFound = TRUE; break; + } + nIndex += ( p->nArgs & _ARGSMASK ) + 1; + p = m_pMethods + nIndex; + } + if( bFound ) + { + // Args-Felder isolieren: + short nAccess = ( p->nArgs & _RWMASK ) >> 8; + short nType = ( p->nArgs & _TYPEMASK ); + String aName( p->pName, RTL_TEXTENCODING_ASCII_US ); + SbxClassType eCT = SbxCLASS_OBJECT; + if( nType & _PROPERTY ) + eCT = SbxCLASS_PROPERTY; + else if( nType & _METHOD ) + eCT = SbxCLASS_METHOD; + pRes = Make( aName, eCT, p->eType ); + // Wir setzen den Array-Index + 1, da ja noch andere + // Standard-Properties existieren, die auch aktiviert + // werden muessen. + pRes->SetUserData( nIndex + 1 ); + pRes->SetFlags( nAccess ); + } + } + return pRes; +} + +// Aktivierung eines Elements oder Anfordern eines Infoblocks + +void CommunicationWrapper::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCT, + const SfxHint& rHint, const TypeId& rHT ) +{ + const SbxHint* pHint = PTR_CAST(SbxHint,&rHint); + if( pHint ) + { + SbxVariable* pVar = pHint->GetVar(); + SbxArray* pPar = pVar->GetParameters(); + USHORT nIndex = (USHORT) pVar->GetUserData(); + // kein Index: weiterreichen! + if( nIndex ) + { + ULONG t = pHint->GetId(); + if( t == SBX_HINT_INFOWANTED ) + pVar->SetInfo( GetInfo( (short) pVar->GetUserData() ) ); + else + { + BOOL bWrite = FALSE; + if( t == SBX_HINT_DATACHANGED ) + bWrite = TRUE; + if( t == SBX_HINT_DATAWANTED || bWrite ) + { + // Parameter-Test fuer Methoden: + USHORT nPar = m_pMethods[ --nIndex ].nArgs & 0x00FF; + // Element 0 ist der Returnwert + if( ( !pPar && nPar ) + || ( pPar && pPar->Count() != nPar+1 ) ) + SetError( SbxERR_WRONG_ARGS ); + // Alles klar, man kann den Call ausfuehren + else + { + (this->*(m_pMethods[ nIndex ].pFunc))( pVar, pPar, bWrite ); + } + } + } + } + SbxObject::SFX_NOTIFY( rBC, rBCT, rHint, rHT ); + } +} + +// Zusammenbau der Infostruktur fuer einzelne Elemente + +SbxInfo* CommunicationWrapper::GetInfo( short nIdx ) +{ + Methods* p = &m_pMethods[ nIdx ]; + // Wenn mal eine Hilfedatei zur Verfuegung steht: + // SbxInfo* pInfo = new SbxInfo( Hilfedateiname, p->nHelpId ); + SbxInfo* pRetInfo = new SbxInfo; + short nPar = p->nArgs & _ARGSMASK; + for( short i = 0; i < nPar; i++ ) + { + p++; + String aName( p->pName, RTL_TEXTENCODING_ASCII_US ); + USHORT nIFlags = ( p->nArgs >> 8 ) & 0x03; + if( p->nArgs & _OPT ) + nIFlags |= SBX_OPTIONAL; + pRetInfo->AddParam( aName, p->eType, nIFlags ); + } + return pRetInfo; +} + + +//////////////////////////////////////////////////////////////////////////// + +// Hilfsmethoden für den Manager + +IMPL_LINK( CommunicationWrapper, Open, CommunicationLink*, pLink ) +{ + if ( m_bCatchOpen ) + m_pNewLink = pLink; + else + Events( CUniString("Open"), pLink ); + return 1; +} + +IMPL_LINK( CommunicationWrapper, Close, CommunicationLink*, pLink ) +{ + Events( CUniString("Close"), pLink ); + return 1; +} + +IMPL_LINK( CommunicationWrapper, Data, CommunicationLink*, pLink ) +{ + Events( CUniString("Data"), pLink ); + return 1; +} + +void CommunicationWrapper::Events( String aType, CommunicationLink* pLink ) +{ + if ( m_aEventHandlerName.Len() ) + { + SbxArrayRef pPar = new SbxArray( SbxVARIANT ); + pPar->Put( new SbxVariable( SbxSTRING ), 1 ); + pPar->Get( 1 )->PutString( aType ); + + pPar->Put( new SbxVariable( SbxOBJECT ), 2 ); + pPar->Get( 2 )->PutObject( new CommunicationWrapper( pLink ) ); + + Call( m_aEventHandlerName, pPar ); + } + else + delete pLink->GetServiceData(); // Stream wegschmeissen um nicht zu blockieren +} + + +//////////////////////////////////////////////////////////////////////////// + +// Properties und Methoden legen beim Get (bPut = FALSE) den Returnwert +// im Element 0 des Argv ab; beim Put (bPut = TRUE) wird der Wert aus +// Element 0 gespeichert. + +// Die Methoden: + +// Manager +void CommunicationWrapper::MStartCommunication( SbxVariable* pVar, SbxArray* pPar, BOOL /*bWrite*/ ) +{ // CommunicationLink StartCommunication( Host, Port ) + m_bCatchOpen = TRUE; + if ( m_pManager->StartCommunication( ByteString( pPar->Get( 1 )->GetString(), RTL_TEXTENCODING_UTF8 ), pPar->Get( 2 )->GetULong() ) ) + { + while ( !m_pNewLink ) + GetpApp()->Reschedule(); + m_bCatchOpen = FALSE; + CommunicationWrapper *pNewLinkWrapper = new CommunicationWrapper( m_pNewLink ); + m_pNewLink = NULL; + pVar->PutObject( pNewLinkWrapper ); + } + +} + +void CommunicationWrapper::MStopAllCommunication( SbxVariable* /*pVar*/, SbxArray* /*pPar*/, BOOL /*bWrite*/ ) +{ // StopAllCommunication // Alle Kommunikation wird abgebrochen + m_pManager->StopCommunication(); +} + +void CommunicationWrapper::MIsCommunicationRunning( SbxVariable* pVar, SbxArray* /*pPar*/, BOOL /*bWrite*/ ) +{ // BOOL IsCommunicationRunning // Läuft noch irgendwas + pVar->PutBool( m_pManager->IsCommunicationRunning() ); +} + +void CommunicationWrapper::MGetMyName( SbxVariable* pVar, SbxArray* /*pPar*/, BOOL /*bWrite*/ ) +{ // String GetMyName Der eigene Name + pVar->PutString( UniString( m_pManager->GetMyName( CM_FQDN ), RTL_TEXTENCODING_UTF8 ) ); +} + +void CommunicationWrapper::MIsLinkValid( SbxVariable* pVar, SbxArray* pPar, BOOL /*bWrite*/ ) +{ // BOOL IsLinkValid( CommunicationLink ) // Ist dieser Link noch gültig + CommunicationWrapper *pWrapper = (CommunicationWrapper*)(pPar->Get( 1 )->GetObject()); + pVar->PutBool( m_pManager->IsLinkValid( pWrapper->GetCommunicationLink() ) ); +} + +void CommunicationWrapper::MSetCommunicationEventHandler( SbxVariable* /*pVar*/, SbxArray* pPar, BOOL /*bWrite*/ ) +{ // SetCommunicationEventHandler( String ) // Diese Funktion wird aufgerufen bei jedem Event + m_aEventHandlerName = pPar->Get( 1 )->GetString(); +} + + + + + +// Link +void CommunicationWrapper::LStopCommunication( SbxVariable* /*pVar*/, SbxArray* /*pPar*/, BOOL /*bWrite*/ ) +{ // StopCommunication Die Kommunikation wird abgebrochen + m_pLink->StopCommunication(); +} + +void CommunicationWrapper::LGetMyName( SbxVariable* pVar, SbxArray* /*pPar*/, BOOL /*bWrite*/ ) +{ // String GetMyName Der eigene Name + pVar->PutString( UniString( m_pLink->GetMyName( CM_FQDN ), RTL_TEXTENCODING_UTF8 ) ); +} + +void CommunicationWrapper::LGetHostName( SbxVariable* pVar, SbxArray* /*pPar*/, BOOL /*bWrite*/ ) +{ // String GetHostName Der Name des Anderen + pVar->PutString( UniString( m_pLink->GetCommunicationPartner( CM_FQDN ), RTL_TEXTENCODING_UTF8 ) ); +} + +void CommunicationWrapper::LSend( SbxVariable* /*pVar*/, SbxArray* pPar, BOOL /*bWrite*/ ) +{ // Send(String ) String an den Partner schicken + SvStream *pSendStream = m_pLink->GetBestCommunicationStream(); + String aSendString = pPar->Get( 1 )->GetString(); + pSendStream->WriteByteString( aSendString, RTL_TEXTENCODING_UTF8 ); + m_pLink->TransferDataStream( pSendStream ); + delete pSendStream; +} + +void CommunicationWrapper::LGetString( SbxVariable* pVar, SbxArray* /*pPar*/, BOOL /*bWrite*/ ) +{ // String GetString Ergebnis des letzten Empfangs + SvStream *pReceiveStream = m_pLink->GetServiceData(); + if ( pReceiveStream ) + { + ULONG nLength = pReceiveStream->Seek( STREAM_SEEK_TO_END ); + pReceiveStream->Seek( STREAM_SEEK_TO_BEGIN ); + char *pBuffer = new char[nLength]; + pReceiveStream->Read( pBuffer, nLength ); + String aReceive( + pBuffer, sal::static_int_cast< xub_StrLen >( nLength ), + RTL_TEXTENCODING_UTF8 ); + delete [] pBuffer; + pVar->PutString( aReceive ); + delete pReceiveStream; + } + else + pVar->PutString( UniString() ); +} + + + +// Die Factory legt unser Objekte an. + +SbxObject* CommunicationFactory::CreateObject( const String& rClass ) +{ + if( rClass.CompareIgnoreCaseToAscii( "CommunicationManager" ) == COMPARE_EQUAL ) + return new CommunicationWrapper( rClass ); + return NULL; +} + diff --git a/automation/source/testtool/comm_bas.hxx b/automation/source/testtool/comm_bas.hxx new file mode 100644 index 000000000000..d39f0895eefd --- /dev/null +++ b/automation/source/testtool/comm_bas.hxx @@ -0,0 +1,120 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _COMM_BAS_HXX +#define _COMM_BAS_HXX + +#include <basic/sbxfac.hxx> +#ifndef __SBX_SBXVARIABLE_HXX //autogen +#include <basic/sbxvar.hxx> +#endif +#include <basic/sbxobj.hxx> + +class CommunicationManagerClientViaSocket; +class CommunicationLink; + +class CommunicationWrapper : public SbxObject // Einer für Manager und Links +{ + // Definition eines Tabelleneintrags. Dies wird hier gemacht, + // da dadurch die Methoden und Properties als private deklariert + // werden koennen. +#if defined ( ICC ) || defined ( HPUX ) || defined ( C50 ) || defined ( C52 ) +public: +#endif + typedef void( CommunicationWrapper::*pMeth ) + ( SbxVariable* pThis, SbxArray* pArgs, BOOL bWrite ); +#if defined ( ICC ) || defined ( HPUX ) +private: +#endif + + struct Methods { + const char* pName; // Name des Eintrags + SbxDataType eType; // Datentyp + pMeth pFunc; // Function Pointer + short nArgs; // Argumente und Flags + }; + static Methods aManagerMethods[]; // Methodentabelle + static Methods aLinkMethods[]; // Methodentabelle + Methods *m_pMethods; // Aktuelle Methodentabelle + + // Methoden + // Manager + void MStartCommunication( SbxVariable* pVar, SbxArray* pPar, BOOL bWrite ); + void MStopAllCommunication( SbxVariable* pVar, SbxArray* pPar, BOOL bWrite ); + void MIsCommunicationRunning( SbxVariable* pVar, SbxArray* pPar, BOOL bWrite ); + void MGetMyName( SbxVariable* pVar, SbxArray* pPar, BOOL bWrite ); + void MIsLinkValid( SbxVariable* pVar, SbxArray* pPar, BOOL bWrite ); + void MSetCommunicationEventHandler( SbxVariable* pVar, SbxArray* pPar, BOOL bWrite ); + + // Link + void LStopCommunication( SbxVariable* pVar, SbxArray* pPar, BOOL bWrite ); + void LGetMyName( SbxVariable* pVar, SbxArray* pPar, BOOL bWrite ); + void LGetHostName( SbxVariable* pVar, SbxArray* pPar, BOOL bWrite ); + void LSend( SbxVariable* pVar, SbxArray* pPar, BOOL bWrite ); + void LGetString( SbxVariable* pVar, SbxArray* pPar, BOOL bWrite ); + + // Interne Member und Methoden + CommunicationManagerClientViaSocket *m_pManager; + CommunicationLink *m_pLink; + BOOL m_bIsManager; // Ist es kein Manager, so ist es ein Link + + // Kram für Manager + DECL_LINK( Open, CommunicationLink* ); + DECL_LINK( Close, CommunicationLink* ); + DECL_LINK( Data, CommunicationLink* ); + void Events( String aType, CommunicationLink* pLink ); + BOOL m_bCatchOpen; + CommunicationLink *m_pNewLink; + String m_aEventHandlerName; + + using SbxVariable::GetInfo; + // Infoblock auffuellen + SbxInfo* GetInfo( short nIdx ); + + // Broadcaster Notification + virtual void SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, + const SfxHint& rHint, const TypeId& rHintType ); +public: + CommunicationWrapper( const String& ); + CommunicationWrapper( CommunicationLink *pThisLink ); + ~CommunicationWrapper(); + // Suchen eines Elements + virtual SbxVariable* Find( const String&, SbxClassType ); + + CommunicationLink* GetCommunicationLink() { return m_pLink; } +}; + + +// Die dazugehoerige Factory: + +class CommunicationFactory : public SbxFactory +{ +public: + virtual SbxObject* CreateObject( const String& ); +}; + +#endif diff --git a/automation/source/testtool/cretstrm.cxx b/automation/source/testtool/cretstrm.cxx new file mode 100644 index 000000000000..a6850b1c2cc4 --- /dev/null +++ b/automation/source/testtool/cretstrm.cxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_automation.hxx" +#ifndef _CRetStream_HXX +#include "cretstrm.hxx" +#endif +#include <tools/debug.hxx> +#include "rcontrol.hxx" +#include "svcommstream.hxx" + + +SV_IMPL_REF(SbxBase) + +CRetStream::CRetStream(SvStream *pIn) +{ + pSammel = pIn; + delete pCommStream; + pCommStream = new SvCommStream( pSammel ); +} + +CRetStream::~CRetStream() +{ + delete pCommStream; +} + +void CRetStream::Read ( String &aString ) +{ + comm_UniChar* pStr; + USHORT nLenInChars; + CmdBaseStream::Read( pStr, nLenInChars ); + + aString = String( pStr, nLenInChars ); + delete [] pStr; +} + +void CRetStream::Read( SbxValue &aValue ) +{ + *pSammel >> nId; + if (nId != BinSbxValue) + { + DBG_ERROR1( "Falscher Typ im Stream: Erwartet SbxValue, gefunden :%hu", nId ); + } + SbxBaseRef xBase = SbxBase::Load( *pSammel ); + if ( IS_TYPE( SbxValue, xBase ) ) + aValue = *PTR_CAST( SbxValue, &xBase ); +} + diff --git a/automation/source/testtool/cretstrm.hxx b/automation/source/testtool/cretstrm.hxx new file mode 100644 index 000000000000..75229bb32cb7 --- /dev/null +++ b/automation/source/testtool/cretstrm.hxx @@ -0,0 +1,55 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _CRETSTRM_HXX +#define _CRETSTRM_HXX + +#include <tools/stream.hxx> +#include <basic/sbxvar.hxx> + +#include "cmdbasestream.hxx" + +class CRetStream : public CmdBaseStream +{ + SvStream *pSammel; + USHORT nId; + +public: + CRetStream( SvStream *pIn ); + ~CRetStream(); + + using CmdBaseStream::Read; + void Read ( comm_USHORT &nNr ){CmdBaseStream::Read ( nNr );} + void Read ( comm_ULONG &nNr ){CmdBaseStream::Read ( nNr );} +// void Read ( comm_UniChar* &aString, comm_USHORT &nLenInChars ){CmdBaseStream::Read ( aString, nLenInChars );} + virtual void Read ( SmartId* &pId ){CmdBaseStream::Read ( pId );} + void Read ( comm_BOOL &bBool ){CmdBaseStream::Read ( bBool );} +// new + void Read( String &aString ); + void Read( SbxValue &aValue ); +}; + +#endif diff --git a/automation/source/testtool/filter.pl b/automation/source/testtool/filter.pl new file mode 100644 index 000000000000..8f45073b0934 --- /dev/null +++ b/automation/source/testtool/filter.pl @@ -0,0 +1,125 @@ +#!/usr/bin/perl +#************************************************************************* +#* +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************/ + +$debug = ""; +$ctrue = 1; +$cfalse = 0; +# reads a block +# Parameter: FileHandle +# list of Regular Expressions which terminate the block. +# for '#ifdef' block would then be ("^#else\$", "^#endif\$") + +sub read_block { + + local($file) = @_; + print "reading block '$file' ",scalar(@_),"\n" if $debug; + while ( <$file> ) { + chop; + s/\s*$//; # remove trailing whitespaces + s/^\s*//; # remove leading whitespaces + print "Input : \"$_\"\n" if $debug; + s/\/\/.*//; # Remove line comment + s/\/\*.*?\*\///g; # remove comments within one line + s/\s+/ /g; # Change all whitespace into a single blank + s/ *$//; # Remove whitespace at end + s/^# /#/; # Change # <command> to #<command> + + + @line = split(/ /,$_,3); + + $_ = $line[0]; + if ( $_ && /^#/ ) { # Line starts with '#' -> preprocessor command + print "proccessing line: @line\n" if $debug; + if (/#define/) + { + if ( $line[1] =~ /^$namefilter/ ) + { + $mykey = $line[1]; + $mykey =~ s/^$namefilter//; + $count += 1; + print OUT "$mykey ", $line[2], "\n"; + print OUT2 "\t{ \"$mykey\", ", $line[2] ," },\n"; + } + } + } + } + print "Leaving read_block at the end\n" if $debug; +} + +# Read a file. +# first parameter ist the filename +sub read_file { + + local ($filename,$file) = @_; + $file++; # String increment + local $TempFileName = $basename."/".$filename; + print "reading file $TempFileName as $file\n" if $debug; + open($file, $TempFileName) || die "error: Could not open file $TempFileName. "; + + &read_block($file); # read data + close($file); + print "done reading $filename\n" if $debug; +} + +# main starts here + +$basename = "."; +$basename = $ARGV[0] if defined($ARGV[0]); + +$filename = "app.hrc"; +$filename = $ARGV[1] if defined($ARGV[1]); + + +$outfilebase = $filename; +$outfilebase =~ s/\.[^.]+$//; # cut off suffix +$outfilebase = $ARGV[2] if defined($ARGV[2]); + + +$namefilter = $ARGV[3] if defined($ARGV[3]); + + +print "Generating $outfilebase:\n"; + +$count = 0; + +open(OUT,">$outfilebase"); +open(OUT2,">$outfilebase.hxx"); +print OUT2 "\{\n"; + +&read_file ($filename,"f00"); + +print OUT2 "\t{ \"\" ,0 }\n\};\n"; + +close(OUT); +close(OUT2); + +if ( $count == 0 ) +{ + die "Error: No Entries Found generating \"$outfilebase.hxx\". Testtool will not work!" +} + diff --git a/automation/source/testtool/httprequest.cxx b/automation/source/testtool/httprequest.cxx new file mode 100644 index 000000000000..1e45fd1fc976 --- /dev/null +++ b/automation/source/testtool/httprequest.cxx @@ -0,0 +1,239 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_automation.hxx" + +#include <stdio.h> +#include "httprequest.hxx" +#include <vos/socket.hxx> +#include <tools/debug.hxx> + + +void HttpRequest::Init() +{ + nResultId = 0; + aHeader.Erase(); + aContentType.Erase(); + delete pStream; + pStream = NULL; +} + +HttpRequest::HttpRequest() +: nStatus( HTTP_INIT ) +, nResultId( 0 ) +, pStream( NULL ) +{} + +HttpRequest::~HttpRequest() +{ + delete pStream; + pStream = NULL; +} + +void HttpRequest::SetRequest( ByteString aHost, ByteString aPath, USHORT nPort ) +{ + nStatus = HTTP_REQUEST_SET; + Init(); + aRequestHost = aHost; + aRequestPath = aPath; + nRequestPort = nPort; +} + +void HttpRequest::SetProxy( ByteString aHost, USHORT nPort ) +{ + nStatus = HTTP_REQUEST_SET; + Init(); + aProxyHost = aHost; + nProxyPort = nPort; +} + +BOOL HttpRequest::Execute() +{ + nStatus = HTTP_REQUEST_PENDING; + Init(); + + // Open channel to standard redir host + NAMESPACE_VOS(OInetSocketAddr) aConnectAddr; + + if ( aProxyHost.Len() ) + { + aConnectAddr.setAddr( rtl::OUString( UniString( aProxyHost, RTL_TEXTENCODING_UTF8 ) ) ); + aConnectAddr.setPort( nProxyPort ); + } + else + { + aConnectAddr.setAddr( rtl::OUString( UniString( aRequestHost, RTL_TEXTENCODING_UTF8 ) ) ); + aConnectAddr.setPort( nRequestPort ); + } + + TimeValue aTV; + aTV.Seconds = 10; // Warte 10 Sekunden + aTV.Nanosec = 0; + + pOutSocket = new NAMESPACE_VOS(OConnectorSocket)(); + if ( pOutSocket->connect( aConnectAddr, &aTV ) == NAMESPACE_VOS(ISocketTypes::TResult_Ok) ) + { +// pOutSocket->setTcpNoDelay( 1 ); + } + else + { + delete pOutSocket; + nStatus = HTTP_REQUEST_ERROR; + return FALSE; + } + + + SendString( pOutSocket, "GET " ); + if ( aProxyHost.Len() ) + { + //GET http://staroffice-doc.germany.sun.com/cgi-bin/htdig/binarycopy.sh?CopyIt=++CopyIt++ HTTP/1.0 + SendString( pOutSocket, "http://" ); + SendString( pOutSocket, aRequestHost ); + SendString( pOutSocket, ":" ); + SendString( pOutSocket, ByteString::CreateFromInt32( nRequestPort ) ); + SendString( pOutSocket, aRequestPath ); + SendString( pOutSocket, " HTTP/1.0\n" ); + + SendString( pOutSocket, "Proxy-Connection: Keep-Alive\n" ); + } + else + { + //GET /cgi-bin/htdig/binarycopy.sh?CopyIt=++CopyIt++ HTTP/1.0 + SendString( pOutSocket, aRequestPath ); + SendString( pOutSocket, " HTTP/1.0\n" ); + + SendString( pOutSocket, "Connection: Keep-Alive\n" ); + } + + SendString( pOutSocket, "User-Agent: Mozilla/4.7 [de] (Linux; I)" ); + SendString( pOutSocket, "Host: " ); + SendString( pOutSocket, aRequestHost ); + // Terminate with empty line + SendString( pOutSocket, "\n\n" ); + + + +#define BUFFRE_SIZE 0x10000 // 64K Buffer + char* pBuffer = new char[ BUFFRE_SIZE ]; + + BOOL bWasError = ( nStatus != HTTP_REQUEST_PENDING ); + + ULONG nDataRead; + pStream = new SvMemoryStream( 0x10000, 0x10000 ); + while ( !bWasError ) + { + bWasError |= ( BUFFRE_SIZE != ( nDataRead = pOutSocket->read( pBuffer, BUFFRE_SIZE ) ) ); + + pStream->Write( pBuffer, nDataRead ); + } + + delete [] pBuffer; + pOutSocket->shutdown(); + pOutSocket->close(); + + pStream->Seek( 0 ); + + ByteString aLine; + BOOL bInsideHeader = TRUE; + while ( bInsideHeader ) + { + pStream->ReadLine( aLine ); + if ( !aLine.Len() ) + bInsideHeader = FALSE; + else + { + if ( IsItem( "HTTP/", aLine ) ) + nResultId = (USHORT)aLine.GetToken( 1, ' ' ).ToInt32(); + if ( IsItem( "Content-Type:", aLine ) ) + { + aContentType = aLine.Copy( 13 ); + aContentType.EraseLeadingAndTrailingChars(); + } + aHeader += aLine; + aHeader += "\n"; + } + } + + if ( nStatus == HTTP_REQUEST_PENDING ) + { + nStatus = HTTP_REQUEST_DONE; + return TRUE; + } + else + { + nStatus = HTTP_REQUEST_ERROR; + return FALSE; + } +} +/* +HTTP/1.1 200 OK +Date: Tue, 22 Jan 2002 14:16:20 GMT +Server: Apache/1.3.14 (Unix) (SuSE/Linux) mod_throttle/3.0 mod_layout/1.0 mod_f +astcgi/2.2.2 mod_jk +Set-Cookie2: JSESSIONID=ffkpgb7tm1;Version=1;Discard;Path="/bugtracker" +Set-Cookie: JSESSIONID=ffkpgb7tm1;Path=/bugtracker +Servlet-Engine: Tomcat Web Server/3.2.1 (JSP 1.1; Servlet 2.2; Java 1.3.0; Linux + 2.4.0-4GB i386; java.vendor=Sun Microsystems Inc.) +Connection: close +Content-Type: text/xml; charset=ISO-8859-1 + */ +void HttpRequest::SendString( vos::OStreamSocket* pSocket , ByteString aText ) +{ + if ( nStatus == HTTP_REQUEST_PENDING ) + pSocket->write( aText.GetBuffer(), aText.Len() ); +} + +BOOL HttpRequest::IsItem( ByteString aItem, ByteString aLine ) +{ + return aItem.Match( aLine ) == STRING_MATCH; +} + + +void HttpRequest::Abort() +{ + if ( pOutSocket ) + { + nStatus = HTTP_REQUEST_ERROR; + pOutSocket->shutdown(); + pOutSocket->close(); + } +} + + + + +SvMemoryStream* HttpRequest::GetBody() +{ + return pStream; +} + +USHORT HttpRequest::GetStatus() +{ + return nStatus; +} + diff --git a/automation/source/testtool/httprequest.hxx b/automation/source/testtool/httprequest.hxx new file mode 100644 index 000000000000..44234239b81f --- /dev/null +++ b/automation/source/testtool/httprequest.hxx @@ -0,0 +1,85 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _HTTPREQUEST_HXX_ +#define _HTTPREQUEST_HXX_ + +#define HTTP_INIT 0 +#define HTTP_REQUEST_SET 1 +#define HTTP_REQUEST_PENDING 2 +#define HTTP_REQUEST_DONE 3 +#define HTTP_REQUEST_ERROR 4 + +#include <tools/string.hxx> +#include <tools/stream.hxx> + +namespace vos +{ + class OStreamSocket; + class OConnectorSocket; +} + +class HttpRequest +{ + ByteString aRequestPath; + ByteString aRequestHost; + USHORT nRequestPort; + ByteString aProxyHost; + USHORT nProxyPort; + + USHORT nStatus; + vos::OConnectorSocket *pOutSocket; + + ByteString aHeader; + USHORT nResultId; + ByteString aContentType; + SvMemoryStream* pStream; + + void SendString( vos::OStreamSocket* pSocket, ByteString aText ); + BOOL IsItem( ByteString aItem, ByteString aLine ); + void Init(); +public: + HttpRequest(); + ~HttpRequest(); + + void SetRequest( ByteString aHost, ByteString aPath, USHORT nPort ); + void SetProxy( ByteString aHost, USHORT nPort ); + + BOOL Execute(); + void Abort(); + + ByteString GetHeader() { return aHeader; } + SvMemoryStream* GetBody(); + + ByteString GetContentType() { return aContentType; } + USHORT GetResultId() { return nResultId; } + + USHORT GetStatus(); + +}; + +#endif diff --git a/automation/source/testtool/makefile.mk b/automation/source/testtool/makefile.mk new file mode 100644 index 000000000000..db8464130c1b --- /dev/null +++ b/automation/source/testtool/makefile.mk @@ -0,0 +1,109 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=automation +TARGET=testtool + +# --- Settings ------------------------------------------------------------ + +.INCLUDE : settings.mk + +# --- Allgemein ------------------------------------------------------------ + +OBJFILES = \ + $(OBJ)$/cmdstrm.obj \ + $(OBJ)$/cretstrm.obj \ + $(OBJ)$/objtest.obj \ + $(OBJ)$/tcommuni.obj \ + $(OBJ)$/comm_bas.obj \ + $(OBJ)$/httprequest.obj \ + + +EXCEPTIONSFILES= \ + $(OBJ)$/tcommuni.obj \ + $(OBJ)$/cmdstrm.obj \ + $(OBJ)$/objtest.obj + +HXXFILES = $(INCCOM)$/keycodes.hxx \ + $(INCCOM)$/classes.hxx \ + $(INCCOM)$/r_cmds.hxx \ + $(INCCOM)$/res_type.hxx + +.IF "$(GUI)" == "WNT" +OBJFILES += $(OBJ)$/sysdir_win.obj +OBJFILES += $(OBJ)$/registry_win.obj +.ENDIF +# --- Targets ------------------------------------------------------------ + +.INCLUDE : target.mk + + +$(OBJFILES) : $(HXXFILES) +$(HXXFILES) : $(MISC)$/xfilter.pl + + +$(INCCOM)$/keycodes.hxx : $(SOLARVERSION)$/$(INPATH)$/inc$(UPDMINOREXT)$/vcl$/keycodes.hxx \ + $(MISC)$/xfilter.pl + $(PERL) $(MISC)$/xfilter.pl $(SOLARVERSION)$/$(INPATH)$/inc$(UPDMINOREXT) vcl$/keycodes.hxx $(INCCOM)$/keycodes KEY_ + +$(INCCOM)$/classes.hxx : ..$/inc$/rcontrol.hxx \ + $(MISC)$/xfilter.pl + $(PERL) $(MISC)$/xfilter.pl ..$/inc rcontrol.hxx $(INCCOM)$/classes M_ + +$(INCCOM)$/r_cmds.hxx : ..$/inc$/rcontrol.hxx \ + $(MISC)$/xfilter.pl + $(PERL) $(MISC)$/xfilter.pl ..$/inc rcontrol.hxx $(INCCOM)$/r_cmds RC_ + +$(INCCOM)$/res_type.hxx : $(SOLARVERSION)$/$(INPATH)$/inc$(UPDMINOREXT)$/tools$/wintypes.hxx \ + $(MISC)$/xfilter.pl + $(PERL) $(MISC)$/xfilter.pl $(SOLARVERSION)$/$(INPATH)$/inc$(UPDMINOREXT) tools$/wintypes.hxx $(INCCOM)$/res_type WINDOW_ + + + +$(MISC)$/xfilter.pl : filter.pl + tr -d "\015" < filter.pl > $(MISC)$/xfilter.pl + chmod 664 $(MISC)$/xfilter.pl + + + +.IF "$(GUI)"=="UNX" +INIFILESUFFIX=rc +BRANDPATH=none +.ELIF "$(GUI)"=="WNT" || "$(GUI)"=="OS2" +INIFILESUFFIX=.ini +BRANDPATH=.. +.END + +$(BIN)$/testtool$(INIFILESUFFIX): testtool.ini + $(SED) -e s/$(EMQ)!INIFILESUFFIX$(EMQ)!/$(INIFILESUFFIX)/ \ + -e s/$(EMQ)!BRANDPATH$(EMQ)!/$(BRANDPATH)/ < $< > $@ + +ALLTAR: \ + $(BIN)$/testtool$(INIFILESUFFIX) + diff --git a/automation/source/testtool/objtest.cxx b/automation/source/testtool/objtest.cxx new file mode 100644 index 000000000000..2361361f277f --- /dev/null +++ b/automation/source/testtool/objtest.cxx @@ -0,0 +1,4268 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_automation.hxx" + +/*#include <com/sun/star/devtools/XIServerProxy.hpp> +#include <com/sun/star/devtools/XInformationClient.hpp> +using namespace com::sun::star::devtools; +*/ +#ifdef OS2 +#define INCL_DOS +//#include <vcl/sysdep.hxx> +#ifndef _SVPM_H +#include <svpm.h> +#endif +#endif + +#include "sysdir_win.hxx" +#include "registry_win.hxx" +#include "sttresid.hxx" +#include <osl/file.hxx> +#ifndef _MSGBOX_HXX //autogen +#include <vcl/msgbox.hxx> +#endif +#ifndef _SOUND_HXX //autogen +#include <vcl/sound.hxx> +#endif +#include <tools/config.hxx> +#ifndef _APP_HXX //autogen +#include <vcl/svapp.hxx> +#endif +#include <svtools/stringtransfer.hxx> +#include <svl/brdcst.hxx> +//#ifndef _SBXCLASS_HXX //autogen +#include <basic/sbx.hxx> +//#endif +#include <com/sun/star/uno/Any.hxx> +#ifndef _COM_SUN_STAR_FRAME_XDESKTOP_HXX_ +#include <com/sun/star/frame/XDesktop.hpp> +#endif +#include <comphelper/processfactory.hxx> +#include <com/sun/star/bridge/XBridgeFactory.hpp> +#include <com/sun/star/connection/XConnector.hpp> +#include <com/sun/star/connection/XConnection.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/uno/XNamingService.hpp> + +#include <cppuhelper/servicefactory.hxx> + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::frame; +using namespace com::sun::star::bridge; +using namespace com::sun::star::connection; +using namespace rtl; + + +#include <svtools/svmedit.hxx> + +#ifdef UNX +#include <unistd.h> // readlink +#include <errno.h> +#endif + +#include <basic/sbuno.hxx> + +//#include <basic/basrid.hxx> +#include <basic/basicrt.hxx> +#ifndef _BASIC_TTRESHLP_HXX +#include <basic/ttstrhlp.hxx> +#endif +#include "tcommuni.hxx" +#include "comm_bas.hxx" +#include <cretstrm.hxx> + +#include "objtest.hxx" +#include "rcontrol.hxx" + +#include <basic/testtool.hrc> +#include <basic/ttmsg.hrc> + +#include <basic/mybasic.hxx> +#include <basic/testtool.hxx> +#include <basic/sbstar.hxx> + +#include <algorithm> + +#ifndef SBX_VALUE_DECL_DEFINED +#define SBX_VALUE_DECL_DEFINED +SV_DECL_REF(SbxValue) +#endif +SV_IMPL_REF(SbxValue) + +static CommunicationFactory aComManFac; + +#define cMyDelim ' ' +#define P_FEHLERLISTE pFehlerListe +#define KEEP_SEQUENCES 100 // Keep Names of last 100 Calls + + +ControlDefLoad __READONLY_DATA Controls::arClasses [] = +#include "classes.hxx" +CNames *Controls::pClasses = NULL; + +ControlDefLoad __READONLY_DATA TestToolObj::arR_Cmds [] = +#include "r_cmds.hxx" +CNames *TestToolObj::pRCommands = NULL; +CErrors *TestToolObj::pFehlerListe = NULL; // Hier werden die Fehler des Testtools gespeichert + + +DBG_NAME( ControlItem ) +DBG_NAME( ControlDef ) + +ControlItem::ControlItem( const sal_Char *Name, SmartId aUIdP ) +{ +DBG_CTOR(ControlItem,0); + InitData(); + pData->Kurzname.AssignAscii( Name ); + pData->aUId = aUIdP; +} + +ControlItem::ControlItem( const String &Name, SmartId aUIdP ) +{ +DBG_CTOR(ControlItem,0); + InitData(); + pData->Kurzname = Name; + pData->aUId = aUIdP; +} + +/*ControlItem::ControlItem( const String &Name, const String &URL, const URLType aType ) +{ +DBG_CTOR(ControlItem,0); + InitData(); + pData->Kurzname = Name; + pData->aURL = URL; + pData->nUId = aType; +} + +ControlItem::ControlItem( const String &Name, const String &URL, const ULONG nUId ) +{ +DBG_CTOR(ControlItem,0); + InitData(); + pData->Kurzname = Name; + pData->aURL = URL; + pData->nUId = nUId; +} + +ControlItem::ControlItem( const char *Name, const String &URL, const ULONG nUId ) +{ +DBG_CTOR(ControlItem,0); + InitData(); + pData->Kurzname.AssignAscii( Name ); + pData->aURL = URL; + pData->nUId = nUId; +} */ + + +ControlItem::ControlItem( ControlData *pDataP ) +{ +DBG_CTOR(ControlItem,0); + pData = pDataP; +} + +ControlSon::~ControlSon() +{ + if (pSons) + { + delete pSons; + pSons = NULL; + } +} + +ControlItemSon::ControlItemSon(const String &Name, SmartId aUIdP ) +: ControlItem( Name, aUIdP ) +{} + +/*ControlItemSon::ControlItemSon(const String &Name, const String &URL, const URLType aType ) +: ControlItem( Name, URL, aType ) +{} + +ControlItemSon::ControlItemSon(const String &Name, const String &URL, const ULONG nUId ) +: ControlItem( Name, URL, nUId ) +{} + +ControlItemSon::ControlItemSon(const char *Name, const String &URL, const ULONG nUId ) +: ControlItem( Name, URL, nUId ) +{}*/ + + + +BOOL ControlDef::operator < (const ControlItem &rPar) +{ + return pData->Kurzname.CompareIgnoreCaseToAscii(rPar.pData->Kurzname) == COMPARE_LESS; +} + +BOOL ControlDef::operator == (const ControlItem &rPar) +{ + return pData->Kurzname.CompareIgnoreCaseToAscii(rPar.pData->Kurzname) == COMPARE_EQUAL; +} + +void ControlDef::Write( SvStream &aStream ) +{ + if ( pSons ) + aStream.WriteByteString( String('*').Append( pData->Kurzname ), RTL_TEXTENCODING_UTF8 ); + else + aStream.WriteByteString( pData->Kurzname, RTL_TEXTENCODING_UTF8 ); + aStream << ((USHORT)pData->aUId.HasNumeric()); + if ( pData->aUId.HasString() ) + aStream.WriteByteString( pData->aUId.GetStr(), RTL_TEXTENCODING_UTF8 ); + else + aStream << static_cast<comm_ULONG>(pData->aUId.GetNum()); //GetNum() ULONG != comm_ULONG on 64bit + if ( pSons ) + for ( USHORT i = 0 ; pSons->Count() > i ; i++ ) + ((ControlDef*)(*pSons)[i])->Write(aStream); +} + +ControlDef::ControlDef(const String &Name, SmartId aUIdP ) +: ControlItemSon( Name, aUIdP) +{ + DBG_CTOR(ControlDef,0); +} + +/*ControlDef::ControlDef(const String &Name, const String &URL, const URLType aType ) +: ControlItemSon( Name, URL, aType ) +{ + DBG_CTOR(ControlDef,0); +} */ + +ControlDef::ControlDef(const String &aOldName, const String &aNewName, ControlDef *pOriginal, BOOL bWithSons ) +: ControlItemSon("", pOriginal->pData->aUId) +{ + DBG_CTOR(ControlDef,0); + if ( pOriginal->pData->Kurzname == aOldName ) + pData->Kurzname = aNewName; + else + pData->Kurzname = pOriginal->pData->Kurzname; + + if ( bWithSons && pOriginal->pSons ) + { + pSons = new CNames(); + for ( USHORT i = 0; i < pOriginal->pSons->Count() ; i++) + { + ControlDef *pNewDef; + pNewDef = new ControlDef( aOldName, aNewName, pOriginal->SonGetObject(i) ,TRUE ); + if (! SonInsert(pNewDef)) + { + DBG_ERROR("Name Doppelt im CopyConstructor. Neuer Name = Controlname!!"); + delete pNewDef; + } + } + + } + else + pSons = NULL; +} + +BOOL ControlItemUId::operator < (const ControlItem &rPar) +{ + return pData->aUId < rPar.pData->aUId; +} + +BOOL ControlItemUId::operator == (const ControlItem &rPar) +{ + return pData->aUId == rPar.pData->aUId; +} + +SV_IMPL_OP_PTRARR_SORT( CNames, ControlItem* ) + +void CRevNames::Insert( String aName, SmartId aUId, ULONG nSeq ) +{ + ControlItem *pRN = new ReverseName(aName,aUId,nSeq); + USHORT nPos; + if ( Seek_Entry(pRN,&nPos) ) + DeleteAndDestroy(nPos); + + if ( !CNames::C40_PTR_INSERT( ControlItem, pRN) ) + { + DBG_ERROR("Interner Fehler beim Speichern der Lokalen KurzNamen"); + delete pRN; + } + +} + +String CRevNames::GetName( SmartId aUId ) +{ + ReverseName *pRN = new ReverseName(UniString(),aUId,0); + USHORT nPos; + BOOL bSeekOK = Seek_Entry(pRN,&nPos); + + delete pRN; + if ( bSeekOK ) + return GetObject(nPos)->pData->Kurzname; + else + { + if ( aUId.Matches( UID_ACTIVE ) ) + return CUniString("Active"); + else + return GEN_RES_STR1( S_NAME_NOT_THERE, aUId.GetText() ); + } +} + +void CRevNames::Invalidate ( ULONG nSeq ) +{ + USHORT i; + for (i = 0; i < Count() ;) + { + if (((ReverseName*)GetObject(i))->LastSequence < nSeq) + DeleteAndDestroy(i); + else + i++; + } +} + + +SV_IMPL_PTRARR(CErrors, ErrorEntry*) + + +SbxTransportMethod::SbxTransportMethod( SbxDataType DT ) +: SbxMethod(CUniString("Dummy"),DT) +{ + nValue = 0; +} + + +TestToolObj::TestToolObj( String aName, String aFilePath ) // Interner Aufruf +: SbxObject( aName ) +, bUseIPC(FALSE) +, bReturnOK(TRUE) +, nSequence(KEEP_SEQUENCES) +, ProgPath() +, IsBlock(FALSE) +, SingleCommandBlock(TRUE) +, m_pControls(NULL) +, m_pNameKontext(NULL) +, m_pSIds(NULL) +, m_pReverseSlots(NULL) +, m_pReverseControls(NULL) +, m_pReverseControlsSon(NULL) +, m_pReverseUIds(NULL) +, pCommunicationManager(NULL) +, aDialogHandlerName() +, nWindowHandlerCallLevel(0) +, nIdleCount(0) +{ + pImpl = new ImplTestToolObj; + pImpl->ProgParam = String(); + pImpl->aFileBase = DirEntry(aFilePath); +// pImpl->aLogFileBase = DirEntry(); + pImpl->aHIDDir = DirEntry(aFilePath); + pImpl->bIsStart = FALSE; + pImpl->pMyBasic = NULL; + + pImpl->aServerTimeout = Time(0,1,00); // 1:00 Minuten fest + InitTestToolObj(); +} + +TestToolObj::TestToolObj( String aName, MyBasic* pBas ) // Aufruf im Testtool +: SbxObject( aName ) +, bUseIPC(TRUE) +, bReturnOK(TRUE) +, nSequence(KEEP_SEQUENCES) +, ProgPath() +, IsBlock(FALSE) +, SingleCommandBlock(TRUE) +, m_pControls(NULL) +, m_pNameKontext(NULL) +, m_pSIds(NULL) +, m_pReverseSlots(NULL) +, m_pReverseControls(NULL) +, m_pReverseControlsSon(NULL) +, m_pReverseUIds(NULL) +, pCommunicationManager(NULL) +, aDialogHandlerName() +, nWindowHandlerCallLevel(0) +, nIdleCount(0) +{ + pImpl = new ImplTestToolObj; + pImpl->ProgParam = String(); + pImpl->bIsStart = FALSE; + pImpl->pMyBasic = pBas; + + LoadIniFile(); + InitTestToolObj(); + + pCommunicationManager = new CommunicationManagerClientViaSocketTT(); + pCommunicationManager->SetDataReceivedHdl( LINK( this, TestToolObj, ReturnResultsLink )); +} + +void TestToolObj::LoadIniFile() // Laden der IniEinstellungen, die durch den ConfigDialog ge�ndert werden k�nnen +{ +#define GETSET(aVar, KeyName, Dafault) \ + { \ + ByteString __##aVar##__; \ + __##aVar##__ = aConf.ReadKey(KeyName); \ + if ( !__##aVar##__.Len() ) \ + { \ + __##aVar##__ = Dafault; \ + aConf.WriteKey(KeyName, __##aVar##__); \ + } \ + aVar = UniString( __##aVar##__, RTL_TEXTENCODING_UTF8 );\ + } + +#define NEWOLD( NewKey, OldKey ) \ + { \ + ByteString aValue; \ + if ( ( (aValue = aConf.ReadKey( OldKey )).Len() ) && !aConf.ReadKey( NewKey ).Len() ) \ + aConf.WriteKey( NewKey, aValue ); \ + } + + + Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") )); + aConf.SetGroup("Misc"); + ByteString aCurrentProfile = aConf.ReadKey( "CurrentProfile", "Path" ); + aConf.SetGroup( aCurrentProfile ); + + NEWOLD( "BaseDir", "Basisverzeichnis" ) + String aFB; + GETSET( aFB, "BaseDir", "" ); + pImpl->aFileBase = DirEntry(aFB); + + // remove old keys + if ( aConf.ReadKey("KeyCodes + Classes").Len() != 0 || + aConf.ReadKey("KeyCodes + Classes + Res_Type").Len() != 0 ) + { + aConf.DeleteKey("KeyCodes + Classes + Res_Type"); + aConf.DeleteKey("KeyCodes + Classes"); + } + + NEWOLD( "LogBaseDir", "LogBasisverzeichnis" ) + String aLFB; + GETSET( aLFB, "LogBaseDir", ByteString( aFB, RTL_TEXTENCODING_UTF8 ) ); + pImpl->aLogFileBase = DirEntry(aLFB); + + NEWOLD( "HIDDir", "HIDVerzeichnis" ) + String aHID; + GETSET( aHID, "HIDDir", "" ); + pImpl->aHIDDir = DirEntry(aHID); + + + aConf.SetGroup("Misc"); + + String aST; + GETSET( aST, "ServerTimeout", ByteString::CreateFromInt64(Time(0,0,45).GetTime()) ); // 45 Sekunden Initial + pImpl->aServerTimeout = Time(ULONG(aST.ToInt64())); + + String aSOSE; + aCurrentProfile = aConf.ReadKey( "CurrentProfile", "Misc" ); + aConf.SetGroup( aCurrentProfile ); + GETSET( aSOSE, "StopOnSyntaxError", "0" ); + pImpl->bStopOnSyntaxError = aSOSE.EqualsAscii("1"); + + + aConf.SetGroup("GUI Platform"); + + String aGP; + ByteString abGP; +#ifdef WNT + abGP.Append( "501" ); // WinXP +#elif defined SOLARIS && defined SPARC + abGP.Append( "01" ); // Solaris SPARC +#elif defined SCO + abGP.Append( "02" ); // SCO UNIX +#elif defined LINUX && defined INTEL + abGP.Append( "03" ); // Linux +#elif defined AIX + abGP.Append( "04" ); +#elif defined SOLARIS && defined INTEL + abGP.Append( "05" ); // Solaris x86 +#elif defined HPUX + abGP.Append( "07" ); +#elif defined FREEBSD + abGP.Append( "08" ); +#elif defined MACOSX + abGP.Append( "12" ); +#elif defined LINUX && defined PPC + abGP.Append( "13" ); +#elif defined NETBSD + abGP.Append( "14" ); +#elif defined LINUX && defined X86_64 + abGP.Append( "15" ); // Linux x86-64 +#elif defined LINUX && defined SPARC + abGP.Append( "16" ); // Linux SPARC +#elif defined OS2 + abGP.Append( "17" ); +#elif defined LINUX && defined MIPS + abGP.Append( "18" ); // Linux MIPS +#elif defined LINUX && defined ARM + abGP.Append( "19" ); // Linux ARM +#elif defined LINUX && defined IA64 + abGP.Append( "20" ); // Linux ia64 +#elif defined LINUX && defined S390 + abGP.Append( "21" ); // Linux S390 +#elif defined LINUX && defined HPPA + abGP.Append( "22" ); // Linux PA-RISC +#elif defined LINUX && defined AXP + abGP.Append( "23" ); // Linux ALPHA +#else +#error ("unknown platform. please request an ID for your platform on qa/dev") +#endif + GETSET( aGP, "Current", abGP ); + +// #i68804# Write default Communication section to testtoolrc/.ini +// this is not fastest but too keep defaultsettings in one place in the code + GetHostConfig(); + GetTTPortConfig(); + GetUnoPortConfig(); +} + +#define MAKE_TT_KEYWORD( cName, aType, aResultType, nID ) \ +{ \ + SbxVariableRef pMeth; \ + pMeth = Make( CUniString(cName), aType, aResultType ); \ + pMeth->SetUserData( nID ); \ +} + +// SetUserData muß irgendwas sein, sonst wird es im Find rausgefiltert!!! +#define MAKE_USHORT_CONSTANT(cName, nValue) \ + { \ + SbxProperty *pVal = new SbxProperty( CUniString( cName) , SbxINTEGER ); \ + pVal->PutInteger( nValue ) ; \ + pVal->SetUserData( 32000 ); \ + Insert( pVal ); \ + } + +#define RTLNAME "@SBRTL" // copied from basic/source/classes/sb.cxx + +void TestToolObj::InitTestToolObj() +{ + pImpl->nNumBorders = 0; // F�r Profiling mit k�stchen + + pImpl->nMinRemoteCommandDelay = 0; + pImpl->nMaxRemoteCommandDelay = 0; + pImpl->bDoRemoteCommandDelay = FALSE; + + pImpl->bLnaguageExtensionLoaded= FALSE; + pImpl->pTTSfxBroadcaster = NULL; + + pImpl->nErrorCount = 0; + pImpl->nWarningCount = 0; + pImpl->nQAErrorCount = 0; + pImpl->nIncludeFileWarningCount = 0; + + pImpl->xErrorList = new SbxDimArray( SbxSTRING ); + pImpl->xWarningList = new SbxDimArray( SbxSTRING ); + pImpl->xQAErrorList = new SbxDimArray( SbxSTRING ); + pImpl->xIncludeFileWarningList = new SbxDimArray( SbxSTRING ); + + pImpl->nTestCaseLineNr = 0; + + pImpl->bEnableQaErrors = TRUE; + pImpl->bDebugFindNoErrors = FALSE; + + pImpl->pChildEnv = new Environment; + + if (!pFehlerListe) + pFehlerListe = new CErrors; // Vor allem anderen. Wer weiss, wer alles einen Fehler ausl�st. + + In = new CmdStream(); + + pShortNames = new CRevNames; + + pImpl->pHttpRequest = NULL; + +// overwrite standard "wait" method, cause we can do better than that!! +// Insert Object into SbiStdObject but change listening. + SbxVariable* pRTL = pImpl->pMyBasic->Find( CUniString(RTLNAME), SbxCLASS_DONTCARE ); + SbxObject* pRTLObject = PTR_CAST( SbxObject, pRTL ); + if ( pRTLObject ) + { + SbxVariableRef pWait; + pWait = pRTLObject->Make( CUniString("Wait"), SbxCLASS_METHOD, SbxNULL ); + pWait->SetUserData( ID_Wait ); + // change listener here + pRTLObject->EndListening( pWait->GetBroadcaster(), TRUE ); + StartListening( pWait->GetBroadcaster(), TRUE ); + } + else + { + DBG_ERROR("Testtool: Could not replace Wait method"); + } + + MAKE_TT_KEYWORD( "Kontext", SbxCLASS_METHOD, SbxNULL, ID_Kontext ); + MAKE_TT_KEYWORD( "GetNextError", SbxCLASS_VARIABLE, SbxVARIANT, ID_GetError ); + MAKE_TT_KEYWORD( "Start", SbxCLASS_METHOD, SbxSTRING, ID_Start ); +// pMeth = Make( "Kill", SbxCLASS_METHOD, SbxNULL ); +// pMeth->SetUserData( ID_Kill ); + /* pMeth = Make( "TestReset", SbxCLASS_METHOD, SbxNULL ); + pMeth->SetUserData( ID_Reset );*/ + MAKE_TT_KEYWORD( "Use", SbxCLASS_METHOD, SbxNULL, ID_Use ); + MAKE_TT_KEYWORD( "StartUse", SbxCLASS_METHOD, SbxNULL, ID_StartUse ); + MAKE_TT_KEYWORD( "FinishUse", SbxCLASS_METHOD, SbxNULL, ID_FinishUse ); + + MAKE_TT_KEYWORD( "CaseLog", SbxCLASS_METHOD, SbxNULL, ID_CaseLog ); + MAKE_TT_KEYWORD( "ExceptLog", SbxCLASS_METHOD, SbxNULL, ID_ExceptLog ); + MAKE_TT_KEYWORD( "PrintLog", SbxCLASS_METHOD, SbxNULL, ID_PrintLog ); + MAKE_TT_KEYWORD( "WarnLog", SbxCLASS_METHOD, SbxNULL, ID_WarnLog ); + MAKE_TT_KEYWORD( "ErrorLog", SbxCLASS_METHOD, SbxNULL, ID_ErrorLog ); + MAKE_TT_KEYWORD( "QAErrorLog", SbxCLASS_METHOD, SbxNULL, ID_QAErrorLog ); + MAKE_TT_KEYWORD( "EnableQaErrors", SbxCLASS_PROPERTY, SbxBOOL, ID_EnableQaErrors ); + MAKE_TT_KEYWORD( "MaybeAddErr", SbxCLASS_METHOD, SbxNULL, ID_MaybeAddErr ); + MAKE_TT_KEYWORD( "ClearError", SbxCLASS_METHOD, SbxNULL, ID_ClearError ); + MAKE_TT_KEYWORD( "SaveIDs", SbxCLASS_METHOD, SbxBOOL, ID_SaveIDs ); + MAKE_TT_KEYWORD( "AutoExecute", SbxCLASS_PROPERTY, SbxBOOL, ID_AutoExecute ); // Achtung! PROPERTY Also eine Variable + MAKE_TT_KEYWORD( "Execute", SbxCLASS_METHOD, SbxNULL, ID_Execute ); + MAKE_TT_KEYWORD( "StopOnSyntaxError", SbxCLASS_PROPERTY, SbxBOOL, ID_StopOnSyntaxError ); + +/* Dialog Handler werden gebraucht, wenn im internen Testtool ein Dialog + hochgerissen wird. Nach versenden der Remote-Kommandos wird IdleHandler aktiviert. + Er testet, ob das Reschedule zum WaitForAnswer zur�ckkehrt. Bleibt das aus, so + wird erst der RemoteHandler zur�ckgesetzt und dann die Handler-Sub im Basic + gerufen.(Entkoppelt �ber PostUserEvent.) + + In returndaten_verarbeiten wird flag f�r ausf�hrung des n�chsten remote-befehls + r�ckgesetzt. Der Handler wird damit auch entwertet. Er gilt also nur f�r den + n�chsten Remotebefehl. +*/ + MAKE_TT_KEYWORD( "DialogHandler", SbxCLASS_METHOD, SbxNULL, ID_DialogHandler ); + + MAKE_TT_KEYWORD( "GetUnoApp", SbxCLASS_METHOD, SbxOBJECT, ID_GetUnoApp ); + MAKE_TT_KEYWORD( "GetIServer", SbxCLASS_METHOD, SbxOBJECT, ID_GetIServer ); + + MAKE_TT_KEYWORD( "RemoteCommandDelay", SbxCLASS_METHOD, SbxNULL, ID_RemoteCommandDelay ); + + MAKE_TT_KEYWORD( "GetApplicationPath", SbxCLASS_METHOD, SbxSTRING, ID_GetApplicationPath ); + MAKE_TT_KEYWORD( "GetCommonApplicationPath", SbxCLASS_METHOD, SbxSTRING, ID_GetCommonApplicationPath ); + MAKE_TT_KEYWORD( "MakeIniFileName", SbxCLASS_METHOD, SbxSTRING, ID_MakeIniFileName ); + +/// active constants returning error and warning count + MAKE_TT_KEYWORD( "GetErrorCount", SbxCLASS_METHOD, SbxULONG, ID_GetErrorCount ); + MAKE_TT_KEYWORD( "GetWarningCount", SbxCLASS_METHOD, SbxULONG, ID_GetWarningCount ); + MAKE_TT_KEYWORD( "GetQAErrorCount", SbxCLASS_METHOD, SbxULONG, ID_GetQAErrorCount ); + MAKE_TT_KEYWORD( "GetUseFileWarningCount", SbxCLASS_METHOD, SbxULONG, ID_GetUseFileWarningCount ); + + MAKE_TT_KEYWORD( "GetErrorList", SbxCLASS_METHOD, SbxOBJECT, ID_GetErrorList ); + MAKE_TT_KEYWORD( "GetWarningList", SbxCLASS_METHOD, SbxOBJECT, ID_GetWarningList ); + MAKE_TT_KEYWORD( "GetQAErrorList", SbxCLASS_METHOD, SbxOBJECT, ID_GetQAErrorList ); + MAKE_TT_KEYWORD( "GetUseFileWarningList", SbxCLASS_METHOD, SbxOBJECT, ID_GetUseFileWarningList ); + + MAKE_TT_KEYWORD( "GetTestCaseName", SbxCLASS_METHOD, SbxSTRING, ID_GetTestCaseName ); + MAKE_TT_KEYWORD( "GetTestCaseFileName", SbxCLASS_METHOD, SbxSTRING, ID_GetTestCaseFileName ); + MAKE_TT_KEYWORD( "GetTestCaseLineNr", SbxCLASS_METHOD, SbxUSHORT, ID_GetTestCaseLineNr ); + + MAKE_TT_KEYWORD( "SetChildEnv", SbxCLASS_METHOD, SbxNULL, ID_SetChildEnv ); + MAKE_TT_KEYWORD( "GetChildEnv", SbxCLASS_METHOD, SbxSTRING, ID_GetChildEnv ); + + MAKE_TT_KEYWORD( "GetLinkDestination", SbxCLASS_METHOD, SbxSTRING, ID_GetLinkDestination ); + MAKE_TT_KEYWORD( "GetRegistryValue", SbxCLASS_METHOD, SbxSTRING, ID_GetRegistryValue ); + + MAKE_TT_KEYWORD( "KillApp", SbxCLASS_METHOD, SbxNULL, ID_KillApp ); + + MAKE_TT_KEYWORD( "HTTPSend", SbxCLASS_METHOD, SbxUSHORT, ID_HTTPSend ); + MAKE_TT_KEYWORD( "HTTPSetProxy", SbxCLASS_METHOD, SbxNULL, ID_HTTPSetProxy ); + + // Load the Remote Commands from list + if ( !pRCommands ) // Ist static, wird also nur einmal geladen + ReadFlatArray( arR_Cmds, pRCommands ); + USHORT i; + for ( i = 0 ; i < pRCommands->Count() ; i++ ) + { + SbxTransportMethod *pMeth = new SbxTransportMethod( SbxVARIANT ); + pMeth->SetName( pRCommands->GetObject( i )->pData->Kurzname ); + pMeth->SetUserData( ID_RemoteCommand ); + pMeth->nValue = pRCommands->GetObject( i )->pData->aUId.GetNum(); + Insert( pMeth ); + StartListening( pMeth->GetBroadcaster(), TRUE ); + } + +// Konstanten f�r SetControlType + MAKE_USHORT_CONSTANT("CTBrowseBox",CONST_CTBrowseBox); + MAKE_USHORT_CONSTANT("CTValueSet",CONST_CTValueSet); + +// Konstanten f�r das Alignment des gesuchten Splitters + MAKE_USHORT_CONSTANT("AlignLeft",CONST_ALIGN_LEFT); + MAKE_USHORT_CONSTANT("AlignTop",CONST_ALIGN_TOP); + MAKE_USHORT_CONSTANT("AlignRight",CONST_ALIGN_RIGHT); + MAKE_USHORT_CONSTANT("AlignBottom",CONST_ALIGN_BOTTOM); + +/// What dialog to use in RC_CloseSysDialog or RC_ExistsSysDialog + MAKE_USHORT_CONSTANT("FilePicker",CONST_FilePicker); + MAKE_USHORT_CONSTANT("FolderPicker",CONST_FolderPicker); + +/// NodeTypes of the SAX Parser + MAKE_USHORT_CONSTANT("NodeTypeCharacter",CONST_NodeTypeCharacter); + MAKE_USHORT_CONSTANT("NodeTypeElement",CONST_NodeTypeElement); + MAKE_USHORT_CONSTANT("NodeTypeComment",CONST_NodeTypeComment); + + +/// ItemTypes for TreeListBox and maybe others + MAKE_USHORT_CONSTANT("ItemTypeText",CONST_ItemTypeText); + MAKE_USHORT_CONSTANT("ItemTypeBMP",CONST_ItemTypeBMP); + MAKE_USHORT_CONSTANT("ItemTypeCheckbox",CONST_ItemTypeCheckbox); + MAKE_USHORT_CONSTANT("ItemTypeContextBMP",CONST_ItemTypeContextBMP); + MAKE_USHORT_CONSTANT("ItemTypeUnknown",CONST_ItemTypeUnknown); + + +/// Return values for WaitSlot + MAKE_USHORT_CONSTANT("WSTimeout",CONST_WSTimeout); + MAKE_USHORT_CONSTANT("WSAborted",CONST_WSAborted); + MAKE_USHORT_CONSTANT("WSFinished",CONST_WSFinished); + + + pImpl->pControlsObj = new Controls( CUniString("GetNextCloseWindow") ); + pImpl->pControlsObj->SetType( SbxVARIANT ); + Insert( pImpl->pControlsObj ); + pImpl->pControlsObj->SetUserData( ID_GetNextCloseWindow ); + pImpl->pControlsObj->ChangeListener( this ); + + for ( i=0;i<VAR_POOL_SIZE;i++) + { +/* pMyVar = new SbxObject( "Dummy" ); + pMyVar->SetType( SbxVARIANT );*/ + +// pMyVar = new SbxMethod( "Dummy", SbxVARIANT ); + + pImpl->pMyVars[i] = new SbxTransportMethod( SbxVARIANT ); + pImpl->pMyVars[i]->SetName( CUniString("VarDummy").Append(String::CreateFromInt32(i) ) ); + + Insert( pImpl->pMyVars[i] ); +// StartListening( pMyVars[i]->GetBroadcaster(), TRUE ); + + } + + m_pControls = new CNames(); + m_pSIds = new CNames(); + m_pNameKontext = m_pControls; + + nMyVar = 0; + + pImpl->pMyBasic->AddFactory( &aComManFac ); + + +// Das ist zum testen des IPC + +/* int sent = 0; + + ModelessDialog *pDlg = new ModelessDialog(NULL); + pDlg->SetOutputSizePixel(Size(100,30)); + + Edit *pMyEd = new Edit(pDlg,WB_CENTER | WB_BORDER); + pMyEd->SetSizePixel(Size(100,30)); + pDlg->Show(); + pMyEd->Show(); + Time aTime; + + String VollePackung; + VollePackung.Fill(32760,'*'); + + BeginBlock(); // zum warm werden + EndBlock(); + ResetError(); + + while ( pDlg->IsVisible() && !IsError() ) + { + BeginBlock(); + In->GenCmdFlow (124,VollePackung); + EndBlock(); + pMyEd->SetText(String("Test Nr. ") + String(++sent)); + while ( aTime.Get100Sec() / 10 == Time().Get100Sec() / 10 ); + aTime = Time(); + } + + delete pMyEd; + delete pDlg; +*/ +// Test ende + + +} + +TestToolObj::~TestToolObj() +{ + pImpl->pMyBasic->RemoveFactory( &aComManFac ); + EndListening( ((StarBASIC*)GetParent())->GetBroadcaster() ); + pImpl->pNextReturn.Clear(); + + pImpl->pControlsObj.Clear(); + + for ( int i = 0 ; i < VAR_POOL_SIZE ; i++ ) + { + pImpl->pMyVars[i].Clear(); + } + + if (m_pControls) + delete m_pControls; + if (m_pReverseSlots) + delete m_pReverseSlots; + if (m_pReverseControls) + delete m_pReverseControls; + if (m_pReverseControlsSon) + delete m_pReverseControlsSon; + if (m_pReverseUIds) + delete m_pReverseUIds; + if (m_pSIds) + delete m_pSIds; + if (pFehlerListe) + { + delete pFehlerListe; + pFehlerListe = NULL; // da pFehlerListe static ist!! + } + if ( pCommunicationManager ) + { + pCommunicationManager->StopCommunication(); + delete pCommunicationManager; + } + delete In; + if ( pImpl->pTTSfxBroadcaster ) + delete pImpl->pTTSfxBroadcaster; + delete pImpl->pChildEnv; + + pImpl->xErrorList.Clear(); + pImpl->xWarningList.Clear(); + pImpl->xQAErrorList.Clear(); + pImpl->xIncludeFileWarningList.Clear(); + + delete pImpl; + + delete pShortNames; +} + +SfxBroadcaster& TestToolObj::GetTTBroadcaster() +{ + if ( !pImpl->pTTSfxBroadcaster ) + pImpl->pTTSfxBroadcaster = new SfxBroadcaster; + return *pImpl->pTTSfxBroadcaster; +} + +void TestToolObj::ReadNames( String Filename, CNames *&pNames, CNames *&pUIds, BOOL bIsFlat ) +{ +/******************************************************************************* +** +** Folgende Dateiendungen sind vorhanden +** +** hid.lst Langname UId +** *.sid Slot Ids Kurzname Langname Datei ist flach +** *.win Controlname Langname Datei mit *name und +name Notation +** +** +*******************************************************************************/ + + + SvFileStream Stream; + String aLine,aShortname,aLongname; + SmartId aUId; + xub_StrLen nLineNr; + USHORT nElement; + ControlDef *pNewDef, *pNewDef2; + ControlDef *pFatherDef = NULL; + + nLineNr = 0; // Wir sind ja noch vor der Datei + + if (! pUIds) + { + String aFileName = (pImpl->aHIDDir + DirEntry(CUniString("hid.lst"))).GetFull(); + { + TTExecutionStatusHint aHint( TT_EXECUTION_SHOW_ACTION, String(SttResId(S_READING_LONGNAMES)), aFileName ); + GetTTBroadcaster().Broadcast( aHint ); + } + ReadFlat( aFileName ,pUIds, TRUE ); + if ( !pUIds ) + return; + pNewDef = new ControlDef("Active",SmartId(0)); + const ControlItem *pItem = pNewDef; + if (! pUIds->Insert(pItem)) + { + ADD_WARNING_LOG2( GEN_RES_STR1c( S_DOUBLE_NAME, "Active" ), Filename, nLineNr ); + delete pNewDef; + } + + } + + ADD_MESSAGE_LOG( Filename ); + + Stream.Open(Filename, STREAM_STD_READ); + if (!Stream.IsOpen()) + { + ADD_ERROR(ERR_NO_FILE,GEN_RES_STR1(S_CANNOT_OPEN_FILE, Filename)); + return; + } + + if ( bIsFlat && !pNames ) + { + TTExecutionStatusHint aHint( TT_EXECUTION_SHOW_ACTION, String(SttResId(S_READING_SLOT_IDS)), Filename ); + GetTTBroadcaster().Broadcast( aHint ); + } + else + { + TTExecutionStatusHint aHint( TT_EXECUTION_SHOW_ACTION, String(SttResId(S_READING_CONTROLS)), Filename ); + GetTTBroadcaster().Broadcast( aHint ); + } + + if ( !pNames ) + pNames = new CNames(); + + { + TTExecutionStatusHint aHint( TT_EXECUTION_ENTERWAIT ); + GetTTBroadcaster().Broadcast( aHint ); + } + while (!Stream.IsEof()) + { + nLineNr++; + + Stream.ReadByteStringLine(aLine, RTL_TEXTENCODING_IBM_850); + aLine.EraseLeadingChars(); + aLine.EraseTrailingChars(); + while ( aLine.SearchAscii(" ") != STRING_NOTFOUND ) + aLine.SearchAndReplaceAllAscii(" ",UniString(' ')); + if (aLine.Len() == 0) continue; + if (aLine.Copy(0,4).CompareIgnoreCaseToAscii("Rem ") == COMPARE_EQUAL) continue; + if (aLine.Copy(0,1).CompareToAscii("'") == COMPARE_EQUAL) continue; + + if ( (aLine.GetTokenCount(cMyDelim) < 2 || aLine.GetTokenCount(cMyDelim) > 3) && aLine.CompareIgnoreCaseToAscii("*Active") != COMPARE_EQUAL ) + { + ADD_WARNING_LOG2( GEN_RES_STR1( S_INVALID_LINE, aLine ), Filename, nLineNr ); + continue; + } + + aShortname = aLine.GetToken(0,cMyDelim); + aLongname = aLine.GetToken(1,cMyDelim); + + String aFirstAllowedExtra, aAllowed; + aFirstAllowedExtra.AssignAscii("+*"); + aAllowed.AssignAscii("_"); + xub_StrLen nIndex = 0; + BOOL bOK = TRUE; + + while ( bOK && nIndex < aShortname.Len() ) + { + sal_Unicode aChar = aShortname.GetChar( nIndex ); + BOOL bOKThis = FALSE; + bOKThis |= ( aAllowed.Search( aChar ) != STRING_NOTFOUND ); + if ( !nIndex ) + bOKThis |= ( aFirstAllowedExtra.Search( aChar ) != STRING_NOTFOUND ); + bOKThis |= ( aChar >= 'A' && aChar <= 'Z' ); + bOKThis |= ( aChar >= 'a' && aChar <= 'z' ); + bOKThis |= ( aChar >= '0' && aChar <= '9' ); + + bOK &= bOKThis; + nIndex++; + } + if ( !bOK ) + { + ADD_WARNING_LOG2( CUniString("Zeile \"").Append(aLine).AppendAscii("\" enth�lt ung�ltige Zeichen."), Filename, nLineNr ); + continue; + } + + BOOL bUnoName = ( aLongname.Copy( 0, 5 ).EqualsIgnoreCaseAscii( ".uno:" ) + || aLongname.Copy( 0, 4 ).EqualsIgnoreCaseAscii( "http" ) + || aLongname.Copy( 0, 15 ).EqualsIgnoreCaseAscii( "private:factory" ) + || aLongname.Copy( 0, 8 ).EqualsIgnoreCaseAscii( "service:" ) + || aLongname.Copy( 0, 6 ).EqualsIgnoreCaseAscii( "macro:" ) + || aLongname.Copy( 0, 8 ).EqualsIgnoreCaseAscii( ".HelpId:" ) ); + // generic method to mark longnames as symbolic + if ( aLongname.Copy( 0, 4 ).EqualsIgnoreCaseAscii( "sym:" ) ) + { + bUnoName = TRUE; + aLongname.Erase( 0, 4 ); + } + BOOL bMozillaName = ( !bIsFlat && aLongname.Copy( 0, 4 ).EqualsIgnoreCaseAscii( ".moz" ) ); + + if ( aShortname.GetChar(0) == '+' ) // Kompletten Eintrag kopieren + { + aShortname.Erase(0,1); + ControlDef WhatName(aLongname,SmartId()); + ControlDef *OldTree; + if (pNames->Seek_Entry(&WhatName,&nElement)) + { + OldTree = (ControlDef*)pNames->GetObject(nElement); + pNewDef = new ControlDef(aLongname,aShortname,OldTree,TRUE); + + const ControlItem *pItem = pNewDef; + if (! pNames->Insert(pItem)) + { + ADD_WARNING_LOG2( GEN_RES_STR1( S_DOUBLE_NAME, aLine ), Filename, nLineNr ); + delete pNewDef; + pFatherDef = NULL; + } + else + { + pFatherDef = pNewDef; + } + } + else + { + ADD_WARNING_LOG2( GEN_RES_STR1( S_SHORTNAME_UNKNOWN, aLine ), Filename, nLineNr ); + continue; + } + + } + else + { + + if (aShortname.CompareIgnoreCaseToAscii("*Active") == COMPARE_EQUAL) + aUId = SmartId( UID_ACTIVE ); + else if ( !bUnoName && !bMozillaName ) + { // Bestimmen der ID aus der Hid.Lst + ControlDef WhatName(aLongname,SmartId()); + if (pUIds->Seek_Entry(&WhatName,&nElement)) + aUId = pUIds->GetObject(nElement)->pData->aUId; + else + { + ADD_WARNING_LOG2( GEN_RES_STR1( S_LONGNAME_UNKNOWN, aLine ), Filename, nLineNr ); + continue; + } + } + else + { + if ( bUnoName ) + aUId = SmartId( aLongname ); + else if ( bMozillaName ) + aUId = SmartId( aLongname ); + else + { + DBG_ERROR("Unknown URL schema"); + } + } + + + + if (aShortname.GetChar(0) == '*' || bIsFlat) // Globaler Kurzname (Dialogname oder SId) + { + if (!bIsFlat) + aShortname.Erase(0,1); + + pNewDef = new ControlDef(aShortname,aUId); + + if (!bIsFlat) + { + pNewDef->Sons( new CNames() ); + + pNewDef2 = new ControlDef(aShortname,aUId); + if (!pNewDef->SonInsert( pNewDef2 )) // Dialog in eigenen Namespace eintragen + { + delete pNewDef2; + DBG_ERROR(" !!!! ACHTUNG !!!! Fehler beim einf�gen in leere Liste!"); + } + } + + const ControlItem *pItem = pNewDef; + if (! pNames->Insert(pItem)) + { + ADD_WARNING_LOG2( GEN_RES_STR1( S_DOUBLE_NAME, aLine ), Filename, nLineNr ); + delete pNewDef; + pFatherDef = NULL; + } + else + { + pFatherDef = pNewDef; + } + } + else + { + if (!pFatherDef) + { + ADD_WARNING_LOG2( GEN_RES_STR0( S_FIRST_SHORTNAME_REQ_ASTRX ), Filename, nLineNr ); + } + else + { + pNewDef = new ControlDef(aShortname,aUId); + if (! pFatherDef->SonInsert(pNewDef)) + { + ADD_WARNING_LOG2( GEN_RES_STR1( S_DOUBLE_NAME, aLine ), Filename, nLineNr ); + delete pNewDef; + } + } + } + } + GetpApp()->Reschedule(); + } + { + TTExecutionStatusHint aHint( TT_EXECUTION_LEAVEWAIT ); + GetTTBroadcaster().Broadcast( aHint ); + } + { + TTExecutionStatusHint aHint( TT_EXECUTION_HIDE_ACTION ); + GetTTBroadcaster().Broadcast( aHint ); + } + + Stream.Close(); +} + + +void TestToolObj::AddName(String &aBisher, String &aNeu ) +{ + String aSl( '/' ); + if ( UniString(aSl).Append(aBisher).Append(aSl).ToUpperAscii().Search( UniString(aSl).Append(aNeu).Append(aSl).ToUpperAscii() ) == STRING_NOTFOUND ) + { + aBisher += aSl; + aBisher += aNeu; + } +} + + +void TestToolObj::ReadFlat( String Filename, CNames *&pNames, BOOL bSortByName ) +// Wenn bSortByName == FALSE, dann nach UId Sortieren (ControlItemUId statt ControlDef) +{ + SvFileStream Stream; + String aLine,aLongname; + SmartId aUId; + xub_StrLen nLineNr; + ControlItem *pNewItem; + USHORT nDoubleCount = 0; + + Stream.Open(Filename, STREAM_STD_READ); + + if (!Stream.IsOpen()) + { + ADD_ERROR(ERR_NO_FILE,GEN_RES_STR1(S_CANNOT_OPEN_FILE, Filename)); + return; + } + + nLineNr = 0; // Wir sind ja noch vor der Datei + + if ( !pNames ) + pNames = new CNames(); + + { + TTExecutionStatusHint aHint( TT_EXECUTION_ENTERWAIT ); + GetTTBroadcaster().Broadcast( aHint ); + } + ADD_MESSAGE_LOG( Filename ); + while (!Stream.IsEof()) + { + nLineNr++; + + Stream.ReadByteStringLine(aLine, RTL_TEXTENCODING_IBM_850); + aLine.EraseLeadingChars(); + aLine.EraseTrailingChars(); + while ( aLine.SearchAscii(" ") != STRING_NOTFOUND ) + aLine.SearchAndReplaceAllAscii(" ",UniString(' ')); + if (aLine.Len() == 0) continue; + + if ( (aLine.GetTokenCount(cMyDelim) < 2 || aLine.GetTokenCount(cMyDelim) > 3) && aLine.CompareIgnoreCaseToAscii("*Active") != COMPARE_EQUAL ) + { + ADD_WARNING_LOG2( GEN_RES_STR1( S_INVALID_LINE, aLine ), Filename, nLineNr ); + continue; + } + + aLongname = aLine.GetToken(0,cMyDelim); + aUId = SmartId( (ULONG)aLine.GetToken(1,cMyDelim).ToInt64() ); + + if ( bSortByName ) + pNewItem = new ControlDef( aLongname, aUId ); + else + pNewItem = new ControlItemUId( aLongname, aUId ); + if ( !pNames->C40_PTR_INSERT( ControlItem, pNewItem ) ) + { + if ( bSortByName ) + { + if ( nDoubleCount++ < 10 ) + { + ADD_WARNING_LOG2( GEN_RES_STR1( S_DOUBLE_NAME, aLine ), Filename, nLineNr ); + } + } + else + { + USHORT nNr; + pNames->Seek_Entry( pNewItem, &nNr ); + AddName( pNames->GetObject(nNr)->pData->Kurzname, pNewItem->pData->Kurzname ); + } + delete pNewItem; + } + GetpApp()->Reschedule(); + } + { + TTExecutionStatusHint aHint( TT_EXECUTION_LEAVEWAIT ); + GetTTBroadcaster().Broadcast( aHint ); + } + + Stream.Close(); +#ifdef DBG_UTIL +// int i; +// for ( i = 0 ; i < pNames->Count() ; i++ ) +// { +// DBG_ERROR( pNames->GetObject(i)->pData->Kurzname ); +// } +#endif +} + +void ReadFlatArray( const ControlDefLoad arWas [], CNames *&pNames ) +{ + USHORT nIndex = 0; + + if ( !pNames ) + pNames = new CNames(); + + while ( String::CreateFromAscii(arWas[nIndex].Kurzname).Len() > 0 ) + { + SmartId aUId (arWas[nIndex].nUId); + const ControlItem *pX = new ControlDef( arWas[nIndex].Kurzname, aUId); + pNames->C40_PTR_INSERT(ControlItem, pX); + nIndex++; + } +} + +void TestToolObj::WaitForAnswer () +{ + if ( bUseIPC ) + { + #ifdef DBG_UTILx + USHORT nSysWinModeMemo = GetpApp()->GetSystemWindowMode(); + GetpApp()->SetSystemWindowMode( 0 ); + ModelessDialog aDlg(NULL); + aDlg.SetOutputSizePixel(Size(200,0)); + aDlg.SetText(CUniString("Waiting for Answer")); + aDlg.Show( TRUE, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE ); + GetpApp()->SetSystemWindowMode( nSysWinModeMemo ); + #endif + BOOL bWasRealWait = !bReturnOK; + BasicRuntime aRun( NULL ); + if ( BasicRuntimeAccess::HasRuntime() ) + aRun = BasicRuntimeAccess::GetRuntime(); + + // this timer to terminate Yield below + Timer aTimer; + aTimer.SetTimeout( pImpl->aServerTimeout.GetMSFromTime() ); + aTimer.Start(); + while ( !bReturnOK && aTimer.IsActive() && pCommunicationManager->IsCommunicationRunning() + && aRun.IsValid() && aRun.IsRun() ) + { + #ifdef OS2 + DosSleep(100); + #endif + GetpApp()->Yield(); + if ( BasicRuntimeAccess::HasRuntime() ) + aRun = BasicRuntimeAccess::GetRuntime(); + else + aRun = BasicRuntime( NULL ); + } + if ( bWasRealWait && aDialogHandlerName.Len() > 0 ) // Damit das ganze auch im Testtool l�uft + CallDialogHandler(GetpApp()); + } + else + { + Time Ende; + + Ende += pImpl->aServerTimeout; + SvStream *pTemp = NULL; + + while ( !bReturnOK && Ende > Time() ) + { +// pTemp = PlugInApplication::GetPlugInApp()->GetReturnFromExecute(); + if ( pTemp ) + { + ReturnResults( pTemp ); + bReturnOK = TRUE; + } + else + { + GetpApp()->Reschedule(); + } + nIdleCount = 0; + } + } + + + if ( !bReturnOK ) + { + ADD_ERROR(ERR_EXEC_TIMEOUT,GEN_RES_STR1(S_TIMOUT_WAITING, String::CreateFromInt64(nSequence))); + bReturnOK = TRUE; + nSequence++; + } +} + + +IMPL_LINK( TestToolObj, IdleHdl, Application*, EMPTYARG ) +{ + if ( !bReturnOK ) + nIdleCount++; + if ( nIdleCount > 10 ) // d.h. Schon 10 mal hier gewesen und noch keinmal im WaitForAnswer + { + GetpApp()->RemoveIdleHdl( LINK( this, TestToolObj, IdleHdl ) ); + GetpApp()->PostUserEvent( LINK( this, TestToolObj, CallDialogHandler ) ); + } + return 0; +} + +IMPL_LINK( TestToolObj, CallDialogHandler, Application*, EMPTYARG ) +{ + nWindowHandlerCallLevel++; + String aHandlerName(aDialogHandlerName); + aDialogHandlerName.Erase(); + + ULONG nRememberSequence = nSequence; // Da sich die Sequence im DialogHandler �ndert + ((StarBASIC*)GetParent())->Call( aHandlerName ); + nSequence = nRememberSequence; + // Die Sequenznummern werden dann zwar doppelt vergeben, aber wen k�mmerts. + + nWindowHandlerCallLevel--; + return 0; +} + + +void TestToolObj::BeginBlock() +{ + WaitForAnswer(); + if ( IsError() ) + return; + + DBG_ASSERT(!IsBlock,"BeginBlock innerhalb eines Blockes"); + In->Reset(nSequence); + IsBlock = TRUE; +} + + +void TestToolObj::SendViaSocket() +{ + if ( !pCommunicationManager ) + { + DBG_ERROR("Kein CommunicationManager vorhanden!!"); + return; + } + + if ( !pCommunicationManager->IsCommunicationRunning() ) + { + // first try to run basic sub "startTheOffice" see i86540 + SbxVariable* pMeth = pImpl->pMyBasic->Find( CUniString( "startTheOffice" ), SbxCLASS_DONTCARE); + if( !pImpl->bIsStart && pMeth && pMeth->ISA(SbxMethod) ) + { + pImpl->pMyBasic->Call( CUniString( "startTheOffice" ) ); + } + else + { + pImpl->pMyBasic->ResetError(); // reset error produced by failed Find above + if ( !pCommunicationManager->StartCommunication( ProgPath, pImpl->ProgParam, pImpl->pChildEnv ) ) + { + ADD_ERROR(ERR_RESTART_FAIL,GEN_RES_STR1(S_APPLICATION_START_FAILED, ProgPath)); + } + else + { + if ( !pImpl->bIsStart ) + { + ADD_ERROR(ERR_RESTART,GEN_RES_STR0(S_APPLICATION_RESTARTED)); + } + } + } + } + + bReturnOK = FALSE; + if ( pCommunicationManager->GetLastNewLink() ) + { + if ( !pCommunicationManager->GetLastNewLink()->TransferDataStream( In->GetStream() ) ) + { + ADD_ERROR(ERR_SEND_TIMEOUT,GEN_RES_STR1(S_TIMOUT_SENDING, String::CreateFromInt64(nSequence))); + nSequence++; + bReturnOK = TRUE; // Kein Return zu erwarten + } + } + else + { + ADD_ERROR(ERR_SEND_TIMEOUT,GEN_RES_STR1(S_NO_CONNECTION, String::CreateFromInt64(nSequence))); + nSequence++; + bReturnOK = TRUE; // Kein Return zu erwarten + } + +} + +void TestToolObj::EndBlock() +{ + if (IsBlock) + { + pImpl->LocalStarttime = Time::GetSystemTicks(); // Setzen der Anfangszeit f�r Performancemessung + + In->GenCmdFlow (F_EndCommandBlock); + + if ( pImpl->bDoRemoteCommandDelay ) + { + ULONG nTimeWait = pImpl->nMinRemoteCommandDelay; + if ( pImpl->nMaxRemoteCommandDelay != pImpl->nMinRemoteCommandDelay ) + nTimeWait += Time::GetSystemTicks() % ( pImpl->nMaxRemoteCommandDelay - pImpl->nMinRemoteCommandDelay ); + Timer aTimer; + aTimer.SetTimeout( nTimeWait ); + aTimer.Start(); + while ( aTimer.IsActive() && pCommunicationManager->IsCommunicationRunning() ) + { + #ifdef OS2 + DosSleep(100); + #endif + GetpApp()->Yield(); + } + } + + if ( bUseIPC ) + SendViaSocket(); + else + { +// PlugInApplication::GetPlugInApp()->ExecuteRemoteStatements( In->GetStream() ); + bReturnOK = FALSE; + if ( aDialogHandlerName.Len() > 0 ) + GetpApp()->InsertIdleHdl( LINK( this, TestToolObj, IdleHdl ), 1 ); + } + IsBlock = FALSE; + } + else + { + DBG_ERROR("EndBlock au�erhalb eines Blockes"); + } +} + + +BOOL TestToolObj::Load( String aFileName, SbModule *pMod ) +{ + BOOL bOk = TRUE; + SvFileStream aStrm( aFileName, STREAM_STD_READ ); + if( aStrm.IsOpen() ) + { + String aText, aLine; + BOOL bIsFirstLine = TRUE; + rtl_TextEncoding aFileEncoding = RTL_TEXTENCODING_IBM_850; + while( !aStrm.IsEof() && bOk ) + { + aStrm.ReadByteStringLine( aLine, aFileEncoding ); + if ( bIsFirstLine && IsTTSignatureForUnicodeTextfile( aLine ) ) + aFileEncoding = RTL_TEXTENCODING_UTF8; + else + { + if ( !bIsFirstLine ) + aText += '\n'; + aText += aLine; + bIsFirstLine = FALSE; + } + if( aStrm.GetError() != SVSTREAM_OK ) + bOk = FALSE; + } + aText.ConvertLineEnd(); + pMod->SetName(CUniString("--").Append(aFileName)); + + pMod->SetComment( GetRevision( aText ) ); + + SbModule* pOldModule = MyBasic::GetCompileModule(); + MyBasic::SetCompileModule( pMod ); + + pMod->SetSource( PreCompile( aText ) ); + + MyBasic::SetCompileModule( pOldModule ); + if ( WasPrecompilerError() ) + bOk = FALSE; + + } + else + bOk = FALSE; + return bOk; +} + + +BOOL TestToolObj::ReadNamesBin( String Filename, CNames *&pSIds, CNames *&pControls ) +{ + SvFileStream aStream; + String aName,aURL; + SmartId aUId; + ControlDef *pNewDef, *pNewDef2; + ControlDef *pFatherDef = NULL; + + + aStream.Open(Filename, STREAM_STD_READ); + if (!aStream.IsOpen()) + { + ADD_ERROR(ERR_NO_FILE,GEN_RES_STR1(S_CANNOT_OPEN_FILE, Filename)); + return FALSE; + } + + if ( !pSIds ) + pSIds = new CNames(); + if ( !pControls ) + pControls = new CNames(); + + { + TTExecutionStatusHint aHint( TT_EXECUTION_ENTERWAIT ); + GetTTBroadcaster().Broadcast( aHint ); + } + + USHORT nAnz; + aStream >> nAnz; + CNames *pNames = pSIds; // first read all the slots + BOOL bIsFlat = TRUE; // Slots do not have children + + while ( nAnz && !aStream.IsEof() ) + { + + aStream.ReadByteString( aName, RTL_TEXTENCODING_UTF8 ); + + USHORT nType; + aStream >> nType; + if ( !nType /* HasNumeric() */) + { + String aStrId; + aStream.ReadByteString( aStrId, RTL_TEXTENCODING_UTF8 ); + aUId = SmartId( aStrId ); + } + else + { + comm_ULONG nUId; + aStream >> nUId; + aUId = SmartId( nUId ); + } + + if (aName.GetChar(0) == '*' || bIsFlat ) // Globaler Kurzname (Dialogname oder SId) + { + if (!bIsFlat) + aName.Erase(0,1); + pNewDef = new ControlDef(aName,aUId); + + if (!bIsFlat) + { + pNewDef->Sons(new CNames()); + + pNewDef2 = new ControlDef(aName,aUId); // Noch einen machen + if (!pNewDef->SonInsert(pNewDef2)) // Dialog in eigenen Namespace eintragen + { + delete pNewDef2; + DBG_ERROR(" !!!! ACHTUNG !!!! Fehler beim einf�gen in leere Liste!"); + } + } + + const ControlItem *pItem = pNewDef; + if (! pNames->Insert(pItem)) + { + DBG_ERROR(" !!!! ACHTUNG !!!! Fehler beim einf�gen eines namens!"); + delete pNewDef; + pFatherDef = NULL; + } + else + { + pFatherDef = pNewDef; + } + } + else + { + if (!pFatherDef) + { + DBG_ERROR( "Internal Error: Erster Kurzname mu� mit * beginnen. �berspringe." ); + } + else + { + pNewDef = new ControlDef(aName,aUId); + if (! pFatherDef->SonInsert(pNewDef)) + { + delete pNewDef; + DBG_ERROR(" !!!! ACHTUNG !!!! Fehler beim einf�gen eines namens!"); + } + } + } + + + nAnz--; + if ( !nAnz && bIsFlat ) // We have read all slots + { + aStream >> nAnz; + pNames = pControls; // Now read the controls + bIsFlat = FALSE; // Controls *do* have children + } + + + GetpApp()->Reschedule(); + } + { + TTExecutionStatusHint aHint( TT_EXECUTION_LEAVEWAIT ); + GetTTBroadcaster().Broadcast( aHint ); + } + + aStream.Close(); + return TRUE; +} + + +BOOL TestToolObj::WriteNamesBin( String Filename, CNames *pSIds, CNames *pControls ) +{ + BOOL bOk = TRUE; + SvFileStream aStrm( String(Filename).AppendAscii(".bin"), STREAM_STD_WRITE ); + if( aStrm.IsOpen() ) + { + USHORT i; + if ( pSIds ) + { + aStrm << pSIds->Count(); + for ( i = 0 ; pSIds->Count() > i && bOk ; i++ ) + { + ((ControlDef*)(*pSIds)[i])->Write(aStrm); + if( aStrm.GetError() != SVSTREAM_OK ) + bOk = FALSE; + } + } + else + aStrm << USHORT( 0 ); + + if ( pControls ) + { + aStrm << pControls->Count(); + for ( i = 0 ; pControls->Count() > i && bOk ; i++ ) + { + ((ControlDef*)(*pControls)[i])->Write(aStrm); + if( aStrm.GetError() != SVSTREAM_OK ) + bOk = FALSE; + } + } + else + aStrm << USHORT( 0 ); + } + else + bOk = FALSE; + return bOk; +} + + +void TestToolObj::SFX_NOTIFY( SfxBroadcaster&, const TypeId&, + const SfxHint& rHint, const TypeId& ) +{ + static CNames *pUIds = NULL; // Halten der hid.lst + + const SbxHint* p = PTR_CAST(SbxHint,&rHint); + if( p ) + { + SbxVariable* pVar = p->GetVar(); + SbxArray* rPar = pVar->GetParameters(); + + ULONG nHintId = p->GetId(); + ULONG nHintUserData = pVar->GetUserData(); + if( nHintId == SBX_HINT_DATAWANTED ) + { + nMyVar = 0; + switch( nHintUserData ) + { + case ID_Kontext: + if ( !rPar ) + { + m_pNameKontext = m_pControls; + + // So da� nicht immer mal wieder was aus einem alten Kontext dazwischenhaut + for (USHORT i=0;i<VAR_POOL_SIZE;i++) + { + pImpl->pMyVars[i]->SetName( CUniString("VarDummy").Append(UniString::CreateFromInt32(i)) ); + } + } + else if ( rPar && rPar->Count() == 2 ) + { + USHORT nElement; + SbxVariableRef pArg = rPar->Get( 1 ); + String aKontext = pArg->GetString(); + ControlDef WhatName(aKontext,SmartId()); + if (m_pControls && m_pControls->Seek_Entry(&WhatName,&nElement)) + { + m_pNameKontext = ((ControlDef*)m_pControls->GetObject(nElement))->GetSons(); + + // So da� nicht immer mal wieder was aus einem alten Kontext dazwischenhaut + for (USHORT i=0;i<VAR_POOL_SIZE;i++) + { + pImpl->pMyVars[i]->SetName( CUniString("VarDummy").Append(UniString::CreateFromInt32(i)) ); + } + } + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_Start: + if ( rPar && rPar->Count() >= 2 ) + { + SbxVariableRef pArg = rPar->Get( 1 ); + ProgPath = pArg->GetString(); + if ( rPar && rPar->Count() >= 3 ) + { + pArg = rPar->Get( 2 ); + pImpl->ProgParam = pArg->GetString(); + } + else + pImpl->ProgParam.Erase(); + + String aTmpStr(ProgPath); + aTmpStr += ' '; + aTmpStr += pImpl->ProgParam; + { + TTExecutionStatusHint aHint( TT_EXECUTION_SHOW_ACTION, String(SttResId(S_STARTING_APPLICATION)), aTmpStr ); + GetTTBroadcaster().Broadcast( aHint ); + } + + pImpl->bIsStart = TRUE; + BeginBlock(); + EndBlock(); + pImpl->bIsStart = FALSE; + { + TTExecutionStatusHint aHint( TT_EXECUTION_HIDE_ACTION ); + GetTTBroadcaster().Broadcast( aHint ); + } + } + break; + case ID_KillApp: + pCommunicationManager->KillApplication(); + break; + case ID_SaveIDs: + if ( rPar && rPar->Count() >= 2 ) // Genau ein Parameter + { + SbxVariableRef pArg = rPar->Get( 1 ); + DirEntry FilePath = pImpl->aFileBase + DirEntry(pArg->GetString(),FSYS_STYLE_VFAT); + WriteNamesBin( FilePath.GetFull(), m_pSIds, m_pControls ); + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_AutoExecute: + if ( !rPar ) // rPar = NULL <=> Kein Parameter + { + pVar->PutBool(SingleCommandBlock); + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_Execute: + if ( !rPar ) // rPar = NULL <=> Kein Parameter + { + EndBlock(); + BeginBlock(); + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_DialogHandler: + if ( rPar && rPar->Count() >= 2 ) // Genau ein Parameter + { + SbxVariableRef pArg = rPar->Get( 1 ); + aDialogHandlerName = pArg->GetString(); + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_GetError: + if ( !rPar ) // rPar = NULL <=> Kein Parameter + { + WaitForAnswer(); + if ( IS_ERROR() ) + { +// pVar->PutULong( GET_ERROR()->nError ); + pVar->PutString( GET_ERROR()->aText ); + POP_ERROR(); + } + else + { +// pVar->PutULong( 0 ); + pVar->PutString( String() ); + } + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_StartUse: + if ( !rPar ) // rPar = NULL <=> Kein Parameter + { + { + BasicRuntime aRun = BasicRuntimeAccess::GetRuntime(); + aLogFileName = DirEntry(aRun.GetModuleName(SbxNAME_NONE)).GetBase().AppendAscii(".res"); + } + + ADD_RUN_LOG(); + ADD_CASE_LOG(GEN_RES_STR0(S_READING_FILE)); + + pCommunicationManager->StopCommunication(); + // Wait for asynchronous events to be processed, so communication will be restarted properly + while ( pCommunicationManager->IsCommunicationRunning() ) + Application::Reschedule(); + + SingleCommandBlock = TRUE; // Bug 57188 + IsBlock = FALSE; + +// pCommunicationManager->StartCommunication(); + + for (USHORT i=0;i<VAR_POOL_SIZE;i++) + { + pImpl->pMyVars[i]->SetName( CUniString("VarDummy").Append(UniString::CreateFromInt32(i)) ); + } + nMyVar = 0; + + if (m_pControls) + { + delete m_pControls; + m_pControls = NULL; + } + if (m_pReverseSlots) + { + delete m_pReverseSlots; + m_pReverseSlots = NULL; + } + if (m_pReverseControls) + { + delete m_pReverseControls; + m_pReverseControls = NULL; + } + if (m_pReverseControlsSon) + { + delete m_pReverseControlsSon; + m_pReverseControlsSon = NULL; + } + if (m_pSIds) + { + delete m_pSIds; + m_pSIds = NULL; + } + if (pUIds) + { + delete pUIds; + pUIds = NULL; + } + if (m_pReverseUIds) + { + delete m_pReverseUIds; + m_pReverseUIds = NULL; + } + m_pNameKontext = m_pControls; + pImpl->bLnaguageExtensionLoaded = FALSE; + SfxSimpleHint aHint( SBX_HINT_LANGUAGE_EXTENSION_LOADED ); + GetTTBroadcaster().Broadcast( aHint ); + + pImpl->nMinRemoteCommandDelay = 0; + pImpl->nMaxRemoteCommandDelay = 0; + pImpl->bDoRemoteCommandDelay = FALSE; + pImpl->aTestCaseName.Erase(); + pImpl->aTestCaseFileName.Erase(); + pImpl->nTestCaseLineNr = 0; + + pImpl->bEnableQaErrors = TRUE; + pImpl->bDebugFindNoErrors = FALSE; + + pImpl->pChildEnv->clear(); + + String aName( CUniString( "StopOnSyntaxError" ) ); + SbxVariableRef xStopOnSyntaxError = SbxObject::Find( aName, SbxCLASS_PROPERTY ); + if ( xStopOnSyntaxError.Is() ) + xStopOnSyntaxError->PutBool( pImpl->bStopOnSyntaxError ); + else + SetError( SbxERR_BAD_ACTION ); + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_Use: + if ( rPar && rPar->Count() >= 2 ) + { + SbxVariableRef pArg = rPar->Get( 1 ); + DirEntry FilePath(pArg->GetString(),FSYS_STYLE_VFAT); + if ( !FilePath.IsAbs() ) + FilePath = pImpl->aFileBase + FilePath; + String Ext = FilePath.GetExtension(); + if ( Ext.CompareIgnoreCaseToAscii("Win") == COMPARE_EQUAL ) + { + ReadNames( FilePath.GetFull(),m_pControls,pUIds); + pImpl->bLnaguageExtensionLoaded = TRUE; + SfxSimpleHint aHint( SBX_HINT_LANGUAGE_EXTENSION_LOADED ); + GetTTBroadcaster().Broadcast( aHint ); + } + else if ( Ext.CompareIgnoreCaseToAscii("Sid") == COMPARE_EQUAL ) + { + ReadNames( FilePath.GetFull(),m_pSIds,pUIds,FLAT); + pImpl->bLnaguageExtensionLoaded = TRUE; + SfxSimpleHint aHint( SBX_HINT_LANGUAGE_EXTENSION_LOADED ); + GetTTBroadcaster().Broadcast( aHint ); + } + else if ( Ext.CompareIgnoreCaseToAscii("Bin") == COMPARE_EQUAL ) + { + ReadNamesBin( FilePath.GetFull(), m_pSIds, m_pControls ); + pImpl->bLnaguageExtensionLoaded = TRUE; + SfxSimpleHint aHint( SBX_HINT_LANGUAGE_EXTENSION_LOADED ); + GetTTBroadcaster().Broadcast( aHint ); + } + else if ( Ext.CompareIgnoreCaseToAscii("Inc") == COMPARE_EQUAL ) + { + { + TTExecutionStatusHint aHint( TT_EXECUTION_SHOW_ACTION, String(SttResId(S_READING_BASIC_MODULE)), FilePath.GetFull() ); + GetTTBroadcaster().Broadcast( aHint ); + } + String aFullPathname = FilePath.GetFull(); + StarBASIC *pBasic = (StarBASIC*)GetParent(); + if ( !aModuleWinExistsHdl.Call( &aFullPathname ) && + !pBasic->FindModule( CUniString( "--" ).Append(aFullPathname) ) ) + { + SbModule *pMod; + pMod = pBasic->MakeModule( CUniString("--"), String() ); + pMod->Clear(); + if ( Load( aFullPathname, pMod ) ) + { + if ( !IS_ERROR() ) + { + pBasic->Compile( pMod ); + pMod->RunInit(); + } + } + else + { + ADD_ERROR( SbxERR_CANNOT_LOAD, FilePath.GetFull() ); + } + } + { + TTExecutionStatusHint aHint( TT_EXECUTION_HIDE_ACTION ); + GetTTBroadcaster().Broadcast( aHint ); + } + } + else + { + ADD_ERROR(SbxERR_CANNOT_LOAD,FilePath.GetFull()); + } + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_FinishUse: + if ( !rPar ) // rPar = NULL <=> Kein Parameter + { + ADD_CASE_LOG( String() ); // Case abschliessen + if (!m_pControls) + m_pControls = new CNames(); + + if (!m_pSIds) + m_pSIds = new CNames(); + + if (pUIds) + { // save some memory + delete pUIds; + pUIds = NULL; + } + + m_pNameKontext = m_pControls; + + if ( pImpl->bLnaguageExtensionLoaded ) + { + SfxSimpleHint aHint( SBX_HINT_LANGUAGE_EXTENSION_LOADED ); + GetTTBroadcaster().Broadcast( aHint ); + } + + pImpl->nIncludeFileWarningCount = pImpl->nWarningCount; + pImpl->nWarningCount = 0; + + *pImpl->xIncludeFileWarningList = *pImpl->xWarningList; + pImpl->xWarningList->SbxArray::Clear(); + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_CaseLog: + if ( rPar ) // rPar != NULL <=> Es gibt Parameter + { + USHORT n; + String aX; + for ( n = 1; n < rPar->Count(); n++ ) + { + SbxVariableRef pArg = rPar->Get( n ); + aX += pArg->GetString(); + } + pImpl->aTestCaseName = aX; + if ( pImpl->aTestCaseName.Len() && BasicRuntimeAccess::HasRuntime() ) + { + BasicRuntime aRun = BasicRuntimeAccess::GetRuntime(); + pImpl->aTestCaseFileName = aRun.GetModuleName(SbxNAME_SHORT_TYPES); + if ( pImpl->aTestCaseFileName.Copy(0,2).CompareToAscii( "--" ) == COMPARE_EQUAL ) + pImpl->aTestCaseFileName.Erase(0,2); + pImpl->nTestCaseLineNr = aRun.GetLine(); + } + else + { + pImpl->aTestCaseFileName.Erase(); + pImpl->nTestCaseLineNr = 0; + } + ADD_CASE_LOG( aX ); + } + break; + case ID_ExceptLog: + if ( IS_ERROR() ) + { + BasicRuntime aRun = BasicRuntimeAccess::GetRuntime(); + BOOL bWasNewError = FALSE; + + if ( BasicRuntimeAccess::HasStack() ) + { + for ( USHORT i = 0 ; i < BasicRuntimeAccess::GetStackEntryCount() -1 ; i++ ) + { + BasicErrorStackEntry aThisEntry = BasicRuntimeAccess::GetStackEntry(i); + if ( !bWasNewError ) + { + bWasNewError = TRUE; + ADD_ERROR_LOG( GET_ERROR()->aText, aThisEntry.GetModuleName(SbxNAME_SHORT_TYPES), + aThisEntry.GetLine(), aThisEntry.GetCol1(), aThisEntry.GetCol2(), aThisEntry.GetSourceRevision() ); + } + ADD_CALL_STACK_LOG( String(aThisEntry.GetModuleName(SbxNAME_SHORT_TYPES)) + .AppendAscii(": ").Append(aThisEntry.GetMethodName(SbxNAME_SHORT_TYPES)), + aThisEntry.GetModuleName(SbxNAME_SHORT_TYPES), + aThisEntry.GetLine(), aThisEntry.GetCol1(), aThisEntry.GetCol2() ); + + } + BasicRuntimeAccess::DeleteStack(); + } + + BOOL bIsFirst = TRUE; + while ( aRun.IsValid() ) + { + xub_StrLen nErrLn; + xub_StrLen nCol1; + xub_StrLen nCol2; + if ( bIsFirst ) + { + bIsFirst = FALSE; + nErrLn = GET_ERROR()->nLine; + nCol1 = GET_ERROR()->nCol1; + nCol2 = GET_ERROR()->nCol2; + } + else + { + nErrLn = aRun.GetLine(); + nCol1 = aRun.GetCol1(); + nCol2 = aRun.GetCol2(); + } + + if ( !bWasNewError ) + { + bWasNewError = TRUE; + ADD_ERROR_LOG( GET_ERROR()->aText, aRun.GetModuleName(SbxNAME_SHORT_TYPES), + nErrLn, nCol1, nCol2, aRun.GetSourceRevision() ); + } + ADD_CALL_STACK_LOG( String(aRun.GetModuleName(SbxNAME_SHORT_TYPES)) + .AppendAscii(": ").Append(aRun.GetMethodName(SbxNAME_SHORT_TYPES)), + aRun.GetModuleName(SbxNAME_SHORT_TYPES), + nErrLn, nCol1, nCol2 ); + aRun = aRun.GetNextRuntime(); + } + } + break; + case ID_ErrorLog: + if ( IS_ERROR() ) + { + BasicRuntime aRun = BasicRuntimeAccess::GetRuntime(); + if ( BasicRuntimeAccess::HasStack() ) + { + BasicErrorStackEntry aThisEntry = BasicRuntimeAccess::GetStackEntry( 0 ); + ADD_ERROR_LOG( GET_ERROR()->aText, aThisEntry.GetModuleName(SbxNAME_SHORT_TYPES), + aThisEntry.GetLine(), aThisEntry.GetCol1(), aThisEntry.GetCol2(), aThisEntry.GetSourceRevision() ); + BasicRuntimeAccess::DeleteStack(); + } + else + { + ADD_ERROR_LOG( GET_ERROR()->aText, aRun.GetModuleName(SbxNAME_SHORT_TYPES), + StarBASIC::GetErl(), aRun.GetCol1(), aRun.GetCol2(), aRun.GetSourceRevision() ); + } + } + break; + case ID_QAErrorLog: + if ( rPar ) // rPar != NULL <=> Es gibt Parameter + { + USHORT n; + String aSammel; + for ( n = 1; n < rPar->Count(); n++ ) + { + SbxVariableRef pArg = rPar->Get( n ); + aSammel += pArg->GetString(); + } + ADD_QA_ERROR_LOG( aSammel ); + } + break; + case ID_PrintLog: + if ( rPar ) // rPar != NULL <=> Es gibt Parameter + { + USHORT n; + String aSammel; + for ( n = 1; n < rPar->Count(); n++ ) + { + SbxVariableRef pArg = rPar->Get( n ); + aSammel += pArg->GetString(); + } + ADD_MESSAGE_LOG( aSammel ); + } + break; + case ID_WarnLog: + if ( rPar ) // rPar != NULL <=> Es gibt Parameter + { + USHORT n; + String aSammel; + for ( n = 1; n < rPar->Count(); n++ ) + { + SbxVariableRef pArg = rPar->Get( n ); + aSammel += pArg->GetString(); + } + ADD_WARNING_LOG( aSammel ); + + } + break; + case ID_ClearError: + while ( IS_ERROR() ) + { + POP_ERROR(); + } + break; + case ID_MaybeAddErr: + if ( ((StarBASIC*)GetParent())->GetErrBasic() && ( !IS_ERROR() || + pFehlerListe->GetObject(pFehlerListe->Count()-1)->nError != ((StarBASIC*)GetParent())->GetErrBasic() ) ) + { + ((StarBASIC*)GetParent())->MakeErrorText(((StarBASIC*)GetParent())->GetErrBasic(),String()); + ADD_ERROR_QUIET(((StarBASIC*)GetParent())->GetErrBasic() , ((StarBASIC*)GetParent())->GetErrorText()) + } + break; + case ID_GetNextCloseWindow: + if ( !rPar ) // rPar = NULL <=> Kein Parameter + { + SetError( SbxERR_NOTIMP ); + break; + +// Das ist total rotten und mu� wohl komplett neu!! + + +/* BOOL bWasBlock = IsBlock; + if ( !IsBlock ) // Impliziter call bei Aufruf mit Methode + if ( SingleCommandBlock ) + BeginBlock(); +// if ( !IsError() ) +// In->GenCmdSlot (128,rPar); +// ((Controls*)pVar)->pMethodVar->nValue = 128; + + ULONG nOldValue = ((Controls*)pVar)->GetULong(); + // Setzen, so da� beim Return der Wert stimmt + ((Controls*)pVar)->PutULong( 128 ); + pImpl->pNextReturn = ((Controls*)pVar)->pMethodVar; + if ( SingleCommandBlock ) + EndBlock(); + WaitForAnswer(); + if ( bWasBlock ) + if ( SingleCommandBlock ) + BeginBlock(); + ((Controls*)pVar)->PutULong( nOldValue ); + + // R�cksetzen, so da� beim n�chsten Aufruf alles klappt +// ((Controls*)pVar)->SetUserData( 128 ); + + +// ((Controls*)pVar)->SetName("xxx"); + // Setzen und r�cksetzen der ID, so dass der Notify ohne Wirkung bleibt. + ((Controls*)pVar)->pMethodVar->SetUserData(ID_ErrorDummy); + ((Controls*)pVar)->PutULong( ((Controls*)pVar)->pMethodVar->GetULong() ); + ((Controls*)pVar)->pMethodVar->SetUserData(ID_Control); + + pShortNames->Insert( CUniString("xxx"), SmartId( ((Controls*)pVar)->pMethodVar->nValue ), nSequence ); + + nOldValue = ((Controls*)pVar)->GetULong(); + + SbxVariable *pMember; + if ( ! (pMember = ((Controls*)pVar)->Find(CUniString("ID"),SbxCLASS_DONTCARE)) ) + { + pMember = new SbxProperty(CUniString("ID"),SbxVARIANT); + ((Controls*)pVar)->Insert(pMember); + } + pMember->PutULong(((Controls*)pVar)->pMethodVar->nValue); + + if ( ! (pMember = ((Controls*)pVar)->Find(CUniString("name"),SbxCLASS_DONTCARE)) ) + { + pMember = NULL; + } + else + pMember->PutString(CUniString("xxx")); + + */ + + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_RemoteCommand: + { + if ( SingleCommandBlock ) + BeginBlock(); + else + if ( ((SbxTransportMethod*)pVar)->nValue & M_WITH_RETURN ) + { + SetError( SbxERR_NOTIMP ); + } + if ( !IsError() ) + In->GenCmdCommand ((USHORT)(((SbxTransportMethod*)pVar)->nValue),rPar); + if ( !IsError() && ((SbxTransportMethod*)pVar)->nValue & M_WITH_RETURN ) + { + pImpl->pNextReturn = ((SbxTransportMethod*)pVar); + aNextReturnId = SmartId( ((SbxTransportMethod*)pVar)->nValue ); + } + if ( SingleCommandBlock ) + EndBlock(); + if ( !IsError() && (USHORT)((SbxTransportMethod*)pVar)->nValue & M_WITH_RETURN ) + { + WaitForAnswer(); + } + // f�r einige noch etwas Nachbehandlung + switch ( ((SbxTransportMethod*)pVar)->nValue ) + { + case RC_WinTree: +// ::svt::OStringTransfer::CopyString(pVar->GetString(), pSomeWindowIDontHave ); + break; + } + + } + break; + case ID_Dispatch: + if ( !rPar || (rPar->Count() % 2) == 1 ) // rPar = NULL <=> Kein Parameter ansonsten Gerade Anzahl(Ungerade, da immer Anzahl+1 + { + if ( SingleCommandBlock ) + BeginBlock(); + if ( !IsError() ) + In->GenCmdSlot ( (USHORT)((SbxTransportMethod*)pVar)->nValue, rPar ); + pVar->PutInteger( (USHORT)((SbxTransportMethod*)pVar)->nValue ); + if ( SingleCommandBlock ) + EndBlock(); + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_UNODispatch: + if ( !rPar ) // rPar = NULL <=> Kein Parameter ansonsten Gerade Anzahl(Ungerade, da immer Anzahl+1 + { + if ( SingleCommandBlock ) + BeginBlock(); + if ( !IsError() ) + In->GenCmdUNOSlot ( ((SbxTransportMethod*)pVar)->aUnoSlot ); + pVar->PutString( ((SbxTransportMethod*)pVar)->aUnoSlot ); + if ( SingleCommandBlock ) + EndBlock(); + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_Control: + case ID_StringControl: + // if only the object is given in the script we don't have to do anything (object stands for itself) + if ( !pVar->ISA( SbxObject ) ) + { + if ( SingleCommandBlock ) + BeginBlock(); + else + if ( ((SbxTransportMethod*)pVar)->nValue & M_WITH_RETURN ) + { + SetError( SbxERR_NOTIMP ); + } + if ( !IsError() ) + { + SbxVariable *pMember = NULL; + if ( pVar->GetParent() ) + pMember = pVar->GetParent()->Find(CUniString("ID"),SbxCLASS_DONTCARE); + if ( pMember == NULL ) + { + SetError( SbxERR_NAMED_NOT_FOUND ); + } + else + { + if ( nHintUserData == ID_Control ) + { + In->GenCmdControl (pMember->GetULong(), + (USHORT)((SbxTransportMethod*)pVar)->nValue, rPar); + aNextReturnId = SmartId( pMember->GetULong() ); + } + else + { + In->GenCmdControl (pMember->GetString(), + (USHORT)((SbxTransportMethod*)pVar)->nValue, rPar); + aNextReturnId = SmartId( pMember->GetString() ); + } + } + + if ( !IsError() && ((SbxTransportMethod*)pVar)->nValue & M_WITH_RETURN ) + { + pImpl->pNextReturn = ((SbxTransportMethod*)pVar); + } + else + { + pImpl->pNextReturn = NULL; + aNextReturnId = SmartId(); + } + + } + if ( SingleCommandBlock ) + EndBlock(); + if ( !IsError() && (USHORT)((SbxTransportMethod*)pVar)->nValue & M_WITH_RETURN ) + { + WaitForAnswer(); + } + } + + break; + case ID_GetUnoApp: + { + // Hier wird der Remote UNO Kram gestartet + // Eintrag in die Konfiguration unter + // org.openoffice.Office.Common/Start/Connection + // socket,host=0,port=12345;iiop;XBla + // oder + // socket,host=0,port=12345;urp;;XBla + + String aString; + aString.AppendAscii( "socket,host=" ); + aString += GetHostConfig(); + aString.AppendAscii( ",port=" ); + aString += String::CreateFromInt32( GetUnoPortConfig() ); + + Reference< XMultiServiceFactory > smgr_xMultiserviceFactory; + try + { + Reference< XMultiServiceFactory > xSMgr = comphelper::getProcessServiceFactory(); +// is allways there +/* if ( ! xSMgr.is() ) + { + xSMgr = ::cppu::createRegistryServiceFactory(OUString(RTL_CONSTASCII_USTRINGPARAM("applicat.rdb")), sal_True ); + if ( xSMgr.is() ) + comphelper::setProcessServiceFactory( xSMgr ); + }*/ + + OUString aURL( aString ); + Reference< XConnector > xConnector( xSMgr->createInstance( + OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector") ) ), UNO_QUERY ); + Reference< XConnection > xConnection( xConnector->connect( aURL ) ); + + Reference< XBridgeFactory > xBridgeFactory( xSMgr->createInstance( + OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory") ) ), UNO_QUERY ); + Reference< XBridge > xBridge( xBridgeFactory->createBridge( + OUString(), OUString( RTL_CONSTASCII_USTRINGPARAM("urp") ), + xConnection, Reference< XInstanceProvider >() ) ); + + // Reference< XInterface > xRet( xBridge->getInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")) ) ); + Reference< XInterface > xRet( xBridge->getInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("StarOffice.ServiceManager")) ) ); + + // Reference< XNamingService > xNamingService(xRet, UNO_QUERY); + + // Reference< XInterface > smgr = xNamingService->getRegisteredObject( OUString( RTL_CONSTASCII_USTRINGPARAM("StarOffice.ServiceManager" ) ) ); + + smgr_xMultiserviceFactory = Reference< XMultiServiceFactory >(xRet, UNO_QUERY); + //MBA fragen!! + } + catch( class Exception & rEx) + { + ADD_ERROR(SbxERR_BAD_ACTION, String( rEx.Message ) ); + } + catch( ... ) + { + ADD_ERROR(SbxERR_BAD_ACTION, CUniString( "Unknown Error" ) ); + } + + if( smgr_xMultiserviceFactory.is() ) + { + Any aAny; +// aAny <<= xBridge; + aAny <<= smgr_xMultiserviceFactory; + + SbxObjectRef xMySbxObj = GetSbUnoObject( CUniString("RemoteUnoAppFuerTesttool"), aAny ); + if ( xMySbxObj.Is() ) + pVar->PutObject( xMySbxObj ); + } + } + break; + case ID_GetIServer: + { + // Hier wird der Remote UNO Kram gestartet + + String aString; +// aString += GetHostConfig(); +// aString.AppendAscii( ":" ); +// aString += String::CreateFromInt32( GetUnoPortConfig() ); + + Reference< XMultiServiceFactory > xSMgr /* = comphelper::getProcessServiceFactory()*/; +// if ( ! xSMgr.is() ) + { + xSMgr = ::cppu::createRegistryServiceFactory(OUString(RTL_CONSTASCII_USTRINGPARAM("g:\\iserverproxy.rdb")), sal_True); +// comphelper::setProcessServiceFactory( xSMgr ); + } + + OUString aURL( aString ); + Reference< XConnector > xConnector( xSMgr->createInstance( + OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector") ) ), UNO_QUERY ); + Reference< XConnection > xConnection( xConnector->connect( OUString( RTL_CONSTASCII_USTRINGPARAM("socket,host=grande,port=7453")) ) ); + + Reference< XBridgeFactory > xBridgeFactory( xSMgr->createInstance( + OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory") ) ), UNO_QUERY ); + Reference< XBridge > xBridge( xBridgeFactory->createBridge( + OUString(), OUString( RTL_CONSTASCII_USTRINGPARAM("urp") ), + xConnection, Reference< XInstanceProvider >() ) ); + + Reference< XInterface > xRet( xBridge->getInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("XIServerProxy")) ) ); + + +/* Reference< XIServerProxy > xIS( xRet, UNO_QUERY ); + if ( xIS.is() ) + { + String aHost( xIS->getIServerHost() ); + +// Reference < XInformationClient > xIC = xIS->createIServerClient( "XInformationClient" ); + Reference < XInformationClient > xIC = xIS->createInformationClient(); + xIC->getTree(OUString::createFromAscii("r:\\b_server\\config\\stand.lst"), OUString() ); + + + Reference< XTypeProvider > xTP( xRet, UNO_QUERY ); + Sequence < com::sun::star::uno::Type > s = xTP->getTypes(); + } + */ + + if( xRet.is() ) + { + Any aAny; + aAny <<= xRet; + + SbxObjectRef xMySbxObj = GetSbUnoObject( CUniString("IServerProxy"), aAny ); + if ( xMySbxObj.Is() ) + pVar->PutObject( xMySbxObj ); + } + // In Basic: + // msgbox dbg_SupportedInterfaces + // msgbox dbg_Properties + // msgbox dbg_Methods + } + break; + case ID_RemoteCommandDelay: + if ( rPar && rPar->Count() >= 2 && rPar->Count() <=3 ) + { + switch (rPar->Get( 1 )->GetType()) + { + case SbxLONG: // alles immer als Short �bertragen + case SbxULONG: + case SbxLONG64: + case SbxULONG64: + case SbxDOUBLE: + case SbxINTEGER: + case SbxBYTE: + case SbxUSHORT: + case SbxINT: + case SbxUINT: + case SbxSINGLE: + pImpl->nMinRemoteCommandDelay = rPar->Get( 1 )->GetULong(); + if ( rPar->Count() == 3 ) + pImpl->nMaxRemoteCommandDelay = rPar->Get( 2 )->GetULong(); + else + pImpl->nMaxRemoteCommandDelay = pImpl->nMinRemoteCommandDelay; + break; + case SbxBOOL: + pImpl->bDoRemoteCommandDelay = rPar->Get( 1 )->GetBool(); + break; + default: + SbxBase::SetError( SbxERR_WRONG_ARGS ); + break; + } + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_GetApplicationPath: + if ( !rPar ) + { + OUString aUrl = Config::GetDefDirectory(); + OUString aPath; + osl::FileBase::getSystemPathFromFileURL( aUrl, aPath ); + pVar->PutString( String( aPath ) ); + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_GetCommonApplicationPath: + if ( !rPar ) + { +#ifdef WNT + //////// adapted this from setup2\win\source\system\winos.cxx + String aSysPath; + aSysPath = _SHGetSpecialFolder_COMMON_APPDATA(); + if ( aSysPath.Len() ) + { + pVar->PutString( aSysPath ); + } + else // default to ID_GetApplicationPath (same as in setup) + { + OUString aUrl = Config::GetDefDirectory(); + OUString aPath; + osl::FileBase::getSystemPathFromFileURL( aUrl, aPath ); + pVar->PutString( String( aPath ) ); + } +#elif defined OS2 + { + char* etc = getenv("ETC"); + if (etc) + pVar->PutString( CUniString( etc ) ); + else + pVar->PutString( CUniString( "/etc" ) ); + } +#else +#if UNX + pVar->PutString( CUniString( "/etc" ) ); +#else +#error not implemented +#endif +#endif + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_MakeIniFileName: + if ( rPar && rPar->Count() == 2 ) + { + OUString aUrl = Config::GetConfigName( String(), rPar->Get( 1 )->GetString() ); + OUString aPath; + osl::FileBase::getSystemPathFromFileURL( aUrl, aPath ); + pVar->PutString( String( aPath ) ); + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_Wait: + { + if( rPar && rPar->Count() == 2 ) + { + long nWait = rPar->Get(1)->GetLong(); + if( nWait >= 0 ) + { +#ifdef DEBUG + Time aStart; +#endif + Timer aTimer; + aTimer.SetTimeout( nWait ); + aTimer.Start(); + while ( aTimer.IsActive() ) + Application::Yield(); +#ifdef DEBUG + Time aEnd; + Time aDiff = aEnd - aStart; + long aMS = long( aDiff.GetMSFromTime() ); + if ( Abs( aMS - nWait ) > 100 ) + { + DBG_ERROR1("Wait was off limit by %i", aDiff.GetMSFromTime() - nWait ); + } +#endif + } + } + else + SetError( SbERR_BAD_NUMBER_OF_ARGS ); + } + break; + case ID_GetErrorCount: + { + pVar->PutULong( pImpl->nErrorCount ); + } + break; + case ID_GetWarningCount: + { + pVar->PutULong( pImpl->nWarningCount ); + } + break; + case ID_GetQAErrorCount: + { + pVar->PutULong( pImpl->nQAErrorCount ); + } + break; + case ID_GetUseFileWarningCount: + { + pVar->PutULong( pImpl->nIncludeFileWarningCount ); + } + break; + case ID_GetErrorList: + { + if ( ! pImpl->xErrorList->GetDims() ) + pImpl->xErrorList->AddDim( 1, 32000 ); + pVar->PutObject( pImpl->xErrorList ); + } + break; + case ID_GetWarningList: + { + if ( ! pImpl->xWarningList->GetDims() ) + pImpl->xWarningList->AddDim( 1, 32000 ); + pVar->PutObject( pImpl->xWarningList ); + } + break; + case ID_GetQAErrorList: + { + if ( ! pImpl->xQAErrorList->GetDims() ) + pImpl->xQAErrorList->AddDim( 1, 32000 ); + pVar->PutObject( pImpl->xQAErrorList ); + } + break; + case ID_GetUseFileWarningList: + { + if ( ! pImpl->xIncludeFileWarningList->GetDims() ) + pImpl->xIncludeFileWarningList->AddDim( 1, 32000 ); + pVar->PutObject( pImpl->xIncludeFileWarningList ); + } + break; + case ID_GetTestCaseName: + { + pVar->PutString( pImpl->aTestCaseName ); + } + break; + case ID_GetTestCaseFileName: + { + pVar->PutString( pImpl->aTestCaseFileName ); + } + break; + case ID_GetTestCaseLineNr: + { + pVar->PutUShort( pImpl->nTestCaseLineNr ); + } + break; + case ID_SetChildEnv: + { + if( rPar && rPar->Count() == 3 ) + { + pImpl->pChildEnv->erase( rPar->Get(1)->GetString() ); + pImpl->pChildEnv->insert( EnvironmentVariable( rPar->Get(1)->GetString(), rPar->Get(2)->GetString() ) ); + } + else + SetError( SbERR_BAD_NUMBER_OF_ARGS ); + } + break; + case ID_GetChildEnv: + { + if( rPar && rPar->Count() == 2 ) + { + Environment::const_iterator aIter = pImpl->pChildEnv->find( rPar->Get(1)->GetString() ); + if ( aIter != pImpl->pChildEnv->end() ) + pVar->PutString( (*aIter).second ); + else + pVar->PutString( String() ); + } + else + SetError( SbERR_BAD_NUMBER_OF_ARGS ); + } + break; + case ID_GetLinkDestination: + { + if( rPar && rPar->Count() == 2 ) + { + String aSource,aDest; + aSource = rPar->Get(1)->GetString(); +#ifdef UNX + ByteString aByteSource( aSource, osl_getThreadTextEncoding() ); + char cDest[1024]; + int nLen = 0; + if ( ( nLen = readlink( aByteSource.GetBuffer(), cDest, sizeof(cDest) ) ) >= 0 ) + { + aDest = String( cDest, nLen, osl_getThreadTextEncoding() ); + } + else + { + int nErr = errno; + switch ( nErr ) + { + case EINVAL: aDest = aSource; + break; + default: + SetError( SbERR_ACCESS_ERROR ); + } + } +#else + aDest = aSource; +#endif + pVar->PutString( aDest ); + } + else + SetError( SbERR_BAD_NUMBER_OF_ARGS ); + } + break; + case ID_GetRegistryValue: + { + if( rPar && rPar->Count() == 3 ) + { + String aValue; +#ifdef WNT + aValue = ReadRegistry( rPar->Get(1)->GetString(), rPar->Get(2)->GetString() ); +#endif + pVar->PutString( aValue ); + } + else + SetError( SbERR_BAD_NUMBER_OF_ARGS ); + } + break; + case ID_HTTPSend: + { + if( rPar && ( rPar->Count() == 4 || rPar->Count() == 5 ) ) + { + if ( !pImpl->pHttpRequest ) + pImpl->pHttpRequest = new HttpRequest; + pImpl->pHttpRequest->SetRequest( ByteString( rPar->Get(1)->GetString(), RTL_TEXTENCODING_ASCII_US ), ByteString( rPar->Get(2)->GetString(), RTL_TEXTENCODING_ASCII_US ), rPar->Get(3)->GetUShort() ); + + if ( pImpl->pHttpRequest->Execute() ) + { + if ( rPar->Count() == 5 ) + { // filename is given + SvFileStream aDestination( rPar->Get(4)->GetString(), STREAM_STD_READWRITE | STREAM_TRUNC ); + (*(pImpl->pHttpRequest->GetBody())) >> aDestination; + if ( aDestination.GetError() != ERRCODE_NONE ) + SetError( SbERR_ACCESS_ERROR ); + aDestination.Close(); + } + pVar->PutUShort( pImpl->pHttpRequest->GetResultId() ); + } + else + SetError( SbERR_ACCESS_ERROR ); + } + else + SetError( SbERR_BAD_NUMBER_OF_ARGS ); + } + break; + case ID_HTTPSetProxy: + { + if( rPar && rPar->Count() == 3 ) + { + if ( !pImpl->pHttpRequest ) + pImpl->pHttpRequest = new HttpRequest; + pImpl->pHttpRequest->SetProxy( ByteString( rPar->Get(1)->GetString(), RTL_TEXTENCODING_ASCII_US ), rPar->Get(2)->GetUShort() ); + } + else + SetError( SbERR_BAD_NUMBER_OF_ARGS ); + } + break; + } // switch( nHintUserData ) + } // if( nHintId == SBX_HINT_DATAWANTED ) + else if( nHintId == SBX_HINT_DATACHANGED ) + { + switch( nHintUserData ) + { + case ID_AutoExecute: + if ( !rPar ) // rPar = NULL <=> Kein Parameter + { + SingleCommandBlock = pVar->GetBool(); + if ( SingleCommandBlock ) + EndBlock(); + else + BeginBlock(); + } + else + SetError( SbxERR_WRONG_ARGS ); + break; + case ID_EnableQaErrors: + if ( !rPar ) // rPar = NULL <=> Kein Parameter + pImpl->bEnableQaErrors = pVar->GetBool(); + else + SetError( SbxERR_WRONG_ARGS ); + break; + } + } // if( nHintId == SBX_HINT_DATACHANGED ) + else if( nHintId == SBX_HINT_BASICSTART ) + { + pImpl->nErrorCount = 0; + pImpl->nWarningCount = 0; + pImpl->nQAErrorCount = 0; + pImpl->nIncludeFileWarningCount = 0; + + pImpl->xErrorList->SbxArray::Clear(); // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content + pImpl->xWarningList->SbxArray::Clear(); // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content + pImpl->xQAErrorList->SbxArray::Clear(); // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content + pImpl->xIncludeFileWarningList->SbxArray::Clear(); // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content + + if (pFehlerListe) + delete pFehlerListe; + pFehlerListe = new CErrors; + + for (USHORT i=0;i<VAR_POOL_SIZE;i++) + { + pImpl->pMyVars[i]->SetName( CUniString("VarDummy").Append(UniString::CreateFromInt32(i)) ); + } + nMyVar = 0; + + } // if( nHintId == SBX_HINT_BASICSTART ) + else if( nHintId == SBX_HINT_BASICSTOP ) + { + // Log summary to journal + ADD_CASE_LOG( String() ); // Case abschliessen + ADD_MESSAGE_LOG( CUniString("***************************************************") ); + if ( pImpl->nErrorCount ) + { + ADD_WARNING_LOG( GEN_RES_STR1( S_ERRORS_DETECTED, String::CreateFromInt32( pImpl->nErrorCount ) ) ); + pImpl->nWarningCount--; // Anpassen, da diese Warnung nicht in die Statistik soll + } + else + ADD_MESSAGE_LOG( GEN_RES_STR0( S_NO_ERRORS_DETECTED ) ); + + if ( pImpl->nWarningCount ) + ADD_WARNING_LOG( GEN_RES_STR1( S_WARNINGS_DETECTED, String::CreateFromInt32( pImpl->nWarningCount ) ) ) + else + ADD_MESSAGE_LOG( GEN_RES_STR0( S_NO_WARNINGS_DETECTED ) ); + + if ( pImpl->nIncludeFileWarningCount ) + ADD_WARNING_LOG( GEN_RES_STR1( S_INCLUDE_FILE_WARNINGS_DETECTED, String::CreateFromInt32( pImpl->nIncludeFileWarningCount ) ) ) + else + ADD_MESSAGE_LOG( GEN_RES_STR0( S_NO_INCLUDE_FILE_WARNINGS_DETECTED ) ); + ADD_MESSAGE_LOG( CUniString("***************************************************") ); + + pImpl->nErrorCount = 0; + pImpl->nWarningCount = 0; + pImpl->nQAErrorCount = 0; + pImpl->nIncludeFileWarningCount = 0; + + pImpl->xErrorList->SbxArray::Clear(); // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content + pImpl->xWarningList->SbxArray::Clear(); // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content + pImpl->xQAErrorList->SbxArray::Clear(); // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content + pImpl->xIncludeFileWarningList->SbxArray::Clear(); // call SbxArray::Clear because SbxVarArray::Clear only clears dimensions but no content + } // if( nHintId == SBX_HINT_BASICSTOP ) + WaitForAnswer(); + if ( IsError() && ( !IS_ERROR() || GET_ERROR()->nError != GetError() ) ) + { + ((StarBASIC*)GetParent())->MakeErrorText(GetError(),String()); + ADD_ERROR_QUIET(GetError(),String(pVar->GetName()).AppendAscii(": "). + Append(((StarBASIC*)GetParent())->GetErrorText())); + } + } +} + +void TestToolObj::DebugFindNoErrors( BOOL bDebugFindNoErrors ) +{ + pImpl->bDebugFindNoErrors = bDebugFindNoErrors; +} + +SbxVariable* TestToolObj::Find( const String& aStr, SbxClassType aType) +{ + if ( BasicRuntimeAccess::IsRunInit() ) // wegen Find im "Global" Befehl des Basic + return NULL; + + SbxVariableRef Old = SbxObject::Find(aStr, aType ); + // do not return any objects from pMyVars[] + if (Old && Old->GetUserData() != ID_Dispatch + && Old->GetUserData() != ID_UNODispatch + && Old->GetUserData() != ID_ErrorDummy + && Old->GetUserData() != 0 ) + return Old; + else if ( aStr.SearchAscii(":") != STRING_NOTFOUND ) + { // ignore qualified names e.g. main:FormWizard If this was removed an error would be generated + } + else + { + + USHORT nElement; + ControlDef *pWhatName = new ControlDef(aStr,SmartId()); + + /// nach Controls suchen + if (m_pNameKontext && m_pNameKontext->Seek_Entry(pWhatName,&nElement)) + { + delete pWhatName; + pWhatName = ((ControlDef*)m_pNameKontext->GetObject(nElement)); + +//// new Controls Object every time + pImpl->pControlsObj = new Controls( pWhatName->pData->Kurzname ); + pImpl->pControlsObj->SetType( SbxOBJECT ); + pImpl->pControlsObj->ChangeListener( this ); + + + // Will be set on method-child further down + if ( pWhatName->pData->aUId.HasNumeric() ) + pImpl->pControlsObj->SetUserData( ID_Control ); + else + pImpl->pControlsObj->SetUserData( ID_StringControl ); + + pShortNames->Insert(pWhatName->pData->Kurzname,pWhatName->pData->aUId,nSequence); + + SbxVariable *pMember = pImpl->pControlsObj->Find(CUniString("ID"),SbxCLASS_DONTCARE); + if ( pMember == NULL ) + { + SbxProperty* pID = new SbxProperty(CUniString("ID"),SbxVARIANT); + pImpl->pControlsObj->Insert(pID); + pImpl->pControlsObj->SetDfltProperty(pID); + pMember = pID; + } + if ( pWhatName->pData->aUId.HasNumeric() ) + pMember->PutULong(pWhatName->pData->aUId.GetNum()); + else + pMember->PutString(pWhatName->pData->aUId.GetStr()); + + pMember = pImpl->pControlsObj->Find(CUniString("name"),SbxCLASS_DONTCARE); + if ( pMember != NULL ) + pMember->PutString(pWhatName->pData->Kurzname); + + return pImpl->pControlsObj; + } + + /// Nach slots suchen + if (m_pSIds && m_pSIds->Seek_Entry(pWhatName,&nElement)) + { + SbxTransportMethodRef pMyVar; + pMyVar = pImpl->pMyVars[nMyVar++]; + if ( nMyVar >= VAR_POOL_SIZE ) + nMyVar = 0; + delete pWhatName; + pWhatName = ( (ControlDef*)m_pSIds->GetObject( nElement ) ); + pMyVar->SetName( pWhatName->pData->Kurzname ); + + if ( pWhatName->pData->aUId.HasNumeric() ) + { + pMyVar->SetUserData( ID_Dispatch ); + pMyVar->nValue = pWhatName->pData->aUId.GetNum(); + pShortNames->Insert( aStr, pWhatName->pData->aUId, nSequence ); + } + else + { + pMyVar->SetUserData( ID_UNODispatch ); + pMyVar->aUnoSlot = pWhatName->pData->aUId.GetStr(); + } + return pMyVar; + } + + /// es kann sich noch um eine SlotID handeln, die numerisch abgefragt wird, statt ausgef�hrt zu werden + if ( aStr.Copy( aStr.Len()-3, 3 ).CompareIgnoreCaseToAscii("_ID") == COMPARE_EQUAL && m_pSIds ) + { + delete pWhatName; + pWhatName = new ControlDef( aStr.Copy( 0, aStr.Len()-3 ), SmartId() ); + if ( m_pSIds->Seek_Entry( pWhatName, &nElement ) ) + { // Nach slots suchen + SbxVariable *pReturn = new SbxVariable; + delete pWhatName; + pWhatName = ( (ControlDef*)m_pSIds->GetObject( nElement ) ); + pReturn->SetName( pWhatName->pData->Kurzname ); + + if ( pWhatName->pData->aUId.HasNumeric() ) + pReturn->PutULong(pWhatName->pData->aUId.GetNum()); + else + pReturn->PutString(pWhatName->pData->aUId.GetStr()); + return pReturn; + } + } + if ( !pImpl->bDebugFindNoErrors ) + { + ADD_ERROR(SbxERR_PROC_UNDEFINED,GEN_RES_STR1(S_UNKNOWN_SLOT_CONTROL, aStr) ); + } + } + return NULL; +} + +String TestToolObj::GetRevision( String const &aSourceIn ) +{ + // search $Revision: 1.40 $ + xub_StrLen nPos; + if ( ( nPos = aSourceIn.SearchAscii( "$Revision:" ) ) != STRING_NOTFOUND ) + return aSourceIn.Copy( nPos+ 10, aSourceIn.SearchAscii( "$", nPos+10 ) -nPos-10); + else + return String::CreateFromAscii("No Revision found"); +} + +BOOL TestToolObj::CError( ULONG code, const String& rMsg, xub_StrLen l, xub_StrLen c1, xub_StrLen c2 ) +{ + bWasPrecompilerError = TRUE; + if ( aCErrorHdl.IsSet() ) + { + ErrorEntry aErrorEntry( code, rMsg, l, c1, c2 ); + return (BOOL)aCErrorHdl.Call( &aErrorEntry ); + } + else + { + ADD_ERROR( code, rMsg ) + return TRUE; + } +} + +void TestToolObj::CalcPosition( String const &aSource, xub_StrLen nPos, xub_StrLen &l, xub_StrLen &c ) +{ + l = 1; + xub_StrLen nAkt = 0; + xub_StrLen nNext; + while ( (nNext = aSource.Search( '\n', nAkt )) != STRING_NOTFOUND && nNext < nPos ) + { + l++; + nAkt = nNext+1; + } + c = nPos - nAkt; +} + + +#define CATCH_LABEL CUniString( "ctch" ) +#define CATCHRES_LABEL CUniString( "ctchres" ) +#define ENDCATCH_LABEL CUniString( "endctch" ) + +BOOL IsAlphaChar( sal_Unicode cChar ) +{ + return ( cChar >= 'a' && cChar <= 'z' ) || + ( cChar >= 'A' && cChar <= 'Z' ); +} + +BOOL IsInsideString( const String& aSource, const xub_StrLen nStart ) +{ + BOOL bInside = FALSE; + xub_StrLen nPos = nStart-1; + + while ( nPos && aSource.GetChar(nPos) != _CR && aSource.GetChar(nPos) != _LF ) + { + if ( aSource.GetChar(nPos) == '"' ) + bInside = !bInside; + nPos--; + } + return bInside; +} + +BOOL IsValidHit( const String& aSource, const xub_StrLen nStart, const xub_StrLen nEnd ) +{ + return !IsAlphaChar( aSource.GetChar(nStart-1) ) && !IsAlphaChar( aSource.GetChar(nEnd+1)) + && !IsInsideString( aSource, nStart ); +} + + +xub_StrLen TestToolObj::ImplSearch( const String &aSource, const xub_StrLen nStart, const xub_StrLen nEnd, const String &aSearch, const xub_StrLen nSearchStart ) +{ + xub_StrLen nPos = aSource.Search( aSearch, std::max( nSearchStart, nStart ) ); + if ( nPos > nEnd - aSearch.Len() || nPos == STRING_NOTFOUND ) + return STRING_NOTFOUND; + else + { + if ( IsValidHit( aSource, nPos, nPos+aSearch.Len()-1 ) ) + return nPos; + else + return ImplSearch( aSource, nStart, nEnd, aSearch, nPos+aSearch.Len() ); + } +} + +xub_StrLen TestToolObj::PreCompilePart( String &aSource, xub_StrLen nStart, xub_StrLen nEnd, String aFinalErrorLabel, USHORT &nLabelCount ) +{ + xub_StrLen nTry,nCatch,nEndcatch; + if( (nTry = ImplSearch( aSource, nStart, nEnd, CUniString("try"), nStart )) == STRING_NOTFOUND ) + return nEnd; + if ( (nCatch = ImplSearch( aSource, nStart, nEnd, CUniString("catch"), nTry )) == STRING_NOTFOUND ) + { + xub_StrLen l,c; + CalcPosition( aSource, nTry, l, c ); + CError( SbERR_BAD_BLOCK, CUniString("catch"), l, c, c+2 ); + return nEnd; + } + if ( (nEndcatch = ImplSearch( aSource, nStart, nEnd, CUniString("endcatch"), nCatch )) == STRING_NOTFOUND ) + { + xub_StrLen l,c; + CalcPosition( aSource, nCatch, l, c ); + CError( SbERR_BAD_BLOCK, CUniString("endcatch"), l, c, c+4 ); + return nEnd; + } + + nLabelCount++; + String aStr = String::CreateFromInt32( nLabelCount ); + String aCatchLabel(CATCH_LABEL); + aCatchLabel += aStr; + String aCatchresLabel(CATCHRES_LABEL); + aCatchresLabel += aStr; + String aEndcatchLabel( ENDCATCH_LABEL); + aEndcatchLabel += aStr; + + xub_StrLen nTry2 = 0; + while ( !WasPrecompilerError() && (nTry2 = ImplSearch( aSource, nStart, nEnd, CUniString("try"), nTry+1 )) != STRING_NOTFOUND ) + { // Wir rekursieren erstmal mit dem 2. Try + if ( nTry2 < nCatch ) + nEnd += PreCompilePart( aSource, nTry2, nEndcatch+8, aCatchLabel, nLabelCount ) - nEndcatch-8; + else + nEnd = PreCompilePart( aSource, nTry2, nEnd, aFinalErrorLabel, nLabelCount ); + + if ( (nCatch = ImplSearch( aSource, nStart, nEnd, CUniString("catch"), nTry )) == STRING_NOTFOUND ) + { + xub_StrLen l,c; + CalcPosition( aSource, nTry, l, c ); + CError( SbERR_BAD_BLOCK, CUniString("catch"), l, c, c+2 ); + return nEnd; + } + if ( (nEndcatch = ImplSearch( aSource, nStart, nEnd, CUniString("endcatch"), nCatch )) == STRING_NOTFOUND ) + { + xub_StrLen l,c; + CalcPosition( aSource, nCatch, l, c ); + CError( SbERR_BAD_BLOCK, CUniString("endcatch"), l, c, c+4 ); + return nEnd; + } + } + + String aReplacement; + int nTotalLength = -3 -5 -8; // try, catch und endcatch fallen raus + + aReplacement.AppendAscii( "on error goto " ); + aReplacement += aCatchLabel; + aSource.SearchAndReplaceAscii( "try", aReplacement, nTry ); + nTotalLength += aReplacement.Len(); + + +// on error goto endcse +// goto endctchXX +// ctchXX: +// if err = 35 or err = 18 then : resume : endif : +// MaybeAddErr +// on error goto endcse +// resume ctchresXX +// ctchresXX: + aReplacement.Erase(); + aReplacement.AppendAscii( "on error goto " ); + aReplacement += aFinalErrorLabel; + aReplacement.AppendAscii( " : goto " ); + aReplacement += aEndcatchLabel; + aReplacement.AppendAscii( " : " ); + aReplacement += aCatchLabel; + aReplacement.AppendAscii( ": if err = 35 or err = 18 then : on error goto 0 : resume : endif" ); + aReplacement.AppendAscii( " : MaybeAddErr : on error goto " ); + aReplacement += aFinalErrorLabel; + aReplacement.AppendAscii( " : resume " ); + aReplacement += aCatchresLabel; + aReplacement.AppendAscii( " : " ); + aReplacement += aCatchresLabel; + aReplacement.AppendAscii( ": " ); + aSource.SearchAndReplaceAscii( "catch", aReplacement, nCatch ); + nTotalLength += aReplacement.Len(); + + + aReplacement.Erase(); + aReplacement.AppendAscii("ClearError : "); + aReplacement += aEndcatchLabel; + aReplacement.AppendAscii(": "); + aSource.SearchAndReplaceAscii( "endcatch", aReplacement, nEndcatch ); + nTotalLength += aReplacement.Len(); + + if ( aSource.Len() >= STRING_MAXLEN ) + { + xub_StrLen l,c; + CalcPosition( aSource, nEndcatch, l, c ); + CError( SbERR_PROG_TOO_LARGE, CUniString("endcatch"), l, c, c+2 ); + } + + return xub_StrLen( nEnd + nTotalLength ); +} + + +void TestToolObj::PreCompileDispatchParts( String &aSource, String aStart, String aEnd, String aFinalLable ) +{ + USHORT nLabelCount = 0; + xub_StrLen nPartPos = 0; + + while ( !WasPrecompilerError() && (nPartPos = ImplSearch( aSource, nPartPos, aSource.Len(), aStart )) != STRING_NOTFOUND ) + { + xub_StrLen nEndPart = ImplSearch( aSource, nPartPos, aSource.Len(), aEnd ); + if ( nEndPart == STRING_NOTFOUND ) + return; + nPartPos = PreCompilePart( aSource, nPartPos, nEndPart, aFinalLable, nLabelCount ); + nPartPos = nPartPos + aEnd.Len(); + } +} + + +BOOL TestToolObj::WasPrecompilerError() +{ + return bWasPrecompilerError; +} + +String TestToolObj::PreCompile( String const &aSourceIn ) +{ + // Im CTOR zu fr�h, und hier grade nicg rechtzeitig. Start und Stop von Programmausf�hrung + StartListening( ((StarBASIC*)GetParent())->GetBroadcaster(), TRUE ); + + xub_StrLen nTestCase; + xub_StrLen nEndCase; + xub_StrLen nStartPos = 0; + String aSource(aSourceIn); + bWasPrecompilerError = FALSE; + +HACK("Ich gestehe alles: Ich war zu faul das richtig zu machen.") + aSource = String(' ').Append( aSource ); // Da Schl�sselworte an Position 0 sonst nicht gefunden werden + + +// Erstmal alle "'" Kommentare raus + + xub_StrLen nComment; + while ( (nComment = aSource.SearchAscii("'",nStartPos)) != STRING_NOTFOUND ) + { + USHORT nStringEndCount = 0; + xub_StrLen nIndex = nComment; + while ( nIndex && aSource.GetChar(nIndex) != '\n' ) + { + if ( aSource.GetChar(nIndex) == '"' ) + nStringEndCount++; + nIndex--; + } + if ( (nStringEndCount & 1) == 0 ) // Wir waren also nicht innerhalb eines Strings + { + xub_StrLen nComEnd = aSource.SearchAscii("\n",nComment); + + while ( aSource.GetChar(nComEnd) == _CR || aSource.GetChar(nComEnd) == _LF ) + nComEnd--; + + nComEnd++; + + aSource.Erase(nComment,nComEnd-nComment); + } + else + nComment++; + nStartPos = nComment; + } + + + PreCompileDispatchParts( aSource, CUniString("sub"), CUniString("end sub"), CUniString("0") ); + PreCompileDispatchParts( aSource, CUniString("function"), CUniString("end function"), CUniString("0") ); + PreCompileDispatchParts( aSource, CUniString("testcase"), CUniString("endcase"), CUniString("endcse") ); + + + xub_StrLen nMainPos = ImplSearch( aSource, 0, aSource.Len(), CUniString("sub main") ); + aSource.SearchAndReplaceAscii("sub main",CUniString("Sub Main StartUse : LoadIncludeFiles : FinishUse "), nMainPos ); + if ( aSource.Len() >= STRING_MAXLEN ) + { + xub_StrLen l,c; + CalcPosition( aSource, nMainPos, l, c ); + CError( SbERR_PROG_TOO_LARGE, CUniString("endcatch"), l, c, c+2 ); + } + + while ( (nTestCase = ImplSearch( aSource, 0, aSource.Len(), CUniString("testcase") ) ) != STRING_NOTFOUND ) + { + xub_StrLen nTcEnd = aSource.SearchAscii("\n",nTestCase); + + while ( aSource.GetChar(nTcEnd) == _CR || aSource.GetChar(nTcEnd) == _LF ) + nTcEnd--; + + nTcEnd++; + + if ( aSource.SearchAscii(":",nTestCase) < nTcEnd ) + nTcEnd = aSource.SearchAscii(":",nTestCase) -1; + String aSuffix = aSource.Copy(nTestCase+8,nTcEnd-nTestCase-8); + USHORT nOldLen; + do + { + nOldLen = aSuffix.Len(); + aSuffix.EraseLeadingAndTrailingChars( ' ' ); + aSuffix.EraseLeadingAndTrailingChars( 0x09 ); + } while ( nOldLen != aSuffix.Len() ); + aSource.Erase(nTestCase,nTcEnd-nTestCase); + aSource.Insert(CUniString("Sub ").Append(aSuffix).AppendAscii(" CaseLog \"").Append(aSuffix).AppendAscii("\" : on error goto endcse : TestEnter "),nTestCase); + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////// + // Attention!!! The lable endsub is officially used to exit a sub instead of using 'exit sub' or 'return' + ///////////////////////////////////////////////////////////////////////////////////////////////////////// + while ( (nEndCase = ImplSearch( aSource, 0, aSource.Len(), CUniString("endcase") ) ) != STRING_NOTFOUND ) + aSource.SearchAndReplaceAscii("endcase",CUniString("goto endsub : endcse: if ( err = 35 and StopOnSyntaxError ) or err = 18 then : on error goto 0 : resume : endif : MaybeAddErr : ExceptLog : resume endcse_res : endcse_res: on error goto 0 : endsub: TestExit : ClearError : CaseLog \"\" : end sub "), nEndCase ); + + if ( aSource.Len() >= STRING_MAXLEN ) + { + xub_StrLen l,c; + CalcPosition( aSource, 0, l, c ); + CError( SbERR_PROG_TOO_LARGE, CUniString("endcatch"), l, c, c+2 ); + } + return aSource; +} + +void TestToolObj::AddToListByNr( CNames *&pControls, ControlItemUId *&pNewItem ) +{ + USHORT nNr; + if ( pControls->Seek_Entry( pNewItem, &nNr ) ) + { + AddName( pControls->GetObject(nNr)->pData->Kurzname, pNewItem->pData->Kurzname ); + delete pNewItem; + pNewItem = (ControlItemUId*)pControls->GetObject(nNr); // f�r einf�gen der S�hne + } + else + { + ControlItem* pNI = pNewItem; + pControls->C40_PTR_INSERT(ControlItem,pNI); + } +} + +IMPL_LINK( TestToolObj, ReturnResultsLink, CommunicationLink*, pCommLink ) +{ + return ReturnResults( pCommLink->GetServiceData() ); +} + +void TestToolObj::ReadHidLstByNumber() +{ + // Die Hid.Lst nach Nummern sortiert einlesen + if ( !m_pReverseUIds ) + { + String aName = (pImpl->aHIDDir + DirEntry(CUniString("hid.lst"))).GetFull(); + + { + TTExecutionStatusHint aHint( TT_EXECUTION_SHOW_ACTION, String(SttResId(S_READING_LONGNAMES)), aName ); + GetTTBroadcaster().Broadcast( aHint ); + } + + ReadFlat( aName, m_pReverseUIds, FALSE ); + + { + TTExecutionStatusHint aHint( TT_EXECUTION_HIDE_ACTION ); + GetTTBroadcaster().Broadcast( aHint ); + } + } +} + +void TestToolObj::SortControlsByNumber( BOOL bIncludeActive ) +{ + // Die Controls einmal hirarchisch und einmal alle flach nach nummer sortiert + if ( !m_pReverseControls && !m_pReverseControlsSon && m_pControls ) + { + m_pReverseControls = new CNames; + m_pReverseControlsSon = new CNames; + USHORT nWin,nCont; + const String aSl('/'); + for ( nWin = 0 ; nWin < m_pControls->Count() ; nWin++ ) + { + String aFatherName( m_pControls->GetObject(nWin)->pData->Kurzname ); + ControlItemUId *pNewFather = new ControlItemUIdSon(aFatherName,m_pControls->GetObject(nWin)->pData->aUId); + AddToListByNr( m_pReverseControlsSon, pNewFather ); + if (! ((ControlItemUIdSon*)pNewFather)->GetSons() ) + ((ControlItemUIdSon*)pNewFather)->Sons( new CNames ); + + // Existieren S�hne, diese in beide Listen eintragen + CNames *pControlList = ((ControlItemSon*)m_pControls->GetObject(nWin))->GetSons(); + if ( pControlList ) + for ( nCont = 0 ; nCont < pControlList->Count() ; nCont++ ) + { + ControlItemUId *pNewItem; + + String aCombinedName( aFatherName ); + aCombinedName.AppendAscii( ":" ); + aCombinedName.Append( pControlList->GetObject(nCont)->pData->Kurzname ); + pNewItem = new ControlItemUId( aCombinedName, pControlList->GetObject(nCont)->pData->aUId ); + AddToListByNr( m_pReverseControls, pNewItem ); + + pNewItem = new ControlItemUId( pControlList->GetObject(nCont)->pData->Kurzname, pControlList->GetObject(nCont)->pData->aUId ); + AddToListByNr( ((ControlItemUIdSon*)pNewFather)->GetSons(), pNewItem ); + } + } + if ( !bIncludeActive ) + { + ControlItem *pZeroItem = new ControlItemUId( UniString(), SmartId(0) ); + USHORT nNr; + if ( m_pReverseControls->Seek_Entry( pZeroItem, &nNr ) ) + { + m_pReverseControls->DeleteAndDestroy( nNr ); +// um VorlagenLaden/UntergeordneteIniDatei/SpeichernDlg/OrdnerDlg/OeffnenDlg/MessageBox/LetzteVersion/GrafikEinfuegenDlg/FarbeDlg/ExportierenDlg/DruckerEinrichten/DruckenDlg/DateiEinfuegenDlg/Active zu verhindern + } +/* if ( m_pReverseControlsSon->Seek_Entry( pZeroItem, &nNr ) ) + { + m_pReverseControlsSon->DeleteAndDestroy( nNr ); +// um VorlagenLaden/UntergeordneteIniDatei/SpeichernDlg/OrdnerDlg/OeffnenDlg/MessageBox/LetzteVersion/GrafikEinfuegenDlg/FarbeDlg/ExportierenDlg/DruckerEinrichten/DruckenDlg/DateiEinfuegenDlg/Active zu verhindern + }*/ + delete pZeroItem; + } + } +} + + +BOOL TestToolObj::ReturnResults( SvStream *pIn ) +{ + + USHORT nId; + ULONG nClearSequence = 0; + BOOL bSequenceOK = TRUE; + CNames *pReverseControlsKontext = NULL; + + CRetStream *pRetStream = new CRetStream(pIn); + + pRetStream->Read( nId ); + while( !pIn->IsEof() ) + { + switch( nId ) + { + case SIReturn: + { + USHORT nRet,nParams; + SmartId aUId; + pRetStream->Read(nRet); + if ( pRetStream->GetNextType() == BinString ) + { + String aUStrId; // UniqueStringID Used for Mozilla Integration + pRetStream->Read( aUStrId ); + aUId = SmartId( aUStrId ); + } + else + { + comm_ULONG nUId; + pRetStream->Read( nUId ); // bei Sequence einfach die Sequence + aUId = SmartId( nUId ); + } + pRetStream->Read(nParams); + + USHORT nNr1 = 0; + comm_ULONG nLNr1 = 0; + String aString1; + BOOL bBool1 = FALSE; + SbxValueRef xValue1 = new SbxValue; + + if( nParams & PARAM_USHORT_1 ) + pRetStream->Read( nNr1 ); + if( nParams & PARAM_ULONG_1 ) + pRetStream->Read( nLNr1 ); + if( nParams & PARAM_STR_1 ) + { + pRetStream->Read( aString1 ); + ReplaceNumbers ( aString1 ); + } + else + aString1.Erase(); + if( nParams & PARAM_BOOL_1 ) + pRetStream->Read( bBool1 ); + if( nParams & PARAM_SBXVALUE_1 ) + pRetStream->Read( *xValue1 ); + switch (nRet) + { + case RET_Sequence: + { + ULONG nUId = aUId.GetNum(); + if ( nSequence != nUId ) + { + bSequenceOK = FALSE; + ADD_ERROR(SbxERR_BAD_ACTION, GEN_RES_STR2(S_RETURN_SEQUENCE_MISSMATCH, String::CreateFromInt64(nUId), String::CreateFromInt64(nSequence)) ); + } + else + { + nClearSequence = nUId; + } + } + break; + case RET_Value: + if ( pImpl->pNextReturn ) + { +// ULONG nHintUserData = pImpl->pNextReturn->GetParent()->GetUserData(); +// pImpl->pNextReturn->GetParent()->SetUserData(0); +// if ( nUId == pImpl->pNextReturn->GetParent()->GetULong() ) + if ( aNextReturnId.Matches( aUId ) ) + { + if( nParams & PARAM_ULONG_1 ) + { + if ( nLNr1 > 0x7fffffff ) + pImpl->pNextReturn->PutLong( long(nLNr1 - 0xffffffff) -1 ); + else + pImpl->pNextReturn->PutULong( nLNr1 ); + } + if( nParams & PARAM_USHORT_1 ) pImpl->pNextReturn->PutUShort( nNr1 ); + if( nParams & PARAM_STR_1 ) pImpl->pNextReturn->PutString( aString1 ); + if( nParams & PARAM_BOOL_1 ) pImpl->pNextReturn->PutBool( bBool1 ); + if( nParams & PARAM_SBXVALUE_1 ) + { + SbxValues aValues( SbxDATE ); + xValue1->Get( aValues ); + pImpl->pNextReturn->Put( aValues ); + } + } + else + { + ADD_ERROR(SbxERR_BAD_ACTION, GEN_RES_STR0(S_RETURNED_VALUE_ID_MISSMATCH) ) + } +// pImpl->pNextReturn->GetParent()->SetUserData(nHintUserData); + pImpl->pNextReturn = NULL; + } + else + { + ADD_ERROR(SbxERR_BAD_ACTION, GEN_RES_STR0(S_RETURNED_VALUE_NO_RECEIVER) ) + } + break; + case RET_WinInfo: + { + if ( !m_pReverseControls && !m_pReverseControlsSon ) + pReverseControlsKontext = NULL; + + ReadHidLstByNumber(); + SortControlsByNumber(); + + // Alle Slots nach Nummer Sortiert + if ( !m_pReverseSlots && m_pSIds ) + { + m_pReverseSlots = new CNames; + USHORT nWin; + const String aSl('/'); + for ( nWin = 0 ; nWin < m_pSIds->Count() ; nWin++ ) + { + ControlItemUId *pNewItem = new ControlItemUId(m_pSIds->GetObject(nWin)->pData->Kurzname,m_pSIds->GetObject(nWin)->pData->aUId); + AddToListByNr( m_pReverseSlots, pNewItem ); + } + } + + WinInfoRec *pWinInfo = new WinInfoRec; + pWinInfo->aUId = aUId.GetText(); + pWinInfo->nRType = (USHORT)nLNr1; // just ULONG for Transport, data is always USHORT + pWinInfo->aRName = aString1; + pWinInfo->bIsReset = bBool1; + pWinInfo->aKurzname.Erase(); + pWinInfo->aSlotname.Erase(); + + // eventuell den Kontext feststellen. Passiert nur beim ersten Eintrag nach reset + if ( !pReverseControlsKontext && m_pReverseControlsSon ) + { + USHORT nNr; + ControlItem *pNewItem = new ControlItemUId( String(), aUId ); + if ( m_pReverseControlsSon->Seek_Entry(pNewItem,&nNr) ) + { + pReverseControlsKontext = ((ControlItemUIdSon*)m_pReverseControlsSon->GetObject(nNr))->GetSons(); + pWinInfo->aKurzname = CUniString("*"); + } + else + pReverseControlsKontext = m_pReverseControls; + + delete pNewItem; + } + + // Reset. Mu� nach bestimmen des Kontext stehen, da sonst mit dem reset-record + // der Kontext falsch gesetzt wird. + if ( pWinInfo->bIsReset ) + pReverseControlsKontext = NULL; // Reihenfolge wichtig! + + + // Kurzname feststellen + if ( pReverseControlsKontext ) + { + USHORT nNr; + ControlItem *pNewItem = new ControlItemUId( String(), aUId ); + if ( pReverseControlsKontext->Seek_Entry(pNewItem,&nNr) ) + { +// SmartId aID = pReverseControlsKontext->GetObject(nNr)->pData->aUId; + pWinInfo->aKurzname += pReverseControlsKontext->GetObject(nNr)->pData->Kurzname; + } + delete pNewItem; + } + + // Slotname feststellen + if ( m_pReverseSlots ) + { + USHORT nNr; + ControlItem *pNewItem = new ControlItemUId( String(), aUId ); + if ( m_pReverseSlots->Seek_Entry(pNewItem,&nNr) ) + pWinInfo->aSlotname = m_pReverseSlots->GetObject(nNr)->pData->Kurzname; + delete pNewItem; + } + + // Langname feststellen + if ( aUId.HasString() ) + { // use the String ID since there is no LongName in hid.lst + pWinInfo->aLangname = aUId.GetStr(); + } + else + { + if ( m_pReverseUIds ) + { + USHORT nNr; + ControlItem *pNewItem = new ControlItemUId( String(), aUId ); + if ( m_pReverseUIds->Seek_Entry(pNewItem,&nNr) ) + pWinInfo->aLangname = m_pReverseUIds->GetObject(nNr)->pData->Kurzname; + delete pNewItem; + } + } + + aWinInfoHdl.Call( pWinInfo ); + + delete pWinInfo; + } + break; + case RET_ProfileInfo: + { + ULONG nUId = aUId.GetNum(); + if ( nParams & PARAM_STR_1 ) + { + DirEntry FilePath = pImpl->aLogFileBase + DirEntry(DirEntry(aLogFileName).GetBase().AppendAscii(".prf")); + SvFileStream aStrm( FilePath.GetFull(), STREAM_STD_WRITE ); + if( aStrm.IsOpen() ) + { + aString1.ConvertLineEnd(LINEEND_CRLF); + aStrm.Seek(STREAM_SEEK_TO_END); + aStrm << ByteString( aString1, RTL_TEXTENCODING_UTF8 ).GetBuffer(); + aStrm.Close(); + } + } + if ( nParams & PARAM_ULONG_1 ) + { + switch ( nUId ) + { + case S_ProfileReset: // nLNr1 = Anzahl Borders + { + pImpl->nNumBorders = (USHORT)nLNr1; // Borders are 0 to 4 + USHORT i; + for ( i=0 ; i<4 ; i++ ) + pImpl->naValBorders[i] = 0; + + for ( i=0 ; i<5 ; i++ ) + { + pImpl->naNumEntries[i] = 0; + pImpl->naRemoteTime[i] = 0; + pImpl->naLocalTime[i] = 0; + } + break; + } + case S_ProfileBorder1: // nLNr1 = Border1 in ms + case S_ProfileBorder2: // nLNr1 = Border2 in ms + case S_ProfileBorder3: // nLNr1 = Border3 in ms + case S_ProfileBorder4: // nLNr1 = Border4 in ms + { + pImpl->naValBorders[ nUId - S_ProfileBorder1 ] = nLNr1; + break; + } + case S_ProfileTime: // nLNr1 = remote Zeit des Befehls + { + USHORT i; + for ( i=0 ; i<pImpl->nNumBorders && + pImpl->naValBorders[i] <= nLNr1 ; i++ ) {}; + + pImpl->naNumEntries[ i ]++; + pImpl->naRemoteTime[ i ] += nLNr1; + pImpl->naLocalTime[ i ] += Time::GetSystemTicks() - pImpl->LocalStarttime; + + #if OSL_DEBUG_LEVEL > 1 + if ( nLNr1 > (Time::GetSystemTicks() - pImpl->LocalStarttime) ) + { + String aLine = CUniString("Testtoolzeit(").Append(String::CreateFromInt64(Time::GetSystemTicks() - pImpl->LocalStarttime)).AppendAscii(") kleiner Officezeit(").Append(String::CreateFromInt64(nLNr1)).AppendAscii(")\n"); + DirEntry FilePath = pImpl->aLogFileBase + DirEntry(DirEntry(aLogFileName).GetBase().AppendAscii(".prf")); + SvFileStream aStrm( FilePath.GetFull(), STREAM_STD_WRITE ); + if( aStrm.IsOpen() ) + { + aLine.ConvertLineEnd(LINEEND_CRLF); + aStrm.Seek(STREAM_SEEK_TO_END); + aStrm << ByteString( aLine, RTL_TEXTENCODING_UTF8 ).GetBuffer(); + aStrm.Close(); + } + } + #endif + + break; + } + case S_ProfileDump: // Gibt die daten aus. + { + if ( pImpl->nNumBorders == 0 ) // Also keine alte R�ckmeldung vom Office + break; + DirEntry FilePath = pImpl->aLogFileBase + DirEntry(DirEntry(aLogFileName).GetBase().AppendAscii(".prf")); + SvFileStream aStrm( FilePath.GetFull(), STREAM_STD_WRITE ); + if( aStrm.IsOpen() ) + { + String aProfile; + USHORT i; + + aProfile += String().Expand(15); + for ( i=0 ; i<pImpl->nNumBorders ; i++ ) + aProfile += (CUniString("< ").Append(String::CreateFromInt64(pImpl->naValBorders[i]))).Expand(20); + + aProfile += (CUniString(">= ").Append(TTFormat::ms2s(pImpl->naValBorders[pImpl->nNumBorders-1]))); + + aProfile += '\n'; + + aProfile += CUniString("Ereignisse").Expand(15); + for ( i=0 ; i<=pImpl->nNumBorders ; i++ ) + aProfile += TTFormat::ms2s(pImpl->naNumEntries[i]).Expand(20); + + aProfile += '\n'; + + aProfile += CUniString("Server Zeit").Expand(15); + for ( i=0 ; i<=pImpl->nNumBorders ; i++ ) + aProfile += TTFormat::ms2s(pImpl->naRemoteTime[i]).Expand(20); + + aProfile += '\n'; + + aProfile += CUniString("Testtool Zeit").Expand(15); + for ( i=0 ; i<=pImpl->nNumBorders ; i++ ) + aProfile += TTFormat::ms2s(pImpl->naLocalTime[i]).Expand(20); + + aProfile += '\n'; + + aProfile += CUniString("Overhead p.e.").Expand(15); + for ( i=0 ; i<=pImpl->nNumBorders ; i++ ) + { + if ( pImpl->naNumEntries[i] > 0 ) + aProfile += TTFormat::ms2s((pImpl->naLocalTime[i]-pImpl->naRemoteTime[i])/pImpl->naNumEntries[i]).Expand(20); + else + aProfile += CUniString( "??" ).Expand(20); + } + + aProfile += '\n'; + + aProfile.ConvertLineEnd(LINEEND_CRLF); + aStrm.Seek(STREAM_SEEK_TO_END); + aStrm << ByteString( aProfile, RTL_TEXTENCODING_UTF8 ).GetBuffer(); + aStrm.Close(); + } + break; + } + default: + DBG_ERROR1("Unbekannter Sub Return Code bei Profile: %hu", nUId ); + break; + } + } + } + break; + case RET_DirectLoging: + { + ULONG nUId = aUId.GetNum(); + switch ( nUId ) + { + case S_AssertError: + { + ADD_ASSERTION_LOG( aString1 ); +// ADD_ERROR_LOG( aString1, aRun.GetModuleName(SbxNAME_SHORT_TYPES), +// aRun.GetLine(), aRun.GetCol1(), aRun.GetCol2() ); + } + break; + case S_QAError: + { + ADD_QA_ERROR_LOG( aString1 ); + } + break; + default: + ; + } + } + break; + case RET_MacroRecorder: + { + SortControlsByNumber( TRUE ); + String aCommand,aControls,aControl,aULongNames,aULongName; + BOOL bWriteNewKontext = FALSE; + + aControls.Erase(); + // Kurzname feststellen + if ( m_pReverseControls ) + { + USHORT nNr; + ControlItem *pNewItem = new ControlItemUId( String(), aUId ); + if ( m_pReverseControls->Seek_Entry(pNewItem,&nNr) ) + aControls = m_pReverseControls->GetObject(nNr)->pData->Kurzname; + delete pNewItem; + } + if ( !aControls.Len() ) + { + aControls = String::CreateFromAscii("UnknownControl:UnknownControl"); + Sound::Beep( SOUND_WARNING ); + } + + aULongNames.Erase(); + if( (nParams & PARAM_ULONG_1) && (nNr1 & M_RET_NUM_CONTROL) ) + { + if ( m_pReverseControls ) + { + USHORT nNr; + ControlItem *pNewItem = new ControlItemUId( String(), SmartId( nLNr1 ) ); + if ( m_pReverseControls->Seek_Entry(pNewItem,&nNr) ) + aULongNames = m_pReverseControls->GetObject(nNr)->pData->Kurzname; + delete pNewItem; + } + if ( !aULongNames.Len() ) + { + aULongNames = String::CreateFromAscii("Unknown:Unknown"); + Sound::Beep( SOUND_WARNING ); + } + + // now determin the best common kontext + USHORT i,j; + BOOL bFoundUlongName = FALSE, bFoundControl = FALSE; + // check for current kontext + for ( i = 0 ; !bFoundUlongName && i < aULongNames.GetTokenCount('/') ; i++ ) + bFoundUlongName = aLastRecordedKontext.Equals( aULongNames.GetToken(i,'/').GetToken( 0,':') ); + + for ( j = 0 ; !bFoundControl && j < aControls.GetTokenCount('/') ; j++ ) + bFoundControl = aLastRecordedKontext.Equals( aControls.GetToken(j,'/').GetToken( 0,':') ); + + if ( bFoundUlongName && bFoundControl ) + { + aULongName = aULongNames.GetToken(i-1,'/').GetToken( 1,':'); + aControl = aControls.GetToken(j-1,'/').GetToken( 1,':'); + } + else + { // see if we can find common kontext + BOOL bFound = FALSE; + + String aCurrentKontext; + for ( i = 0 ; !bFound && i < aULongNames.GetTokenCount('/') ; i++ ) + { + aCurrentKontext = aULongNames.GetToken(i,'/').GetToken( 0,':'); + + for ( j = 0 ; !bFound && j < aControls.GetTokenCount('/') ; j++ ) + { + if ( aCurrentKontext.Equals( aControls.GetToken(j,'/').GetToken( 0,':') ) ) + { + bFound = TRUE; + aULongName = aULongNames.GetToken(i,'/').GetToken( 1,':'); + aControl = aControls.GetToken(j,'/').GetToken( 1,':'); + aLastRecordedKontext = aCurrentKontext; + bWriteNewKontext = TRUE; + } + } + } + if ( !bFound ) + { + // check if both contain toplevel + bFoundUlongName = FALSE; + bFoundControl = FALSE; + for ( i = 0 ; !bFoundUlongName && i < aULongNames.GetTokenCount('/') ; i++ ) + bFoundUlongName = aULongNames.GetToken(i,'/').GetToken( 0,':').Equals( aULongNames.GetToken(i,'/').GetToken( 1,':') ); + + for ( j = 0 ; !bFoundControl && j < aControls.GetTokenCount('/') ; j++ ) + bFoundControl = aControls.GetToken(j,'/').GetToken( 0,':').Equals( aControls.GetToken(j,'/').GetToken( 1,':') ); + + if ( bFoundUlongName && bFoundControl ) + { + aULongName = aULongNames.GetToken(i-1,'/').GetToken( 1,':'); + aControl = aControls.GetToken(j-1,'/').GetToken( 1,':'); + if ( aLastRecordedKontext.Len() ) + { + aLastRecordedKontext.Erase(); + bWriteNewKontext = TRUE; + } + } + else + { + String aComment; + aComment = CUniString( "'could not Determin common kontext\n" ); + Sound::Beep( SOUND_WARNING ); + aWriteStringHdl.Call( &aComment ); + aULongName = aULongNames.GetToken(i,'/'); + aControl = aControls.GetToken(j,'/'); + } + } + } + + } + else + { // we only have a Control + USHORT i; + BOOL bFoundControl = FALSE; + // check for current kontext + for ( i = 0 ; !bFoundControl && i < aControls.GetTokenCount('/') ; i++ ) + bFoundControl = aLastRecordedKontext.Equals( aControls.GetToken(i,'/').GetToken( 0,':') ); + if ( bFoundControl ) + aControl = aControls.GetToken(i-1,'/').GetToken( 1,':'); + else + { + aLastRecordedKontext = aControls.GetToken(0,'/').GetToken( 0,':'); + bWriteNewKontext = TRUE; + aControl = aControls.GetToken(0,'/').GetToken( 1,':'); + } + + } + + + if ( bWriteNewKontext ) + { + String aKontextCommand = CUniString( "Kontext" ); + if ( aLastRecordedKontext.Len() ) + { + aKontextCommand.AppendAscii ( " \"" ); + aKontextCommand += aLastRecordedKontext; + aKontextCommand.AppendAscii ( "\"" ); + } + aKontextCommand.AppendAscii( "\n" ); + aWriteStringHdl.Call( &aKontextCommand ); + } + + aCommand = aControl; + + // Add Method name + String aMethod = GetMethodName( nNr1 & ~M_RET_NUM_CONTROL ); + aCommand += '.'; + aCommand += aMethod; + + BOOL bWasParam = FALSE; + + if( nParams & PARAM_STR_1 ) + { + bWasParam = TRUE; + aCommand.AppendAscii( " \"" ); + if ( nNr1 & M_KEY_STRING ) + { + USHORT nModify = 0; + BOOL bIsProsa = FALSE; + xub_StrLen i; + for ( i = 0; i < aString1.Len(); i++ ) + { + if ( ((USHORT)aString1.GetChar(i)) == 1 ) // we have a spechial char + { + i++; + if ( !bIsProsa ) + { + aCommand.AppendAscii( "<" ); + bIsProsa = TRUE; + } + else + aCommand.AppendAscii( " " ); + + USHORT nKeyCode = (USHORT)aString1.GetChar(i) & KEY_CODE; + USHORT nNewModify = (USHORT)aString1.GetChar(i) & KEY_MODTYPE; + if ( nNewModify != nModify ) + { // generate modifiers + USHORT nChanged = ( nNewModify ^ nModify ); + if ( nChanged & KEY_SHIFT ) + { + aCommand += GetKeyName( KEY_SHIFT ); + aCommand.AppendAscii( " " ); + } + if ( nChanged & KEY_MOD1 ) + { + aCommand += GetKeyName( KEY_MOD1 ); + aCommand.AppendAscii( " " ); + } + if ( nChanged & KEY_MOD2 ) + { + aCommand += GetKeyName( KEY_MOD2 ); + aCommand.AppendAscii( " " ); + } + } + aCommand += GetKeyName( nKeyCode ); + nModify = nNewModify; + } + else + { + if ( bIsProsa ) + { + aCommand.AppendAscii( ">" ); + bIsProsa = FALSE; + } + aCommand += aString1.GetChar(i); + nModify = 0; + } + } + if ( bIsProsa ) + { + aCommand.AppendAscii( ">" ); + bIsProsa = FALSE; + } + } + else + { + aCommand += aString1; + } + aCommand.AppendAscii( "\"" ); + } + if( nParams & PARAM_ULONG_1 ) + { + if ( bWasParam ) + aCommand.AppendAscii( ", " ); + else + aCommand.AppendAscii( " " ); + bWasParam = TRUE; + if ( nNr1 & M_RET_NUM_CONTROL ) + { + aCommand.Append( aULongName ); + } + else + { + aCommand.Append( String::CreateFromInt64( nLNr1 ) ); + } + } + if( nParams & PARAM_BOOL_1 ) + { + if ( bWasParam ) + aCommand.AppendAscii( ", " ); + else + aCommand.AppendAscii( " " ); + bWasParam = TRUE; + if ( bBool1 ) + aCommand.AppendAscii( "true" ); + else + aCommand.AppendAscii( "false" ); + } + + aCommand.AppendAscii( "\n" ); + + aWriteStringHdl.Call( &aCommand ); + } + break; + default: + DBG_ERROR1( "Unbekannter Return Code: %iu", nRet ); + break; + } + + break; + } + case SIReturnError: + { + String aString; + SmartId aUId; + if ( pRetStream->GetNextType() == BinString ) + { + String aUStrId; // UniqueStringID Used for Mozilla Integration + pRetStream->Read( aUStrId ); + aUId = SmartId( aUStrId ); + } + else + { + comm_ULONG nUId; + pRetStream->Read( nUId ); // bei Sequence einfach die Sequence + aUId = SmartId( nUId ); + } + pRetStream->Read( aString ); + ReplaceNumbers (aString); + + String aShortName; + aShortName = pShortNames->GetName(aUId); + aShortName.AppendAscii( " : " ); + + String aTmpStr(aShortName); + aTmpStr += aString; + ADD_ERROR(SbxERR_BAD_ACTION, aTmpStr/*, nNr*/); + break; + } + default: + DBG_ERROR1( "Unbekannter Request im Return Stream Nr: %iu", nId ); + break; + } + if( !pIn->IsEof() ) + pRetStream->Read( nId ); + else + { + DBG_ERROR( "truncated input stream" ); + } + + } + + delete pRetStream; + if ( bSequenceOK ) + { + nSequence++; + pShortNames->Invalidate( nClearSequence - KEEP_SEQUENCES ); + } + + bReturnOK = TRUE; + + return TRUE; +} // RetService::Request() + +String TestToolObj::GetMethodName( ULONG nMethodId ) +{ + USHORT nElement; + if ( !Controls::pClasses ) // Ist static, wird also nur einmal geladen + ReadFlatArray( Controls::arClasses, Controls::pClasses ); + if ( Controls::pClasses ) + { + for ( nElement = 0 ; nElement < Controls::pClasses->Count() ; nElement++ ) + if ( Controls::pClasses->GetObject(nElement)->pData->aUId.Matches( nMethodId ) ) + return Controls::pClasses->GetObject(nElement)->pData->Kurzname; + } + return String(); +} + +String TestToolObj::GetKeyName( USHORT nKeyCode ) +{ + USHORT nElement; + if ( !CmdStream::pKeyCodes ) // Ist static, wird also nur einmal geladen + ReadFlatArray( CmdStream::arKeyCodes, CmdStream::pKeyCodes ); + if ( CmdStream::pKeyCodes ) + { + for ( nElement = 0 ; nElement < CmdStream::pKeyCodes->Count() ; nElement++ ) + if ( CmdStream::pKeyCodes->GetObject(nElement)->pData->aUId.Matches( nKeyCode ) ) + return CmdStream::pKeyCodes->GetObject(nElement)->pData->Kurzname; + } + return CUniString( "UnknownKeyCode" ); +} + +void TestToolObj::ReplaceNumbers(String &aText) +{ +static ControlDefLoad __READONLY_DATA arRes_Type [] = +#include "res_type.hxx" + + static CNames *pRTypes = NULL; + xub_StrLen nStart = STRING_NOTFOUND; + xub_StrLen nGleich = STRING_NOTFOUND; + xub_StrLen nEnd = STRING_NOTFOUND; + xub_StrLen nStartPos = 0; + ULONG nNumber; + String aType; + String aResult; + BOOL bFound; + + while ( (nStart = aText.Search(StartKenn,nStartPos)) != STRING_NOTFOUND && + (nGleich = aText.SearchAscii("=",nStart+StartKenn.Len())) != STRING_NOTFOUND && + (nEnd = aText.Search(EndKenn,nGleich+1)) != STRING_NOTFOUND) + { + aType = aText.Copy(nStart,nGleich-nStart); + nNumber = (ULONG)aText.Copy(nGleich+1,nEnd-nGleich-1).ToInt64(); + bFound = FALSE; + if ( aType.CompareTo(UIdKenn) == COMPARE_EQUAL ) + { + aResult = pShortNames->GetName(SmartId(nNumber)); + bFound = TRUE; + } + if ( aType.CompareTo(MethodKenn ) == COMPARE_EQUAL ) + { + bFound = TRUE; + aResult = GetMethodName( nNumber ); + } + if ( aType.CompareTo(RcKenn ) == COMPARE_EQUAL ) + { + bFound = TRUE; + if ( !pRCommands ) // Ist static, wird also nur einmal geladen + ReadFlatArray( arR_Cmds, pRCommands ); + + USHORT nElement; + if ( pRCommands ) + { + for ( nElement = 0 ; nElement < pRCommands->Count() ; nElement++ ) + if ( pRCommands->GetObject(nElement)->pData->aUId.Matches( nNumber ) ) + { + aResult = pRCommands->GetObject(nElement)->pData->Kurzname; + nElement = pRCommands->Count(); + } + } + } + if ( aType.CompareTo(TypeKenn ) == COMPARE_EQUAL ) + { + bFound = TRUE; + if ( !pRTypes ) // Ist static, wird also nur einmal geladen + ReadFlatArray( arRes_Type, pRTypes ); + + USHORT nElement; + if ( pRTypes ) + { + for ( nElement = 0 ; nElement < pRTypes->Count() ; nElement++ ) + if ( pRTypes->GetObject(nElement)->pData->aUId.Matches( nNumber ) ) + { + aResult = pRTypes->GetObject(nElement)->pData->Kurzname; + nElement = pRTypes->Count(); + } + } + } + if ( aType.CompareTo(SlotKenn ) == COMPARE_EQUAL ) + { + aResult = pShortNames->GetName(SmartId(nNumber)); + bFound = TRUE; + } + if ( aType.CompareTo(TabKenn ) == COMPARE_EQUAL ) + { + if ( nNumber > nStart ) + aResult.Fill( (USHORT)nNumber - nStart +1 ); + else + aResult = CUniString(" "); + bFound = TRUE; + } + + nStartPos = nStart; + if ( bFound ) + { + aText.Erase(nStart,nEnd+EndKenn.Len()-nStart); + aText.Insert(aResult,nStart); + nStartPos = nStartPos + aResult.Len(); + } + else + nStartPos = nStartPos + StartKenn.Len(); + } +} + + +SbTextType TestToolObj::GetSymbolType( const String &rSymbol, BOOL bWasControl ) +{ + if ( rSymbol.CompareToAscii( "try" ) == COMPARE_EQUAL + || rSymbol.CompareToAscii( "catch" ) == COMPARE_EQUAL + || rSymbol.CompareToAscii( "endcatch" ) == COMPARE_EQUAL + || rSymbol.CompareToAscii( "testcase" ) == COMPARE_EQUAL + || rSymbol.CompareToAscii( "endcase" ) == COMPARE_EQUAL ) + { + return TT_KEYWORD; + } + + + ControlDef WhatName( rSymbol, SmartId() ); + + if ( bWasControl ) + { + if ( !Controls::pClasses ) // Ist static, wird also nur einmal geladen + ReadFlatArray( Controls::arClasses, Controls::pClasses ); + + if ( (Controls::pClasses && Controls::pClasses->Seek_Entry( &WhatName )) + || rSymbol.EqualsIgnoreCaseAscii( "ID" ) + || rSymbol.EqualsIgnoreCaseAscii( "Name" ) ) + return TT_METHOD; + else + return TT_NOMETHOD; + } + + // Die Controls durchsuchen + if ( m_pControls ) + { + USHORT nWin; + + for ( nWin = 0 ; nWin < m_pControls->Count() ; nWin++ ) + { + if ( ((ControlDef*)m_pControls->GetObject( nWin ))->SonSeek_Entry( &WhatName ) ) + return TT_CONTROL; + } + } + + // Die Slots durchsuchen + if ( m_pSIds && m_pSIds->Seek_Entry( &WhatName ) ) + return TT_SLOT; + + // Ist es ein RemoteCommand + if ( !pRCommands ) // Ist static, wird also nur einmal geladen + ReadFlatArray( arR_Cmds, pRCommands ); + if ( pRCommands && pRCommands->Seek_Entry( &WhatName ) ) + return TT_REMOTECMD; + + // Wenns sonst nix war, dann vielleicht ein Lokales Kommando + SbxVariable *pVar = SbxObject::Find( rSymbol, SbxCLASS_DONTCARE ); + if ( pVar && ( pVar->ISA(SbxMethod) || pVar->ISA(SbxProperty) ) ) + { + return TT_LOCALCMD; + } + + return SB_SYMBOL; // Alles was hier landet ist vom Typ SB_SYMBOL und bleibt es auch +} + + +#undef P_FEHLERLISTE +#define P_FEHLERLISTE TestToolObj::pFehlerListe + +Controls::Controls( String aCName ) +: SbxObject( aCName) +{ + pMethodVar = new SbxTransportMethod( SbxVARIANT ); + pMethodVar->SetName( CUniString("Dummy") ); + Insert( pMethodVar ); +// pMethodVar = Make( CUniString("Dummy"), SbxCLASS_PROPERTY, SbxULONG ); +} + + +Controls::~Controls() +{} + + +void Controls::ChangeListener( SbxObject* parent ) +{ + EndListening( pMethodVar->GetBroadcaster(), TRUE ); + parent->StartListening( pMethodVar->GetBroadcaster(), TRUE ); +} + +void Controls::SFX_NOTIFY( SfxBroadcaster&, const TypeId&, + const SfxHint&, const TypeId& ) +{} + + + +SbxVariable* Controls::Find( const String& aStr, SbxClassType aType) +{ + if ( !pClasses ) // Ist static, wird also nur einmal geladen + ReadFlatArray( arClasses, pClasses ); + + if ( GetUserData() == ID_ErrorDummy ) + { + pMethodVar->SetName(UniString(GetName()).AppendAscii(".").Append(aStr)); + pMethodVar->SetUserData( ID_ErrorDummy ); + return pMethodVar; + } + + + USHORT nElement; + ControlDef WhatName(aStr,SmartId()); + if (pClasses && pClasses->Seek_Entry(&WhatName,&nElement)) + { + pMethodVar->SetName(aStr); + ULONG nUId = pClasses->GetObject(nElement)->pData->aUId.GetNum(); + pMethodVar->nValue = nUId; + + pMethodVar->SetUserData( GetUserData() ); + return pMethodVar; + } + else + { // mainly for ID and name + SbxVariableRef Old = SbxObject::Find(aStr, aType ); + if (Old) + return Old; + else if ( aStr.EqualsIgnoreCaseAscii("ID") ) + return NULL; // suppress generation of error in this case + } + ADD_ERROR(SbxERR_BAD_METHOD,GEN_RES_STR2(S_UNKNOWN_METHOD, GetName(), aStr)); + return NULL; +} + + +String TTFormat::ms2s( ULONG nMilliSeconds ) +{ + if ( nMilliSeconds < 100000 ) // 100 Sekunden + return String::CreateFromInt64( nMilliSeconds ); + if ( nMilliSeconds < 100000*60 ) // 100 Minuten + return String::CreateFromInt32( nMilliSeconds / 1000 ).AppendAscii("Sec"); + return String::CreateFromInt32( nMilliSeconds / 1000 / 60 ).AppendAscii("Min"); +} + + diff --git a/automation/source/testtool/objtest.hxx b/automation/source/testtool/objtest.hxx new file mode 100644 index 000000000000..d82e4626a4d2 --- /dev/null +++ b/automation/source/testtool/objtest.hxx @@ -0,0 +1,403 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _OBJTEST_HXX +#define _OBJTEST_HXX + +#include <tools/fsys.hxx> + + +#include <testapp.hxx> +#include <testtool.hxx> +#include "cmdstrm.hxx" +#include <basic/basicrt.hxx> +#include <vcl/smartid.hxx> +#include "httprequest.hxx" + +#include <map> + +// #define ID_BeginBlock 1 +// #define ID_EndBlock 2 +#define ID_Kontext 3 +#define ID_GetError 4 +#define ID_ErrorDummy 5 // Intern zum Behandlen von Fehlenden Controls und Methoden +#define ID_RecordError 6 +#define ID_Start 7 +//#define ID_Kill 8 +//#define ID_Reset 9 +// #define ID_AppAbort 10 +#define ID_Dispatch 11 +#define ID_UNODispatch 12 +#define ID_Control 13 +#define ID_StartUse 14 +#define ID_Use 15 +#define ID_FinishUse 16 +#define ID_CaseLog 17 +#define ID_ExceptLog 18 +#define ID_PrintLog 19 +#define ID_WarnLog 20 +#define ID_ErrorLog 21 +#define ID_EnableQaErrors 22 +#define ID_QAErrorLog 23 +#define ID_MaybeAddErr 24 +#define ID_ClearError 25 +#define ID_GetNextCloseWindow 26 +#define ID_RemoteCommand 27 +#define ID_SaveIDs 28 +#define ID_AutoExecute 29 +#define ID_Execute 30 +#define ID_DialogHandler 31 +#define ID_GetUnoApp 32 +#define ID_GetIServer 33 +#define ID_RemoteCommandDelay 34 +#define ID_GetApplicationPath 35 +#define ID_GetCommonApplicationPath 36 +#define ID_MakeIniFileName 37 +#define ID_StringControl 38 +#define ID_Wait 39 +#define ID_GetErrorCount 40 +#define ID_GetWarningCount 41 +#define ID_GetQAErrorCount 42 +#define ID_GetUseFileWarningCount 43 +#define ID_GetErrorList 44 +#define ID_GetWarningList 45 +#define ID_GetQAErrorList 46 +#define ID_GetUseFileWarningList 47 +#define ID_GetTestCaseName 48 +#define ID_GetTestCaseFileName 49 +#define ID_GetTestCaseLineNr 50 +#define ID_StopOnSyntaxError 51 +#define ID_SetChildEnv 52 +#define ID_GetChildEnv 53 +#define ID_GetLinkDestination 54 +#define ID_GetRegistryValue 55 +#define ID_KillApp 56 +#define ID_HTTPSend 57 +#define ID_HTTPSetProxy 58 +#define ID_DoNothing 99 + +void ReadFlatArray( const ControlDefLoad arWas [], CNames *&pNames ); + +class ControlData +{ +public: + String Kurzname; + SmartId aUId; +}; + +DBG_NAMEEX( ControlItem ) +DBG_NAMEEX( ControlDef ) +class ControlItem +{ +private: + void InitData() { pData = new ControlData; } +public: + ControlData *pData; + + ControlItem( const char *Name, SmartId aUIdP ); + ControlItem( const String &Name, SmartId aUIdP ); +// ControlItem( const String &Name, const String &URL, const URLType aType ); +// ControlItem( const String &Name, const String &URL, const ULONG nUId ); +// ControlItem( const char *Name, const String &URL, const ULONG nUId ); + ControlItem( ControlData *pDataP ); + virtual ~ControlItem() { +DBG_DTOR(ControlItem,0); + delete pData; + } + virtual BOOL operator < (const ControlItem &rPar)=0; + virtual BOOL operator == (const ControlItem &rPar)=0; +// void Write( SvStream &aStream ); +}; + +SV_DECL_PTRARR_SORT_DEL(CNames, ControlItem*, 50, 10) + +#define MK_SON_ACCESS( ClassName )\ + BOOL SonInsert( const ClassName *pNewEntry ) { const ControlItem *pItem = pNewEntry; return pSons->Insert( pItem ); }\ + BOOL SonSeek_Entry( const ClassName *pSearchEntry, USHORT *nRes = NULL) { return pSons->Seek_Entry( pSearchEntry, nRes ); }\ + ClassName* SonGetObject( USHORT nNr ) { return (ClassName*)pSons->GetObject( nNr ); } + +class ControlSon +{ +protected: + CNames *pSons; // um sicherzustelle, daß nur Söhne des richtien Type reinkommen + +public: + ControlSon() : pSons( NULL ) {}; + ~ControlSon(); +// void Write( SvStream &aStream ); + + USHORT Son_Count() { return pSons->Count(); } + void Sons( CNames *pNewSons ) { pSons = pNewSons; } + CNames*& GetSons() { return pSons; } +}; + +class ControlItemSon : public ControlItem, public ControlSon +{ +public: + ControlItemSon(const char *Name, SmartId aUIdP ) + : ControlItem( Name, aUIdP ) {} + ControlItemSon(const String &Name, SmartId aUIdP ); +// ControlItemSon(const String &Name, const String &URL, const URLType aType ); +// ControlItemSon(const String &Name, const String &URL, const ULONG nUId ); +// ControlItemSon(const char *Name, const String &URL, const ULONG nUId ); +// void Write( SvStream &aStream ); +}; + +class ControlDef : public ControlItemSon +{ +public: + ControlDef(const char *Name, SmartId aUIdP ) + : ControlItemSon( Name, aUIdP ) {DBG_CTOR(ControlDef,0);} + ControlDef(const String &Name, SmartId aUIdP ); +// ControlDef(const String &Name, const String &URL, const URLType aType ); + ControlDef(const String &aOldName, const String &aNewName, ControlDef *pOriginal, BOOL bWithSons = FALSE ); + ~ControlDef() {DBG_DTOR(ControlDef,0);} + virtual BOOL operator < (const ControlItem &rPar); + virtual BOOL operator == (const ControlItem &rPar); + void Write( SvStream &aStream ); + MK_SON_ACCESS( ControlDef ) +}; + +class ControlItemUId : public ControlItem +{ +public: + ControlItemUId(String Name, SmartId aUIdP) + : ControlItem( Name, aUIdP){} + virtual BOOL operator < (const ControlItem &rPar); + virtual BOOL operator == (const ControlItem &rPar); +}; + +class ControlItemUIdSon : public ControlItemUId, public ControlSon +{ +public: + ControlItemUIdSon(String Name, SmartId aUIdP) : ControlItemUId( Name, aUIdP) {} + MK_SON_ACCESS( ControlItemUId ) +}; + +class ReverseName : public ControlItemUId +{ +public: + ULONG LastSequence; + + ReverseName(String Name, SmartId aUIdP, ULONG nSeq) : ControlItemUId( Name, aUIdP), LastSequence(nSeq) {} +}; + +class CRevNames: public CNames +{ +public: + void Insert( String aName, SmartId aUId, ULONG nSeq ); + String GetName( SmartId aUId ); + void Invalidate ( ULONG nSeq ); +}; + + +class SbxTransportMethod: public SbxMethod +{ +public: + SbxTransportMethod( SbxDataType ); + ULONG nValue; + String aUnoSlot; +}; +SV_DECL_IMPL_REF(SbxTransportMethod); + +class Controls: public SbxObject +{ +public: + Controls( String aCName ); + ~Controls(); + void ChangeListener( SbxObject* pParent ); + + void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& ); + virtual SbxVariable* Find( const String&, SbxClassType ); + SbxTransportMethodRef pMethodVar; // zum Transport von Find nach Notify + static CNames *pClasses; + static ControlDefLoad __READONLY_DATA arClasses []; +}; +SV_DECL_IMPL_REF(Controls); + +typedef std::map< String, String > Environment; + +class ImplTestToolObj +{ +public: +// ImplTestToolObj() +// ~ImplTestToolObj() + + String ProgParam; // Parameter der zu Testenden APP; Gesetzt über Start + + DirEntry aFileBase; // Grundpfad für die *.sid und *.win Dateien (Aus Configdatei) + DirEntry aLogFileBase; // Grundpfad für die *.res Dateien (Aus Configdatei) + DirEntry aHIDDir; // Verzeichnis, in dem die hid.lst gesucht wird + + SbxTransportMethodRef pNextReturn; // Verweis auf die Var, die den Returnwert aufnimmt. + + ControlsRef pControlsObj; // Jeweiliges Objekt, an dem Methoden aufgerufen weden. + +#define VAR_POOL_SIZE 8 + SbxTransportMethodRef pMyVars[VAR_POOL_SIZE]; // Falls in Ausdrücken mehrere verwendet werden + + Time aServerTimeout; + + +// Profiling Datenfelder + ULONG LocalStarttime; + USHORT nNumBorders; + ULONG naValBorders[4]; + ULONG naNumEntries[5]; + ULONG naRemoteTime[5]; + ULONG naLocalTime[5]; + + ULONG nMinRemoteCommandDelay; + ULONG nMaxRemoteCommandDelay; + BOOL bDoRemoteCommandDelay; + + BOOL bLnaguageExtensionLoaded; // Wurde über 'use' was geladen? Für syntax highlighting + SfxBroadcaster *pTTSfxBroadcaster; + + ULONG nErrorCount; + ULONG nWarningCount; + ULONG nQAErrorCount; + ULONG nIncludeFileWarningCount; + + SbxDimArrayRef xErrorList; + SbxDimArrayRef xWarningList; + SbxDimArrayRef xQAErrorList; + SbxDimArrayRef xIncludeFileWarningList; + + BOOL bIsStart; // set tu TRUE while command Start is initiating the communication + + MyBasic* pMyBasic; + + String aTestCaseName; // holds name of current TestCase + String aTestCaseFileName; // holds FileName of current TestCase + USHORT nTestCaseLineNr; // holds Line of current TestCase + + BOOL bEnableQaErrors; // include QA errors in report + BOOL bDebugFindNoErrors; // suppress generating errors when find of variables is called for variable viewing purposes + + BOOL bStopOnSyntaxError; // catch syntax errors in testcases or not + + Environment *pChildEnv; // Environment Variables for child Process + + HttpRequest *pHttpRequest; // used for sending HTTP requests +}; + + +class TTFormat +{ +public: + static String ms2s( ULONG nMilliSeconds ); +}; + + +#define ADD_TO_LOG( aLogTypep, aMsgp, aFilenamep, nLinep, nCol1p, nCol2p, aRevisionp, pLogList )\ +{ \ + TTLogMsg *pLogMsg = new TTLogMsg(); \ + pLogMsg->aDebugData.aMsg = aMsgp; \ + pLogMsg->aLogFileName = (pImpl->aLogFileBase + DirEntry(aLogFileName)).GetFull(); \ + pLogMsg->aDebugData.aFilename = aFilenamep; \ + pLogMsg->aDebugData.nLine = nLinep; \ + pLogMsg->aDebugData.nCol1 = nCol1p; \ + pLogMsg->aDebugData.nCol2 = nCol2p; \ + pLogMsg->aDebugData.aLogType = aLogTypep; \ + aLogHdl.Call( pLogMsg ); \ + void* pDummyForWarningAboutNULL = pLogList; \ + if( pDummyForWarningAboutNULL ) \ + { \ + SbxDimArray* pLogArray = (SbxDimArray*)pLogList; \ + SbxVariable* pLogLine = new SbxVariable( SbxSTRING ); \ + String aCollect; \ + aCollect.Append( pLogMsg->aDebugData.aFilename ); \ + aCollect.AppendAscii( ";" ); \ + aCollect.Append( String::CreateFromInt32( nLinep ) ); \ + aCollect.AppendAscii( ";" ); \ + aCollect.Append( aRevisionp ); \ + aCollect.AppendAscii( ";" ); \ + aCollect.Append( pLogMsg->aDebugData.aMsg ); \ + pLogLine->PutString( aCollect ); \ + pLogArray->Insert( pLogLine, pLogArray->Count() ); \ + } \ + delete pLogMsg; \ +} \ + + +#define ADD_RUN_LOG() \ + ADD_TO_LOG(LOG_RUN, String(), String(), 0, 0, 0, String(), NULL) \ + +#define ADD_ERROR_LOG(aMsg, aFilename, nLine, nCol1, nCol2, aRevision) \ +{ \ + ADD_TO_LOG(LOG_ERROR, aMsg, aFilename, nLine, nCol1, nCol2, aRevision, &pImpl->xErrorList) \ + pImpl->nErrorCount++; \ +} + +#define ADD_CALL_STACK_LOG(aMsg, aFilename, nLine, nCol1, nCol2) \ + ADD_TO_LOG(LOG_CALL_STACK, aMsg, aFilename, nLine, nCol1, nCol2, String(), NULL) \ + + +#define ADD_AUTO_LOG(aLogType, aMsg, pLogList) \ +{ \ + if ( BasicRuntimeAccess::HasRuntime() ) \ + { \ + BasicRuntime aRun = BasicRuntimeAccess::GetRuntime(); \ + ADD_TO_LOG(aLogType, aMsg, aRun.GetModuleName(SbxNAME_SHORT_TYPES), \ + aRun.GetLine(), aRun.GetCol1(), aRun.GetCol2(), aRun.GetSourceRevision(), pLogList) \ + } \ + else \ + { \ + ADD_TO_LOG(aLogType, aMsg, UniString(), 0, 0, STRING_LEN, String(), pLogList) \ + } \ +} \ + +#define ADD_CASE_LOG(aMsg) \ + ADD_AUTO_LOG(LOG_TEST_CASE, aMsg, NULL) \ + +#define ADD_MESSAGE_LOG(aMsg) \ + ADD_AUTO_LOG(LOG_MESSAGE, aMsg, NULL) \ + +#define ADD_WARNING_LOG(aMsg) \ +{ \ + ADD_AUTO_LOG(LOG_WARNING, aMsg, &pImpl->xWarningList) \ + pImpl->nWarningCount++; \ +} + +#define ADD_WARNING_LOG2(aMsg, aFilename, nLine ) \ +{ \ + ADD_TO_LOG(LOG_WARNING, aMsg, aFilename, nLine, 0, STRING_LEN, String(), &pImpl->xWarningList) \ + pImpl->nWarningCount++; \ +} + +#define ADD_ASSERTION_LOG(aMsg) \ + ADD_AUTO_LOG(LOG_ASSERTION, aMsg, NULL) \ + +#define ADD_QA_ERROR_LOG(aMsg) \ + if ( pImpl->bEnableQaErrors ) \ + { \ + ADD_AUTO_LOG(LOG_QA_ERROR, aMsg, &pImpl->xQAErrorList) \ + pImpl->nQAErrorCount++; \ + } + +#endif diff --git a/automation/source/testtool/registry_win.cxx b/automation/source/testtool/registry_win.cxx new file mode 100644 index 000000000000..d0b1c0a0aa1b --- /dev/null +++ b/automation/source/testtool/registry_win.cxx @@ -0,0 +1,89 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_automation.hxx" + +//////////////////////////////////////////////////////////////////////////// +//// +//// Windows ONLY +//// +//////////////////////////////////////////////////////////////////////////// + + +#include <tools/prewin.h> +#include "winreg.h" +#include <tools/postwin.h> +// as we define it ourselves further down the line we remove it here +#ifdef IS_ERROR +// #undef IS_ERROR +#endif + +//#include <tchar.h> +#include "registry_win.hxx" +#include <osl/thread.h> + + +String ReadRegistry( String aKey, String aValueName ) +{ + String aRet; + HKEY hBaseKey; + if ( aKey.GetToken( 0, '\\' ).EqualsIgnoreCaseAscii( "HKEY_CURRENT_USER" ) ) + hBaseKey = HKEY_CURRENT_USER; + else if ( aKey.GetToken( 0, '\\' ).EqualsIgnoreCaseAscii( "HKEY_LOCAL_MACHINE" ) ) + hBaseKey = HKEY_LOCAL_MACHINE; + else + { + return aRet; + } + + aKey.Erase( 0, aKey.Search( '\\' )+1 ); + + HKEY hRegKey; + + if ( RegOpenKeyW( hBaseKey, + reinterpret_cast<LPCWSTR>(aKey.GetBuffer()), + &hRegKey ) == ERROR_SUCCESS ) + { + LONG lRet; + sal_Unicode PathW[_MAX_PATH]; + DWORD lSize = sizeof(PathW) / sizeof( sal_Unicode ); + DWORD Type = REG_SZ; + + lRet = RegQueryValueExW(hRegKey, reinterpret_cast<LPCWSTR>(aValueName.GetBuffer()), NULL, &Type, (LPBYTE)PathW, &lSize); + + if ((lRet == ERROR_SUCCESS) && (Type == REG_SZ)) + { + aRet = String( PathW ); + } + + RegCloseKey(hRegKey); + } + return aRet; +} + + diff --git a/automation/source/testtool/registry_win.hxx b/automation/source/testtool/registry_win.hxx new file mode 100644 index 000000000000..7099f39a3874 --- /dev/null +++ b/automation/source/testtool/registry_win.hxx @@ -0,0 +1,31 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#include <tools/string.hxx> + +String ReadRegistry( String aKey, String aValueName ); diff --git a/automation/source/testtool/sysdir_win.cxx b/automation/source/testtool/sysdir_win.cxx new file mode 100644 index 000000000000..ec87c65cfb4a --- /dev/null +++ b/automation/source/testtool/sysdir_win.cxx @@ -0,0 +1,105 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_automation.hxx" + +//////////////////////////////////////////////////////////////////////////// +//// +//// Windows ONLY +//// +//////////////////////////////////////////////////////////////////////////// + + +#include <tools/prewin.h> +#ifndef _SHOBJ_H +#if defined _MSC_VER +#pragma warning(push, 1) +#pragma warning(disable: 4917) +#endif +#include <shlobj.h> +#if defined _MSC_VER +#pragma warning(pop) +#endif +#endif +#include <tools/postwin.h> +// as we define it ourselves further down the line we remove it here +#ifdef IS_ERROR + #undef IS_ERROR +#endif + +#include <tchar.h> +#include "sysdir_win.hxx" + + +//////// copied this from setup2\win\source\system\winos.cxx + +void _SHFree( void *pv ) +{ + IMalloc *pMalloc; + if( NOERROR == SHGetMalloc(&pMalloc) ) + { + pMalloc->Free( pv ); + pMalloc->Release(); + } +} + +#define ALLOC(type, n) ((type *) HeapAlloc(GetProcessHeap(), 0, sizeof(type) * n )) +#define FREE(p) HeapFree(GetProcessHeap(), 0, p) + +UniString _SHGetSpecialFolder( int nFolderID ) +{ + + LPITEMIDLIST pidl; + HRESULT hHdl = SHGetSpecialFolderLocation( NULL, nFolderID, &pidl ); + UniString aFolder; + + if( hHdl == NOERROR ) + { + WCHAR *lpFolderW; + lpFolderW = ALLOC( WCHAR, 16000 ); + + SHGetPathFromIDListW( pidl, lpFolderW ); + aFolder = UniString( reinterpret_cast<const sal_Unicode*>(lpFolderW) ); + + FREE( lpFolderW ); + _SHFree( pidl ); + } + return aFolder; +} + + +/////////////// end of copy + + + +String _SHGetSpecialFolder_COMMON_APPDATA() +{ + return _SHGetSpecialFolder( CSIDL_COMMON_APPDATA ); +} + + diff --git a/automation/source/testtool/sysdir_win.hxx b/automation/source/testtool/sysdir_win.hxx new file mode 100644 index 000000000000..f406f69572db --- /dev/null +++ b/automation/source/testtool/sysdir_win.hxx @@ -0,0 +1,31 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#include <tools/string.hxx> + +String _SHGetSpecialFolder_COMMON_APPDATA(); diff --git a/automation/source/testtool/tcommuni.cxx b/automation/source/testtool/tcommuni.cxx new file mode 100644 index 000000000000..97684cfba2cf --- /dev/null +++ b/automation/source/testtool/tcommuni.cxx @@ -0,0 +1,200 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_automation.hxx" + + +#include <tools/config.hxx> +#include <vcl/svapp.hxx> +#include <tools/time.hxx> +#include <tools/debug.hxx> +#include <vcl/timer.hxx> + +#ifndef _BASIC_TTRESHLP_HXX +#include <basic/ttstrhlp.hxx> +#endif + +#include "rcontrol.hxx" +#include "tcommuni.hxx" +#include <basic/testtool.hxx> + +CommunicationManagerClientViaSocketTT::CommunicationManagerClientViaSocketTT() +: CommunicationManagerClientViaSocket( TRUE ) +, aAppPath() +, aAppParams() +, pProcess( NULL ) +{ +} + + +BOOL CommunicationManagerClientViaSocketTT::StartCommunication() +{ + bApplicationStarted = FALSE; + return CommunicationManagerClientViaSocket::StartCommunication( ByteString( GetHostConfig(), RTL_TEXTENCODING_UTF8 ), GetTTPortConfig() ); +} + + +BOOL CommunicationManagerClientViaSocketTT::StartCommunication( String aApp, String aParams, Environment *pChildEnv ) +{ + aAppPath = aApp; + aAppParams = aParams; + aAppEnv = (*pChildEnv); + return StartCommunication(); +} + + +BOOL CommunicationManagerClientViaSocketTT::RetryConnect() +{ + if ( !bApplicationStarted ) + { + // Die App ist wohl nicht da. Starten wir sie mal. + if ( aAppPath.Len() ) + { + delete pProcess; + + pProcess = new Process(); + pProcess->SetImage( aAppPath, aAppParams, &aAppEnv ); + + BOOL bSucc = pProcess->Start(); + bApplicationStarted = TRUE; + + if ( bSucc ) + { + aFirstRetryCall = Time() + Time( 0, 1 ); // Max eine Minute Zeit + for ( int i = 10 ; i-- ; ) + GetpApp()->Reschedule(); + } + return bSucc; + } + return FALSE; + } + else + { + if ( aFirstRetryCall > Time() ) + { + Timer aWait; + aWait.SetTimeout( 500 ); // Max 500 mSec + aWait.Start(); + while ( aWait.IsActive() ) + GetpApp()->Yield(); + return TRUE; + } + else + return FALSE; + } +} + +BOOL CommunicationManagerClientViaSocketTT::KillApplication() +{ + if ( pProcess ) + return pProcess->Terminate(); + return TRUE; +} + +#define GETSET(aVar, KeyName, Dafault) \ + aVar = aConf.ReadKey(KeyName,"No Entry"); \ + if ( aVar.CompareTo("No Entry") == COMPARE_EQUAL ) \ + { \ + aVar = ByteString(Dafault); \ + aConf.WriteKey(KeyName, aVar); \ + } + + +String GetHostConfig() +{ + String aHostToTalk; + + for ( USHORT i = 0 ; i < Application::GetCommandLineParamCount() ; i++ ) + { + if ( Application::GetCommandLineParam( i ).Copy(0,6).CompareIgnoreCaseToAscii("-host=") == COMPARE_EQUAL +#ifndef UNX + || Application::GetCommandLineParam( i ).Copy(0,6).CompareIgnoreCaseToAscii("/host=") == COMPARE_EQUAL +#endif + ) + return Application::GetCommandLineParam( i ).Copy(6); + } + + ByteString abHostToTalk; + Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") )); + aConf.SetGroup("Communication"); + + GETSET( abHostToTalk, "Host", DEFAULT_HOST ); + return UniString( abHostToTalk, RTL_TEXTENCODING_UTF8 ); +} + + +ULONG GetTTPortConfig() +{ + String aPortToTalk; + + for ( USHORT i = 0 ; i < Application::GetCommandLineParamCount() ; i++ ) + { + if ( Application::GetCommandLineParam( i ).Copy(0,6).CompareIgnoreCaseToAscii("-port=") == COMPARE_EQUAL +#ifndef UNX + || Application::GetCommandLineParam( i ).Copy(0,6).CompareIgnoreCaseToAscii("/port=") == COMPARE_EQUAL +#endif + ) + { + aPortToTalk = Application::GetCommandLineParam( i ).Copy(6); + return (ULONG)aPortToTalk.ToInt64(); + } + } + + ByteString abPortToTalk; + Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") )); + aConf.SetGroup("Communication"); + + GETSET( abPortToTalk, "TTPort", ByteString::CreateFromInt32( TESTTOOL_DEFAULT_PORT ) ); + return (ULONG)abPortToTalk.ToInt64(); +} + + +ULONG GetUnoPortConfig() +{ + String aPortToTalk; + + for ( USHORT i = 0 ; i < Application::GetCommandLineParamCount() ; i++ ) + { + if ( Application::GetCommandLineParam( i ).Copy(0,9).CompareIgnoreCaseToAscii("-unoport=") == COMPARE_EQUAL +#ifndef UNX + || Application::GetCommandLineParam( i ).Copy(0,9).CompareIgnoreCaseToAscii("/unoport=") == COMPARE_EQUAL +#endif + ) + { + aPortToTalk = Application::GetCommandLineParam( i ).Copy(6); + return (ULONG)aPortToTalk.ToInt64(); + } + } + + ByteString abPortToTalk; + Config aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") )); + aConf.SetGroup("Communication"); + + GETSET( abPortToTalk, "UnoPort", ByteString::CreateFromInt32( UNO_DEFAULT_PORT ) ); + return (ULONG)abPortToTalk.ToInt64(); +} diff --git a/automation/source/testtool/tcommuni.hxx b/automation/source/testtool/tcommuni.hxx new file mode 100644 index 000000000000..4374edfd7fc9 --- /dev/null +++ b/automation/source/testtool/tcommuni.hxx @@ -0,0 +1,67 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <automation/communi.hxx> +#include <tools/link.hxx> +#include <svl/svarray.hxx> + +#include <vos/thread.hxx> + +#ifndef _STRING_LIST +DECLARE_LIST( StringList, String * ) +#define _STRING_LIST +#endif +#include <basic/process.hxx> + +class Process; + +class CommunicationManagerClientViaSocketTT : public CommunicationManagerClientViaSocket +{ +public: + CommunicationManagerClientViaSocketTT(); + + using CommunicationManagerClientViaSocket::StartCommunication; + virtual BOOL StartCommunication(); + virtual BOOL StartCommunication( String aApp, String aParams, Environment *pChildEnv ); + + BOOL KillApplication(); + +protected: + virtual BOOL RetryConnect(); + BOOL bApplicationStarted; + Time aFirstRetryCall; + String aAppPath; + String aAppParams; + Environment aAppEnv; + Process *pProcess; +}; + + +String GetHostConfig(); +ULONG GetTTPortConfig(); +ULONG GetUnoPortConfig(); + diff --git a/automation/source/testtool/testtool.ini b/automation/source/testtool/testtool.ini new file mode 100644 index 000000000000..ff2e43f5c0f6 --- /dev/null +++ b/automation/source/testtool/testtool.ini @@ -0,0 +1,19 @@ +[Bootstrap] +URE_BOOTSTRAP=${ORIGIN}/fundamentalbasis!INIFILESUFFIX! +OOO_BASE_DIR=${ORIGIN}/.. +BRAND_BASE_DIR=${OOO_BASE_DIR}/!BRANDPATH! +UserInstallation=${SYSUSERCONFIG}/.oootesttool + +[Misc] +CurrentProfile=_profile_Default + +[OOoProgramDir] +Type=Path +Current=. + +[Crashreporter] +UseProxy=false +ProxyServer=none +ProxyPort=8080 +AllowContact=false +ReturnAddress= |