1*89b56da7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*89b56da7SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*89b56da7SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*89b56da7SAndrew Rist * distributed with this work for additional information
6*89b56da7SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*89b56da7SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*89b56da7SAndrew Rist * "License"); you may not use this file except in compliance
9*89b56da7SAndrew Rist * with the License. You may obtain a copy of the License at
10*89b56da7SAndrew Rist *
11*89b56da7SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*89b56da7SAndrew Rist *
13*89b56da7SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*89b56da7SAndrew Rist * software distributed under the License is distributed on an
15*89b56da7SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*89b56da7SAndrew Rist * KIND, either express or implied. See the License for the
17*89b56da7SAndrew Rist * specific language governing permissions and limitations
18*89b56da7SAndrew Rist * under the License.
19*89b56da7SAndrew Rist *
20*89b56da7SAndrew Rist *************************************************************/
21*89b56da7SAndrew Rist
22*89b56da7SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_tools.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "tools/testtoolloader.hxx"
28cdf0e10cSrcweir #include <osl/module.h>
29cdf0e10cSrcweir #include <rtl/logfile.hxx>
30cdf0e10cSrcweir #include <vos/process.hxx>
31cdf0e10cSrcweir #include "tools/solar.h"
32cdf0e10cSrcweir #include "tools/string.hxx"
33cdf0e10cSrcweir #include "tools/debug.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include <comphelper/uieventslogger.hxx>
36cdf0e10cSrcweir
37cdf0e10cSrcweir using namespace rtl;
38cdf0e10cSrcweir
39cdf0e10cSrcweir namespace tools
40cdf0e10cSrcweir {
41cdf0e10cSrcweir typedef void ( *pfunc_CreateRemoteControl)();
42cdf0e10cSrcweir typedef void ( *pfunc_DestroyRemoteControl)();
43cdf0e10cSrcweir
44cdf0e10cSrcweir typedef void ( *pfunc_CreateEventLogger)();
45cdf0e10cSrcweir typedef void ( *pfunc_DestroyEventLogger)();
46cdf0e10cSrcweir
47cdf0e10cSrcweir static oslModule aTestToolModule = 0;
48cdf0e10cSrcweir // are we to be automated at all?
49cdf0e10cSrcweir static bool bAutomate = false;
50cdf0e10cSrcweir static bool bLoggerStarted = false;
51cdf0e10cSrcweir
52cdf0e10cSrcweir
GetCommandLineParamCount()53cdf0e10cSrcweir sal_uInt32 GetCommandLineParamCount()
54cdf0e10cSrcweir {
55cdf0e10cSrcweir vos:: OStartupInfo aStartInfo;
56cdf0e10cSrcweir return aStartInfo.getCommandArgCount();
57cdf0e10cSrcweir }
58cdf0e10cSrcweir
GetCommandLineParam(sal_uInt32 nParam)59cdf0e10cSrcweir String GetCommandLineParam( sal_uInt32 nParam )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir vos:: OStartupInfo aStartInfo;
62cdf0e10cSrcweir ::rtl::OUString aParam;
63cdf0e10cSrcweir vos:: OStartupInfo ::TStartupError eError = aStartInfo.getCommandArg( nParam, aParam );
64cdf0e10cSrcweir if ( eError == vos:: OStartupInfo ::E_None )
65cdf0e10cSrcweir return String( aParam );
66cdf0e10cSrcweir else
67cdf0e10cSrcweir {
68cdf0e10cSrcweir DBG_ERROR( "Unable to get CommandLineParam" );
69cdf0e10cSrcweir return String();
70cdf0e10cSrcweir }
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
thisModule()73cdf0e10cSrcweir extern "C" { static void SAL_CALL thisModule() {} }
74cdf0e10cSrcweir
LoadLib()75cdf0e10cSrcweir void LoadLib()
76cdf0e10cSrcweir {
77cdf0e10cSrcweir if ( !aTestToolModule )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir aTestToolModule = osl_loadModuleRelative(
80cdf0e10cSrcweir &thisModule,
81cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SVLIBRARY("sts"))).pData,
82cdf0e10cSrcweir SAL_LOADMODULE_GLOBAL );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
InitTestToolLib()86cdf0e10cSrcweir void InitTestToolLib()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "desktop (cd100003) ::InitTestToolLib" );
89cdf0e10cSrcweir
90cdf0e10cSrcweir sal_uInt32 i;
91cdf0e10cSrcweir
92cdf0e10cSrcweir for ( i = 0 ; i < GetCommandLineParamCount() ; i++ )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir if ( GetCommandLineParam( i ).EqualsIgnoreCaseAscii("/enableautomation")
95cdf0e10cSrcweir || GetCommandLineParam( i ).EqualsIgnoreCaseAscii("-enableautomation"))
96cdf0e10cSrcweir {
97cdf0e10cSrcweir bAutomate = true;
98cdf0e10cSrcweir break;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
102cdf0e10cSrcweir if ( bAutomate )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir OUString aFuncName( RTL_CONSTASCII_USTRINGPARAM( "CreateRemoteControl" ));
105cdf0e10cSrcweir
106cdf0e10cSrcweir LoadLib();
107cdf0e10cSrcweir if ( aTestToolModule )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir oslGenericFunction pInitFunc = osl_getFunctionSymbol(
110cdf0e10cSrcweir aTestToolModule, aFuncName.pData );
111cdf0e10cSrcweir if ( pInitFunc )
112cdf0e10cSrcweir (reinterpret_cast< pfunc_CreateRemoteControl >(pInitFunc))();
113cdf0e10cSrcweir else
114cdf0e10cSrcweir {
115cdf0e10cSrcweir DBG_ERROR1( "Unable to get Symbol 'CreateRemoteControl' from library %s while loading testtool support.", SVLIBRARY( "sts" ) );
116cdf0e10cSrcweir }
117cdf0e10cSrcweir }
118cdf0e10cSrcweir else
119cdf0e10cSrcweir {
120cdf0e10cSrcweir DBG_ERROR1( "Unable to access library %s while loading testtool support.", SVLIBRARY( "sts" ) );
121cdf0e10cSrcweir }
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir if ( ::comphelper::UiEventsLogger::isEnabled() )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir OUString aFuncName( RTL_CONSTASCII_USTRINGPARAM( "CreateEventLogger" ));
127cdf0e10cSrcweir
128cdf0e10cSrcweir LoadLib();
129cdf0e10cSrcweir if ( aTestToolModule )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir oslGenericFunction pInitFunc = osl_getFunctionSymbol(
132cdf0e10cSrcweir aTestToolModule, aFuncName.pData );
133cdf0e10cSrcweir if ( pInitFunc )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir (reinterpret_cast< pfunc_CreateEventLogger >(pInitFunc))();
136cdf0e10cSrcweir bLoggerStarted = sal_True;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir else
139cdf0e10cSrcweir {
140cdf0e10cSrcweir DBG_ERROR1( "Unable to get Symbol 'CreateEventLogger' from library %s while loading testtool support.", SVLIBRARY( "sts" ) );
141cdf0e10cSrcweir }
142cdf0e10cSrcweir }
143cdf0e10cSrcweir else
144cdf0e10cSrcweir {
145cdf0e10cSrcweir DBG_ERROR1( "Unable to access library %s while loading testtool support.", SVLIBRARY( "sts" ) );
146cdf0e10cSrcweir }
147cdf0e10cSrcweir }
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
DeInitTestToolLib()150cdf0e10cSrcweir void DeInitTestToolLib()
151cdf0e10cSrcweir {
152cdf0e10cSrcweir if ( aTestToolModule )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir if ( bAutomate )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir OUString aFuncName( RTL_CONSTASCII_USTRINGPARAM( "DestroyRemoteControl" ));
157cdf0e10cSrcweir
158cdf0e10cSrcweir oslGenericFunction pDeInitFunc = osl_getFunctionSymbol(
159cdf0e10cSrcweir aTestToolModule, aFuncName.pData );
160cdf0e10cSrcweir if ( pDeInitFunc )
161cdf0e10cSrcweir (reinterpret_cast< pfunc_DestroyRemoteControl >(pDeInitFunc))();
162cdf0e10cSrcweir }
163cdf0e10cSrcweir
164cdf0e10cSrcweir if ( bLoggerStarted /*::comphelper::UiEventsLogger::isEnabled()*/ )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir OUString aFuncName( RTL_CONSTASCII_USTRINGPARAM( "DestroyEventLogger" ));
167cdf0e10cSrcweir
168cdf0e10cSrcweir oslGenericFunction pDeInitFunc = osl_getFunctionSymbol(
169cdf0e10cSrcweir aTestToolModule, aFuncName.pData );
170cdf0e10cSrcweir if ( pDeInitFunc )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir (reinterpret_cast< pfunc_DestroyEventLogger >(pDeInitFunc))();
173cdf0e10cSrcweir bLoggerStarted = sal_False;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir }
176cdf0e10cSrcweir
177cdf0e10cSrcweir osl_unloadModule( aTestToolModule );
178cdf0e10cSrcweir }
179cdf0e10cSrcweir }
180cdf0e10cSrcweir
181cdf0e10cSrcweir } // namespace tools
182