diff options
Diffstat (limited to 'sal/qa/rtl/random/rtl_random.cxx')
-rw-r--r-- | sal/qa/rtl/random/rtl_random.cxx | 118 |
1 files changed, 62 insertions, 56 deletions
diff --git a/sal/qa/rtl/random/rtl_random.cxx b/sal/qa/rtl/random/rtl_random.cxx index 47ff63e480c4..0ee897291c91 100644 --- a/sal/qa/rtl/random/rtl_random.cxx +++ b/sal/qa/rtl/random/rtl_random.cxx @@ -1,3 +1,4 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -28,13 +29,19 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sal.hxx" -// autogenerated file with codegen.pl -#include <algorithm> // STL +#include <algorithm> -#include <testshl/simpleheader.hxx> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <osl/diagnose.h> #include <rtl/random.h> +#include <string.h> + namespace rtl_random { @@ -160,7 +167,7 @@ public: rtl_random_addBytes(aPool, pBuffer, nBufLen); - t_print("%2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]); + printf("%2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]); rtl_random_destroyPool(aPool); delete [] pBuffer; @@ -190,57 +197,62 @@ class Statistics public: void clearDispensation() + { + for (int i = 0;i < 256;++i) // clear array { - for (int i = 0;i < 256;i ++) // clear array - { - m_nDispensation[i] = 0; - } + m_nDispensation[i] = 0; } + } Statistics() - { - clearDispensation(); - } + : m_nMin(0) + , m_nMax(0) + , m_nAverage(0) + , m_nMinDeviation(0) + , m_nMaxDeviation(0) + { + clearDispensation(); + } ~Statistics(){} void addValue(sal_Int16 _nIndex, sal_Int32 _nValue) - { - OSL_ASSERT(_nIndex >= 0 && _nIndex < 256); - m_nDispensation[_nIndex] += _nValue; - } + { + OSL_ASSERT(_nIndex >= 0 && _nIndex < 256); + m_nDispensation[_nIndex] += _nValue; + } void build(sal_Int32 _nCountMax) - { - m_nMin = _nCountMax; - m_nMax = 0; + { + m_nMin = _nCountMax; + m_nMax = 0; - m_nAverage = _nCountMax / 256; + m_nAverage = _nCountMax / 256; - m_nMinDeviation = _nCountMax; - m_nMaxDeviation = 0; + m_nMinDeviation = _nCountMax; + m_nMaxDeviation = 0; - for (int i = 0;i < 256;i ++) // show dispensation - { - m_nMin = std::min(m_nMin, m_nDispensation[i]); - m_nMax = std::max(m_nMax, m_nDispensation[i]); + for (int i = 0;i < 256;++i) // show dispensation + { + m_nMin = std::min(m_nMin, m_nDispensation[i]); + m_nMax = std::max(m_nMax, m_nDispensation[i]); - m_nMinDeviation = std::min(m_nMinDeviation, abs(m_nAverage - m_nDispensation[i])); - m_nMaxDeviation = std::max(m_nMaxDeviation, abs(m_nAverage - m_nDispensation[i])); - } + m_nMinDeviation = std::min(m_nMinDeviation, abs(m_nAverage - m_nDispensation[i])); + m_nMaxDeviation = std::max(m_nMaxDeviation, abs(m_nAverage - m_nDispensation[i])); } + } void print() - { - // LLA: these are only info values - t_print("\nSome statistics\n"); - t_print("Min: %d\n", m_nMin); - t_print("Max: %d\n", m_nMax); - t_print("Average: %d\n", m_nAverage); - t_print("Min abs deviation: %d\n", m_nMinDeviation); - t_print("Max abs deviation: %d\n", m_nMaxDeviation); - } + { + // LLA: these are only info values + printf("\nSome statistics\n"); + printf("Min: %d\n", m_nMin); + printf("Max: %d\n", m_nMax); + printf("Average: %d\n", m_nAverage); + printf("Min abs deviation: %d\n", m_nMinDeviation); + printf("Max abs deviation: %d\n", m_nMaxDeviation); + } - sal_Int32 getAverage() {return m_nAverage;} - sal_Int32 getMaxDeviation() {return m_nMaxDeviation;} + sal_Int32 getAverage() const {return m_nAverage;} + sal_Int32 getMaxDeviation() const {return m_nMaxDeviation;} }; @@ -289,7 +301,7 @@ public: rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer, nBufLen); CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); - t_print("%2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]); + printf("%2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]); rtl_random_destroyPool(aPool); delete [] pBuffer; @@ -308,7 +320,7 @@ public: rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer, nBufLen); CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); - t_print("%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]); + 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]); CPPUNIT_ASSERT_MESSAGE("internal memory overwrite", pBuffer[4] == 0 && pBuffer[5] == 0 && pBuffer[6] == 0 && pBuffer[7] == 0); @@ -331,7 +343,7 @@ public: int nCount = 0; int nCountMax = 1000000; - for(nCount = 0;nCount < nCountMax; nCount ++) // run 100000000 through getBytes(...) + for(nCount = 0;nCount < nCountMax; ++nCount) // run 100000000 through getBytes(...) { /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer, nBufLen); /* CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); */ @@ -363,15 +375,13 @@ public: int nCount = 0; int nCountMax = 10000; - for(nCount = 0;nCount < nCountMax; nCount ++) // run 100000000 through getBytes(...) + for(nCount = 0;nCount < nCountMax; ++nCount) // run 100000000 through getBytes(...) { /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer, nBufLen); // CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); - for (sal_uInt32 i=0;i<nBufLen;i++) - { + for (sal_uInt32 i=0;i<nBufLen;++i) aStat.addValue(pBuffer[i], 1); - } } aStat.build(nCountMax * nBufLen); @@ -397,16 +407,12 @@ public: }; // class getBytes // ----------------------------------------------------------------------------- -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_random::createPool, "rtl_random"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_random::destroyPool, "rtl_random"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_random::addBytes, "rtl_random"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_random::getBytes, "rtl_random"); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_random::createPool); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_random::destroyPool); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_random::addBytes); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_random::getBytes); } // namespace rtl_random +CPPUNIT_PLUGIN_IMPLEMENT(); -// ----------------------------------------------------------------------------- - -// 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; - +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |