1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: objtest.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 #include <tools/fsys.hxx>
37 #include <testapp.hxx>
38 #include <testtool.hxx>
39 #include "cmdstrm.hxx"
40 #include <basic/basicrt.hxx>
41 #include <vcl/smartid.hxx>
42 #include "httprequest.hxx"
46 // #define ID_BeginBlock 1
47 // #define ID_EndBlock 2
50 #define ID_ErrorDummy 5 // Intern zum Behandlen von Fehlenden Controls und Methoden
51 #define ID_RecordError 6
55 // #define ID_AppAbort 10
56 #define ID_Dispatch 11
57 #define ID_UNODispatch 12
59 #define ID_StartUse 14
61 #define ID_FinishUse 16
63 #define ID_ExceptLog 18
64 #define ID_PrintLog 19
66 #define ID_ErrorLog 21
67 #define ID_EnableQaErrors 22
68 #define ID_QAErrorLog 23
69 #define ID_MaybeAddErr 24
70 #define ID_ClearError 25
71 #define ID_GetNextCloseWindow 26
72 #define ID_RemoteCommand 27
74 #define ID_AutoExecute 29
76 #define ID_DialogHandler 31
77 #define ID_GetUnoApp 32
78 #define ID_GetIServer 33
79 #define ID_RemoteCommandDelay 34
80 #define ID_GetApplicationPath 35
81 #define ID_GetCommonApplicationPath 36
82 #define ID_MakeIniFileName 37
83 #define ID_StringControl 38
85 #define ID_GetErrorCount 40
86 #define ID_GetWarningCount 41
87 #define ID_GetQAErrorCount 42
88 #define ID_GetUseFileWarningCount 43
89 #define ID_GetErrorList 44
90 #define ID_GetWarningList 45
91 #define ID_GetQAErrorList 46
92 #define ID_GetUseFileWarningList 47
93 #define ID_GetTestCaseName 48
94 #define ID_GetTestCaseFileName 49
95 #define ID_GetTestCaseLineNr 50
96 #define ID_StopOnSyntaxError 51
97 #define ID_SetChildEnv 52
98 #define ID_GetChildEnv 53
99 #define ID_GetLinkDestination 54
100 #define ID_GetRegistryValue 55
101 #define ID_KillApp 56
102 #define ID_HTTPSend 57
103 #define ID_HTTPSetProxy 58
104 #define ID_DoNothing 99
106 void ReadFlatArray( const ControlDefLoad arWas
[], CNames
*&pNames
);
115 DBG_NAMEEX( ControlItem
)
116 DBG_NAMEEX( ControlDef
)
120 void InitData() { pData
= new ControlData
; }
124 ControlItem( const char *Name
, SmartId aUIdP
);
125 ControlItem( const String
&Name
, SmartId aUIdP
);
126 // ControlItem( const String &Name, const String &URL, const URLType aType );
127 // ControlItem( const String &Name, const String &URL, const ULONG nUId );
128 // ControlItem( const char *Name, const String &URL, const ULONG nUId );
129 ControlItem( ControlData
*pDataP
);
130 virtual ~ControlItem() {
131 DBG_DTOR(ControlItem
,0);
134 virtual BOOL
operator < (const ControlItem
&rPar
)=0;
135 virtual BOOL
operator == (const ControlItem
&rPar
)=0;
136 // void Write( SvStream &aStream );
139 SV_DECL_PTRARR_SORT_DEL(CNames
, ControlItem
*, 50, 10)
141 #define MK_SON_ACCESS( ClassName )\
142 BOOL SonInsert( const ClassName *pNewEntry ) { return pSons->C40_PTR_INSERT( ControlItem, (ControlItem*&)pNewEntry ); }\
143 BOOL SonSeek_Entry( const ClassName *pSearchEntry, USHORT *nRes = NULL) { return pSons->Seek_Entry( pSearchEntry, nRes ); }\
144 ClassName* SonGetObject( USHORT nNr ) { return (ClassName*)pSons->GetObject( nNr ); }
149 CNames
*pSons
; // um sicherzustelle, daß nur Söhne des richtien Type reinkommen
152 ControlSon() : pSons( NULL
) {};
154 // void Write( SvStream &aStream );
156 USHORT
Son_Count() { return pSons
->Count(); }
157 void Sons( CNames
*pNewSons
) { pSons
= pNewSons
; }
158 CNames
*& GetSons() { return pSons
; }
161 class ControlItemSon
: public ControlItem
, public ControlSon
164 ControlItemSon(const char *Name
, SmartId aUIdP
)
165 : ControlItem( Name
, aUIdP
) {}
166 ControlItemSon(const String
&Name
, SmartId aUIdP
);
167 // ControlItemSon(const String &Name, const String &URL, const URLType aType );
168 // ControlItemSon(const String &Name, const String &URL, const ULONG nUId );
169 // ControlItemSon(const char *Name, const String &URL, const ULONG nUId );
170 // void Write( SvStream &aStream );
173 class ControlDef
: public ControlItemSon
176 ControlDef(const char *Name
, SmartId aUIdP
)
177 : ControlItemSon( Name
, aUIdP
) {DBG_CTOR(ControlDef
,0);}
178 ControlDef(const String
&Name
, SmartId aUIdP
);
179 // ControlDef(const String &Name, const String &URL, const URLType aType );
180 ControlDef(const String
&aOldName
, const String
&aNewName
, ControlDef
*pOriginal
, BOOL bWithSons
= FALSE
);
181 ~ControlDef() {DBG_DTOR(ControlDef
,0);}
182 virtual BOOL
operator < (const ControlItem
&rPar
);
183 virtual BOOL
operator == (const ControlItem
&rPar
);
184 void Write( SvStream
&aStream
);
185 MK_SON_ACCESS( ControlDef
)
188 class ControlItemUId
: public ControlItem
191 ControlItemUId(String Name
, SmartId aUIdP
)
192 : ControlItem( Name
, aUIdP
){}
193 virtual BOOL
operator < (const ControlItem
&rPar
);
194 virtual BOOL
operator == (const ControlItem
&rPar
);
197 class ControlItemUIdSon
: public ControlItemUId
, public ControlSon
200 ControlItemUIdSon(String Name
, SmartId aUIdP
) : ControlItemUId( Name
, aUIdP
) {}
201 MK_SON_ACCESS( ControlItemUId
)
204 class ReverseName
: public ControlItemUId
209 ReverseName(String Name
, SmartId aUIdP
, ULONG nSeq
) : ControlItemUId( Name
, aUIdP
), LastSequence(nSeq
) {}
212 class CRevNames
: public CNames
215 void Insert( String aName
, SmartId aUId
, ULONG nSeq
);
216 String
GetName( SmartId aUId
);
217 void Invalidate ( ULONG nSeq
);
221 class SbxTransportMethod
: public SbxMethod
224 SbxTransportMethod( SbxDataType
);
228 SV_DECL_IMPL_REF(SbxTransportMethod
);
230 class Controls
: public SbxObject
233 Controls( String aCName
);
235 void ChangeListener( SbxObject
* pParent
);
237 void SFX_NOTIFY( SfxBroadcaster
&, const TypeId
&, const SfxHint
& rHint
, const TypeId
& );
238 virtual SbxVariable
* Find( const String
&, SbxClassType
);
239 SbxTransportMethodRef pMethodVar
; // zum Transport von Find nach Notify
240 static CNames
*pClasses
;
241 static ControlDefLoad __READONLY_DATA arClasses
[];
243 SV_DECL_IMPL_REF(Controls
);
245 typedef std::map
< String
, String
> Environment
;
247 class ImplTestToolObj
251 // ~ImplTestToolObj()
253 String ProgParam
; // Parameter der zu Testenden APP; Gesetzt über Start
255 DirEntry aFileBase
; // Grundpfad für die *.sid und *.win Dateien (Aus Configdatei)
256 DirEntry aLogFileBase
; // Grundpfad für die *.res Dateien (Aus Configdatei)
257 DirEntry aHIDDir
; // Verzeichnis, in dem die hid.lst gesucht wird
259 SbxTransportMethodRef pNextReturn
; // Verweis auf die Var, die den Returnwert aufnimmt.
261 ControlsRef pControlsObj
; // Jeweiliges Objekt, an dem Methoden aufgerufen weden.
263 #define VAR_POOL_SIZE 8
264 SbxTransportMethodRef pMyVars
[VAR_POOL_SIZE
]; // Falls in Ausdrücken mehrere verwendet werden
269 // Profiling Datenfelder
270 ULONG LocalStarttime
;
272 ULONG naValBorders
[4];
273 ULONG naNumEntries
[5];
274 ULONG naRemoteTime
[5];
275 ULONG naLocalTime
[5];
277 ULONG nMinRemoteCommandDelay
;
278 ULONG nMaxRemoteCommandDelay
;
279 BOOL bDoRemoteCommandDelay
;
281 BOOL bLnaguageExtensionLoaded
; // Wurde über 'use' was geladen? Für syntax highlighting
282 SfxBroadcaster
*pTTSfxBroadcaster
;
287 ULONG nIncludeFileWarningCount
;
289 SbxDimArrayRef xErrorList
;
290 SbxDimArrayRef xWarningList
;
291 SbxDimArrayRef xQAErrorList
;
292 SbxDimArrayRef xIncludeFileWarningList
;
294 BOOL bIsStart
; // set tu TRUE while command Start is initiating the communication
298 String aTestCaseName
; // holds name of current TestCase
299 String aTestCaseFileName
; // holds FileName of current TestCase
300 USHORT nTestCaseLineNr
; // holds Line of current TestCase
302 BOOL bEnableQaErrors
; // include QA errors in report
303 BOOL bDebugFindNoErrors
; // suppress generating errors when find of variables is called for variable viewing purposes
305 BOOL bStopOnSyntaxError
; // catch syntax errors in testcases or not
307 Environment
*pChildEnv
; // Environment Variables for child Process
309 HttpRequest
*pHttpRequest
; // used for sending HTTP requests
316 static String
ms2s( ULONG nMilliSeconds
);
320 #define ADD_TO_LOG( aLogTypep, aMsgp, aFilenamep, nLinep, nCol1p, nCol2p, aRevisionp, pLogList )\
322 TTLogMsg *pLogMsg = new TTLogMsg(); \
323 pLogMsg->aDebugData.aMsg = aMsgp; \
324 pLogMsg->aLogFileName = (pImpl->aLogFileBase + DirEntry(aLogFileName)).GetFull(); \
325 pLogMsg->aDebugData.aFilename = aFilenamep; \
326 pLogMsg->aDebugData.nLine = nLinep; \
327 pLogMsg->aDebugData.nCol1 = nCol1p; \
328 pLogMsg->aDebugData.nCol2 = nCol2p; \
329 pLogMsg->aDebugData.aLogType = aLogTypep; \
330 aLogHdl.Call( pLogMsg ); \
331 void* pDummyForWarningAboutNULL = pLogList; \
332 if( pDummyForWarningAboutNULL ) \
334 SbxDimArray* pLogArray = (SbxDimArray*)pLogList; \
335 SbxVariable* pLogLine = new SbxVariable( SbxSTRING ); \
337 aCollect.Append( pLogMsg->aDebugData.aFilename ); \
338 aCollect.AppendAscii( ";" ); \
339 aCollect.Append( String::CreateFromInt32( nLinep ) ); \
340 aCollect.AppendAscii( ";" ); \
341 aCollect.Append( aRevisionp ); \
342 aCollect.AppendAscii( ";" ); \
343 aCollect.Append( pLogMsg->aDebugData.aMsg ); \
344 pLogLine->PutString( aCollect ); \
345 pLogArray->Insert( pLogLine, pLogArray->Count() ); \
351 #define ADD_RUN_LOG() \
352 ADD_TO_LOG(LOG_RUN, String(), String(), 0, 0, 0, String(), NULL) \
354 #define ADD_ERROR_LOG(aMsg, aFilename, nLine, nCol1, nCol2, aRevision) \
356 ADD_TO_LOG(LOG_ERROR, aMsg, aFilename, nLine, nCol1, nCol2, aRevision, &pImpl->xErrorList) \
357 pImpl->nErrorCount++; \
360 #define ADD_CALL_STACK_LOG(aMsg, aFilename, nLine, nCol1, nCol2) \
361 ADD_TO_LOG(LOG_CALL_STACK, aMsg, aFilename, nLine, nCol1, nCol2, String(), NULL) \
364 #define ADD_AUTO_LOG(aLogType, aMsg, pLogList) \
366 if ( BasicRuntimeAccess::HasRuntime() ) \
368 BasicRuntime aRun = BasicRuntimeAccess::GetRuntime(); \
369 ADD_TO_LOG(aLogType, aMsg, aRun.GetModuleName(SbxNAME_SHORT_TYPES), \
370 aRun.GetLine(), aRun.GetCol1(), aRun.GetCol2(), aRun.GetSourceRevision(), pLogList) \
374 ADD_TO_LOG(aLogType, aMsg, UniString(), 0, 0, STRING_LEN, String(), pLogList) \
378 #define ADD_CASE_LOG(aMsg) \
379 ADD_AUTO_LOG(LOG_TEST_CASE, aMsg, NULL) \
381 #define ADD_MESSAGE_LOG(aMsg) \
382 ADD_AUTO_LOG(LOG_MESSAGE, aMsg, NULL) \
384 #define ADD_WARNING_LOG(aMsg) \
386 ADD_AUTO_LOG(LOG_WARNING, aMsg, &pImpl->xWarningList) \
387 pImpl->nWarningCount++; \
390 #define ADD_WARNING_LOG2(aMsg, aFilename, nLine ) \
392 ADD_TO_LOG(LOG_WARNING, aMsg, aFilename, nLine, 0, STRING_LEN, String(), &pImpl->xWarningList) \
393 pImpl->nWarningCount++; \
396 #define ADD_ASSERTION_LOG(aMsg) \
397 ADD_AUTO_LOG(LOG_ASSERTION, aMsg, NULL) \
399 #define ADD_QA_ERROR_LOG(aMsg) \
400 if ( pImpl->bEnableQaErrors ) \
402 ADD_AUTO_LOG(LOG_QA_ERROR, aMsg, &pImpl->xQAErrorList) \
403 pImpl->nQAErrorCount++; \