2 commits - c++/lib c++/tests
Christian Mollekopf
mollekopf at kolabsys.com
Thu Mar 1 22:58:13 CET 2012
c++/lib/kolabcontainers.h | 6 +++--
c++/lib/kolabkcalconversion.cpp | 40 +++++++++++++++++++++++++++++----
c++/tests/kcalconversiontest.cpp | 46 +++++++++++++++++++++++++++++++++++++--
c++/tests/kcalconversiontest.h | 3 ++
4 files changed, 86 insertions(+), 9 deletions(-)
New commits:
commit 08a7d5792169aa199a2335fc1cca8f5e592a9330
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Thu Mar 1 22:56:45 2012 +0100
Duration testing, duration, end date, transparency
diff --git a/c++/lib/kolabkcalconversion.cpp b/c++/lib/kolabkcalconversion.cpp
index 88ec2bc..ec777ae 100644
--- a/c++/lib/kolabkcalconversion.cpp
+++ b/c++/lib/kolabkcalconversion.cpp
@@ -92,10 +92,31 @@ DateTime fromDate(const KDateTime &dt)
KCalCore::Duration toDuration(const Kolab::Duration &d)
{
- KCalCore::Duration d1(d.weeks()*7+d.days(), KCalCore::Duration::Days);
- KCalCore::Duration d2(d.hours()*60*60+d.minutes()*60+d.seconds());
- //TODO handle negative durations?
- return d1+d2;
+ //TODO should we support negative durations?
+ if (d.hours() || d.minutes() || d.seconds()) {
+ return KCalCore::Duration(((((d.weeks() * 7 + d.days()) * 24 + d.hours()) * 60 + d.minutes()) * 60 + d.seconds()));
+ }
+ return KCalCore::Duration(d.weeks() * 7 + d.days(), KCalCore::Duration::Days);
+}
+
+Kolab::Duration fromDuration(const KCalCore::Duration &d)
+{
+ if (d.value() <= 0) {
+ return Kolab::Duration();
+ }
+ //We don't know how the seconds/days were distributed before, so no point in distributing them (probably)
+ //TODO should we support negative durations?
+ if (d.isDaily()) {
+ int days = d.value();
+ return Kolab::Duration(days, 0, 0, 0, false);
+ }
+ int seconds = d.value();
+// int minutes = seconds / 60;
+// seconds = seconds % 60;
+// int hours = minutes / 60;
+// minutes = minutes % 60;
+ return Kolab::Duration(0, 0, 0, seconds, false);
+
}
KCalCore::Incidence::Secrecy toSecrecy(Kolab::Classification c)
@@ -632,7 +653,16 @@ Event fromKCalCore(const KCalCore::Event &event)
Event e;
getIncidence(e, event);
getTodoEvent(e, event);
- //TODO end, duration transp
+ if (event.hasEndDate()) {
+ e.setEnd(fromDate(event.dtEnd()));
+ } else if (event.hasDuration()) {
+ e.setDuration(fromDuration(event.duration()));
+ }
+ if (event.transparency() == KCalCore::Event::Transparent) {
+ e.setTransparency(true);
+ } else {
+ e.setTransparency(false);
+ }
return e;
}
diff --git a/c++/tests/kcalconversiontest.cpp b/c++/tests/kcalconversiontest.cpp
index 85a5f9a..612da5d 100644
--- a/c++/tests/kcalconversiontest.cpp
+++ b/c++/tests/kcalconversiontest.cpp
@@ -22,6 +22,7 @@ Q_DECLARE_METATYPE(std::vector<Kolab::DateTime>);
Q_DECLARE_METATYPE(KCalCore::Event);
Q_DECLARE_METATYPE(KCalCore::Todo);
Q_DECLARE_METATYPE(KCalCore::Journal);
+Q_DECLARE_METATYPE(KCalCore::Duration);
namespace QTest {
@@ -126,6 +127,18 @@ namespace QTest {
ba += ")";
return qstrdup(ba.data());
}
+
+ template<>
+ char *toString(const KCalCore::Duration &d)
+ {
+ QByteArray ba;
+ ba += "KCalCore::Duration(";
+ ba += QString::number(d.isDaily()) + ", ";
+ ba += QString::number(d.value()) + " ";
+ ba += ")";
+ return qstrdup(ba.data());
+ }
+
}
template <typename T>
@@ -162,6 +175,34 @@ void KCalConversionTest::testDate()
QCOMPARE(r2, input);
}
+void KCalConversionTest::testDuration_data()
+{
+ QTest::addColumn<Kolab::Duration>( "input" );
+ QTest::addColumn<KCalCore::Duration>( "result" );
+ QTest::addColumn<Kolab::Duration>( "fromResult" );
+
+ QTest::newRow( "seconds" ) << Kolab::Duration(0,0,0,30,false) << KCalCore::Duration(30, KCalCore::Duration::Seconds) << Kolab::Duration(0,0,0,30,false);
+ QTest::newRow( "minutes" ) << Kolab::Duration(0,0,1,30,false) << KCalCore::Duration(90, KCalCore::Duration::Seconds) << Kolab::Duration(0,0,0,90,false);
+ QTest::newRow( "hours" ) << Kolab::Duration(0,1,1,30,false) << KCalCore::Duration(60*60+90, KCalCore::Duration::Seconds) << Kolab::Duration(0,0,0,60*60+90,false);
+ QTest::newRow( "days" ) << Kolab::Duration(1,1,1,30,false) << KCalCore::Duration(24*60*60+60*60+90, KCalCore::Duration::Seconds) << Kolab::Duration(0,0,0,24*60*60+60*60+90,false);
+ QTest::newRow( "daysonly" ) << Kolab::Duration(30,0,0,0, false) << KCalCore::Duration(30, KCalCore::Duration::Days) << Kolab::Duration(30,0,0,0,false);
+ QTest::newRow( "weeks" ) << Kolab::Duration(30,false) << KCalCore::Duration(30*7, KCalCore::Duration::Days) << Kolab::Duration(30*7,0,0,0,false);
+}
+
+
+void KCalConversionTest::testDuration()
+{
+ QFETCH(Kolab::Duration, input);
+ QFETCH(KCalCore::Duration, result);
+ QFETCH(Kolab::Duration, fromResult);
+
+ const KCalCore::Duration &r = Kolab::KCalConversion::toDuration(input);
+ QCOMPARE(r, result);
+
+ const Kolab::Duration &r2 = Kolab::KCalConversion::fromDuration(result);
+ QCOMPARE(r2, fromResult);
+}
+
void KCalConversionTest::testDateTZ_data()
{
@@ -402,8 +443,9 @@ void KCalConversionTest::testConversion()
QCOMPARE(b.classification(), kolab.classification());
QCOMPARE(b.categories(), kolab.categories());
QCOMPARE(b.start(), kolab.start());
- //end
- //duration
+ QCOMPARE(b.end(), kolab.end());
+ QCOMPARE(b.duration(), kolab.duration());
+ QCOMPARE(b.transparency(), kolab.transparency());
QCOMPARE(b.recurrenceRule(), kolab.recurrenceRule());
QCOMPARE(b.recurrenceID(), kolab.recurrenceID());
diff --git a/c++/tests/kcalconversiontest.h b/c++/tests/kcalconversiontest.h
index 3eb662f..fa926a5 100644
--- a/c++/tests/kcalconversiontest.h
+++ b/c++/tests/kcalconversiontest.h
@@ -12,6 +12,9 @@ class KCalConversionTest : public QObject
void testDate_data();
void testDate();
+ void testDuration_data();
+ void testDuration();
+
void testConversion_data();
void testConversion();
commit ece8b66bc7c361640f0dc1f4548778db6769d631
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Thu Mar 1 22:52:41 2012 +0100
Compare durations in seconds because KCalCore doesn't let us keep the exact structure.
diff --git a/c++/lib/kolabcontainers.h b/c++/lib/kolabcontainers.h
index 7065710..4ff7ea0 100644
--- a/c++/lib/kolabcontainers.h
+++ b/c++/lib/kolabcontainers.h
@@ -140,12 +140,14 @@ struct Duration {
Duration():mWeeks(0), mDays(0), mHours(0), mMinutes(0), mSeconds(0), mNegative(false), valid(false){};
Duration(int weeks, bool negative = false): mWeeks(weeks), mDays(0), mHours(0), mMinutes(0), mSeconds(0), mNegative(negative), valid(true){};
Duration(int days, int hours, int minutes, int seconds, bool negative = false): mWeeks(0), mDays(days), mHours(hours), mMinutes(minutes), mSeconds(seconds), mNegative(negative), valid(true){};
- bool operator==(const Duration &other) const{ return (mWeeks == other.mWeeks &&
+ bool operator==(const Duration &other) const{ return (/*mWeeks == other.mWeeks &&
mDays == other.mDays &&
mHours == other.mHours &&
mMinutes == other.mMinutes &&
mSeconds == other.mSeconds &&
- mNegative == other.mNegative &&
+ mNegative == other.mNegative &&*/
+ ( ((((mWeeks * 7 + mDays) * 24 + mHours) * 60 + mMinutes) * 60 + mSeconds) ==
+ ((((other.mWeeks * 7 + other.mDays) * 24 + other.mHours) * 60 + other.mMinutes) * 60 + other.mSeconds) ) &&
valid == other.valid );};
int weeks() const { return mWeeks; };
int days() const { return mDays; };
More information about the commits
mailing list