diff options
Diffstat (limited to 'soltools/testSHL/util')
-rw-r--r-- | soltools/testSHL/util/makefile.mk | 45 | ||||
-rw-r--r-- | soltools/testSHL/util/tlog.cxx | 108 | ||||
-rw-r--r-- | soltools/testSHL/util/tstMgr.cxx | 164 | ||||
-rw-r--r-- | soltools/testSHL/util/tutil.cxx | 147 |
4 files changed, 464 insertions, 0 deletions
diff --git a/soltools/testSHL/util/makefile.mk b/soltools/testSHL/util/makefile.mk new file mode 100644 index 000000000000..a2582f9c1abd --- /dev/null +++ b/soltools/testSHL/util/makefile.mk @@ -0,0 +1,45 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME=soltools +TARGET=tstutil + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# ------------------------------------------------------------------ + +OBJFILES =\ + $(OBJ)$/tlog.obj \ + $(OBJ)$/tutil.obj \ + $(OBJ)$/tstMgr.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/soltools/testSHL/util/tlog.cxx b/soltools/testSHL/util/tlog.cxx new file mode 100644 index 000000000000..48eeafc7908a --- /dev/null +++ b/soltools/testSHL/util/tlog.cxx @@ -0,0 +1,108 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_soltools.hxx" + +#include "tlog.hxx" + +using namespace std; + +// <namespace_tstutl> +namespace tstutl { + +// <method_initialize> +void tLog::initialize( const ::rtl::OString& name ) { + m_logname = cnvrtPth( name ); + m_logfile = new ::osl::File( m_logname ); +} // </method_initialize> + +// <method_open> +::osl::FileBase::RC tLog::open( sal_Bool append ) { + + if ( m_logfile ) { + ::osl::FileBase::RC ret; + + if ( ! append ) { + ret = ::osl::File::remove( m_logname ); + } + + if( m_logfile->open( OpenFlag_Write ) == ::osl::FileBase::E_NOENT ) { + ret = m_logfile->open( OpenFlag_Write | OpenFlag_Create ); + } + else { + ret = m_logfile->setPos( Pos_End, 0 ); + } + return ret; + } + return ( ::osl::FileBase::E_INVAL ); +} // </method_open> + +// <method_close> +::osl::FileBase::RC tLog::close() { + if ( m_logfile ) { + return m_logfile->close(); + } + return ( ::osl::FileBase::E_INVAL ); +} // </method_close> + +// <method_writeRes> +::osl::FileBase::RC tLog::writeRes( ::rtl::TestResult& oRes, sal_Bool v, sal_Bool xml ) { + ::osl::FileBase::RC ret; + + sal_Char* ptr = oRes.getName(); + ptr = cat( ptr, ";" ); + ptr = cat( ptr, oRes.getResult() ); + ret = write( cat( ptr, "\n" ), v ); + delete [] ptr; + + return( ret ); +} // </method_writeRes> + +// <method_write> +::osl::FileBase::RC tLog::write( const sal_Char* buf, sal_Bool v ) { + + if ( ! m_logfile ) { + fprintf( stderr, "%s", buf ); + return ( ::osl::FileBase::E_NOENT ); + } + sal_uInt64 uBytes=0; + sal_uInt32 len = ln( buf ); + const sal_Char* ptr = buf; + + if ( v ) { + fprintf( stderr, "%s", buf ); + } + return m_logfile->write( buf, len , uBytes ); +} // </method_write> + +} // </namespace_tstutl> + + + + + diff --git a/soltools/testSHL/util/tstMgr.cxx b/soltools/testSHL/util/tstMgr.cxx new file mode 100644 index 000000000000..2aad1c758d41 --- /dev/null +++ b/soltools/testSHL/util/tstMgr.cxx @@ -0,0 +1,164 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_soltools.hxx" +#include "tstMgr.hxx" +#include <osl/module.hxx> +#include <rtl/tres.hxx> + +#ifndef _SOLTOOLS_TESTSHL_TLOG_HXX_ +#include "tlog.hxx" +#endif + +#ifndef _SOLTOOLS_TESTSHL_TUTIL_HXX_ +#include "tutil.hxx" +#endif + +using namespace rtl; + +// <namespace_tstutl> +namespace tstutl { + +typedef void* ( tstFunc )( TestResult* ); +void test_Entry_Impl( ::osl::Module& oMod, TestResult* oRes ); + +// <private_members> +struct tstMgr::tstMgr_Impl { + ::osl::Module m_tstmodule; + sal_Bool m_boom; +}; +// </private_members> + +// <method_initialize> +sal_Bool tstMgr::initialize( sal_Char* modName, sal_Bool boom ) { + + ::rtl::OUString tstMod( ::rtl::OUString::createFromAscii( modName ) ); + pImpl = new tstMgr_Impl; + pImpl->m_boom = boom; + return ( pImpl->m_tstmodule.load( tstMod ) ); +} // <method_initialize> + +// <method_test_Entries> +sal_Bool tstMgr::test_Entries( vector< sal_Char* > entries, + sal_Char* logName ) { + + sal_Bool bOK = sal_False; + if ( ! entries.empty() ) { + + bOK = sal_True; + vector< sal_Char* >::iterator iter = entries.begin(); + + tLog log( logName ); + // open testLog + log.open(); + while ( iter != entries.end() ) { + if ( *iter[0] != '#' ) { + ::rtl::TestResult oRes( *iter, pImpl->m_boom ); + test_Entry_Impl( pImpl->m_tstmodule, &oRes ); + bOK &= oRes.getState(); + log.writeRes( oRes ); + } + iter++; + } + log.close(); + } + return ( bOK ); +} // </method_test_Entries> + +// <method_test_Entry> +sal_Bool tstMgr::test_Entry( sal_Char* entry, sal_Char* logName ) { + + tLog log( logName ); + // open testLog + log.open(); + ::rtl::TestResult oRes( entry, pImpl->m_boom ); + test_Entry_Impl( pImpl->m_tstmodule, &oRes ); + log.writeRes( oRes, sal_True ); + log.close(); + return ( oRes.getState() ); +} // </method_test_Entry> + +// <method_test_EntriesFromFile> +sal_Bool tstMgr::test_EntriesFromFile( sal_Char* fName, sal_Char* logName ) { + + sal_Bool bOK = sal_False; + vector< sal_Char* > entries; + + if ( getEntriesFromFile( fName, entries ) ) { + sal_Bool bOK = test_Entries( entries, logName ); + + vector< sal_Char* >::iterator iter = entries.begin(); + while ( iter != entries.end() ) { + if ( *iter ) { + delete [] *iter; + } + iter++; + } + } + else { + bOK = test_Entry( fName ); + } + return ( bOK ); + +} // </method_test_EntriesFromFile> + +// <method_cleanup> +void tstMgr::cleanup() { + if ( pImpl ) { + delete pImpl; + } +} // </method_cleanup> + + +// <function_test_Entry_Impl> +void test_Entry_Impl( ::osl::Module& oMod, ::rtl::TestResult* oRes ) { + + tstFunc* pFunc; // entry pointer + ::rtl::OString entryName( "test_" ); // entryname prefix + + // prefix entryname + entryName += oRes->getName(); + + // get entry pointer + pFunc = (tstFunc*) oMod.getSymbol( + ::rtl::OUString::createFromAscii( entryName.getStr() ) ); + + if ( pFunc ) { + // call entry + pFunc( oRes ); + oRes->end(); + } + else { + oRes->end("symbol not found"); + } + // return + return; + +} // </function_test_Entry_Impl> + +} // </namespace_tstutl> diff --git a/soltools/testSHL/util/tutil.cxx b/soltools/testSHL/util/tutil.cxx new file mode 100644 index 000000000000..60c5f6deba02 --- /dev/null +++ b/soltools/testSHL/util/tutil.cxx @@ -0,0 +1,147 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_soltools.hxx" +#include "tutil.hxx" + +// <namespace_tstutl> +namespace tstutl { + +// getcwd hack is deprecated as soon as normalizePath works as intend +#ifdef WNT +#define _getcwd getcwd +#include <direct.h> // _getcwd +#else +#include <unistd.h> // getcwd +#endif + +// <function_cnvrtPth> +::rtl::OUString cnvrtPth( ::rtl::OString sysPth ) { + + using ::osl::FileBase; + using ::rtl::OUString; + using ::rtl::OString; + + ::rtl::OUString ret; + sysPth = sysPth.replace( '\\','/' ); + OUString pth( OUString::createFromAscii( sysPth.getStr() ) ); + + if ( sysPth.indexOf("..") != -1 ) { + + // <hack> for osl_normalizePath() can't handle relatives + char buffer[256]; + OString curPth(getcwd(buffer,256)); + // </hack> + OUString nrmCurPth; + FileBase::normalizePath( OUString::createFromAscii( curPth ) , + nrmCurPth ); + FileBase::getAbsolutePath( nrmCurPth, pth, ret ); + } + else { + FileBase::normalizePath( pth, ret ); + } + return ret; + +} // </function_cnvrtPth> + +// <function_getEntriesFromFile> +sal_uInt32 getEntriesFromFile( sal_Char* fName, + vector< sal_Char* >& entries ) { + + ::osl::File inFile( cnvrtPth( fName ) ); + if ( inFile.open( OpenFlag_Read ) == ::osl::FileBase::E_None) { + ::rtl::ByteSequence byteSeq; + inFile.readLine( byteSeq ); + while ( byteSeq.getLength() ) { + sal_uInt32 len = byteSeq.getLength(); + sal_uInt32 i; + sal_Char* pEnt = new sal_Char[ len+1 ]; + sal_Char* bsPtr = (sal_Char*)byteSeq.getArray(); + for ( i=0; i<len; i++ ) { + pEnt[i] = bsPtr[i]; + } + pEnt[len] = '\0'; + entries.push_back( pEnt ); + + inFile.readLine( byteSeq ); + } + } + return ( entries.size() ); + +} // </function_getEntriesFromFile> + +// <function_cpy> +sal_Char* cpy( sal_Char** dest, const sal_Char* src ) { + + *dest = new sal_Char[ ln(src)+1 ]; + // set pointer + sal_Char* pdest = *dest; + const sal_Char* psrc = src; + + // copy string by char + while( *pdest++ = *psrc++ ); + + return ( *dest ); + +} // </function_cpy> + +// <function_cat> +sal_Char* cat( const sal_Char* str1, const sal_Char* str2 ) { + + // allocate memory for destination string + sal_Char* dest = new sal_Char[ ln(str1)+ln(str2)+1 ]; + + // set pointers + sal_Char* pdest = dest; + const sal_Char* psrc = str1; + + // copy string1 by char to dest + while( *pdest++ = *psrc++ ); + pdest--; + psrc = str2; + while( *pdest++ = *psrc++ ); + + return ( dest ); + +} // </function_cat> + +// <function_ln> +sal_uInt32 ln( const sal_Char* str ) { + + sal_uInt32 len = 0; + const sal_Char* ptr = str; + + if( ptr ) { + while( *ptr++ ) len++; + } + + return(len); +} // <function_ln> + +} // </namespace_tstutl> + |