Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117883975
kcalconversiontest.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
24 KB
Referenced Files
None
Subscribers
None
kcalconversiontest.cpp
View Options
#include
"kcalconversiontest.h"
#include
<QtCore/QObject>
#include
<QtTest/QtTest>
#include
<KDE/KSystemTimeZones>
#include
<kcalcore/recurrence.h>
#include
<lib/kolabkcalconversion.h>
#include
<lib/kolabkcalconversion.cpp>
#include
<lib/calendaring.h>
#include
"serializers.h"
using
namespace
Kolab
::
KCalConversion
;
Q_DECLARE_METATYPE
(
Kolab
::
Duration
);
Q_DECLARE_METATYPE
(
Kolab
::
cDateTime
);
Q_DECLARE_METATYPE
(
Kolab
::
Event
);
Q_DECLARE_METATYPE
(
Kolab
::
Todo
);
Q_DECLARE_METATYPE
(
Kolab
::
Journal
);
Q_DECLARE_METATYPE
(
std
::
vector
<
Kolab
::
cDateTime
>
);
Q_DECLARE_METATYPE
(
KCalCore
::
Event
);
Q_DECLARE_METATYPE
(
KCalCore
::
Todo
);
Q_DECLARE_METATYPE
(
KCalCore
::
Journal
);
Q_DECLARE_METATYPE
(
KCalCore
::
Duration
);
namespace
QTest
{
template
<>
char
*
toString
(
const
KDateTime
&
dt
)
{
QByteArray
ba
=
"KDateTime("
;
ba
+=
dt
.
toString
().
toAscii
();
ba
+=
dt
.
timeZone
().
name
();
ba
+=
")"
;
return
qstrdup
(
ba
.
data
());
}
template
<>
char
*
toString
(
const
KCalCore
::
Attendee
&
at
)
{
QByteArray
ba
=
"Attendee("
;
ba
+=
at
.
name
().
toAscii
()
+
", "
;
ba
+=
at
.
email
().
toAscii
()
+
", "
;
ba
+=
QString
::
number
(
at
.
role
())
+
", "
;
ba
+=
QString
::
number
(
at
.
status
())
+
", "
;
ba
+=
QString
::
number
(
at
.
RSVP
())
+
", "
;
ba
+=
at
.
delegate
().
toAscii
()
+
", "
;
ba
+=
at
.
delegator
().
toAscii
()
+
", "
;
ba
+=
at
.
uid
().
toAscii
()
+
", "
;
ba
+=
")"
;
return
qstrdup
(
ba
.
data
());
}
template
<>
char
*
toString
(
const
QList
<
int
>
&
l
)
{
QByteArray
ba
=
"QList<int>("
;
foreach
(
int
i
,
l
)
{
ba
+=
QString
::
number
(
i
)
+
", "
;
}
ba
+=
")"
;
return
qstrdup
(
ba
.
data
());
}
template
<>
char
*
toString
(
const
QList
<
KCalCore
::
RecurrenceRule
::
WDayPos
>
&
l
)
{
QByteArray
ba
=
"QList<int>("
;
foreach
(
const
KCalCore
::
RecurrenceRule
::
WDayPos
&
i
,
l
)
{
ba
+=
QString
::
number
(
i
.
pos
())
+
" "
;
ba
+=
QString
::
number
(
i
.
day
())
+
", "
;
}
ba
+=
")"
;
return
qstrdup
(
ba
.
data
());
}
template
<>
char
*
toString
(
const
KCalCore
::
DateList
&
l
)
{
QByteArray
ba
=
"KCalCore::DateList("
;
foreach
(
const
QDate
&
i
,
l
)
{
ba
+=
i
.
toString
();
}
ba
+=
")"
;
return
qstrdup
(
ba
.
data
());
}
template
<>
char
*
toString
(
const
KCalCore
::
DateTimeList
&
l
)
{
QByteArray
ba
=
"KCalCore::DateTimeList("
;
foreach
(
const
KDateTime
&
i
,
l
)
{
ba
+=
toString
(
i
);
}
ba
+=
")"
;
return
qstrdup
(
ba
.
data
());
}
template
<>
char
*
toString
(
const
KCalCore
::
Recurrence
&
at
)
{
at
.
dump
();
KCalCore
::
RecurrenceRule
*
r
=
at
.
defaultRRule
();
QByteArray
ba
;
if
(
!
r
)
{
ba
+=
"Recurrence( )"
;
}
else
{
Q_ASSERT
(
r
);
Q_ASSERT
(
at
.
rRules
().
size
()
==
1
);
ba
+=
"Recurrence("
;
ba
+=
QString
::
number
(
r
->
recurrenceType
())
+
"
\n
"
;
ba
+=
QString
::
number
(
r
->
frequency
())
+
"
\n
"
;
ba
+=
QString
::
number
(
r
->
duration
())
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
r
->
startDt
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
r
->
endDt
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
r
->
bySeconds
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
r
->
byMinutes
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
r
->
byHours
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
r
->
byDays
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
r
->
byMonthDays
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
r
->
byYearDays
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
r
->
byMonths
()))
+
"
\n
"
;
ba
+=
")
\n
"
;
ba
+=
QByteArray
(
toString
(
at
.
exDates
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
at
.
exDateTimes
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
at
.
rDates
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
at
.
rDateTimes
()))
+
"
\n
"
;
}
return
qstrdup
(
ba
.
data
());
}
template
<>
char
*
toString
(
const
Kolab
::
RecurrenceRule
&
at
)
{
QByteArray
ba
;
ba
+=
"KolabRecurrenceRule("
;
ba
+=
QString
::
number
(
at
.
weekStart
())
+
"
\n
"
;
ba
+=
QString
::
number
(
at
.
frequency
())
+
"
\n
"
;
ba
+=
QString
::
number
(
at
.
interval
())
+
"
\n
"
;
ba
+=
QString
::
number
(
at
.
count
())
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
at
.
end
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
at
.
bysecond
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
at
.
byminute
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
at
.
byhour
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
at
.
byday
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
at
.
bymonthday
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
at
.
byyearday
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
at
.
byweekno
()))
+
"
\n
"
;
ba
+=
QByteArray
(
toString
(
at
.
bymonth
()))
+
"
\n
"
;
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
>
void
comparePointerVectors
(
const
QVector
<
T
>
&
list
,
const
QVector
<
T
>
&
other
)
{
QCOMPARE
(
list
.
size
(),
other
.
size
());
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++
)
{
QCOMPARE
(
*
list
.
at
(
i
),
*
other
.
at
(
i
));
}
}
void
KCalConversionTest
::
testDate_data
()
{
QTest
::
addColumn
<
Kolab
::
cDateTime
>
(
"input"
);
QTest
::
addColumn
<
KDateTime
>
(
"result"
);
QTest
::
newRow
(
"datetime with tz"
)
<<
Kolab
::
cDateTime
(
"Europe/Zurich"
,
2006
,
1
,
8
,
12
,
0
,
0
)
<<
KDateTime
(
QDate
(
2006
,
1
,
8
),
QTime
(
12
,
0
,
0
),
KSystemTimeZones
::
zone
(
"Europe/Zurich"
));
QTest
::
newRow
(
"floating datetime"
)
<<
Kolab
::
cDateTime
(
2006
,
1
,
8
,
12
,
0
,
0
,
false
)
<<
KDateTime
(
QDate
(
2006
,
1
,
8
),
QTime
(
12
,
0
,
0
),
KDateTime
::
Spec
(
KDateTime
::
ClockTime
));
QTest
::
newRow
(
"utc datetime"
)
<<
Kolab
::
cDateTime
(
2006
,
1
,
8
,
12
,
0
,
0
,
true
)
<<
KDateTime
(
KDateTime
(
QDate
(
2006
,
1
,
8
),
QTime
(
12
,
0
,
0
),
KDateTime
::
UTC
));
QTest
::
newRow
(
"date only"
)
<<
Kolab
::
cDateTime
(
2006
,
1
,
8
)
<<
KDateTime
(
QDate
(
2006
,
1
,
8
));
}
void
KCalConversionTest
::
testDate
()
{
QFETCH
(
Kolab
::
cDateTime
,
input
);
QFETCH
(
KDateTime
,
result
);
const
KDateTime
&
r
=
Kolab
::
KCalConversion
::
toDate
(
input
);
QCOMPARE
(
r
,
result
);
const
Kolab
::
cDateTime
&
r2
=
Kolab
::
KCalConversion
::
fromDate
(
result
);
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
()
{
QTest
::
addColumn
<
Kolab
::
cDateTime
>
(
"input"
);
QTest
::
addColumn
<
KDateTime
>
(
"result"
);
QTest
::
addColumn
<
int
>
(
"offset"
);
QTest
::
newRow
(
"berlin"
)
<<
Kolab
::
cDateTime
(
"Europe/Berlin"
,
2006
,
1
,
8
,
12
,
0
,
0
)
<<
KDateTime
(
QDate
(
2006
,
1
,
8
),
QTime
(
12
,
0
,
0
),
KSystemTimeZones
::
zone
(
"Europe/Berlin"
))
<<
3600
;
}
void
KCalConversionTest
::
testDateTZ
()
{
QFETCH
(
Kolab
::
cDateTime
,
input
);
QFETCH
(
KDateTime
,
result
);
QFETCH
(
int
,
offset
);
const
KDateTime
&
r
=
Kolab
::
KCalConversion
::
toDate
(
input
);
QCOMPARE
(
result
.
timeZone
().
name
(),
QString
::
fromStdString
(
input
.
timezone
()));
QCOMPARE
(
r
.
timeZone
().
currentOffset
(),
offset
);
const
Kolab
::
cDateTime
&
r2
=
Kolab
::
KCalConversion
::
fromDate
(
result
);
QCOMPARE
(
QString
::
fromStdString
(
r2
.
timezone
()),
result
.
timeZone
().
name
());
}
void
KCalConversionTest
::
testConversion_data
()
{
QTest
::
addColumn
<
KCalCore
::
Event
>
(
"kcal"
);
QTest
::
addColumn
<
Kolab
::
Event
>
(
"kolab"
);
Kolab
::
cDateTime
date
(
2011
,
2
,
2
,
12
,
11
,
10
);
Kolab
::
cDateTime
date2
(
2011
,
2
,
2
,
12
,
12
,
10
);
Kolab
::
cDateTime
date3
(
2012
,
2
,
2
,
12
,
12
,
10
);
std
::
vector
<
int
>
intVector
;
intVector
.
push_back
(
1
);
intVector
.
push_back
(
-3
);
intVector
.
push_back
(
2
);
std
::
vector
<
std
::
string
>
stringVector
;
stringVector
.
push_back
(
"cat1"
);
stringVector
.
push_back
(
"cat2"
);
stringVector
.
push_back
(
"parent/child"
);
{
KCalCore
::
Event
kcal
;
kcal
.
setUid
(
"uid"
);
kcal
.
setCreated
(
toDate
(
date
));
kcal
.
setLastModified
(
toDate
(
date
));
kcal
.
setRevision
(
3
);
kcal
.
setSecrecy
(
KCalCore
::
Incidence
::
SecrecyConfidential
);
kcal
.
setCategories
(
toStringList
(
stringVector
));
kcal
.
setDtStart
(
toDate
(
date
));
kcal
.
setDtEnd
(
toDate
(
date2
));
kcal
.
setTransparency
(
KCalCore
::
Event
::
Transparent
);
kcal
.
setRecurrenceId
(
toDate
(
date2
));
//TODO THISANDFUTURE
kcal
.
recurrence
()
->
setDaily
(
3
);
kcal
.
recurrence
()
->
setDuration
(
5
);
kcal
.
recurrence
()
->
addRDateTime
(
toDate
(
date2
));
kcal
.
recurrence
()
->
addRDate
(
toDate
(
date2
).
date
());
kcal
.
recurrence
()
->
addExDateTime
(
toDate
(
date3
));
kcal
.
recurrence
()
->
addExDate
(
toDate
(
date3
).
date
());
KCalCore
::
RecurrenceRule
*
rr
=
kcal
.
recurrence
()
->
defaultRRule
(
true
);
QList
<
int
>
intList
=
QVector
<
int
>::
fromStdVector
(
intVector
).
toList
();
rr
->
setBySeconds
(
intList
);
rr
->
setByMinutes
(
intList
);
rr
->
setByHours
(
intList
);
rr
->
setByDays
(
QList
<
KCalCore
::
RecurrenceRule
::
WDayPos
>
()
<<
KCalCore
::
RecurrenceRule
::
WDayPos
(
3
,
1
)
<<
KCalCore
::
RecurrenceRule
::
WDayPos
(
5
,
4
));
rr
->
setByMonthDays
(
intList
);
rr
->
setByYearDays
(
intList
);
rr
->
setByMonths
(
intList
);
rr
->
setByWeekNumbers
(
intList
);
kcal
.
setSummary
(
"summary"
);
kcal
.
setDescription
(
"description"
);
kcal
.
setPriority
(
3
);
kcal
.
setStatus
(
KCalCore
::
Incidence
::
StatusConfirmed
);
kcal
.
setLocation
(
"location"
);
kcal
.
setOrganizer
(
KCalCore
::
Person
::
Ptr
(
new
KCalCore
::
Person
(
"organizer"
,
"organizer@email"
)));
kcal
.
addAttendee
(
KCalCore
::
Attendee
::
Ptr
(
new
KCalCore
::
Attendee
(
"attendee"
,
"attendee@email"
,
false
,
KCalCore
::
Attendee
::
NeedsAction
,
KCalCore
::
Attendee
::
ReqParticipant
)));
//TODO KCalCore Delegate/Delegator
kcal
.
addAttachment
(
KCalCore
::
Attachment
::
Ptr
(
new
KCalCore
::
Attachment
(
QString
(
"uri"
),
"mimetype/mime"
)));
KCalCore
::
Alarm
::
Ptr
alarm
=
KCalCore
::
Alarm
::
Ptr
(
new
KCalCore
::
Alarm
(
&
kcal
));
KCalCore
::
Person
::
List
addressees
;
addressees
.
append
(
KCalCore
::
Person
::
Ptr
(
new
KCalCore
::
Person
(
"name"
,
"email@email"
)));
alarm
->
setEmailAlarm
(
"subject"
,
"text"
,
addressees
,
QStringList
());
//No support for attachments
kcal
.
addAlarm
(
alarm
);
//TODO alarms
//TODO custom properties
Kolab
::
Event
kolab
;
kolab
.
setUid
(
"uid"
);
kolab
.
setCreated
(
date
);
kolab
.
setLastModified
(
date
);
kolab
.
setSequence
(
3
);
kolab
.
setClassification
(
Kolab
::
ClassConfidential
);
kolab
.
setCategories
(
stringVector
);
kolab
.
setStart
(
date
);
kolab
.
setEnd
(
date2
);
kolab
.
setTransparency
(
true
);
Kolab
::
RecurrenceRule
rrule
;
rrule
.
setInterval
(
3
);
rrule
.
setFrequency
(
Kolab
::
RecurrenceRule
::
Daily
);
rrule
.
setCount
(
5
);
rrule
.
setBysecond
(
intVector
);
rrule
.
setByminute
(
intVector
);
rrule
.
setByhour
(
intVector
);
rrule
.
setByday
(
std
::
vector
<
Kolab
::
DayPos
>
()
<<
Kolab
::
DayPos
(
3
,
Kolab
::
Monday
)
<<
Kolab
::
DayPos
(
5
,
Kolab
::
Thursday
));
rrule
.
setBymonthday
(
intVector
);
rrule
.
setByyearday
(
intVector
);
rrule
.
setByweekno
(
intVector
);
rrule
.
setBymonth
(
intVector
);
kolab
.
setRecurrenceRule
(
rrule
);
kolab
.
setRecurrenceID
(
date2
,
true
);
kolab
.
setRecurrenceDates
(
std
::
vector
<
Kolab
::
cDateTime
>
()
<<
date2
<<
Kolab
::
cDateTime
(
date2
.
year
(),
date2
.
month
(),
date2
.
day
()));
kolab
.
setExceptionDates
(
std
::
vector
<
Kolab
::
cDateTime
>
()
<<
date3
<<
Kolab
::
cDateTime
(
date3
.
year
(),
date3
.
month
(),
date3
.
day
()));
kolab
.
setSummary
(
"summary"
);
kolab
.
setDescription
(
"description"
);
kolab
.
setPriority
(
3
);
kolab
.
setStatus
(
Kolab
::
StatusConfirmed
);
kolab
.
setLocation
(
"location"
);
kolab
.
setOrganizer
(
Kolab
::
ContactReference
(
Kolab
::
ContactReference
::
EmailReference
,
"organizer@email"
,
"organizer"
));
//TODO uid
Kolab
::
Attendee
a
(
Kolab
::
ContactReference
(
Kolab
::
ContactReference
::
EmailReference
,
"attendee@email"
,
"attendee"
));
//TODO uid
kolab
.
setAttendees
(
std
::
vector
<
Kolab
::
Attendee
>
()
<<
a
);
Kolab
::
Attachment
attach
;
attach
.
setUri
(
"uri"
,
"mimetype/mime"
);
kolab
.
setAttachments
(
std
::
vector
<
Kolab
::
Attachment
>
()
<<
attach
);
// std::vector<std::string> receipents;
// receipents.push_back("email@email");
// Kolab::Alarm alarm2("summary", "description", receipents);
// kolab.setAlarms(std::vector<Kolab::Alarm>() << alarm2);
QTest
::
newRow
(
"with endDate and recurrence duration"
)
<<
kcal
<<
kolab
;
}
{
KCalCore
::
Event
kcal
;
kcal
.
setUid
(
"uid"
);
kcal
.
setCreated
(
toDate
(
date
));
kcal
.
setLastModified
(
toDate
(
date
));
kcal
.
setRevision
(
3
);
kcal
.
setDtStart
(
toDate
(
date
));
kcal
.
setDuration
(
KCalCore
::
Duration
(
toDate
(
date
),
toDate
(
date2
)));
kcal
.
recurrence
()
->
setDaily
(
3
);
kcal
.
recurrence
()
->
setEndDateTime
(
toDate
(
date3
));
Kolab
::
Event
kolab
;
kolab
.
setUid
(
"uid"
);
kolab
.
setCreated
(
date
);
kolab
.
setLastModified
(
date
);
kolab
.
setSequence
(
3
);
kolab
.
setStart
(
date
);
kolab
.
setDuration
(
Kolab
::
Duration
(
0
,
0
,
1
,
0
));
Kolab
::
RecurrenceRule
rrule
;
rrule
.
setInterval
(
3
);
rrule
.
setFrequency
(
Kolab
::
RecurrenceRule
::
Daily
);
rrule
.
setEnd
(
date3
);
kolab
.
setRecurrenceRule
(
rrule
);
QTest
::
newRow
(
"with duration and recurrence endDate"
)
<<
kcal
<<
kolab
;
}
{
Kolab
::
cDateTime
start
(
2011
,
1
,
1
);
Kolab
::
cDateTime
end
(
2011
,
1
,
3
);
KCalCore
::
Event
kcal
;
kcal
.
setUid
(
"uid"
);
kcal
.
setCreated
(
toDate
(
date
));
kcal
.
setLastModified
(
toDate
(
date
));
kcal
.
setDtStart
(
toDate
(
start
));
kcal
.
setDtEnd
(
toDate
(
end
));
kcal
.
recurrence
()
->
setDaily
(
3
);
kcal
.
recurrence
()
->
setEndDateTime
(
toDate
(
end
));
Kolab
::
Event
kolab
;
kolab
.
setUid
(
"uid"
);
kolab
.
setCreated
(
date
);
kolab
.
setLastModified
(
date
);
kolab
.
setStart
(
start
);
kolab
.
setEnd
(
end
);
Kolab
::
RecurrenceRule
rrule
;
rrule
.
setInterval
(
3
);
rrule
.
setFrequency
(
Kolab
::
RecurrenceRule
::
Daily
);
rrule
.
setEnd
(
end
);
kolab
.
setRecurrenceRule
(
rrule
);
QTest
::
newRow
(
"date only dates"
)
<<
kcal
<<
kolab
;
}
}
void
KCalConversionTest
::
testConversion
()
{
QFETCH
(
KCalCore
::
Event
,
kcal
);
QFETCH
(
Kolab
::
Event
,
kolab
);
const
KCalCore
::
Event
::
Ptr
e
=
toKCalCore
(
kolab
);
QCOMPARE
(
e
->
uid
(),
kcal
.
uid
());
QCOMPARE
(
e
->
created
(),
kcal
.
created
());
QCOMPARE
(
e
->
lastModified
(),
kcal
.
lastModified
());
QCOMPARE
(
e
->
revision
(),
kcal
.
revision
());
QCOMPARE
(
e
->
secrecy
(),
kcal
.
secrecy
());
QCOMPARE
(
e
->
categories
(),
kcal
.
categories
());
QCOMPARE
(
e
->
dtStart
(),
kcal
.
dtStart
());
QCOMPARE
(
e
->
dtEnd
(),
kcal
.
dtEnd
());
QCOMPARE
(
e
->
duration
(),
kcal
.
duration
());
QCOMPARE
(
e
->
transparency
(),
kcal
.
transparency
());
QCOMPARE
(
*
e
->
recurrence
(),
*
kcal
.
recurrence
());
QCOMPARE
(
e
->
recurrenceId
(),
kcal
.
recurrenceId
());
QCOMPARE
(
e
->
recurrenceType
(),
kcal
.
recurrenceType
());
QCOMPARE
(
e
->
summary
(),
kcal
.
summary
());
QCOMPARE
(
e
->
description
(),
kcal
.
description
());
QCOMPARE
(
e
->
priority
(),
kcal
.
priority
());
QCOMPARE
(
e
->
status
(),
kcal
.
status
());
QCOMPARE
(
e
->
location
(),
kcal
.
location
());
QCOMPARE
(
e
->
organizer
()
->
name
(),
kcal
.
organizer
()
->
name
());
QCOMPARE
(
e
->
organizer
()
->
email
(),
kcal
.
organizer
()
->
email
());
comparePointerVectors
(
e
->
attendees
(),
kcal
.
attendees
());
comparePointerVectors
(
e
->
attachments
(),
kcal
.
attachments
());
// QCOMPARE(e->alarms(), kcal.alarms()); //TODO
//TODO custom properties
QBENCHMARK
{
toKCalCore
(
kolab
);
}
const
Kolab
::
Event
&
b
=
fromKCalCore
(
kcal
);
QCOMPARE
(
b
.
uid
(),
kolab
.
uid
());
QCOMPARE
(
b
.
created
(),
kolab
.
created
());
QCOMPARE
(
b
.
lastModified
(),
kolab
.
lastModified
());
QCOMPARE
(
b
.
sequence
(),
kolab
.
sequence
());
QCOMPARE
(
b
.
classification
(),
kolab
.
classification
());
QCOMPARE
(
b
.
categories
(),
kolab
.
categories
());
QCOMPARE
(
b
.
start
(),
kolab
.
start
());
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
());
QCOMPARE
(
b
.
recurrenceDates
(),
kolab
.
recurrenceDates
());
QCOMPARE
(
b
.
exceptionDates
(),
kolab
.
exceptionDates
());
QCOMPARE
(
b
.
summary
(),
kolab
.
summary
());
QCOMPARE
(
b
.
description
(),
kolab
.
description
());
QCOMPARE
(
b
.
status
(),
kolab
.
status
());
}
void
KCalConversionTest
::
testTodoConversion_data
()
{
QTest
::
addColumn
<
KCalCore
::
Todo
>
(
"kcal"
);
QTest
::
addColumn
<
Kolab
::
Todo
>
(
"kolab"
);
Kolab
::
cDateTime
date
(
2011
,
2
,
2
,
12
,
11
,
10
);
Kolab
::
cDateTime
date2
(
2011
,
2
,
2
,
12
,
12
,
10
);
{
KCalCore
::
Todo
kcal
;
kcal
.
setUid
(
"uid"
);
kcal
.
setDtStart
(
toDate
(
date
));
kcal
.
setDtDue
(
toDate
(
date2
));
Kolab
::
Todo
kolab
;
kolab
.
setUid
(
"uid"
);
kolab
.
setStart
(
date
);
kolab
.
setDue
(
date2
);
QTest
::
newRow
(
"todo"
)
<<
kcal
<<
kolab
;
}
}
void
KCalConversionTest
::
testTodoConversion
()
{
QFETCH
(
KCalCore
::
Todo
,
kcal
);
QFETCH
(
Kolab
::
Todo
,
kolab
);
const
KCalCore
::
Todo
::
Ptr
e
=
toKCalCore
(
kolab
);
QCOMPARE
(
e
->
uid
(),
kcal
.
uid
());
QCOMPARE
(
e
->
dtStart
(),
kcal
.
dtStart
());
QCOMPARE
(
e
->
dtDue
(),
kcal
.
dtDue
());
const
Kolab
::
Todo
&
b
=
fromKCalCore
(
kcal
);
QCOMPARE
(
b
.
uid
(),
kolab
.
uid
());
QCOMPARE
(
b
.
start
(),
kolab
.
start
());
QCOMPARE
(
b
.
due
(),
kolab
.
due
());
}
void
KCalConversionTest
::
testJournalConversion_data
()
{
QTest
::
addColumn
<
KCalCore
::
Journal
>
(
"kcal"
);
QTest
::
addColumn
<
Kolab
::
Journal
>
(
"kolab"
);
Kolab
::
cDateTime
date
(
2011
,
2
,
2
,
12
,
11
,
10
);
Kolab
::
cDateTime
date2
(
2011
,
2
,
2
,
12
,
12
,
10
);
{
KCalCore
::
Journal
kcal
;
kcal
.
setUid
(
"uid"
);
kcal
.
setDtStart
(
toDate
(
date
));
kcal
.
setSummary
(
"summary"
);
Kolab
::
Journal
kolab
;
kolab
.
setUid
(
"uid"
);
kolab
.
setStart
(
date
);
kolab
.
setSummary
(
"summary"
);
QTest
::
newRow
(
"journal"
)
<<
kcal
<<
kolab
;
}
}
void
KCalConversionTest
::
testJournalConversion
()
{
QFETCH
(
KCalCore
::
Journal
,
kcal
);
QFETCH
(
Kolab
::
Journal
,
kolab
);
const
KCalCore
::
Journal
::
Ptr
e
=
toKCalCore
(
kolab
);
QCOMPARE
(
e
->
uid
(),
kcal
.
uid
());
QCOMPARE
(
e
->
dtStart
(),
kcal
.
dtStart
());
QCOMPARE
(
e
->
summary
(),
kcal
.
summary
());
const
Kolab
::
Journal
&
b
=
fromKCalCore
(
kcal
);
QCOMPARE
(
b
.
uid
(),
kolab
.
uid
());
QCOMPARE
(
b
.
start
(),
kolab
.
start
());
QCOMPARE
(
b
.
summary
(),
kolab
.
summary
());
}
void
KCalConversionTest
::
testEventConflict_data
()
{
QTest
::
addColumn
<
Kolab
::
Event
>
(
"e1"
);
QTest
::
addColumn
<
Kolab
::
Event
>
(
"e2"
);
QTest
::
addColumn
<
bool
>
(
"result"
);
{
Kolab
::
Event
e1
;
e1
.
setStart
(
Kolab
::
cDateTime
(
2011
,
10
,
10
,
12
,
1
,
1
));
e1
.
setEnd
(
Kolab
::
cDateTime
(
2011
,
10
,
11
,
12
,
1
,
1
));
Kolab
::
Event
e2
;
e2
.
setStart
(
Kolab
::
cDateTime
(
2011
,
11
,
10
,
12
,
1
,
1
));
e2
.
setEnd
(
Kolab
::
cDateTime
(
2011
,
11
,
11
,
12
,
1
,
1
));
QTest
::
newRow
(
"after"
)
<<
e1
<<
e2
<<
false
;
}
{
Kolab
::
Event
e1
;
e1
.
setStart
(
Kolab
::
cDateTime
(
2011
,
10
,
10
,
12
,
1
,
1
));
e1
.
setEnd
(
Kolab
::
cDateTime
(
2011
,
10
,
11
,
12
,
1
,
1
));
Kolab
::
Event
e2
;
e2
.
setStart
(
Kolab
::
cDateTime
(
2011
,
9
,
10
,
12
,
1
,
1
));
e2
.
setEnd
(
Kolab
::
cDateTime
(
2011
,
9
,
11
,
12
,
1
,
1
));
QTest
::
newRow
(
"before"
)
<<
e1
<<
e2
<<
false
;
}
{
Kolab
::
Event
e1
;
e1
.
setStart
(
Kolab
::
cDateTime
(
2011
,
10
,
10
,
12
,
1
,
1
));
e1
.
setEnd
(
Kolab
::
cDateTime
(
2011
,
10
,
11
,
12
,
1
,
1
));
Kolab
::
Event
e2
;
e2
.
setStart
(
Kolab
::
cDateTime
(
2011
,
10
,
10
,
12
,
1
,
1
));
e2
.
setEnd
(
Kolab
::
cDateTime
(
2011
,
10
,
11
,
12
,
1
,
1
));
QTest
::
newRow
(
"conflict"
)
<<
e1
<<
e2
<<
true
;
}
{
Kolab
::
Event
e1
;
e1
.
setStart
(
Kolab
::
cDateTime
(
"Europe/Zurich"
,
2011
,
10
,
10
,
6
,
1
,
1
));
e1
.
setEnd
(
Kolab
::
cDateTime
(
"Europe/Zurich"
,
2011
,
10
,
10
,
6
,
1
,
2
));
Kolab
::
Event
e2
;
e2
.
setStart
(
Kolab
::
cDateTime
(
"Asia/Dubai"
,
2011
,
10
,
10
,
6
,
1
,
1
));
e2
.
setEnd
(
Kolab
::
cDateTime
(
"Asia/Dubai"
,
2011
,
10
,
10
,
6
,
1
,
2
));
QTest
::
newRow
(
"tz non-conflict"
)
<<
e1
<<
e2
<<
false
;
}
{
Kolab
::
Event
e1
;
e1
.
setStart
(
Kolab
::
cDateTime
(
"Europe/Berlin"
,
2011
,
10
,
10
,
6
,
1
,
1
));
e1
.
setEnd
(
Kolab
::
cDateTime
(
"Europe/Berlin"
,
2011
,
10
,
10
,
6
,
1
,
2
));
Kolab
::
Event
e2
;
e2
.
setStart
(
Kolab
::
cDateTime
(
"Europe/Zurich"
,
2011
,
10
,
10
,
6
,
1
,
1
));
e2
.
setEnd
(
Kolab
::
cDateTime
(
"Europe/Zurich"
,
2011
,
10
,
10
,
6
,
1
,
2
));
QTest
::
newRow
(
"tz conflict"
)
<<
e1
<<
e2
<<
true
;
}
}
void
KCalConversionTest
::
testEventConflict
()
{
QFETCH
(
Kolab
::
Event
,
e1
);
QFETCH
(
Kolab
::
Event
,
e2
);
QFETCH
(
bool
,
result
);
QCOMPARE
(
Kolab
::
Calendaring
::
conflicts
(
e1
,
e2
),
result
);
}
void
KCalConversionTest
::
testTimesInInterval_data
()
{
QTest
::
addColumn
<
Kolab
::
Event
>
(
"event"
);
QTest
::
addColumn
<
Kolab
::
cDateTime
>
(
"start"
);
QTest
::
addColumn
<
Kolab
::
cDateTime
>
(
"end"
);
QTest
::
addColumn
<
std
::
vector
<
Kolab
::
cDateTime
>
>
(
"result"
);
{
{
Kolab
::
Event
event
;
event
.
setStart
(
Kolab
::
cDateTime
(
2011
,
1
,
1
,
1
,
1
,
1
));
event
.
setEnd
(
Kolab
::
cDateTime
(
2011
,
1
,
1
,
2
,
1
,
1
));
Kolab
::
RecurrenceRule
rrule
;
rrule
.
setFrequency
(
Kolab
::
RecurrenceRule
::
Daily
);
rrule
.
setInterval
(
1
);
rrule
.
setCount
(
5
);
event
.
setRecurrenceRule
(
rrule
);
std
::
vector
<
Kolab
::
cDateTime
>
result
;
result
.
push_back
(
Kolab
::
cDateTime
(
2011
,
1
,
1
,
1
,
1
,
1
));
result
.
push_back
(
Kolab
::
cDateTime
(
2011
,
1
,
2
,
1
,
1
,
1
));
result
.
push_back
(
Kolab
::
cDateTime
(
2011
,
1
,
3
,
1
,
1
,
1
));
result
.
push_back
(
Kolab
::
cDateTime
(
2011
,
1
,
4
,
1
,
1
,
1
));
result
.
push_back
(
Kolab
::
cDateTime
(
2011
,
1
,
5
,
1
,
1
,
1
));
QTest
::
newRow
(
"simple"
)
<<
event
<<
Kolab
::
cDateTime
(
2011
,
1
,
1
,
1
,
1
,
1
)
<<
Kolab
::
cDateTime
(
2011
,
1
,
5
,
1
,
1
,
1
)
<<
result
;
}
}
}
void
KCalConversionTest
::
testTimesInInterval
()
{
QFETCH
(
Kolab
::
Event
,
event
);
QFETCH
(
Kolab
::
cDateTime
,
start
);
QFETCH
(
Kolab
::
cDateTime
,
end
);
QFETCH
(
std
::
vector
<
Kolab
::
cDateTime
>
,
result
);
QCOMPARE
(
Kolab
::
Calendaring
::
timeInInterval
(
event
,
start
,
end
),
result
);
}
void
KCalConversionTest
::
testTimesInIntervalBenchmark
()
{
Kolab
::
Event
event
;
event
.
setStart
(
Kolab
::
cDateTime
(
2011
,
1
,
1
,
1
,
1
,
1
));
event
.
setEnd
(
Kolab
::
cDateTime
(
2011
,
1
,
1
,
2
,
1
,
1
));
Kolab
::
RecurrenceRule
rrule
;
rrule
.
setFrequency
(
Kolab
::
RecurrenceRule
::
Daily
);
rrule
.
setInterval
(
1
);
rrule
.
setCount
(
500
);
event
.
setRecurrenceRule
(
rrule
);
QBENCHMARK
{
Kolab
::
Calendaring
::
timeInInterval
(
event
,
Kolab
::
cDateTime
(
2011
,
1
,
1
,
1
,
1
,
1
),
Kolab
::
cDateTime
(
2013
,
1
,
1
,
1
,
1
,
1
));
}
const
std
::
vector
<
Kolab
::
cDateTime
>
&
result
=
Kolab
::
Calendaring
::
timeInInterval
(
event
,
Kolab
::
cDateTime
(
2011
,
1
,
1
,
1
,
1
,
1
),
Kolab
::
cDateTime
(
2013
,
1
,
1
,
1
,
1
,
1
));
QVERIFY
(
result
.
size
()
==
500
);
// qDebug() << QTest::toString(result);
}
QTEST_MAIN
(
KCalConversionTest
)
#include
"kcalconversiontest.moc"
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Mon, Apr 6, 1:14 AM (2 d, 7 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
46/04/5255591c7e764c5e14073ce7386c
Default Alt Text
kcalconversiontest.cpp (24 KB)
Attached To
Mode
rLKX libkolabxml
Attached
Detach File
Event Timeline