1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 // System include |
|
19 #include <QtTest/QtTest> |
|
20 #include <HbMainWindow> |
|
21 #include <NotesEditor> |
|
22 #include <AgendaUtil> |
|
23 #include <AgendaEntry> |
|
24 |
|
25 // User includes |
|
26 #include "unittest_noteseditor.h" |
|
27 |
|
28 |
|
29 /*! |
|
30 \class TestNotesEditor |
|
31 |
|
32 Unit test clas for Notes Editor apis |
|
33 */ |
|
34 |
|
35 |
|
36 /*! |
|
37 Constructor |
|
38 */ |
|
39 |
|
40 TestNotesEditor::TestNotesEditor() |
|
41 { |
|
42 |
|
43 } |
|
44 |
|
45 /*! |
|
46 Destructor |
|
47 */ |
|
48 TestNotesEditor::~TestNotesEditor() |
|
49 { |
|
50 } |
|
51 |
|
52 /*! |
|
53 Initialise before calling the test case |
|
54 */ |
|
55 void TestNotesEditor::init() |
|
56 { |
|
57 } |
|
58 |
|
59 /*! |
|
60 Do cleanup after each test case |
|
61 */ |
|
62 void TestNotesEditor::cleanup() |
|
63 { |
|
64 } |
|
65 |
|
66 /*! |
|
67 Test the api NotesEditor::NotesEditor() |
|
68 */ |
|
69 |
|
70 void TestNotesEditor::testConstructionWithoutAgendaUtil() |
|
71 { |
|
72 // Create NotesEditor object |
|
73 NotesEditor *notesEditor = new NotesEditor(this); |
|
74 QVERIFY(notesEditor!=0); |
|
75 |
|
76 // Cleanup |
|
77 delete notesEditor; |
|
78 } |
|
79 |
|
80 /*! |
|
81 Test the api NotesEditor::NotesEditor() |
|
82 */ |
|
83 void TestNotesEditor::testConstructionWithAgendaUtil() |
|
84 { |
|
85 // Create AgendaUtil object. |
|
86 AgendaUtil *agendaUtil = new AgendaUtil(); |
|
87 QVERIFY(agendaUtil); |
|
88 |
|
89 // Create NotesEditor object. |
|
90 NotesEditor *notesEditor = new NotesEditor(agendaUtil); |
|
91 |
|
92 QVERIFY(notesEditor!=0); |
|
93 |
|
94 // Cleanup. |
|
95 delete notesEditor; |
|
96 delete agendaUtil; |
|
97 } |
|
98 |
|
99 /*! |
|
100 Test the api NotesEditor::~NotesEditor |
|
101 */ |
|
102 void TestNotesEditor::testDestruction() |
|
103 { |
|
104 // Create NotesEditor object. |
|
105 QPointer<NotesEditor> notesEditor = new NotesEditor(); |
|
106 delete notesEditor; |
|
107 |
|
108 QVERIFY(!notesEditor); |
|
109 |
|
110 // Create AgendaUtil object. |
|
111 QPointer<AgendaUtil> agendaUtil = new AgendaUtil(); |
|
112 QPointer<NotesEditor> notesEditorWithAgendaUtil = |
|
113 new NotesEditor(agendaUtil); |
|
114 |
|
115 delete notesEditorWithAgendaUtil; |
|
116 delete agendaUtil; |
|
117 |
|
118 QVERIFY(!notesEditorWithAgendaUtil); |
|
119 } |
|
120 |
|
121 /*! |
|
122 Test the api NotesEditor::edit(const QString &string) |
|
123 */ |
|
124 void TestNotesEditor::testEditingNoteWithText() |
|
125 { |
|
126 HbMainWindow window; |
|
127 window.show(); |
|
128 // Create NotesEditor object. |
|
129 NotesEditor *notesEditor = new NotesEditor(this); |
|
130 QVERIFY(notesEditor); |
|
131 |
|
132 QString noteText("This is test note"); |
|
133 // Call edit using the text. |
|
134 notesEditor->edit(QString("This is test note")); |
|
135 |
|
136 QTest::qWait(1000); |
|
137 |
|
138 // Call close on editor by saving the note |
|
139 ulong id = notesEditor->close(NotesEditor::CloseWithSave); |
|
140 QVERIFY(id); |
|
141 |
|
142 // Create agenda Utility. |
|
143 AgendaUtil *agendaUtil = new AgendaUtil(); |
|
144 QVERIFY(agendaUtil); |
|
145 |
|
146 // Fetch the entry using the id |
|
147 AgendaEntry entry = agendaUtil->fetchById(id); |
|
148 |
|
149 int compareResult = noteText.compare(entry.description()); |
|
150 QVERIFY(!compareResult); |
|
151 |
|
152 delete agendaUtil; |
|
153 delete notesEditor; |
|
154 } |
|
155 |
|
156 /*! |
|
157 Test the api NotesEditor::edit(const QFile &handle) |
|
158 */ |
|
159 void TestNotesEditor::testEditingNoteWithFileHandle() |
|
160 { |
|
161 // Nothing yet |
|
162 } |
|
163 |
|
164 /*! |
|
165 Test the api NotesEditor::edit(AgendaEntry entry) |
|
166 */ |
|
167 void TestNotesEditor::testEditingNoteWithAgendaEntry() |
|
168 { |
|
169 HbMainWindow window; |
|
170 window.show(); |
|
171 |
|
172 NotesEditor *notesEditor = new NotesEditor(); |
|
173 QVERIFY(notesEditor); |
|
174 |
|
175 AgendaEntry entry; |
|
176 entry.setType(AgendaEntry::TypeNote); |
|
177 entry.setDescription(QString("A simple note")); |
|
178 |
|
179 // Call edit on agenda entry |
|
180 notesEditor->edit(entry); |
|
181 |
|
182 QTest::qWait(1000); |
|
183 |
|
184 ulong id = notesEditor->close(NotesEditor::CloseWithSave); |
|
185 |
|
186 AgendaUtil *agendaUtil = new AgendaUtil(); |
|
187 QVERIFY(agendaUtil); |
|
188 |
|
189 AgendaEntry afterSave = agendaUtil->fetchById(id); |
|
190 QCOMPARE(afterSave.description(), entry.description()); |
|
191 |
|
192 delete agendaUtil; |
|
193 delete notesEditor; |
|
194 } |
|
195 |
|
196 /*! |
|
197 Test the api NotesEditor::edit(ulong id) |
|
198 */ |
|
199 void TestNotesEditor::testEditingNoteWithId() |
|
200 { |
|
201 HbMainWindow window; |
|
202 window.show(); |
|
203 |
|
204 NotesEditor *notesEditor = new NotesEditor(); |
|
205 QVERIFY(notesEditor); |
|
206 |
|
207 AgendaUtil *agendaUtil = new AgendaUtil(); |
|
208 QVERIFY(agendaUtil); |
|
209 |
|
210 AgendaEntry entry; |
|
211 entry.setType(AgendaEntry::TypeNote); |
|
212 entry.setDescription("A simple note"); |
|
213 |
|
214 ulong id = agendaUtil->addEntry(entry); |
|
215 |
|
216 notesEditor->edit(id); |
|
217 |
|
218 QTest::qWait(1000); |
|
219 |
|
220 ulong savedId = notesEditor->close(NotesEditor::CloseWithSave); |
|
221 |
|
222 AgendaEntry afterSave = agendaUtil->fetchById(id); |
|
223 QCOMPARE(afterSave.description(), entry.description()); |
|
224 |
|
225 delete agendaUtil; |
|
226 delete notesEditor; |
|
227 |
|
228 } |
|
229 |
|
230 |
|
231 /*! |
|
232 Test the api NotesEditor::edit(const QFile &handle) |
|
233 */ |
|
234 void TestNotesEditor::testEditingTodoWithFileHandle() |
|
235 { |
|
236 // Nothing yet. |
|
237 } |
|
238 |
|
239 /*! |
|
240 Test the api NotesEditor::edit(AgendaEntry entry) |
|
241 */ |
|
242 void TestNotesEditor::testEditingTodoWithAgendaEntry() |
|
243 { |
|
244 HbMainWindow window; |
|
245 window.show(); |
|
246 |
|
247 NotesEditor *notesEditor = new NotesEditor(); |
|
248 QVERIFY(notesEditor); |
|
249 |
|
250 AgendaUtil *agendaUtil = new AgendaUtil(); |
|
251 QVERIFY(agendaUtil); |
|
252 |
|
253 // Create a agenda entry with type to-do |
|
254 AgendaEntry entry; |
|
255 entry.setType(AgendaEntry::TypeTodo); |
|
256 entry.setSummary(QString("Buy Books")); |
|
257 entry.setDescription(QString("@Landmarks")); |
|
258 entry.setStartAndEndTime( |
|
259 QDateTime::currentDateTime(),QDateTime::currentDateTime()); |
|
260 entry.setStatus(AgendaEntry::TodoNeedsAction); |
|
261 entry.setPriority(2); |
|
262 |
|
263 ulong id = agendaUtil->addEntry(entry); |
|
264 |
|
265 // Call edit on agenda entry |
|
266 notesEditor->edit(entry); |
|
267 |
|
268 QTest::qWait(3000); |
|
269 |
|
270 ulong afterSaveId = notesEditor->close(NotesEditor::CloseWithSave); |
|
271 |
|
272 AgendaEntry afterSave = agendaUtil->fetchById(id); |
|
273 QCOMPARE(afterSave.id(),id); |
|
274 QCOMPARE(afterSave.type(),entry.type()); |
|
275 QCOMPARE(afterSave.summary(), entry.summary()); |
|
276 QCOMPARE(afterSave.description(), entry.description()); |
|
277 |
|
278 delete agendaUtil; |
|
279 delete notesEditor; |
|
280 } |
|
281 |
|
282 /*! |
|
283 Test the api NotesEditor::edit(ulong id) |
|
284 */ |
|
285 void TestNotesEditor::testEditingTodoWithId() |
|
286 { |
|
287 HbMainWindow window; |
|
288 window.show(); |
|
289 |
|
290 NotesEditor *notesEditor = new NotesEditor(); |
|
291 QVERIFY(notesEditor); |
|
292 |
|
293 AgendaUtil *agendaUtil = new AgendaUtil(); |
|
294 QVERIFY(agendaUtil); |
|
295 |
|
296 // Create a agenda entry with type to-do |
|
297 AgendaEntry entry; |
|
298 entry.setType(AgendaEntry::TypeTodo); |
|
299 entry.setSummary(QString("Buy Books")); |
|
300 entry.setDescription(QString("@Landmarks")); |
|
301 entry.setStartAndEndTime( |
|
302 QDateTime::currentDateTime(),QDateTime::currentDateTime()); |
|
303 entry.setStatus(AgendaEntry::TodoNeedsAction); |
|
304 entry.setPriority(2); |
|
305 |
|
306 ulong id = agendaUtil->addEntry(entry); |
|
307 |
|
308 // Call edit using the id |
|
309 notesEditor->edit(id); |
|
310 |
|
311 QTest::qWait(3000); |
|
312 |
|
313 ulong afterSaveId = notesEditor->close(NotesEditor::CloseWithSave); |
|
314 |
|
315 AgendaEntry afterSave = agendaUtil->fetchById(id); |
|
316 QCOMPARE(afterSave.id(),id); |
|
317 QCOMPARE(afterSave.type(),entry.type()); |
|
318 QCOMPARE(afterSave.summary(), entry.summary()); |
|
319 QCOMPARE(afterSave.description(), entry.description()); |
|
320 |
|
321 delete agendaUtil; |
|
322 delete notesEditor; |
|
323 |
|
324 } |
|
325 |
|
326 /*! |
|
327 Test the api NotesEditor::create(CreateType type) |
|
328 */ |
|
329 void TestNotesEditor::testCreationOfNote() |
|
330 { |
|
331 HbMainWindow window; |
|
332 window.show(); |
|
333 |
|
334 NotesEditor *notesEditor = new NotesEditor(); |
|
335 QVERIFY(notesEditor); |
|
336 |
|
337 notesEditor->create(NotesEditor::CreateNote); |
|
338 |
|
339 QTest::qWait(3000); |
|
340 |
|
341 ulong afterSaveId = notesEditor->close(NotesEditor::CloseWithSave); |
|
342 |
|
343 // Note is not saved since description is empty |
|
344 // TODO use key press events here |
|
345 |
|
346 QVERIFY(!afterSaveId); |
|
347 |
|
348 delete notesEditor; |
|
349 } |
|
350 |
|
351 /*! |
|
352 Test the api NotesEditor::create(CreateType type) |
|
353 */ |
|
354 void TestNotesEditor::testCreationofTodo() |
|
355 { |
|
356 HbMainWindow window; |
|
357 window.show(); |
|
358 |
|
359 NotesEditor *notesEditor = new NotesEditor(); |
|
360 QVERIFY(notesEditor); |
|
361 |
|
362 notesEditor->create(NotesEditor::CreateTodo); |
|
363 |
|
364 // TODO |
|
365 // Needs key interaction to edit the fields in to-do editor. |
|
366 |
|
367 QTest::qWait(3000); |
|
368 |
|
369 delete notesEditor; |
|
370 } |
|
371 |
|
372 /*! |
|
373 Test the api NotesEditor::close(CloseType type); |
|
374 */ |
|
375 |
|
376 void TestNotesEditor::testClosingOfNotesEditorWithSave() |
|
377 { |
|
378 HbMainWindow window; |
|
379 window.show(); |
|
380 // Create NotesEditor object. |
|
381 NotesEditor *notesEditor = new NotesEditor(this); |
|
382 QVERIFY(notesEditor); |
|
383 |
|
384 QString noteText("This is test note"); |
|
385 // Call edit using the text. |
|
386 notesEditor->edit(QString("This is test note")); |
|
387 |
|
388 QTest::qWait(1000); |
|
389 |
|
390 // Call close on editor by saving the note |
|
391 ulong id = notesEditor->close(NotesEditor::CloseWithSave); |
|
392 QVERIFY(id); |
|
393 |
|
394 // Create agenda Utility. |
|
395 AgendaUtil *agendaUtil = new AgendaUtil(); |
|
396 QVERIFY(agendaUtil); |
|
397 |
|
398 // Fetch the entry using the id |
|
399 AgendaEntry entry = agendaUtil->fetchById(id); |
|
400 |
|
401 QCOMPARE(noteText,entry.description()); |
|
402 |
|
403 delete agendaUtil; |
|
404 delete notesEditor; |
|
405 } |
|
406 |
|
407 /*! |
|
408 Test the api NotesEditor::close(CloseType type); |
|
409 */ |
|
410 void TestNotesEditor::testClosingOfNotesEditorWithoutSave() |
|
411 { |
|
412 HbMainWindow window; |
|
413 window.show(); |
|
414 // Create NotesEditor object. |
|
415 NotesEditor *notesEditor = new NotesEditor(this); |
|
416 QVERIFY(notesEditor); |
|
417 |
|
418 QString noteText("This is test note"); |
|
419 // Call edit using the text. |
|
420 notesEditor->edit(QString("This is test note")); |
|
421 |
|
422 QTest::qWait(1000); |
|
423 |
|
424 // Call close on editor by saving the note |
|
425 ulong id = notesEditor->close(NotesEditor::CloseWithoutSave); |
|
426 QVERIFY(!id); |
|
427 |
|
428 delete notesEditor; |
|
429 } |
|
430 |
|
431 /*! |
|
432 Test the api NotesEditor::close(CloseType type); |
|
433 */ |
|
434 void TestNotesEditor::testClosingOfTodoEditorWithSave() |
|
435 { |
|
436 HbMainWindow window; |
|
437 window.show(); |
|
438 |
|
439 NotesEditor *notesEditor = new NotesEditor(); |
|
440 QVERIFY(notesEditor); |
|
441 |
|
442 AgendaUtil *agendaUtil = new AgendaUtil(); |
|
443 QVERIFY(agendaUtil); |
|
444 |
|
445 // Create a agenda entry with type to-do |
|
446 AgendaEntry entry; |
|
447 entry.setType(AgendaEntry::TypeTodo); |
|
448 entry.setSummary(QString("Buy Books")); |
|
449 entry.setDescription(QString("@Landmarks")); |
|
450 entry.setStartAndEndTime( |
|
451 QDateTime::currentDateTime(),QDateTime::currentDateTime()); |
|
452 entry.setStatus(AgendaEntry::TodoNeedsAction); |
|
453 entry.setPriority(2); |
|
454 |
|
455 ulong id = agendaUtil->addEntry(entry); |
|
456 |
|
457 // Call edit on agenda entry |
|
458 notesEditor->edit(entry); |
|
459 |
|
460 QTest::qWait(3000); |
|
461 |
|
462 ulong afterSaveId = notesEditor->close(NotesEditor::CloseWithSave); |
|
463 |
|
464 AgendaEntry afterSave = agendaUtil->fetchById(id); |
|
465 QCOMPARE(afterSave.id(),id); |
|
466 QCOMPARE(afterSave.type(),entry.type()); |
|
467 QCOMPARE(afterSave.summary(), entry.summary()); |
|
468 QCOMPARE(afterSave.description(), entry.description()); |
|
469 |
|
470 delete agendaUtil; |
|
471 delete notesEditor; |
|
472 } |
|
473 |
|
474 /*! |
|
475 Test the api NotesEditor::close(CloseType type); |
|
476 */ |
|
477 void TestNotesEditor::testClosingOfTodoEditorWithoutSave() |
|
478 { |
|
479 HbMainWindow window; |
|
480 window.show(); |
|
481 |
|
482 NotesEditor *notesEditor = new NotesEditor(); |
|
483 QVERIFY(notesEditor); |
|
484 |
|
485 AgendaUtil *agendaUtil = new AgendaUtil(); |
|
486 QVERIFY(agendaUtil); |
|
487 |
|
488 // Create a agenda entry with type to-do |
|
489 AgendaEntry entry; |
|
490 entry.setType(AgendaEntry::TypeTodo); |
|
491 entry.setSummary(QString("Buy Books")); |
|
492 entry.setDescription(QString("@Landmarks")); |
|
493 entry.setStartAndEndTime( |
|
494 QDateTime::currentDateTime(),QDateTime::currentDateTime()); |
|
495 entry.setStatus(AgendaEntry::TodoNeedsAction); |
|
496 entry.setPriority(2); |
|
497 |
|
498 ulong id = agendaUtil->addEntry(entry); |
|
499 |
|
500 // Call edit on agenda entry |
|
501 notesEditor->edit(entry); |
|
502 |
|
503 QTest::qWait(3000); |
|
504 |
|
505 ulong afterSaveId = notesEditor->close(NotesEditor::CloseWithoutSave); |
|
506 QVERIFY(!afterSaveId); |
|
507 |
|
508 delete agendaUtil; |
|
509 delete notesEditor; |
|
510 } |
|
511 // End of file --Don't remove this. |
|