update dev300-m58
[ooovba.git] / soltools / testSHL / util / tlog.cxx
blobf2c1f4443fc628067979a61ad54949be2702115a
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: tlog.cxx,v $
10 * $Revision: 1.5 $
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"
34 #include "tlog.hxx"
36 using namespace std;
38 // <namespace_tstutl>
39 namespace tstutl {
41 // <method_initialize>
42 void tLog::initialize( const ::rtl::OString& name ) {
43 m_logname = cnvrtPth( name );
44 m_logfile = new ::osl::File( m_logname );
45 } // </method_initialize>
47 // <method_open>
48 ::osl::FileBase::RC tLog::open( sal_Bool append ) {
50 if ( m_logfile ) {
51 ::osl::FileBase::RC ret;
53 if ( ! append ) {
54 ret = ::osl::File::remove( m_logname );
57 if( m_logfile->open( OpenFlag_Write ) == ::osl::FileBase::E_NOENT ) {
58 ret = m_logfile->open( OpenFlag_Write | OpenFlag_Create );
60 else {
61 ret = m_logfile->setPos( Pos_End, 0 );
63 return ret;
65 return ( ::osl::FileBase::E_INVAL );
66 } // </method_open>
68 // <method_close>
69 ::osl::FileBase::RC tLog::close() {
70 if ( m_logfile ) {
71 return m_logfile->close();
73 return ( ::osl::FileBase::E_INVAL );
74 } // </method_close>
76 // <method_writeRes>
77 ::osl::FileBase::RC tLog::writeRes( ::rtl::TestResult& oRes, sal_Bool v, sal_Bool xml ) {
78 ::osl::FileBase::RC ret;
80 sal_Char* ptr = oRes.getName();
81 ptr = cat( ptr, ";" );
82 ptr = cat( ptr, oRes.getResult() );
83 ret = write( cat( ptr, "\n" ), v );
84 delete [] ptr;
86 return( ret );
87 } // </method_writeRes>
89 // <method_write>
90 ::osl::FileBase::RC tLog::write( const sal_Char* buf, sal_Bool v ) {
92 if ( ! m_logfile ) {
93 fprintf( stderr, "%s", buf );
94 return ( ::osl::FileBase::E_NOENT );
96 sal_uInt64 uBytes=0;
97 sal_uInt32 len = ln( buf );
98 const sal_Char* ptr = buf;
100 if ( v ) {
101 fprintf( stderr, "%s", buf );
103 return m_logfile->write( buf, len , uBytes );
104 } // </method_write>
106 } // </namespace_tstutl>