basegfx/CppunitTest_basegfx.mk | 1 basegfx/test/boxclipper.cxx | 4 basic/source/runtime/methods.cxx | 4 comphelper/source/misc/random.cxx | 58 connectivity/workben/testmoz/initUNO.cxx | 37 connectivity/workben/testmoz/main.cxx | 663 ---------- connectivity/workben/testmoz/makefile.mk | 61 connectivity/workben/testmoz/mozthread.cxx | 454 ------ cui/source/customize/cfg.cxx | 4 desktop/source/deployment/misc/lockfile.cxx | 8 drawinglayer/source/primitive2d/polygonprimitive2d.cxx | 16 drawinglayer/source/texture/texture.cxx | 9 include/comphelper/random.hxx | 21 include/drawinglayer/tools/converters.hxx | 2 oox/source/export/chartexport.cxx | 4 sc/Library_scopencl.mk | 1 sc/source/core/data/global.cxx | 2 sc/source/core/data/table3.cxx | 5 sc/source/core/opencl/opencl_device.cxx | 4 sc/source/core/tool/interpr1.cxx | 2 sc/source/core/tool/interpr3.cxx | 3 sc/source/ui/StatisticsDialogs/SamplingDialog.cxx | 13 scaddins/idl/com/sun/star/sheet/addin/XAnalysis.idl | 2 scaddins/source/analysis/analysis.cxx | 9 sd/source/core/CustomAnimationPreset.cxx | 7 sd/source/ui/remotecontrol/AvahiNetworkService.cxx | 5 slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx | 4 slideshow/source/inc/tools.hxx | 5 svx/source/svdraw/sdrpagewindow.cxx | 6 svx/source/svdraw/sdrpaintwindow.cxx | 32 sw/qa/core/uwriter.cxx | 16 sw/source/filter/ww8/docxattributeoutput.cxx | 9 vbahelper/source/vbahelper/vbacommandbarhelper.cxx | 4 vcl/source/window/debugevent.cxx | 3 xmloff/source/text/txtlists.cxx | 4 35 files changed, 149 insertions(+), 1333 deletions(-)
New commits: commit 17dd074b3f775326b6787c0fc77d4048e541e220 Author: Caolán McNamara <[email protected]> Date: Mon Oct 6 12:50:20 2014 +0100 drop connectivity testmoz workben Change-Id: I09b387606dee76605ad60dcf8cfb3fc68057d7be diff --git a/connectivity/workben/testmoz/initUNO.cxx b/connectivity/workben/testmoz/initUNO.cxx deleted file mode 100644 index 2cc1d35..0000000 --- a/connectivity/workben/testmoz/initUNO.cxx +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - - -#include <rtl/bootstrap.hxx> -#include <cppuhelper/bootstrap.hxx> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> - -using namespace cppu; -using namespace com::sun::star::lang; -using namespace com::sun::star; -using namespace com::sun::star::uno; - -Reference< XMultiServiceFactory > InitializeFac( void ) -{ - Reference<XComponentContext> xComponentContext = ::cppu::defaultBootstrap_InitialComponentContext(); - Reference<XMultiServiceFactory> xMS(xComponentContext->getServiceManager(), UNO_QUERY); - return xMS; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/workben/testmoz/main.cxx b/connectivity/workben/testmoz/main.cxx deleted file mode 100644 index 0b49ea3..0000000 --- a/connectivity/workben/testmoz/main.cxx +++ /dev/null @@ -1,663 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <connectivity/sqlparse.hxx> -#include <connectivity/sqliterator.hxx> -#include <com/sun/star/sdbcx/XTablesSupplier.hpp> -#include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> -#include <com/sun/star/sdbc/XResultSet.hpp> -#include <com/sun/star/sdbc/XResultSetMetaData.hpp> -#include <com/sun/star/sdbc/XRow.hpp> -#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/beans/PropertyState.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <cppuhelper/servicefactory.hxx> -#include <com/sun/star/sdbc/XConnection.hpp> -#include <com/sun/star/sdbc/XDriver.hpp> -#include <com/sun/star/sdbc/XDriverAccess.hpp> -#include <com/sun/star/sdbcx/XRowLocate.hpp> -#include <com/sun/star/sdbc/XRowUpdate.hpp> -#include <com/sun/star/sdbc/XResultSetUpdate.hpp> -#include <com/sun/star/sdbcx/XDeleteRows.hpp> -#include <com/sun/star/sdbc/XCloseable.hpp> -#include <com/sun/star/sdb/XDatabaseEnvironment.hpp> -#include <com/sun/star/uno/Any.hxx> - -#include <connectivity/sqlnode.hxx> -#include <rtl/ustring.hxx> -#include <rtl/ustrbuf.hxx> -#include <osl/process.h> - -#include <cppuhelper/bootstrap.hxx> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/registry/XImplementationRegistration.hpp> -#include <com/sun/star/ucb/XUniversalContentBroker.hpp> - -#include <osl/module.h> - -#include <stdio.h> - -using namespace comphelper; -using namespace cppu; -using namespace com::sun::star::uno; -using namespace com::sun::star::lang; -using namespace com::sun::star::registry; -using namespace com::sun::star::ucb; -using namespace com::sun::star::beans; - -using namespace connectivity; -using namespace com::sun::star::sdb; -using namespace com::sun::star::sdbc; -using namespace com::sun::star::sdbcx; -using namespace ::com::sun::star::container; - - -#define OUtoCStr( x ) (OUStringToOString ( (x), RTL_TEXTENCODING_ASCII_US ).getStr()) -#define PRINTSTR(x) printf("%s",x); - -int autoTest(Reference<XResultSet> &xRes); - -void printColumns( Reference<XResultSet> &xRes ) -{ - if(xRes.is()) { - char* aPat = " %-22s "; - Reference<XResultSetMetaData> xMeta = Reference<XResultSetMetaDataSupplier>(xRes,UNO_QUERY)->getMetaData(); - printf( "ColumnCount = %d\n", xMeta->getColumnCount()); - for(sal_Int32 i=1;i<=xMeta->getColumnCount();++i) - { - printf( aPat, OUtoCStr(xMeta->getColumnName(i) ); - } - printf("\n"); - printf("------------------------------------------------------------------------------------------\n"); - } else { - printf(": FAILED to get a ResultSet \n"); - } -} -void printXResultSet( Reference<XResultSet> &xRes ) -{ - if(xRes.is()) { - char* aPat_Short = " %-12s "; - Reference<XRow> xRow(xRes,UNO_QUERY); - Reference<XResultSetMetaData> xMeta = Reference<XResultSetMetaDataSupplier>(xRes,UNO_QUERY)->getMetaData(); - for(sal_Int32 j=1;j<=xMeta->getColumnCount();++j) - { - try { - printf( aPat_Short, OUtoCStr(xRow->getString(j)) ); - } catch (...) { - printf(" Ex "); - } - } - printf("\n"); - } else { - printf(": FAILED to get a ResultSet \n"); - } -} - -void printXResultSets( Reference<XResultSet> &xRes ) -{ - if(xRes.is()) { - printColumns(xRes); - sal_Int32 nRows = 0; - while( xRes.is() && xRes->next()) - { - printXResultSet(xRes); - nRows++; - } - printf( "%d Row(s)\n", nRows); - } else { - printf(": FAILED to get a ResultSet \n"); - } -} - -static const char * const components[] = -{ - SAL_MODULENAME( "ucb1" ) // KSO, ABI - , SAL_MODULENAME( "ucpfile1" ) - , SAL_MODULENAME( "cfgmgr2" ) - , "sax.uno" SAL_DLLEXTENSION - , "stocservices.uno" SAL_DLLEXTENSION - , SAL_MODULENAME( "fileacc" ) - , SAL_MODULENAME( "mcnttype" ) //Clipboard Ask Oliver Braun - , "i18npool.uno" SAL_DLLEXTENSION - // Reading of files in specific encodings like UTF-8 using - // createUnoService( "com.sun.star.io.TextInputStream" ) and such - , "textinstream.uno" SAL_DLLEXTENSION - , "textoutstream.uno" SAL_DLLEXTENSION - , "introspection.uno" SAL_DLLEXTENSION - , "corereflection.uno" SAL_DLLEXTENSION - // RemoteUno - , "connector.uno" SAL_DLLEXTENSION - , "bridgefac.uno" SAL_DLLEXTENSION - , "remotebridge.uno" SAL_DLLEXTENSION - , "dbtools2" SAL_DLLEXTENSION - , "mozab2" SAL_DLLEXTENSION - , "mozabdrv2" SAL_DLLEXTENSION - , "sdbc2" SAL_DLLEXTENSION - , "dbpool2" SAL_DLLEXTENSION -#ifdef SAL_UNX - , SVLIBRARY( "dtransX11" ) // OBR -#endif -#ifdef SAL_W32 - , SAL_MODULENAME( "sysdtrans" ) - , SAL_MODULENAME( "ftransl" ) - , SAL_MODULENAME( "dnd" ) -#endif - , 0 -}; - -Reference< XMultiServiceFactory > InitializeFac( void ) -{ - OUString path; - if( osl_Process_E_None != osl_getExecutableFile( (rtl_uString**)&path ) ) - { - printf("Exit.\n"); - exit( 1 ); - } - OSL_ASSERT( path.lastIndexOf( '/' ) >= 0 ); - - - OUStringBuffer bufServices( path.copy( 0, path.lastIndexOf( '/' )+1 ) ); - bufServices.appendAscii("services.rdb"); - OUString services = bufServices.makeStringAndClear(); - - OUStringBuffer bufTypes( path.copy( 0, path.lastIndexOf( '/' )+1 ) ); - bufTypes.appendAscii("types.rdb"); - OUString types = bufTypes.makeStringAndClear(); - - printf("Create Registry.\n"); - - Reference< XMultiServiceFactory > xSMgr; - try - { - xSMgr = createRegistryServiceFactory( types, services, sal_True ); - } - catch( com::sun::star::uno::Exception & ) - { - try - { - { - Reference< XMultiServiceFactory > interimSmgr = - createRegistryServiceFactory( types, sal_True ); - Reference< XImplementationRegistration > xIR( - interimSmgr->createInstance( - OUString::( - "com.sun.star.registry.ImplementationRegistration" ) ), UNO_QUERY ); - - Reference< XSimpleRegistry > xReg( - interimSmgr->createInstance( - OUString::( - "com.sun.star.registry.SimpleRegistry" ) ), UNO_QUERY ); - if ( xReg.is() ) - { - xReg->open(services, sal_False, sal_True); - if ( xReg->isValid() ) - { - OUString loader( "com.sun.star.loader.SharedLibrary" ); - for( sal_Int32 i = 0; components[i] ; i ++ ) - { - printf("Registering %s ... ", components[i]); - xIR->registerImplementation( - loader, OUString::createFromAscii(components[i]),xReg); - printf("done\n"); - } - xReg->close(); - } else - { - printf("Cannot open Registry. Terminating Program\n"); - exit (1); - } - } - - Reference< XComponent > xComp( interimSmgr, UNO_QUERY ); - if( xComp.is() ) - xComp->dispose(); - } - - // now try it again readonly - printf("Opening Registry readonly\n"); - xSMgr = createRegistryServiceFactory( types, services, sal_True ); - } - catch( com::sun::star::uno::Exception & exc ) - { - fprintf( stderr, "Couldn't bootstrap uno servicemanager for reason : %s\n" , - OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ).getStr() ); - } - } - - printf("set global factory.\n"); - - - // set global factory - setProcessServiceFactory( xSMgr ); - - -// Create unconfigured Ucb: - Reference< XUniversalContentBroker > xUcb - ( xSMgr->createInstance("com.sun.star.ucb.UniversalContentBroker"), UNO_QUERY_THROW ); - - Reference< XContentProvider > xFileProvider - ( xSMgr->createInstance("com.sun.star.ucb.FileContentProvider"), UNO_QUERY_THROW ); - xUcb->registerContentProvider( xFileProvider, OUString("file"), sal_True ); - - return xSMgr; -} - -int TestMetaData(Reference< ::com::sun::star::sdbc::XConnection> &pConnection) -{ - // Test some metadata - Reference< XDatabaseMetaData > xDmd = pConnection->getMetaData(); - if ( xDmd.is() ) { - printf(": got DatabaseMetaData \n"); - - OUString sQuoteStr = xDmd->getIdentifierQuoteString(); - printf( "Quote String : '%s'\n", OUtoCStr( sQuoteStr ) ); - - OUString sSQLCmds = xDmd->getSQLKeywords(); - printf( "SQL Commands : '%s'\n", OUtoCStr( sSQLCmds ) ); - - printf("Testing getColumns() : START\n"); - { - Reference<XResultSet> xRes = xDmd->getColumns( - makeAny(OUString("")), // Catalog - OUString("%"), // Schema - OUString("%"), // TabName - OUString("%") - ); - printXResultSets( xRes ); - } - printf("Testing getColumns() : END\n"); - - printf("Testing getTypeInfo() : START\n"); - { - Reference<XResultSet> xRes = xDmd-> getTypeInfo(); - printXResultSets( xRes ); - } - printf("Testing getTypeInfo() : END\n"); - - printf("Testing getTables() : START\n"); - { - Reference<XResultSet> xRes = xDmd->getTables( - makeAny(OUString("")), // Catalog - OUString("%"), // Schema - OUString("%"), // TabName - Sequence<OUString>() - ); - printXResultSets( xRes ); - } - printf("Testing getTables() : END\n"); - - } else { - printf(": FAILED to get DatabaseMetaData \n"); - } - - return 0; -} -int TestBookMark(Reference<XResultSet> &xRes); -int TestRowUpdate(Reference<XResultSet> &xRes); - -Reference<XResultSet> TestQuery(Reference< ::com::sun::star::sdbc::XConnection> &pConnection,sal_Int32 choice) -{ - // Try a query - printf("Testing createStatement() & executeQuery() : START\n"); - Reference<XStatement> xStmt = pConnection->createStatement(); - Reference<XResultSet> xRes; - if(xStmt.is()) - { - printf(": got statement\n"); - printf(": excuteQuery() : START \n"); -// SELECT "First Name", "Display Name", "E-mail" FROM "addr" "addr" - char sql[256]="SELECT \"First Name\", \"Display Name\", \"E-mail\" FROM \"addr\""; - if (choice!=-1) - { - printf("Please input a query,end by \";\" and less then 256 char plz:\n"); - char ch=0; - int index=0; - while (ch != ';') - { - scanf("%c",&ch); - sql[index++] = ch; - } - sql[index]= 0; - printf("SQL:%s\n",sql); - } - try - { - sal_Int32 times=0; - for (times = 0;times< 100;times ++) - { - Reference<XResultSet> tmpRes = - xStmt->executeQuery(OUString::createFromAscii(sql)); - - autoTest( tmpRes ); - Reference<XCloseable> clsRes(tmpRes,UNO_QUERY); - clsRes->close(); - printf("Current Times:%d\n",times); - } - TestBookMark(xRes); - TestRowUpdate(xRes); - } catch ( Exception &e ) { - printf( "Exception caught : %s\n", OUtoCStr( e.Message) ); - } catch (...) { - printf( "Non-UNO Exception caught\n" ); - } - printf(": excuteQuery() : END \n"); - } - else - { - printf(": FAILED to get statement\n"); - } - printf("Testing createStatement() & executeQuery() : END\n"); - return xRes; -} -Reference< ::com::sun::star::sdbc::XConnection> TestConnected - (Reference< ::com::sun::star::sdbc::XDriver> &pDriver,sal_Int32 choice) -{ - ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> pConnection; - printf("Begin Connect!\n"); - OUString url; - Sequence<PropertyValue> aValue; - - switch (choice) - { - case -1: - case 1: //mozilla - url = "sdbc:address:mozilla://"; - break; - case 2: - url = "sdbc:address:ldap://"; - char hostname[40],basedn[40]; - scanf("%s %s",hostname,basedn); - aValue.realloc(2); - aValue[0].Name = "HostName"; - aValue[0].Value <<= OUString::createFromAscii(hostname); - aValue[1].Name = "BaseDN"; - aValue[1].Value <<= OUString::createFromAscii(basedn); - break; - case 3: - case 4: - break; - case 5: - //Default LDAP AB - url = "sdbc:address:ldap://"; - aValue.realloc(2); - aValue[0].Name = "HostName"; - aValue[0].Value <<= OUString("sun-ds"); - aValue[1].Name = "BaseDN"; - aValue[1].Value <<= OUString("dc=sun,dc=com"); - break; - default: - return pConnection; - } - pConnection = - pDriver->connect(url,aValue); - return pConnection; - } - -void menuBookmark() -{ - PRINTSTR("0 Exit\n") - PRINTSTR("1 Show Max rowcount\n") - PRINTSTR("2 Move First\n") - PRINTSTR("3 Record bookmark 1\n") - PRINTSTR("4 Record bookmark 2\n") - PRINTSTR("5 Move to bookmark. Usage: 5 bookid\n") - PRINTSTR("6 moveRelativeToBookmark, follow bookid rows plz\n") - PRINTSTR("7 compareBookmark\n") - PRINTSTR("8 print boomark hash. Usage: 8 bookid\n") - PRINTSTR("9 print current row\n") - PRINTSTR("10 Auto test\n") - - PRINTSTR("Please Input you choice:") -} -int autoTest(Reference<XResultSet> &xRes) -{ - printColumns(xRes); - if(xRes.is()) - { - sal_Int32 nRows = 0; - while( xRes.is() && xRes->next()) - { - nRows++; - } - printf( "%d Row(s)\n", nRows); - sal_Int32 times; - sal_Int32 pos; - for(times = 1;times < 100; times ++) - { - pos= rand() % nRows+1; - printf("pos:%d\n",pos); - xRes->absolute(pos); - printXResultSet(xRes); - } - } else { - printf(": FAILED to get a ResultSet \n"); - } - return 0; -} -int TestBookMark(Reference<XResultSet> &xRes) -{ - Reference<XResultSet> mRes(xRes); - if (!mRes.is() || !mRes->first()) - { - return sal_False; - } - - Reference<XRow> mRow(xRes,UNO_QUERY); - Reference<XResultSetMetaData> xMeta = Reference<XResultSetMetaDataSupplier>(mRes,UNO_QUERY)->getMetaData(); - printXResultSet(mRes); - Reference< ::com::sun::star::sdbcx::XRowLocate> xRowLocate(xRes, UNO_QUERY); - ::com::sun::star::uno::Any xBookMark[2]; - int index; - if (xRowLocate.is()) - { - int choice=-1; - while (choice) - { - menuBookmark(); - - scanf("%d",&choice); - printf("Your choice is:%d\n",choice); - switch (choice) - { - case 1: - printf("Rowcount:Current don't know\n"); - break; - case 2: - if (!mRes->isFirst()) mRes->first(); - break; - case 3: - xBookMark[0] = xRowLocate->getBookmark(); - break; - case 4: - xBookMark[1] = xRowLocate->getBookmark(); - break; - case 5: - scanf("%d",&index); - if (index == 1 || index == 2) - xRowLocate->moveToBookmark(xBookMark[index-1]); - break; - case 6: - int rows; - scanf("%d %d",&index,&rows); - if (index == 1 || index == 2) - xRowLocate->moveRelativeToBookmark(xBookMark[index-1],rows); - break; - case 7: - printf("compareBookmarks:%d\n",xRowLocate->compareBookmarks(xBookMark[0],xBookMark[1])); - break; - case 8: - scanf("%d",&index); - printf("HashBookmark[%d]:%d\n",index,xRowLocate->hashBookmark(xBookMark[index-1])); - break; - case 9: - printXResultSet(mRes); - break; - case 10: - autoTest(mRes); - break; - default: - break; - } - } - } - return 0; -} -void menuRowUpdate() -{ - PRINTSTR("0 Exit\n") - PRINTSTR("1 Print Columns\n") - PRINTSTR("2 Move to row. Usage:2 rowid\n") - PRINTSTR("3 Print Row values\n") - PRINTSTR("4 Change Column Value: 4 columnid newvalue\n") - PRINTSTR("5 Commit changes\n") - PRINTSTR("6 Delete Current Row\n") - PRINTSTR("Please Input Your choice:") -} -int TestRowUpdate(Reference<XResultSet> &xRes) -{ - if (!xRes.is() || !xRes->first()) - { - return sal_False; - } - printf("Test XRowUpdate START\n"); - Reference< ::com::sun::star::sdbc::XRowUpdate> xRowUpdate(xRes, UNO_QUERY); - Reference< ::com::sun::star::sdbc::XResultSetUpdate> xResultSetUpdate(xRes, UNO_QUERY); - int index; - if (xRowUpdate.is()) - { - int choice=-1; - char newString[256]; - while (choice) - { - menuRowUpdate(); - - scanf("%d",&choice); - printf("Your choice is:%d\n",choice); - switch (choice) - { - case 1: - printColumns(xRes); - break; - case 2: - scanf("%d",&index); - xRes->absolute(index); - break; - case 3: - printXResultSet(xRes); - break; - case 4: - scanf("%d %s",&index,newString); - xRowUpdate->updateString(index,OUString::createFromAscii(newString)); - printXResultSet(xRes); - break; - case 5: - if (xResultSetUpdate.is()) - { - xResultSetUpdate->updateRow(); - printXResultSet(xRes); - } - else - printf("Can't update!\n"); - break; - case 6: - if (xResultSetUpdate.is()) - { - xResultSetUpdate->deleteRow(); - printXResultSet(xRes); - } - else - printf("Can't update!\n"); - break; - - default: - break; - } - } - } - printf("Test XRowUpdate END\n"); - return 0; -} - -void menuMain() -{ - PRINTSTR("0 Exit\n") - PRINTSTR("1 Open Mozilla Address Book\n") - PRINTSTR("2 Open LDAP. Pleae follow hostname and base dn.\n") - PRINTSTR("3 Open Outlook Address Book\n") - PRINTSTR("4 Open OE Address Book\n") - PRINTSTR("Please Input your choice:") -} - -int main( int argc, char * argv[] ) -{ - Reference< XMultiServiceFactory > xMgr = InitializeFac(); - ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> m_xConnection; - try - { - Reference< ::com::sun::star::sdbc::XDriver> - m_xDriver(xMgr->createInstance( - OUString("com.sun.star.comp.sdbc.MozabDriver")), - UNO_QUERY); - if(m_xDriver.is()) - { - int choice=-1; - if (argc > 1 ) - { - menuMain(); - scanf("%d",&choice); - } - - while (choice) - { - - m_xConnection = TestConnected(m_xDriver,choice); - if(m_xConnection.is()) - { - if (!TestMetaData(m_xConnection)) - { - Reference<XResultSet> xRes=TestQuery(m_xConnection,choice); - if (xRes.is()) - { - } - } - }else printf("Can't connected!\n"); - - if (argc > 1) - { - menuMain(); - scanf("%d",&choice); - } - else - choice = 0; - - } - } else { - printf("No driver!\n"); - } - } - catch(...) - { - printf("Exception thrown!\n"); - } - printf("Exiting...\n"); - return 0; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/workben/testmoz/makefile.mk b/connectivity/workben/testmoz/makefile.mk deleted file mode 100644 index 6011129..0000000 --- a/connectivity/workben/testmoz/makefile.mk +++ /dev/null @@ -1,61 +0,0 @@ -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This file incorporates work covered by the following license notice: -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed -# with this work for additional information regarding copyright -# ownership. The ASF licenses this file to you under the Apache -# License, Version 2.0 (the "License"); you may not use this file -# except in compliance with the License. You may obtain a copy of -# the License at http://www.apache.org/licenses/LICENSE-2.0 . -# - -PRJ=..$/.. - -PRJNAME=connectivity -TARGET=testmoz -TARGETTYPE=CUI -LIBTARGET=NO -ENABLE_EXCEPTIONS=TRUE - -# --- Settings ----------------------------------------------------- - -.INCLUDE : settings.mk - -# --- Files -------------------------------------------------------- -OBJFILES= $(OBJ)$/main.obj - - -APPSTDLIBS=$(SALLIB) \ - \ - $(CPPULIB) \ - $(CPPUHELPERLIB) \ - $(UCBHELPERLIB) \ - $(DBTOOLSLIB) \ - $(COMPHELPERLIB) - - -# ... cfgapi .............................. - -APP1TARGET= $(TARGET) -APP1OBJS= $(OBJFILES) -APP1STDLIBS = $(APPSTDLIBS) - - - -APP2TARGET = mozThread -APP2OBJS = $(OBJ)$/initUNO.obj \ - $(OBJ)$/mozthread.obj - -APP2STDLIBS = $(APPSTDLIBS) - -# --- Targets ------------------------------------------------------ - -.INCLUDE : target.mk - diff --git a/connectivity/workben/testmoz/mozthread.cxx b/connectivity/workben/testmoz/mozthread.cxx deleted file mode 100644 index 527d2f3..0000000 --- a/connectivity/workben/testmoz/mozthread.cxx +++ /dev/null @@ -1,454 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <connectivity/sqlparse.hxx> -#include <connectivity/sqliterator.hxx> -#include <com/sun/star/sdbcx/XTablesSupplier.hpp> -#include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> -#include <com/sun/star/sdbc/XResultSet.hpp> -#include <com/sun/star/sdbc/XResultSetMetaData.hpp> -#include <com/sun/star/sdbc/XRow.hpp> -#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/beans/PropertyState.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <cppuhelper/servicefactory.hxx> -#include <com/sun/star/sdbc/XConnection.hpp> -#include <com/sun/star/sdbc/XDriver.hpp> -#include <com/sun/star/sdbc/XDriverAccess.hpp> -#include <com/sun/star/sdbcx/XRowLocate.hpp> -#include <com/sun/star/sdbc/XRowUpdate.hpp> -#include <com/sun/star/sdbc/XResultSetUpdate.hpp> -#include <com/sun/star/sdbcx/XDeleteRows.hpp> -#include <com/sun/star/sdbc/XCloseable.hpp> -#include <com/sun/star/sdb/XDatabaseEnvironment.hpp> -#include <com/sun/star/uno/Any.hxx> - -#include <connectivity/sqlnode.hxx> -#include <rtl/ustring.hxx> -#include <rtl/ustrbuf.hxx> -#include <osl/process.h> - -#include <cppuhelper/bootstrap.hxx> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/registry/XImplementationRegistration.hpp> -#include <com/sun/star/ucb/XContentProviderManager.hpp> - -#include <ucbhelper/content.hxx> -#include <osl/module.h> - -#include <stdio.h> -#include <osl/thread.hxx> -#include <osl/diagnose.h> -#include <osl/conditn.hxx> -#include <time.h> - - -using namespace comphelper; -using namespace cppu; -using namespace com::sun::star::uno; -using namespace com::sun::star::lang; -using namespace com::sun::star::registry; -using namespace com::sun::star::ucb; -using namespace com::sun::star::beans; - -using namespace connectivity; -using namespace com::sun::star::sdb; -using namespace com::sun::star::sdbc; -using namespace com::sun::star::sdbcx; -using namespace ::com::sun::star::container; - - -extern Reference< XMultiServiceFactory > InitializeFac( void ); -Reference< XMultiServiceFactory > mMgr; - -#define OUtoCStr( x ) (OUStringToOString ( (x), RTL_TEXTENCODING_ASCII_US ).getStr()) -#define PRINTSTR(x) printf("%s",x); -#define PRINTLN(x) printf("%s\n",x); - -const int testLDAP=0; -const int testMozilla=1; -const int testOp=2; -const int testOe=3; - -static int testCount = 0; -static int testList[4] = {0,0,0,0}; - -int autoTest(Reference<XResultSet> &xRes); - -void printColumns( Reference<XResultSet> &xRes ) -{ - if(xRes.is()) - { - char* aPat = " %-22s "; - char* aPat_Short = " %-12s "; - Reference<XResultSetMetaData> xMeta = Reference<XResultSetMetaDataSupplier>(xRes,UNO_QUERY)->getMetaData(); - OSL_TRACE( "ColumnCount = %d", xMeta->getColumnCount()); - for(sal_Int32 i=1;i<=xMeta->getColumnCount();++i) - { - OSL_TRACE( aPat, OUtoCStr(xMeta->getColumnName(i) ); - } - OSL_TRACE("\n"); - OSL_TRACE("------------------------------------------------------------------------------------------"); - } - else - { - OSL_TRACE(": FAILED to get a ResultSet"); - } -} -void printXResultSet( Reference<XResultSet> &xRes ) -{ - if(xRes.is()) - { - char* aPat = " %-22s "; - char* aPat_Short = " %-12s "; - Reference<XRow> xRow(xRes,UNO_QUERY); - Reference<XResultSetMetaData> xMeta = Reference<XResultSetMetaDataSupplier>(xRes,UNO_QUERY)->getMetaData(); - for(sal_Int32 j=1;j<=xMeta->getColumnCount();++j) - { - try - { - OSL_TRACE( aPat_Short, OUtoCStr(xRow->getString(j) ); - } catch (...) { - OSL_TRACE(" Ex "); - } - } - OSL_TRACE("\n"); - } - else - OSL_TRACE("FAILED to get a ResultSet"); -} - -void printXResultSets( Reference<XResultSet> &xRes ) -{ - if(xRes.is()) - { - printColumns(xRes); - sal_Int32 nRows = 0; - while( xRes.is() && xRes->next()) - { - printXResultSet(xRes); - nRows++; - } - OSL_TRACE( "%d Row(s)", nRows); - }else - OSL_TRACE("FAILED to get a ResultSet"); -} - - - -int TestMetaData(Reference< ::com::sun::star::sdbc::XConnection> &pConnection) -{ - // Test some metadata - Reference< XDatabaseMetaData > xDmd = pConnection->getMetaData(); - if ( xDmd.is() ) - { - OSL_TRACE(": got DatabaseMetaData"); - - OUString sQuoteStr = xDmd->getIdentifierQuoteString(); - OSL_TRACE( "Quote String : '%s'", OUtoCStr( sQuoteStr ) ); - - OUString sSQLCmds = xDmd->getSQLKeywords(); - OSL_TRACE( "SQL Commands : '%s'", OUtoCStr( sSQLCmds ) ); - - OSL_TRACE("Testing getColumns() : START"); - { - Reference<XResultSet> xRes = xDmd->getColumns( - makeAny(OUString("")), // Catalog - OUString("%"), // Schema - OUString("%"), // TabName - OUString("%") - ); - printXResultSets( xRes ); - } - OSL_TRACE("Testing getColumns() : END"); - - OSL_TRACE("Testing getTypeInfo() : START"); - { - Reference<XResultSet> xRes = xDmd-> getTypeInfo(); - printXResultSets( xRes ); - } - OSL_TRACE("Testing getTypeInfo() : END"); - - OSL_TRACE("Testing getTables() : START"); - { - Reference<XResultSet> xRes = xDmd->getTables( - makeAny(OUString("")), // Catalog - OUString("%"), // Schema - OUString("%"), // TabName - Sequence<OUString>() ); - printXResultSets( xRes ); - } - OSL_TRACE("Testing getTables() : END"); - - } - else - OSL_TRACE(": FAILED to get DatabaseMetaData"); - return 0; -} - -void TestQuery(Reference< ::com::sun::star::sdbc::XConnection> &pConnection) -{ - // Try a query - OSL_TRACE("Testing createStatement() & executeQuery() : START"); - Reference<XStatement> xStmt = pConnection->createStatement(); - Reference<XResultSet> xRes; - if(xStmt.is()) - { - OSL_TRACE(": got statement"); - OSL_TRACE(": excuteQuery() : START \n"); -// SELECT "First Name", "Display Name", "E-mail" FROM tablename - OUString sqlPrefix("SELECT \"First Name\", \"Display Name\", \"E-mail\" FROM "); - try - { - sal_Int32 times=0; - Reference< XDatabaseMetaData > xDmd = pConnection->getMetaData(); - if ( xDmd.is() ) - { - OSL_TRACE("getTables() : START"); - OUString qut = xDmd->getIdentifierQuoteString(); - - Reference<XResultSet> xRes = xDmd->getTables( - makeAny(OUString("")), // Catalog - OUString("%"), // Schema - OUString("%"), // TabName - Sequence<OUString>() ); - sal_Int32 nTables = 0; - while( xRes.is() && xRes->next()) - { - Reference<XRow> xRow(xRes,UNO_QUERY); - OSL_TRACE("Testing Table:%s",OUtoCStr(xRow->getString(3)); - - Reference<XResultSet> tmpRes = - xStmt->executeQuery(sqlPrefix + qut + xRow->getString(3) + qut); - autoTest( tmpRes ); - Reference<XCloseable> clsRes(tmpRes,UNO_QUERY); - clsRes->close(); - nTables++; - } - OSL_TRACE("Tested Tables:%d",nTables); - } - } catch ( Exception &e ) { - OSL_TRACE( "Exception caught : %s", OUtoCStr( e.Message) ); - } -// catch (...) { -// OSL_TRACE( "Non-UNO Exception caught\n" ); -// } - OSL_TRACE("excuteQuery() : END"); - } - else - { - OSL_TRACE(": FAILED to get statement"); - } - OSL_TRACE("Testing createStatement() & executeQuery() : END"); -} -Reference< ::com::sun::star::sdbc::XConnection> TestConnected - (Reference< ::com::sun::star::sdbc::XDriver> &pDriver) -{ - ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> pConnection; - OSL_TRACE("Begin Connect!"); - OUString url; - Sequence<PropertyValue> aValue; - int nType=0; - srand( (unsigned)time( NULL ) ); - nType = rand() % testCount + 1; - int nIndex=0,nCount=0; - for ( nIndex = 0; nIndex< 4;nIndex++) - { - if (testList[nIndex]) - nCount++; - if (nCount == nType) - break; - } - switch( nIndex) - { - case testLDAP: - url = "sdbc:address:ldap://"; - aValue.realloc(2); - aValue[0].Name = "HostName"; - aValue[0].Value <<= OUString("sun-ds"); - aValue[1].Name = "BaseDN"; - aValue[1].Value <<= OUString("dc=sun,dc=com"); - break; - case testMozilla: - url = "sdbc:address:mozilla://"; - break; - case testOp: - url = "sdbc:address:outlook://"; - break; - case testOe: - url = "sdbc:address:outlookexp://"; - break; - default: - url = "sdbc:address:mozilla://"; - break; - } - pConnection = - pDriver->connect(url,aValue); - return pConnection; - } - -int autoTest(Reference<XResultSet> &xRes) -{ - sal_Int32 nRows = 0; - printColumns(xRes); - if(xRes.is()) - { - while( xRes.is() && xRes->next()) - { - nRows++; - } - OSL_TRACE( "%d Row(s)", nRows); - sal_Int32 times; - sal_Int32 pos; - if (nRows) - { - for(times = 1;times < 10; times ++) - { - pos= rand() % nRows+1; - OSL_TRACE("pos:%d",pos); - xRes->absolute(pos); - printXResultSet(xRes); - } - } - } - else - { - OSL_TRACE(": FAILED to get a ResultSet"); - } - TimeValue timeValue = { 1, 0 }; //sleep 1 Seconds to give time to other threads - osl_waitThread(&timeValue); - return 0; -} -void SAL_CALL mozThread(void*) -{ - ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> m_xConnection; - try - { - Reference< ::com::sun::star::sdbc::XDriver> - m_xDriver(mMgr->createInstance( - OUString("com.sun.star.comp.sdbc.MozabDriver")), - UNO_QUERY); - if(m_xDriver.is()) - { - - m_xConnection = TestConnected(m_xDriver); - if(m_xConnection.is()) - { - if (!TestMetaData(m_xConnection)) - { - TestQuery(m_xConnection); - } - } - else - OSL_TRACE("Can't connected!"); - - } - else - { - OSL_TRACE("No driver!"); - } - } catch ( Exception &e ) { - OSL_TRACE( "Exception caught : %s", OUtoCStr( e.Message) ); - } -// catch (...) { -// OSL_TRACE( "Non-UNO Exception caught\n" ); -// } -} -const int THREAD_COUNT=100; - - -void usage() -{ - PRINTLN("mozThread [opts] threadcount"); - PRINTLN("opts:"); - PRINTLN("-l test ldap"); - PRINTLN("-m test mozilla"); - PRINTLN("-p test outlook"); - PRINTLN("-e test outlook express"); - PRINTLN("0 < threadcount <= 100, default 100"); -} - -int main( int argc, char * argv[] ) -{ - OSL_TRACE("Init UNO"); - Reference< XMultiServiceFactory > xMgr =InitializeFac(); - int threadCount=THREAD_COUNT; - int nAc; - for (nAc = 1; nAc < argc; nAc ++) - { - if (strcmp(argv[nAc],"-l") ==0) - { - testList[testLDAP] = 1; - }else if(strcmp(argv[nAc],"-m") ==0) - { - testList[testMozilla]=1; - }else if(strcmp(argv[nAc],"-p") ==0) - { - testList[testOp]=1; - }else if(strcmp(argv[nAc],"-e") ==0) - { - testList[testOe]=1; - }else if(strcmp(argv[nAc],"-h") ==0 || strcmp(argv[nAc],"--help") ==0) - { - usage(); - return 0; - }else - { - int tmpCount = atoi(argv[nAc]); - if (tmpCount > 0 && tmpCount < threadCount) - { - threadCount = tmpCount; - } - } - } - testCount = testList[testLDAP] + testList[testMozilla] + testList[testOp] + testList[testOe]; - if ( testCount == 0) - { - testList[testLDAP] = 1; - testCount = 1; - } - - if (!xMgr.is()) - { - OSL_TRACE("Error init UNO"); - return 1; - } - else - OSL_TRACE("UNO initted"); - - mMgr = xMgr; - oslThread xThreads[THREAD_COUNT]; - int index=0; - for(index=0;index < threadCount; index++) - { - xThreads[index] = osl_createThread(mozThread,(void*)NULL); - TimeValue timeValue = { 1, 0 }; //sleep 1 Seconds to give time to other threads - osl_waitThread(&timeValue); - } - for(index=0;index < threadCount; index++) - { - if (osl_isThreadRunning(xThreads[index])) - osl_joinWithThread(xThreads[index]); - } - OSL_TRACE("Exiting..."); - return 0; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 8f436d3de7e99268a8862664d2cb2574231c3b18 Author: Caolán McNamara <[email protected]> Date: Fri Oct 3 17:12:23 2014 +0100 use comphelper::rng::uniform_*_distribution everywhere and automatically seed from time on first use coverity#1242393 Don't call rand coverity#1242404 Don't call rand coverity#1242410 Don't call rand and additionally allow 0xFF as a value coverity#1242409 Don't call rand coverity#1242399 Don't call rand coverity#1242372 Don't call rand coverity#1242377 Don't call rand coverity#1242378 Don't call rand coverity#1242379 Don't call rand coverity#1242382 Don't call rand coverity#1242383 Don't call rand coverity#1242402 Don't call rand coverity#1242397 Don't call rand coverity#1242390 Don't call rand coverity#1242389 Don't call rand coverity#1242388 Don't call rand coverity#1242386 Don't call rand coverity#1242384 Don't call rand coverity#1242394 Don't call rand Change-Id: I241feab9cb370e091fd6ccaba2af941eb95bc7cf diff --git a/basegfx/CppunitTest_basegfx.mk b/basegfx/CppunitTest_basegfx.mk index d3bb56f..8f34f3b 100644 --- a/basegfx/CppunitTest_basegfx.mk +++ b/basegfx/CppunitTest_basegfx.mk @@ -18,6 +18,7 @@ $(eval $(call gb_CppunitTest_use_api,basegfx,\ $(eval $(call gb_CppunitTest_use_libraries,basegfx,\ basegfx \ + comphelper \ cppu \ cppuhelper \ sal \ diff --git a/basegfx/test/boxclipper.cxx b/basegfx/test/boxclipper.cxx index 7ce2acf..54e5e96 100644 --- a/basegfx/test/boxclipper.cxx +++ b/basegfx/test/boxclipper.cxx @@ -33,6 +33,7 @@ #include <basegfx/polygon/b2dpolygonclipper.hxx> #include <basegfx/polygon/b2dpolypolygon.hxx> #include <basegfx/numeric/ftools.hxx> +#include <comphelper/random.hxx> #include <boost/bind.hpp> @@ -47,8 +48,7 @@ double getRandomOrdinal( const ::std::size_t n ) { // use this one when displaying polygons in OOo, which still sucks // great rocks when trying to import non-integer svg:d attributes - // return sal_Int64(double(n) * rand() / (RAND_MAX + 1.0)); - return double(n) * rand() / (RAND_MAX + 1.0); + return comphelper::rng::uniform_int_distribution(static_cast<size_t>(0), n-1); } inline bool compare(const B2DPoint& left, const B2DPoint& right) diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 4c6c877..3ccc46e 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -3528,7 +3528,7 @@ RTLFUNC(Randomize) { nSeed = (int)time(NULL); } - comphelper::rng::seed( nSeed ); + comphelper::rng::reseed(nSeed); } RTLFUNC(Rnd) @@ -3542,7 +3542,7 @@ RTLFUNC(Rnd) } else { - rPar.Get(0)->PutDouble( comphelper::rng::uniform() ); + rPar.Get(0)->PutDouble(comphelper::rng::uniform_real_distribution()); } } diff --git a/comphelper/source/misc/random.cxx b/comphelper/source/misc/random.cxx index a976086..4fb4a1f 100644 --- a/comphelper/source/misc/random.cxx +++ b/comphelper/source/misc/random.cxx @@ -11,8 +11,8 @@ */ #include <boost/random.hpp> - #include <comphelper/random.hxx> +#include <rtl/instance.hxx> // this is nothing but a simple wrapper around // the boost random generators @@ -29,23 +29,55 @@ namespace rng // memory requirement: 625*sizeof(uint32_t) // http://en.wikipedia.org/wiki/Mersenne_twister #define BOOST_RNG_ALGO boost::mt19937 -BOOST_RNG_ALGO global_rng; -// initialises the state of the global random number generator -// should only be called once at the start of the main programme -// (note, a few boost::variate_generator<> (like normal) have their -// own state which would need a reset as well to guarantee identical -// sequence of numbers, e.g. via myrand.distribution().reset()) -void seed(int i) +struct RandomNumberGenerator +{ + BOOST_RNG_ALGO global_rng; + RandomNumberGenerator() + { + // initialises the state of the global random number generator + // should only be called once. + // (note, a few boost::variate_generator<> (like normal) have their + // own state which would need a reset as well to guarantee identical + // sequence of numbers, e.g. via myrand.distribution().reset()) + global_rng.seed(time(NULL)); + } +}; + +class theRandomNumberGenerator : public rtl::Static<RandomNumberGenerator, theRandomNumberGenerator> {}; + +// re-initialises the state of the global random number generator +void reseed(int i) +{ + return theRandomNumberGenerator::get().global_rng.seed(i); +} + +// uniform ints [a,b] distribution +int uniform_int_distribution(int a, int b) +{ + boost::random::uniform_int_distribution<int> dist(a, b); + return dist(theRandomNumberGenerator::get().global_rng); +} + +// uniform ints [a,b] distribution +unsigned int uniform_int_distribution(unsigned int a, unsigned int b) +{ + boost::random::uniform_int_distribution<unsigned int> dist(a, b); + return dist(theRandomNumberGenerator::get().global_rng); +} + +// uniform size_t [a,b] distribution +size_t uniform_int_distribution(size_t a, size_t b) { - global_rng.seed(i); + boost::random::uniform_int_distribution<size_t> dist(a, b); + return dist(theRandomNumberGenerator::get().global_rng); } -// uniform [0,1) or [a,b) distribution -double uniform() +// uniform size_t [a,b) distribution +double uniform_real_distribution(double a, double b) { - static boost::uniform_01<BOOST_RNG_ALGO&> myrand(global_rng); - return myrand(); + boost::random::uniform_real_distribution<double> dist(a, b); + return dist(theRandomNumberGenerator::get().global_rng); } } // namespace diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx index 30a7b8a..a8adf2f 100644 --- a/cui/source/customize/cfg.cxx +++ b/cui/source/customize/cfg.cxx @@ -63,6 +63,7 @@ #include <comphelper/documentinfo.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/random.hxx> #include <unotools/configmgr.hxx> #include <com/sun/star/embed/ElementModes.hpp> #include <com/sun/star/embed/FileSystemStorageFactory.hpp> @@ -297,8 +298,7 @@ generateCustomName( sal_uInt32 generateRandomValue() { - srand( unsigned( time( NULL ) )); - return sal_uInt32( rand() ); + return comphelper::rng::uniform_int_distribution(static_cast<unsigned int>(0), std::numeric_limits<unsigned int>::max()); } OUString diff --git a/desktop/source/deployment/misc/lockfile.cxx b/desktop/source/deployment/misc/lockfile.cxx index 96d9dce..1f3d2f2 100644 --- a/desktop/source/deployment/misc/lockfile.cxx +++ b/desktop/source/deployment/misc/lockfile.cxx @@ -24,6 +24,7 @@ #else #include <windows.h> #endif +#include <comphelper/random.hxx> #include <sal/types.h> #include <osl/file.hxx> #include <osl/socket.hxx> @@ -33,7 +34,6 @@ #include "lockfile.hxx" - using namespace ::osl; using namespace ::rtl; using namespace ::utl; @@ -85,11 +85,9 @@ namespace desktop { // generate ID const int nIdBytes = 16; char tmpId[nIdBytes*2+1]; - time_t t; - srand( (unsigned)(t = time( NULL )) ); - int tmpByte = 0; + time_t t = time(NULL); for (int i = 0; i<nIdBytes; i++) { - tmpByte = rand( ) % 0xFF; + int tmpByte = comphelper::rng::uniform_int_distribution(0, 0xFF); sprintf( tmpId+i*2, "%02X", tmpByte ); } tmpId[nIdBytes*2]=0x00; diff --git a/drawinglayer/source/primitive2d/polygonprimitive2d.cxx b/drawinglayer/source/primitive2d/polygonprimitive2d.cxx index 79a5e9e..4a2944b 100644 --- a/drawinglayer/source/primitive2d/polygonprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/polygonprimitive2d.cxx @@ -25,9 +25,9 @@ #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> #include <drawinglayer/geometry/viewinformation2d.hxx> #include <basegfx/polygon/b2dlinegeometry.hxx> +#include <boost/math/special_functions/next.hpp> #include <com/sun/star/drawing/LineCap.hpp> - - +#include <comphelper/random.hxx> using namespace com::sun::star; @@ -212,10 +212,16 @@ namespace drawinglayer } // end of namespace primitive2d } // end of namespace drawinglayer - - namespace drawinglayer { + namespace tools + { + double getRandomColorRange() + { + return comphelper::rng::uniform_real_distribution(0.0, boost::math::nextafter(1.0, DBL_MAX)); + } + } + namespace primitive2d { Primitive2DSequence PolygonStrokePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const @@ -271,7 +277,7 @@ namespace drawinglayer const basegfx::B2DPolyPolygon aNewPolyPolygon(aAreaPolyPolygon.getB2DPolygon(b)); static bool bTestByUsingRandomColor(false); const basegfx::BColor aColor(bTestByUsingRandomColor - ? basegfx::BColor(rand() / 32767.0, rand() / 32767.0, rand() / 32767.0) + ? basegfx::BColor(tools::getRandomColorRange(), tools::getRandomColorRange(), tools::getRandomColorRange()) : getLineAttribute().getColor()); const Primitive2DReference xRef(new PolyPolygonColorPrimitive2D(aNewPolyPolygon, aColor)); aRetval[b] = xRef; diff --git a/drawinglayer/source/texture/texture.cxx b/drawinglayer/source/texture/texture.cxx index e1f8f92..89953e6 100644 --- a/drawinglayer/source/texture/texture.cxx +++ b/drawinglayer/source/texture/texture.cxx @@ -18,12 +18,11 @@ */ #include <drawinglayer/texture/texture.hxx> +#include <drawinglayer/tools/converters.hxx> #include <basegfx/numeric/ftools.hxx> #include <basegfx/tools/gradienttools.hxx> #include <basegfx/matrix/b2dhommatrixtools.hxx> - - namespace drawinglayer { namespace texture @@ -45,9 +44,9 @@ namespace drawinglayer void GeoTexSvx::modifyBColor(const basegfx::B2DPoint& /*rUV*/, basegfx::BColor& rBColor, double& /*rfOpacity*/) const { // base implementation creates random color (for testing only, may also be pure virtual) - rBColor.setRed((rand() & 0x7fff) / 32767.0); - rBColor.setGreen((rand() & 0x7fff) / 32767.0); - rBColor.setBlue((rand() & 0x7fff) / 32767.0); + rBColor.setRed(tools::getRandomColorRange()); + rBColor.setGreen(tools::getRandomColorRange()); + rBColor.setBlue(tools::getRandomColorRange()); } void GeoTexSvx::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const diff --git a/include/comphelper/random.hxx b/include/comphelper/random.hxx index 6b5d6eb..e7051a8 100644 --- a/include/comphelper/random.hxx +++ b/include/comphelper/random.hxx @@ -18,11 +18,24 @@ namespace comphelper namespace rng { -/// set initial seed (equivalent of libc srand()) -COMPHELPER_DLLPUBLIC void seed(int i); +/// reset initial seed, typically you don't call this as the initial seed is taken from the +// time on the first use of the distribution functions +COMPHELPER_DLLPUBLIC void reseed(int i); -/// uniform distribution in [0,1) -COMPHELPER_DLLPUBLIC double uniform(); +// note that uniform_int_distribution is inclusive of b, i.e. [a,b] while +// uniform_real_distribution is exclusive of b, i.e. [a,b), [std/boost]::nextafter may be your friend there + +/// uniform distribution in [a,b) +COMPHELPER_DLLPUBLIC double uniform_real_distribution(double a = 0.0, double b = 1.0); + +/// uniform distribution in [a,b] +COMPHELPER_DLLPUBLIC int uniform_int_distribution(int a, int b); + +/// uniform distribution in [a,b] +COMPHELPER_DLLPUBLIC unsigned int uniform_int_distribution(unsigned int a, unsigned int b); + +/// uniform distribution in [a,b] +COMPHELPER_DLLPUBLIC size_t uniform_int_distribution(size_t a, size_t b); } // namespace diff --git a/include/drawinglayer/tools/converters.hxx b/include/drawinglayer/tools/converters.hxx index 957973f..c004e25 100644 --- a/include/drawinglayer/tools/converters.hxx +++ b/include/drawinglayer/tools/converters.hxx @@ -37,6 +37,8 @@ namespace drawinglayer sal_uInt32 nDiscreteHeight, sal_uInt32 nMaxQuadratPixels); + double DRAWINGLAYER_DLLPUBLIC getRandomColorRange(); + } // end of namespace tools } // end of namespace drawinglayer diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index 4629005..6591238 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -83,6 +83,7 @@ #include <com/sun/star/container/XNamed.hpp> #include <comphelper/processfactory.hxx> +#include <comphelper/random.hxx> #include <xmloff/SchXMLSeriesHelper.hxx> #include "ColorPropertySet.hxx" #include <set> @@ -431,8 +432,7 @@ sal_Int32 lcl_getChartType( const OUString& sChartType ) sal_Int32 lcl_generateRandomValue() { - static sal_Int32 MAX_NUMBER = 100000000; - return sal_Int32( rand() % MAX_NUMBER ); + return comphelper::rng::uniform_int_distribution(0, 100000000-1); } ChartExport::ChartExport( sal_Int32 nXmlNamespace, FSHelperPtr pFS, Reference< frame::XModel >& xModel, XmlFilterBase* pFB, DocumentType eDocumentType ) diff --git a/sc/Library_scopencl.mk b/sc/Library_scopencl.mk index 3e6b955..5f60a37 100644 --- a/sc/Library_scopencl.mk +++ b/sc/Library_scopencl.mk @@ -24,6 +24,7 @@ $(eval $(call gb_Library_use_externals,scopencl,\ )) $(eval $(call gb_Library_use_libraries,scopencl,\ + comphelper \ cppu \ cppuhelper \ for \ diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx index 9b4e63e..ae9e84c 100644 --- a/sc/source/core/data/global.cxx +++ b/sc/source/core/data/global.cxx @@ -521,8 +521,6 @@ void ScGlobal::Init() // arguments are to be merged in, which in turn need strings of function // names from the compiler. ScParameterClassification::Init(); - srand( (unsigned) time( NULL ) ); // Random Seed Init for Interpreter - ::comphelper::rng::seed( time( NULL ) ); // seed for libc rand() replacement InitAddIns(); diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index 7d5d79f..e41458b 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -18,6 +18,7 @@ */ #include <rtl/math.hxx> +#include <comphelper/random.hxx> #include <unotools/textsearch.hxx> #include <svl/zforlist.hxx> #include <svl/zformat.hxx> @@ -1287,10 +1288,10 @@ bool ScTable::IsSorted( SCCOLROW nStart, SCCOLROW nEnd ) const // ueber aSortP void ScTable::DecoladeRow( ScSortInfoArray* pArray, SCROW nRow1, SCROW nRow2 ) { SCROW nRow; - SCROW nMax = nRow2 - nRow1; + int nMax = nRow2 - nRow1; for (SCROW i = nRow1; (i + 4) <= nRow2; i += 4) { - nRow = rand() % nMax; + nRow = comphelper::rng::uniform_int_distribution(0, nMax-1); pArray->Swap(i, nRow1 + nRow); } } diff --git a/sc/source/core/opencl/opencl_device.cxx b/sc/source/core/opencl/opencl_device.cxx index 0dec267..6b99758 100644 --- a/sc/source/core/opencl/opencl_device.cxx +++ b/sc/source/core/opencl/opencl_device.cxx @@ -20,6 +20,7 @@ #include <iostream> #include <sstream> #include <vector> +#include <comphelper/random.hxx> #include <boost/scoped_ptr.hpp> #include "opencl_device.hxx" @@ -170,13 +171,12 @@ double timerCurrent(timer* mytimer) /* Random number generator */ double random(double min, double max) { - return floor(((double)rand() / ((unsigned int)RAND_MAX + 1)) * (max - min + 1) + min); + return comphelper::rng::uniform_real_distribution(min, max); } /* Populate input */ void populateInput(LibreOfficeDeviceEvaluationIO* testData) { - srand((unsigned int)time(NULL)); double* input0 = &testData->input0[0]; double* input1 = &testData->input1[0]; double* input2 = &testData->input2[0]; diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index 7c7dff3..358dab0 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -1662,7 +1662,7 @@ void ScInterpreter::ScPi() void ScInterpreter::ScRandom() { - PushDouble(::comphelper::rng::uniform()); + PushDouble(::comphelper::rng::uniform_real_distribution()); } void ScInterpreter::ScTrue() diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx index 685e372..7b97d59 100644 --- a/sc/source/core/tool/interpr3.cxx +++ b/sc/source/core/tool/interpr3.cxx @@ -34,6 +34,7 @@ #include <vector> #include <algorithm> #include <boost/math/special_functions/log1p.hpp> +#include <comphelper/random.hxx> using ::std::vector; using namespace formula; @@ -3819,7 +3820,7 @@ void ScInterpreter::QuickSort( vector<double>& rSortArray, vector<long>* pIndexO size_t nValCount = rSortArray.size(); for (size_t i = 0; (i + 4) <= nValCount-1; i += 4) { - size_t nInd = rand() % (int) (nValCount-1); + size_t nInd = comphelper::rng::uniform_int_distribution(static_cast<size_t>(0), nValCount-2); ::std::swap( rSortArray[i], rSortArray[nInd]); if (pIndexOrder) ::std::swap( pIndexOrder->at(i), pIndexOrder->at(nInd)); diff --git a/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx b/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx index 49b2d43..a88faaf 100644 --- a/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx +++ b/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx @@ -11,7 +11,7 @@ #include <sfx2/dispatch.hxx> #include <svl/zforlist.hxx> #include <svl/undo.hxx> - +#include <comphelper/random.hxx> #include "rangelst.hxx" #include "scitems.hxx" #include "docsh.hxx" @@ -22,8 +22,6 @@ #include "docfunc.hxx" #include "StatisticsDialogs.hrc" -#include <boost/random.hpp> - #include "SamplingDialog.hxx" ScSamplingDialog::ScSamplingDialog( @@ -203,11 +201,6 @@ ScRange ScSamplingDialog::PerformRandomSampling(ScDocShell* pDocShell) SCCOL outCol = mOutputAddress.Col(); SCROW outRow = mOutputAddress.Row(); - TimeValue now; - osl_getSystemTime(&now); - boost::mt19937 seed(now.Nanosec); - boost::uniform_01<boost::mt19937> rng(seed); - SCROW inRow; sal_Int64 aSampleSize = mpSampleSize->GetValue(); @@ -222,11 +215,9 @@ ScRange ScSamplingDialog::PerformRandomSampling(ScDocShell* pDocShell) outRow = mOutputAddress.Row(); inRow = aStart.Row(); - double aRandomValue; - while ((outRow - mOutputAddress.Row()) < aSampleSize) { - aRandomValue = rng(); + double aRandomValue = comphelper::rng::uniform_real_distribution(); if ( (aPopulationSize - (inRow - aStart.Row())) * aRandomValue >= aSampleSize - (outRow - mOutputAddress.Row()) ) { diff --git a/scaddins/idl/com/sun/star/sheet/addin/XAnalysis.idl b/scaddins/idl/com/sun/star/sheet/addin/XAnalysis.idl index e349284..4622f2a 100644 --- a/scaddins/idl/com/sun/star/sheet/addin/XAnalysis.idl +++ b/scaddins/idl/com/sun/star/sheet/addin/XAnalysis.idl @@ -109,6 +109,8 @@ module addin raises( com::sun::star::lang::IllegalArgumentException ); // randbetween. + // Min is the smallest value randbetween will return + // Max is the largest value randbetween will return double getRandbetween( [in] double Min, [in] double Max ) raises( com::sun::star::lang::IllegalArgumentException ); diff --git a/scaddins/source/analysis/analysis.cxx b/scaddins/source/analysis/analysis.cxx index 6349b7b..d1751f4 100644 --- a/scaddins/source/analysis/analysis.cxx +++ b/scaddins/source/analysis/analysis.cxx @@ -22,6 +22,7 @@ #include "bessel.hxx" #include <cppuhelper/factory.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/random.hxx> #include <cppuhelper/supportsservice.hxx> #include <osl/diagnose.h> #include <rtl/ustrbuf.hxx> @@ -30,6 +31,7 @@ #include <string.h> #include <tools/resmgr.hxx> #include <tools/rcid.h> +#include <boost/math/special_functions/next.hpp> #define ADDIN_SERVICE "com.sun.star.sheet.AddIn" #define MY_SERVICE "com.sun.star.sheet.addin.Analysis" @@ -700,12 +702,7 @@ double SAL_CALL AnalysisAddIn::getRandbetween( double fMin, double fMax ) throw( if( fMin > fMax ) throw lang::IllegalArgumentException(); - // fMax -> range - double fRet = fMax - fMin + 1.0; - fRet *= rand(); - fRet /= (RAND_MAX + 1.0); - fRet += fMin; - fRet = floor( fRet ); // simple floor is sufficient here + double fRet = comphelper::rng::uniform_real_distribution(fMin, boost::math::nextafter(fMax, DBL_MAX)); RETURN_FINITE( fRet ); } diff --git a/sd/source/core/CustomAnimationPreset.cxx b/sd/source/core/CustomAnimationPreset.cxx index b070733..09ba6a5 100644 --- a/sd/source/core/CustomAnimationPreset.cxx +++ b/sd/source/core/CustomAnimationPreset.cxx @@ -30,6 +30,7 @@ #include <com/sun/star/beans/NamedValue.hpp> #include <unotools/streamwrap.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/random.hxx> #include <comphelper/string.hxx> #include <unotools/pathoptions.hxx> #include <tools/stream.hxx> @@ -576,12 +577,12 @@ Reference< XAnimationNode > CustomAnimationPresets::getRandomPreset( sal_Int16 n if( pCategoryList && pCategoryList->size() ) { - sal_Int32 nCategory = (rand() * pCategoryList->size() / RAND_MAX); + sal_Int32 nCategory = comphelper::rng::uniform_int_distribution(static_cast<size_t>(0), pCategoryList->size()-1); PresetCategoryPtr pCategory = (*pCategoryList)[nCategory]; if( pCategory.get() && !pCategory->maEffects.empty() ) { - sal_Int32 nDescriptor = (rand() * pCategory->maEffects.size() / RAND_MAX); + sal_Int32 nDescriptor = comphelper::rng::uniform_int_distribution(static_cast<size_t>(0), pCategory->maEffects.size()-1); CustomAnimationPresetPtr pPreset = pCategory->maEffects[nDescriptor]; if( pPreset.get() ) { @@ -590,7 +591,7 @@ Reference< XAnimationNode > CustomAnimationPresets::getRandomPreset( sal_Int16 n OUString aSubType; if( !aSubTypes.empty() ) { - sal_Int32 nSubType = (rand() * aSubTypes.size() / RAND_MAX); + size_t nSubType = comphelper::rng::uniform_int_distribution(static_cast<size_t>(0), aSubTypes.size()-1); aSubType = aSubTypes[nSubType]; } xNode = pPreset->create( aSubType ); diff --git a/sd/source/ui/remotecontrol/AvahiNetworkService.cxx b/sd/source/ui/remotecontrol/AvahiNetworkService.cxx index ad2bfef..9f53c5d 100644 --- a/sd/source/ui/remotecontrol/AvahiNetworkService.cxx +++ b/sd/source/ui/remotecontrol/AvahiNetworkService.cxx @@ -20,7 +20,7 @@ #include <avahi-common/error.h> #include <avahi-common/timeval.h> #include <avahi-common/thread-watch.h> - +#include <comphelper/random.hxx> #include <dbus/dbus.h> #include <sal/log.hxx> @@ -99,7 +99,8 @@ static bool create_services(AvahiClient *c) { if (avahi_entry_group_is_empty(group)) { SAL_INFO("sdremote.wifi", "Adding service '" << avahiService->getName() << "'"); char r[128]; - snprintf(r, sizeof(r), "random=%i", rand()); + int nRandom = comphelper::rng::uniform_int_distribution(0, std::numeric_limits<int>::max()); + snprintf(r, sizeof(r), "random=%i", nRandom); int ret = avahi_entry_group_add_service( group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, static_cast<AvahiPublishFlags>(0), avahiService->getName().c_str(), kREG_TYPE, NULL, NULL, 1599, "local", r, NULL diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx index 86d11bf..ce78ab0 100644 --- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx @@ -32,6 +32,8 @@ #include <utility> #include <boost/make_shared.hpp> +#include <boost/math/special_functions/next.hpp> +#include <comphelper/random.hxx> #include "OGLTrans_TransitionImpl.hxx" #include <math.h> @@ -674,7 +676,7 @@ boost::shared_ptr<OGLTransitionImpl> makeRochade() inline double randFromNeg1to1() { - return ( ( static_cast<double>( rand() ) / static_cast<double>( RAND_MAX ) ) * 2.0 ) - 1.0; + return comphelper::rng::uniform_real_distribution(-1.0, boost::math::nextafter(1.0, DBL_MAX)); } // TODO(Q3): extract to basegfx diff --git a/slideshow/source/inc/tools.hxx b/slideshow/source/inc/tools.hxx index 4e8037e..682530f 100644 --- a/slideshow/source/inc/tools.hxx +++ b/slideshow/source/inc/tools.hxx @@ -26,7 +26,7 @@ #include <com/sun/star/animations/XAnimationNode.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> #include <com/sun/star/container/XEnumeration.hpp> - +#include <comphelper/random.hxx> #include <vector> #include <cppcanvas/color.hxx> @@ -293,8 +293,7 @@ namespace slideshow /// Gets a random ordinal [0,n) inline ::std::size_t getRandomOrdinal( const ::std::size_t n ) { - return static_cast< ::std::size_t >( - double(n) * rand() / (RAND_MAX + 1.0) ); + return comphelper::rng::uniform_int_distribution(static_cast<size_t>(0), n-1); } /// To work around ternary operator in initializer lists diff --git a/svx/source/svdraw/sdrpagewindow.cxx b/svx/source/svdraw/sdrpagewindow.cxx index f4cccca..bdd163d 100644 --- a/svx/source/svdraw/sdrpagewindow.cxx +++ b/svx/source/svdraw/sdrpagewindow.cxx @@ -23,6 +23,7 @@ #include <com/sun/star/awt/PosSize.hpp> #include <com/sun/star/util/XModeChangeBroadcaster.hpp> #include <comphelper/processfactory.hxx> +#include <comphelper/random.hxx> #include <vcl/svapp.hxx> #include <toolkit/helper/vclunohelper.hxx> #include <svx/svdouno.hxx> @@ -254,7 +255,10 @@ namespace for(sal_uInt32 a(0L); a < aResult.count(); a++) { - Color aColor(rand()%255, rand()%255, rand()%255); + int nR = comphelper::rng::uniform_int_distribution(0, 254); + int nG = comphelper::rng::uniform_int_distribution(0, 254); + int nB = comphelper::rng::uniform_int_distribution(0, 254); + Color aColor(nR, nG, nB); impPaintStrokePolygon(aResult.getB2DPolygon(a), rOutDev, aColor); } } diff --git a/svx/source/svdraw/sdrpaintwindow.cxx b/svx/source/svdraw/sdrpaintwindow.cxx index f64aea3..ae6f6d5 100644 --- a/svx/source/svdraw/sdrpaintwindow.cxx +++ b/svx/source/svdraw/sdrpaintwindow.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <comphelper/random.hxx> #include <svx/sdrpaintwindow.hxx> #include <sdr/overlay/overlaymanagerbuffered.hxx> #include <svx/svdpntv.hxx> @@ -174,7 +175,10 @@ void SdrPreRenderDevice::OutputPreRenderDevice(const vcl::Region& rExpandedRegio if(bDoPaintForVisualControlRegion) { - const Color aColor((((((rand()&0x7f)|0x80)<<8L)|((rand()&0x7f)|0x80))<<8L)|((rand()&0x7f)|0x80)); + int nR = comphelper::rng::uniform_int_distribution(0, 0x7F-1); + int nG = comphelper::rng::uniform_int_distribution(0, 0x7F-1); + int nB = comphelper::rng::uniform_int_distribution(0, 0x7F-1); + const Color aColor(((((nR|0x80)<<8L)|(nG|0x80))<<8L)|(nB|0x80)); mrOutputDevice.SetLineColor(aColor); mrOutputDevice.SetFillColor(); @@ -183,32 +187,6 @@ void SdrPreRenderDevice::OutputPreRenderDevice(const vcl::Region& rExpandedRegio #endif } -// while(aRegionPixel.GetEnumRects(aRegionHandle, aRegionRectanglePixel)) -// { -// // for each rectangle, copy the area -// const Point aTopLeft(aRegionRectanglePixel.TopLeft()); -// const Size aSize(aRegionRectanglePixel.GetSize()); - -// mrOutputDevice.DrawOutDev( -// aTopLeft, aSize, -// aTopLeft, aSize, -// maPreRenderDevice); - -//#ifdef DBG_UTIL -// // #i74769# -// static bool bDoPaintForVisualControlRegion(false); -// if(bDoPaintForVisualControlRegion) -// { -// Color aColor((((((rand()&0x7f)|0x80)<<8L)|((rand()&0x7f)|0x80))<<8L)|((rand()&0x7f)|0x80)); -// mrOutputDevice.SetLineColor(aColor); -// mrOutputDevice.SetFillColor(); -// mrOutputDevice.DrawRect(aRegionRectanglePixel); -// } -//#endif -// } - -// aRegionPixel.EndEnumRects(aRegionHandle); - mrOutputDevice.EnableMapMode(bMapModeWasEnabledDest); maPreRenderDevice.EnableMapMode(bMapModeWasEnabledSource); } diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx index ec62c05..a739ca0 100644 --- a/sw/qa/core/uwriter.cxx +++ b/sw/qa/core/uwriter.cxx @@ -16,6 +16,7 @@ #include <com/sun/star/i18n/TransliterationModulesExtra.hpp> #include <comphelper/processfactory.hxx> +#include <comphelper/random.hxx> #include <tools/urlobj.hxx> #include <unotools/tempfile.hxx> #include <unotools/transliterationwrapper.hxx> @@ -849,7 +850,7 @@ getRand(int modulus) { if (modulus <= 0) return 0; - return rand() % modulus; + return comphelper::rng::uniform_int_distribution(0, modulus-1); } static OUString @@ -869,12 +870,13 @@ static SwPosition getRandomPosition(SwDoc *pDoc, int /* nOffset */) { const SwPosition aPos(pDoc->GetNodes().GetEndOfContent()); - sal_uLong nNodes = aPos.nNode.GetNode().GetIndex() - aPos.nNode.GetNode().StartOfSectionIndex(); - sal_uLong n = (rand() * nNodes) / RAND_MAX; - SwPaM pam(aPos); - for (sal_uLong i = 0; i < n; ++i) { - pam.Move(fnMoveBackward, fnGoNode); - } + sal_uLong nNodes = aPos.nNode.GetNode().GetIndex() - aPos.nNode.GetNode().StartOfSectionIndex(); + sal_uLong n = comphelper::rng::uniform_int_distribution(static_cast<sal_uLong>(0), nNodes); + SwPaM pam(aPos); + for (sal_uLong i = 0; i < n; ++i) + { + pam.Move(fnMoveBackward, fnGoNode); + } return *pam.GetPoint(); } diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 36b1f30..95b0ea4 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -40,6 +40,7 @@ #include "wrtww8.hxx" +#include <comphelper/random.hxx> #include <comphelper/string.hxx> #include <comphelper/flagguard.hxx> #include <oox/token/tokens.hxx> @@ -657,9 +658,9 @@ void DocxAttributeOutput::WriteSdtBlock( sal_Int32& nSdtPrToken, if( nSdtPrToken == FSNS( XML_w, XML_id ) || ( bPara && m_bParagraphSdtHasId ) ) //Word won't open a document with an empty id tag, we fill it with a random number - m_pSerializer->singleElementNS(XML_w, XML_id, - FSNS(XML_w, XML_val), OString::number( rand() ), - FSEND ); + m_pSerializer->singleElementNS(XML_w, XML_id, FSNS(XML_w, XML_val), + OString::number(comphelper::rng::uniform_int_distribution(0, std::numeric_limits<int>::max())), + FSEND); if(( pSdtPrDataBindingAttrs ) && !m_rExport.SdrExporter().IsParagraphHasDrawing()) { @@ -4794,7 +4795,7 @@ void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, const Size& rSize, const S XML_ProgID, OUStringToOString( sProgID, RTL_TEXTENCODING_UTF8 ).getStr(), XML_ShapeID, sShapeId.getStr(), XML_DrawAspect, OUStringToOString( sDrawAspect, RTL_TEXTENCODING_UTF8 ).getStr(), - XML_ObjectID, "_" + OString::number( rand() ), + XML_ObjectID, "_" + OString::number(comphelper::rng::uniform_int_distribution(0, std::numeric_limits<int>::max())), FSNS( XML_r, XML_id ), sId.getStr(), FSEND ); diff --git a/vbahelper/source/vbahelper/vbacommandbarhelper.cxx b/vbahelper/source/vbahelper/vbacommandbarhelper.cxx index 0c35ebc..f162e5c 100644 --- a/vbahelper/source/vbahelper/vbacommandbarhelper.cxx +++ b/vbahelper/source/vbahelper/vbacommandbarhelper.cxx @@ -26,6 +26,7 @@ #include <com/sun/star/ui/UIElementType.hpp> #include <com/sun/star/ui/theWindowStateConfiguration.hpp> #include <comphelper/processfactory.hxx> +#include <comphelper/random.hxx> #include <vbahelper/vbahelper.hxx> #include <rtl/ustrbuf.hxx> #include <time.h> @@ -262,8 +263,7 @@ OUString VbaCommandBarHelper::generateCustomURL() url += CUSTOM_TOOLBAR_STR; // use a random number to minimize possible clash with existing custom toolbars - srand( unsigned( time( NULL ) )); - url += OUString::number( rand(), 16 ); + url += OUString::number(comphelper::rng::uniform_int_distribution(0, std::numeric_limits<int>::max()), 16); return url; } diff --git a/vcl/source/window/debugevent.cxx b/vcl/source/window/debugevent.cxx index cc4a865..b2b7553 100644 --- a/vcl/source/window/debugevent.cxx +++ b/vcl/source/window/debugevent.cxx @@ -7,6 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <comphelper/random.hxx> #include <rtl/math.hxx> #include <rtl/string.hxx> #include <tools/time.hxx> @@ -29,7 +30,7 @@ DebugEventInjector::DebugEventInjector( sal_uInt32 nMaxEvents) : static double getRandom() { - return (double)rand() / RAND_MAX; + return comphelper::rng::uniform_real_distribution(); } vcl::Window *DebugEventInjector::ChooseWindow() diff --git a/xmloff/source/text/txtlists.cxx b/xmloff/source/text/txtlists.cxx index 79a1325..52265c8 100644 --- a/xmloff/source/text/txtlists.cxx +++ b/xmloff/source/text/txtlists.cxx @@ -19,7 +19,7 @@ #include <txtlists.hxx> - +#include <comphelper/random.hxx> #include <tools/debug.hxx> #include <tools/date.hxx> #include <tools/time.hxx> @@ -233,7 +233,7 @@ OUString XMLTextListsHelper::GenerateNewListId() const // Value of xml:id in element <text:list> has to be a valid ID type (#i92478#) sal_Int64 n = ::tools::Time( ::tools::Time::SYSTEM ).GetTime(); n += Date( Date::SYSTEM ).GetDate(); - n += rand(); + n += comphelper::rng::uniform_int_distribution(0, std::numeric_limits<int>::max()); // Value of xml:id in element <text:list> has to be a valid ID type (#i92478#) sTmpStr += OUString::number( n ); }
_______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
