sal/qa/osl/module/makefile.mk | 30 sal/qa/osl/module/osl_Module.cxx | 440 ++---- sal/qa/osl/module/osl_Module_Const.h | 1 sal/qa/osl/module/osl_Module_DLL.cxx | 1 sal/qa/osl/process/makefile.mk | 53 sal/qa/osl/process/osl_Thread.cxx | 2317 +++++++++++++++-------------------- sal/qa/osl/process/osl_process.cxx | 611 +++------ 7 files changed, 1533 insertions(+), 1920 deletions(-)
New commits: commit 06474710a5810a69c3a76be15dcda1b5d8789711 Author: Damjan Jovanovic <dam...@apache.org> Date: Fri Sep 4 18:33:14 2015 +0000 #i125003# migrate main/sal/qa/osl/module from cppunit to Google Test. diff --git a/sal/qa/osl/module/makefile.mk b/sal/qa/osl/module/makefile.mk index 609db6d..78a510e 100644 --- a/sal/qa/osl/module/makefile.mk +++ b/sal/qa/osl/module/makefile.mk @@ -32,6 +32,12 @@ 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) @@ -48,28 +54,28 @@ SHL1VERSIONMAP = export_dll.map # --- main l ------------------------------------------------------ -SHL2OBJS= $(SLO)$/osl_Module.obj - -SHL2TARGET= osl_Module -SHL2STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) +APP2OBJS= $(SLO)$/osl_Module.obj +APP2TARGET= osl_Module +APP2STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB) .IF "$(GUI)" == "WNT" -SHL2STDLIBS+=i$(SHL2TARGET).lib +APP2STDLIBS+=i$(SHL1TARGET).lib .ENDIF .IF "$(GUI)" == "UNX" -APP3STDLIBS+=-l$(SHL2TARGET) +APP2STDLIBS+=-l$(SHL1TARGET) .ENDIF -SHL2DEPN= $(SHL1OBJS) -SHL2IMPLIB= i$(SHL2TARGET) -SHL2DEF= $(MISC)$/$(SHL2TARGET).def +APP2DEPN= $(SHL1OBJS) +APP2TEST = enabled +#SHL2IMPLIB= i$(SHL2TARGET) +#SHL2DEF= $(MISC)$/$(SHL2TARGET).def -DEF2NAME =$(SHL2TARGET) -SHL2VERSIONMAP= $(PRJ)$/qa$/export.map +#DEF2NAME =$(SHL2TARGET) +#SHL2VERSIONMAP= $(PRJ)$/qa$/export.map # END ------------------------------------------------------------------ # --- Targets ------------------------------------------------------ .INCLUDE : target.mk -.INCLUDE : _cppunit.mk +.ENDIF # "$(ENABLE_UNIT_TESTS)" != "YES" \ No newline at end of file diff --git a/sal/qa/osl/module/osl_Module.cxx b/sal/qa/osl/module/osl_Module.cxx index eba1ab2..97a0f3a 100644 --- a/sal/qa/osl/module/osl_Module.cxx +++ b/sal/qa/osl/module/osl_Module.cxx @@ -28,6 +28,7 @@ // include files //------------------------------------------------------------------------ #include <osl_Module_Const.h> +#include "gtest/gtest.h" using namespace osl; using namespace rtl; @@ -41,8 +42,8 @@ using namespace rtl; */ inline void printBool( sal_Bool bOk ) { - t_print("#printBool# " ); - ( sal_True == bOk ) ? t_print("TRUE!\n" ): t_print("FALSE!\n" ); + printf("#printBool# " ); + ( sal_True == bOk ) ? printf("TRUE!\n" ): printf("FALSE!\n" ); } /** print a UNI_CODE String. @@ -51,9 +52,9 @@ inline void printUString( const ::rtl::OUString & str ) { rtl::OString aString; - t_print("#printUString_u# " ); + printf("#printUString_u# " ); aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); - t_print("%s\n", aString.getStr( ) ); + printf("%s\n", aString.getStr( ) ); } /** get dll file URL. @@ -68,9 +69,17 @@ inline ::rtl::OUString getDllURL( void ) ::rtl::OUString dirPath, dllPath; osl::Module::getUrlFromAddress( ( void* ) &getDllURL, dirPath ); + // file:///aoo/main/sal/unx/bin/osl_Module + dirPath = dirPath.copy( 0, dirPath.lastIndexOf('/')); + // file:///aoo/main/sal/unx/bin dirPath = dirPath.copy( 0, dirPath.lastIndexOf('/') + 1); + // file:///aoo/main/sal/unx/ + dirPath = dirPath + rtl::OUString::createFromAscii( "lib/" ); + // file:///aoo/main/sal/unx/lib/ osl::FileBase::getAbsoluteFileURL( dirPath, libPath, dllPath ); +rtl::OString aOString = ::rtl::OUStringToOString (dllPath, RTL_TEXTENCODING_UTF8); +printf("getDllURL() returning %s\n", aOString.getStr()); return dllPath; } @@ -80,9 +89,9 @@ inline void printFileName( const ::rtl::OUString & str ) { rtl::OString aString; - t_print("#printFileName_u# " ); + printf("#printFileName_u# " ); aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); - t_print("%s\n", aString.getStr( ) ); + printf("%s\n", aString.getStr( ) ); } inline sal_Bool isURL( const ::rtl::OUString pathname ) @@ -101,7 +110,7 @@ inline void createTestDirectory( const ::rtl::OUString dirname ) if ( !isURL( dirname ) ) ::osl::FileBase::getFileURLFromSystemPath( dirname, aPathURL ); //convert if not full qualified URL nError = ::osl::Directory::create( aPathURL ); - CPPUNIT_ASSERT_MESSAGE( "In createTestDirectory Function: creation: ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_EXIST ) ); + ASSERT_TRUE(( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_EXIST )) << "In createTestDirectory Function: creation: "; } /** delete a temp test directory using OUString name of full qualified URL or system path. @@ -120,7 +129,7 @@ inline void deleteTestDirectory( const ::rtl::OUString dirname ) } nError = ::osl::Directory::remove( aPathURL ); - CPPUNIT_ASSERT_MESSAGE( "In deleteTestDirectory function: remove ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT ) ); + ASSERT_TRUE(( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT )) << "In deleteTestDirectory function: remove "; } //check if the file exist @@ -153,10 +162,10 @@ inline void deleteTestFile( const ::rtl::OUString filename ) ::osl::FileBase::getFileURLFromSystemPath( filename, aPathURL ); //convert if not full qualified URL nError = ::osl::File::setAttributes( aPathURL, Attribute_GrpWrite| Attribute_OwnWrite| Attribute_OthWrite ); // if readonly, make writtenable. - CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: set writtenable ", ( ::osl::FileBase::E_None == nError ) || ( ::osl::FileBase::E_NOENT == nError ) ); + ASSERT_TRUE(( ::osl::FileBase::E_None == nError ) || ( ::osl::FileBase::E_NOENT == nError )) << "In deleteTestFile Function: set writtenable "; nError = ::osl::File::remove( aPathURL ); - CPPUNIT_ASSERT_MESSAGE( "In deleteTestFile Function: remove ", ( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT ) ); + ASSERT_TRUE(( ::osl::FileBase::E_None == nError ) || ( nError == ::osl::FileBase::E_NOENT )) << "In deleteTestFile Function: remove "; } @@ -175,7 +184,7 @@ namespace osl_Module public: static void myFunc() { - t_print("#Sun Microsystem\n"); + printf("#Sun Microsystem\n"); }; }; @@ -184,335 +193,260 @@ namespace osl_Module Module(); Module( const ::rtl::OUString& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT); */ - class ctors : public CppUnit::TestFixture + class ctors : public ::testing::Test { public: sal_Bool bRes, bRes1; + }; // class ctors - void ctors_none( ) - { - ::osl::Module aMod; - bRes = aMod.is(); - - CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor without parameter.", - sal_False == bRes ); - } - - void ctors_name_mode( ) - { - OUString aFileURL; - bRes = osl::Module::getUrlFromAddress( ( void* ) &::osl_Module::testClass::myFunc, aFileURL ); - - if ( !( bRes ) ) - { - CPPUNIT_ASSERT_MESSAGE("Cannot locate current module.", sal_False ); - } - ::osl::Module aMod( aFileURL ); - bRes = aMod.is( ); - aMod.unload( ); + TEST_F(ctors, ctors_none) + { + ::osl::Module aMod; + bRes = aMod.is(); - CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with load action.", - sal_True == bRes ); - } + ASSERT_TRUE( sal_False == bRes ) << "#test comment#: test constructor without parameter."; + } - CPPUNIT_TEST_SUITE( ctors ); - CPPUNIT_TEST( ctors_none ); - CPPUNIT_TEST( ctors_name_mode ); - CPPUNIT_TEST_SUITE_END( ); - }; // class ctors + TEST_F(ctors, ctors_name_mode) + { + ::osl::Module aMod( getDllURL( ) ); + bRes = aMod.is( ); + aMod.unload( ); + ASSERT_TRUE( sal_True == bRes ) << "#test comment#: test constructor with load action."; + } /** testing the methods: static sal_Bool getUrlFromAddress(void * addr, ::rtl::OUString & libraryUrl) */ - class getUrlFromAddress : public CppUnit::TestFixture + class getUrlFromAddress : public ::testing::Test { public: sal_Bool bRes, bRes1; + }; // class getUrlFromAddress - void getUrlFromAddress_001( ) - { - OUString aFileURL; - bRes = osl::Module::getUrlFromAddress( ( void* ) &::osl_Module::testClass::myFunc, aFileURL ) ; - if ( !( bRes ) ) - { - CPPUNIT_ASSERT_MESSAGE("Cannot locate current module.", sal_False ); - } - - CPPUNIT_ASSERT_MESSAGE( "#test comment#: test get Module URL from address.", - sal_True == bRes && 0 < aFileURL.lastIndexOf('/') ); - } + /* tester comments: another case is getFunctionSymbol_001*/ - void getUrlFromAddress_002( ) + TEST_F(getUrlFromAddress, getUrlFromAddress_001 ) + { + OUString aFileURL; + bRes = osl::Module::getUrlFromAddress( ( void* ) &::osl_Module::testClass::myFunc, aFileURL ) ; + if ( !( bRes ) ) { - ::osl::Module aMod( getDllURL( ) ); - FuncPtr pFunc = ( FuncPtr ) aMod.getSymbol( rtl::OUString::createFromAscii( "firstfunc" ) ); - - OUString aFileURL; - bRes = osl::Module::getUrlFromAddress( ( void* )pFunc, aFileURL ); - if ( !( bRes ) ) - { - CPPUNIT_ASSERT_MESSAGE("Cannot locate current module.", sal_False ); - } - aMod.unload( ); - - CPPUNIT_ASSERT_MESSAGE( "#test comment#: load an external library, get its function address and get its URL.", - sal_True == bRes && 0 < aFileURL.lastIndexOf('/') && aFileURL.equalsIgnoreAsciiCase( getDllURL( ) ) ); + ASSERT_TRUE(sal_False) << "Cannot locate current module."; } - /* tester comments: another case is getFunctionSymbol_001*/ + ASSERT_TRUE(sal_True == bRes && 0 < aFileURL.lastIndexOf('/')) << "#test comment#: test get Module URL from address."; + } - CPPUNIT_TEST_SUITE( getUrlFromAddress ); - CPPUNIT_TEST( getUrlFromAddress_001 ); - CPPUNIT_TEST( getUrlFromAddress_002 ); - CPPUNIT_TEST_SUITE_END( ); - }; // class getUrlFromAddress + TEST_F(getUrlFromAddress, getUrlFromAddress_002 ) + { + ::osl::Module aMod( getDllURL( ) ); + FuncPtr pFunc = ( FuncPtr ) aMod.getSymbol( rtl::OUString::createFromAscii( "firstfunc" ) ); + OUString aFileURL; + bRes = osl::Module::getUrlFromAddress( ( void* )pFunc, aFileURL ); + if ( !( bRes ) ) + { + ASSERT_TRUE(sal_False) << "Cannot locate current module."; + } + aMod.unload( ); + + ASSERT_TRUE( sal_True == bRes && 0 < aFileURL.lastIndexOf('/') && aFileURL.equalsIgnoreAsciiCase( getDllURL( ) ) ) + << "#test comment#: load an external library, get its function address and get its URL."; + } /** testing the method: sal_Bool SAL_CALL load( const ::rtl::OUString& strModuleName, sal_Int32 nRtldMode = SAL_LOADMODULE_DEFAULT) */ - class load : public CppUnit::TestFixture + class load : public ::testing::Test { public: sal_Bool bRes, bRes1; + }; // class load - void load_001( ) - { - ::osl::Module aMod( getDllURL( ) ); - ::osl::Module aMod1; + TEST_F(load, load_001 ) + { + ::osl::Module aMod( getDllURL( ) ); + ::osl::Module aMod1; - aMod1.load( getDllURL( ) ); - bRes = oslModule(aMod) == oslModule(aMod1); - aMod.unload( ); - aMod1.unload( ); + aMod1.load( getDllURL( ) ); + bRes = oslModule(aMod) == oslModule(aMod1); + aMod.unload( ); + aMod1.unload( ); - CPPUNIT_ASSERT_MESSAGE( "#test comment#: load function should do the same thing as constructor with library name.", - sal_True == bRes ); - } - // load lib which is under a CJK directory - void load_002( ) - { + ASSERT_TRUE(sal_True == bRes) << "#test comment#: load function should do the same thing as constructor with library name."; + } + // load lib which is under a CJK directory + TEST_F(load, load_002 ) + { #ifdef UNX - //Can not get a CJK directory already exist, so here create one. Perhaps reason is encoding problem. - ::rtl::OUString aPidDirURL = rtl::OUString::createFromAscii( "file:///tmp/" ) + ::rtl::OUString::valueOf( ( long )getpid( ) ); - ::rtl::OUString aMyDirURL = aPidDirURL + aKname; - createTestDirectory( aPidDirURL ); - createTestDirectory( aMyDirURL ); - - ::rtl::OUString aDLLURL = aMyDirURL + rtl::OUString::createFromAscii( "/libModule_DLL.so" ); - //check if the lib exist. - //FIXME: if assert condition is false, the case will return, so the directory will not be clean-up - CPPUNIT_ASSERT_MESSAGE( "#Source file is not exist. please manually clean-up directory and file under /tmp", ifFileExist( getDllURL( ) ) == sal_True ); - ::osl::FileBase::RC nError = ::osl::File::copy( getDllURL( ), aDLLURL ); - CPPUNIT_ASSERT_MESSAGE( "#copy failed. please manually clean-up directory and file under /tmp", nError == ::osl::FileBase::E_None ); - //ifFileExist returned false but the file exist - CPPUNIT_ASSERT_MESSAGE( "#This file is not exist, copy failed. please manually clean-up directory and file under /tmp", ifFileExist( aDLLURL ) == sal_True ); - - //test if can create a normal file - ::rtl::OUString aFileURL = aMyDirURL + rtl::OUString::createFromAscii( "/test_file" ); - ::osl::File testFile( aFileURL ); - nError = testFile.open( OpenFlag_Create ); - CPPUNIT_ASSERT_MESSAGE( "#create failed. please manually clean-up directory and file under /tmp", nError == ::osl::FileBase::E_None ); - CPPUNIT_ASSERT_MESSAGE( "#This file is not exist, create failed. please manually clean-up directory and file under /tmp", ifFileExist( aFileURL ) == sal_True ); - - //load the copied dll - ::osl::Module aMod( aDLLURL ); - ::osl::Module aMod1; - - sal_Bool bOK = aMod1.load( aDLLURL ); - bRes = oslModule(aMod) == oslModule(aMod1); - aMod.unload( ); - aMod1.unload( ); - deleteTestFile( aFileURL ); - deleteTestFile( aDLLURL ); - deleteTestDirectory( aMyDirURL ); - deleteTestDirectory( aPidDirURL ); - - CPPUNIT_ASSERT_MESSAGE( "#test comment#: load lib which is under a CJK directory.", - sal_True == bRes && bOK == sal_True ); + //Can not get a CJK directory already exist, so here create one. Perhaps reason is encoding problem. + ::rtl::OUString aPidDirURL = rtl::OUString::createFromAscii( "file:///tmp/" ) + ::rtl::OUString::valueOf( ( long )getpid( ) ); + ::rtl::OUString aMyDirURL = aPidDirURL + aKname; + createTestDirectory( aPidDirURL ); + createTestDirectory( aMyDirURL ); + + ::rtl::OUString aDLLURL = aMyDirURL + rtl::OUString::createFromAscii( "/libModule_DLL.so" ); + //check if the lib exist. + //FIXME: if assert condition is false, the case will return, so the directory will not be clean-up + ASSERT_TRUE(ifFileExist( getDllURL( ) ) == sal_True) << "#Source file is not exist. please manually clean-up directory and file under /tmp"; + ::osl::FileBase::RC nError = ::osl::File::copy( getDllURL( ), aDLLURL ); + ASSERT_TRUE(nError == ::osl::FileBase::E_None) << "#copy failed. please manually clean-up directory and file under /tmp"; + //ifFileExist returned false but the file exist + ASSERT_TRUE( ifFileExist( aDLLURL ) == sal_True ) + << "#This file is not exist, copy failed. please manually clean-up directory and file under /tmp"; + + //test if can create a normal file + ::rtl::OUString aFileURL = aMyDirURL + rtl::OUString::createFromAscii( "/test_file" ); + ::osl::File testFile( aFileURL ); + nError = testFile.open( OpenFlag_Create ); + ASSERT_TRUE(nError == ::osl::FileBase::E_None) << "#create failed. please manually clean-up directory and file under /tmp"; + ASSERT_TRUE( ifFileExist( aFileURL ) == sal_True ) + << "#This file is not exist, create failed. please manually clean-up directory and file under /tmp"; + + //load the copied dll + ::osl::Module aMod( aDLLURL ); + ::osl::Module aMod1; + + sal_Bool bOK = aMod1.load( aDLLURL ); + bRes = oslModule(aMod) == oslModule(aMod1); + aMod.unload( ); + aMod1.unload( ); + deleteTestFile( aFileURL ); + deleteTestFile( aDLLURL ); + deleteTestDirectory( aMyDirURL ); + deleteTestDirectory( aPidDirURL ); + + ASSERT_TRUE(sal_True == bRes && bOK == sal_True) << "#test comment#: load lib which is under a CJK directory."; #endif - } - - CPPUNIT_TEST_SUITE( load ); - CPPUNIT_TEST( load_001 ); - CPPUNIT_TEST( load_002 ); - CPPUNIT_TEST_SUITE_END( ); - }; // class load - + } /** testing the method: void SAL_CALL unload() */ - class unload : public CppUnit::TestFixture + class unload : public ::testing::Test { public: sal_Bool bRes, bRes1; + }; // class unload - void unload_001( ) - { - ::osl::Module aMod( getDllURL( ) ); - - aMod.unload( ); - bRes = oslModule(aMod) ==NULL; - - CPPUNIT_ASSERT_MESSAGE( "#test comment#: unload function should do the same thing as destructor.", - sal_True == bRes ); - } + TEST_F(unload, unload_001) + { + ::osl::Module aMod( getDllURL( ) ); - CPPUNIT_TEST_SUITE( unload ); - CPPUNIT_TEST( unload_001 ); - CPPUNIT_TEST_SUITE_END( ); - }; // class unload + aMod.unload( ); + bRes = oslModule(aMod) ==NULL; + ASSERT_TRUE(sal_True == bRes) << "#test comment#: unload function should do the same thing as destructor."; + } /** testing the methods: sal_Bool SAL_CALL is() const */ - class is : public CppUnit::TestFixture + class is : public ::testing::Test { public: sal_Bool bRes, bRes1; - - void is_001( ) - { - OUString aFileURL; - bRes = osl::Module::getUrlFromAddress( ( void* ) &::osl_Module::testClass::myFunc, aFileURL ); - if ( !( bRes ) ) - { - CPPUNIT_ASSERT_MESSAGE("Cannot locate current module - using executable instead", sal_False ); - } - - ::osl::Module aMod; - bRes = aMod.is( ); - aMod.load( aFileURL ); - bRes1 = aMod.is( ); - aMod.unload( ); - - CPPUNIT_ASSERT_MESSAGE( "#test comment#: test if a module is a loaded module.", - sal_False == bRes && sal_True == bRes1); - } - CPPUNIT_TEST_SUITE( is ); - CPPUNIT_TEST( is_001 ); - CPPUNIT_TEST_SUITE_END( ); }; // class is + TEST_F(is, is_001) + { + ::osl::Module aMod; + bRes = aMod.is( ); + aMod.load( getDllURL( ) ); + bRes1 = aMod.is( ); + aMod.unload( ); + + ASSERT_TRUE(sal_False == bRes && sal_True == bRes1) << "#test comment#: test if a module is a loaded module."; + } /** testing the methods: void* SAL_CALL getSymbol( const ::rtl::OUString& strSymbolName) */ - class getSymbol : public CppUnit::TestFixture + class getSymbol : public ::testing::Test { public: sal_Bool bRes; - - void getSymbol_001( ) - { - ::osl::Module aMod( getDllURL( ) ); - FuncPtr pFunc = ( FuncPtr ) aMod.getSymbol( rtl::OUString::createFromAscii( "firstfunc" ) ); - bRes = sal_False; - if ( pFunc ) - bRes = pFunc( bRes ); - aMod.unload(); - - CPPUNIT_ASSERT_MESSAGE( "#test comment#: load a dll and call one function in it.", - sal_True == bRes ); - } - - CPPUNIT_TEST_SUITE( getSymbol ); - CPPUNIT_TEST( getSymbol_001 ); - CPPUNIT_TEST_SUITE_END( ); }; // class getSymbol + TEST_F(getSymbol, getSymbol_001) + { + ::osl::Module aMod( getDllURL( ) ); + FuncPtr pFunc = ( FuncPtr ) aMod.getSymbol( rtl::OUString::createFromAscii( "firstfunc" ) ); + bRes = sal_False; + if ( pFunc ) + bRes = pFunc( bRes ); + aMod.unload(); + + ASSERT_TRUE(sal_True == bRes) << "#test comment#: load a dll and call one function in it."; + } /** testing the methods: operator oslModule() const */ - class optr_oslModule : public CppUnit::TestFixture + class optr_oslModule : public ::testing::Test { public: sal_Bool bRes, bRes1; + }; // class optr_oslModule - void optr_oslModule_001( ) - { - ::osl::Module aMod; - bRes = ( (oslModule)aMod == NULL ); - - aMod.load( getDllURL( ) ); - bRes1 = (oslModule)aMod != NULL; + TEST_F(optr_oslModule, optr_oslModule_001 ) + { + ::osl::Module aMod; + bRes = ( (oslModule)aMod == NULL ); - aMod.unload( ); + aMod.load( getDllURL( ) ); + bRes1 = (oslModule)aMod != NULL; - CPPUNIT_ASSERT_MESSAGE( "#test comment#: the m_Module of a Module instance will be NULL when is not loaded, it will not be NULL after loaded.", - sal_True == bRes && sal_True == bRes1); - } + aMod.unload( ); - void optr_oslModule_002( ) - { - ::osl::Module aMod( getDllURL( ) ); - ::rtl::OUString funcName(::rtl::OUString::createFromAscii( "firstfunc" ) ); + ASSERT_TRUE(sal_True == bRes && sal_True == bRes1) + << "#test comment#: the m_Module of a Module instance will be NULL when is not loaded, it will not be NULL after loaded."; + } - FuncPtr pFunc = ( FuncPtr ) osl_getSymbol( (oslModule)aMod, funcName.pData ); - bRes = sal_False; - if ( pFunc ) - bRes = pFunc( bRes ); + TEST_F(optr_oslModule, optr_oslModule_002 ) + { + ::osl::Module aMod( getDllURL( ) ); + ::rtl::OUString funcName(::rtl::OUString::createFromAscii( "firstfunc" ) ); - aMod.unload(); + FuncPtr pFunc = ( FuncPtr ) osl_getSymbol( (oslModule)aMod, funcName.pData ); + bRes = sal_False; + if ( pFunc ) + bRes = pFunc( bRes ); - CPPUNIT_ASSERT_MESSAGE( "#test comment#: use m_Module to call osl_getSymbol() function.", - sal_True == bRes ); - } + aMod.unload(); - CPPUNIT_TEST_SUITE( optr_oslModule ); - CPPUNIT_TEST( optr_oslModule_001 ); - CPPUNIT_TEST( optr_oslModule_002 ); - CPPUNIT_TEST_SUITE_END( ); - }; // class optr_oslModule + ASSERT_TRUE(sal_True == bRes) << "#test comment#: use m_Module to call osl_getSymbol() function."; + } /** testing the methods: oslGenericFunction SAL_CALL getFunctionSymbol( const ::rtl::OUString& ustrFunctionSymbolName ) */ - class getFunctionSymbol : public CppUnit::TestFixture + class getFunctionSymbol : public ::testing::Test { public: sal_Bool bRes, bRes1; - - void getFunctionSymbol_001( ) - { - ::osl::Module aMod( getDllURL( ) ); - oslGenericFunction oslFunc = aMod.getFunctionSymbol( rtl::OUString::createFromAscii( "firstfunc" ) ); - ::rtl::OUString aLibraryURL; - bRes = ::osl::Module::getUrlFromAddress( oslFunc, aLibraryURL); - aMod.unload(); - printFileName( aLibraryURL ); - - CPPUNIT_ASSERT_MESSAGE( "#test comment#: load a dll and get its function addr and get its URL.", - sal_True == bRes && aLibraryURL.equalsIgnoreAsciiCase( getDllURL() ) ); - } - - CPPUNIT_TEST_SUITE( getFunctionSymbol ); - CPPUNIT_TEST( getFunctionSymbol_001 ); - //CPPUNIT_TEST( getFunctionSymbol_002 ); - CPPUNIT_TEST_SUITE_END( ); }; // class getFunctionSymbol -// ----------------------------------------------------------------------------- -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::ctors, "osl_Module"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::getUrlFromAddress, "osl_Module"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::load, "osl_Module"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::unload, "osl_Module"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::is, "osl_Module"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::getSymbol, "osl_Module"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::optr_oslModule, "osl_Module"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Module::getFunctionSymbol, "osl_Module"); -// ----------------------------------------------------------------------------- + TEST_F(getFunctionSymbol, getFunctionSymbol_001) + { + ::osl::Module aMod( getDllURL( ) ); + oslGenericFunction oslFunc = aMod.getFunctionSymbol( rtl::OUString::createFromAscii( "firstfunc" ) ); + ::rtl::OUString aLibraryURL; + bRes = ::osl::Module::getUrlFromAddress( oslFunc, aLibraryURL); + aMod.unload(); + printFileName( aLibraryURL ); + + ASSERT_TRUE(sal_True == bRes && aLibraryURL.equalsIgnoreAsciiCase( getDllURL() )) << "#test comment#: load a dll and get its function addr and get its URL."; + } } // namespace osl_Module -// ----------------------------------------------------------------------------- - -// this macro creates an empty function, which will called by the RegisterAllFunctions() -// to let the user the possibility to also register some functions by hand. -NOADDITIONAL; +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/sal/qa/osl/module/osl_Module_Const.h b/sal/qa/osl/module/osl_Module_Const.h index d3268ee..3eb90e7 100644 --- a/sal/qa/osl/module/osl_Module_Const.h +++ b/sal/qa/osl/module/osl_Module_Const.h @@ -30,7 +30,6 @@ #include <osl/module.hxx> #include <osl/file.hxx> -#include <testshl/simpleheader.hxx> #if ( defined UNX ) || ( defined OS2 ) //Unix # include <unistd.h> diff --git a/sal/qa/osl/module/osl_Module_DLL.cxx b/sal/qa/osl/module/osl_Module_DLL.cxx index a4a18de..f640558 100644 --- a/sal/qa/osl/module/osl_Module_DLL.cxx +++ b/sal/qa/osl/module/osl_Module_DLL.cxx @@ -26,7 +26,6 @@ #include <stdio.h> #include <sal/types.h> -#include <testshl/simpleheader.hxx> extern "C" sal_Bool SAL_CALL firstfunc( sal_Bool bRes ) { commit 43fbebfbe5d14054c72486aed92f9702367406f8 Author: Damjan Jovanovic <dam...@apache.org> Date: Fri Sep 4 16:32:10 2015 +0000 #i125003# migrate main/sal/qa/osl/process from cppunit to Google Test. diff --git a/sal/qa/osl/process/makefile.mk b/sal/qa/osl/process/makefile.mk index 72e0e00..c45f014 100644 --- a/sal/qa/osl/process/makefile.mk +++ b/sal/qa/osl/process/makefile.mk @@ -31,6 +31,13 @@ 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) @@ -41,33 +48,23 @@ CXXFLAGS+= $(LFS_CFLAGS) CFLAGS+=/Ob1 .ENDIF -SHL1OBJS= \ +APP1OBJS= \ $(SLO)$/osl_Thread.obj -SHL1TARGET= osl_Thread -SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) - -SHL1IMPLIB= i$(SHL1TARGET) - -# SHL1DEF= $(MISC)$/$(SHL1TARGET).def - -DEF1NAME =$(SHL1TARGET) - -# DEF1EXPORTFILE= export.exp -SHL1VERSIONMAP = $(PRJ)$/qa$/export.map +APP1TARGET= osl_Thread +APP1STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB) +APP1RPATH = NONE +APP1TEST = enabled # END ------------------------------------------------------------------ #.IF "$(GUI)" == "WNT" -SHL2OBJS=$(SLO)$/osl_process.obj -SHL2TARGET=osl_process -SHL2STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB) - -SHL2IMPLIB=i$(SHL2TARGET) -SHL2DEF=$(MISC)$/$(SHL2TARGET).def -DEF2NAME=$(SHL2TARGET) -DEF2EXPORTFILE=export.exp +APP2OBJS=$(SLO)$/osl_process.obj +APP2TARGET=osl_process +APP2STDLIBS= $(SALLIB) $(GTESTLIB) $(TESTSHL2LIB) +APP2RPATH = NONE +APP2TEST = enabled # END ------------------------------------------------------------------ @@ -85,20 +82,8 @@ APP3STDLIBS=$(SALLIB) #.ENDIF # "$(GUI)" == "WNT" -#------------------------------- All object files ------------------------------- -# do this here, so we get right dependencies - -.IF "$(GUI)" == "OS2" - -SLOFILES=$(SHL2OBJS) - -.ELSE - -SLOFILES=$(SHL1OBJS) $(SHL2OBJS) - -.ENDIF - # --- Targets ------------------------------------------------------ .INCLUDE : target.mk -.INCLUDE : _cppunit.mk + +.ENDIF # "$(ENABLE_UNIT_TESTS)" != "YES" diff --git a/sal/qa/osl/process/osl_Thread.cxx b/sal/qa/osl/process/osl_Thread.cxx index 36bf0cc..01cbe00 100644 --- a/sal/qa/osl/process/osl_Thread.cxx +++ b/sal/qa/osl/process/osl_Thread.cxx @@ -45,7 +45,7 @@ #endif #include <osl/time.h> -#include <testshl/simpleheader.hxx> +#include "gtest/gtest.h" using namespace osl; using namespace rtl; @@ -92,7 +92,7 @@ void StopWatch::start() m_bIsValid = false; m_bIsRunning = true; osl_getSystemTime( &t1 ); - t_print("# %d %d nsecs\n", t1.Seconds, t1.Nanosec); + printf("# %d %d nsecs\n", t1.Seconds, t1.Nanosec); // gettimeofday(&t1, 0); } @@ -103,7 +103,7 @@ void StopWatch::stop() // gettimeofday(&t2, 0); // Timer ausfragen osl_getSystemTime( &t2 ); - t_print("# %d %d nsecs\n", t2.Seconds, t2.Nanosec); + printf("# %d %d nsecs\n", t2.Seconds, t2.Nanosec); if (m_bIsRunning) { // check ob gestartet. @@ -123,7 +123,7 @@ void StopWatch::stop() m_nNanoSec = 1000000000 + static_cast<sal_Int32>(t2.Nanosec) - static_cast<sal_Int32>(t1.Nanosec); m_nSeconds -= 1; } - t_print("# %d %d nsecs\n", m_nSeconds, m_nNanoSec ); + printf("# %d %d nsecs\n", m_nSeconds, m_nNanoSec ); //if (m_nNanoSec < 0) //{ //m_nNanoSec += 1000000000; @@ -193,7 +193,7 @@ namespace ThreadHelper { // if (nVerbose == VERBOSE) // { - // t_print("wait %d tenth seconds. ", _nTenthSec ); + // printf("wait %d tenth seconds. ", _nTenthSec ); // fflush(stdout); // } #ifdef WNT //Windows @@ -207,7 +207,7 @@ namespace ThreadHelper #endif // if (nVerbose == VERBOSE) // { - // t_print("done\n"); + // printf("done\n"); // } } @@ -216,27 +216,27 @@ namespace ThreadHelper // LLA: output the priority if (_aPriority == osl_Thread_PriorityHighest) { - t_print("Prio is High\n"); + printf("Prio is High\n"); } else if (_aPriority == osl_Thread_PriorityAboveNormal) { - t_print("Prio is above normal\n"); + printf("Prio is above normal\n"); } else if (_aPriority == osl_Thread_PriorityNormal) { - t_print("Prio is normal\n"); + printf("Prio is normal\n"); } else if (_aPriority == osl_Thread_PriorityBelowNormal) { - t_print("Prio is below normal\n"); + printf("Prio is below normal\n"); } else if (_aPriority == osl_Thread_PriorityLowest) { - t_print("Prio is lowest\n"); + printf("Prio is lowest\n"); } else { - t_print("Prio is unknown\n"); + printf("Prio is unknown\n"); } } } @@ -277,7 +277,7 @@ public: { if (isRunning()) { - t_print("error: not terminated.\n"); + printf("error: not terminated.\n"); } } @@ -293,7 +293,7 @@ public: OCountThread() { m_nWaitSec = 0; - t_print("new OCountThread thread %d!\n", getIdentifier()); + printf("new OCountThread thread %d!\n", getIdentifier()); } sal_Int32 getValue() { return m_aFlag.getValue(); } @@ -339,7 +339,7 @@ protected: } void SAL_CALL onTerminated() { - t_print("normally terminate this thread %d!\n", getIdentifier()); + printf("normally terminate this thread %d!\n", getIdentifier()); } public: @@ -347,7 +347,7 @@ public: { if (isRunning()) { - t_print("error: not terminated.\n"); + printf("error: not terminated.\n"); } } @@ -399,7 +399,7 @@ public: { if (isRunning()) { - t_print("error: not terminated.\n"); + printf("error: not terminated.\n"); } } @@ -434,18 +434,18 @@ protected: } void SAL_CALL onTerminated() { - t_print("normally terminate this thread %d!\n", getIdentifier()); + printf("normally terminate this thread %d!\n", getIdentifier()); } public: ONoScheduleThread() { - t_print("new thread id %d!\n", getIdentifier()); + printf("new thread id %d!\n", getIdentifier()); } ~ONoScheduleThread() { if (isRunning()) { - t_print("error: not terminated.\n"); + printf("error: not terminated.\n"); } } @@ -478,7 +478,7 @@ protected: } void SAL_CALL onTerminated() { - // t_print("normally terminate this thread %d!\n", getIdentifier()); + // printf("normally terminate this thread %d!\n", getIdentifier()); } public: @@ -486,7 +486,7 @@ public: { if (isRunning()) { - // t_print("error: not terminated.\n"); + // printf("error: not terminated.\n"); } } @@ -504,7 +504,7 @@ namespace osl_Thread // while on Windows, after createSuspended, the thread can not terminate, wait endlessly, // so here call resume at first, then call terminate. #ifdef WNT - t_print("resumeAndWaitThread\n"); + printf("resumeAndWaitThread\n"); _pThread->resume(); ThreadHelper::thread_sleep_tenth_sec(1); #else @@ -525,145 +525,123 @@ namespace osl_Thread _pThread->resume(); ThreadHelper::thread_sleep_tenth_sec(1); #endif - t_print("#wait for join.\n"); + printf("#wait for join.\n"); _pThread->join(); } /** Test of the osl::Thread::create method */ - class create : public CppUnit::TestFixture + class create : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class create - /** Simple create a thread. - Create a simple thread, it just does add 1 to value(which initialized 0), - if the thread run, the value should be 1. - */ - void create_001() - { - myThread* newthread = new myThread(); - sal_Bool bRes = newthread->create(); - CPPUNIT_ASSERT_MESSAGE("Can not creates a new thread!\n", bRes == sal_True ); - - ThreadHelper::thread_sleep_tenth_sec(1); // wait short - sal_Bool isRunning = newthread->isRunning(); // check if thread is running - /// wait for the new thread to assure it has run - ThreadHelper::thread_sleep_tenth_sec(3); - sal_Int32 nValue = newthread->getValue(); - /// to assure the new thread has terminated - termAndJoinThread(newthread); - delete newthread; - - t_print(" nValue = %d\n", nValue); - t_print("isRunning = %d\n", isRunning); - - CPPUNIT_ASSERT_MESSAGE( - "Creates a new thread", - nValue >= 1 && isRunning == sal_True - ); + /** Simple create a thread. - } + Create a simple thread, it just does add 1 to value(which initialized 0), + if the thread run, the value should be 1. + */ + TEST_F(create, create_001) + { + myThread* newthread = new myThread(); + sal_Bool bRes = newthread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can not creates a new thread!\n"; - /** only one running thread per instance, return false if create secondly - */ - void create_002() - { - myThread* newthread = new myThread(); - sal_Bool res1 = newthread->create(); - sal_Bool res2 = newthread->create(); - t_print("In non pro, an assertion should occurred. This behaviour is right.\n"); - termAndJoinThread(newthread); - delete newthread; - - CPPUNIT_ASSERT_MESSAGE( - "Creates a new thread: can not create two threads per instance", - res1 && !res2 - ); + ThreadHelper::thread_sleep_tenth_sec(1); // wait short + sal_Bool isRunning = newthread->isRunning(); // check if thread is running + /// wait for the new thread to assure it has run + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nValue = newthread->getValue(); + /// to assure the new thread has terminated + termAndJoinThread(newthread); + delete newthread; - } + printf(" nValue = %d\n", nValue); + printf("isRunning = %d\n", isRunning); - CPPUNIT_TEST_SUITE(create); - CPPUNIT_TEST(create_001); - CPPUNIT_TEST(create_002); - CPPUNIT_TEST_SUITE_END(); - }; // class create + ASSERT_TRUE(nValue >= 1 && isRunning == sal_True) << "Creates a new thread"; + } + + /** only one running thread per instance, return false if create secondly + */ + TEST_F(create, create_002) + { + myThread* newthread = new myThread(); + sal_Bool res1 = newthread->create(); + sal_Bool res2 = newthread->create(); + printf("In non pro, an assertion should occured. This behaviour is right.\n"); + termAndJoinThread(newthread); + delete newthread; + + ASSERT_TRUE(res1 && !res2) << "Creates a new thread: can not create two threads per instance"; + + } /** Test of the osl::Thread::createSuspended method */ - class createSuspended : public CppUnit::TestFixture + class createSuspended : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class createSuspended - /** Create a suspended thread, use the same class as create_001 + /** Create a suspended thread, use the same class as create_001 - after create, wait enough time, check the value, if it's still the initial value, pass - */ - void createSuspended_001() - { - myThread* newthread = new myThread(); - sal_Bool bRes = newthread->createSuspended(); - CPPUNIT_ASSERT_MESSAGE("Can not creates a new thread!", bRes == sal_True ); - - ThreadHelper::thread_sleep_tenth_sec(1); - sal_Bool isRunning = newthread->isRunning(); - ThreadHelper::thread_sleep_tenth_sec(3); - sal_Int32 nValue = newthread->getValue(); + after create, wait enough time, check the value, if it's still the initial value, pass + */ + TEST_F(createSuspended, createSuspended_001) + { + myThread* newthread = new myThread(); + sal_Bool bRes = newthread->createSuspended(); + ASSERT_TRUE(bRes == sal_True) << "Can not creates a new thread!"; - resumeAndWaitThread(newthread); + ThreadHelper::thread_sleep_tenth_sec(1); + sal_Bool isRunning = newthread->isRunning(); + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nValue = newthread->getValue(); - termAndJoinThread(newthread); - delete newthread; + resumeAndWaitThread(newthread); - CPPUNIT_ASSERT_MESSAGE( - "Creates a new suspended thread", - nValue == 0 && isRunning - ); - } + termAndJoinThread(newthread); + delete newthread; - void createSuspended_002() - { - myThread* newthread = new myThread(); - sal_Bool res1 = newthread->createSuspended(); - sal_Bool res2 = newthread->createSuspended(); + ASSERT_TRUE(nValue == 0 && isRunning) << "Creates a new suspended thread"; + } + // LLA: Deadlocked!!! + TEST_F(createSuspended, createSuspended_002) + { + myThread* newthread = new myThread(); + sal_Bool res1 = newthread->createSuspended(); + sal_Bool res2 = newthread->createSuspended(); - resumeAndWaitThread(newthread); + resumeAndWaitThread(newthread); - termAndJoinThread(newthread); + termAndJoinThread(newthread); - delete newthread; + delete newthread; - CPPUNIT_ASSERT_MESSAGE( - "Creates a new thread: can not create two threads per instance", - res1 && !res2 - ); - } + ASSERT_TRUE(res1 && !res2) << "Creates a new thread: can not create two threads per instance"; + } - CPPUNIT_TEST_SUITE(createSuspended); - CPPUNIT_TEST(createSuspended_001); - // LLA: Deadlocked!!! - CPPUNIT_TEST(createSuspended_002); - CPPUNIT_TEST_SUITE_END(); - }; // class createSuspended /** when the count value equal to or more than 3, suspend the thread. */ @@ -683,436 +661,384 @@ namespace osl_Thread /** Test of the osl::Thread::suspend method */ - class suspend : public CppUnit::TestFixture + class suspend : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class suspend - /** Use a thread which has a flag added 1 every second + /** Use a thread which has a flag added 1 every second - ALGORITHM: - create the thread, after running special time, record value of flag, then suspend it, - wait a long time, check the flag, if it remains unchanged during suspending - */ - void suspend_001() - { - OCountThread* aCountThread = new OCountThread(); - sal_Bool bRes = aCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); - // the thread run for some seconds, but not terminate - suspendCountThread( aCountThread ); + ALGORITHM: + create the thread, after running special time, record value of flag, then suspend it, + wait a long time, check the flag, if it remains unchanged during suspending + */ + TEST_F(suspend, suspend_001) + { + OCountThread* aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; + // the thread run for some seconds, but not terminate + suspendCountThread( aCountThread ); - // the value just after calling suspend - sal_Int32 nValue = aCountThread->getValue(); // (2) + // the value just after calling suspend + sal_Int32 nValue = aCountThread->getValue(); // (2) - ThreadHelper::thread_sleep_tenth_sec(3); + ThreadHelper::thread_sleep_tenth_sec(3); - // the value after waiting 3 seconds - sal_Int32 nLaterValue = aCountThread->getValue(); // (3) + // the value after waiting 3 seconds + sal_Int32 nLaterValue = aCountThread->getValue(); // (3) - resumeAndWaitThread(aCountThread); - termAndJoinThread(aCountThread); - delete aCountThread; + resumeAndWaitThread(aCountThread); + termAndJoinThread(aCountThread); + delete aCountThread; - CPPUNIT_ASSERT_MESSAGE( - "Suspend the thread", - bRes == sal_True && nValue == nLaterValue - ); + ASSERT_TRUE(bRes == sal_True && nValue == nLaterValue) << "Suspend the thread"; - } - /** suspend a thread in it's worker-function, the ALGORITHM is same as suspend_001 - reason of deadlocked I think: no schedule can schedule other threads to go on excuting - */ - void suspend_002() + } + /** suspend a thread in it's worker-function, the ALGORITHM is same as suspend_001 + reason of deadlocked I think: no schedule can schedule other threads to go on excuting + */ + TEST_F(suspend, suspend_002) + { +#if 0 + OSuspendThread* aThread = new OSuspendThread(); + sal_Bool bRes = aThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; + // first the thread run for some seconds, but not terminate + sal_Int32 nValue = 0; + //while (1) + //{ + ThreadHelper::thread_sleep_tenth_sec(3); + nValue = aThread->getValue(); // (1) + printf(" getValue is %d !", nValue ); + if (nValue >= 2) { - OSuspendThread* aThread = new OSuspendThread(); - sal_Bool bRes = aThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); - // first the thread run for some seconds, but not terminate - sal_Int32 nValue = 0; - //while (1) - //{ - ThreadHelper::thread_sleep_tenth_sec(3); - nValue = aThread->getValue(); // (1) - t_print(" getValue is %d !", nValue ); - if (nValue >= 2) - { - aThread->setSuspend(); - //break; - } - //} - t_print(" after while!"); - // the value just after calling suspend - nValue = aThread->getValue(); // (2) - - ThreadHelper::thread_sleep_tenth_sec(3); - t_print(" after sleep!"); - // the value after waiting 3 seconds - sal_Int32 nLaterValue = aThread->getValue(); // (3) - - //resumeAndWaitThread(aThread); - aThread->resume(); - termAndJoinThread(aThread); - delete aThread; - - CPPUNIT_ASSERT_MESSAGE( - "Suspend the thread", - bRes == sal_True && nValue == nLaterValue - ); + aThread->setSuspend(); + //break; } + //} + printf(" after while!"); + // the value just after calling suspend + nValue = aThread->getValue(); // (2) + + ThreadHelper::thread_sleep_tenth_sec(3); + printf(" after sleep!"); + // the value after waiting 3 seconds + sal_Int32 nLaterValue = aThread->getValue(); // (3) + + //resumeAndWaitThread(aThread); + aThread->resume(); + termAndJoinThread(aThread); + delete aThread; + + ASSERT_TRUE(bRes == sal_True && nValue == nLaterValue) << "Suspend the thread"; +#endif + } - CPPUNIT_TEST_SUITE(suspend); - CPPUNIT_TEST(suspend_001); - // LLA: Deadlocked!!! - // CPPUNIT_TEST(createSuspended_002); - CPPUNIT_TEST_SUITE_END(); - }; // class suspend /** Test of the osl::Thread::resume method */ - class resume : public CppUnit::TestFixture + class resume : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class resume - /** check if the thread run samely as usual after suspend and resume - - ALGORITHM: - compare the values before and after suspend, they should be same, - then compare values before and after resume, the difference should be same as the sleep seconds number - */ - void resume_001() - { - OCountThread* pCountThread = new OCountThread(); - sal_Bool bRes = pCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + /** check if the thread run samely as usual after suspend and resume - suspendCountThread(pCountThread); + ALGORITHM: + compare the values before and after suspend, they should be same, + then compare values before and after resume, the difference should be same as the sleep seconds number + */ + TEST_F(resume, resume_001) + { + OCountThread* pCountThread = new OCountThread(); + sal_Bool bRes = pCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; - sal_Int32 nSuspendValue = pCountThread->getValue(); // (2) - // suspend for 3 seconds - ThreadHelper::thread_sleep_tenth_sec(3); - pCountThread->resume(); + suspendCountThread(pCountThread); - ThreadHelper::thread_sleep_tenth_sec(3); - sal_Int32 nResumeValue = pCountThread->getValue(); + sal_Int32 nSuspendValue = pCountThread->getValue(); // (2) + // suspend for 3 seconds + ThreadHelper::thread_sleep_tenth_sec(3); + pCountThread->resume(); - ThreadHelper::thread_sleep_tenth_sec(3); - sal_Int32 nLaterValue = pCountThread->getValue(); + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nResumeValue = pCountThread->getValue(); - termAndJoinThread(pCountThread); - delete pCountThread; + ThreadHelper::thread_sleep_tenth_sec(3); + sal_Int32 nLaterValue = pCountThread->getValue(); - t_print("SuspendValue: %d\n", nSuspendValue); - t_print("ResumeValue: %d\n", nResumeValue); - t_print("LaterValue: %d\n", nLaterValue); + termAndJoinThread(pCountThread); + delete pCountThread; - /* LLA: this assumption is no longer relevant: nResumeValue == nSuspendValue && */ - CPPUNIT_ASSERT_MESSAGE( - "Suspend then resume the thread", - nLaterValue >= 9 && - nResumeValue > nSuspendValue && - nLaterValue > nResumeValue - ); + printf("SuspendValue: %d\n", nSuspendValue); + printf("ResumeValue: %d\n", nResumeValue); + printf("LaterValue: %d\n", nLaterValue); - } + /* LLA: this assumption is no longer relevant: nResumeValue == nSuspendValue && */ + ASSERT_TRUE(nLaterValue >= 9 && + nResumeValue > nSuspendValue && + nLaterValue > nResumeValue) << "Suspend then resume the thread"; - /** Create a suspended thread then resume, check if the thread has run - */ - void resume_002() - { - myThread* newthread = new myThread(); - sal_Bool bRes = newthread->createSuspended(); - CPPUNIT_ASSERT_MESSAGE ( "Can't create thread!", bRes == sal_True ); + } - newthread->resume(); - ThreadHelper::thread_sleep_tenth_sec(2); - sal_Int32 nValue = newthread->getValue(); + /** Create a suspended thread then resume, check if the thread has run + */ + TEST_F(resume, resume_002) + { + myThread* newthread = new myThread(); + sal_Bool bRes = newthread->createSuspended(); + ASSERT_TRUE(bRes == sal_True) << "Can't create thread!"; - termAndJoinThread(newthread); - delete newthread; + newthread->resume(); + ThreadHelper::thread_sleep_tenth_sec(2); + sal_Int32 nValue = newthread->getValue(); - t_print(" nValue = %d\n", nValue); + termAndJoinThread(newthread); + delete newthread; - CPPUNIT_ASSERT_MESSAGE( - "Creates a suspended thread, then resume", - nValue >= 1 - ); - } + printf(" nValue = %d\n", nValue); - CPPUNIT_TEST_SUITE(resume); - CPPUNIT_TEST(resume_001); - CPPUNIT_TEST(resume_002); - CPPUNIT_TEST_SUITE_END(); - }; // class resume + ASSERT_TRUE(nValue >= 1) << "Creates a suspended thread, then resume"; + } /** Test of the osl::Thread::terminate method */ - class terminate : public CppUnit::TestFixture + class terminate : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class terminate - /** Check after call terminate if the running thread running go on executing + /** Check after call terminate if the running thread running go on executing - ALGORITHM: - before and after call terminate, the values should be the same - */ - void terminate_001() - { - OCountThread* aCountThread = new OCountThread(); - sal_Bool bRes = aCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); - - ThreadHelper::thread_sleep_tenth_sec(2); - sal_Int32 nValue = aCountThread->getValue(); - aCountThread->terminate(); - ThreadHelper::thread_sleep_tenth_sec(2); - sal_Int32 nLaterValue = aCountThread->getValue(); - - // isRunning should be false after terminate - sal_Bool isRunning = aCountThread->isRunning(); - aCountThread->join(); - delete aCountThread; - - t_print(" nValue = %d\n", nValue); - t_print("nLaterValue = %d\n", nLaterValue); - - CPPUNIT_ASSERT_MESSAGE( - "Terminate the thread", - isRunning == sal_False && nLaterValue >= nValue - ); - } - /** Check if a suspended thread will terminate after call terminate, different on w32 and on UNX - */ - void terminate_002() - { - OCountThread* aCountThread = new OCountThread(); - sal_Bool bRes = aCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); + ALGORITHM: + before and after call terminate, the values should be the same + */ + TEST_F(terminate, terminate_001) + { + OCountThread* aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; - ThreadHelper::thread_sleep_tenth_sec(1); - suspendCountThread(aCountThread); - sal_Int32 nValue = aCountThread->getValue(); + ThreadHelper::thread_sleep_tenth_sec(2); + sal_Int32 nValue = aCountThread->getValue(); + aCountThread->terminate(); + ThreadHelper::thread_sleep_tenth_sec(2); + sal_Int32 nLaterValue = aCountThread->getValue(); + + // isRunning should be false after terminate + sal_Bool isRunning = aCountThread->isRunning(); + aCountThread->join(); + delete aCountThread; - // seems a suspended thread can not be terminated on W32, while on Solaris can - resumeAndWaitThread(aCountThread); + printf(" nValue = %d\n", nValue); + printf("nLaterValue = %d\n", nLaterValue); - ThreadHelper::thread_sleep_tenth_sec(2); + ASSERT_TRUE(isRunning == sal_False && nLaterValue >= nValue) << "Terminate the thread"; + } + /** Check if a suspended thread will terminate after call terminate, different on w32 and on UNX + */ + TEST_F(terminate, terminate_002) + { + OCountThread* aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; - termAndJoinThread(aCountThread); - sal_Int32 nLaterValue = aCountThread->getValue(); - delete aCountThread; + ThreadHelper::thread_sleep_tenth_sec(1); + suspendCountThread(aCountThread); + sal_Int32 nValue = aCountThread->getValue(); - t_print(" nValue = %d\n", nValue); - t_print("nLaterValue = %d\n", nLaterValue); + // seems a suspended thread can not be terminated on W32, while on Solaris can + resumeAndWaitThread(aCountThread); - CPPUNIT_ASSERT_MESSAGE( - "Suspend then resume the thread", - nLaterValue > nValue ); - } + ThreadHelper::thread_sleep_tenth_sec(2); + + termAndJoinThread(aCountThread); + sal_Int32 nLaterValue = aCountThread->getValue(); + delete aCountThread; + + printf(" nValue = %d\n", nValue); + printf("nLaterValue = %d\n", nLaterValue); + + ASSERT_TRUE(nLaterValue > nValue) << "Suspend then resume the thread"; + } - CPPUNIT_TEST_SUITE(terminate); - CPPUNIT_TEST(terminate_001); - CPPUNIT_TEST(terminate_002); - CPPUNIT_TEST_SUITE_END(); - }; // class terminate /** Test of the osl::Thread::join method */ - class join : public CppUnit::TestFixture + class join : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class join - /** Check after call terminate if the thread running function will not go on executing + /** Check after call terminate if the thread running function will not go on executing - the next statement after join will not exec before the thread terminate - ALGORITHM: - recode system time at the beginning of the thread run, call join, then record system time again, - the difference of the two time should be equal or more than 20 seconds, the CountThead normally terminate - */ - void join_001() - { - OCountThread *aCountThread = new OCountThread(); - sal_Bool bRes = aCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); - - StopWatch aStopWatch; - aStopWatch.start(); - // TimeValue aTimeVal_befor; - // osl_getSystemTime( &aTimeVal_befor ); - //t_print("#join:the system time is %d,%d\n", pTimeVal_befor->Seconds,pTimeVal_befor->Nanosec); - - aCountThread->join(); - - //the below line will be executed after aCountThread terminate - // TimeValue aTimeVal_after; - // osl_getSystemTime( &aTimeVal_after ); - aStopWatch.stop(); - // sal_uInt32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; - double nSec = aStopWatch.getSeconds(); - t_print("join_001 nSec=%f\n", nSec); - delete aCountThread; - - CPPUNIT_ASSERT_MESSAGE( - "Join the thread: after the thread terminate", - nSec >= 2 - ); + the next statement after join will not exec before the thread terminate + ALGORITHM: + recode system time at the beginning of the thread run, call join, then record system time again, + the difference of the two time should be equal or more than 20 seconds, the CountThead normally terminate + */ + TEST_F(join, join_001) + { + OCountThread *aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; - } - /** after terminated by another thread, join exited immediately + StopWatch aStopWatch; + aStopWatch.start(); + // TimeValue aTimeVal_befor; + // osl_getSystemTime( &aTimeVal_befor ); + //printf("#join:the system time is %d,%d\n", pTimeVal_befor->Seconds,pTimeVal_befor->Nanosec); - ALGORITHM: - terminate the thread when value>=3, call join, check the beginning time and time after join, - the difference should be 3 seconds, join costs little time - */ - void join_002() - { - OCountThread *aCountThread = new OCountThread(); - sal_Bool bRes = aCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); - - //record the time when the running begin - // TimeValue aTimeVal_befor; - // osl_getSystemTime( &aTimeVal_befor ); - StopWatch aStopWatch; - aStopWatch.start(); - - ThreadHelper::thread_sleep_tenth_sec(10); - termAndJoinThread(aCountThread); - - //the below line will be executed after aCountThread terminate - // TimeValue aTimeVal_after; - // osl_getSystemTime( &aTimeVal_after ); - // sal_uInt32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; - aStopWatch.stop(); - double nSec = aStopWatch.getSeconds(); - t_print("join_002 nSec=%f\n", nSec); - - delete aCountThread; - CPPUNIT_ASSERT_MESSAGE( - "Join the thread: after thread terminate by another thread", - nSec >= 1 - ); - } + aCountThread->join(); - CPPUNIT_TEST_SUITE(join); - CPPUNIT_TEST(join_001); - CPPUNIT_TEST(join_002); - CPPUNIT_TEST_SUITE_END(); - }; // class join + //the below line will be executed after aCountThread terminate + // TimeValue aTimeVal_after; + // osl_getSystemTime( &aTimeVal_after ); + aStopWatch.stop(); + // sal_uInt32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; + double nSec = aStopWatch.getSeconds(); + printf("join_001 nSec=%f\n", nSec); + delete aCountThread; + + ASSERT_TRUE(nSec >= 2) << "Join the thread: after the thread terminate"; + + } + /** after terminated by another thread, join exited immediately + + ALGORITHM: + terminate the thread when value>=3, call join, check the beginning time and time after join, + the difference should be 3 seconds, join costs little time + */ + TEST_F(join, join_002) + { + OCountThread *aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; + + //record the time when the running begin + // TimeValue aTimeVal_befor; + // osl_getSystemTime( &aTimeVal_befor ); + StopWatch aStopWatch; + aStopWatch.start(); + + ThreadHelper::thread_sleep_tenth_sec(10); + termAndJoinThread(aCountThread); + + //the below line will be executed after aCountThread terminate + // TimeValue aTimeVal_after; + // osl_getSystemTime( &aTimeVal_after ); + // sal_uInt32 nSec = aTimeVal_after.Seconds - aTimeVal_befor.Seconds; + aStopWatch.stop(); + double nSec = aStopWatch.getSeconds(); + printf("join_002 nSec=%f\n", nSec); + + delete aCountThread; + ASSERT_TRUE(nSec >= 1) << "Join the thread: after thread terminate by another thread"; + } /** Test of the osl::Thread::isRunning method */ - class isRunning : public CppUnit::TestFixture + class isRunning : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } + }; // class isRunning - /** - */ - void isRunning_001() - { - OCountThread *aCountThread = new OCountThread(); - sal_Bool bRes = aCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); - - sal_Bool bRun = aCountThread->isRunning(); - - ThreadHelper::thread_sleep_tenth_sec(2); - termAndJoinThread(aCountThread); - sal_Bool bTer = aCountThread->isRunning(); - delete aCountThread; + /** + */ + TEST_F(isRunning, isRunning_001) + { + OCountThread *aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; - CPPUNIT_ASSERT_MESSAGE( - "Test isRunning", - bRun == sal_True && bTer == sal_False - ); - } - /** check the value of isRunning when suspending and after resume - */ - void isRunning_002() - { - OCountThread *aCountThread = new OCountThread(); - sal_Bool bRes = aCountThread->create(); - CPPUNIT_ASSERT_MESSAGE ( "Can't start thread!", bRes == sal_True ); - - // sal_Bool bRunning = aCountThread->isRunning(); - // sal_Int32 nValue = 0; - suspendCountThread(aCountThread); - - sal_Bool bRunning_sup = aCountThread->isRunning(); - ThreadHelper::thread_sleep_tenth_sec(2); - aCountThread->resume(); - ThreadHelper::thread_sleep_tenth_sec(2); - sal_Bool bRunning_res = aCountThread->isRunning(); - termAndJoinThread(aCountThread); - sal_Bool bRunning_ter = aCountThread->isRunning(); - delete aCountThread; - - CPPUNIT_ASSERT_MESSAGE( - "Test isRunning", - bRes == sal_True && - bRunning_sup == sal_True && - bRunning_res == sal_True && - bRunning_ter == sal_False - ); + sal_Bool bRun = aCountThread->isRunning(); - } + ThreadHelper::thread_sleep_tenth_sec(2); + termAndJoinThread(aCountThread); + sal_Bool bTer = aCountThread->isRunning(); + delete aCountThread; - CPPUNIT_TEST_SUITE(isRunning); - CPPUNIT_TEST(isRunning_001); - CPPUNIT_TEST(isRunning_002); - CPPUNIT_TEST_SUITE_END(); - }; // class isRunning + ASSERT_TRUE(bRun == sal_True && bTer == sal_False) << "Test isRunning"; + } + /** check the value of isRunning when suspending and after resume + */ + TEST_F(isRunning, isRunning_002) + { + OCountThread *aCountThread = new OCountThread(); + sal_Bool bRes = aCountThread->create(); + ASSERT_TRUE(bRes == sal_True) << "Can't start thread!"; + + // sal_Bool bRunning = aCountThread->isRunning(); + // sal_Int32 nValue = 0; + suspendCountThread(aCountThread); + + sal_Bool bRunning_sup = aCountThread->isRunning(); + ThreadHelper::thread_sleep_tenth_sec(2); + aCountThread->resume(); + ThreadHelper::thread_sleep_tenth_sec(2); + sal_Bool bRunning_res = aCountThread->isRunning(); + termAndJoinThread(aCountThread); + sal_Bool bRunning_ter = aCountThread->isRunning(); + delete aCountThread; + + ASSERT_TRUE(bRes == sal_True && + bRunning_sup == sal_True && + bRunning_res == sal_True && + bRunning_ter == sal_False) << "Test isRunning"; + } /// check osl::Thread::setPriority - class setPriority : public CppUnit::TestFixture + class setPriority : public ::testing::Test { public: // initialise your test code values here. - void setUp() + void SetUp() { } - void tearDown() + void TearDown() { } @@ -1179,10 +1105,10 @@ namespace osl_Thread nValueNormal2 = p2Thread->getValue(); rtl::OString sPrio = getPrioName(_aPriority); - t_print("After 10 tenth seconds\n"); + printf("After 10 tenth seconds\n"); - t_print("nValue in %s Prio Thread is %d\n",sPrio.getStr(), nValueNormal); - t_print("nValue in %s Prio Thread is %d\n", sPrio.getStr(), nValueNormal2); + printf("nValue in %s Prio Thread is %d\n",sPrio.getStr(), nValueNormal); + printf("nValue in %s Prio Thread is %d\n", sPrio.getStr(), nValueNormal2); // ThreadHelper::thread_sleep_tenth_sec(1); pThread->join(); @@ -1193,618 +1119,556 @@ namespace osl_Thread sal_Int32 nDelta = abs(nValueNormal - nValueNormal2); double nQuotient = std::max(nValueNormal, nValueNormal2); - CPPUNIT_ASSERT_MESSAGE( - "Quotient is zero, which means, there exist no right values.", - nQuotient != 0 - ); + ASSERT_TRUE(nQuotient != 0) << "Quotient is zero, which means, there exist no right values."; double nDeltaPercent = nDelta / nQuotient * 100; - t_print("Delta value %d, percent %f\n",nDelta, nDeltaPercent); + printf("Delta value %d, percent %f\n",nDelta, nDeltaPercent); // LLA: it's not a bug if the current OS is not able to handle thread scheduling right and good. // like Windows XP - // LLA: CPPUNIT_ASSERT_MESSAGE( - // LLA: "Run 2 normal threads, the count diff more than 5 percent.", - // LLA: nDeltaPercent <= 5 - // LLA: ); - } - - void setPriority_001_1() - { - check2Threads(osl_Thread_PriorityHighest); - } - void setPriority_001_2() - { - check2Threads(osl_Thread_PriorityAboveNormal); + // LLA: ASSERT_TRUE(// LLA: nDeltaPercent <= 5 + // LLA:) << // LLA: "Run 2 normal threads, the count diff more than 5 percent."; } - void setPriority_001_3() - { - check2Threads(osl_Thread_PriorityNormal); - } - void setPriority_001_4() - { - check2Threads(osl_Thread_PriorityBelowNormal); - } - void setPriority_001_5() - { - check2Threads(osl_Thread_PriorityLowest); - } - - void setPriority_002() - { - // initial 5 threads with different priorities - - OAddThread aHighestThread; - OAddThread aAboveNormalThread; - OAddThread aNormalThread; - //OAddThread *aBelowNormalThread = new OAddThread(); - //OAddThread *aLowestThread = new OAddThread(); - - //Create them and start running at the same time - aHighestThread.createSuspended(); - aHighestThread.setPriority(osl_Thread_PriorityHighest); - - aAboveNormalThread.createSuspended(); - aAboveNormalThread.setPriority(osl_Thread_PriorityAboveNormal); - - aNormalThread.createSuspended(); - aNormalThread.setPriority(osl_Thread_PriorityNormal); - /*aBelowNormalThread->create(); - aBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); - aLowestThread->create(); - aLowestThread->setPriority(osl_Thread_PriorityLowest); - */ - - aHighestThread.resume(); - aAboveNormalThread.resume(); - aNormalThread.resume(); - - ThreadHelper::thread_sleep_tenth_sec(5); - - aHighestThread.suspend(); - aAboveNormalThread.suspend(); - aNormalThread.suspend(); - - termAndJoinThread(&aNormalThread); - termAndJoinThread(&aAboveNormalThread); - termAndJoinThread(&aHighestThread); - //aBelowNormalThread->terminate(); - //aLowestThread->terminate(); - - sal_Int32 nValueHighest = 0; - nValueHighest = aHighestThread.getValue(); + }; // class setPriority - sal_Int32 nValueAboveNormal = 0; - nValueAboveNormal = aAboveNormalThread.getValue(); + TEST_F(setPriority, setPriority_001_1) + { + check2Threads(osl_Thread_PriorityHighest); + } + TEST_F(setPriority, setPriority_001_2) + { + check2Threads(osl_Thread_PriorityAboveNormal); + } + TEST_F(setPriority, setPriority_001_3) + { + check2Threads(osl_Thread_PriorityNormal); + } + TEST_F(setPriority, setPriority_001_4) + { + check2Threads(osl_Thread_PriorityBelowNormal); + } + TEST_F(setPriority, setPriority_001_5) + { + check2Threads(osl_Thread_PriorityLowest); + } - sal_Int32 nValueNormal = 0; - nValueNormal = aNormalThread.getValue(); - - // sal_Int32 nValueBelowNormal = 0; - //nValueBelowNormal = aBelowNormalThread->getValue(); - // sal_Int32 nValueLowest = 0; - //nValueLowest = aLowestThread->getValue(); - t_print("After 10 tenth seconds\n"); - t_print("nValue in Highest Prio Thread is %d\n",nValueHighest); - t_print("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); - t_print("nValue in Normal Prio Thread is %d\n",nValueNormal); - - // LLA: this is not a save test, so we only check if all values not zero - // LLA: CPPUNIT_ASSERT_MESSAGE( - // LLA: "SetPriority", - // LLA: nValueHighest >= nValueAboveNormal && - // LLA: nValueAboveNormal >= nValueNormal && - // LLA: nValueNormal > 0 - // LLA: ); +#ifndef SOLARIS + TEST_F(setPriority, setPriority_002) + { + // initial 5 threads with different priorities + + OAddThread aHighestThread; + OAddThread aAboveNormalThread; + OAddThread aNormalThread; + //OAddThread *aBelowNormalThread = new OAddThread(); + //OAddThread *aLowestThread = new OAddThread(); + + //Create them and start running at the same time + aHighestThread.createSuspended(); + aHighestThread.setPriority(osl_Thread_PriorityHighest); + + aAboveNormalThread.createSuspended(); + aAboveNormalThread.setPriority(osl_Thread_PriorityAboveNormal); + + aNormalThread.createSuspended(); + aNormalThread.setPriority(osl_Thread_PriorityNormal); + /*aBelowNormalThread->create(); + aBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); + aLowestThread->create(); + aLowestThread->setPriority(osl_Thread_PriorityLowest); + */ + + aHighestThread.resume(); + aAboveNormalThread.resume(); + aNormalThread.resume(); + + ThreadHelper::thread_sleep_tenth_sec(5); + + aHighestThread.suspend(); + aAboveNormalThread.suspend(); + aNormalThread.suspend(); + + termAndJoinThread(&aNormalThread); + termAndJoinThread(&aAboveNormalThread); + termAndJoinThread(&aHighestThread); + //aBelowNormalThread->terminate(); + //aLowestThread->terminate(); + + sal_Int32 nValueHighest = 0; + nValueHighest = aHighestThread.getValue(); + + sal_Int32 nValueAboveNormal = 0; + nValueAboveNormal = aAboveNormalThread.getValue(); + + sal_Int32 nValueNormal = 0; + nValueNormal = aNormalThread.getValue(); + + // sal_Int32 nValueBelowNormal = 0; + //nValueBelowNormal = aBelowNormalThread->getValue(); + // sal_Int32 nValueLowest = 0; + //nValueLowest = aLowestThread->getValue(); + printf("After 10 tenth seconds\n"); + printf("nValue in Highest Prio Thread is %d\n",nValueHighest); + printf("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); + printf("nValue in Normal Prio Thread is %d\n",nValueNormal); + + // LLA: this is not a save test, so we only check if all values not zero + // LLA: ASSERT_TRUE(// LLA: nValueHighest >= nValueAboveNormal && + // LLA: nValueAboveNormal >= nValueNormal && + // LLA: nValueNormal > 0 + // LLA:) << // LLA: "SetPriority"; // LLA: windows let starve threads with lower priority #ifndef WNT - CPPUNIT_ASSERT_MESSAGE( - "SetPriority", - nValueHighest > 0 && - nValueAboveNormal > 0 && - nValueNormal > 0 - ); + ASSERT_TRUE(nValueHighest > 0 && + nValueAboveNormal > 0 && + nValueNormal > 0) << "SetPriority"; #endif - } - - void setPriority_003() - { - // initial 5 threads with different priorities - OAddThread *pHighestThread = new OAddThread(); - OAddThread *pAboveNormalThread = new OAddThread(); - OAddThread *pNormalThread = new OAddThread(); - OAddThread *pBelowNormalThread = new OAddThread(); - OAddThread *pLowestThread = new OAddThread(); - - //Create them and start running at the same time - pHighestThread->createSuspended(); - pHighestThread->setPriority(osl_Thread_PriorityHighest); - - pAboveNormalThread->createSuspended(); - pAboveNormalThread->setPriority(osl_Thread_PriorityAboveNormal); - - pNormalThread->createSuspended(); - pNormalThread->setPriority(osl_Thread_PriorityNormal); - - pBelowNormalThread->createSuspended(); - pBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); - - pLowestThread->createSuspended(); - pLowestThread->setPriority(osl_Thread_PriorityLowest); - - pHighestThread->resume(); - pAboveNormalThread->resume(); - pNormalThread->resume(); - pBelowNormalThread->resume(); - pLowestThread->resume(); - - ThreadHelper::thread_sleep_tenth_sec(5); - - pHighestThread->suspend(); - pAboveNormalThread->suspend(); - pNormalThread->suspend(); - pBelowNormalThread->suspend(); - pLowestThread->suspend(); - - termAndJoinThread(pHighestThread); - termAndJoinThread(pAboveNormalThread); - termAndJoinThread(pNormalThread); - termAndJoinThread(pBelowNormalThread); - termAndJoinThread(pLowestThread); - - sal_Int32 nValueHighest = 0; - nValueHighest = pHighestThread->getValue(); - - sal_Int32 nValueAboveNormal = 0; - nValueAboveNormal = pAboveNormalThread->getValue(); + } - sal_Int32 nValueNormal = 0; - nValueNormal = pNormalThread->getValue(); - - sal_Int32 nValueBelowNormal = 0; - nValueBelowNormal = pBelowNormalThread->getValue(); - - sal_Int32 nValueLowest = 0; - nValueLowest = pLowestThread->getValue(); - - t_print("After 10 tenth seconds\n"); - t_print("nValue in Highest Prio Thread is %d\n",nValueHighest); - t_print("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); - t_print("nValue in Normal Prio Thread is %d\n",nValueNormal); - t_print("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal); - t_print("nValue in Lowest Prio Thread is %d\n",nValueLowest); - - delete pHighestThread; - delete pAboveNormalThread; - delete pNormalThread; - delete pBelowNormalThread; - delete pLowestThread; - - // LLA: this is not a save test, so we only check if all values not zero - // LLA: CPPUNIT_ASSERT_MESSAGE( - // LLA: "SetPriority", - // LLA: nValueHighest > nValueAboveNormal && - // LLA: nValueAboveNormal > nValueNormal && - // LLA: nValueNormal > nValueBelowNormal && - // LLA: nValueBelowNormal > nValueLowest && - // LLA: nValueLowest > 0 - // LLA: ); + TEST_F(setPriority, setPriority_003) + { + // initial 5 threads with different priorities + OAddThread *pHighestThread = new OAddThread(); + OAddThread *pAboveNormalThread = new OAddThread(); + OAddThread *pNormalThread = new OAddThread(); + OAddThread *pBelowNormalThread = new OAddThread(); + OAddThread *pLowestThread = new OAddThread(); + + //Create them and start running at the same time + pHighestThread->createSuspended(); + pHighestThread->setPriority(osl_Thread_PriorityHighest); + + pAboveNormalThread->createSuspended(); + pAboveNormalThread->setPriority(osl_Thread_PriorityAboveNormal); + + pNormalThread->createSuspended(); + pNormalThread->setPriority(osl_Thread_PriorityNormal); + + pBelowNormalThread->createSuspended(); + pBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); + + pLowestThread->createSuspended(); + pLowestThread->setPriority(osl_Thread_PriorityLowest); + + pHighestThread->resume(); + pAboveNormalThread->resume(); + pNormalThread->resume(); + pBelowNormalThread->resume(); + pLowestThread->resume(); + + ThreadHelper::thread_sleep_tenth_sec(5); + + pHighestThread->suspend(); + pAboveNormalThread->suspend(); + pNormalThread->suspend(); + pBelowNormalThread->suspend(); + pLowestThread->suspend(); + + termAndJoinThread(pHighestThread); + termAndJoinThread(pAboveNormalThread); + termAndJoinThread(pNormalThread); + termAndJoinThread(pBelowNormalThread); + termAndJoinThread(pLowestThread); + + sal_Int32 nValueHighest = 0; + nValueHighest = pHighestThread->getValue(); + + sal_Int32 nValueAboveNormal = 0; + nValueAboveNormal = pAboveNormalThread->getValue(); + + sal_Int32 nValueNormal = 0; + nValueNormal = pNormalThread->getValue(); + + sal_Int32 nValueBelowNormal = 0; + nValueBelowNormal = pBelowNormalThread->getValue(); + + sal_Int32 nValueLowest = 0; + nValueLowest = pLowestThread->getValue(); + + printf("After 10 tenth seconds\n"); + printf("nValue in Highest Prio Thread is %d\n",nValueHighest); + printf("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); + printf("nValue in Normal Prio Thread is %d\n",nValueNormal); + printf("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal); + printf("nValue in Lowest Prio Thread is %d\n",nValueLowest); + + delete pHighestThread; + delete pAboveNormalThread; + delete pNormalThread; + delete pBelowNormalThread; + delete pLowestThread; + + // LLA: this is not a save test, so we only check if all values not zero + // LLA: ASSERT_TRUE(// LLA: nValueHighest > nValueAboveNormal && + // LLA: nValueAboveNormal > nValueNormal && + // LLA: nValueNormal > nValueBelowNormal && + // LLA: nValueBelowNormal > nValueLowest && + // LLA: nValueLowest > 0 + // LLA:) << // LLA: "SetPriority"; // LLA: windows let starve threads with lower priority #ifndef WNT - CPPUNIT_ASSERT_MESSAGE( - "SetPriority", - nValueHighest > 0 && - nValueAboveNormal > 0 && - nValueNormal > 0 && - nValueBelowNormal > 0 && - nValueLowest > 0 - ); + ASSERT_TRUE(nValueHighest > 0 && + nValueAboveNormal > 0 && + nValueNormal > 0 && + nValueBelowNormal > 0 && + nValueLowest > 0) << "SetPriority"; #endif - } - - void setPriority_004() - { - // initial 5 threads with different priorities - // OAddThread *pHighestThread = new OAddThread(); - OAddThread *pAboveNormalThread = new OAddThread(); - OAddThread *pNormalThread = new OAddThread(); - OAddThread *pBelowNormalThread = new OAddThread(); - OAddThread *pLowestThread = new OAddThread(); - - //Create them and start running at the same time - // pHighestThread->createSuspended(); - // pHighestThread->setPriority(osl_Thread_PriorityHighest); - - pAboveNormalThread->createSuspended(); - pAboveNormalThread->setPriority(osl_Thread_PriorityAboveNormal); - - pNormalThread->createSuspended(); - pNormalThread->setPriority(osl_Thread_PriorityNormal); - - pBelowNormalThread->createSuspended(); - pBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); - - pLowestThread->createSuspended(); - pLowestThread->setPriority(osl_Thread_PriorityLowest); - - // pHighestThread->resume(); - pAboveNormalThread->resume(); - pNormalThread->resume(); - pBelowNormalThread->resume(); - pLowestThread->resume(); - - ThreadHelper::thread_sleep_tenth_sec(5); - - // pHighestThread->suspend(); - pAboveNormalThread->suspend(); - pNormalThread->suspend(); - pBelowNormalThread->suspend(); - pLowestThread->suspend(); - - // termAndJoinThread(pHighestThread); - termAndJoinThread(pAboveNormalThread); - termAndJoinThread(pNormalThread); - termAndJoinThread(pBelowNormalThread); - termAndJoinThread(pLowestThread); - - // sal_Int32 nValueHighest = 0; - // nValueHighest = pHighestThread->getValue(); - - sal_Int32 nValueAboveNormal = 0; - nValueAboveNormal = pAboveNormalThread->getValue(); + } - sal_Int32 nValueNormal = 0; - nValueNormal = pNormalThread->getValue(); - - sal_Int32 nValueBelowNormal = 0; - nValueBelowNormal = pBelowNormalThread->getValue(); - - sal_Int32 nValueLowest = 0; - nValueLowest = pLowestThread->getValue(); - - t_print("After 5 tenth seconds\n"); - // t_print("nValue in Highest Prio Thread is %d\n",nValueHighest); - t_print("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); - t_print("nValue in Normal Prio Thread is %d\n",nValueNormal); - t_print("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal); - t_print("nValue in Lowest Prio Thread is %d\n",nValueLowest); - - // delete pHighestThread; - delete pAboveNormalThread; - delete pNormalThread; - delete pBelowNormalThread; - delete pLowestThread; - - // LLA: this is not a save test, so we only check if all values not zero - // LLA: CPPUNIT_ASSERT_MESSAGE( - // LLA: "SetPriority", - // LLA: nValueHighest > nValueAboveNormal && - // LLA: nValueAboveNormal > nValueNormal && - // LLA: nValueNormal > nValueBelowNormal && - // LLA: nValueBelowNormal > nValueLowest && - // LLA: nValueLowest > 0 - // LLA: ); + TEST_F(setPriority, setPriority_004) + { + // initial 5 threads with different priorities + // OAddThread *pHighestThread = new OAddThread(); + OAddThread *pAboveNormalThread = new OAddThread(); + OAddThread *pNormalThread = new OAddThread(); + OAddThread *pBelowNormalThread = new OAddThread(); + OAddThread *pLowestThread = new OAddThread(); + + //Create them and start running at the same time + // pHighestThread->createSuspended(); + // pHighestThread->setPriority(osl_Thread_PriorityHighest); + + pAboveNormalThread->createSuspended(); + pAboveNormalThread->setPriority(osl_Thread_PriorityAboveNormal); + + pNormalThread->createSuspended(); + pNormalThread->setPriority(osl_Thread_PriorityNormal); + + pBelowNormalThread->createSuspended(); + pBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); + + pLowestThread->createSuspended(); + pLowestThread->setPriority(osl_Thread_PriorityLowest); + + // pHighestThread->resume(); + pAboveNormalThread->resume(); + pNormalThread->resume(); + pBelowNormalThread->resume(); + pLowestThread->resume(); + + ThreadHelper::thread_sleep_tenth_sec(5); + + // pHighestThread->suspend(); + pAboveNormalThread->suspend(); + pNormalThread->suspend(); + pBelowNormalThread->suspend(); + pLowestThread->suspend(); + + // termAndJoinThread(pHighestThread); + termAndJoinThread(pAboveNormalThread); + termAndJoinThread(pNormalThread); + termAndJoinThread(pBelowNormalThread); + termAndJoinThread(pLowestThread); + + // sal_Int32 nValueHighest = 0; + // nValueHighest = pHighestThread->getValue(); + + sal_Int32 nValueAboveNormal = 0; + nValueAboveNormal = pAboveNormalThread->getValue(); + + sal_Int32 nValueNormal = 0; + nValueNormal = pNormalThread->getValue(); + + sal_Int32 nValueBelowNormal = 0; + nValueBelowNormal = pBelowNormalThread->getValue(); + + sal_Int32 nValueLowest = 0; + nValueLowest = pLowestThread->getValue(); + + printf("After 5 tenth seconds\n"); + // printf("nValue in Highest Prio Thread is %d\n",nValueHighest); + printf("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); + printf("nValue in Normal Prio Thread is %d\n",nValueNormal); + printf("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal); + printf("nValue in Lowest Prio Thread is %d\n",nValueLowest); + + // delete pHighestThread; + delete pAboveNormalThread; + delete pNormalThread; + delete pBelowNormalThread; + delete pLowestThread; + + // LLA: this is not a save test, so we only check if all values not zero + // LLA: ASSERT_TRUE(// LLA: nValueHighest > nValueAboveNormal && + // LLA: nValueAboveNormal > nValueNormal && + // LLA: nValueNormal > nValueBelowNormal && + // LLA: nValueBelowNormal > nValueLowest && + // LLA: nValueLowest > 0 + // LLA:) << // LLA: "SetPriority"; // LLA: windows let starve threads with lower priority #ifndef WNT - CPPUNIT_ASSERT_MESSAGE( - "SetPriority", - /* nValueHighest > 0 && */ - nValueAboveNormal > 0 && - nValueNormal > 0 && - nValueBelowNormal > 0 && - nValueLowest > 0 - ); + ASSERT_TRUE(/* nValueHighest > 0 && */ + nValueAboveNormal > 0 && + nValueNormal > 0 && + nValueBelowNormal > 0 && + nValueLowest > 0) << "SetPriority"; #endif - } - void setPriority_005() - { - // initial 5 threads with different priorities - // OAddThread *pHighestThread = new OAddThread(); - // OAddThread *pAboveNormalThread = new OAddThread(); - OAddThread *pNormalThread = new OAddThread(); - OAddThread *pBelowNormalThread = new OAddThread(); - OAddThread *pLowestThread = new OAddThread(); - - //Create them and start running at the same time - // pHighestThread->createSuspended(); - // pHighestThread->setPriority(osl_Thread_PriorityHighest); - - // pAboveNormalThread->createSuspended(); - // pAboveNormalThread->setPriority(osl_Thread_PriorityAboveNormal); - - pNormalThread->createSuspended(); - pNormalThread->setPriority(osl_Thread_PriorityNormal); - - pBelowNormalThread->createSuspended(); - pBelowNormalThread->setPriority(osl_Thread_PriorityBelowNormal); - - pLowestThread->createSuspended(); - pLowestThread->setPriority(osl_Thread_PriorityLowest); - - // pHighestThread->resume(); - // pAboveNormalThread->resume(); - pNormalThread->resume(); - pBelowNormalThread->resume(); - pLowestThread->resume(); - - ThreadHelper::thread_sleep_tenth_sec(5); - - // pHighestThread->suspend(); - // pAboveNormalThread->suspend(); - pNormalThread->suspend(); - pBelowNormalThread->suspend(); - pLowestThread->suspend(); - - // termAndJoinThread(pHighestThread); - // termAndJoinThread(pAboveNormalThread); - termAndJoinThread(pNormalThread); - termAndJoinThread(pBelowNormalThread); - termAndJoinThread(pLowestThread); - - // sal_Int32 nValueHighest = 0; - // nValueHighest = pHighestThread->getValue(); - - // sal_Int32 nValueAboveNormal = 0; - // nValueAboveNormal = pAboveNormalThread->getValue(); - - sal_Int32 nValueNormal = 0; - nValueNormal = pNormalThread->getValue(); - - sal_Int32 nValueBelowNormal = 0; - nValueBelowNormal = pBelowNormalThread->getValue(); - - sal_Int32 nValueLowest = 0; - nValueLowest = pLowestThread->getValue(); - - t_print("After 5 tenth seconds\n"); - // t_print("nValue in Highest Prio Thread is %d\n",nValueHighest); - // t_print("nValue in AboveNormal Prio Thread is %d\n",nValueAboveNormal); - t_print("nValue in Normal Prio Thread is %d\n",nValueNormal); - t_print("nValue in BelowNormal Prio Thread is %d\n",nValueBelowNormal); - t_print("nValue in Lowest Prio Thread is %d\n",nValueLowest); - - // delete pHighestThread; - // delete pAboveNormalThread; - delete pNormalThread; - delete pBelowNormalThread; ... etc. - the rest is truncated _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits