summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2018-11-30 21:37:58 +0100
committerEike Rathke <erack@redhat.com>2018-12-01 16:45:26 +0100
commit52f9d3848bcb64c39401eeaefa27eda2dfd94a84 (patch)
tree8a449391582606d96ca0b448a1f84cb09146aee4 /sal
parentac7d134c46aa8864d6b7b352f17202f412926b21 (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> (cherry picked from commit d43e48cabce7fa8235207288e66a06fce1c58975) Reviewed-on: https://gerrit.libreoffice.org/64369
Diffstat (limited to 'sal')
-rw-r--r--sal/qa/rtl/math/test-rtl-math.cxx56
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() {