c++/lib c++/tests
Christian Mollekopf
mollekopf at kolabsys.com
Wed Mar 14 14:56:46 CET 2012
c++/lib/utils.cpp | 2 +-
c++/lib/xcardconversions.h | 21 ++++++++++++++++++---
c++/tests/bindingstest.cpp | 2 +-
c++/tests/conversiontest.cpp | 9 +++++++++
c++/tests/conversiontest.h | 2 ++
5 files changed, 31 insertions(+), 5 deletions(-)
New commits:
commit f07befdd5a5ac84e6108510fb194086daa98eca4
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Wed Mar 14 14:56:41 2012 +0100
That the UID is stored as URN is an xcard specific implementation detail. Hide accrodingly from the api.
diff --git a/c++/lib/utils.cpp b/c++/lib/utils.cpp
index 4140fd5..f49b37b 100644
--- a/c++/lib/utils.cpp
+++ b/c++/lib/utils.cpp
@@ -94,7 +94,7 @@ std::string getUID(const std::string &s)
{
if (s.empty()) {
boost::uuids::uuid u; // initialize uuid
- return std::string("urn:uuid:")+boost::uuids::to_string(u);
+ return boost::uuids::to_string(u);
}
return s;
}
diff --git a/c++/lib/xcardconversions.h b/c++/lib/xcardconversions.h
index ea4ad8b..d1b9e7f 100644
--- a/c++/lib/xcardconversions.h
+++ b/c++/lib/xcardconversions.h
@@ -477,7 +477,22 @@ void writeCard<Kolab::DistList>(vcard_4_0::vcard &vcard, const Kolab::DistList &
}
}
+std::string toURN(const std::string &uid)
+{
+ if (uid.substr(0, 9) == std::string("urn:uuid:")) {
+ return uid;
+ }
+ return std::string("urn:uuid:")+uid;
+}
+std::string fromURN(const std::string &uid)
+{
+ if (uid.substr(0, 9) != std::string("urn:uuid:")) {
+ WARNING("not a urn");
+ return uid;
+ }
+ return uid.substr(9);
+}
template <typename T>
std::string serializeCard(const T &card, const std::string prod = std::string()) {
@@ -487,8 +502,8 @@ std::string serializeCard(const T &card, const std::string prod = std::string())
clearErrors();
try {
- vcard_4_0::vcard::uid_type uid(getUID(card.uid()));
- setCreatedUid(uid.uri());
+ vcard_4_0::vcard::uid_type uid(toURN(getUID(card.uid())));
+ setCreatedUid(fromURN(uid.uri()));
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()));
@@ -807,7 +822,7 @@ boost::shared_ptr<T> deserializeCard(const std::string& s, bool isUrl)
}
boost::shared_ptr<T> card = readCard<T>(vcards->vcard());
- card->setUid(vcards->vcard().uid().uri());
+ card->setUid(fromURN(vcards->vcard().uid().uri()));
card->setName(vcards->vcard().fn().text());
setProductId( vcards->vcard().prodid().text() );
diff --git a/c++/tests/bindingstest.cpp b/c++/tests/bindingstest.cpp
index 09dd294..6d4c381 100644
--- a/c++/tests/bindingstest.cpp
+++ b/c++/tests/bindingstest.cpp
@@ -341,7 +341,7 @@ void BindingsTest::contactCompletness()
stringlist.push_back("sdf");
Kolab::Contact c;
- c.setUid("urn:uuid:1045b57d-ff7f-0000-d814-867b4d7f0000");
+ c.setUid("1045b57d-ff7f-0000-d814-867b4d7f0000");
c.setCategories(stringlist);
c.setName("name");
Kolab::NameComponents nc;
diff --git a/c++/tests/conversiontest.cpp b/c++/tests/conversiontest.cpp
index 218ea42..3097b35 100644
--- a/c++/tests/conversiontest.cpp
+++ b/c++/tests/conversiontest.cpp
@@ -198,6 +198,15 @@ void ConversionTest::mailtoUriEncodingTest()
}
+void ConversionTest::urnTest()
+{
+ QCOMPARE(Kolab::XCARD::toURN("1045b57d-ff7f-0000-d814-867b4d7f0000"), std::string("urn:uuid:1045b57d-ff7f-0000-d814-867b4d7f0000"));
+ QCOMPARE(Kolab::XCARD::toURN("urn:uuid:1045b57d-ff7f-0000-d814-867b4d7f0000"), std::string("urn:uuid:1045b57d-ff7f-0000-d814-867b4d7f0000"));
+ QCOMPARE(Kolab::XCARD::fromURN("urn:uuid:1045b57d-ff7f-0000-d814-867b4d7f0000"), std::string("1045b57d-ff7f-0000-d814-867b4d7f0000"));
+ QCOMPARE(Kolab::XCARD::fromURN("1045b57d-ff7f-0000-d814-867b4d7f0000"), std::string("1045b57d-ff7f-0000-d814-867b4d7f0000"));
+ QCOMPARE(Kolab::Utils::getError(), Kolab::NoError);
+}
+
void threadF()
{
diff --git a/c++/tests/conversiontest.h b/c++/tests/conversiontest.h
index 3ccdd1c..8df558f 100644
--- a/c++/tests/conversiontest.h
+++ b/c++/tests/conversiontest.h
@@ -33,6 +33,8 @@ class ConversionTest : public QObject
void mailtoUriEncodingTest_data();
void mailtoUriEncodingTest();
+ void urnTest();
+
void threadLocalTest();
};
More information about the commits
mailing list