Kaydet (Commit) a5920326 authored tarafından Theo van Klaveren's avatar Theo van Klaveren Kaydeden (comit) Caolán McNamara

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').
üst f737c717
...@@ -43,8 +43,8 @@ bool is_equal(T x, T y, sal_Int16 _nPrec) ...@@ -43,8 +43,8 @@ bool is_equal(T x, T y, sal_Int16 _nPrec)
if (_nPrec != PREC_long_double) if (_nPrec != PREC_long_double)
{ {
t_print(T_VERBOSE, "double equal: %.20f\n", x); printf("double equal: %.20f\n", x);
t_print(T_VERBOSE, " %.20f\n", y); printf(" %.20f\n", y);
} }
//here nPrecOfN is the number after dot //here nPrecOfN is the number after dot
sal_Int32 nBeforeDot = sal_Int32( log10(x) ); sal_Int32 nBeforeDot = sal_Int32( log10(x) );
...@@ -52,34 +52,34 @@ bool is_equal(T x, T y, sal_Int16 _nPrec) ...@@ -52,34 +52,34 @@ bool is_equal(T x, T y, sal_Int16 _nPrec)
{ {
nBeforeDot = 0; nBeforeDot = 0;
} }
//t_print(T_VERBOSE, "nPRECISION is %d\n", nPRECISION); //printf("nPRECISION is %d\n", nPRECISION);
sal_Int32 nPrecOfN = -nPRECISION + nBeforeDot; sal_Int32 nPrecOfN = -nPRECISION + nBeforeDot;
if (_nPrec != PREC_long_double) 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); long double nPrec = pow(0.1, -nPrecOfN);
if (_nPrec != PREC_long_double) if (_nPrec != PREC_long_double)
t_print(T_VERBOSE, " prec: %.20f\n", nPrec); printf(" prec: %.20f\n", nPrec);
long double nDelta = fabs( x - y ) ; long double nDelta = fabs( x - y ) ;
if (_nPrec != PREC_long_double) if (_nPrec != PREC_long_double)
{ {
t_print(T_VERBOSE, " delta: %.20f\n", nDelta); printf(" delta: %.20f\n", nDelta);
t_print(T_VERBOSE, " nPrec: %.20f\n", nPrec); printf(" nPrec: %.20f\n", nPrec);
t_print(T_VERBOSE, "delta must be less or equal to prec!\n\n"); printf("delta must be less or equal to prec!\n\n");
} }
if (nDelta > nPrec) 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; return false;
} }
// else // else
// { // {
// t_print(T_VERBOSE, "values are equal. ndelta:%.20f\n", nDelta); // printf("values are equal. ndelta:%.20f\n", nDelta);
return true; return true;
// } // }
} }
...@@ -101,25 +101,25 @@ bool is_equal(T x, T y, sal_Int16 _nPrec) ...@@ -101,25 +101,25 @@ bool is_equal(T x, T y, sal_Int16 _nPrec)
// LLA: y = -y; // LLA: y = -y;
// LLA: } // LLA: }
// 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: sal_Int32 nPrecOfN = -nPRECISION + sal_Int32( log10(x) );
// LLA: // LLA:
// LLA: t_print(T_VERBOSE, "prec: %d\n", nPrecOfN); // LLA: printf("prec: %d\n", nPrecOfN);
// LLA: double nPrec = pow(10, nPrecOfN) * 1; // LLA: double nPrec = pow(10, nPrecOfN) * 1;
// LLA: // LLA:
// LLA: t_print(T_VERBOSE, " prec: %.20f\n", nPrec); // LLA: printf(" prec: %.20f\n", nPrec);
// LLA: // LLA:
// LLA: double nDelta = fabs( x - y ); // 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:
// LLA: if (nDelta > nPrec) // LLA: if (nDelta > nPrec)
// LLA: { // 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: return false;
// LLA: } // LLA: }
// LLA: // else // LLA: // else
// LLA: // { // 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: return true;
// LLA: // } // LLA: // }
// LLA: } // LLA: }
......
...@@ -35,10 +35,13 @@ ...@@ -35,10 +35,13 @@
#endif #endif
#include <math.h> #include <math.h>
#include <testshl/simpleheader.hxx>
#include <rtl/math.h> #include <rtl/math.h>
#include <rtl/string.hxx> #include <rtl/string.hxx>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
#include "valueequal.hxx" #include "valueequal.hxx"
namespace rtl_math namespace rtl_math
...@@ -615,7 +618,7 @@ public: ...@@ -615,7 +618,7 @@ public:
}; // class test }; // class test
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_math::test, "rtl_math"); CPPUNIT_TEST_SUITE_REGISTRATION(rtl_math::test);
} // namespace rtl_math } // namespace rtl_math
...@@ -623,6 +626,6 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_math::test, "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() // 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. // to let the user the possibility to also register some functions by hand.
NOADDITIONAL; CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -35,13 +35,16 @@ ...@@ -35,13 +35,16 @@
#include "rtl/string.h" #include "rtl/string.h"
#include "rtl/string.hxx" #include "rtl/string.hxx"
#include "rtl/textenc.h" #include "rtl/textenc.h"
#include <testshl/tresstatewrapper.hxx>
#include "rtl/ustring.hxx" #include "rtl/ustring.hxx"
#include "sal/types.h" #include "sal/types.h"
#include <sal/macros.h> #include <sal/macros.h>
#include <stdlib.h> #include <stdlib.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
namespace { namespace {
struct FloatTraits struct FloatTraits
...@@ -118,12 +121,11 @@ struct TestNumberToString ...@@ -118,12 +121,11 @@ struct TestNumberToString
}; };
template< typename StringT, typename NumberT > template< typename StringT, typename NumberT >
bool testNumberToString(hTestResult pTestResult, void testNumberToString(TestNumberToString const & rTest)
TestNumberToString const & rTest)
{ {
typename NumberT::Number fValue = static_cast< typename NumberT::Number >(rTest.fValue); typename NumberT::Number fValue = static_cast< typename NumberT::Number >(rTest.fValue);
if (fValue != rTest.fValue) if (fValue != rTest.fValue)
return true; return;
// LLA: t_print("size: %d ", sizeof(fValue)); // LLA: t_print("size: %d ", sizeof(fValue));
typename StringT::String aResult1; typename StringT::String aResult1;
...@@ -134,16 +136,6 @@ bool testNumberToString(hTestResult pTestResult, ...@@ -134,16 +136,6 @@ bool testNumberToString(hTestResult pTestResult,
typename StringT::String aResult2(StringT::createFromAscii(rTest.pResult)); 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; rtl::OStringBuffer aBuffer;
aBuffer.append(StringT::getPrefix()); aBuffer.append(StringT::getPrefix());
aBuffer.append(RTL_CONSTASCII_STRINGPARAM("/")); aBuffer.append(RTL_CONSTASCII_STRINGPARAM("/"));
...@@ -160,27 +152,19 @@ bool testNumberToString(hTestResult pTestResult, ...@@ -160,27 +152,19 @@ bool testNumberToString(hTestResult pTestResult,
aBuffer.append(static_cast< sal_Int32 >(rTest.bEraseTrailingDecZeros)); aBuffer.append(static_cast< sal_Int32 >(rTest.bEraseTrailingDecZeros));
aBuffer.append(RTL_CONSTASCII_STRINGPARAM("): ")); aBuffer.append(RTL_CONSTASCII_STRINGPARAM("): "));
StringT::appendBuffer(aBuffer, aResult1); StringT::appendBuffer(aBuffer, aResult1);
if (!bSuccess) if (aResult1 != aResult2)
{ {
aBuffer.append(RTL_CONSTASCII_STRINGPARAM(" != ")); aBuffer.append(RTL_CONSTASCII_STRINGPARAM(" != "));
StringT::appendBuffer(aBuffer, aResult2); StringT::appendBuffer(aBuffer, aResult2);
} }
// call to the real test checker CPPUNIT_ASSERT_MESSAGE(aBuffer.getStr(), aResult1 == aResult2);
// pTestResult->pFuncs->state_(pTestResult, bSuccess, "test_rtl_math",
// aBuffer.getStr(), false);
c_rtl_tres_state(pTestResult, bSuccess, aBuffer.getStr(), "testNumberToString");
return bSuccess;
} }
template< typename StringT, typename NumberT > template< typename StringT, typename NumberT >
bool testNumberToString(hTestResult pTestResult, void testNumberToString(TestNumberToString const * pTests, size_t nCount)
TestNumberToString const * pTests, size_t nCount)
{ {
bool bSuccess = true;
for (size_t i = 0; i < nCount; ++i) for (size_t i = 0; i < nCount; ++i)
bSuccess &= testNumberToString< StringT, NumberT >(pTestResult, testNumberToString< StringT, NumberT >(pTests[i]);
pTests[i]);
return bSuccess;
} }
struct TestStringToNumberToString struct TestStringToNumberToString
...@@ -194,8 +178,7 @@ struct TestStringToNumberToString ...@@ -194,8 +178,7 @@ struct TestStringToNumberToString
}; };
template< typename StringT > template< typename StringT >
bool testStringToNumberToString(hTestResult pTestResult, void testStringToNumberToString(TestStringToNumberToString const & rTest)
TestStringToNumberToString const & rTest)
{ {
double d = rtl::math::stringToDouble(StringT::createFromAscii(rTest.pValue), double d = rtl::math::stringToDouble(StringT::createFromAscii(rTest.pValue),
rTest.cDecSeparator, 0, 0, 0); rTest.cDecSeparator, 0, 0, 0);
...@@ -204,7 +187,6 @@ bool testStringToNumberToString(hTestResult pTestResult, ...@@ -204,7 +187,6 @@ bool testStringToNumberToString(hTestResult pTestResult,
rTest.cDecSeparator, rTest.cDecSeparator,
rTest.bEraseTrailingDecZeros)); rTest.bEraseTrailingDecZeros));
typename StringT::String aResult2(StringT::createFromAscii(rTest.pResult)); typename StringT::String aResult2(StringT::createFromAscii(rTest.pResult));
bool bSuccess = aResult1 == aResult2;
rtl::OStringBuffer aBuffer; rtl::OStringBuffer aBuffer;
aBuffer.append(StringT::getPrefix()); aBuffer.append(StringT::getPrefix());
aBuffer.append(RTL_CONSTASCII_STRINGPARAM( aBuffer.append(RTL_CONSTASCII_STRINGPARAM(
...@@ -222,37 +204,36 @@ bool testStringToNumberToString(hTestResult pTestResult, ...@@ -222,37 +204,36 @@ bool testStringToNumberToString(hTestResult pTestResult,
aBuffer.append(static_cast< sal_Int32 >(rTest.bEraseTrailingDecZeros)); aBuffer.append(static_cast< sal_Int32 >(rTest.bEraseTrailingDecZeros));
aBuffer.append(RTL_CONSTASCII_STRINGPARAM("): ")); aBuffer.append(RTL_CONSTASCII_STRINGPARAM("): "));
StringT::appendBuffer(aBuffer, aResult1); StringT::appendBuffer(aBuffer, aResult1);
if (!bSuccess) if (aResult1 != aResult2)
{ {
aBuffer.append(RTL_CONSTASCII_STRINGPARAM(" != ")); aBuffer.append(RTL_CONSTASCII_STRINGPARAM(" != "));
StringT::appendBuffer(aBuffer, aResult2); StringT::appendBuffer(aBuffer, aResult2);
} }
// call to the real test checker CPPUNIT_ASSERT_MESSAGE(aBuffer.getStr(), aResult1 == aResult2);
// pTestResult->pFuncs->state_(pTestResult, bSuccess, "test_rtl_math",
// aBuffer.getStr(), false);
c_rtl_tres_state(pTestResult, bSuccess, aBuffer.getStr(), "testStringToNumberToString");
return bSuccess;
} }
template< typename StringT > template< typename StringT >
bool testStringToNumberToString(hTestResult pTestResult, void testStringToNumberToString(TestStringToNumberToString const * pTests,
TestStringToNumberToString const * pTests,
size_t nCount) size_t nCount)
{ {
bool bSuccess = true;
for (size_t i = 0; i < nCount; ++i) for (size_t i = 0; i < nCount; ++i)
bSuccess &= testStringToNumberToString< StringT >(pTestResult, testStringToNumberToString< StringT >(pTests[i]);
pTests[i]);
return bSuccess;
} }
} }
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[] static TestNumberToString const aTest[]
= { // 1, 1+2^-1, ..., 1+2^-52 = { // 1, 1+2^-1, ..., 1+2^-52
...@@ -541,14 +522,13 @@ extern "C" sal_Bool SAL_CALL test_rtl_math(hTestResult pTestResult) ...@@ -541,14 +522,13 @@ extern "C" sal_Bool SAL_CALL test_rtl_math(hTestResult pTestResult)
// bReturn &= testNumberToString< StringTraits, FloatTraits >( // bReturn &= testNumberToString< StringTraits, FloatTraits >(
// pTestResult, aTest, nCount); // pTestResult, aTest, nCount);
bReturn &= testNumberToString< StringTraits, DoubleTraits >( testNumberToString< StringTraits, DoubleTraits >(aTest, nCount);
pTestResult, aTest, nCount);
// bReturn &= testNumberToString< UStringTraits, FloatTraits >( // bReturn &= testNumberToString< UStringTraits, FloatTraits >(
// pTestResult, aTest, nCount); // pTestResult, aTest, nCount);
bReturn &= testNumberToString< UStringTraits, DoubleTraits >( testNumberToString< UStringTraits, DoubleTraits >(aTest, nCount);
pTestResult, aTest, nCount);
} }
void rtl_math_002()
{ {
static TestStringToNumberToString const aTest[] static TestStringToNumberToString const aTest[]
= { { "1", rtl_math_StringFormat_Automatic, = { { "1", rtl_math_StringFormat_Automatic,
...@@ -647,31 +627,36 @@ extern "C" sal_Bool SAL_CALL test_rtl_math(hTestResult pTestResult) ...@@ -647,31 +627,36 @@ extern "C" sal_Bool SAL_CALL test_rtl_math(hTestResult pTestResult)
"1.#INF" }, "1.#INF" },
}; };
size_t const nCount = SAL_N_ELEMENTS(aTest); size_t const nCount = SAL_N_ELEMENTS(aTest);
bReturn &= testStringToNumberToString< StringTraits >( testStringToNumberToString< StringTraits >(aTest, nCount);
pTestResult, aTest, nCount); testStringToNumberToString< UStringTraits >(aTest, nCount);
bReturn &= testStringToNumberToString< UStringTraits >(
pTestResult, 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 ) //extern "C" void /* sal_Bool */ SAL_CALL test_rtl_math2( hTestResult hRtlTestResult )
{ //{
c_rtl_tres_state_start(hRtlTestResult, "rtl_math" ); // 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, "");
// }
//}
test_rtl_math( hRtlTestResult ); CPPUNIT_TEST_SUITE_REGISTRATION(::Math);
c_rtl_tres_state_end(hRtlTestResult, "rtl_math" ); CPPUNIT_PLUGIN_IMPLEMENT();
}
// -----------------------------------------------------------------------------
void RegisterAdditionalFunctions(FktRegFuncPtr _pFunc)
{
if (_pFunc)
{
(_pFunc)(&test_rtl_math2, "");
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment