Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117754013
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
54 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/c++/lib/kolabcontact.h b/c++/lib/kolabcontact.h
index e0f35ec..f1b2441 100644
--- a/c++/lib/kolabcontact.h
+++ b/c++/lib/kolabcontact.h
@@ -1,306 +1,310 @@
/*
* Copyright (C) 2011 Christian Mollekopf <mollekopf@kolabsys.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KOLABCONTACT_H
#define KOLABCONTACT_H
#include <string>
#include <vector>
#include <boost/scoped_ptr.hpp>
#include "kolabcontainers.h"
namespace Kolab {
struct NameComponents {
bool operator==(const NameComponents &other) const { return mSurnames == other.mSurnames &&
mGiven == other.mGiven &&
mAdditional == other.mAdditional &&
mPrefixes == other.mPrefixes &&
mSuffixes == other.mSuffixes;
};
void setSurnames(const std::vector<std::string> &s) { mSurnames = s; };
std::vector<std::string> surnames() const { return mSurnames; };
void setGiven(const std::vector<std::string> &s) { mGiven = s; };
std::vector<std::string> given() const { return mGiven; };
void setAdditional(const std::vector<std::string> &s) { mAdditional = s; };
std::vector<std::string> additional() const { return mAdditional; };
void setPrefixes(const std::vector<std::string> &s) { mPrefixes = s; };
std::vector<std::string> prefixes() const { return mPrefixes; };
void setSuffixes(const std::vector<std::string> &s) { mSuffixes = s; };
std::vector<std::string> suffixes() const { return mSuffixes; };
bool isValid() const { return !(mSurnames.empty() && mGiven.empty() && mAdditional.empty() && mPrefixes.empty() && mSuffixes.empty()); };
private:
std::vector<std::string> mSurnames;
std::vector<std::string> mGiven;
std::vector<std::string> mAdditional;
std::vector<std::string> mPrefixes;
std::vector<std::string> mSuffixes;
};
struct Affiliation {
bool operator==(const Affiliation &other) const { return mOrg == other.mOrg &&
mLogo == other.mLogo &&
+ mLogoMimetype == other.mLogoMimetype &&
mTitles == other.mTitles &&
mRoles == other.mRoles &&
mManagers == other.mManagers &&
mAssistants == other.mAssistants &&
mOffices == other.mOffices;
};
void setOrganisation(const std::string &org) { mOrg = org; };
std::string organisation() const { return mOrg; };
// void setOrganisationalUnits(const std::vector<std::string> &units);
- void setLogo(const std::string &l) { mLogo = l; };
+ void setLogo(const std::string &l, const std::string mimetype) { mLogo = l; mLogoMimetype = mimetype; };
std::string logo() const { return mLogo; };
+ std::string logoMimetype() const { return mLogoMimetype; };
+
void setTitles(const std::vector<std::string> &titles) { mTitles = titles; };
std::vector<std::string> titles() const { return mTitles; };
void setRoles(const std::vector<std::string> &roles) { mRoles = roles; };
std::vector<std::string> roles() const { return mRoles; };
void setManagers(const std::vector<std::string> &managers) { mManagers = managers; };
std::vector<std::string> managers() const { return mManagers; };
void setAssistants(const std::vector<std::string> &assistants) { mAssistants = assistants; };
std::vector<std::string> assistants() const { return mAssistants; };
void setOffices(const std::vector<std::string> &offices) { mOffices = offices; };
std::vector<std::string> offices() const { return mOffices; };
private:
std::string mOrg;
std::vector<std::string> mOrgUnits;
std::string mLogo;
+ std::string mLogoMimetype;
std::vector<std::string> mTitles;
std::vector<std::string> mRoles;
std::vector<std::string> mManagers;
std::vector<std::string> mAssistants;
std::vector<std::string> mOffices;
};
struct Address {
Address(): mTypes(0) {};
enum Type {
Work = 0x01,
Home = 0x02
};
bool operator==(const Address &other) const { return mTypes == other.mTypes &&
mLabel == other.mLabel &&
mStreet == other.mStreet &&
mLocality == other.mLocality &&
mRegion == other.mRegion &&
mCode == other.mCode &&
mCountry == other.mCountry;
};
void setTypes(int t) { mTypes = t; };
int types() const { return mTypes; };
void setLabel(const std::string &s) { mLabel = s; };
std::string label() const { return mLabel; }
void setStreet(const std::string &s) { mStreet = s; };
std::string street() const { return mStreet; };
void setLocality(const std::string &s) { mLocality = s; };
std::string locality() const { return mLocality; };
void setRegion(const std::string &s) { mRegion = s; };
std::string region() const { return mRegion; };
void setCode(const std::string &s) { mCode = s; };
std::string code() const { return mCode; };
void setCountry(const std::string &s) { mCountry = s; };
std::string country() const { return mCountry; };
private:
int mTypes;
std::string mLabel;
std::string mStreet;
std::string mLocality;
std::string mRegion;
std::string mCode;
std::string mCountry;
};
struct Related {
// void setUri(const std::string &);
// std::string uri() const;
// void setText(const std::string &);
// std::string text() const;
// enum Type {
// Child,
// Spouse
// };
// void setType(Type t) { type = t; };
// Type type() const { return type; };
// private:
// std::string uri;
// std::string text;
// Type type;
};
struct Telephone {
enum Type {
Work = 0x01,
Home = 0x02,
Text = 0x04,
Voice = 0x08,
Fax = 0x10,
Cell = 0x20,
Video = 0x40,
Pager = 0x80,
Textphone = 0x100,
Car = 0x200
};
Telephone(): mType(0){};
bool operator==(const Telephone &other) const { return mNumber == other.mNumber &&
mType == other.mType;
};
void setTypes(int t) { mType = t; };
int types() const { return mType; };
void setNumber(const std::string &n) { mNumber = n; };
std::string number() const { return mNumber; };
private:
std::string mNumber;
int mType;
};
struct Crypto {
};
class DistList {
public:
DistList();
~DistList();
DistList(const DistList &);
void operator=(const DistList &);
void setUid(const std::string &);
std::string uid() const;
void setLastModified(const DateTime &);
DateTime lastModified() const;
void setName(const std::string &);
std::string name() const;
void setMembers(const std::vector<std::string> members);
std::vector<std::string> members() const;
void setCustomProperties(const std::vector<CustomProperty> &);
std::vector<CustomProperty> customProperties() const;
private:
struct Private;
boost::scoped_ptr<Private> d;
};
class Contact {
public:
Contact();
~Contact();
Contact(const Contact &);
void operator=(const Contact &);
void setUid(const std::string &);
std::string uid() const;
void setLastModified(const DateTime &);
DateTime lastModified() const;
void setCategories(const std::vector<std::string> &);
void addCategory(const std::string &);
std::vector<std::string> categories() const;
void setName(const std::string &);
std::string name() const;
void setNameComponents(const NameComponents &);
NameComponents nameComponents() const;
void setNote(const std::string &);
std::string note() const;
void setFreeBusyUrl(const std::string &);
std::string freeBusyUrl() const;
void setAffiliations(const std::vector<Affiliation> &);
std::vector<Affiliation> affiliations() const;
void setUrls(const std::vector<std::string> &);
std::vector<std::string> urls() const;
void setAddresses(const std::vector<Address> &, int preferred = -1);
std::vector<Address> addresses() const;
int addressPreferredIndex() const;
void setNickNames(const std::vector< std::string > &);
std::vector< std::string > nickNames() const;
void setRelateds(const std::vector<Related> &);
std::vector<Related> relateds() const;
void setBDay(const DateTime &);
DateTime bDay() const;
void setAnniversary(const DateTime &);
DateTime anniversary() const;
void setPhoto(const std::string &data, const std::string &mimetype);
std::string photo() const;
std::string photoMimetype() const;
enum Gender {
NotSet,
NotSpecified,
Male,
Female
};
void setGender(Gender);
Gender gender() const;
void setLanguages(const std::vector<std::string> &);
std::vector<std::string> languages() const;
void setTelephones(const std::vector<Telephone> &, int preferredIndex = -1);
std::vector<Telephone> telephones() const;
int telephonesPreferredIndex() const;
void setIMaddresses(const std::vector<std::string> &, int preferredIndex = -1);
std::vector<std::string> imAddresses() const;
int imAddressPreferredIndex() const;
void setEmailAddresses(const std::vector<std::string> &, int preferredIndex = -1);
std::vector<std::string> emailAddresses() const;
int emailAddressPreferredIndex() const;
void setGPSpos(const std::vector<std::string> &);
std::vector<std::string> gpsPos() const;
void setCrypto(const Crypto &);
Crypto crypto() const;
void setCustomProperties(const std::vector<CustomProperty> &);
std::vector<CustomProperty> customProperties() const;
private:
struct Private;
boost::scoped_ptr<Private> d;
};
} //Namespace
#endif // KOLABCONTACT_H
diff --git a/c++/lib/xcardconversions.h b/c++/lib/xcardconversions.h
index f8f13a4..3d11bc3 100644
--- a/c++/lib/xcardconversions.h
+++ b/c++/lib/xcardconversions.h
@@ -1,788 +1,793 @@
/*
* Copyright (C) 2011 Christian Mollekopf <mollekopf@kolabsys.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KOLABXCARDCONVERSION_H
#define KOLABXCARDCONVERSION_H
#include <bindings/kolabformat-xcard.hxx>
#include "kolabcontainers.h"
#include <XMLParserWrapper.h>
#include <boost/shared_ptr.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include "global_definitions.h"
#include "utils.h"
#include "kolabcontact.h"
namespace Kolab {
namespace XCARD {
const char* const XCARD_NAMESPACE = "urn:ietf:params:xml:ns:vcard-4.0";
const char* const INDIVIDUAL = "individual";
const char* const GROUP = "group";
using namespace Kolab::Utils;
template <typename T>
std::string getType();
template <>
std::string getType<Kolab::Contact>()
{
return INDIVIDUAL;
}
template <>
std::string getType<Kolab::DistList>()
{
return GROUP;
}
template <typename T>
xsd::cxx::tree::sequence<T> fromList(const std::vector<std::string> &input)
{
xsd::cxx::tree::sequence<T> list;
BOOST_FOREACH(const std::string &s, input) {
list.push_back(T(s));
}
return list;
}
template <typename T>
xsd::cxx::tree::sequence<T> fromList(const std::vector<std::string> &input, int preferredIndex)
{
xsd::cxx::tree::sequence<T> list;
int index = 0;
BOOST_FOREACH(const std::string &s, input) {
T im(s);
if(preferredIndex == index) {
typename T::parameters_type parameters;
parameters.baseParameter().push_back(vcard_4_0::prefParamType(vcard_4_0::prefParamType::integer_default_value()));
im.parameters(parameters);
}
index++;
list.push_back(im);
}
return list;
}
template <typename T>
std::vector<std::string> toUriList(const xsd::cxx::tree::sequence<T> &input)
{
std::vector<std::string> list;
BOOST_FOREACH(const vcard_4_0::UriPropertyType &s, input) {
list.push_back(s.uri());
}
return list;
}
template <typename T>
std::vector<std::string> toTextList(const xsd::cxx::tree::sequence<T> &input)
{
std::vector<std::string> list;
BOOST_FOREACH(const vcard_4_0::TextPropertyType &s, input) {
list.push_back(s.text());
}
return list;
}
std::vector<std::string> toStringList(const ::xsd::cxx::tree::sequence< ::xml_schema::string > &s)
{
std::vector<std::string> d;
std::copy(s.begin(), s.end(), std::back_inserter(d));
return d;
}
::xsd::cxx::tree::sequence< ::xml_schema::string > fromStringList(const std::vector<std::string> &s)
{
::xsd::cxx::tree::sequence< ::xml_schema::string > d;
std::copy(s.begin(), s.end(), std::back_inserter(d));
return d;
}
std::string fromDate(const DateTime &dt)
{
if (!dt.isDateOnly()) {
WARNING("fromDate called on date time value");
}
std::stringstream s;
s << dt.year() << dt.month() << dt.day();
return s.str();
}
std::string fromDateTime(const DateTime &dt)
{
std::stringstream s;
s.fill('0');
s << std::right;
s.width(4);
s << dt.year();
s.width(2);
s << dt.month();
s.width(2);
s << dt.day();
s.width(1);
if (dt.isDateOnly()) {
return s.str();
}
s << "T";
s.width(2);
s << dt.hour();
s.width(2);
s << dt.minute();
s.width(2);
s << dt.second();
if (dt.isUTC()) {
s << "Z";
}
return s.str();
}
DateTime toDateTime(const std::string &input)
{
int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0;
bool isUtc = false;
try {
year = boost::lexical_cast<int>(input.substr(0, 4));
month = boost::lexical_cast<int>(input.substr(4, 2));
day = boost::lexical_cast<int>(input.substr(6, 2));
if (input.size() >= 15) { //Minimum for time
if (input.at(8) != 'T') {
ERROR("Wrong demiliter");
return DateTime();
}
hour = boost::lexical_cast<int>(input.substr(9, 2));
minute = boost::lexical_cast<int>(input.substr(11, 2));
second = boost::lexical_cast<int>(input.substr(13, 2));
} else {
if (input.size() >= 9) {
ERROR("Invalid dt " + input);
return DateTime();
}
return DateTime(year, month, day);
}
if (input.size() >= 16) {
if (input.at(15) == 'Z') {
isUtc = true;
} else {
ERROR("wrong utc char? " + input.at(15));
return DateTime();
}
}
} catch (boost::bad_lexical_cast &c) {
ERROR("failed to convert: "+std::string(c.what()));
return DateTime();
} catch (...) {
ERROR("failed to convert: unkown exception");
return DateTime();
}
return DateTime(year, month, day, hour, minute, second, isUtc);
}
DateTime toDateTime(const vcard_4_0::DateDatetimePropertyType &prop)
{
if (prop.date_time()) {
return toDateTime(*prop.date_time());
} else if (prop.date()) {
return toDateTime(*prop.date());
}
ERROR("no date and no datetime");
return DateTime();
}
template <typename T>
T fromDateTime(const Kolab::DateTime &dt)
{
T prop;
if (dt.isDateOnly()) {
prop.date(fromDate(dt));
} else {
prop.date_time(fromDateTime(dt));
}
return prop;
}
template <typename T>
void writeCard(vcard_4_0::vcard &vcard, const T &);
template <>
void writeCard<Kolab::Contact>(vcard_4_0::vcard &vcard, const Kolab::Contact &contact)
{
using namespace vcard_4_0;
if (!contact.categories().empty()) {
vcard_4_0::vcard::categories_type cat;
vcard_4_0::vcard::categories_type::text_sequence seq;
BOOST_FOREACH(const std::string &s, contact.categories()) {
seq.push_back(s);
}
cat.text(seq);
vcard.categories(cat);
}
if (contact.nameComponents().isValid()) {
const NameComponents &nc = contact.nameComponents();
vcard::n_type n;
n.surname(fromStringList(nc.surnames()));
n.given(fromStringList(nc.given()));
n.additional(fromStringList(nc.additional()));
n.prefix(fromStringList(nc.prefixes()));
n.suffix(fromStringList(nc.suffixes()));
vcard.n(n);
}
if (!contact.note().empty()) {
vcard.note(vcard::note_type(contact.note()));
}
if (!contact.freeBusyUrl().empty()) {
vcard.fburl(vcard::fburl_type(contact.freeBusyUrl()));
}
if (!contact.affiliations().empty()) {
vcard::group_sequence affiliations;
BOOST_FOREACH(const Affiliation &a, contact.affiliations()) {
- std::string encodedLogo = a.logo();//TODO encode logo
+ std::string encodedLogo;
+ if (!a.logo().empty()) {
+ encodedLogo = uriInlineEncoding(a.logo(), a.logoMimetype());
+ }
affiliationPropType::org_type org;
org.text().push_back(a.organisation());
vcard::group_type group(org, affiliationPropType::logo_type(encodedLogo));
group.title(fromList<affiliationPropType::title_type >(a.titles()));
group.role(fromList<affiliationPropType::role_type>(a.roles()));
group.x_manager(fromList<affiliationPropType::x_manager_type>(a.managers()));
group.x_assistant(fromList<affiliationPropType::x_assistant_type >(a.assistants()));
group.x_office(fromList<affiliationPropType::x_office_type>(a.offices()));
affiliations.push_back(group);
}
vcard.group(affiliations);
}
if (!contact.urls().empty()) {
vcard.url(fromList<vcard::url_type>(contact.urls()));
}
if (!contact.addresses().empty()) {
vcard::adr_sequence adrs;
int index = 0;
BOOST_FOREACH(const Kolab::Address &address, contact.addresses()) {
index++;
vcard::adr_type a(vcard::adr_type::pobox_type(std::string()/*address.pobox()*/),
vcard::adr_type::ext_type(std::string()/*address.ext()*/),
vcard::adr_type::street_type(address.street()),
vcard::adr_type::locality_type(address.locality()),
vcard::adr_type::region_type(address.region()),
address.code(),
vcard::adr_type::country_type(address.country())
);
vcard::adr_type::parameters_type::baseParameter_sequence base;
vcard::adr_type::parameters_type b;
if (address.types()) {
vcard_4_0::typeParamType::text_sequence seq;
if (address.types() & Kolab::Address::Home) {
seq.push_back(TypeValueType::home);
}
if (address.types() & Kolab::Address::Work) {
seq.push_back(TypeValueType::work);
}
if (!seq.empty()) {
vcard_4_0::typeParamType type;
type.text(seq);
b.baseParameter().push_back(type);
}
}
if (!address.label().empty()) {
b.baseParameter().push_back(vcard_4_0::labelParamType(address.label()));
}
if(contact.addressPreferredIndex() == index) {
b.baseParameter().push_back(vcard_4_0::prefParamType(vcard_4_0::prefParamType::integer_default_value()));
}
index++;
a.parameters(b);
adrs.push_back(a);
}
vcard.adr(adrs);
}
if (!contact.nickNames().empty()) {
vcard::nickname_type::text_sequence textsequence;
BOOST_FOREACH(const std::string &s, contact.nickNames()) {
textsequence.push_back(s);
}
vcard::nickname_type nickName;
nickName.text(textsequence);
vcard.nickname(nickName);
}
if (!contact.relateds().empty()) {
vcard::related_sequence seq;
// BOOST_FOREACH(const std::string &s, contact.urls()) {
// urls.push_back(vcard::url_type(s));
// }
//TODO
vcard.related(seq);
}
if (contact.bDay().isValid()) {
Kolab::DateTime dt = contact.bDay();
if (dt.isUTC() || !dt.timezone().empty()) {
WARNING("Must be local time, local time assumed");
dt.setUTC(false);
}
vcard.bday(fromDateTime<vcard::bday_type>(dt));
}
if (contact.anniversary().isValid()) {
Kolab::DateTime dt = contact.anniversary();
if (dt.isUTC() || !dt.timezone().empty()) {
WARNING("Must be local time, local time assumed");
dt.setUTC(false);
}
vcard.anniversary(fromDateTime<vcard::anniversary_type>(dt));
}
if (!contact.photo().empty()) {
vcard::photo_type photo(vcard_4_0::UriPropertyType::uri_type(uriInlineEncoding(contact.photo(), contact.photoMimetype())));
vcard.photo(photo);
}
if (contact.gender() != Contact::NotSet) {
switch (contact.gender()) {
case Contact::NotSpecified:
vcard.gender(vcard::gender_type(vcard::gender_type::sex_type::empty));
break;
case Contact::Male:
vcard.gender(vcard::gender_type(vcard::gender_type::sex_type::M));
break;
case Contact::Female:
vcard.gender(vcard::gender_type(vcard::gender_type::sex_type::F));
break;
default:
ERROR("Unhandled gender");
}
}
if (!contact.languages().empty()) {
vcard.lang(fromList<vcard::lang_type>(contact.languages()));
}
if (!contact.telephones().empty()) {
vcard::tel_sequence seq;
int index = 0;
BOOST_FOREACH(const Kolab::Telephone &t, contact.telephones()) {
vcard::tel_type tel(t.number());
vcard_4_0::typeParamType telTypeParam;
if (t.types() & Kolab::Telephone::Car) {
telTypeParam.text().push_back(TypeValueType::x_car);
}
if (t.types() & Kolab::Telephone::Cell) {
telTypeParam.text().push_back(TypeValueType::cell);
}
if (t.types() & Kolab::Telephone::Fax) {
telTypeParam.text().push_back(TypeValueType::fax);
}
if (t.types() & Kolab::Telephone::Home) {
telTypeParam.text().push_back(TypeValueType::home);
}
if (t.types() & Kolab::Telephone::Work) {
telTypeParam.text().push_back(TypeValueType::work);
}
if (t.types() & Kolab::Telephone::Text) {
telTypeParam.text().push_back(TypeValueType::text);
}
if (t.types() & Kolab::Telephone::Voice) {
telTypeParam.text().push_back(TypeValueType::voice);
}
if (t.types() & Kolab::Telephone::Video) {
telTypeParam.text().push_back(TypeValueType::video);
}
if (t.types() & Kolab::Telephone::Textphone) {
telTypeParam.text().push_back(TypeValueType::textphone);
}
if (t.types() & Kolab::Telephone::Pager) {
telTypeParam.text().push_back(TypeValueType::pager);
}
vcard::tel_type::parameters_type params;
if(contact.telephonesPreferredIndex() == index) {
params.baseParameter().push_back(vcard_4_0::prefParamType(vcard_4_0::prefParamType::integer_default_value()));
}
index++;
if (!telTypeParam.text().empty()) {
params.baseParameter().push_back(telTypeParam);
tel.parameters(params);
}
seq.push_back(tel);
}
vcard.tel(seq);
}
if (!contact.imAddresses().empty()) {
vcard.impp(fromList<vcard::impp_type>(contact.imAddresses(), contact.imAddressPreferredIndex()));
}
if (!contact.emailAddresses().empty()) {
vcard.email(fromList<vcard::email_type>(contact.emailAddresses(), contact.emailAddressPreferredIndex()));
}
if (!contact.gpsPos().empty()) {
//TODO
}
// if (!contact.crypto().isValid()) {
// //TODO
// }
}
template <>
void writeCard<Kolab::DistList>(vcard_4_0::vcard &vcard, const Kolab::DistList &distlist)
{
if (!distlist.members().empty()) {
vcard.member(fromList<vcard_4_0::vcard::member_type>(distlist.members()));
} else {
WARNING("empty distlist");
}
}
template <typename T>
std::string serializeCard(const T &card, const std::string prod = std::string()) {
using namespace vcard_4_0;
clearErrors();
try {
vcard_4_0::vcard::uid_type uid(getUID(card.uid()));
setCreatedUid(uid.text());
vcard_4_0::vcard::x_kolab_version_type kolab_version(KOLAB_FORMAT_VERSION);
vcard_4_0::vcard::prodid_type prodid(prod+KOLAB_LIBNAME+KOLAB_LIB_VERSION);
vcard_4_0::vcard::rev_type rev(fromDateTime(getCurrentTime()));
vcard_4_0::vcard::kind_type kind(getType<T>());
vcard_4_0::vcard::fn_type fn(card.name());
vcard_4_0::vcard vcard(uid, kolab_version, prodid, rev, kind, fn);
//TODO custom properties
writeCard<T>(vcard, card);
VcardsType vcards(vcard);
xml_schema::namespace_infomap map;
map[""].name = XCARD_NAMESPACE;
std::ostringstream ostringstream;
vcard_4_0::vcards(ostringstream, vcards, map);
return ostringstream.str();
} catch (const xml_schema::exception& e) {
CRITICAL("Unknown Exception: failed to write Contact");
}
return std::string();
}
template <typename T>
boost::shared_ptr<T> readCard(const vcard_4_0::VcardsType::vcard_type &vcard);
template <>
boost::shared_ptr<Kolab::Contact> readCard <Kolab::Contact> (const vcard_4_0::VcardsType::vcard_type &vcard)
{
using namespace vcard_4_0;
boost::shared_ptr<Kolab::Contact> contact(new Kolab::Contact);
if (vcard.categories()) {
contact->setCategories(toStringList((*vcard.categories()).text()));
}
if (vcard.n()) {
NameComponents nc;
nc.setSurnames(toStringList((*vcard.n()).surname()));
nc.setGiven(toStringList((*vcard.n()).given()));
nc.setPrefixes(toStringList((*vcard.n()).prefix()));
nc.setSuffixes(toStringList((*vcard.n()).suffix()));
nc.setAdditional(toStringList((*vcard.n()).additional()));
contact->setNameComponents(nc);
}
if (vcard.note()) {
contact->setNote((*vcard.note()).text());
}
if (vcard.fburl()) {
contact->setFreeBusyUrl((*vcard.fburl()).uri());
}
if (!vcard.group().empty()) {
std::vector<Kolab::Affiliation> list;
BOOST_FOREACH (const vcard::group_type &group, vcard.group()) {
Kolab::Affiliation aff;
std::string org;
if (!group.org().text().empty()) {
org = *group.org().text().begin();
} else {
WARNING("No org present");
}
aff.setOrganisation(org);
- aff.setLogo(group.logo().uri());
+ std::string mimetype;
+ const std::string &logo = uriInlineDecoding(group.logo().uri(), mimetype);
+ aff.setLogo(logo, mimetype);
aff.setTitles(toTextList<vcard::group_type::title_type>(group.title()));
aff.setRoles(toTextList<vcard::group_type::role_type>(group.role()));
aff.setManagers(toTextList<vcard::group_type::x_manager_type>(group.x_manager()));
aff.setAssistants(toTextList<vcard::group_type::x_assistant_type>(group.x_assistant()));
aff.setOffices(toTextList<vcard::group_type::x_office_type>(group.x_office()));
list.push_back(aff);
}
contact->setAffiliations(list);
}
if (!vcard.url().empty()) {
contact->setUrls(toUriList<vcard::url_type >(vcard.url()));
}
if (!vcard.adr().empty()) {
std::vector<Kolab::Address> list;
int preferredIndex = -1;
int index = 0;
BOOST_FOREACH(const vcard::adr_type &adr, vcard.adr()) {
Kolab::Address address;
if (adr.parameters()) {
BOOST_FOREACH(const vcard_4_0::ArrayOfParameters::baseParameter_type ¶m, (*adr.parameters()).baseParameter()) {
if (const vcard_4_0::labelParamType *rel = dynamic_cast<const vcard_4_0::labelParamType*> (¶m)) {
address.setLabel(rel->text());
} else if (dynamic_cast<const vcard_4_0::prefParamType*> (¶m)) {
preferredIndex = index;
} else if (const vcard_4_0::typeParamType *rel = dynamic_cast<const vcard_4_0::typeParamType*> (¶m)) {
int types = 0;
BOOST_FOREACH(const std::string &s, rel->text()) {
if (s == TypeValueType(TypeValueType::work)) {
types |= Kolab::Telephone::Work;
}
if (s == TypeValueType(TypeValueType::home)) {
types |= Kolab::Telephone::Home;
}
}
address.setTypes(types);
}
}
}
index++;
address.setCode(adr.code());
address.setCountry(adr.country());
address.setLocality(adr.locality());
address.setRegion(adr.region());
address.setStreet(adr.street());
list.push_back(address);
}
contact->setAddresses(list, preferredIndex);
}
if (vcard.nickname()) {
contact->setNickNames(toTextList<TextListPropertyType::text_type>((*vcard.nickname()).text()));
}
if (!vcard.related().empty()) {
// std::vector<Related> list;
// BOOST_FOREACH(const vcard::lang_type l, vcard.lang()) {
// list.push_back(l.language_tag());
// }
// contact->setRelateds();
//TODO
}
if (vcard.bday()) {
contact->setBDay(toDateTime(*vcard.bday()));
}
if (vcard.anniversary()) {
contact->setAnniversary(toDateTime(*vcard.anniversary()));
}
if (vcard.photo()) {
std::string mimetype;
const std::string decodedPhoto = uriInlineDecoding((*vcard.photo()).uri(), mimetype);
contact->setPhoto(decodedPhoto, mimetype);
}
if (vcard.gender()) {
if ((*vcard.gender()).sex() == vcard::gender_type::sex_type::empty) {
contact->setGender(Kolab::Contact::NotSpecified);
} else if ((*vcard.gender()).sex() == vcard::gender_type::sex_type::M) {
contact->setGender(Kolab::Contact::Male);
} else if ((*vcard.gender()).sex() == vcard::gender_type::sex_type::F) {
contact->setGender(Kolab::Contact::Female);
}
}
if (!vcard.lang().empty()) {
std::vector<std::string> list;
BOOST_FOREACH(const vcard::lang_type l, vcard.lang()) {
list.push_back(l.language_tag());
}
contact->setLanguages(list);
}
if (!vcard.tel().empty()) {
std::vector<Kolab::Telephone> list;
int preferredIndex = -1;
int index = 0;
BOOST_FOREACH(const vcard::tel_type &tel, vcard.tel()) {
Kolab::Telephone telephone;
if (tel.parameters()) {
BOOST_FOREACH(const vcard_4_0::ArrayOfParameters::baseParameter_type ¶m, (*tel.parameters()).baseParameter()) {
if (dynamic_cast<const vcard_4_0::prefParamType*> (¶m)) {
preferredIndex = index;
} else if (const vcard_4_0::typeParamType *rel = dynamic_cast<const vcard_4_0::typeParamType*> (¶m)) {
int types = 0;
BOOST_FOREACH(const std::string &s, rel->text()) {
if (s == TypeValueType(TypeValueType::work)) {
types |= Kolab::Telephone::Work;
}
if (s == TypeValueType(TypeValueType::home)) {
types |= Kolab::Telephone::Home;
}
if (s == TypeValueType(TypeValueType::text)) {
types |= Kolab::Telephone::Text;
}
if (s == TypeValueType(TypeValueType::voice)) {
types |= Kolab::Telephone::Voice;
}
if (s == TypeValueType(TypeValueType::fax)) {
types |= Kolab::Telephone::Fax;
}
if (s == TypeValueType(TypeValueType::cell)) {
types |= Kolab::Telephone::Cell;
}
if (s == TypeValueType(TypeValueType::video)) {
types |= Kolab::Telephone::Video;
}
if (s == TypeValueType(TypeValueType::pager)) {
types |= Kolab::Telephone::Pager;
}
if (s == TypeValueType(TypeValueType::textphone)) {
types |= Kolab::Telephone::Textphone;
}
if (s == TypeValueType(TypeValueType::x_car)) {
types |= Kolab::Telephone::Car;
}
}
telephone.setTypes(types);
}
}
}
index++;
telephone.setNumber(tel.text());
list.push_back(telephone);
}
contact->setTelephones(list, preferredIndex);
}
if (!vcard.impp().empty()) {
int preferredIndex = -1;
std::vector<std::string> list;
int i = 0;
BOOST_FOREACH(const vcard_4_0::UriPropertyType &s, vcard.impp()) {
if (s.parameters()) {
BOOST_FOREACH(const vcard_4_0::ArrayOfParameters::baseParameter_type ¶m, (*s.parameters()).baseParameter()) {
if (dynamic_cast<const vcard_4_0::prefParamType*> (¶m)) {
preferredIndex = i;
}
}
}
i++;
list.push_back(s.uri());
}
contact->setIMaddresses(list, preferredIndex);
}
if (!vcard.email().empty()) {
int preferredIndex = -1;
std::vector<std::string> list;
int i = 0;
BOOST_FOREACH(const vcard_4_0::TextPropertyType &s, vcard.email()) {
if (s.parameters()) {
BOOST_FOREACH(const vcard_4_0::ArrayOfParameters::baseParameter_type ¶m, (*s.parameters()).baseParameter()) {
if (dynamic_cast<const vcard_4_0::prefParamType*> (¶m)) {
preferredIndex = i;
}
}
}
i++;
list.push_back(s.text());
}
contact->setEmailAddresses(list, preferredIndex);
}
if (!vcard.geo().empty()) {
//TODO Geo
}
if (!vcard.x_crypto().empty()) {
//TODO Crypto
}
return contact;
}
template <>
boost::shared_ptr<Kolab::DistList> readCard <Kolab::DistList> (const vcard_4_0::VcardsType::vcard_type &vcard)
{
using namespace vcard_4_0;
boost::shared_ptr<Kolab::DistList> distlist(new Kolab::DistList);
if (!vcard.member().empty()) {
distlist->setMembers(toUriList<vcard_4_0::vcard::member_type>(vcard.member()));
} else {
WARNING("empty distlist");
}
return distlist;
}
template <typename T>
boost::shared_ptr<T> deserializeCard(const std::string& s, bool isUrl)
{
clearErrors();
try {
std::auto_ptr<vcard_4_0::VcardsType> vcards;
if (isUrl) {
xsd::cxx::xml::dom::auto_ptr <xercesc_3_1::DOMDocument > doc = XMLParserWrapper::inst().parseFile(s);
if (doc.get()) {
vcards = vcard_4_0::vcards(doc);
}
} else {
xsd::cxx::xml::dom::auto_ptr <xercesc_3_1::DOMDocument > doc = XMLParserWrapper::inst().parseString(s);
if (doc.get()) {
vcards = vcard_4_0::vcards(doc);
}
}
if (!vcards.get()) {
CRITICAL("failed to parse card!");
return boost::shared_ptr<T>();
}
boost::shared_ptr<T> card = readCard<T>(vcards->vcard());
card->setUid(vcards->vcard().uid().text());
card->setName(vcards->vcard().fn().text());
setProductId( vcards->vcard().prodid().text() );
// setFormatVersion( vcards->vcard().version().text() );
// global_xCardVersion = vcalendar.properties().version().text();
setKolabVersion( vcards->vcard().x_kolab_version().text() );
return card;
} catch (const xml_schema::exception& e) {
std::cerr << e << std::endl;
CRITICAL("Failed to read card!");
}
return boost::shared_ptr<T>();
}
}
} //Namespace
#endif
\ No newline at end of file
diff --git a/c++/tests/bindingstest.cpp b/c++/tests/bindingstest.cpp
index ebc0130..d1fb65c 100644
--- a/c++/tests/bindingstest.cpp
+++ b/c++/tests/bindingstest.cpp
@@ -1,423 +1,423 @@
#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>
// void BindingsTest::eventCompletness_data()
template <typename T>
void setIncidence(T &ev)
{
ev.setUid("UID");
ev.setCreated(Kolab::DateTime(2006,1,6,12,0,0)); //UTC
ev.setSequence(1);
ev.setClassification(Kolab::Confidential);
ev.addCategory("Category");
ev.setStart(Kolab::DateTime("US/Eastern", 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::DateTime("US/Eastern", 2006,1,6,12,0,0));
ev.addExceptionDate(Kolab::DateTime("US/Eastern", 2006,1,6,12,0,0));
ev.setRecurrenceID(Kolab::DateTime("US/Eastern", 2006,1,6,12,0,0), true);
ev.setSummary("summary");
ev.setDescription("description");
ev.setPriority(3);
ev.setStatus(Kolab::Confirmed);
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::DateTime(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::DateTime(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::DateTime("US/Eastern", 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.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::DateTime("US/Eastern", 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::contactCompletness()
{
std::vector<std::string> stringlist;
stringlist.push_back("lbksdfbklsd");
stringlist.push_back("sdf");
Kolab::Contact c;
c.setUid("uid");
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::DateTime(2001,12,10,12,12,12,false));
c.setAnniversary(Kolab::DateTime(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");
+ aff.setLogo("logo", "mime/miem");
aff.setTitles(stringlist);
aff.setRoles(stringlist);
aff.setManagers(stringlist);
aff.setAssistants(stringlist);
aff.setOffices(stringlist);
list.push_back(aff);
list.push_back(aff);
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);
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");
c.setMembers(stringlist);
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
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Apr 4, 6:30 AM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18769656
Default Alt Text
(54 KB)
Attached To
Mode
rLKX libkolabxml
Attached
Detach File
Event Timeline