summaryrefslogtreecommitdiffstats
path: root/lib/kotext/tests
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
commit8362bf63dea22bbf6736609b0f49c152f975eb63 (patch)
tree0eea3928e39e50fae91d4e68b21b1e6cbae25604 /lib/kotext/tests
downloadkoffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz
koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'lib/kotext/tests')
-rw-r--r--lib/kotext/tests/KoUserStyleTester.cpp162
-rw-r--r--lib/kotext/tests/KoUserStyleTester.h34
-rw-r--r--lib/kotext/tests/Makefile.am24
-rw-r--r--lib/kotext/tests/kobordertest.cpp113
-rw-r--r--lib/kotext/tests/kotextformattertest.cpp220
-rw-r--r--lib/kotext/tests/kovariabletest.cpp67
6 files changed, 620 insertions, 0 deletions
diff --git a/lib/kotext/tests/KoUserStyleTester.cpp b/lib/kotext/tests/KoUserStyleTester.cpp
new file mode 100644
index 00000000..4fff7085
--- /dev/null
+++ b/lib/kotext/tests/KoUserStyleTester.cpp
@@ -0,0 +1,162 @@
+/* This file is part of the KDE project
+ Copyright (C) 2005 David Faure <faure@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+// KoUserStyle/KoUserStyleCollection test
+
+#include <kunittest/runner.h>
+#include <kunittest/module.h>
+
+#include <KoUserStyleCollection.h>
+#include <KoUserStyle.h>
+#include <kdebug.h>
+#include <kglobal.h>
+
+#include "KoUserStyleTester.h"
+#include "KoUserStyleTester.moc"
+
+KUNITTEST_MODULE(kunittest_KoUserStyleTester, "KoUserStyle Tester");
+KUNITTEST_MODULE_REGISTER_TESTER(KoUserStyleTester);
+
+#undef COMPARE
+/// for source-compat with qttestlib: use COMPARE(x,y) if you plan to port to qttestlib later.
+#define COMPARE CHECK
+
+/// for source-compat with qttestlib: use VERIFY(x) if you plan to port to qttestlib later.
+#undef VERIFY
+#define VERIFY( x ) CHECK( x, true )
+
+void KoUserStyleTester::testEmptyCollection()
+{
+ KoUserStyleCollection coll( "test" );
+ VERIFY( coll.isEmpty() );
+ COMPARE( coll.count(), 0 );
+ VERIFY( coll.styleList().isEmpty() );
+}
+
+void KoUserStyleTester::testAddStyle()
+{
+ KoUserStyleCollection coll( "test" );
+
+ KoUserStyle* style = new KoUserStyle( "test1" );
+ COMPARE( style->name(), QString( "test1" ) );
+ COMPARE( style->displayName(), QString( "test1" ) );
+ const QString displayName = "A lovely name";
+ style->setDisplayName( displayName );
+ COMPARE( style->displayName(), displayName );
+
+ KoUserStyle* ret = coll.addStyle( style );
+ COMPARE( ret, style );
+
+ KoUserStyle* style2 = new KoUserStyle( "test1" );
+ COMPARE( style2->name(), QString( "test1" ) );
+ style2->setDisplayName( displayName );
+ ret = coll.addStyle( style2 );
+ // here style2 got deleted.
+ COMPARE( ret, style );
+
+ VERIFY( !coll.isEmpty() );
+ COMPARE( coll.count(), 1 );
+ COMPARE( (int)coll.styleList().count(), 1 );
+
+ // Add another style for good this time
+ KoUserStyle* style3 = new KoUserStyle( "test3" );
+ COMPARE( style3->name(), QString( "test3" ) );
+ ret = coll.addStyle( style3 );
+
+ QStringList displayNames = coll.displayNameList();
+ COMPARE( (int)displayNames.count(), 2 );
+ COMPARE( displayNames[0], displayName );
+ COMPARE( displayNames[1], style3->name() );
+}
+
+void KoUserStyleTester::testFindStyle()
+{
+ KoUserStyleCollection coll( "test" );
+ KoUserStyle* style = new KoUserStyle( "test1" );
+ const QString displayName = "A lovely name";
+ style->setDisplayName( displayName );
+ coll.addStyle( style );
+
+ // --- findStyle tests ---
+ KoUserStyle* ret = coll.findStyle( "test1", QString::null );
+ COMPARE( ret, style );
+
+ ret = coll.findStyle( "foo", QString::null );
+ COMPARE( ret, (KoUserStyle*)0 );
+
+ ret = coll.findStyle( "foo", "test1" ); // fallback not used for style 'foo'
+ COMPARE( ret, (KoUserStyle*)0 );
+
+ ret = coll.findStyle( "test1", "test1" ); // fallback used for standard style test1
+ COMPARE( ret, style );
+
+ // --- findStyleByDisplayName tests ---
+ ret = coll.findStyleByDisplayName( displayName );
+ COMPARE( ret, style );
+
+ ret = coll.findStyleByDisplayName( "foo" );
+ COMPARE( ret, (KoUserStyle*)0 );
+
+ // --- indexOf tests ---
+ int pos = coll.indexOf( style );
+ COMPARE( pos, 0 );
+
+ KoUserStyle* style2 = new KoUserStyle( "test1" );
+ pos = coll.indexOf( style2 );
+ COMPARE( pos, -1 );
+ delete style2;
+}
+
+void KoUserStyleTester::testRemoveStyle()
+{
+ KoUserStyleCollection coll( "test" );
+ KoUserStyle* style = new KoUserStyle( "test1" );
+ coll.addStyle( style );
+ COMPARE( coll.count(), 1 );
+
+ // Try removing an unrelated style (noop)
+ KoUserStyle* style2 = new KoUserStyle( "test1" );
+ coll.removeStyle( style2 );
+ delete style2;
+ COMPARE( coll.count(), 1 );
+
+ coll.removeStyle( style );
+ COMPARE( coll.count(), 0 );
+}
+
+void KoUserStyleTester::testReorder()
+{
+ KoUserStyleCollection coll( "test" );
+ KoUserStyle* style = new KoUserStyle( "test1" );
+ coll.addStyle( style );
+ style = new KoUserStyle( "test2" );
+ coll.addStyle( style );
+ style = new KoUserStyle( "test3" );
+ coll.addStyle( style );
+ COMPARE( coll.count(), 3 );
+
+ QStringList newOrder;
+ newOrder << "test3";
+ newOrder << "test2";
+ newOrder << "test1";
+ coll.updateStyleListOrder( newOrder );
+ COMPARE( coll.count(), 3 );
+ QStringList displayNames = coll.displayNameList();
+ COMPARE( (int)displayNames.count(), 3 );
+ COMPARE( displayNames.join(","), newOrder.join(",") );
+}
diff --git a/lib/kotext/tests/KoUserStyleTester.h b/lib/kotext/tests/KoUserStyleTester.h
new file mode 100644
index 00000000..79e61c6a
--- /dev/null
+++ b/lib/kotext/tests/KoUserStyleTester.h
@@ -0,0 +1,34 @@
+/* This file is part of the KDE project
+ Copyright (C) 2005 David Faure <faure@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KOUSERSTYLETESTER_H
+#define KOUSERSTYLETESTER_H
+
+#include <kunittest/tester.h>
+
+class KoUserStyleTester : public KUnitTest::SlotTester {
+ Q_OBJECT
+private slots:
+ void testEmptyCollection();
+ void testAddStyle();
+ void testFindStyle();
+ void testRemoveStyle();
+ void testReorder();
+};
+
+#endif
diff --git a/lib/kotext/tests/Makefile.am b/lib/kotext/tests/Makefile.am
new file mode 100644
index 00000000..a505dce1
--- /dev/null
+++ b/lib/kotext/tests/Makefile.am
@@ -0,0 +1,24 @@
+INCLUDES = $(KOFFICECORE_INCLUDES) $(KOFFICEUI_INCLUDES) $(KOTEXT_INCLUDES) $(all_includes)
+KDE_CXXFLAGS = $(USE_EXCEPTIONS)
+
+METASOURCES = AUTO
+
+check_PROGRAMS = kotextformattertest kobordertest kovariabletest
+
+TESTS = kotextformattertest kovariabletest
+
+LDADD = ../libkotext.la
+AM_LDFLAGS = $(KDE_RPATH) $(all_libraries)
+
+kobordertest_SOURCES = kobordertest.cpp
+kotextformattertest_SOURCES = kotextformattertest.cpp
+kovariabletest_SOURCES = kovariabletest.cpp
+
+check_LTLIBRARIES = kunittest_KoUserStyleTester.la
+
+kunittest_KoUserStyleTester_la_SOURCES = KoUserStyleTester.cpp
+kunittest_KoUserStyleTester_la_LIBADD = ../libkotext.la -lkunittest
+kunittest_KoUserStyleTester_la_LDFLAGS = -module $(KDE_CHECK_PLUGIN) $(all_libraries)
+
+check-local:
+ kunittestmodrunner
diff --git a/lib/kotext/tests/kobordertest.cpp b/lib/kotext/tests/kobordertest.cpp
new file mode 100644
index 00000000..cce43179
--- /dev/null
+++ b/lib/kotext/tests/kobordertest.cpp
@@ -0,0 +1,113 @@
+#include <KoBorder.h>
+#include <KoZoomHandler.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <qpainter.h>
+#include <qwidget.h>
+#include <qgrid.h>
+
+class MyWidget : public QWidget
+{
+public:
+ MyWidget( KoZoomHandler* _zh, QWidget* parent )
+ : QWidget( parent ), m_zh(_zh) {
+ setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
+ }
+
+ QSize sizeHint() const {
+ return QSize( 150, 150 );
+ }
+ QSize minimumSizeHint() const {
+ return sizeHint();
+ }
+
+ KoBorder m_leftBorder;
+ KoBorder m_rightBorder;
+ KoBorder m_topBorder;
+ KoBorder m_bottomBorder;
+
+protected:
+ virtual void paintEvent( QPaintEvent* )
+ {
+ QPainter p( this );
+ QRect rect( 10, 10, 100, 100 );
+ KoBorder::drawBorders( p, m_zh, rect, m_leftBorder,
+ m_rightBorder, m_topBorder, m_bottomBorder,
+ 0, QPen() );
+ // Show the corners of the rect - they must apppear _inside_ the borders.
+ p.setPen( black );
+ p.drawPoint( rect.topLeft() );
+ p.drawPoint( rect.topRight() );
+ p.drawPoint( rect.bottomRight() );
+ p.drawPoint( rect.bottomLeft() );
+ }
+private:
+ KoZoomHandler* m_zh;
+};
+
+int main (int argc, char ** argv)
+{
+ KApplication::disableAutoDcopRegistration();
+ KCmdLineArgs::init(argc,argv,"kobordertest", 0, 0, 0, 0);
+ KApplication app;
+
+ KoZoomHandler* zh = new KoZoomHandler();
+
+ QGrid* grid = new QGrid(2, Qt::Horizontal, 0L); // 2 columns
+ {
+ // First square
+ MyWidget* w = new MyWidget(zh, grid);
+ w->m_leftBorder.setPenWidth( 6 );
+ w->m_leftBorder.color = Qt::red;
+ w->m_rightBorder.setPenWidth( 9 );
+ w->m_rightBorder.color = Qt::red;
+ w->m_topBorder.setPenWidth( 11 );
+ w->m_topBorder.color = Qt::blue;
+ w->m_bottomBorder.setPenWidth( 13 );
+ w->m_bottomBorder.color = Qt::green;
+ }
+ {
+ // Second square, with opposite (odd/even-wise) widths
+ MyWidget* w = new MyWidget(zh, grid);
+ w->m_leftBorder.setPenWidth( 7 );
+ w->m_leftBorder.color = Qt::red;
+ w->m_rightBorder.setPenWidth( 8 );
+ w->m_rightBorder.color = Qt::red;
+ w->m_topBorder.setPenWidth( 10 );
+ w->m_topBorder.color = Qt::blue;
+ w->m_bottomBorder.setPenWidth( 12 );
+ w->m_bottomBorder.color = Qt::green;
+ }
+ {
+ // Third square, with double borders
+ MyWidget* w2 = new MyWidget(zh, grid);
+ w2->m_leftBorder.setPenWidth( 2 );
+ w2->m_leftBorder.setStyle( KoBorder::DOUBLE_LINE );
+ w2->m_rightBorder.setPenWidth( 6 );
+ w2->m_rightBorder.color = Qt::red;
+ w2->m_rightBorder.setStyle( KoBorder::DOUBLE_LINE );
+ w2->m_topBorder.setPenWidth( 4 );
+ w2->m_topBorder.color = Qt::blue;
+ w2->m_topBorder.setStyle( KoBorder::DOUBLE_LINE );
+ w2->m_bottomBorder.setPenWidth( 6 );
+ w2->m_bottomBorder.color = Qt::green;
+ w2->m_bottomBorder.setStyle( KoBorder::DOUBLE_LINE );
+ }
+ {
+ // Fourth square, with double borders
+ MyWidget* w2 = new MyWidget(zh, grid);
+ w2->m_leftBorder.setPenWidth( 1 );
+ w2->m_leftBorder.setStyle( KoBorder::DOUBLE_LINE );
+ w2->m_rightBorder.setPenWidth( 5 );
+ w2->m_rightBorder.color = Qt::red;
+ w2->m_rightBorder.setStyle( KoBorder::DOUBLE_LINE );
+ w2->m_topBorder.setPenWidth( 3 );
+ w2->m_topBorder.color = Qt::blue;
+ w2->m_topBorder.setStyle( KoBorder::DOUBLE_LINE );
+ w2->m_bottomBorder.setPenWidth( 5 );
+ w2->m_bottomBorder.color = Qt::green;
+ w2->m_bottomBorder.setStyle( KoBorder::DOUBLE_LINE );
+ }
+ grid->show();
+ return app.exec();
+}
diff --git a/lib/kotext/tests/kotextformattertest.cpp b/lib/kotext/tests/kotextformattertest.cpp
new file mode 100644
index 00000000..0a4ab140
--- /dev/null
+++ b/lib/kotext/tests/kotextformattertest.cpp
@@ -0,0 +1,220 @@
+//KoTextFormatter test (also for profiling purposes), GPL v2, David Faure <faure@kde.org>
+
+#include <kapplication.h>
+#include <kdebug.h>
+#include <kglobal.h>
+#include <klocale.h>
+
+#include "KoTextFormatter.h"
+#include "KoTextFormat.h"
+#include "KoTextDocument.h"
+#include "KoTextParag.h"
+#include "KoTextZoomHandler.h"
+#include "KoParagCounter.h"
+
+#include <assert.h>
+
+class KoTextFormatterTest
+{
+public:
+ KoTextFormatterTest();
+ ~KoTextFormatterTest() {
+ delete zh;
+ delete doc;
+ }
+
+ void speedTest();
+ void counterAndBigChar();
+ void oneLineTest();
+ void noHeightTest();
+ void noWidthEverTest();
+ void tooWideChar();
+
+private:
+ KoTextZoomHandler* zh;
+ KoTextDocument* doc;
+};
+
+// To test various cases with variable document widths: a custom KoTextFlow
+class TextFlow : public KoTextFlow
+{
+public:
+ TextFlow( int availableWidth, int availableHeight )
+ : m_availableWidth( availableWidth ), m_availableHeight( availableHeight ),
+ m_leftMargin( 0 )
+ {
+ setWidth( m_availableWidth );
+ }
+ virtual int availableHeight() const {
+ return m_availableHeight;
+ }
+ void setLeftMargin( int lm ) {
+ m_leftMargin = lm;
+ }
+ virtual void adjustMargins( int yp, int h, int reqMinWidth, int& leftMargin, int& rightMargin, int& pageWidth, KoTextParag* ) {
+ Q_UNUSED(yp);
+ Q_UNUSED(h);
+ Q_UNUSED(reqMinWidth);
+ Q_UNUSED(rightMargin);
+ if ( m_leftMargin ) {
+ leftMargin = m_leftMargin;
+ pageWidth = m_availableWidth - m_leftMargin;
+ kdDebug() << "adjustMargins: returning leftMargin=" << leftMargin << " pageWidth=" << pageWidth << endl;
+ } else
+ pageWidth = m_availableWidth;
+ }
+private:
+ int m_availableWidth;
+ int m_availableHeight;
+ int m_leftMargin;
+};
+
+KoTextFormatterTest::KoTextFormatterTest()
+{
+ zh = new KoTextZoomHandler;
+ QFont defaultFont( "helvetica", 12 );
+ KoTextFormatCollection* fc = new KoTextFormatCollection( defaultFont, Qt::black, "en_US", false /*no hyphenation*/ );
+ KoTextFormatter* formatter = new KoTextFormatter;
+ // fc and formatter are owned by the doc
+ doc = new KoTextDocument( zh, fc, formatter );
+}
+
+void KoTextFormatterTest::speedTest()
+{
+ kdDebug() << k_funcinfo << endl;
+ doc->clear(true);
+ KoTextParag* parag = doc->firstParag();
+ parag->append( "They burst into flames when it is time for them to die, and then they are reborn from the ashes" );
+
+ // Format it 50 times
+ for ( uint i = 0 ; i < 50 ; ++i )
+ {
+ parag->invalidate(0);
+ parag->format();
+ }
+ doc->clear(false);
+}
+
+void KoTextFormatterTest::noHeightTest()
+{
+ kdDebug() << k_funcinfo << endl;
+ // We test the case of going past maxY - by setting the available height to 0
+ // Expected result: the formatter 'aborts', i.e. no line-breaking, but still
+ // goes over each character to set them all correctly; and usually KWord
+ // would create a new page and reformat the paragraph
+ doc->setFlow( new TextFlow( 250, 0 ) ); // 250 is just enough for one char
+ doc->clear(true);
+ KoTextParag* parag = doc->firstParag();
+ parag->append( "abcdefghi" );
+ parag->format();
+ assert( parag->lines() == 2 ); // one break, then we keep going
+ doc->clear(false);
+ doc->setFlow( new KoTextFlow ); // default
+}
+
+void KoTextFormatterTest::noWidthEverTest()
+{
+ kdDebug() << k_funcinfo << endl;
+ // We test the case of formatting where there is no width (e.g. narrow
+ // passage, or after last page).
+ // Expected result: the formatter goes down until it finds more width
+ // (TODO a test case where this happens)
+ // If it doesn't find any (and hits maxY), then it 'aborts', i.e. no line-breaking,
+ // but still goes over each character to set them all correctly; and usually KWord
+ // would create a new page and reformat the paragraph
+ TextFlow* flow = new TextFlow( 1000, 2000 );
+ flow->setLeftMargin( 1000 );
+ doc->setFlow( flow );
+
+ doc->clear(true);
+ KoTextParag* parag = doc->firstParag();
+ parag->append( "abcdefghi" );
+ parag->format();
+ // The resulting paragraph is NOT marked as formatted. See kotextformatter.cc -r1.79
+ assert( !parag->isValid() );
+ doc->clear(false);
+ doc->setFlow( new KoTextFlow ); // default
+}
+
+void KoTextFormatterTest::tooWideChar()
+{
+ kdDebug() << k_funcinfo << endl;
+ // We test the case of formatting where there is not enough width
+ // for the character (e.g. a very large inline table, larger than the document).
+ // Expected result: the formatter goes down until it finds more width,
+ // gives up, and come back up.
+ doc->setFlow( new TextFlow( 10, 2000 ) );
+ doc->clear(true);
+ KoTextParag* parag = doc->firstParag();
+ parag->append( "a" );
+ parag->format();
+ assert( parag->isValid() );
+ assert( parag->lines() == 1 );
+
+ doc->clear(false);
+ doc->setFlow( new KoTextFlow ); // default
+}
+
+void KoTextFormatterTest::oneLineTest()
+{
+ kdDebug() << k_funcinfo << endl;
+ // Normal case, only one line
+ // Expected: the parag is as wide as the doc
+ doc->setFlow( new TextFlow( 2000, 200 ) );
+ doc->clear(true);
+ KoTextParag* parag = doc->firstParag();
+ parag->append( "abcdefghi" );
+ parag->format();
+ assert( parag->lines() == 1 );
+ assert( parag->isValid() );
+ assert( parag->rect().width() == 2000 );
+ assert( parag->widthUsed() < 2000 );
+ doc->clear(false);
+ doc->setFlow( new KoTextFlow ); // default
+}
+
+void KoTextFormatterTest::counterAndBigChar()
+{
+ kdDebug() << k_funcinfo << endl;
+ // Only one line, with a counter and a big char.
+ // Bug #82609: the new height led to "formatting again" which restarted without taking the counter into account
+ // Expected: the char starts after the counter
+ doc->setFlow( new TextFlow( 2000, 200 ) );
+ doc->clear(true);
+ KoTextParag* parag = doc->firstParag();
+ parag->append( "aB" );
+ KoTextFormat f( *parag->at( 0 )->format() );
+ f.setPointSize( 48 );
+ parag->setFormat( 1, 1, doc->formatCollection()->format( &f ), true );
+ KoParagCounter counter;
+ counter.setNumbering( KoParagCounter::NUM_LIST );
+ counter.setStyle( KoParagCounter::STYLE_NUM );
+ parag->setCounter( &counter );
+ parag->format();
+ assert( parag->lines() == 1 );
+ assert( parag->isValid() );
+ assert( parag->rect().width() == 2000 );
+ assert( parag->widthUsed() < 2000 );
+ assert( parag->at(0)->x > 0 );
+ doc->clear(false);
+ doc->setFlow( new KoTextFlow ); // default
+}
+
+int main (int argc, char ** argv)
+{
+ KApplication app(argc, argv, "KoTextFormatter test");
+
+ // Don't let locale settings lead to different hyphenation output
+ KGlobal::locale()->setLanguage( QString::fromLatin1( "en_US" ) );
+ KGlobal::locale()->setCountry( QString::fromLatin1( "C" ) );
+
+ KoTextFormatterTest test;
+ //test.speedTest();
+ test.oneLineTest();
+ test.counterAndBigChar();
+ test.noHeightTest();
+ test.noWidthEverTest();
+ test.tooWideChar();
+
+ return 0;
+}
diff --git a/lib/kotext/tests/kovariabletest.cpp b/lib/kotext/tests/kovariabletest.cpp
new file mode 100644
index 00000000..05b801c6
--- /dev/null
+++ b/lib/kotext/tests/kovariabletest.cpp
@@ -0,0 +1,67 @@
+/* This file is part of the KDE project
+ Copyright (C) 2005 David Faure <faure@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qstring.h>
+#include <assert.h>
+
+#include "../IsoDuration.h"
+
+void testMinutes()
+{
+ int minutes = 145;
+ QString str = minutesToISODuration( minutes );
+ int result = ISODurationToMinutes( str );
+ qDebug( "%d minutes -> %s -> %d", minutes, str.latin1(), result );
+ assert( result == minutes );
+}
+
+void testNegativeMinutes()
+{
+ int minutes = -15;
+ QString str = minutesToISODuration( minutes );
+ int result = ISODurationToMinutes( str );
+ qDebug( "%d minutes -> %s -> %d", minutes, str.latin1(), result );
+ assert( result == minutes );
+}
+
+void testDays()
+{
+ int days = 14;
+ QString str = daysToISODuration( days );
+ int result = ISODurationToDays( str );
+ qDebug( "%d days -> %s -> %d", days, str.latin1(), result );
+ assert( result == days );
+}
+
+void testNegativeDays()
+{
+ int days = -14;
+ QString str = daysToISODuration( days );
+ int result = ISODurationToDays( str );
+ qDebug( "%d days -> %s -> %d", days, str.latin1(), result );
+ assert( result == days );
+}
+
+int main ( int argc, char ** argv )
+{
+ testMinutes();
+ testDays();
+ testNegativeMinutes();
+ testNegativeDays();
+ return 0;
+}