summaryrefslogtreecommitdiffstats
path: root/kmail/tests
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /kmail/tests
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kmail/tests')
-rw-r--r--kmail/tests/Makefile.am23
-rw-r--r--kmail/tests/messagedicttests.cpp79
-rw-r--r--kmail/tests/messagedicttests.h30
-rw-r--r--kmail/tests/mimelibtests.cpp117
-rw-r--r--kmail/tests/mimelibtests.h44
-rw-r--r--kmail/tests/multipartmixed.mbox10
-rw-r--r--kmail/tests/signedmail.mbox111
-rw-r--r--kmail/tests/storagelayermodule.cpp16
-rw-r--r--kmail/tests/utiltests.cpp207
-rw-r--r--kmail/tests/utiltests.h30
10 files changed, 667 insertions, 0 deletions
diff --git a/kmail/tests/Makefile.am b/kmail/tests/Makefile.am
new file mode 100644
index 000000000..f8bc6ce49
--- /dev/null
+++ b/kmail/tests/Makefile.am
@@ -0,0 +1,23 @@
+INCLUDES = -I$(top_srcdir)/kmail -I$(top_srcdir)/mimelib $(all_includes)
+AM_CPPFLAGS = -DKDESRCDIR=\"$(srcdir)\"
+METASOURCES = AUTO
+
+check_LTLIBRARIES = kunittest_storagelayermodule.la \
+ kunittest_utilmodule.la \
+ kunittest_mimelibmodule.la
+
+kunittest_storagelayermodule_la_SOURCES = storagelayermodule.cpp messagedicttests.cpp ../kmdict.cpp
+kunittest_storagelayermodule_la_LIBADD = -lkunittest
+kunittest_utilmodule_la_SOURCES = utiltests.cpp ../util.cpp
+kunittest_utilmodule_la_LIBADD = -lkunittest ../../mimelib/libmimelib.la
+kunittest_mimelibmodule_la_SOURCES = mimelibtests.cpp ../util.cpp
+kunittest_mimelibmodule_la_LIBADD = -lkunittest ../../mimelib/libmimelib.la
+
+#LIBADD = -lkunittest
+AM_LDFLAGS = -module $(KDE_CHECK_PLUGIN) $(all_libraries)
+
+check-local:
+ kunittestmodrunner
+
+guicheck:
+ kunittestguimodrunner
diff --git a/kmail/tests/messagedicttests.cpp b/kmail/tests/messagedicttests.cpp
new file mode 100644
index 000000000..063fc1cb4
--- /dev/null
+++ b/kmail/tests/messagedicttests.cpp
@@ -0,0 +1,79 @@
+/**
+ * Copyright (C) 2005 Till Adam <adam@kde.org>
+ * This file is subject to the GPL version 2.
+ */
+
+#include <kdebug.h>
+#include <kunittest/runner.h>
+#include <kunittest/module.h>
+
+#include "kmdict.h"
+
+#include "messagedicttests.h"
+
+static void p( const QString & str )
+{
+ kdDebug() << str << endl;
+}
+
+void MessageDictTester::setUp()
+{
+ kdDebug() << "setUp" << endl;
+ m_dict = new KMDict( 4 ); // will be thrown away in init
+}
+
+void MessageDictTester::tearDown()
+{
+ kdDebug() << "tearDown" << endl;
+ delete m_dict;
+}
+
+void MessageDictTester::testKMDictCreation()
+{
+ p("MessageDictTester::testKMDict()");
+ p("Check creation with size of next prime: ");
+ CHECK( m_dict->size(), 31 );
+ m_dict->init( 13 ); // will be created with a 13, no nextPrime()
+ CHECK( m_dict->size(), 13 );
+}
+
+void MessageDictTester::testKMDictInsert()
+{
+ p("Insert: ");
+ KMDictItem *item = new KMDictItem();
+ m_dict->insert( 12345, item );
+ KMDictItem *found = m_dict->find( 12345 );
+ CHECK( item, found);
+}
+
+void MessageDictTester::testKMDictRemove()
+{
+ p("Remove: ");
+ m_dict->remove( 12345 );
+ KMDictItem *item = m_dict->find( 12345 );
+ CHECK( item, (KMDictItem*)0 );
+}
+
+void MessageDictTester::testKMDictClear()
+{
+ p("Check clear: ");
+ for ( unsigned int i=0; i<11; ++i )
+ m_dict->insert( i, new KMDictItem() );
+ m_dict->clear();
+ CHECK( m_dict->mVecs, (KMDictItem**)0 );
+}
+
+void MessageDictTester::testKMDictReplace()
+{
+ p("Check replace: ");
+ m_dict->init( 31 );
+ KMDictItem *oldItem = new KMDictItem();
+ KMDictItem *newItem = new KMDictItem();
+ m_dict->insert( 12345, oldItem );
+ m_dict->replace( 12345, newItem );
+ KMDictItem *found = m_dict->find( 12345 );
+ CHECK( found, newItem );
+}
+
+#include "messagedicttests.moc"
+
diff --git a/kmail/tests/messagedicttests.h b/kmail/tests/messagedicttests.h
new file mode 100644
index 000000000..81385efff
--- /dev/null
+++ b/kmail/tests/messagedicttests.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2005 Till Adam <adam@kde.org>
+ *
+ * This file is subject to the GPL version 2.
+ */
+
+#ifndef MESSAGEDICTTESTS_H
+#define MESSAGEDICTTESTS_H
+
+#include <kunittest/tester.h>
+
+class KMDict;
+
+class MessageDictTester : public KUnitTest::SlotTester
+{
+ Q_OBJECT
+
+public slots:
+ void setUp();
+ void tearDown();
+ void testKMDictCreation();
+ void testKMDictInsert();
+ void testKMDictRemove();
+ void testKMDictClear();
+ void testKMDictReplace();
+private:
+ KMDict *m_dict;
+};
+
+#endif
diff --git a/kmail/tests/mimelibtests.cpp b/kmail/tests/mimelibtests.cpp
new file mode 100644
index 000000000..8d9cf9e78
--- /dev/null
+++ b/kmail/tests/mimelibtests.cpp
@@ -0,0 +1,117 @@
+/* This file is part of the KDE project
+ Copyright (C) 2007 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 as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ 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 "mimelibtests.h"
+#include "mimelibtests.moc"
+
+#include <kdebug.h>
+#include <kunittest/runner.h>
+#include <kunittest/module.h>
+
+using namespace KUnitTest;
+
+KUNITTEST_MODULE( kunittest_mimelibmodule, "Mimelib Tests" );
+KUNITTEST_MODULE_REGISTER_TESTER( MimeLibTester );
+
+#include <mimelib/string.h>
+#include <mimelib/message.h>
+#include "util.h"
+#include <qfile.h>
+#include <assert.h>
+
+#if 0
+static QString makePrintable( const QCString& str )
+{
+ QString a = str;
+ a = a.replace( '\r', "\\r" );
+ a = a.replace( '\n', "\\n" );
+ return a;
+}
+#endif
+
+static QString makePrintable( const DwString& str )
+{
+ QString a = KMail::Util::CString( str ); // ## we assume latin1
+ a = a.replace( '\r', "\\r" );
+ a = a.replace( '\n', "\\n" );
+ return a;
+}
+
+QCString MimeLibTester::readFile(const QString& fileName)
+{
+ QFile file( fileName );
+ // #!@#$& kunittest... VERIFY() does nothing in setUp. Using assert instead.
+ bool ok = file.open( IO_ReadOnly );
+ if ( !ok ) {
+ kdError() << fileName << " not found!" << endl;
+ abort();
+ }
+ QByteArray data = file.readAll();
+ assert( data.size() > 1 );
+ QCString result;
+ KMail::Util::setFromByteArray( result, data );
+ return result;
+}
+
+void MimeLibTester::setUp()
+{
+ // This multipart-mixed mail has a part that starts without headers;
+ // the newline after the (empty) headers must be preserved.
+ mMultipartMixedMail = readFile( KDESRCDIR "/multipartmixed.mbox" );
+ // This is the full signed mail which was simplified to above.
+ // Kept around in case we want to do anything else with a signed mail later :)
+ mSignedMail = readFile( KDESRCDIR "/signedmail.mbox" );
+}
+
+void MimeLibTester::tearDown()
+{
+}
+
+// Simply test creating a DwMessage and then calling AsString on it.
+// Then the same with Parse+Assemble
+bool MimeLibTester::test_dwMessage_AsString( const DwString& text )
+{
+ VERIFY( text.size() > 0 );
+
+ // First without Parse + Assemble
+ {
+ DwMessage* msg = new DwMessage( text, 0 );
+ COMPARE( makePrintable( msg->AsString() ), makePrintable( text ) );
+ delete msg;
+ }
+ // Then with Parse + Assemble
+ {
+ DwMessage* msg = new DwMessage( text, 0 );
+ msg->Parse();
+ msg->Assemble();
+ COMPARE( makePrintable( msg->AsString() ), makePrintable( text ) );
+ if ( msg->AsString() != text )
+ return false;
+ delete msg;
+ }
+ return true;
+}
+
+void MimeLibTester::test_dwMessage_AsString()
+{
+ if ( !test_dwMessage_AsString( mMultipartMixedMail.data() ) )
+ return;
+ if ( !test_dwMessage_AsString( mSignedMail.data() ) )
+ return;
+}
diff --git a/kmail/tests/mimelibtests.h b/kmail/tests/mimelibtests.h
new file mode 100644
index 000000000..3c0dad71c
--- /dev/null
+++ b/kmail/tests/mimelibtests.h
@@ -0,0 +1,44 @@
+/* This file is part of the KDE project
+ Copyright (C) 2007 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 as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ 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 MIMELIBTEST_H
+#define MIMELIBTEST_H
+
+#include <kunittest/tester.h>
+class DwString;
+
+class MimeLibTester : public KUnitTest::SlotTester
+{
+ Q_OBJECT
+
+public slots:
+ void setUp();
+ void tearDown();
+ void test_dwMessage_AsString();
+
+private:
+ QCString readFile(const QString& fileName);
+ bool test_dwMessage_AsString( const DwString& );
+
+ QCString mMultipartMixedMail;
+ QCString mSignedMail;
+};
+
+#endif /* MIMELIBTEST_H */
+
diff --git a/kmail/tests/multipartmixed.mbox b/kmail/tests/multipartmixed.mbox
new file mode 100644
index 000000000..a1c593ee0
--- /dev/null
+++ b/kmail/tests/multipartmixed.mbox
@@ -0,0 +1,10 @@
+From wilde@intevation.de Thu Mar 15 15:16:02 2007
+Subject: aegpyten/issue734
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="==-=-=";
+
+--==-=-=
+
+One empty line above this line.
+--==-=-=--
+
diff --git a/kmail/tests/signedmail.mbox b/kmail/tests/signedmail.mbox
new file mode 100644
index 000000000..1df5f3eed
--- /dev/null
+++ b/kmail/tests/signedmail.mbox
@@ -0,0 +1,111 @@
+From wilde@intevation.de Thu Mar 15 15:16:02 2007
+Return-Path: <nobody@example.org>
+Received: from localhost (localhost [127.0.0.1])
+ by smykowski.kdab.net (Cyrus v2.2.12) with LMTPA;
+ Tue, 03 Apr 2007 10:38:19 +0200
+X-Sieve: CMU Sieve 2.2
+Received: from localhost (localhost [127.0.0.1])
+ by smykowski.kdab.net (Postfix) with ESMTP id 0DEF8E6C750
+ for <dfaure@kdab.net>; Tue, 3 Apr 2007 10:38:19 +0200 (CEST)
+Received: from smykowski.kdab.net ([127.0.0.1])
+ by localhost (smykowski.kdab.net [127.0.0.1]) (amavisd-new, port 10024)
+ with ESMTP id 16175-09 for <dfaure@kdab.net>;
+ Tue, 3 Apr 2007 10:38:17 +0200 (CEST)
+Received: from localhost (localhost [127.0.0.1])
+ by smykowski.kdab.net (Postfix) with ESMTP id F1D4DE6C751
+ for <dfaure@kdab.net>; Tue, 3 Apr 2007 10:38:16 +0200 (CEST)
+Received: from smtp4-g19.free.fr (smtp4-g19.free.fr [212.27.42.30])
+ by smykowski.kdab.net (Postfix) with ESMTP id D7976E6C750
+ for <dfaure@kdab.net>; Tue, 3 Apr 2007 10:38:10 +0200 (CEST)
+Received: from [192.168.0.1] (lns-bzn-51f-81-56-143-51.adsl.proxad.net [81.56.143.51])
+ by smtp4-g19.free.fr (Postfix) with ESMTP id C961269606
+ for <dfaure@kdab.net>; Tue, 3 Apr 2007 10:41:56 +0200 (CEST)
+Subject: Test for aegpyten/issue734-1, OpenPGP signed
+From: Sascha Wilde <wilde@intevation.de>
+Date: Thu, 15 Mar 2007 15:16:02 +0100
+MIME-Version: 1.0
+Content-Type: multipart/signed;
+ boundary="==-=-=";
+ micalg=pgp-sha1;
+ protocol="application/pgp-signature"
+Message-Id: <20070403084156.C961269606@smtp4-g19.free.fr>
+To: undisclosed-recipients:;
+X-Virus-Scanned: by amavisd-new at kdab.net
+X-Spam-Status: Yes, score=7.598 tagged_above=3 required=6.3
+ tests=[BAYES_50=0.001, DATE_IN_PAST_96_XX=2.02, DNS_FROM_AHBL_RHSBL=0.231,
+ DNS_FROM_RFC_ABUSE=0.2, DNS_FROM_RFC_DSN=2.597, DNS_FROM_RFC_POST=1.708,
+ UNDISC_RECIPS=0.841]
+X-Spam-Score: 7.598
+X-Spam-Level: *******
+X-Spam-Flag: YES
+X-Kolab-Scheduling-Message: FALSE
+X-UID: 68768
+X-Length: 3235
+Status: RO
+X-Status: RPT
+X-KMail-EncryptionState:
+X-KMail-SignatureState:
+X-KMail-MDN-Sent:
+
+--==-=-=
+Content-Type: multipart/mixed; boundary="=-=-="
+
+--=-=-=
+
+
+Hallo Bernhard
+
+hier also die mail....
+jetzt kommt gleich der Anhang...
+3 ...
+2 ...
+1 ...
+BOOOM
+
+
+--=-=-=
+Content-Type: text/plain; charset=iso-8859-1
+Content-Disposition: attachment; filename=x.txt
+Content-Transfer-Encoding: quoted-printable
+Content-Description: Anhang
+
+
+Ein Anhang mit Text.
+Weil das wohl auch in der urspr=FCnglichen Mail so war
+
+und nicht ein wenig mehr Text, damit es nicht so langweilig ist...
+
+
+
+--=-=-=
+Content-Type: text/plain; charset=iso-8859-1
+Content-Transfer-Encoding: quoted-printable
+
+
+und hier geht der Text weiter...
+sch=F6n mit Umlaut, wie besprochen!
+
+Und das ganz nat=FCrlich signiert...
+
+und? hilft's?
+sascha
+=2D-=20
+Sascha Wilde OpenPGP key: 4BB86568
+Intevation GmbH, Osnabr=FCck http://www.intevation.de/~wilde/
+Amtsgericht Osnabr=FCck, HR B 18998 http://www.intevation.de/
+Gesch=E4ftsf=FChrer: Frank Koormann, Bernhard Reiter, Dr. Jan-Oliver Wagner
+
+--=-=-=--
+
+--==-=-=
+Content-Type: application/pgp-signature
+
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.6 (GNU/Linux)
+
+iD8DBQFF+VUtuyGFFEu4ZWgRApmZAKCGHUi440uPEggdKZoE1WHWO0ah6QCfaqLv
+HYelJfvqQQJkoW99SKRUVec=
+=AmlK
+-----END PGP SIGNATURE-----
+--==-=-=--
+
diff --git a/kmail/tests/storagelayermodule.cpp b/kmail/tests/storagelayermodule.cpp
new file mode 100644
index 000000000..91362471d
--- /dev/null
+++ b/kmail/tests/storagelayermodule.cpp
@@ -0,0 +1,16 @@
+/**
+ * Copyright (C) 2005 Till Adam <adam@kde.org>
+ *
+ * This software is under the "if you run these tests and they break you
+ * have to fix it" license.
+ */
+
+#include <kunittest/runner.h>
+#include <kunittest/module.h>
+
+#include "messagedicttests.h"
+
+using namespace KUnitTest;
+
+KUNITTEST_MODULE( kunittest_storagelayermodule, "KMail Storage Layer Tests" );
+KUNITTEST_MODULE_REGISTER_TESTER( MessageDictTester );
diff --git a/kmail/tests/utiltests.cpp b/kmail/tests/utiltests.cpp
new file mode 100644
index 000000000..6f09416ff
--- /dev/null
+++ b/kmail/tests/utiltests.cpp
@@ -0,0 +1,207 @@
+/**
+ * Copyright (C) 2007 David Faure <faure@kde.org>
+ * This file is subject to the GPL version 2.
+ */
+
+#include <kdebug.h>
+#include <kunittest/runner.h>
+#include <kunittest/module.h>
+#include "utiltests.h"
+
+using namespace KUnitTest;
+
+KUNITTEST_MODULE( kunittest_utilmodule, "KMail::Util Tests" );
+KUNITTEST_MODULE_REGISTER_TESTER( UtilTester );
+
+#include "util.h"
+#include <mimelib/string.h>
+
+
+void UtilTester::setUp()
+{
+ kdDebug() << "setUp" << endl;
+}
+
+void UtilTester::tearDown()
+{
+ kdDebug() << "tearDown" << endl;
+}
+
+static QString makePrintable( const QCString& str )
+{
+ QString a = str;
+ a = a.replace( '\r', "\\r" );
+ a = a.replace( '\n', "\\n" );
+ return a;
+}
+static QString makePrintable( const QByteArray& arr )
+{
+ QCString str;
+ KMail::Util::setFromByteArray( str, arr );
+ return makePrintable( str );
+}
+
+void UtilTester::test_lf2crlf()
+{
+ QCString src = "\nfoo\r\n\nbar\rblah\n\r\r\n\n\r";
+ QCString conv = KMail::Util::lf2crlf( src );
+ COMPARE( makePrintable( conv ), makePrintable("\r\nfoo\r\n\r\nbar\rblah\r\n\r\r\n\r\n\r") );
+ COMPARE( KMail::Util::lf2crlf( QCString("") ), QCString("") );
+
+ // QByteArray version
+ QByteArray arr; KMail::Util::setFromQCString( arr, src );
+ COMPARE( arr[arr.size()-1], '\r' );
+ QByteArray arrConv = KMail::Util::lf2crlf( arr );
+ COMPARE( arrConv[arrConv.size()-1], '\r' );
+ COMPARE( makePrintable( arrConv ), makePrintable("\r\nfoo\r\n\r\nbar\rblah\r\n\r\r\n\r\n\r") );
+ QByteArray empty;
+ arrConv = KMail::Util::lf2crlf( empty );
+ COMPARE( makePrintable( arrConv ), QString("") );
+}
+
+void UtilTester::test_crlf2lf()
+{
+ QCString src = "\r\n\r\nfoo\r\n\r\nbar\rblah\r\n\r\r\n\r\n\r";
+ int len = src.length();
+ COMPARE( src[len], '\0' );
+ int newLen = KMail::Util::crlf2lf( src.data(), len );
+ VERIFY( newLen <= len );
+ QCString cstr( src.data(), newLen + 1 );
+ COMPARE( makePrintable( cstr ), makePrintable("\n\nfoo\n\nbar\rblah\n\r\n\n\r") );
+}
+
+void UtilTester::test_escapeFrom()
+{
+ // TODO should take a DwString, then fix kmfoldermbox.cpp:1021 msgText = escapeFrom( aMsg->asString() );
+
+}
+
+void UtilTester::test_append()
+{
+ QCString test;
+ QCString str = "foo";
+ COMPARE( (int)str.size(), 4 ); // trailing nul included
+ QByteArray s1 = KMail::Util::byteArrayFromQCStringNoDetach( str );
+ COMPARE( (int)s1.size(), 3 );
+ COMPARE( (int)str.size(), 3 ); // trailing nul got removed
+ COMPARE( s1.data(), str.data() ); // yes, no detach
+ COMPARE( s1[2], 'o' );
+
+ QCString bar( "bar" );
+ QByteArray s2 = KMail::Util::byteArrayFromQCStringNoDetach( bar );
+ COMPARE( (int)s2.size(), 3 );
+
+ KMail::Util::append( s1, s2 );
+ COMPARE( (int)s1.size(), 6 );
+ KMail::Util::setFromByteArray( test, s1 );
+ COMPARE( test, QCString( "foobar" ) );
+
+ KMail::Util::append( s1, 0 ); // no-op
+ COMPARE( (int)s1.size(), 6 );
+ KMail::Util::setFromByteArray( test, s1 );
+ COMPARE( test, QCString( "foobar" ) );
+
+ KMail::Util::append( s1, "blah" );
+ COMPARE( (int)s1.size(), 10 );
+ KMail::Util::setFromByteArray( test, s1 );
+ COMPARE( test, QCString( "foobarblah" ) );
+
+ KMail::Util::append( s1, QCString( " str" ) );
+ COMPARE( (int)s1.size(), 14 );
+ KMail::Util::setFromByteArray( test, s1 );
+ COMPARE( test, QCString( "foobarblah str" ) );
+
+ QByteArray empty;
+ KMail::Util::append( empty, "a" );
+ COMPARE( (int)empty.size(), 1 );
+ COMPARE( empty[0], 'a' );
+}
+
+void UtilTester::test_insert()
+{
+ QCString test;
+ QCString str = "foo";
+ COMPARE( (int)str.size(), 4 ); // trailing nul included
+ QByteArray s1;
+ KMail::Util::setFromQCString( s1, str );
+
+ KMail::Util::insert( s1, 1, "bar" );
+ COMPARE( (int)s1.size(), 6 );
+ COMPARE( makePrintable(s1), QString( "fbaroo" ) );
+
+ KMail::Util::insert( s1, 6, "END" );
+ COMPARE( (int)s1.size(), 9 );
+ COMPARE( makePrintable(s1), QString( "fbarooEND" ) );
+
+ KMail::Util::insert( s1, 0, "BEGIN" );
+ COMPARE( (int)s1.size(), 14 );
+ COMPARE( makePrintable(s1), QString( "BEGINfbarooEND" ) );
+}
+
+void UtilTester::test_DwStringConversions( const QCString& cstr )
+{
+ // QCString->DwString->QCString
+ COMPARE( (int)cstr.size(), 8 );
+ DwString dwstr = KMail::Util::dwString( cstr );
+ COMPARE( (int)dwstr.size(), 7 );
+ COMPARE( dwstr[6], 'r' );
+ QCString cstr2 = KMail::Util::CString( dwstr );
+ COMPARE( (int)cstr2.size(), 8 );
+ COMPARE( cstr2, cstr );
+ COMPARE( cstr2[6], 'r' );
+
+ // And also QCString->QByteArray
+ QByteArray arr;
+ KMail::Util::setFromQCString( arr, cstr );
+ COMPARE( (int)arr.size(), 7 );
+ COMPARE( arr[6], 'r' );
+
+ KMail::Util::setFromQCString( arr, QCString() );
+ COMPARE( (int)arr.size(), 0 );
+
+ // DwString->QByteArray
+ QByteArray ba = KMail::Util::ByteArray( dwstr );
+ COMPARE( (int)ba.size(), 7 );
+ COMPARE( ba[6], 'r' );
+
+ ba = KMail::Util::ByteArray( DwString() );
+ COMPARE( (int)ba.size(), 0 );
+}
+
+void UtilTester::test_DwStringConversions()
+{
+ QCString cstr = "foo&bar";
+ test_DwStringConversions( cstr );
+ // now embed a nul. Note that cstr="foo\0bar" wouldn't work.
+ cstr[3] = '\0';
+ test_DwStringConversions( cstr );
+
+ cstr = QCString();
+ DwString dwstr = KMail::Util::dwString( cstr );
+ COMPARE( (int)dwstr.size(), 0 );
+ VERIFY( dwstr.empty() );
+
+ dwstr = KMail::Util::dwString( QByteArray() );
+ COMPARE( (int)dwstr.size(), 0 );
+ VERIFY( dwstr.empty() );
+}
+
+void UtilTester::test_QByteArrayQCString()
+{
+ QCString str = "foobar";
+ COMPARE( (int)str.size(), 7 ); // trailing nul included
+ QByteArray s1 = KMail::Util::byteArrayFromQCStringNoDetach( str );
+ COMPARE( (int)str.size(), 6 ); // trailing nul got removed
+ COMPARE( s1.data(), str.data() ); // yes, no detach
+ COMPARE( s1[5], 'r' );
+ COMPARE( str[5], 'r' );
+
+ KMail::Util::restoreQCString( str );
+ COMPARE( (int)str.size(), 7 ); // trailing nul included
+ COMPARE( str[5], 'r' );
+ COMPARE( str[6], '\0' );
+
+}
+
+#include "utiltests.moc"
+
diff --git a/kmail/tests/utiltests.h b/kmail/tests/utiltests.h
new file mode 100644
index 000000000..58de40901
--- /dev/null
+++ b/kmail/tests/utiltests.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2007 David Faure <faure@kde.org>
+ *
+ * This file is subject to the GPL version 2.
+ */
+
+#ifndef UTILTESTS_H
+#define UTILTESTS_H
+
+#include <kunittest/tester.h>
+
+class UtilTester : public KUnitTest::SlotTester
+{
+ Q_OBJECT
+
+public slots:
+ void setUp();
+ void tearDown();
+ void test_lf2crlf();
+ void test_crlf2lf();
+ void test_escapeFrom();
+ void test_append();
+ void test_insert();
+ void test_DwStringConversions();
+ void test_QByteArrayQCString();
+private:
+ void test_DwStringConversions( const QCString& cstr );
+};
+
+#endif