summaryrefslogtreecommitdiff
path: root/sax/qa/cppunit/test_converter.cxx
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2012-04-20 18:39:36 +0200
committerMichael Stahl <mstahl@redhat.com>2012-04-20 20:54:29 +0200
commitee376102becc16c0c44d23e5eb2a322aadc45197 (patch)
treefdf17950e3944ab14f2b606d6568361cb920c462 /sax/qa/cppunit/test_converter.cxx
parent62a0b2405798a3be6a4e38652f1da7a685c84bfc (diff)
fdo#48969: add unit test for Converter::convertDouble
Diffstat (limited to 'sax/qa/cppunit/test_converter.cxx')
-rw-r--r--sax/qa/cppunit/test_converter.cxx72
1 files changed, 72 insertions, 0 deletions
diff --git a/sax/qa/cppunit/test_converter.cxx b/sax/qa/cppunit/test_converter.cxx
index 4a3d36405edb..a8dad879555f 100644
--- a/sax/qa/cppunit/test_converter.cxx
+++ b/sax/qa/cppunit/test_converter.cxx
@@ -39,11 +39,13 @@
#include <com/sun/star/util/DateTime.hpp>
#include <com/sun/star/util/Date.hpp>
#include <com/sun/star/util/Duration.hpp>
+#include <com/sun/star/util/MeasureUnit.hpp>
#include "sax/tools/converter.hxx"
using namespace ::com::sun::star;
+using namespace ::com::sun::star::util::MeasureUnit;
using sax::Converter;
@@ -58,10 +60,12 @@ public:
void testDuration();
void testDateTime();
+ void testDouble();
CPPUNIT_TEST_SUITE(ConverterTest);
CPPUNIT_TEST(testDuration);
CPPUNIT_TEST(testDateTime);
+ CPPUNIT_TEST(testDouble);
CPPUNIT_TEST_SUITE_END();
private:
@@ -249,6 +253,74 @@ void ConverterTest::testDateTime()
OSL_TRACE("\nSAX CONVERTER TEST END");
}
+void doTestDouble(char const*const pis, double const rd,
+ sal_Int16 const nSourceUnit, sal_Int16 const nTargetUnit)
+{
+ ::rtl::OUString const is(::rtl::OUString::createFromAscii(pis));
+ double od;
+ bool bSuccess(Converter::convertDouble(od, is, nSourceUnit, nTargetUnit));
+ OSL_TRACE("%f", od);
+ CPPUNIT_ASSERT(bSuccess);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(rd, od, 0.00000001);
+ ::rtl::OUStringBuffer buf;
+ Converter::convertDouble(buf, od, true, nTargetUnit, nSourceUnit);
+ OSL_TRACE("%s",
+ ::rtl::OUStringToOString(buf.getStr(), RTL_TEXTENCODING_UTF8).getStr());
+ CPPUNIT_ASSERT_EQUAL(is, buf.makeStringAndClear());
+}
+
+void ConverterTest::testDouble()
+{
+ doTestDouble("42", 42.0, TWIP, TWIP);
+ doTestDouble("42", 42.0, POINT, POINT);
+ doTestDouble("42", 42.0, MM_100TH, MM_100TH);
+ doTestDouble("42", 42.0, MM_10TH, MM_10TH);
+ doTestDouble("42", 42.0, MM, MM); // identity don't seem to add unit?
+ doTestDouble("42", 42.0, CM, CM);
+ doTestDouble("42", 42.0, INCH, INCH);
+ doTestDouble("2pt", 40.0, POINT, TWIP);
+ doTestDouble("20pc", 1, TWIP, POINT);
+ doTestDouble("4", 2.26771653543307, MM_100TH, TWIP);
+ doTestDouble("4", 22.6771653543307, MM_10TH, TWIP);
+ doTestDouble("4mm", 226.771653543307, MM, TWIP);
+ doTestDouble("4cm", 2267.71653543307, CM, TWIP);
+ doTestDouble("4in", 5760.0, INCH, TWIP);
+ doTestDouble("1440pc", 1.0, TWIP, INCH);
+ doTestDouble("567pc", 1.000125, TWIP, CM);
+ doTestDouble("56.7pc", 1.000125, TWIP, MM);
+ doTestDouble("5.67pc", 1.000125, TWIP, MM_10TH);
+ doTestDouble("0.567pc", 1.000125, TWIP, MM_100TH);
+ doTestDouble("42pt", 1.4816666666666, POINT, CM);
+ doTestDouble("42pt", 14.816666666666, POINT, MM);
+ doTestDouble("42pt", 148.16666666666, POINT, MM_10TH);
+ doTestDouble("42pt", 1481.6666666666, POINT, MM_100TH);
+ doTestDouble("72pt", 1.0, POINT, INCH);
+ doTestDouble("3.5in", 8.89, INCH, CM);
+ doTestDouble("3.5in", 88.9, INCH, MM);
+ doTestDouble("3.5in", 889.0, INCH, MM_10TH);
+ doTestDouble("3.5in", 8890.0, INCH, MM_100TH);
+ doTestDouble("2in", 144, INCH, POINT);
+ doTestDouble("5.08cm", 2.0, CM, INCH);
+ doTestDouble("3.5cm", 3500.0, CM, MM_100TH);
+ doTestDouble("3.5cm", 350.0, CM, MM_10TH);
+ doTestDouble("3.5cm", 35.0, CM, MM);
+ doTestDouble("10cm", 283.464566929134, CM, POINT);
+ doTestDouble("0.5cm", 283.464566929134, CM, TWIP);
+ doTestDouble("10mm", 28.3464566929134, MM, POINT);
+ doTestDouble("0.5mm", 28.3464566929134, MM, TWIP);
+ doTestDouble("10", 2.83464566929134, MM_10TH, POINT);
+ doTestDouble("0.5", 2.83464566929134, MM_10TH, TWIP);
+ doTestDouble("10", 0.283464566929134, MM_100TH, POINT);
+ doTestDouble("0.5", 0.283464566929134, MM_100TH, TWIP);
+ doTestDouble("10mm", 1.0, MM, CM);
+ doTestDouble("10mm", 100.0, MM, MM_10TH);
+ doTestDouble("20mm", 2000.0, MM, MM_100TH);
+ doTestDouble("300", 30.0, MM_10TH, MM);
+ doTestDouble("400", 4.0, MM_100TH, MM);
+ doTestDouble("600", 6000.0, MM_10TH, MM_100TH);
+ doTestDouble("700", 70.0, MM_100TH, MM_10TH);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(ConverterTest);
}