diff options
Diffstat (limited to 'sal/qa')
-rw-r--r-- | sal/qa/osl/process/osl_Thread.cxx | 10 | ||||
-rw-r--r-- | sal/qa/rtl/oustring/rtl_OUString2.cxx | 5 | ||||
-rw-r--r-- | sal/qa/rtl/process/rtl_Process.cxx | 5 | ||||
-rw-r--r-- | sal/qa/rtl/random/rtl_random.cxx | 50 |
4 files changed, 27 insertions, 43 deletions
diff --git a/sal/qa/osl/process/osl_Thread.cxx b/sal/qa/osl/process/osl_Thread.cxx index 58d916e7fe9c..463096e93c8a 100644 --- a/sal/qa/osl/process/osl_Thread.cxx +++ b/sal/qa/osl/process/osl_Thread.cxx @@ -28,17 +28,14 @@ // include files #include <sal/types.h> - #include <rtl/string.hxx> - #include <rtl/strbuf.hxx> - #include <osl/thread.hxx> - #include <osl/mutex.hxx> #include <osl/time.h> #include <string.h> +#include <memory> #include <cppunit/TestFixture.h> #include <cppunit/extensions/HelperMacros.h> @@ -1694,13 +1691,12 @@ public: private: void SAL_CALL run() override { - oslThreadIdentifier* pId = new oslThreadIdentifier; + std::unique_ptr<oslThreadIdentifier> pId( new oslThreadIdentifier ); *pId = getIdentifier(); - idData.setData(pId); + idData.setData(pId.get()); oslThreadIdentifier* pIdData = static_cast<oslThreadIdentifier*>(idData.getData()); //t_print("Thread %d has Data %d\n", getIdentifier(), *pIdData); m_Id = *pIdData; - delete pId; } public: diff --git a/sal/qa/rtl/oustring/rtl_OUString2.cxx b/sal/qa/rtl/oustring/rtl_OUString2.cxx index 0fb7a09a95aa..5c00a4c6f306 100644 --- a/sal/qa/rtl/oustring/rtl_OUString2.cxx +++ b/sal/qa/rtl/oustring/rtl_OUString2.cxx @@ -893,9 +893,7 @@ public: // Test interning lots of things int i; static const int nSequence = 4096; - rtl::OUString *pStrs; - - pStrs = new rtl::OUString[nSequence]; + std::unique_ptr<rtl::OUString[]> pStrs(new rtl::OUString[nSequence]); for (i = 0; i < nSequence; i++) { pStrs[i] = rtl::OUString::number( sqrt( static_cast<double>(i) ) ).intern(); @@ -906,7 +904,6 @@ public: CPPUNIT_ASSERT_EQUAL_MESSAGE("double intern failed", pStrs[i].pData, aNew.pData); } - delete [] pStrs; } CPPUNIT_TEST_SUITE(construction); diff --git a/sal/qa/rtl/process/rtl_Process.cxx b/sal/qa/rtl/process/rtl_Process.cxx index 7101bade2fc7..5901529af6e9 100644 --- a/sal/qa/rtl/process/rtl_Process.cxx +++ b/sal/qa/rtl/process/rtl_Process.cxx @@ -119,11 +119,11 @@ public: // "osl_joinProcess returned with failure", // osl_Process_E_None == osl_error // ); - oslProcessInfo* pInfo = new oslProcessInfo; + std::unique_ptr<oslProcessInfo> pInfo( new oslProcessInfo ); //please pay attention to initial the Size to sizeof(oslProcessInfo), or else //you will get unknown error when call osl_getProcessInfo pInfo->Size = sizeof(oslProcessInfo); - osl_error = osl_getProcessInfo( hProcess, osl_Process_EXITCODE, pInfo ); + osl_error = osl_getProcessInfo( hProcess, osl_Process_EXITCODE, pInfo.get() ); CPPUNIT_ASSERT_EQUAL_MESSAGE ( "osl_getProcessInfo returned with failure", @@ -132,7 +132,6 @@ public: printf("the exit code is %" SAL_PRIuUINT32 ".\n", pInfo->Code ); CPPUNIT_ASSERT_EQUAL_MESSAGE("rtl_getAppCommandArg or rtl_getAppCommandArgCount error.", static_cast<oslProcessExitCode>(2), pInfo->Code); - delete pInfo; } CPPUNIT_TEST_SUITE(getAppCommandArg); diff --git a/sal/qa/rtl/random/rtl_random.cxx b/sal/qa/rtl/random/rtl_random.cxx index a9ecf9ec8b0a..f537c7c832d6 100644 --- a/sal/qa/rtl/random/rtl_random.cxx +++ b/sal/qa/rtl/random/rtl_random.cxx @@ -98,8 +98,8 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 4; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; - memset(pBuffer, 0, nBufLen); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); rtlRandomError aError = rtl_random_addBytes(nullptr, nullptr, 0); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); @@ -107,12 +107,10 @@ public: /* rtlRandomError */ aError = rtl_random_addBytes(aPool, nullptr, 0); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); - /* rtlRandomError */ aError = rtl_random_addBytes(aPool, pBuffer, nBufLen); + /* rtlRandomError */ aError = rtl_random_addBytes(aPool, pBuffer.get(), nBufLen); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); rtl_random_destroyPool(aPool); - delete [] pBuffer; - } void addBytes_001() @@ -120,16 +118,15 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 4; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); - memset(pBuffer, 0, nBufLen); + memset(pBuffer.get(), 0, nBufLen); - rtl_random_addBytes(aPool, pBuffer, nBufLen); + rtl_random_addBytes(aPool, pBuffer.get(), nBufLen); printf("%2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]); rtl_random_destroyPool(aPool); - delete [] pBuffer; } // Change the following lines only, if you add, remove or rename @@ -220,8 +217,8 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 4; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; - memset(pBuffer, 0, nBufLen); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); rtlRandomError aError = rtl_random_getBytes(nullptr, nullptr, 0); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); @@ -229,11 +226,10 @@ public: /* rtlRandomError */ aError = rtl_random_getBytes(aPool, nullptr, 0); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); - /* rtlRandomError */ aError = rtl_random_getBytes(aPool, pBuffer, nBufLen); + /* rtlRandomError */ aError = rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); rtl_random_destroyPool(aPool); - delete [] pBuffer; } void getBytes_001() @@ -241,16 +237,15 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 4; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; - memset(pBuffer, 0, nBufLen); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); - rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer, nBufLen); + rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); printf("%2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]); rtl_random_destroyPool(aPool); - delete [] pBuffer; } void getBytes_002() @@ -258,12 +253,12 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 4; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen << 1 ]; - memset(pBuffer, 0, nBufLen << 1); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen << 1 ] ); + memset(pBuffer.get(), 0, nBufLen << 1); CPPUNIT_ASSERT_MESSAGE("memset failed", pBuffer[4] == 0 && pBuffer[5] == 0 && pBuffer[6] == 0 && pBuffer[7] == 0); - rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer, nBufLen); + rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); printf("%2x %2x %2x %2x %2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3], pBuffer[4], pBuffer[5], pBuffer[6], pBuffer[7]); @@ -271,7 +266,6 @@ public: CPPUNIT_ASSERT_MESSAGE("internal memory overwrite", pBuffer[4] == 0 && pBuffer[5] == 0 && pBuffer[6] == 0 && pBuffer[7] == 0); rtl_random_destroyPool(aPool); - delete [] pBuffer; } void getBytes_003() @@ -279,8 +273,8 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 1; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; - memset(pBuffer, 0, nBufLen); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); Statistics aStat; @@ -291,7 +285,7 @@ public: int nCountMax = 1000000; for(nCount = 0;nCount < nCountMax; ++nCount) // run 100000000 through getBytes(...) { - /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer, nBufLen); + /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); /* CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); */ aStat.addValue(pBuffer[0], 1); @@ -303,7 +297,6 @@ public: CPPUNIT_ASSERT_MESSAGE("deviation should be less average", aStat.getMaxDeviation() < aStat.getAverage()); rtl_random_destroyPool(aPool); - delete [] pBuffer; } void getBytes_003_1() @@ -311,8 +304,8 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 256; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; - memset(pBuffer, 0, nBufLen); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); Statistics aStat; @@ -323,7 +316,7 @@ public: int nCountMax = 10000; for(nCount = 0;nCount < nCountMax; ++nCount) // run 100000000 through getBytes(...) { - /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer, nBufLen); + /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); // CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); for (sal_uInt32 i=0;i<nBufLen;++i) @@ -336,7 +329,6 @@ public: CPPUNIT_ASSERT_MESSAGE("deviation should be less average", aStat.getMaxDeviation() < aStat.getAverage()); rtl_random_destroyPool(aPool); - delete [] pBuffer; } // Change the following lines only, if you add, remove or rename |