Make the qa/rtl/rtl_math test compile again.
Interesting is that it fails a test that according to the API docs should work (rtl_matH_doubleToString of 1.#INF returns 'INF' instead of '1.#INF').
This commit is contained in:
parent
f737c717b9
commit
a5920326e2
3 changed files with 76 additions and 88 deletions
|
@ -43,8 +43,8 @@ bool is_equal(T x, T y, sal_Int16 _nPrec)
|
|||
|
||||
if (_nPrec != PREC_long_double)
|
||||
{
|
||||
t_print(T_VERBOSE, "double equal: %.20f\n", x);
|
||||
t_print(T_VERBOSE, " %.20f\n", y);
|
||||
printf("double equal: %.20f\n", x);
|
||||
printf(" %.20f\n", y);
|
||||
}
|
||||
//here nPrecOfN is the number after dot
|
||||
sal_Int32 nBeforeDot = sal_Int32( log10(x) );
|
||||
|
@ -52,34 +52,34 @@ bool is_equal(T x, T y, sal_Int16 _nPrec)
|
|||
{
|
||||
nBeforeDot = 0;
|
||||
}
|
||||
//t_print(T_VERBOSE, "nPRECISION is %d\n", nPRECISION);
|
||||
//printf("nPRECISION is %d\n", nPRECISION);
|
||||
sal_Int32 nPrecOfN = -nPRECISION + nBeforeDot;
|
||||
|
||||
if (_nPrec != PREC_long_double)
|
||||
t_print(T_VERBOSE, "nPrecOfN is %d\n", nPrecOfN);
|
||||
printf("nPrecOfN is %d\n", nPrecOfN);
|
||||
|
||||
long double nPrec = pow(0.1, -nPrecOfN);
|
||||
|
||||
if (_nPrec != PREC_long_double)
|
||||
t_print(T_VERBOSE, " prec: %.20f\n", nPrec);
|
||||
printf(" prec: %.20f\n", nPrec);
|
||||
|
||||
long double nDelta = fabs( x - y ) ;
|
||||
|
||||
if (_nPrec != PREC_long_double)
|
||||
{
|
||||
t_print(T_VERBOSE, " delta: %.20f\n", nDelta);
|
||||
t_print(T_VERBOSE, " nPrec: %.20f\n", nPrec);
|
||||
t_print(T_VERBOSE, "delta must be less or equal to prec!\n\n");
|
||||
printf(" delta: %.20f\n", nDelta);
|
||||
printf(" nPrec: %.20f\n", nPrec);
|
||||
printf("delta must be less or equal to prec!\n\n");
|
||||
}
|
||||
|
||||
if (nDelta > nPrec)
|
||||
{
|
||||
// t_print(T_VERBOSE, "values are not equal! ndelta:%.20f\n", nDelta);
|
||||
// printf("values are not equal! ndelta:%.20f\n", nDelta);
|
||||
return false;
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// t_print(T_VERBOSE, "values are equal. ndelta:%.20f\n", nDelta);
|
||||
// printf("values are equal. ndelta:%.20f\n", nDelta);
|
||||
return true;
|
||||
// }
|
||||
}
|
||||
|
@ -101,25 +101,25 @@ bool is_equal(T x, T y, sal_Int16 _nPrec)
|
|||
// LLA: y = -y;
|
||||
// LLA: }
|
||||
// LLA:
|
||||
// LLA: t_print(T_VERBOSE, "double equal: %.20f\n# %.20f\n", x, y);
|
||||
// LLA: printf("double equal: %.20f\n# %.20f\n", x, y);
|
||||
// LLA: sal_Int32 nPrecOfN = -nPRECISION + sal_Int32( log10(x) );
|
||||
// LLA:
|
||||
// LLA: t_print(T_VERBOSE, "prec: %d\n", nPrecOfN);
|
||||
// LLA: printf("prec: %d\n", nPrecOfN);
|
||||
// LLA: double nPrec = pow(10, nPrecOfN) * 1;
|
||||
// LLA:
|
||||
// LLA: t_print(T_VERBOSE, " prec: %.20f\n", nPrec);
|
||||
// LLA: printf(" prec: %.20f\n", nPrec);
|
||||
// LLA:
|
||||
// LLA: double nDelta = fabs( x - y );
|
||||
// LLA: t_print(T_VERBOSE, " delta: %.20f\n\n", nDelta);
|
||||
// LLA: printf(" delta: %.20f\n\n", nDelta);
|
||||
// LLA:
|
||||
// LLA: if (nDelta > nPrec)
|
||||
// LLA: {
|
||||
// LLA: // t_print(T_VERBOSE, "values are not equal! ndelta:%.20f\n", nDelta);
|
||||
// LLA: // printf("values are not equal! ndelta:%.20f\n", nDelta);
|
||||
// LLA: return false;
|
||||
// LLA: }
|
||||
// LLA: // else
|
||||
// LLA: // {
|
||||
// LLA: // t_print(T_VERBOSE, "values are equal. ndelta:%.20f\n", nDelta);
|
||||
// LLA: // printf("values are equal. ndelta:%.20f\n", nDelta);
|
||||
// LLA: return true;
|
||||
// LLA: // }
|
||||
// LLA: }
|
||||
|
|
|
@ -35,10 +35,13 @@
|
|||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <testshl/simpleheader.hxx>
|
||||
#include <rtl/math.h>
|
||||
#include <rtl/string.hxx>
|
||||
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/plugin/TestPlugIn.h>
|
||||
|
||||
#include "valueequal.hxx"
|
||||
|
||||
namespace rtl_math
|
||||
|
@ -615,7 +618,7 @@ public:
|
|||
}; // class test
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_math::test, "rtl_math");
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(rtl_math::test);
|
||||
} // namespace rtl_math
|
||||
|
||||
|
||||
|
@ -623,6 +626,6 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_math::test, "rtl_math");
|
|||
|
||||
// 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;
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
|
|
@ -35,13 +35,16 @@
|
|||
#include "rtl/string.h"
|
||||
#include "rtl/string.hxx"
|
||||
#include "rtl/textenc.h"
|
||||
#include <testshl/tresstatewrapper.hxx>
|
||||
#include "rtl/ustring.hxx"
|
||||
#include "sal/types.h"
|
||||
#include <sal/macros.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/plugin/TestPlugIn.h>
|
||||
|
||||
namespace {
|
||||
|
||||
struct FloatTraits
|
||||
|
@ -118,12 +121,11 @@ struct TestNumberToString
|
|||
};
|
||||
|
||||
template< typename StringT, typename NumberT >
|
||||
bool testNumberToString(hTestResult pTestResult,
|
||||
TestNumberToString const & rTest)
|
||||
void testNumberToString(TestNumberToString const & rTest)
|
||||
{
|
||||
typename NumberT::Number fValue = static_cast< typename NumberT::Number >(rTest.fValue);
|
||||
if (fValue != rTest.fValue)
|
||||
return true;
|
||||
return;
|
||||
|
||||
// LLA: t_print("size: %d ", sizeof(fValue));
|
||||
typename StringT::String aResult1;
|
||||
|
@ -134,16 +136,6 @@ bool testNumberToString(hTestResult pTestResult,
|
|||
|
||||
typename StringT::String aResult2(StringT::createFromAscii(rTest.pResult));
|
||||
|
||||
// LLA: rtl::OStringBuffer aBuf;
|
||||
// LLA: StringT::appendBuffer(aBuf, aResult1);
|
||||
// LLA: t_print("aResult1: %s ", aBuf.getStr());
|
||||
// LLA:
|
||||
// LLA: rtl::OStringBuffer aBuf2;
|
||||
// LLA: StringT::appendBuffer(aBuf2, aResult2);
|
||||
// LLA: t_print("aResult2: %s\n", aBuf2.getStr());
|
||||
|
||||
bool bSuccess = aResult1 == aResult2;
|
||||
|
||||
rtl::OStringBuffer aBuffer;
|
||||
aBuffer.append(StringT::getPrefix());
|
||||
aBuffer.append(RTL_CONSTASCII_STRINGPARAM("/"));
|
||||
|
@ -160,27 +152,19 @@ bool testNumberToString(hTestResult pTestResult,
|
|||
aBuffer.append(static_cast< sal_Int32 >(rTest.bEraseTrailingDecZeros));
|
||||
aBuffer.append(RTL_CONSTASCII_STRINGPARAM("): "));
|
||||
StringT::appendBuffer(aBuffer, aResult1);
|
||||
if (!bSuccess)
|
||||
if (aResult1 != aResult2)
|
||||
{
|
||||
aBuffer.append(RTL_CONSTASCII_STRINGPARAM(" != "));
|
||||
StringT::appendBuffer(aBuffer, aResult2);
|
||||
}
|
||||
// call to the real test checker
|
||||
// pTestResult->pFuncs->state_(pTestResult, bSuccess, "test_rtl_math",
|
||||
// aBuffer.getStr(), false);
|
||||
c_rtl_tres_state(pTestResult, bSuccess, aBuffer.getStr(), "testNumberToString");
|
||||
return bSuccess;
|
||||
CPPUNIT_ASSERT_MESSAGE(aBuffer.getStr(), aResult1 == aResult2);
|
||||
}
|
||||
|
||||
template< typename StringT, typename NumberT >
|
||||
bool testNumberToString(hTestResult pTestResult,
|
||||
TestNumberToString const * pTests, size_t nCount)
|
||||
void testNumberToString(TestNumberToString const * pTests, size_t nCount)
|
||||
{
|
||||
bool bSuccess = true;
|
||||
for (size_t i = 0; i < nCount; ++i)
|
||||
bSuccess &= testNumberToString< StringT, NumberT >(pTestResult,
|
||||
pTests[i]);
|
||||
return bSuccess;
|
||||
testNumberToString< StringT, NumberT >(pTests[i]);
|
||||
}
|
||||
|
||||
struct TestStringToNumberToString
|
||||
|
@ -194,8 +178,7 @@ struct TestStringToNumberToString
|
|||
};
|
||||
|
||||
template< typename StringT >
|
||||
bool testStringToNumberToString(hTestResult pTestResult,
|
||||
TestStringToNumberToString const & rTest)
|
||||
void testStringToNumberToString(TestStringToNumberToString const & rTest)
|
||||
{
|
||||
double d = rtl::math::stringToDouble(StringT::createFromAscii(rTest.pValue),
|
||||
rTest.cDecSeparator, 0, 0, 0);
|
||||
|
@ -204,7 +187,6 @@ bool testStringToNumberToString(hTestResult pTestResult,
|
|||
rTest.cDecSeparator,
|
||||
rTest.bEraseTrailingDecZeros));
|
||||
typename StringT::String aResult2(StringT::createFromAscii(rTest.pResult));
|
||||
bool bSuccess = aResult1 == aResult2;
|
||||
rtl::OStringBuffer aBuffer;
|
||||
aBuffer.append(StringT::getPrefix());
|
||||
aBuffer.append(RTL_CONSTASCII_STRINGPARAM(
|
||||
|
@ -222,37 +204,36 @@ bool testStringToNumberToString(hTestResult pTestResult,
|
|||
aBuffer.append(static_cast< sal_Int32 >(rTest.bEraseTrailingDecZeros));
|
||||
aBuffer.append(RTL_CONSTASCII_STRINGPARAM("): "));
|
||||
StringT::appendBuffer(aBuffer, aResult1);
|
||||
if (!bSuccess)
|
||||
if (aResult1 != aResult2)
|
||||
{
|
||||
aBuffer.append(RTL_CONSTASCII_STRINGPARAM(" != "));
|
||||
StringT::appendBuffer(aBuffer, aResult2);
|
||||
}
|
||||
// call to the real test checker
|
||||
// pTestResult->pFuncs->state_(pTestResult, bSuccess, "test_rtl_math",
|
||||
// aBuffer.getStr(), false);
|
||||
c_rtl_tres_state(pTestResult, bSuccess, aBuffer.getStr(), "testStringToNumberToString");
|
||||
|
||||
return bSuccess;
|
||||
CPPUNIT_ASSERT_MESSAGE(aBuffer.getStr(), aResult1 == aResult2);
|
||||
}
|
||||
|
||||
template< typename StringT >
|
||||
bool testStringToNumberToString(hTestResult pTestResult,
|
||||
TestStringToNumberToString const * pTests,
|
||||
void testStringToNumberToString(TestStringToNumberToString const * pTests,
|
||||
size_t nCount)
|
||||
{
|
||||
bool bSuccess = true;
|
||||
for (size_t i = 0; i < nCount; ++i)
|
||||
bSuccess &= testStringToNumberToString< StringT >(pTestResult,
|
||||
pTests[i]);
|
||||
return bSuccess;
|
||||
testStringToNumberToString< StringT >(pTests[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern "C" sal_Bool SAL_CALL test_rtl_math(hTestResult pTestResult)
|
||||
class Math : public CppUnit::TestFixture
|
||||
{
|
||||
bool bReturn = true;
|
||||
public:
|
||||
void setUp()
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
void rtl_math_001()
|
||||
{
|
||||
static TestNumberToString const aTest[]
|
||||
= { // 1, 1+2^-1, ..., 1+2^-52
|
||||
|
@ -541,14 +522,13 @@ extern "C" sal_Bool SAL_CALL test_rtl_math(hTestResult pTestResult)
|
|||
|
||||
// bReturn &= testNumberToString< StringTraits, FloatTraits >(
|
||||
// pTestResult, aTest, nCount);
|
||||
bReturn &= testNumberToString< StringTraits, DoubleTraits >(
|
||||
pTestResult, aTest, nCount);
|
||||
testNumberToString< StringTraits, DoubleTraits >(aTest, nCount);
|
||||
// bReturn &= testNumberToString< UStringTraits, FloatTraits >(
|
||||
// pTestResult, aTest, nCount);
|
||||
bReturn &= testNumberToString< UStringTraits, DoubleTraits >(
|
||||
pTestResult, aTest, nCount);
|
||||
testNumberToString< UStringTraits, DoubleTraits >(aTest, nCount);
|
||||
}
|
||||
|
||||
void rtl_math_002()
|
||||
{
|
||||
static TestStringToNumberToString const aTest[]
|
||||
= { { "1", rtl_math_StringFormat_Automatic,
|
||||
|
@ -647,31 +627,36 @@ extern "C" sal_Bool SAL_CALL test_rtl_math(hTestResult pTestResult)
|
|||
"1.#INF" },
|
||||
};
|
||||
size_t const nCount = SAL_N_ELEMENTS(aTest);
|
||||
bReturn &= testStringToNumberToString< StringTraits >(
|
||||
pTestResult, aTest, nCount);
|
||||
bReturn &= testStringToNumberToString< UStringTraits >(
|
||||
pTestResult, aTest, nCount);
|
||||
testStringToNumberToString< StringTraits >(aTest, nCount);
|
||||
testStringToNumberToString< UStringTraits >(aTest, nCount);
|
||||
}
|
||||
|
||||
return bReturn;
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(Math);
|
||||
CPPUNIT_TEST(rtl_math_001);
|
||||
CPPUNIT_TEST(rtl_math_002);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
extern "C" void /* sal_Bool */ SAL_CALL test_rtl_math2( hTestResult hRtlTestResult )
|
||||
{
|
||||
c_rtl_tres_state_start(hRtlTestResult, "rtl_math" );
|
||||
|
||||
test_rtl_math( hRtlTestResult );
|
||||
|
||||
c_rtl_tres_state_end(hRtlTestResult, "rtl_math" );
|
||||
}
|
||||
//extern "C" void /* sal_Bool */ SAL_CALL test_rtl_math2( hTestResult hRtlTestResult )
|
||||
//{
|
||||
// c_rtl_tres_state_start(hRtlTestResult, "rtl_math" );
|
||||
//
|
||||
// test_rtl_math( hRtlTestResult );
|
||||
//
|
||||
// c_rtl_tres_state_end(hRtlTestResult, "rtl_math" );
|
||||
//}
|
||||
// -----------------------------------------------------------------------------
|
||||
void RegisterAdditionalFunctions(FktRegFuncPtr _pFunc)
|
||||
{
|
||||
if (_pFunc)
|
||||
{
|
||||
(_pFunc)(&test_rtl_math2, "");
|
||||
}
|
||||
}
|
||||
//void RegisterAdditionalFunctions(FktRegFuncPtr _pFunc)
|
||||
//{
|
||||
// if (_pFunc)
|
||||
// {
|
||||
// (_pFunc)(&test_rtl_math2, "");
|
||||
// }
|
||||
//}
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(::Math);
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
|
Loading…
Reference in a new issue