diff options
author | Eike Rathke <erack@redhat.com> | 2018-11-30 21:37:58 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2018-12-01 02:04:11 +0100 |
commit | d43e48cabce7fa8235207288e66a06fce1c58975 (patch) | |
tree | c03e9b56cdc9afb74b09510db226512bc393d1c2 | |
parent | 262ba64960f6295e901dfeaa1de971e090a8a1dc (diff) |
Unit test for leading and trailing group separator characters
Change-Id: I10ff8b59ba707d5795338ff5e9037473d31337bc
Reviewed-on: https://gerrit.libreoffice.org/64361
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
-rw-r--r-- | sal/qa/rtl/math/test-rtl-math.cxx | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/sal/qa/rtl/math/test-rtl-math.cxx b/sal/qa/rtl/math/test-rtl-math.cxx index 214ddb035177..5038b45a13c8 100644 --- a/sal/qa/rtl/math/test-rtl-math.cxx +++ b/sal/qa/rtl/math/test-rtl-math.cxx @@ -101,6 +101,54 @@ public: CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), end); CPPUNIT_ASSERT_EQUAL(5.0, res); + + // Leading 0 and group separator. + res = rtl::math::stringToDouble( + OUString("0,123"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), end); + CPPUNIT_ASSERT_EQUAL(123.0, res); + + // Leading 0 and two consecutive group separators are none. + res = rtl::math::stringToDouble( + OUString("0,,1"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + + // Leading 0 and group separator at end is none. + res = rtl::math::stringToDouble( + OUString("0,"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + + // Leading 0 and group separator before non-digit is none. + res = rtl::math::stringToDouble( + OUString("0,x"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); + + // Trailing group separator is none. + res = rtl::math::stringToDouble( + OUString("1,234,"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), end); + CPPUNIT_ASSERT_EQUAL(1234.0, res); + + // Group separator followed by non-digit is none. + res = rtl::math::stringToDouble( + OUString("1,234,x"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), end); + CPPUNIT_ASSERT_EQUAL(1234.0, res); } void test_stringToDouble_bad() { @@ -133,6 +181,14 @@ public: CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end); CPPUNIT_ASSERT_EQUAL(0.0, res); + + // Leading group separator is none. + res = rtl::math::stringToDouble( + OUString(",1234"), + '.', ',', &status, &end); + CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end); + CPPUNIT_ASSERT_EQUAL(0.0, res); } void test_stringToDouble_exponent_without_digit() { |