rtl_logfile.cxx (87d2adbc) | rtl_logfile.cxx (98e2c44a) |
---|---|
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 --- 25 unchanged lines hidden (view full) --- 34#include <stdlib.h> 35#include <string.h> 36 37#if defined(UNX) || defined(OS2) 38# include <unistd.h> 39#endif 40 41#include <rtl/logfile.hxx> | 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 --- 25 unchanged lines hidden (view full) --- 34#include <stdlib.h> 35#include <string.h> 36 37#if defined(UNX) || defined(OS2) 38# include <unistd.h> 39#endif 40 41#include <rtl/logfile.hxx> |
42#include <testshl/simpleheader.hxx> | 42#include "gtest/gtest.h" |
43 44// #ifndef _OSL_MODULE_HXX_ 45// #include <osl/module.hxx> 46// #endif 47#include <osl/file.hxx> 48#if ( defined WNT ) // Windows 49#include <tools/prewin.h> 50// #define UNICODE --- 5 unchanged lines hidden (view full) --- 56 57using namespace ::osl; 58 59inline void printUString( const ::rtl::OUString & str, const sal_Char * msg = "" ) 60{ 61 62 if (strlen(msg) > 0) 63 { | 43 44// #ifndef _OSL_MODULE_HXX_ 45// #include <osl/module.hxx> 46// #endif 47#include <osl/file.hxx> 48#if ( defined WNT ) // Windows 49#include <tools/prewin.h> 50// #define UNICODE --- 5 unchanged lines hidden (view full) --- 56 57using namespace ::osl; 58 59inline void printUString( const ::rtl::OUString & str, const sal_Char * msg = "" ) 60{ 61 62 if (strlen(msg) > 0) 63 { |
64 t_print("%s: ", msg ); | 64 printf("%s: ", msg ); |
65 } 66 rtl::OString aString; 67 aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); | 65 } 66 rtl::OString aString; 67 aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); |
68 t_print("%s\n", (char *)aString.getStr( ) ); | 68 printf("%s\n", (char *)aString.getStr( ) ); |
69} 70 71/** get the absolute source file URL "file:///.../sal/qa/rtl/logfile/" 72 */ 73 74inline ::rtl::OUString getTempPath( void ) 75{ 76#ifdef UNX --- 37 unchanged lines hidden (view full) --- 114/* 115 * LLA: 116 * check if logfile is create 117 * be careful with relative logfiles they will create near the source, maybe it's no write access to it. 118 * use absolute path to logfile instead. 119 */ 120namespace rtl_logfile 121{ | 69} 70 71/** get the absolute source file URL "file:///.../sal/qa/rtl/logfile/" 72 */ 73 74inline ::rtl::OUString getTempPath( void ) 75{ 76#ifdef UNX --- 37 unchanged lines hidden (view full) --- 114/* 115 * LLA: 116 * check if logfile is create 117 * be careful with relative logfiles they will create near the source, maybe it's no write access to it. 118 * use absolute path to logfile instead. 119 */ 120namespace rtl_logfile 121{ |
122 class logfile : public CppUnit::TestFixture | 122 class logfile : public ::testing::Test |
123 { | 123 { |
124 public: | 124 }; |
125 | 125 |
126 //directly call rtl_logfile_trace 127 void logfile_001() 128 { | 126 //directly call rtl_logfile_trace 127 TEST_F(logfile, logfile_001) 128 { |
129#ifdef SOLARIS | 129#ifdef SOLARIS |
130 putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile1")); | 130 putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile1")); 131#elif WNT 132 putenv("RTL_LOGFILE=c:\\temp\\logfile1"); 133#else 134 setenv("RTL_LOGFILE", "/tmp/logfile1", 0); |
131#endif | 135#endif |
132#ifdef WNT 133 putenv("RTL_LOGFILE=c:\\temp\\logfile1"); 134#endif 135#ifdef LINUX 136 setenv("RTL_LOGFILE", "/tmp/logfile1", 0); 137#endif 138 rtl_logfile_trace("trace %d\n", 2 ); 139 rtl_logfile_trace("trace %d %d\n" , 1,2 ); 140 rtl_logfile_trace("trace %d %d %d\n" , 1 , 2 ,3 ); | 136 rtl_logfile_trace("trace %d\n", 2 ); 137 rtl_logfile_trace("trace %d %d\n" , 1,2 ); 138 rtl_logfile_trace("trace %d %d %d\n" , 1 , 2 ,3 ); 139 for (int i = 0; i < 1024; i++) 140 rtl_logfile_trace("rubbish to flush the log\n"); |
141 | 141 |
142 rtl::OUString suFilePath = getTempPath(); 143 suFilePath += rtl::OUString::createFromAscii("logfile1_") + getCurrentPID( ); 144 suFilePath += rtl::OUString::createFromAscii(".log"); | 142 rtl::OUString suFilePath = getTempPath(); 143 suFilePath += rtl::OUString::createFromAscii("logfile1_") + getCurrentPID( ); 144 suFilePath += rtl::OUString::createFromAscii(".log"); |
145 | 145 |
146 ::osl::FileBase::RC nError1; 147 ::osl::File aTestFile( suFilePath ); 148 printUString( suFilePath ); 149 nError1 = aTestFile.open ( OpenFlag_Read ); 150 CPPUNIT_ASSERT_MESSAGE("create the log file: but the logfile does not exist", 151 ( ::osl::FileBase::E_NOENT != nError1 ) && 152 ( ::osl::FileBase::E_ACCES != nError1 ) ); 153 sal_Char buffer_read[400]; 154 sal_uInt64 nCount_read; 155 nError1 = aTestFile.read( buffer_read, 400, nCount_read ); 156 //t_print("buffer is %s\n", buffer_read ); 157 CPPUNIT_ASSERT_MESSAGE("write right logs", strstr( buffer_read, "trace 1 2 3") != NULL ); 158 aTestFile.sync(); 159 aTestFile.close(); 160 /*// delete logfile on the disk | 146 ::osl::FileBase::RC nError1; 147 ::osl::File aTestFile( suFilePath ); 148 printUString( suFilePath ); 149 nError1 = aTestFile.open ( OpenFlag_Read ); 150 ASSERT_TRUE(( ::osl::FileBase::E_NOENT != nError1 ) && 151 ( ::osl::FileBase::E_ACCES != nError1 ) ) << "create the log file: but the logfile does not exist"; 152 sal_Char buffer_read[400]; 153 sal_uInt64 nCount_read; 154 nError1 = aTestFile.read( buffer_read, 400, nCount_read ); 155 //print("buffer is %s\n", buffer_read ); 156 ASSERT_TRUE( strstr( buffer_read, "trace 1 2 3") != NULL ) << "write right logs"; 157 aTestFile.sync(); 158 aTestFile.close(); 159 /*// delete logfile on the disk |
161 | 160 |
162 nError1 = osl::File::remove( suFilePath ); 163 printError( nError1 ); 164 CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: remove ", ( ::osl::FileBase::E_None == nError1 ) || ( nError1 == ::osl::FileBase::E_NOENT ) ); 165 */ 166 } 167 //Profiling output should only be generated for a special product version of OpenOffice 168 // which is compiled with a defined preprocessor symbol 'TIMELOG'. Now, the symbol not defined 169 void logfile_002() 170 { | 161 nError1 = osl::File::remove( suFilePath ); 162 printError( nError1 ); 163 CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: remove ", ( ::osl::FileBase::E_None == nError1 ) || ( nError1 == ::osl::FileBase::E_NOENT ) ); 164 */ 165 } 166 167 //Profiling output should only be generated for a special product version of OpenOffice 168 // which is compiled with a defined preprocessor symbol 'TIMELOG'. Now, the symbol not defined 169 TEST_F(logfile, logfile_002) 170 { |
171#ifdef SOLARIS | 171#ifdef SOLARIS |
172 putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile2")); | 172 putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile2")); |
173#endif 174#ifdef WNT | 173#endif 174#ifdef WNT |
175 putenv("RTL_LOGFILE=c:\\temp\\logfile2"); | 175 putenv("RTL_LOGFILE=c:\\temp\\logfile2"); |
176#endif 177#ifdef LINUX | 176#endif 177#ifdef LINUX |
178 setenv("RTL_LOGFILE", "/tmp/logfile2", 0); | 178 setenv("RTL_LOGFILE", "/tmp/logfile2", 0); |
179#endif | 179#endif |
180 RTL_LOGFILE_TRACE( "trace the log" ); 181 RTL_LOGFILE_TRACE1( "trace %d" , 1 ); 182 RTL_LOGFILE_TRACE2( "trace %d %d" , 1,2 ); 183 RTL_LOGFILE_TRACE3( "trace %d %d %d" , 1 , 2 ,3 ); | 180 RTL_LOGFILE_TRACE( "trace the log" ); 181 RTL_LOGFILE_TRACE1( "trace %d" , 1 ); 182 RTL_LOGFILE_TRACE2( "trace %d %d" , 1,2 ); 183 RTL_LOGFILE_TRACE3( "trace %d %d %d" , 1 , 2 ,3 ); |
184// TODO: assertion test! | 184// TODO: assertion test! |
185 } | 185 } |
186 | 186 |
187 void logfile_003() 188 { | 187 TEST_F(logfile, logfile_003) 188 { |
189#ifdef SOLARIS | 189#ifdef SOLARIS |
190 putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile2")); | 190 putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile2")); |
191#endif 192#ifdef WNT | 191#endif 192#ifdef WNT |
193 putenv("RTL_LOGFILE=c:\\temp\\logfile2"); | 193 putenv("RTL_LOGFILE=c:\\temp\\logfile2"); |
194#endif 195#ifdef LINUX | 194#endif 195#ifdef LINUX |
196 setenv("RTL_LOGFILE", "/tmp/logfile2", 0); | 196 setenv("RTL_LOGFILE", "/tmp/logfile2", 0); |
197#endif | 197#endif |
198 RTL_LOGFILE_CONTEXT ( foo , "foo-function" ); 199 RTL_LOGFILE_CONTEXT_TRACE ( foo , "trace" ); 200 RTL_LOGFILE_CONTEXT_TRACE1 ( foo , "trace %d" , 1 ); 201 RTL_LOGFILE_CONTEXT_TRACE2 ( foo , "trace %d %d" , 1 , 2 ); 202 RTL_LOGFILE_CONTEXT_TRACE3 ( foo , "trace %d %d %d" , 1 , 2 , 3); | 198 RTL_LOGFILE_CONTEXT ( foo , "foo-function" ); 199 RTL_LOGFILE_CONTEXT_TRACE ( foo , "trace" ); 200 RTL_LOGFILE_CONTEXT_TRACE1 ( foo , "trace %d" , 1 ); 201 RTL_LOGFILE_CONTEXT_TRACE2 ( foo , "trace %d %d" , 1 , 2 ); 202 RTL_LOGFILE_CONTEXT_TRACE3 ( foo , "trace %d %d %d" , 1 , 2 , 3); |
203// TODO: assertion test! | 203// TODO: assertion test! |
204 } | 204 } |
205 | 205 |
206 207 CPPUNIT_TEST_SUITE( logfile ); 208 CPPUNIT_TEST( logfile_001 ); 209 CPPUNIT_TEST( logfile_002 ); 210 CPPUNIT_TEST( logfile_003 ); 211 CPPUNIT_TEST_SUITE_END( ); 212 }; 213 | |
214} // namespace rtl_logfile 215 | 206} // namespace rtl_logfile 207 |
216// ----------------------------------------------------------------------------- 217CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_logfile::logfile, "rtl_logfile" ); | |
218 219// ----------------------------------------------------------------------------- | 208 209// ----------------------------------------------------------------------------- |
220NOADDITIONAL; | |
221 222//~ do some clean up work after all test completed. 223class GlobalObject 224{ 225public: 226 ~GlobalObject() 227 { 228 try 229 { | 210 211//~ do some clean up work after all test completed. 212class GlobalObject 213{ 214public: 215 ~GlobalObject() 216 { 217 try 218 { |
230 t_print( "\n#Do some clean-ups ... only delete logfile1_*.log here!\n" ); | 219 printf( "\n#Do some clean-ups ... only delete logfile1_*.log here!\n" ); |
231 rtl::OUString suFilePath = getTempPath(); 232 suFilePath += rtl::OUString::createFromAscii("logfile1_") + getCurrentPID( ); 233 suFilePath += rtl::OUString::createFromAscii(".log"); 234 235 //if ( ifFileExist( suFilePath ) == sal_True ) 236 ::osl::FileBase::RC nError1; 237 nError1 = osl::File::remove( suFilePath ); 238#ifdef WNT | 220 rtl::OUString suFilePath = getTempPath(); 221 suFilePath += rtl::OUString::createFromAscii("logfile1_") + getCurrentPID( ); 222 suFilePath += rtl::OUString::createFromAscii(".log"); 223 224 //if ( ifFileExist( suFilePath ) == sal_True ) 225 ::osl::FileBase::RC nError1; 226 nError1 = osl::File::remove( suFilePath ); 227#ifdef WNT |
239 t_print("Please remove logfile* manully! Error is Permision denied!"); | 228 printf("Please remove logfile* manully! Error is Permision denied!"); |
240#endif 241 } | 229#endif 230 } |
242 catch (CppUnit::Exception &e) 243 { 244 t_print("Exception caught in GlobalObject dtor(). Exception message: '%s'. Source line: %d\n", e.what(), e.sourceLine().lineNumber()); 245 } | |
246 catch (...) 247 { | 231 catch (...) 232 { |
248 t_print("Exception caught (...) in GlobalObject dtor()\n"); | 233 printf("Exception caught (...) in GlobalObject dtor()\n"); |
249 } 250 } 251}; 252 253GlobalObject theGlobalObject; 254 | 234 } 235 } 236}; 237 238GlobalObject theGlobalObject; 239 |
255 256 | 240int main(int argc, char **argv) 241{ 242 ::testing::InitGoogleTest(&argc, argv); 243 return RUN_ALL_TESTS(); 244} |