xref: /aoo42x/main/soltools/testSHL/util/tstMgr.cxx (revision 7a4715d3)
1*7a4715d3SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*7a4715d3SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*7a4715d3SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*7a4715d3SAndrew Rist  * distributed with this work for additional information
6*7a4715d3SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*7a4715d3SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*7a4715d3SAndrew Rist  * "License"); you may not use this file except in compliance
9*7a4715d3SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*7a4715d3SAndrew Rist  *
11*7a4715d3SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*7a4715d3SAndrew Rist  *
13*7a4715d3SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*7a4715d3SAndrew Rist  * software distributed under the License is distributed on an
15*7a4715d3SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*7a4715d3SAndrew Rist  * KIND, either express or implied.  See the License for the
17*7a4715d3SAndrew Rist  * specific language governing permissions and limitations
18*7a4715d3SAndrew Rist  * under the License.
19*7a4715d3SAndrew Rist  *
20*7a4715d3SAndrew Rist  *************************************************************/
21*7a4715d3SAndrew Rist 
22*7a4715d3SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_soltools.hxx"
26cdf0e10cSrcweir #include "tstMgr.hxx"
27cdf0e10cSrcweir #include <osl/module.hxx>
28cdf0e10cSrcweir #include <rtl/tres.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #ifndef _SOLTOOLS_TESTSHL_TLOG_HXX_
31cdf0e10cSrcweir #include "tlog.hxx"
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #ifndef _SOLTOOLS_TESTSHL_TUTIL_HXX_
35cdf0e10cSrcweir #include "tutil.hxx"
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir 
38cdf0e10cSrcweir using namespace rtl;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // <namespace_tstutl>
41cdf0e10cSrcweir namespace tstutl {
42cdf0e10cSrcweir 
43cdf0e10cSrcweir typedef void* ( tstFunc )( TestResult* );
44cdf0e10cSrcweir void test_Entry_Impl( ::osl::Module& oMod, TestResult* oRes );
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // <private_members>
47cdf0e10cSrcweir struct tstMgr::tstMgr_Impl {
48cdf0e10cSrcweir     ::osl::Module m_tstmodule;
49cdf0e10cSrcweir     sal_Bool m_boom;
50cdf0e10cSrcweir };
51cdf0e10cSrcweir // </private_members>
52cdf0e10cSrcweir 
53cdf0e10cSrcweir // <method_initialize>
initialize(sal_Char * modName,sal_Bool boom)54cdf0e10cSrcweir sal_Bool tstMgr::initialize( sal_Char* modName, sal_Bool boom ) {
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     ::rtl::OUString tstMod( ::rtl::OUString::createFromAscii( modName ) );
57cdf0e10cSrcweir     pImpl = new tstMgr_Impl;
58cdf0e10cSrcweir     pImpl->m_boom = boom;
59cdf0e10cSrcweir     return ( pImpl->m_tstmodule.load( tstMod ) );
60cdf0e10cSrcweir } // <method_initialize>
61cdf0e10cSrcweir 
62cdf0e10cSrcweir // <method_test_Entries>
test_Entries(vector<sal_Char * > entries,sal_Char * logName)63cdf0e10cSrcweir sal_Bool tstMgr::test_Entries( vector< sal_Char* > entries,
64cdf0e10cSrcweir                                                         sal_Char* logName ) {
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     sal_Bool bOK = sal_False;
67cdf0e10cSrcweir     if ( ! entries.empty() ) {
68cdf0e10cSrcweir 
69cdf0e10cSrcweir         bOK = sal_True;
70cdf0e10cSrcweir         vector< sal_Char* >::iterator iter = entries.begin();
71cdf0e10cSrcweir 
72cdf0e10cSrcweir         tLog log( logName );
73cdf0e10cSrcweir         // open testLog
74cdf0e10cSrcweir         log.open();
75cdf0e10cSrcweir             while ( iter != entries.end() ) {
76cdf0e10cSrcweir                 if ( *iter[0] != '#' ) {
77cdf0e10cSrcweir                     ::rtl::TestResult oRes( *iter, pImpl->m_boom );
78cdf0e10cSrcweir                     test_Entry_Impl( pImpl->m_tstmodule, &oRes );
79cdf0e10cSrcweir                     bOK &= oRes.getState();
80cdf0e10cSrcweir                     log.writeRes( oRes );
81cdf0e10cSrcweir                 }
82cdf0e10cSrcweir 				iter++;
83cdf0e10cSrcweir             }
84cdf0e10cSrcweir         log.close();
85cdf0e10cSrcweir     }
86cdf0e10cSrcweir     return ( bOK );
87cdf0e10cSrcweir } // </method_test_Entries>
88cdf0e10cSrcweir 
89cdf0e10cSrcweir // <method_test_Entry>
test_Entry(sal_Char * entry,sal_Char * logName)90cdf0e10cSrcweir sal_Bool tstMgr::test_Entry( sal_Char* entry, sal_Char* logName ) {
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     tLog log( logName );
93cdf0e10cSrcweir     // open testLog
94cdf0e10cSrcweir     log.open();
95cdf0e10cSrcweir     ::rtl::TestResult oRes( entry, pImpl->m_boom );
96cdf0e10cSrcweir     test_Entry_Impl( pImpl->m_tstmodule, &oRes );
97cdf0e10cSrcweir     log.writeRes( oRes, sal_True );
98cdf0e10cSrcweir     log.close();
99cdf0e10cSrcweir     return ( oRes.getState() );
100cdf0e10cSrcweir } // </method_test_Entry>
101cdf0e10cSrcweir 
102cdf0e10cSrcweir // <method_test_EntriesFromFile>
test_EntriesFromFile(sal_Char * fName,sal_Char * logName)103cdf0e10cSrcweir sal_Bool tstMgr::test_EntriesFromFile( sal_Char* fName, sal_Char* logName ) {
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     sal_Bool bOK = sal_False;
106cdf0e10cSrcweir     vector< sal_Char* > entries;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     if ( getEntriesFromFile( fName, entries ) ) {
109cdf0e10cSrcweir         sal_Bool bOK = test_Entries( entries, logName );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir         vector< sal_Char* >::iterator iter =  entries.begin();
112cdf0e10cSrcweir         while ( iter != entries.end() ) {
113cdf0e10cSrcweir             if ( *iter ) {
114cdf0e10cSrcweir                 delete [] *iter;
115cdf0e10cSrcweir             }
116cdf0e10cSrcweir             iter++;
117cdf0e10cSrcweir         }
118cdf0e10cSrcweir     }
119cdf0e10cSrcweir     else  {
120cdf0e10cSrcweir         bOK = test_Entry( fName );
121cdf0e10cSrcweir     }
122cdf0e10cSrcweir     return ( bOK );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir } // </method_test_EntriesFromFile>
125cdf0e10cSrcweir 
126cdf0e10cSrcweir // <method_cleanup>
cleanup()127cdf0e10cSrcweir void tstMgr::cleanup() {
128cdf0e10cSrcweir     if ( pImpl ) {
129cdf0e10cSrcweir         delete pImpl;
130cdf0e10cSrcweir     }
131cdf0e10cSrcweir } // </method_cleanup>
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 
134cdf0e10cSrcweir // <function_test_Entry_Impl>
test_Entry_Impl(::osl::Module & oMod,::rtl::TestResult * oRes)135cdf0e10cSrcweir void test_Entry_Impl( ::osl::Module& oMod, ::rtl::TestResult* oRes ) {
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     tstFunc* pFunc;                             // entry pointer
138cdf0e10cSrcweir     ::rtl::OString entryName( "test_" );        // entryname prefix
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     // prefix entryname
141cdf0e10cSrcweir     entryName += oRes->getName();
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     // get entry pointer
144cdf0e10cSrcweir     pFunc = (tstFunc*) oMod.getSymbol(
145cdf0e10cSrcweir                     ::rtl::OUString::createFromAscii( entryName.getStr() ) );
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     if ( pFunc ) {
148cdf0e10cSrcweir         // call entry
149cdf0e10cSrcweir         pFunc( oRes );
150cdf0e10cSrcweir         oRes->end();
151cdf0e10cSrcweir     }
152cdf0e10cSrcweir     else  {
153cdf0e10cSrcweir         oRes->end("symbol not found");
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir     // return
156cdf0e10cSrcweir     return;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir } // </function_test_Entry_Impl>
159cdf0e10cSrcweir 
160cdf0e10cSrcweir } // </namespace_tstutl>
161