xref: /trunk/main/soltools/testSHL/util/tlog.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_soltools.hxx"
30 
31 #include    "tlog.hxx"
32 
33 using namespace std;
34 
35 // <namespace_tstutl>
36 namespace tstutl {
37 
38 // <method_initialize>
39 void tLog::initialize( const ::rtl::OString& name ) {
40     m_logname = cnvrtPth( name );
41     m_logfile = new ::osl::File( m_logname );
42 } // </method_initialize>
43 
44 // <method_open>
45 ::osl::FileBase::RC tLog::open( sal_Bool append ) {
46 
47     if ( m_logfile ) {
48         ::osl::FileBase::RC ret;
49 
50         if ( ! append ) {
51             ret = ::osl::File::remove( m_logname );
52         }
53 
54     if( m_logfile->open( OpenFlag_Write ) == ::osl::FileBase::E_NOENT ) {
55             ret = m_logfile->open( OpenFlag_Write | OpenFlag_Create );
56         }
57         else  {
58             ret = m_logfile->setPos( Pos_End, 0 );
59         }
60         return ret;
61     }
62     return ( ::osl::FileBase::E_INVAL );
63 } // </method_open>
64 
65 // <method_close>
66 ::osl::FileBase::RC tLog::close() {
67     if ( m_logfile ) {
68         return m_logfile->close();
69     }
70     return ( ::osl::FileBase::E_INVAL );
71 } // </method_close>
72 
73 // <method_writeRes>
74 ::osl::FileBase::RC tLog::writeRes( ::rtl::TestResult& oRes, sal_Bool v, sal_Bool xml ) {
75     ::osl::FileBase::RC ret;
76 
77     sal_Char* ptr = oRes.getName();
78     ptr = cat( ptr, ";" );
79     ptr = cat( ptr, oRes.getResult() );
80     ret = write( cat( ptr, "\n" ), v );
81     delete [] ptr;
82 
83     return( ret );
84 } // </method_writeRes>
85 
86 // <method_write>
87 ::osl::FileBase::RC tLog::write( const sal_Char* buf, sal_Bool v ) {
88 
89     if ( ! m_logfile ) {
90         fprintf( stderr, "%s", buf );
91         return ( ::osl::FileBase::E_NOENT );
92     }
93 	sal_uInt64 uBytes=0;
94     sal_uInt32 len = ln( buf );
95     const sal_Char* ptr = buf;
96 
97 	if ( v ) {
98         fprintf( stderr, "%s", buf );
99 	}
100     return m_logfile->write( buf, len , uBytes );
101 } // </method_write>
102 
103 } // </namespace_tstutl>
104 
105 
106 
107 
108 
109