summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2013-01-02 13:19:38 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2013-01-02 13:19:38 (GMT)
commit2befab0a53b6794020e750cab2e3a5feae1de412 (patch)
treeed0f6927daf75ad790fc8b357b8f46559c1e3c77 /tests
parentb2aaea7035eb6915ccaf9c4cb9091323edaae62b (diff)
downloadlibkolab-2befab0a53b6794020e750cab2e3a5feae1de412.tar.gz
Use the correct kolab type for distlists + test.
Diffstat (limited to 'tests')
-rw-r--r--tests/formattest.cpp79
-rw-r--r--tests/formattest.h3
-rw-r--r--tests/testfiles/v3/contacts/distlist.vcf5
-rw-r--r--tests/testfiles/v3/contacts/distlist.vcf.mime18
-rw-r--r--tests/testutils.h1
5 files changed, 92 insertions, 14 deletions
diff --git a/tests/formattest.cpp b/tests/formattest.cpp
index 9e2613c..5354920 100644
--- a/tests/formattest.cpp
+++ b/tests/formattest.cpp
@@ -29,6 +29,7 @@
#include <kcalcore/icalformat.h>
#include <kabc/vcardconverter.h>
+#include <kabc/contactgrouptool.h>
#include <akonadi/notes/noteutils.h>
#include "testutils.h"
@@ -280,6 +281,72 @@ void FormatTest::testContact()
QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug);
}
+void FormatTest::testDistlist_data()
+{
+ QTest::addColumn<Kolab::Version>( "version" );
+ QTest::addColumn<Kolab::ObjectType>( "type" );
+ QTest::addColumn<QString>( "vcardFileName" );
+ QTest::addColumn<QString>( "mimeFileName" );
+
+ QTest::newRow( "v3distlistSimple" ) << Kolab::KolabV3 << Kolab::DistlistObject << TESTFILEDIR+QString::fromLatin1("v3/contacts/distlist.vcf") << TESTFILEDIR+QString::fromLatin1("v3/contacts/distlist.vcf.mime");
+}
+
+void FormatTest::testDistlist()
+{
+ QFETCH( Kolab::Version, version );
+ QFETCH( Kolab::ObjectType, type );
+ QFETCH( QString, vcardFileName ); //To compare
+ QFETCH( QString, mimeFileName ); //For parsing
+
+ //Parse mime message
+ bool ok = false;
+ const KMime::Message::Ptr &msg = readMimeFile( mimeFileName, ok );
+ QVERIFY(ok);
+ Kolab::KolabObjectReader reader;
+ Kolab::ObjectType t = reader.parseMimeMessage(msg);
+ QCOMPARE(t, type);
+ QCOMPARE(reader.getVersion(), version);
+ QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug);
+
+ KABC::ContactGroup convertedAddressee = reader.getDistlist();
+
+ //Parse vcard
+ QFile vcardFile( vcardFileName );
+ QVERIFY( vcardFile.open( QFile::ReadOnly ) );
+ KABC::VCardConverter converter;
+ QByteArray c = vcardFile.readAll();
+ QBuffer data(&c);
+ data.open(QIODevice::ReadOnly);
+
+ KABC::ContactGroup realAddressee;
+ KABC::ContactGroupTool::convertFromXml( &data, realAddressee );
+
+ {
+ QBuffer expected;
+ expected.open(QIODevice::WriteOnly);
+ KABC::ContactGroupTool::convertToXml(realAddressee, &expected);
+
+ QBuffer converted;
+ converted.open(QIODevice::WriteOnly);
+ KABC::ContactGroupTool::convertToXml(convertedAddressee, &converted);
+
+ showDiff(expected.buffer(), converted.buffer());
+ }
+ QCOMPARE( realAddressee, convertedAddressee );
+
+ //Write
+ const KMime::Message::Ptr &convertedMime = Kolab::KolabObjectWriter::writeDistlist(realAddressee, version);
+
+ if ( !compareMimeMessage( convertedMime, msg )) {
+ QString expected = msg->encodedContent();
+ normalizeMimemessage(expected);
+ QString converted = convertedMime->encodedContent();
+ normalizeMimemessage(converted);
+ showDiff(expected, converted);
+ QVERIFY( false );
+ }
+ QCOMPARE(Kolab::ErrorHandler::instance().error(), Kolab::ErrorHandler::Debug);
+}
void FormatTest::testNote_data()
{
@@ -377,6 +444,18 @@ void FormatTest::generateVCard()
// KABC::Addressee convertedAddressee = reader.getContact();
// KABC::VCardConverter converter;
// qDebug() << converter.createVCard(convertedAddressee);
+
+// bool ok = false;
+// const KMime::Message::Ptr &msg = readMimeFile( TESTFILEDIR+QString::fromLatin1("v3/contacts/distlist.vcf.mime"), ok );
+// qDebug() << msg->encodedContent();
+// Kolab::KolabObjectReader reader;
+// Kolab::ObjectType t = reader.parseMimeMessage(msg);
+//
+// KABC::ContactGroup convertedAddressee = reader.getDistlist();
+// QBuffer buf;
+// buf.open(QIODevice::WriteOnly);
+// KABC::ContactGroupTool::convertToXml(convertedAddressee, &buf);
+// qDebug() << buf.buffer();
}
//Pseudo test to show that JPG is always lossy, even with quality set to 100
diff --git a/tests/formattest.h b/tests/formattest.h
index 12655fb..8097bfc 100644
--- a/tests/formattest.h
+++ b/tests/formattest.h
@@ -55,6 +55,9 @@ private slots:
void testContact_data();
void testContact();
+
+ void testDistlist_data();
+ void testDistlist();
void testNote_data();
void testNote();
diff --git a/tests/testfiles/v3/contacts/distlist.vcf b/tests/testfiles/v3/contacts/distlist.vcf
new file mode 100644
index 0000000..cc4984c
--- /dev/null
+++ b/tests/testfiles/v3/contacts/distlist.vcf
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<contactGroup uid="4xuyC0cyjV" name="My Distlist">
+ <contactData name="John Doe" email="jdoe@example.com"/>
+ <contactData name="John Doe2" email="jdoe2@example.com"/>
+</contactGroup> \ No newline at end of file
diff --git a/tests/testfiles/v3/contacts/distlist.vcf.mime b/tests/testfiles/v3/contacts/distlist.vcf.mime
index d54c26c..372728e 100644
--- a/tests/testfiles/v3/contacts/distlist.vcf.mime
+++ b/tests/testfiles/v3/contacts/distlist.vcf.mime
@@ -1,10 +1,9 @@
Date: Mon, 23 Apr 2012 12:46:37 +0200
-X-Kolab-Type: application/x-vnd.kolab.distribution-list
+X-Kolab-Type: application/x-vnd.kolab.contact.distlist
X-Kolab-Mime-Version: 3.0
User-Agent: Libkolab-0.1.0
Content-Type: multipart/mixed; boundary="nextPart1365947.WmFcbPlLFA"
Subject: 4xuyC0cyjV
-From: Volker Krause <vkrause@kde.org>
MIME-Version: 1.0
@@ -38,10 +37,6 @@ Content-Disposition: attachment; filename="kolab.xml"
<rev>
<timestamp>20120505T050505Z</timestamp>
</rev>
- <categories>
- <text>cat1</text>
- <text>cat2</text>
- </categories>
<kind>
<text>group</text>
</kind>
@@ -49,18 +44,13 @@ Content-Disposition: attachment; filename="kolab.xml"
<text>My Distlist</text>
</fn>
<member>
- <uri>mailto:John%20Doe%3cjdoe@example.com%3e</uri>
+ <uri>mailto:John%20Doe%3Cjdoe%40example.com%3E</uri>
</member>
<member>
- <uri>mailto:John%20Doe2%3cjdoe2@example.com%3e</uri>
+ <uri>mailto:John%20Doe2%3Cjdoe2%40example.com%3E</uri>
</member>
- <x-custom>
- <identifier>X-Identifier</identifier>
- <value>TestValue</value>
- </x-custom>
-
</vcard>
</vcards>
---nextPart1365947.WmFcbPlLFA-- \ No newline at end of file
+--nextPart1365947.WmFcbPlLFA--
diff --git a/tests/testutils.h b/tests/testutils.h
index 24f1db5..d61ec22 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -96,6 +96,7 @@ void normalizeMimemessage(QString &content)
content.replace(QRegExp("\\bLibkolabxml-\\d.\\d\\b", Qt::CaseSensitive), "Libkolabxml-x.x.x");
content.replace(QRegExp("<uri>cid:*@kolab.resource.akonadi</uri>", Qt::CaseSensitive, QRegExp::Wildcard), "<uri>cid:id@kolab.resource.akonadi</uri>");
content.replace(QRegExp("<last-modification-date>*</last-modification-date>", Qt::CaseSensitive, QRegExp::Wildcard), "<last-modification-date></last-modification-date>");
+ content.replace(QRegExp("<timestamp>*</timestamp>", Qt::CaseSensitive, QRegExp::Wildcard), "<timestamp></timestamp>");
content.replace(QRegExp("--nextPart\\S*", Qt::CaseSensitive), "--part");
content.replace(QRegExp("\\bboundary=\"nextPart[^\\n]*", Qt::CaseSensitive), "boundary");