Author: damjan
Date: Tue Sep  1 18:38:35 2015
New Revision: 1700637

URL: http://svn.apache.org/r1700637
Log:
#i125003# migrate main/sal/qa/rtl/logfile from cppunit to Google Test. Also fix 
a test
that was failing on non-Solaris non-Windows non-Linux OSes.


Modified:
    openoffice/trunk/main/sal/qa/rtl/logfile/makefile.mk
    openoffice/trunk/main/sal/qa/rtl/logfile/rtl_logfile.cxx

Modified: openoffice/trunk/main/sal/qa/rtl/logfile/makefile.mk
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sal/qa/rtl/logfile/makefile.mk?rev=1700637&r1=1700636&r2=1700637&view=diff
==============================================================================
--- openoffice/trunk/main/sal/qa/rtl/logfile/makefile.mk (original)
+++ openoffice/trunk/main/sal/qa/rtl/logfile/makefile.mk Tue Sep  1 18:38:35 
2015
@@ -32,28 +32,27 @@ ENABLE_EXCEPTIONS=TRUE
 
 .INCLUDE :  settings.mk
 
+.IF "$(ENABLE_UNIT_TESTS)" != "YES"
+all:
+       @echo unit tests are disabled. Nothing to do.
+
+.ELSE
+
 CFLAGS+= $(LFS_CFLAGS)
 CXXFLAGS+= $(LFS_CFLAGS)
 
-CFLAGSCXX += $(CPPUNIT_CFLAGS)
-
 # --- BEGIN --------------------------------------------------------
-SHL1OBJS=  \
+APP1OBJS=  \
        $(SLO)$/rtl_logfile.obj
-SHL1TARGET= rtl_logfile
-SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB)
-
-SHL1IMPLIB= i$(SHL1TARGET)
-DEF1NAME    =$(SHL1TARGET)
-SHL1VERSIONMAP = $(PRJ)$/qa$/export.map
+APP1TARGET= rtl_logfile
+APP1STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB)
+APP1RPATH = NONE
+APP1TEST = enabled
 
 # END --------------------------------------------------------------
 
-#------------------------------- All object files 
-------------------------------
-# do this here, so we get right dependencies
-# SLOFILES=$(SHL1OBJS)
-
 # --- Targets ------------------------------------------------------
 
 .INCLUDE :  target.mk
-.INCLUDE : _cppunit.mk
+
+.ENDIF # "$(ENABLE_UNIT_TESTS)" != "YES"

Modified: openoffice/trunk/main/sal/qa/rtl/logfile/rtl_logfile.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/sal/qa/rtl/logfile/rtl_logfile.cxx?rev=1700637&r1=1700636&r2=1700637&view=diff
==============================================================================
--- openoffice/trunk/main/sal/qa/rtl/logfile/rtl_logfile.cxx (original)
+++ openoffice/trunk/main/sal/qa/rtl/logfile/rtl_logfile.cxx Tue Sep  1 
18:38:35 2015
@@ -39,7 +39,7 @@
 #endif
 
 #include <rtl/logfile.hxx>
-#include <testshl/simpleheader.hxx>
+#include "gtest/gtest.h"
 
 // #ifndef      _OSL_MODULE_HXX_
 // #include <osl/module.hxx>
@@ -61,11 +61,11 @@ inline void printUString( const ::rtl::O
 
     if (strlen(msg) > 0)
     {
-        t_print("%s: ", msg );
+        printf("%s: ", msg );
     }
     rtl::OString aString;
     aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
-    t_print("%s\n", (char *)aString.getStr( ) );
+    printf("%s\n", (char *)aString.getStr( ) );
 }
 
 /** get the absolute source file URL "file:///.../sal/qa/rtl/logfile/"
@@ -119,105 +119,94 @@ inline ::rtl::OUString getCurrentPID(  )
  */
 namespace rtl_logfile
 {
-    class logfile : public CppUnit::TestFixture
+    class logfile : public ::testing::Test
     {
-    public:
+    };
 
-        //directly call rtl_logfile_trace
-        void logfile_001()
-        {
+    //directly call rtl_logfile_trace
+    TEST_F(logfile, logfile_001)
+    {
 #ifdef SOLARIS
-                putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile1"));
-#endif
-#ifdef WNT
-                putenv("RTL_LOGFILE=c:\\temp\\logfile1");
-#endif
-#ifdef LINUX
-                setenv("RTL_LOGFILE", "/tmp/logfile1", 0);
+        putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile1"));
+#elif WNT
+        putenv("RTL_LOGFILE=c:\\temp\\logfile1");
+#else
+        setenv("RTL_LOGFILE", "/tmp/logfile1", 0);
 #endif
-                rtl_logfile_trace("trace %d\n", 2 );
-                rtl_logfile_trace("trace %d %d\n" , 1,2 );
-                rtl_logfile_trace("trace %d %d %d\n" , 1 , 2 ,3 );
-
-                rtl::OUString suFilePath = getTempPath();
-                suFilePath +=  rtl::OUString::createFromAscii("logfile1_") + 
getCurrentPID( );
-                suFilePath +=  rtl::OUString::createFromAscii(".log");
-
-                ::osl::FileBase::RC   nError1;
-                ::osl::File aTestFile( suFilePath );
-                printUString( suFilePath );
-                nError1 = aTestFile.open ( OpenFlag_Read );
-                CPPUNIT_ASSERT_MESSAGE("create the log file: but the logfile 
does not exist",
-                                       ( ::osl::FileBase::E_NOENT != nError1 ) 
&&
-                                       ( ::osl::FileBase::E_ACCES != nError1 ) 
);
-                sal_Char       buffer_read[400];
-                sal_uInt64      nCount_read;
-                nError1 = aTestFile.read( buffer_read, 400, nCount_read );
-                //t_print("buffer is %s\n", buffer_read );
-                CPPUNIT_ASSERT_MESSAGE("write right logs", strstr( 
buffer_read, "trace 1 2 3") != NULL );
-                aTestFile.sync();
-                aTestFile.close();
-                /*// delete logfile on the disk
+        rtl_logfile_trace("trace %d\n", 2 );
+        rtl_logfile_trace("trace %d %d\n" , 1,2 );
+        rtl_logfile_trace("trace %d %d %d\n" , 1 , 2 ,3 );
+        for (int i = 0; i < 1024; i++)
+            rtl_logfile_trace("rubbish to flush the log\n");
+
+        rtl::OUString suFilePath = getTempPath();
+        suFilePath +=  rtl::OUString::createFromAscii("logfile1_") + 
getCurrentPID( );
+        suFilePath +=  rtl::OUString::createFromAscii(".log");
+
+        ::osl::FileBase::RC   nError1;
+        ::osl::File aTestFile( suFilePath );
+        printUString( suFilePath );
+        nError1 = aTestFile.open ( OpenFlag_Read );
+        ASSERT_TRUE(( ::osl::FileBase::E_NOENT != nError1 ) &&
+                    ( ::osl::FileBase::E_ACCES != nError1 ) ) << "create the 
log file: but the logfile does not exist";
+        sal_Char       buffer_read[400];
+        sal_uInt64      nCount_read;
+        nError1 = aTestFile.read( buffer_read, 400, nCount_read );
+        //print("buffer is %s\n", buffer_read );
+        ASSERT_TRUE( strstr( buffer_read, "trace 1 2 3") != NULL ) << "write 
right logs";
+        aTestFile.sync();
+        aTestFile.close();
+        /*// delete logfile on the disk
+
+        nError1 = osl::File::remove( suFilePath );
+        printError( nError1 );
+        CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: remove ", ( 
::osl::FileBase::E_None == nError1 ) || ( nError1 == ::osl::FileBase::E_NOENT ) 
);
+        */
+    }
 
-                nError1 = osl::File::remove( suFilePath );
-                printError( nError1 );
-                CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: remove ", 
( ::osl::FileBase::E_None == nError1 ) || ( nError1 == ::osl::FileBase::E_NOENT 
) );
-                */
-        }
-        //Profiling output should only be generated for a special product 
version of OpenOffice
-        // which is compiled with a defined preprocessor symbol 'TIMELOG'. 
Now, the symbol not defined
-        void logfile_002()
-            {
+    //Profiling output should only be generated for a special product version 
of OpenOffice
+    // which is compiled with a defined preprocessor symbol 'TIMELOG'. Now, 
the symbol not defined
+    TEST_F(logfile, logfile_002)
+    {
 #ifdef SOLARIS
-                putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile2"));
+        putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile2"));
 #endif
 #ifdef WNT
-                putenv("RTL_LOGFILE=c:\\temp\\logfile2");
+        putenv("RTL_LOGFILE=c:\\temp\\logfile2");
 #endif
 #ifdef LINUX
-                setenv("RTL_LOGFILE", "/tmp/logfile2", 0);
+        setenv("RTL_LOGFILE", "/tmp/logfile2", 0);
 #endif
-                RTL_LOGFILE_TRACE( "trace the log" );
-                RTL_LOGFILE_TRACE1( "trace %d" , 1 );
-                RTL_LOGFILE_TRACE2( "trace %d %d" , 1,2 );
-                RTL_LOGFILE_TRACE3( "trace %d %d %d" , 1 , 2 ,3 );
+        RTL_LOGFILE_TRACE( "trace the log" );
+        RTL_LOGFILE_TRACE1( "trace %d" , 1 );
+        RTL_LOGFILE_TRACE2( "trace %d %d" , 1,2 );
+        RTL_LOGFILE_TRACE3( "trace %d %d %d" , 1 , 2 ,3 );
 // TODO: assertion test!
-        }
+    }
 
-        void logfile_003()
-            {
+    TEST_F(logfile, logfile_003)
+    {
 #ifdef SOLARIS
-                putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile2"));
+        putenv(const_cast< char * >("RTL_LOGFILE=/tmp/logfile2"));
 #endif
 #ifdef WNT
-                putenv("RTL_LOGFILE=c:\\temp\\logfile2");
+        putenv("RTL_LOGFILE=c:\\temp\\logfile2");
 #endif
 #ifdef LINUX
-                setenv("RTL_LOGFILE", "/tmp/logfile2", 0);
+        setenv("RTL_LOGFILE", "/tmp/logfile2", 0);
 #endif
-                RTL_LOGFILE_CONTEXT ( foo , "foo-function" );
-                RTL_LOGFILE_CONTEXT_TRACE ( foo , "trace" );
-                RTL_LOGFILE_CONTEXT_TRACE1 ( foo , "trace %d" , 1 );
-                RTL_LOGFILE_CONTEXT_TRACE2 ( foo , "trace %d %d" , 1 , 2 );
-                RTL_LOGFILE_CONTEXT_TRACE3 ( foo , "trace %d %d %d" , 1 , 2 , 
3);
+        RTL_LOGFILE_CONTEXT ( foo , "foo-function" );
+        RTL_LOGFILE_CONTEXT_TRACE ( foo , "trace" );
+        RTL_LOGFILE_CONTEXT_TRACE1 ( foo , "trace %d" , 1 );
+        RTL_LOGFILE_CONTEXT_TRACE2 ( foo , "trace %d %d" , 1 , 2 );
+        RTL_LOGFILE_CONTEXT_TRACE3 ( foo , "trace %d %d %d" , 1 , 2 , 3);
 // TODO: assertion test!
-            }
-
-
-        CPPUNIT_TEST_SUITE( logfile );
-        CPPUNIT_TEST( logfile_001 );
-        CPPUNIT_TEST( logfile_002 );
-        CPPUNIT_TEST( logfile_003 );
-        CPPUNIT_TEST_SUITE_END( );
-    };
+    }
 
 } // namespace rtl_logfile
 
-// 
-----------------------------------------------------------------------------
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( rtl_logfile::logfile, "rtl_logfile" );
 
 // 
-----------------------------------------------------------------------------
-NOADDITIONAL;
 
 //~ do some clean up work after all test completed.
 class GlobalObject
@@ -227,7 +216,7 @@ public:
         {
             try
             {
-                t_print( "\n#Do some clean-ups ... only delete logfile1_*.log 
here!\n" );
+                printf( "\n#Do some clean-ups ... only delete logfile1_*.log 
here!\n" );
                 rtl::OUString suFilePath = getTempPath();
                 suFilePath +=  rtl::OUString::createFromAscii("logfile1_") + 
getCurrentPID( );
                 suFilePath +=  rtl::OUString::createFromAscii(".log");
@@ -236,21 +225,20 @@ public:
                 ::osl::FileBase::RC nError1;
                 nError1 = osl::File::remove( suFilePath );
 #ifdef WNT
-                t_print("Please remove logfile* manully! Error is Permision 
denied!");
+                printf("Please remove logfile* manully! Error is Permision 
denied!");
 #endif
             }
-            catch (CppUnit::Exception &e)
-            {
-                t_print("Exception caught in GlobalObject dtor(). Exception 
message: '%s'. Source line: %d\n", e.what(), e.sourceLine().lineNumber());
-            }
             catch (...)
             {
-                t_print("Exception caught (...) in GlobalObject dtor()\n");
+                printf("Exception caught (...) in GlobalObject dtor()\n");
             }
         }
 };
 
 GlobalObject theGlobalObject;
 
-
-
+int main(int argc, char **argv)
+{
+    ::testing::InitGoogleTest(&argc, argv);
+    return RUN_ALL_TESTS();
+}


Reply via email to