summaryrefslogtreecommitdiff
path: root/qt4
diff options
context:
space:
mode:
authorFabio D'Urso <fabiodurso@hotmail.it>2013-12-27 17:08:50 +0100
committerAlbert Astals Cid <aacid@kde.org>2013-12-28 23:02:54 +0100
commitfe88f20cc565b4cf4765fed56c821989148ef454 (patch)
treeff5ee8611ca9486c976beae7266e0f5a41fd8c69 /qt4
parent5234a349adb678d267a3d8ca13176ac8abb7afd2 (diff)
GooString format: Added some tests + improved documentation
Diffstat (limited to 'qt4')
-rw-r--r--qt4/tests/check_goostring.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/qt4/tests/check_goostring.cpp b/qt4/tests/check_goostring.cpp
index 07999b5d..69f7cdc5 100644
--- a/qt4/tests/check_goostring.cpp
+++ b/qt4/tests/check_goostring.cpp
@@ -1,3 +1,4 @@
+#include <QtCore/QScopedPointer>
#include <QtTest/QtTest>
#include "goo/GooString.h"
@@ -9,6 +10,7 @@ private slots:
void testInsertData_data();
void testInsertData();
void testInsert();
+ void testFormat();
};
void TestGooString::testInsertData_data()
@@ -56,6 +58,70 @@ void TestGooString::testInsert()
}
}
+void TestGooString::testFormat()
+{
+ {
+ const QScopedPointer<GooString> goo(GooString::format("{0:d},{1:x}", 1, 0xF));
+ QCOMPARE(goo->getCString(), "1,f");
+ }
+ {
+ const QScopedPointer<GooString> goo(GooString::format("{0:d},{0:x},{0:X},{0:o},{0:b},{0:w}", 0xA));
+ QCOMPARE(goo->getCString(), "10,a,A,12,1010, ");
+ }
+ {
+ const QScopedPointer<GooString> goo(GooString::format("{0:d},{0:x},{0:X},{0:o},{0:b}", -0xA));
+ QCOMPARE(goo->getCString(), "-10,-a,-A,-12,-1010");
+ }
+ {
+ const QScopedPointer<GooString> goo(GooString::format("{0:c}{1:c}{2:c}{3:c}",
+ 'T', (char)'E', (short)'S', (int)'T'));
+ QCOMPARE(goo->getCString(), "TEST");
+
+ const QScopedPointer<GooString> goo2(GooString::format("{0:s} {1:t}", "TEST", goo.data()));
+ QCOMPARE(goo2->getCString(), "TEST TEST");
+ }
+ {
+ const QScopedPointer<GooString> goo(GooString::format("{0:ud} {1:d} {2:d}",
+ UINT_MAX, INT_MAX, INT_MIN));
+ const QByteArray expected = QString("%1 %2 %3").arg(UINT_MAX).arg(INT_MAX).arg(INT_MIN).toLatin1();
+ QCOMPARE(goo->getCString(), expected.constData());
+ }
+ {
+ const QScopedPointer<GooString> goo(GooString::format("{0:uld} {1:ld} {2:ld}",
+ ULONG_MAX, LONG_MAX, LONG_MIN));
+ const QByteArray expected = QString("%1 %2 %3").arg(ULONG_MAX).arg(LONG_MAX).arg(LONG_MIN).toLatin1();
+ QCOMPARE(goo->getCString(), expected.constData());
+ }
+ {
+ const QScopedPointer<GooString> goo(GooString::format("{0:ulld} {1:lld} {2:lld}",
+ ULLONG_MAX, LLONG_MAX, LLONG_MIN));
+ const QByteArray expected = QString("%1 %2 %3").arg(ULLONG_MAX).arg(LLONG_MAX).arg(LLONG_MIN).toLatin1();
+ QCOMPARE(goo->getCString(), expected.constData());
+ }
+ {
+ const QScopedPointer<GooString> gooD(GooString::format("{0:.1f} {0:.1g} {0:.1gs} | {1:.1f} {1:.1g} {1:.1gs}", 1., .012));
+ const QScopedPointer<GooString> gooF(GooString::format("{0:.1f} {0:.1g} {0:.1gs} | {1:.1f} {1:.1g} {1:.1gs}", 1.f, .012f));
+ QCOMPARE(gooD->getCString(), "1.0 1 1 | 0.0 0 0.01");
+ QCOMPARE(gooF->getCString(), "1.0 1 1 | 0.0 0 0.01");
+ }
+ {
+ const QScopedPointer<GooString> goo(GooString::format("{0:.4f} {0:.4g} {0:.4gs}", .012));
+ QCOMPARE(goo->getCString(), "0.0120 0.012 0.012");
+ }
+ {
+ const QScopedPointer<GooString> goo(GooString::format("{{ SomeText {0:d} }}", 1));
+ QCOMPARE(goo->getCString(), "{ SomeText 1 }");
+ }
+ {
+ const QScopedPointer<GooString> goo(GooString::format("{{{{ {{ SomeText {0:d}", 2));
+ QCOMPARE(goo->getCString(), "{{ { SomeText 2");
+ }
+ {
+ const QScopedPointer<GooString> goo(GooString::format("SomeText {0:d} }} }}}}", 3));
+ QCOMPARE(goo->getCString(), "SomeText 3 } }}");
+ }
+}
+
QTEST_MAIN(TestGooString)
#include "check_goostring.moc"