1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
/*
This file is part of the testing framework for libkcal.
Copyright (c) 2005 Adriaan de Groot <groot@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <tdeaboutdata.h>
#include <tdeapplication.h>
#include <kdebug.h>
#include <klocale.h>
#include <tdecmdlineargs.h>
#include "calendarlocal.h"
#include <tqfile.h>
using namespace KCal;
static const TDECmdLineOptions options[] =
{
{"verbose", "Verbose output", 0},
TDECmdLineLastOption
};
int main(int argc,char **argv)
{
TDEAboutData aboutData("testfields","Test calendar fields read/write","0.1");
TDECmdLineArgs::init(argc,argv,&aboutData);
TDECmdLineArgs::addCmdLineOptions( options );
// TDEApplication app( false, false );
TDEApplication app;
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
Q_UNUSED(args)
CalendarLocal cal( TQString::fromLatin1("UTC") );
TQString file = TQString::fromLatin1( INPUT );
if (!cal.load( file ) ) {
kdError() << "Can't load " << file << endl;
return 1;
}
// 2 tests... first uid should result in a syncStatus of 0. second uid
// should have a new summary and a 1 for syncStatus.
TQString uid1 = TQString::fromLatin1("KOrganizer-1345486115.965");
TQString uid2 = TQString::fromLatin1("KOrganizer-1345486115.967");
Event *e = cal.event( uid1 );
if (!e) {
kdError() << "No event " << uid1 << endl;
return 1;
}
kdDebug() << "Event description " << e->summary() << endl;
if (e->hasEndDate()) {
TQDateTime d = e->dtEnd();
kdDebug() << "Event ends " << d << endl;
}
if (e->pilotId()) {
kdDebug() << "Pilot ID = " << e->pilotId() << endl;
kdDebug() << "Pilot Sync Status = " << e->syncStatus() << endl;
} else {
kdError() << "No Pilot ID" << endl;
return 1;
}
kdDebug() << "First test passed. Able to read fields." << endl;
e->setSyncStatus(KCal::Incidence::SYNCNONE);
TQString newSummary = TQString::fromLatin1("Mooo summary");
Event *f = new Event(*e);
f->setUid(uid2);
// add event so we trigger updated()
cal.addEvent(f);
f->setPilotId(34567);
f->setSummary(newSummary);
TQString filew = file +".out";
// weird, yes, I know, but we have a bug right now with saving the file
// twice which is corrupting X-PILOTSTAT
if ( !cal.save( filew ) || !cal.save( filew ) ) {
kdError() << "Can't save " << filew << endl;
return 1;
}
// now try to read the file back in and see if our changes made it
CalendarLocal cal2( TQString::fromLatin1("UTC") );
if (!cal2.load( filew ) ) {
kdError() << "Can't load " << filew << endl;
return 1;
}
TQFile::remove( filew );
// check for uid1--should have syncStatus of 0
e = cal2.event( uid1 );
if (!e) {
kdError() << "No event for first read test" << uid1 << endl;
return 1;
}
kdDebug() << "Event 1 description " << e->summary() << endl;
if (e->pilotId()) {
kdDebug() << "First Pilot ID = " << e->pilotId() << endl;
kdDebug() << "First Pilot Sync Status = " << e->syncStatus() << endl;
} else {
kdError() << "No Pilot ID for first test" << endl;
return 1;
}
if (e->syncStatus() != KCal::Incidence::SYNCNONE) {
kdError() << "Wrong Pilot sync status." << endl;
return 1;
}
// now check our second event for correctness
f = cal2.event( uid2 );
kdDebug() << "Event 2 description " << f->summary() << endl;
if (f->summary() != newSummary) {
kdError() << "Wrong summary for second read test." << endl;
return 1;
}
if (f->pilotId()) {
kdDebug() << "Second Pilot ID = " << f->pilotId() << endl;
kdDebug() << "Second Pilot Sync Status = " << f->syncStatus() << endl;
} else {
kdError() << "No Pilot ID for second read test" << endl;
return 1;
}
if (f->syncStatus() != KCal::Incidence::SYNCMOD) {
kdError() << "Wrong Pilot sync status for second read test." << endl;
return 1;
}
return 0;
}
|