Page MenuHomePhorge

bindingstest.cpp
No OneTemporary

Authored By
Unknown
Size
18 KB
Referenced Files
None
Subscribers
None

bindingstest.cpp

#include "bindingstest.h"
#include <QObject>
#include <QtTest/QtTest>
#include "bindings/iCalendar-props.hxx"
#include "bindings/iCalendar-valtypes.hxx"
#include "bindings/kolabformat.hxx"
#include <iostream>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <lib/kolabformat.h>
#include <kdebug.h>
#include <lib/kolabkcalconversion.h>
#include <iostream>
#include <fstream>
#include "serializers.h"
#include <lib/utils.h>
#include <lib/kolabjournal.h>
void BindingsTest::noteCompletness()
{
Kolab::Note note;
note.setUid("UID");
note.setCreated(Kolab::cDateTime(2006,1,6,12,0,0)); //UTC
note.setClassification(Kolab::ClassConfidential);
note.addCategory("Category");
note.setSummary("summary");
note.setDescription("description");
note.setColor("color");
const std::string &result = Kolab::writeNote(note);
std::cout << result << std::endl;
const Kolab::Note &re = Kolab::readNote(result, false);
QCOMPARE(re.uid(), note.uid());
QCOMPARE(re.created(), note.created());
QCOMPARE(re.classification(), note.classification());
QCOMPARE(re.categories(), note.categories());
QCOMPARE(re.summary(), note.summary());
QCOMPARE(re.description(), note.description());
QCOMPARE(re.color(), note.color());
}
// void BindingsTest::eventCompletness_data()
template <typename T>
void setIncidence(T &ev)
{
ev.setUid("UID");
ev.setCreated(Kolab::cDateTime(2006,1,6,12,0,0)); //UTC
ev.setSequence(1);
ev.setClassification(Kolab::ClassConfidential);
ev.addCategory("Category");
ev.setStart(Kolab::cDateTime("Europe/Zurich", 2006,1,6,12,0,0));
Kolab::RecurrenceRule rule;
rule.setFrequency(Kolab::RecurrenceRule::Daily);
rule.setCount(5);
std::vector<int> list;
list.push_back(1);
list.push_back(3);
rule.setBysecond(list);
rule.setByminute(list);
rule.setByhour(list);
std::vector<Kolab::DayPos> byday;
byday.push_back(Kolab::DayPos(15, Kolab::Friday));
byday.push_back(Kolab::DayPos(0, Kolab::Monday));
byday.push_back(Kolab::DayPos(-3, Kolab::Monday));
rule.setByday(byday);
rule.setBymonthday(list);
rule.setByyearday(list);
rule.setByweekno(list);
rule.setBymonth(list);
ev.setRecurrenceRule(rule);
ev.addRecurrenceDate(Kolab::cDateTime("Europe/Zurich", 2006,1,6,12,0,0));
ev.addExceptionDate(Kolab::cDateTime("Europe/Zurich", 2006,1,6,12,0,0));
ev.setRecurrenceID(Kolab::cDateTime("Europe/Zurich", 2006,1,6,12,0,0), true);
ev.setSummary("summary");
ev.setDescription("description");
ev.setPriority(3);
ev.setStatus(Kolab::StatusConfirmed);
ev.setLocation("location");
ev.setOrganizer("email","organizer");
Kolab::Attendee attendee("email");
attendee.setName("name");
attendee.setPartStat(Kolab::PartDelegated);
attendee.setRole(Kolab::Chair);
attendee.setRSVP(true);
attendee.setUid("uid");
ev.setAttendees(std::vector<Kolab::Attendee>() << attendee << attendee);
std::vector<Kolab::Attachment> attachments;
Kolab::Attachment attach;
attach.setData("data????*?*?*?*?*?", "mimetype");
attach.setLabel("label");
attachments.push_back(attach);
Kolab::Attachment attach2;
attach2.setUri("../../tests/testfiles/icalEvent.xml", "mimetype");
attach2.setLabel("labe2l");
attachments.push_back(attach2);
Kolab::Attachment attach3;
using namespace std;
ifstream file ("../../tests/testfiles/icalEvent.xml", ios::in|ios::binary|ios::ate);
if (file.is_open()) {
int size = file.tellg();
char *memblock = new char [size];
file.seekg (0, ios::beg);
file.read (memblock, size);
file.close();
attach3.setData(string(memblock, size), "mimetype");
delete[] memblock;
}
attach3.setLabel("labe3l");
attachments.push_back(attach3);
ev.setAttachments(attachments);
std::vector<Kolab::CustomProperty> properties;
properties.push_back(Kolab::CustomProperty("ident", "value"));
properties.push_back(Kolab::CustomProperty("ident", "value"));
ev.setCustomProperties(properties);
std::vector<Kolab::Alarm> alarms;
Kolab::Alarm dispAlarm("ident");
dispAlarm.setRelativeStart(Kolab::Duration(3, true), Kolab::Start);
alarms.push_back(dispAlarm);
std::vector<std::string> att;
att.push_back("attendee1");
att.push_back("attendee2");
Kolab::Alarm emailAlarm("ident", "value", att);
emailAlarm.setStart(Kolab::cDateTime(2003,2,3,2,3,4, true));
alarms.push_back(emailAlarm);
Kolab::Attachment audiofile;
audiofile.setUri("ksdjlksdflj", "sdkljdfl");
Kolab::Alarm audio(audiofile);
audio.setStart(Kolab::cDateTime(2003,2,3,2,3,4, true));
alarms.push_back(audio);
ev.setAlarms(alarms);
}
template <typename T>
void checkIncidence(const T &ev, const T &re)
{
//Common to all
QCOMPARE(ev.uid(), re.uid());
QCOMPARE(ev.created(), re.created());
QVERIFY(re.lastModified().isValid()); //TODO can we check this better?
QCOMPARE(ev.sequence(), re.sequence());
QCOMPARE(ev.classification(), re.classification());
QCOMPARE(ev.categories(), re.categories());
QCOMPARE(ev.start(), re.start());
//Recurrence
const Kolab::RecurrenceRule &r1 = ev.recurrenceRule();
const Kolab::RecurrenceRule &r2 = re.recurrenceRule();
QCOMPARE(r1.isValid(), r2.isValid());
QCOMPARE(r1.frequency(), r2.frequency());
QCOMPARE(r1.interval(), r2.interval());
QCOMPARE(r1.weekStart(), r2.weekStart());
QCOMPARE(r1.count(), r2.count());
QCOMPARE(r1.end(), r2.end());
QCOMPARE(r1.bysecond(), r2.bysecond());
QCOMPARE(r1.byminute(), r2.byminute());
QCOMPARE(r1.byhour(), r2.byhour());
QCOMPARE(r1.byday(), r2.byday());
QCOMPARE(r1.bymonthday(), r2.bymonthday());
QCOMPARE(r1.byyearday(), r2.byyearday());
QCOMPARE(r1.byweekno(), r2.byweekno());
QCOMPARE(r1.bymonth(), r2.bymonth());
//Rest
QCOMPARE(ev.recurrenceDates(), re.recurrenceDates());
QCOMPARE(ev.exceptionDates(), re.exceptionDates());
QCOMPARE(ev.recurrenceID(), re.recurrenceID());
QCOMPARE(ev.thisAndFuture(), re.thisAndFuture());
QCOMPARE(ev.summary(), re.summary());
QCOMPARE(ev.description(), re.description());
QCOMPARE(ev.priority(), re.priority());
QCOMPARE(ev.status(), re.status());
QCOMPARE(ev.location(), re.location());
QCOMPARE(ev.organizerEmail(), re.organizerEmail());
QCOMPARE(ev.organizerName(), re.organizerName());
QCOMPARE(ev.attendees(), re.attendees());
QCOMPARE(ev.attachments(), re.attachments());
QCOMPARE(ev.customProperties(), re.customProperties());
QCOMPARE(ev.alarms(), re.alarms());
}
void BindingsTest::eventCompletness()
{
Kolab::Event ev;
setIncidence(ev);
ev.setEnd(Kolab::cDateTime("Europe/Zurich", 2006,1,8,12,0,0));
ev.setTransparency(true);
std::string result = Kolab::writeEvent(ev);
QVERIFY(Kolab::error() == Kolab::NoError);
// std::cout << result << endl;
Kolab::Event e = Kolab::readEvent(result, false);
QVERIFY(Kolab::error() == Kolab::NoError);
checkIncidence(ev, e);
QCOMPARE(ev.end(), e.end());
QCOMPARE(ev.transparency(), e.transparency());
}
void BindingsTest::eventDuration()
{
Kolab::Event ev;
ev.setStart(Kolab::cDateTime("Europe/Zurich", 2006,1,8,12,0,0));
ev.setDuration(Kolab::Duration(11,22,33,44, true));
const std::string result = Kolab::writeEvent(ev);
QVERIFY(Kolab::error() == Kolab::NoError);
// std::cout << result << endl;
const Kolab::Event e = Kolab::readEvent(result, false);
QVERIFY(Kolab::error() == Kolab::NoError);
QVERIFY(ev.duration().isValid());
QCOMPARE(ev.duration(), e.duration());
}
void BindingsTest::todoCompletness()
{
Kolab::Todo ev;
setIncidence(ev);
ev.setDue(Kolab::cDateTime("Europe/Zurich", 2006,1,8,12,0,0));
ev.addRelatedTo("rel1");
ev.addRelatedTo("rel2");
ev.setPercentComplete(50);
std::string result = Kolab::writeTodo(ev);
QVERIFY(Kolab::error() == Kolab::NoError);
// std::cout << result << endl;
Kolab::Todo e = Kolab::readTodo(result, false);
QVERIFY(Kolab::error() == Kolab::NoError);
checkIncidence(ev, e);
QCOMPARE(ev.due(), e.due());
QCOMPARE(ev.relatedTo(), e.relatedTo());
QCOMPARE(ev.percentComplete(), e.percentComplete());
}
void BindingsTest::journalCompletness()
{
Kolab::Journal ev;
ev.setUid("UID");
ev.setCreated(Kolab::cDateTime(2006,1,6,12,0,0)); //UTC
ev.setSequence(1);
ev.setClassification(Kolab::ClassConfidential);
ev.addCategory("Category");
ev.setStart(Kolab::cDateTime("Europe/Zurich", 2006,1,6,12,0,0));
Kolab::Attendee attendee("email");
attendee.setName("name");
attendee.setPartStat(Kolab::PartDelegated);
attendee.setRole(Kolab::Chair);
attendee.setRSVP(true);
attendee.setUid("uid");
ev.setAttendees(std::vector<Kolab::Attendee>() << attendee << attendee);
std::vector<Kolab::Attachment> attachments;
Kolab::Attachment attach;
attach.setData("data????*?*?*?*?*?", "mimetype");
attach.setLabel("label");
attachments.push_back(attach);
Kolab::Attachment attach2;
attach2.setUri("../../tests/testfiles/icalEvent.xml", "mimetype");
attach2.setLabel("labe2l");
attachments.push_back(attach2);
Kolab::Attachment attach3;
using namespace std;
ifstream file ("../../tests/testfiles/icalEvent.xml", ios::in|ios::binary|ios::ate);
if (file.is_open()) {
int size = file.tellg();
char *memblock = new char [size];
file.seekg (0, ios::beg);
file.read (memblock, size);
file.close();
attach3.setData(string(memblock, size), "mimetype");
delete[] memblock;
}
attach3.setLabel("labe3l");
attachments.push_back(attach3);
ev.setAttachments(attachments);
std::vector<Kolab::CustomProperty> properties;
properties.push_back(Kolab::CustomProperty("ident", "value"));
properties.push_back(Kolab::CustomProperty("ident", "value"));
ev.setCustomProperties(properties);
std::string result = Kolab::writeJournal(ev);
QVERIFY(Kolab::error() == Kolab::NoError);
// std::cout << result << endl;
Kolab::Journal re = Kolab::readJournal(result, false);
QVERIFY(Kolab::error() == Kolab::NoError);
QCOMPARE(ev.uid(), re.uid());
QCOMPARE(ev.created(), re.created());
QVERIFY(re.lastModified().isValid()); //TODO can we check this better?
QCOMPARE(ev.sequence(), re.sequence());
QCOMPARE(ev.classification(), re.classification());
QCOMPARE(ev.categories(), re.categories());
QCOMPARE(ev.start(), re.start());
QCOMPARE(ev.summary(), re.summary());
QCOMPARE(ev.description(), re.description());
QCOMPARE(ev.status(), re.status());
QCOMPARE(ev.attendees(), re.attendees());
QCOMPARE(ev.attachments(), re.attachments());
QCOMPARE(ev.customProperties(), re.customProperties());
}
void BindingsTest::contactCompletness()
{
std::vector<std::string> stringlist;
stringlist.push_back("lbksdfbklsd");
stringlist.push_back("sdf");
Kolab::Contact c;
c.setUid("urn:uuid:1045b57d-ff7f-0000-d814-867b4d7f0000");
c.setCategories(stringlist);
c.setName("name");
Kolab::NameComponents nc;
nc.setSurnames(stringlist);
nc.setGiven(stringlist);
nc.setAdditional(stringlist);
nc.setPrefixes(stringlist);
nc.setSuffixes(stringlist);
c.setNameComponents(nc);
c.setNote("note");
c.setFreeBusyUrl("freebusy");
c.setUrls(stringlist);
c.setNickNames(stringlist);
c.setBDay(Kolab::cDateTime(2001,12,10,12,12,12,false));
c.setAnniversary(Kolab::cDateTime(2001,3,2,1,1,1,false));
c.setPhoto("photo", "mimetype");
c.setGender(Kolab::Contact::Male);
c.setLanguages(stringlist);
c.setIMaddresses(stringlist,1);
c.setEmailAddresses(stringlist,1);
std::vector<Kolab::Affiliation> list;
Kolab::Affiliation aff;
aff.setOrganisation("org");
aff.setLogo("logo", "mime/miem");
aff.setTitles(stringlist);
aff.setRoles(stringlist);
aff.setManagers(stringlist);
aff.setAssistants(stringlist);
aff.setOffices(stringlist);
list.push_back(aff);
Kolab::Affiliation aff2;
list.push_back(aff2);
c.setAffiliations(list);
Kolab::Address address;
address.setCode("oiuoiu");
address.setCountry("werwer");
address.setLabel("lkjlkj");
address.setLocality("alla");
address.setRegion("skjdfkd");
address.setStreet("sldkflsdfj");
address.setTypes( Kolab::Address::Work | Kolab::Address::Home );
std::vector<Kolab::Address> addresses;
addresses.push_back(address);
addresses.push_back(address);
c.setAddresses(addresses);
Kolab::Telephone phone;
phone.setNumber("lkjsdflkjfds");
phone.setTypes(Kolab::Telephone::Work|
Kolab::Telephone::Home|
Kolab::Telephone::Text|
Kolab::Telephone::Voice|
Kolab::Telephone::Fax|
Kolab::Telephone::Cell|
Kolab::Telephone::Video|
Kolab::Telephone::Pager|
Kolab::Telephone::Textphone|
Kolab::Telephone::Car
);
std::vector<Kolab::Telephone> telephones;
telephones.push_back(phone);
telephones.push_back(phone);
c.setTelephones(telephones, 1);
// c.setGPSpos(stringlist,1);
std::vector<Kolab::CustomProperty> properties;
properties.push_back(Kolab::CustomProperty("ident", "value"));
properties.push_back(Kolab::CustomProperty("ident", "value"));
c.setCustomProperties(properties);
const std::string result = Kolab::writeContact(c);
QVERIFY(Kolab::error() == Kolab::NoError);
// std::cout << result << endl;
Kolab::Contact e = Kolab::readContact(result, false);
QVERIFY(Kolab::error() == Kolab::NoError);
QCOMPARE(e.uid(), c.uid());
QCOMPARE(e.categories(), c.categories());
QCOMPARE(e.name(), c.name());
QCOMPARE(e.nameComponents(), c.nameComponents());
QCOMPARE(e.note(), c.note());
QCOMPARE(e.freeBusyUrl(), c.freeBusyUrl());
QCOMPARE(e.affiliations(), c.affiliations());
QCOMPARE(e.urls(), c.urls());
QCOMPARE(e.addresses(), c.addresses());
QCOMPARE(e.addressPreferredIndex(), c.addressPreferredIndex());
QCOMPARE(e.nickNames(), c.nickNames());
// QCOMPARE(e.relateds(), c.relateds());
QCOMPARE(e.bDay(), c.bDay());
QCOMPARE(e.anniversary(), c.anniversary());
QCOMPARE(e.photo(), c.photo());
QCOMPARE(e.photoMimetype(), c.photoMimetype());
QCOMPARE(e.gender(), c.gender());
QCOMPARE(e.languages(), c.languages());
QCOMPARE(e.telephones(), c.telephones());
QCOMPARE(e.telephonesPreferredIndex(), c.telephonesPreferredIndex());
QCOMPARE(e.imAddresses(), c.imAddresses());
QCOMPARE(e.imAddressPreferredIndex(), c.imAddressPreferredIndex());
QCOMPARE(e.emailAddresses(), c.emailAddresses());
QCOMPARE(e.emailAddressPreferredIndex(), c.emailAddressPreferredIndex());
// QCOMPARE(e.gpsPos(), c.gpsPos());
// QCOMPARE(e.crypto(), c.crypto());
QCOMPARE(e.customProperties(), c.customProperties());
}
void BindingsTest::distlistCompletness()
{
std::vector<std::string> stringlist;
stringlist.push_back("lbksdfbklsd");
stringlist.push_back("sdf");
Kolab::DistList c;
c.setName("name");
c.setUid("uid");
std::vector<Kolab::Member> members;
members.push_back(Kolab::Member("email@email.com"));
Kolab::Member m2("email2@email.com");
m2.setName("name todo");
m2.setUid("uid");
members.push_back(m2);
c.setMembers(members);
std::vector<Kolab::CustomProperty> properties;
properties.push_back(Kolab::CustomProperty("ident", "value"));
properties.push_back(Kolab::CustomProperty("ident", "value"));
c.setCustomProperties(properties);
const std::string result = Kolab::writeDistlist(c);
QVERIFY(Kolab::error() == Kolab::NoError);
// std::cout << result << endl;
Kolab::DistList e = Kolab::readDistlist(result, false);
QVERIFY(Kolab::error() == Kolab::NoError);
QCOMPARE(e.uid(), c.uid());
QCOMPARE(e.name(), c.name());
QCOMPARE(e.members(), c.members());
QCOMPARE(e.customProperties(), c.customProperties());
}
void BindingsTest::versionTest()
{
Kolab::Todo ev;
setIncidence(ev);
std::string result = Kolab::writeTodo(ev);
Kolab::Todo e = Kolab::readTodo(result, false);
QCOMPARE(Kolab::productId(), std::string(Kolab::KOLAB_LIBNAME) + std::string(Kolab::KOLAB_LIB_VERSION));
QCOMPARE(Kolab::xKolabVersion(), std::string(Kolab::KOLAB_FORMAT_VERSION));
QCOMPARE(Kolab::xCalVersion(), std::string("2.0"));
}
void BindingsTest::errorTest()
{
Kolab::Todo e = Kolab::readTodo("klbsdfbklsdbkl", false);
QCOMPARE(Kolab::error(), Kolab::Critical);
QVERIFY(!Kolab::errorMessage().empty());
}
//Don't break due to an error
void BindingsTest::errorRecoveryTest()
{
Kolab::Todo e = Kolab::readTodo("klbsdfbklsdbkl", false);
QCOMPARE(Kolab::error(), Kolab::Critical);
Kolab::Todo ev;
setIncidence(ev);
const std::string result = Kolab::writeTodo(ev);
Kolab::readTodo(result, false);
QCOMPARE(Kolab::error(), Kolab::NoError);
}
void BindingsTest::BenchmarkRoundtripKolab()
{
const Kolab::Event &event = Kolab::readEvent("../../tests/testfiles/icalEvent.xml", true);
std::string result = Kolab::writeEvent(event);
QBENCHMARK {
Kolab::readEvent(result, false);
}
}
void BindingsTest::BenchmarkRoundtripKCAL()
{
const Kolab::Event &event = Kolab::readEvent("../../tests/testfiles/icalEvent.xml", true);
std::string result = Kolab::writeEvent(event);
QBENCHMARK {
Kolab::KCalConversion::toKCalCore(Kolab::readEvent(result, false));
}
}
void BindingsTest::BenchmarkRoundtrip()
{
const Kolab::Event &event = Kolab::readEvent("../../tests/testfiles/icalEvent.xml", true);
std::string result;
QBENCHMARK {
result = Kolab::writeEvent(event);
Kolab::readEvent(result, false);
}
}
QTEST_MAIN( BindingsTest )
#include "bindingstest.moc"

File Metadata

Mime Type
text/x-c++
Expires
Sat, Apr 4, 3:00 AM (4 d, 13 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18822326
Default Alt Text
bindingstest.cpp (18 KB)

Event Timeline