1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_soltools.hxx" 30*cdf0e10cSrcweir #include "tstMgr.hxx" 31*cdf0e10cSrcweir #include <osl/module.hxx> 32*cdf0e10cSrcweir #include <rtl/tres.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #ifndef _SOLTOOLS_TESTSHL_TLOG_HXX_ 35*cdf0e10cSrcweir #include "tlog.hxx" 36*cdf0e10cSrcweir #endif 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #ifndef _SOLTOOLS_TESTSHL_TUTIL_HXX_ 39*cdf0e10cSrcweir #include "tutil.hxx" 40*cdf0e10cSrcweir #endif 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir using namespace rtl; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir // <namespace_tstutl> 45*cdf0e10cSrcweir namespace tstutl { 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir typedef void* ( tstFunc )( TestResult* ); 48*cdf0e10cSrcweir void test_Entry_Impl( ::osl::Module& oMod, TestResult* oRes ); 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir // <private_members> 51*cdf0e10cSrcweir struct tstMgr::tstMgr_Impl { 52*cdf0e10cSrcweir ::osl::Module m_tstmodule; 53*cdf0e10cSrcweir sal_Bool m_boom; 54*cdf0e10cSrcweir }; 55*cdf0e10cSrcweir // </private_members> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir // <method_initialize> 58*cdf0e10cSrcweir sal_Bool tstMgr::initialize( sal_Char* modName, sal_Bool boom ) { 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir ::rtl::OUString tstMod( ::rtl::OUString::createFromAscii( modName ) ); 61*cdf0e10cSrcweir pImpl = new tstMgr_Impl; 62*cdf0e10cSrcweir pImpl->m_boom = boom; 63*cdf0e10cSrcweir return ( pImpl->m_tstmodule.load( tstMod ) ); 64*cdf0e10cSrcweir } // <method_initialize> 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir // <method_test_Entries> 67*cdf0e10cSrcweir sal_Bool tstMgr::test_Entries( vector< sal_Char* > entries, 68*cdf0e10cSrcweir sal_Char* logName ) { 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir sal_Bool bOK = sal_False; 71*cdf0e10cSrcweir if ( ! entries.empty() ) { 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir bOK = sal_True; 74*cdf0e10cSrcweir vector< sal_Char* >::iterator iter = entries.begin(); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir tLog log( logName ); 77*cdf0e10cSrcweir // open testLog 78*cdf0e10cSrcweir log.open(); 79*cdf0e10cSrcweir while ( iter != entries.end() ) { 80*cdf0e10cSrcweir if ( *iter[0] != '#' ) { 81*cdf0e10cSrcweir ::rtl::TestResult oRes( *iter, pImpl->m_boom ); 82*cdf0e10cSrcweir test_Entry_Impl( pImpl->m_tstmodule, &oRes ); 83*cdf0e10cSrcweir bOK &= oRes.getState(); 84*cdf0e10cSrcweir log.writeRes( oRes ); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir iter++; 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir log.close(); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir return ( bOK ); 91*cdf0e10cSrcweir } // </method_test_Entries> 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir // <method_test_Entry> 94*cdf0e10cSrcweir sal_Bool tstMgr::test_Entry( sal_Char* entry, sal_Char* logName ) { 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir tLog log( logName ); 97*cdf0e10cSrcweir // open testLog 98*cdf0e10cSrcweir log.open(); 99*cdf0e10cSrcweir ::rtl::TestResult oRes( entry, pImpl->m_boom ); 100*cdf0e10cSrcweir test_Entry_Impl( pImpl->m_tstmodule, &oRes ); 101*cdf0e10cSrcweir log.writeRes( oRes, sal_True ); 102*cdf0e10cSrcweir log.close(); 103*cdf0e10cSrcweir return ( oRes.getState() ); 104*cdf0e10cSrcweir } // </method_test_Entry> 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir // <method_test_EntriesFromFile> 107*cdf0e10cSrcweir sal_Bool tstMgr::test_EntriesFromFile( sal_Char* fName, sal_Char* logName ) { 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir sal_Bool bOK = sal_False; 110*cdf0e10cSrcweir vector< sal_Char* > entries; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir if ( getEntriesFromFile( fName, entries ) ) { 113*cdf0e10cSrcweir sal_Bool bOK = test_Entries( entries, logName ); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir vector< sal_Char* >::iterator iter = entries.begin(); 116*cdf0e10cSrcweir while ( iter != entries.end() ) { 117*cdf0e10cSrcweir if ( *iter ) { 118*cdf0e10cSrcweir delete [] *iter; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir iter++; 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir else { 124*cdf0e10cSrcweir bOK = test_Entry( fName ); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir return ( bOK ); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir } // </method_test_EntriesFromFile> 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir // <method_cleanup> 131*cdf0e10cSrcweir void tstMgr::cleanup() { 132*cdf0e10cSrcweir if ( pImpl ) { 133*cdf0e10cSrcweir delete pImpl; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir } // </method_cleanup> 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // <function_test_Entry_Impl> 139*cdf0e10cSrcweir void test_Entry_Impl( ::osl::Module& oMod, ::rtl::TestResult* oRes ) { 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir tstFunc* pFunc; // entry pointer 142*cdf0e10cSrcweir ::rtl::OString entryName( "test_" ); // entryname prefix 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir // prefix entryname 145*cdf0e10cSrcweir entryName += oRes->getName(); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir // get entry pointer 148*cdf0e10cSrcweir pFunc = (tstFunc*) oMod.getSymbol( 149*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( entryName.getStr() ) ); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir if ( pFunc ) { 152*cdf0e10cSrcweir // call entry 153*cdf0e10cSrcweir pFunc( oRes ); 154*cdf0e10cSrcweir oRes->end(); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir else { 157*cdf0e10cSrcweir oRes->end("symbol not found"); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir // return 160*cdf0e10cSrcweir return; 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir } // </function_test_Entry_Impl> 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir } // </namespace_tstutl> 165