xref: /AOO41X/main/soltools/testSHL/util/tlog.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 
31*cdf0e10cSrcweir #include    "tlog.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir using namespace std;
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir // <namespace_tstutl>
36*cdf0e10cSrcweir namespace tstutl {
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir // <method_initialize>
39*cdf0e10cSrcweir void tLog::initialize( const ::rtl::OString& name ) {
40*cdf0e10cSrcweir     m_logname = cnvrtPth( name );
41*cdf0e10cSrcweir     m_logfile = new ::osl::File( m_logname );
42*cdf0e10cSrcweir } // </method_initialize>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir // <method_open>
45*cdf0e10cSrcweir ::osl::FileBase::RC tLog::open( sal_Bool append ) {
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir     if ( m_logfile ) {
48*cdf0e10cSrcweir         ::osl::FileBase::RC ret;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir         if ( ! append ) {
51*cdf0e10cSrcweir             ret = ::osl::File::remove( m_logname );
52*cdf0e10cSrcweir         }
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir     if( m_logfile->open( OpenFlag_Write ) == ::osl::FileBase::E_NOENT ) {
55*cdf0e10cSrcweir             ret = m_logfile->open( OpenFlag_Write | OpenFlag_Create );
56*cdf0e10cSrcweir         }
57*cdf0e10cSrcweir         else  {
58*cdf0e10cSrcweir             ret = m_logfile->setPos( Pos_End, 0 );
59*cdf0e10cSrcweir         }
60*cdf0e10cSrcweir         return ret;
61*cdf0e10cSrcweir     }
62*cdf0e10cSrcweir     return ( ::osl::FileBase::E_INVAL );
63*cdf0e10cSrcweir } // </method_open>
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir // <method_close>
66*cdf0e10cSrcweir ::osl::FileBase::RC tLog::close() {
67*cdf0e10cSrcweir     if ( m_logfile ) {
68*cdf0e10cSrcweir         return m_logfile->close();
69*cdf0e10cSrcweir     }
70*cdf0e10cSrcweir     return ( ::osl::FileBase::E_INVAL );
71*cdf0e10cSrcweir } // </method_close>
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir // <method_writeRes>
74*cdf0e10cSrcweir ::osl::FileBase::RC tLog::writeRes( ::rtl::TestResult& oRes, sal_Bool v, sal_Bool xml ) {
75*cdf0e10cSrcweir     ::osl::FileBase::RC ret;
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir     sal_Char* ptr = oRes.getName();
78*cdf0e10cSrcweir     ptr = cat( ptr, ";" );
79*cdf0e10cSrcweir     ptr = cat( ptr, oRes.getResult() );
80*cdf0e10cSrcweir     ret = write( cat( ptr, "\n" ), v );
81*cdf0e10cSrcweir     delete [] ptr;
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir     return( ret );
84*cdf0e10cSrcweir } // </method_writeRes>
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir // <method_write>
87*cdf0e10cSrcweir ::osl::FileBase::RC tLog::write( const sal_Char* buf, sal_Bool v ) {
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir     if ( ! m_logfile ) {
90*cdf0e10cSrcweir         fprintf( stderr, "%s", buf );
91*cdf0e10cSrcweir         return ( ::osl::FileBase::E_NOENT );
92*cdf0e10cSrcweir     }
93*cdf0e10cSrcweir 	sal_uInt64 uBytes=0;
94*cdf0e10cSrcweir     sal_uInt32 len = ln( buf );
95*cdf0e10cSrcweir     const sal_Char* ptr = buf;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 	if ( v ) {
98*cdf0e10cSrcweir         fprintf( stderr, "%s", buf );
99*cdf0e10cSrcweir 	}
100*cdf0e10cSrcweir     return m_logfile->write( buf, len , uBytes );
101*cdf0e10cSrcweir } // </method_write>
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir } // </namespace_tstutl>
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 
109