[poppler] goo/GooString.cc qt4/tests
Pino Toscano
pino at kemper.freedesktop.org
Tue Nov 27 07:07:09 PST 2012
goo/GooString.cc | 2 +-
qt4/tests/check_goostring.cpp | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 1 deletion(-)
New commits:
commit 55940e989701eb9118015e30f4f48eb654fa34c4
Author: Pino Toscano <pino at kde.org>
Date: Tue Nov 27 16:05:15 2012 +0100
fix my previous GooString::insert fix
we need only to move the characters after the specified position, not all of them
extend qt4's check_goostring with few more checks covering this (and the previous) fix
diff --git a/goo/GooString.cc b/goo/GooString.cc
index e52380e..d35161d 100644
--- a/goo/GooString.cc
+++ b/goo/GooString.cc
@@ -775,7 +775,7 @@ GooString *GooString::insert(int i, const char *str, int lengthA) {
lengthA = strlen(str);
resize(length + lengthA);
- memmove(s+i+lengthA, s+i, prevLen);
+ memmove(s+i+lengthA, s+i, prevLen-i);
memcpy(s+i, str, lengthA);
return this;
}
diff --git a/qt4/tests/check_goostring.cpp b/qt4/tests/check_goostring.cpp
index 41c28d3..97f246d 100644
--- a/qt4/tests/check_goostring.cpp
+++ b/qt4/tests/check_goostring.cpp
@@ -6,15 +6,54 @@ class TestGooString : public QObject
{
Q_OBJECT
private slots:
+ void testInsertData_data();
+ void testInsertData();
void testInsert();
};
+void TestGooString::testInsertData_data()
+{
+ QTest::addColumn<QByteArray>("string");
+ QTest::addColumn<QByteArray>("addition");
+ QTest::addColumn<int>("position");
+ QTest::addColumn<QByteArray>("result");
+
+ QTest::newRow("foo") << QByteArray("foo") << QByteArray("bar") << 0 << QByteArray("barfoo");
+ QTest::newRow("<empty>") << QByteArray() << QByteArray("bar") << 0 << QByteArray("bar");
+ QTest::newRow("foo+bar #1") << QByteArray("f+bar") << QByteArray("oo") << 1 << QByteArray("foo+bar");
+ QTest::newRow("foo+bar #2") << QByteArray("fobar") << QByteArray("o+") << 2 << QByteArray("foo+bar");
+ QTest::newRow("foo+bar #last") << QByteArray("foo+r") << QByteArray("ba") << 4 << QByteArray("foo+bar");
+ QTest::newRow("foo+bar #end") << QByteArray("foo+") << QByteArray("bar") << 4 << QByteArray("foo+bar");
+ QTest::newRow("long #start") << QByteArray("very string") << QByteArray("long long long long long ") << 5 << QByteArray("very long long long long long string");
+}
+
+void TestGooString::testInsertData()
+{
+ QFETCH(QByteArray, string);
+ QFETCH(QByteArray, addition);
+ QFETCH(int, position);
+ QFETCH(QByteArray, result);
+
+ GooString goo(string.constData());
+ QCOMPARE(goo.getCString(), string.constData());
+ goo.insert(position, addition.constData());
+ QCOMPARE(goo.getCString(), result.constData());
+}
+
void TestGooString::testInsert()
{
+ {
GooString goo;
goo.insert(0, ".");
goo.insert(0, "This is a very long long test string");
QCOMPARE(goo.getCString(), "This is a very long long test string.");
+ }
+ {
+ GooString goo;
+ goo.insert(0, "second-part-third-part");
+ goo.insert(0, "first-part-");
+ QCOMPARE(goo.getCString(), "first-part-second-part-third-part");
+ }
}
QTEST_MAIN(TestGooString)
More information about the poppler
mailing list