update dev300-m58
[ooovba.git] / soltools / testSHL / util / tstMgr.cxx
blobd297c3d6eb46b3606cad61532212ebf012fec108
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tstMgr.cxx,v $
10 * $Revision: 1.6 $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_soltools.hxx"
33 #include "tstMgr.hxx"
34 #include <osl/module.hxx>
35 #include <rtl/tres.hxx>
37 #ifndef _SOLTOOLS_TESTSHL_TLOG_HXX_
38 #include "tlog.hxx"
39 #endif
41 #ifndef _SOLTOOLS_TESTSHL_TUTIL_HXX_
42 #include "tutil.hxx"
43 #endif
45 using namespace rtl;
47 // <namespace_tstutl>
48 namespace tstutl {
50 typedef void* ( tstFunc )( TestResult* );
51 void test_Entry_Impl( ::osl::Module& oMod, TestResult* oRes );
53 // <private_members>
54 struct tstMgr::tstMgr_Impl {
55 ::osl::Module m_tstmodule;
56 sal_Bool m_boom;
58 // </private_members>
60 // <method_initialize>
61 sal_Bool tstMgr::initialize( sal_Char* modName, sal_Bool boom ) {
63 ::rtl::OUString tstMod( ::rtl::OUString::createFromAscii( modName ) );
64 pImpl = new tstMgr_Impl;
65 pImpl->m_boom = boom;
66 return ( pImpl->m_tstmodule.load( tstMod ) );
67 } // <method_initialize>
69 // <method_test_Entries>
70 sal_Bool tstMgr::test_Entries( vector< sal_Char* > entries,
71 sal_Char* logName ) {
73 sal_Bool bOK = sal_False;
74 if ( ! entries.empty() ) {
76 bOK = sal_True;
77 vector< sal_Char* >::iterator iter = entries.begin();
79 tLog log( logName );
80 // open testLog
81 log.open();
82 while ( iter != entries.end() ) {
83 if ( *iter[0] != '#' ) {
84 ::rtl::TestResult oRes( *iter, pImpl->m_boom );
85 test_Entry_Impl( pImpl->m_tstmodule, &oRes );
86 bOK &= oRes.getState();
87 log.writeRes( oRes );
89 iter++;
91 log.close();
93 return ( bOK );
94 } // </method_test_Entries>
96 // <method_test_Entry>
97 sal_Bool tstMgr::test_Entry( sal_Char* entry, sal_Char* logName ) {
99 tLog log( logName );
100 // open testLog
101 log.open();
102 ::rtl::TestResult oRes( entry, pImpl->m_boom );
103 test_Entry_Impl( pImpl->m_tstmodule, &oRes );
104 log.writeRes( oRes, sal_True );
105 log.close();
106 return ( oRes.getState() );
107 } // </method_test_Entry>
109 // <method_test_EntriesFromFile>
110 sal_Bool tstMgr::test_EntriesFromFile( sal_Char* fName, sal_Char* logName ) {
112 sal_Bool bOK = sal_False;
113 vector< sal_Char* > entries;
115 if ( getEntriesFromFile( fName, entries ) ) {
116 sal_Bool bOK = test_Entries( entries, logName );
118 vector< sal_Char* >::iterator iter = entries.begin();
119 while ( iter != entries.end() ) {
120 if ( *iter ) {
121 delete [] *iter;
123 iter++;
126 else {
127 bOK = test_Entry( fName );
129 return ( bOK );
131 } // </method_test_EntriesFromFile>
133 // <method_cleanup>
134 void tstMgr::cleanup() {
135 if ( pImpl ) {
136 delete pImpl;
138 } // </method_cleanup>
141 // <function_test_Entry_Impl>
142 void test_Entry_Impl( ::osl::Module& oMod, ::rtl::TestResult* oRes ) {
144 tstFunc* pFunc; // entry pointer
145 ::rtl::OString entryName( "test_" ); // entryname prefix
147 // prefix entryname
148 entryName += oRes->getName();
150 // get entry pointer
151 pFunc = (tstFunc*) oMod.getSymbol(
152 ::rtl::OUString::createFromAscii( entryName.getStr() ) );
154 if ( pFunc ) {
155 // call entry
156 pFunc( oRes );
157 oRes->end();
159 else {
160 oRes->end("symbol not found");
162 // return
163 return;
165 } // </function_test_Entry_Impl>
167 } // </namespace_tstutl>