1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_soltools.hxx"
26
27 #include "tlog.hxx"
28
29 using namespace std;
30
31 // <namespace_tstutl>
32 namespace tstutl {
33
34 // <method_initialize>
initialize(const::rtl::OString & name)35 void tLog::initialize( const ::rtl::OString& name ) {
36 m_logname = cnvrtPth( name );
37 m_logfile = new ::osl::File( m_logname );
38 } // </method_initialize>
39
40 // <method_open>
open(sal_Bool append)41 ::osl::FileBase::RC tLog::open( sal_Bool append ) {
42
43 if ( m_logfile ) {
44 ::osl::FileBase::RC ret;
45
46 if ( ! append ) {
47 ret = ::osl::File::remove( m_logname );
48 }
49
50 if( m_logfile->open( OpenFlag_Write ) == ::osl::FileBase::E_NOENT ) {
51 ret = m_logfile->open( OpenFlag_Write | OpenFlag_Create );
52 }
53 else {
54 ret = m_logfile->setPos( Pos_End, 0 );
55 }
56 return ret;
57 }
58 return ( ::osl::FileBase::E_INVAL );
59 } // </method_open>
60
61 // <method_close>
close()62 ::osl::FileBase::RC tLog::close() {
63 if ( m_logfile ) {
64 return m_logfile->close();
65 }
66 return ( ::osl::FileBase::E_INVAL );
67 } // </method_close>
68
69 // <method_writeRes>
writeRes(::rtl::TestResult & oRes,sal_Bool v,sal_Bool xml)70 ::osl::FileBase::RC tLog::writeRes( ::rtl::TestResult& oRes, sal_Bool v, sal_Bool xml ) {
71 ::osl::FileBase::RC ret;
72
73 sal_Char* ptr = oRes.getName();
74 ptr = cat( ptr, ";" );
75 ptr = cat( ptr, oRes.getResult() );
76 ret = write( cat( ptr, "\n" ), v );
77 delete [] ptr;
78
79 return( ret );
80 } // </method_writeRes>
81
82 // <method_write>
write(const sal_Char * buf,sal_Bool v)83 ::osl::FileBase::RC tLog::write( const sal_Char* buf, sal_Bool v ) {
84
85 if ( ! m_logfile ) {
86 fprintf( stderr, "%s", buf );
87 return ( ::osl::FileBase::E_NOENT );
88 }
89 sal_uInt64 uBytes=0;
90 sal_uInt32 len = ln( buf );
91 const sal_Char* ptr = buf;
92
93 if ( v ) {
94 fprintf( stderr, "%s", buf );
95 }
96 return m_logfile->write( buf, len , uBytes );
97 } // </method_write>
98
99 } // </namespace_tstutl>
100
101
102
103
104
105