goo/GooString.cc | 2 +- qt5/tests/check_goostring.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-)
New commits: commit 853623c23e0c805e9b04c59f9449b388a485f31a Author: Greg Knight <[email protected]> Date: Wed Nov 28 08:44:39 2018 -0500 use qt5 _data tests per Adam Reichold's recommendation diff --git a/qt5/tests/check_goostring.cpp b/qt5/tests/check_goostring.cpp index c9506472..4a18ad1f 100644 --- a/qt5/tests/check_goostring.cpp +++ b/qt5/tests/check_goostring.cpp @@ -14,6 +14,7 @@ private slots: void testInsert(); void testFormat(); void testFromNullptr(); + void testFromInt_data(); void testFromInt(); }; @@ -162,23 +163,24 @@ void TestGooString::testFromNullptr() } } +void TestGooString::testFromInt_data() +{ + QTest::addColumn<int>("inty"); + QTest::addColumn<QByteArray>("stringy"); + + QTest::newRow("Natural") << 12345 << QByteArray("12345"); + QTest::newRow("Negative") << -1 << QByteArray("-1"); + QTest::newRow("Zero") << 0 << QByteArray("0"); + QTest::newRow("INT_MAX") << 0x7fffffff << QByteArray("2147483647"); + QTest::newRow("-INT_MAX-1") << (-0x7fffffff - 1) << QByteArray("-2147483648"); +} + void TestGooString::testFromInt() { - struct _testcase { - int inty; - const char* str; - } cases[] = { - { 12345, "12345" }, - { -1, "-1" }, - { 0, "0" }, - { 0x7fffffff, "2147483647" }, - { -0x7fffffff - 1, "-2147483648" }, - }; - - for (size_t k = 0; k < sizeof(cases) / sizeof(cases[0]); ++k) { - QScopedPointer<GooString> str(GooString::fromInt(cases[k].inty)); - QCOMPARE(str->c_str(), cases[k].str); - } + QFETCH(int, inty); + QFETCH(QByteArray, stringy); + QScopedPointer<GooString> str(GooString::fromInt(inty)); + QCOMPARE(str->c_str(), stringy.constData()); } QTEST_GUILESS_MAIN(TestGooString) commit 96a0c301a13d02570f44dc0eafbc97b302e996cb Author: Greg Knight <[email protected]> Date: Tue Nov 27 18:37:25 2018 -0500 add testFromInt to fail if GooString::fromInt is broken again diff --git a/qt5/tests/check_goostring.cpp b/qt5/tests/check_goostring.cpp index 3bdfcf77..c9506472 100644 --- a/qt5/tests/check_goostring.cpp +++ b/qt5/tests/check_goostring.cpp @@ -14,6 +14,7 @@ private slots: void testInsert(); void testFormat(); void testFromNullptr(); + void testFromInt(); }; void TestGooString::testInsertData_data() @@ -161,6 +162,25 @@ void TestGooString::testFromNullptr() } } +void TestGooString::testFromInt() +{ + struct _testcase { + int inty; + const char* str; + } cases[] = { + { 12345, "12345" }, + { -1, "-1" }, + { 0, "0" }, + { 0x7fffffff, "2147483647" }, + { -0x7fffffff - 1, "-2147483648" }, + }; + + for (size_t k = 0; k < sizeof(cases) / sizeof(cases[0]); ++k) { + QScopedPointer<GooString> str(GooString::fromInt(cases[k].inty)); + QCOMPARE(str->c_str(), cases[k].str); + } +} + QTEST_GUILESS_MAIN(TestGooString) #include "check_goostring.moc" commit 903983bbd921a5139e3cd6de227b571870c764d8 Author: Greg Knight <[email protected]> Date: Sun Nov 25 15:47:18 2018 -0500 gooString::fromInt: Repair the return value. formatInt renders from "right to left" and returns the position of the most significant digit in 'p' - which is not generally equal to 'buf' in the case of GooString::fromInt (unless you're rendering a 24-digit number.) This repairs several issues in pdftohtml diff --git a/goo/GooString.cc b/goo/GooString.cc index e1fff699..0a22e283 100644 --- a/goo/GooString.cc +++ b/goo/GooString.cc @@ -141,7 +141,7 @@ GooString *GooString::fromInt(int x) { int len; formatInt(x, buf, sizeof(buf), false, 0, 10, &p, &len); - return new GooString(buf, len); + return new GooString(p, len); } GooString *GooString::format(const char *fmt, ...) { _______________________________________________ poppler mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/poppler
