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