aboutsummaryrefslogtreecommitdiffstats
path: root/libtests
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-02-12 09:44:12 +0100
committerJay Berkenbilt <ejb@ql.org>2021-02-13 08:30:00 +0100
commit07f40bd25442f25c0af948ae1b0dac7fdff1688c (patch)
tree3fca13d92b02bc3712d98c3c43f9612ae4c56cf1 /libtests
parent8fbc8579f2481dc3eeb962e99522047291e16fbe (diff)
downloadqpdf-07f40bd25442f25c0af948ae1b0dac7fdff1688c.tar.zst
QUtil::double_to_string: trim trailing zeroes with option to disable
Diffstat (limited to 'libtests')
-rw-r--r--libtests/json.cc4
-rw-r--r--libtests/matrix.cc28
-rw-r--r--libtests/qtest/qutil/qutil.out6
-rw-r--r--libtests/qutil.cc12
4 files changed, 31 insertions, 19 deletions
diff --git a/libtests/json.cc b/libtests/json.cc
index 1ee7a5d3..d788ab4e 100644
--- a/libtests/json.cc
+++ b/libtests/json.cc
@@ -36,7 +36,7 @@ static void test_main()
" \"a\\tb\",\n"
" null,\n"
" 16059,\n"
- " 3.141590,\n"
+ " 3.14159,\n"
" 2.1e5\n"
"]");
JSON jmap = JSON::makeDictionary();
@@ -56,7 +56,7 @@ static void test_main()
" \"a\\tb\",\n"
" null,\n"
" 16059,\n"
- " 3.141590,\n"
+ " 3.14159,\n"
" 2.1e5\n"
" ],\n"
" \"b\": \"a\\tb\",\n"
diff --git a/libtests/matrix.cc b/libtests/matrix.cc
index 77a058ee..ecaa02a0 100644
--- a/libtests/matrix.cc
+++ b/libtests/matrix.cc
@@ -44,39 +44,39 @@ static void check_rect(QPDFObjectHandle::Rectangle const& r,
int main()
{
QPDFMatrix m;
- check(m, "1.00000 0.00000 0.00000 1.00000 0.00000 0.00000");
+ check(m, "1 0 0 1 0 0");
m.translate(10, 20);
- check(m, "1.00000 0.00000 0.00000 1.00000 10.00000 20.00000");
+ check(m, "1 0 0 1 10 20");
m.scale(1.5, 2);
- check(m, "1.50000 0.00000 0.00000 2.00000 10.00000 20.00000");
+ check(m, "1.5 0 0 2 10 20");
double xp = 0;
double yp = 0;
m.transform(10, 100, xp, yp);
- check_xy(xp, yp, "25.00 220.00");
+ check_xy(xp, yp, "25 220");
m.translate(30, 40);
- check(m, "1.50000 0.00000 0.00000 2.00000 55.00000 100.00000");
+ check(m, "1.5 0 0 2 55 100");
m.transform(10, 100, xp, yp);
- check_xy(xp, yp, "70.00 300.00");
+ check_xy(xp, yp, "70 300");
m.concat(QPDFMatrix(1, 2, 3, 4, 5, 6));
- check(m, "1.50000 4.00000 4.50000 8.00000 62.50000 112.00000");
+ check(m, "1.5 4 4.5 8 62.5 112");
m.rotatex90(90);
- check(m, "4.50000 8.00000 -1.50000 -4.00000 62.50000 112.00000");
+ check(m, "4.5 8 -1.5 -4 62.5 112");
m.rotatex90(180);
- check(m, "-4.50000 -8.00000 1.50000 4.00000 62.50000 112.00000");
+ check(m, "-4.5 -8 1.5 4 62.5 112");
m.rotatex90(270);
- check(m, "-1.50000 -4.00000 -4.50000 -8.00000 62.50000 112.00000");
+ check(m, "-1.5 -4 -4.5 -8 62.5 112");
m.rotatex90(180);
- check(m, "1.50000 4.00000 4.50000 8.00000 62.50000 112.00000");
+ check(m, "1.5 4 4.5 8 62.5 112");
m.rotatex90(12345);
- check(m, "1.50000 4.00000 4.50000 8.00000 62.50000 112.00000");
+ check(m, "1.5 4 4.5 8 62.5 112");
m.transform(240, 480, xp, yp);
- check_xy(xp, yp, "2582.50 4912.00");
+ check_xy(xp, yp, "2582.5 4912");
check(QPDFMatrix(
QPDFObjectHandle::parse(
"[3 1 4 1 5 9.26535]").getArrayAsMatrix()),
- "3.00000 1.00000 4.00000 1.00000 5.00000 9.26535");
+ "3 1 4 1 5 9.26535");
m = QPDFMatrix();
m.rotatex90(90);
diff --git a/libtests/qtest/qutil/qutil.out b/libtests/qtest/qutil/qutil.out
index a5b79e7f..7dded2e3 100644
--- a/libtests/qtest/qutil/qutil.out
+++ b/libtests/qtest/qutil/qutil.out
@@ -9,6 +9,12 @@
0.00012
0.12346
0.00012
+1.0102
+1
+1
+1.00000
+10.00
+10
16059
37273
3ebb
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index 965c4352..abe05f35 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -117,13 +117,19 @@ void string_conversion_test()
std::cout << QUtil::int_to_string(16059) << std::endl
<< QUtil::int_to_string(16059, 7) << std::endl
<< QUtil::int_to_string(16059, -7) << std::endl
- << QUtil::double_to_string(3.14159) << std::endl
+ << QUtil::double_to_string(3.14159, 0, false) << std::endl
<< QUtil::double_to_string(3.14159, 3) << std::endl
- << QUtil::double_to_string(1000.123, -1024) << std::endl
- << QUtil::double_to_string(.1234, 5) << std::endl
+ << QUtil::double_to_string(1000.123, -1024, false) << std::endl
+ << QUtil::double_to_string(.1234, 5, false) << std::endl
<< QUtil::double_to_string(.0001234, 5) << std::endl
<< QUtil::double_to_string(.123456, 5) << std::endl
<< QUtil::double_to_string(.000123456, 5) << std::endl
+ << QUtil::double_to_string(1.01020, 5, true) << std::endl
+ << QUtil::double_to_string(1.00000, 5, true) << std::endl
+ << QUtil::double_to_string(1, 5, true) << std::endl
+ << QUtil::double_to_string(1, 5, false) << std::endl
+ << QUtil::double_to_string(10, 2, false) << std::endl
+ << QUtil::double_to_string(10, 2, true) << std::endl
<< QUtil::int_to_string_base(16059, 10) << std::endl
<< QUtil::int_to_string_base(16059, 8) << std::endl
<< QUtil::int_to_string_base(16059, 16) << std::endl