tizen 2.3 release
[framework/web/wearable/wrt-security.git] / tests / smack_security / smackSecurityTest1 / js / WAC2.0 / TestCalendar.js
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * This file contains the implementation of test calendar class.
18  *
19  * @author      Lukasz Marek (l.marek@samsung.com)
20  * @version     0.1
21  */
22
23 var TYPE_MISMATCH_ERR = 17;
24 var INVALID_VALUES_ERR = 22;
25 var NOT_FOUND_ERR = 8;
26
27 var TestCalendar = {
28     calendar: null,
29     event:null,
30     old_event:null,
31     num_events:null,
32     found_events:null,
33     all_events:null,
34     expectedErrorCode: null,
35
36     createTestEvent: function (response)
37     {
38         return TestCalendar.calendar.createEvent({description:'Test Event 1',
39                 summary:'Event created to test event creation',
40                 startTime: new Date(2009, 3, 30, 10, 0),
41                 duration : 60,
42                 location:'London',
43                 recurrence:0});
44     },
45
46     onSuccessNonExpected: function(response)
47     {
48         TestEngine.test("non expected successCallback invoked", false);
49     },
50
51     onErrorExpected: function(response)
52     {
53         TestEngine.test("expected errorCallback invoked", true);
54         TestEngine.testPresence("error code", response.code);
55         TestEngine.test("Error number", response.code == TestCalendar.expectedErrorCode);
56     },
57
58     onSuccess: function(response)
59     {
60         TestEngine.test("Callback success", true);
61     },
62
63     onErrorCb: function(response)
64     {
65         TestEngine.logErr("errorCallback invoked [" + response.code + ']');
66     },
67
68     //Cal001
69     test_modulePresence: function()
70     {
71         TestEngine.test("Calendar manager presence", deviceapis.pim.calendar);
72     },
73     //Cal002
74     test_calendarManagerConstants: function()
75     {
76         TestEngine.test("test property SIM_CALENDAR", deviceapis.pim.calendar.SIM_CALENDAR === 0);
77         TestEngine.test("test property DEVICE_CALENDAR", deviceapis.pim.calendar.DEVICE_CALENDAR === 1);
78         TestEngine.test("test property NO RECURRENCE", deviceapis.pim.calendar.NO_RECURRENCE === 0);
79         TestEngine.test("test property DAILY RECURENCE", deviceapis.pim.calendar.DAILY_RECURRENCE === 1);
80         TestEngine.test("test property WEEKLY RECURRENCE", deviceapis.pim.calendar.WEEKLY_RECURRENCE === 2);
81         TestEngine.test("test property MONTHLY RECURRENCE", deviceapis.pim.calendar.MONTHLY_RECURRENCE === 3);
82         TestEngine.test("test property YEARLY_RECURRENCE", deviceapis.pim.calendar.YEARLY_RECURRENCE === 4);
83         TestEngine.test("test property TENTATIVE_STATUS", deviceapis.pim.calendar.TENTATIVE_STATUS === 0);
84         TestEngine.test("test property CONFIRMED STATUS", deviceapis.pim.calendar.CONFIRMED_STATUS === 1);
85         TestEngine.test("test property CANCELED STATUS", deviceapis.pim.calendar.CANCELLED_STATUS === 2);
86         TestEngine.test("test property ALARM", deviceapis.pim.calendar.NO_ALARM === 0);
87         TestEngine.test("test property SILENT_ALARM", deviceapis.pim.calendar.SILENT_ALARM === 1);
88         TestEngine.test("test property SOUND_ALARM", deviceapis.pim.calendar.SOUND_ALARM === 2);
89     },
90
91     //Cal003
92     test_getCalendar: function()
93     {
94         function onSuccessGetCalendar(response)
95         {
96             TestEngine.test("Found calendars", response.length > 0);
97             TestCalendar.calendar=response[0];
98         }
99         function onErrorCb(response)
100         {
101             TestEngine.test("getCalendars error callback", false);
102             TestEngine.log("error callback invoked with code " +response.code);
103         }
104
105         var cbObj = TestEngine.registerCallback("getCalendars",
106             onSuccessGetCalendar,
107             onErrorCb);
108         deviceapis.pim.calendar.getCalendars(cbObj.successCallback, cbObj.errorCallback);
109     },
110
111     //Cal004
112     test_getCalendarNoCallbacks: function()
113     {
114         testNoExceptionWithMessage("getCalendars() missing error callback",
115             function()
116             {
117                 deviceapis.pim.calendar.getCalendars(null);
118             }
119         );
120         testNoExceptionWithMessage("getCalendars() missing error callback",
121             function()
122             {
123                 deviceapis.pim.calendar.getCalendars(undefined);
124             }
125         );
126         testNoExceptionWithMessage("getCalendars() missing error callback",
127             function()
128             {
129                 deviceapis.pim.calendar.getCalendars(null, null);
130             }
131         );
132         testNoExceptionWithMessage("getCalendars() missing error callback",
133             function()
134             {
135                 deviceapis.pim.calendar.getCalendars(undefined, undefined);
136             }
137         );
138         testNoExceptionWithMessage("getCalendars() missing error callback",
139             function()
140             {
141                 deviceapis.pim.calendar.getCalendars(null, undefined);
142             }
143         );
144         testNoExceptionWithMessage("getCalendars() missing error callback",
145             function()
146             {
147                 deviceapis.pim.calendar.getCalendars(undefined, null);
148             }
149         );
150     },
151
152     //Cal005
153     test_getCalendarInvalidCallbacks: function()
154     {
155         function onError(error)
156         {
157             TestEngine.test("getCalendars()", (error.code == INVALID_VALUES_ERR));
158         }
159         function onUnexpectedCallback()
160         {
161             TestEngine.test("getCalendars() unexpected callback", false);
162         }
163
164         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, deviceapis.pim.calendar, "getCalendars");
165
166         var cbObj = TestEngine.registerCallback("getCalendars", null, onError);
167         deviceapis.pim.calendar.getCalendars(null, cbObj.errorCallback);
168
169         cbObj = TestEngine.registerCallback("getCalendars", null, onError);
170         deviceapis.pim.calendar.getCalendars(undefined, cbObj.errorCallback);
171
172         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, deviceapis.pim.calendar, "getCalendars", onUnexpectedCallback, 2);
173         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, deviceapis.pim.calendar, "getCalendars", onUnexpectedCallback, "test2");
174         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, deviceapis.pim.calendar, "getCalendars", 2, onUnexpectedCallback);
175         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, deviceapis.pim.calendar, "getCalendars", "test2", onUnexpectedCallback);
176         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, deviceapis.pim.calendar, "getCalendars", 2, null);
177         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, deviceapis.pim.calendar, "getCalendars", "test2", undefined);
178         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, deviceapis.pim.calendar, "getCalendars", 2);
179         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, deviceapis.pim.calendar, "getCalendars", "test2");
180     },
181
182     //Cal006
183     test_calendarMethodsPresence: function()
184     {
185         TestEngine.testPresence("calendar.createEvent presence", TestCalendar.calendar.createEvent);
186         TestEngine.testPresence("calendar.addEvent presence", TestCalendar.calendar.addEvent);
187         TestEngine.testPresence("calendar.updateEvent presence", TestCalendar.calendar.updateEvent);
188         TestEngine.testPresence("calendar.deleteEvent presence", TestCalendar.calendar.deleteEvent);
189         TestEngine.testPresence("calendar.findEvents presence", TestCalendar.calendar.findEvents);
190     },
191
192     //Cal007
193     test_getCalendarName: function()
194     {
195         var cName = TestCalendar.calendar.name;
196         TestEngine.test("test getName", isString(cName) && cName.length > 0);
197         TestEngine.log("calendar name: " + cName);
198     },
199
200     //Cal008
201     test_getCalendarType: function ()
202     {
203         var cType = TestCalendar.calendar.type;
204         TestEngine.test("test getType", cType === deviceapis.pim.calendar.SIM_CALENDAR ||
205                                         cType === deviceapis.pim.calendar.DEVICE_CALENDAR);
206         TestEngine.log("calendar type: " + cType);
207
208     },
209
210     //Cal009
211     test_createEmptyEvent: function()
212     {
213         var event = TestCalendar.calendar.createEvent();
214         TestEngine.test("event created", isObject(event));
215     },
216
217     //Cal010
218     test_eventAttributes: function()
219     {
220         var event = TestCalendar.calendar.createEvent();
221         TestEngine.test("test attribute id", isString(event.id) || isNull(event.id) || isUndefineD(event.id));
222         var oldId = event.id;
223         event.id = "test" + oldId;
224         TestEngine.test("attribute id is read only", event.id === oldId);
225         TestEngine.test("test attribute description", isString(event.description));
226         TestEngine.test("test attribute summary", isString(event.summary));
227         TestEngine.test("test attribute startTime", isDate(event.startTime));
228         TestEngine.test("test attribute duration", isNumber(event.duration));
229         TestEngine.test("test attribute location", isString(event.location));
230         TestEngine.test("test attribute categories", isObject(event.categories) && event.categories.length == 0);
231         TestEngine.test("test attribute recurrence", isNumber(event.recurrence) && event.recurrence === deviceapis.pim.calendar.NO_RECURRENCE);
232         TestEngine.test("test attribute expires", event.expires === null);
233         TestEngine.test("test attribute interval", isNumber(event.interval));
234         TestEngine.test("test attribute status", isNumber(event.status) && event.status === deviceapis.pim.calendar.CONFIRMED_STATUS);
235         TestEngine.test("test attribute alarmTrigger", isNumber(event.alarmTrigger) && event.alarmTrigger === 0);
236         TestEngine.test("test attribute alarmType", isNumber(event.alarmType) && event.alarmType === deviceapis.pim.calendar.NO_ALARM);
237     },
238
239     //Cal011
240     test_createEvent: function()
241     {
242         var eventProp = {
243                 description: 'Event created to test event creation',
244                 summary: 'Test Event 1',
245                 startTime: new Date(2009, 3, 30, 10, 0),
246                 duration: 60,
247                 location: 'London',
248                 categories: ["SPRC"],
249                 recurrence: deviceapis.pim.calendar.DAILY_RECURRENCE,
250                 expires: new Date(2009, 4, 30, 10, 0),
251                 interval: 2,
252                 status: deviceapis.pim.calendar.CANCELLED_STATUS,
253                 alarmTrigger: -5,
254                 alarmType: deviceapis.pim.calendar.SILENT_ALARM
255             };
256
257         var newEvent = TestCalendar.calendar.createEvent(eventProp);
258
259         TestEngine.test("event with param created ", newEvent);
260         TestEngine.test("correct description", newEvent.description === eventProp.description);
261         TestEngine.test("correct summary", newEvent.summary === eventProp.summary);
262         TestEngine.test("correct startTime", newEvent.startTime.toString() === eventProp.startTime.toString());
263         TestEngine.test("correct duration", newEvent.duration === eventProp.duration);
264         TestEngine.test("correct location", newEvent.location === eventProp.location);
265         TestEngine.test("correct categories", newEvent.categories.length === eventProp.categories.length &&
266                                               newEvent.categories[0] === eventProp.categories[0]);
267         TestEngine.test("correct recurrence", newEvent.recurrence === eventProp.recurrence);
268         TestEngine.test("correct expires", newEvent.expires.toString() === eventProp.expires.toString());
269         TestEngine.test("correct interval", newEvent.interval === eventProp.interval);
270         TestEngine.test("correct status", newEvent.status === eventProp.status);
271         TestEngine.test("correct alarmTrigger", newEvent.alarmTrigger === eventProp.alarmTrigger);
272         TestEngine.test("correct alarmType", newEvent.alarmType === eventProp.alarmType);
273
274     },
275
276     //this function is called from test_addEvent1, test_addEvent2 ...
277     addEvent: function(newEvent)
278     {
279         var event = newEvent;
280         var num_events;
281
282         function onErrorCb(response)
283         {
284             TestEngine.logErr("errorCallback invoked [" + response.code + ']');
285             TestEngine.test("add event", false);
286         }
287
288         function onSuccessAddEventCountAfter(response)
289         {
290             TestEngine.log("There is " + response.length +" events");
291             TestEngine.log("added event's id " + event.id);
292             TestEngine.test("Number of events increased", num_events + 1 == response.length);
293             var eventValidated = false;
294             for (var i in response) {
295                 if (event.id != response[i].id) {
296                     continue;
297                 }
298                 TestEngine.test("description the same", response[i].description === event.description);
299                 TestEngine.test("summary the same", response[i].summary === event.summary);
300                 TestEngine.test("startTime the same", response[i].startTime.toString() === event.startTime.toString());
301                 TestEngine.test("duration the same", response[i].duration === event.duration);
302                 TestEngine.test("location the same", response[i].location === event.location);
303                 TestEngine.test("categories the same", response[i].categories.length === event.categories.length);
304                 TestEngine.test("recurrence the same", response[i].recurrence === event.recurrence);
305                 TestEngine.test("expires the same", isNull(event.expires) ||
306                                                     response[i].expires.toString() === event.expires.toString());
307                 TestEngine.test("interval the same", response[i].interval === event.interval);
308                 TestEngine.test("status the same", response[i].status === event.status);
309                 TestEngine.test("alarmTrigger the same, " + response[i].alarmTrigger, response[i].alarmTrigger === event.alarmTrigger);
310                 TestEngine.test("alarmType the same", response[i].alarmType === event.alarmType);
311                 eventValidated = true;
312             }
313             TestEngine.test("Event has been validated", eventValidated)
314             num_events=null;
315         }
316
317         function onSuccessAddEventAdd(response)
318         {
319             TestEngine.log("event added");
320             //count the number of events
321             TestEngine.log("counting existing events");
322             var objCb = TestEngine.registerCallback("onSuccessAddEventAdd",
323                 onSuccessAddEventCountAfter, onErrorCb);
324             TestCalendar.calendar.findEvents(objCb.successCallback,
325                 objCb.errorCallback);
326         }
327
328         function onSuccessAddEventCountBefore(response)
329         {
330             TestEngine.log("events counted");
331             //save current number of events
332             num_events = response.length;
333             TestEngine.log("There is " + num_events +" events");
334             TestEngine.log("adding new event");
335             //add new event
336             var objCb = TestEngine.registerCallback("onSuccessAddEventCountBefore",
337                 onSuccessAddEventAdd, onErrorCb);
338             TestCalendar.calendar.addEvent(objCb.successCallback,
339                 objCb.errorCallback,
340                 event);
341         }
342
343         //save current number of events
344         TestEngine.log("counting existing events");
345         var objCb = TestEngine.registerCallback("findEvents",
346             onSuccessAddEventCountBefore,
347             onErrorCb);
348         TestCalendar.calendar.findEvents(objCb.successCallback, objCb.errorCallback);
349         //rest of test in callbacks...
350     },
351
352     //Cal012
353     test_addEvent1: function()
354     {
355         TestEngine.log("creating new event");
356         var event = TestCalendar.calendar.createEvent();
357         TestEngine.log("new event created");
358         TestCalendar.addEvent(event);
359     },
360
361     //Cal013
362     test_addEvent2: function()
363     {
364         TestEngine.log("creating new event");
365         var event = TestCalendar.calendar.createEvent({
366                 description:'Event created to test event creation',
367                 summary:'Test Event 2',
368                 startTime: new Date(2010, 11, 30, 10, 0),
369                 duration: 15,
370                 location:'London',
371                 categories: ["SPRC"],
372                 recurrence: deviceapis.pim.calendar.DAILY_RECURRENCE,
373                 expires: null,
374                 interval: 1,
375                 status: deviceapis.pim.calendar.TENTATIVE_STATUS,
376                 alarmTrigger: 10,
377                 alarmType: deviceapis.pim.calendar.SILENT_ALARM
378             });
379         TestEngine.log("new event created");
380         TestCalendar.addEvent(event);
381     },
382
383     //Cal014
384     test_addEvent3: function()
385     {
386         TestEngine.log("creating new event");
387         var event = TestCalendar.calendar.createEvent({
388                 description:'Event created to test event creation',
389                 summary:'Test Event 3',
390                 startTime: new Date(2010, 11, 30, 10, 0),
391                 duration: 2,
392                 location:'London',
393                 categories: ["SPRC"],
394                 recurrence: deviceapis.pim.calendar.WEEKLY_RECURRENCE,
395                 expires: new Date(2011, 11, 30, 10, 0),
396                 interval: 1,
397                 status: deviceapis.pim.calendar.CANCELLED_STATUS,
398                 alarmTrigger: 0,
399                 alarmType: deviceapis.pim.calendar.SOUND_ALARM
400             });
401         TestEngine.log("new event created");
402         TestCalendar.addEvent(event);
403     },
404
405     //Cal015
406     test_addEvent4: function()
407     {
408         var event = TestCalendar.calendar.createEvent({
409                 description:'Event created to test event creation',
410                 summary:'Test Event 4',
411                 startTime: new Date(2010, 11, 30, 10, 0),
412                 duration: 60,
413                 location:'London',
414                 categories: ["SPRC"],
415                 recurrence: deviceapis.pim.calendar.NO_RECURRENCE,
416                 expires: null,
417                 interval: 1,
418                 status: deviceapis.pim.calendar.CONFIRMED_STATUS,
419                 alarmTrigger: -15,
420                 alarmType: deviceapis.pim.calendar.NO_ALARM
421             });
422         TestCalendar.addEvent(event);
423     },
424
425     //Cal016
426     test_addEvent5: function()
427     {
428         var event = TestCalendar.calendar.createEvent({
429                 description:'Event created to test event creation',
430                 summary:'Test Event 5',
431                 startTime: new Date(2010, 11, 30, 10, 0),
432                 duration: 60,
433                 location:'London',
434                 categories: ["SPRC"],
435                 recurrence: deviceapis.pim.calendar.MONTHLY_RECURRENCE,
436                 expires: null,
437                 interval: 1,
438                 status: deviceapis.pim.calendar.CONFIRMED_STATUS,
439                 alarmTrigger: -15,
440                 alarmType: deviceapis.pim.calendar.NO_ALARM
441             });
442         TestCalendar.addEvent(event);
443     },
444
445     //Cal017
446     test_addEvent6: function()
447     {
448         var event = TestCalendar.calendar.createEvent({
449                 description:'Event created to test event creation',
450                 summary:'Test Event 6',
451                 startTime: new Date(2010, 11, 30, 10, 0),
452                 duration: 60,
453                 location:'London',
454                 categories: ["SPRC"],
455                 recurrence: deviceapis.pim.calendar.YEARLY_RECURRENCE,
456                 expires: null,
457                 interval: 1,
458                 status: deviceapis.pim.calendar.CONFIRMED_STATUS,
459                 alarmTrigger: -15,
460                 alarmType: deviceapis.pim.calendar.NO_ALARM
461             });
462         TestCalendar.addEvent(event);
463     },
464
465     //Cal019
466     test_addEventNoParams: function()
467     {
468         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "addEvent");
469     },
470
471     //Cal020
472     test_addEventInvalidCallbacksParams: function()
473     {
474         function onError(error)
475         {
476             TestEngine.test("addEvent()", (error.code == INVALID_VALUES_ERR));
477         }
478         function onUnexpectedCallback()
479         {
480             TestEngine.test("addEvent() unexpected callback", false);
481         }
482
483         var event = TestCalendar.createTestEvent();
484
485         testNoExceptionWithMessage("addEvent()", function() {
486             TestCalendar.calendar.addEvent(undefined, undefined, event);
487         });
488         testNoExceptionWithMessage("addEvent()", function() {
489             TestCalendar.calendar.addEvent(null, undefined, event);
490         });
491         testNoExceptionWithMessage("addEvent()", function() {
492             TestCalendar.calendar.addEvent(undefined, null, event);
493         });
494         testNoExceptionWithMessage("addEvent()", function() {
495             TestCalendar.calendar.addEvent(null, null, event);
496         });
497
498         var cbObj = TestEngine.registerCallback("addEvent()", null, onError);
499         deviceapis.pim.calendar.getCalendars(null, cbObj.errorCallback, event);
500
501         cbObj = TestEngine.registerCallback("addEvent()", null, onError);
502         deviceapis.pim.calendar.getCalendars(undefined, cbObj.errorCallback, event);
503
504         testNoExceptionWithMessage("addEvent()", function() {
505             TestCalendar.calendar.addEvent(undefined, undefined, null);
506         });
507         testNoExceptionWithMessage("addEvent()", function() {
508             TestCalendar.calendar.addEvent(undefined, undefined, undefined);
509         });
510
511         testNoExceptionWithMessage("addEvent()", function() {
512             TestCalendar.calendar.addEvent(null, null, null);
513         });
514         testNoExceptionWithMessage("addEvent()", function() {
515             TestCalendar.calendar.addEvent(null, null, undefined);
516         });
517
518         testNoExceptionWithMessage("addEvent()", function() {
519             TestCalendar.calendar.addEvent(null, undefined, null);
520         });
521         testNoExceptionWithMessage("addEvent()", function() {
522             TestCalendar.calendar.addEvent(null, undefined, undefined);
523         });
524
525         testNoExceptionWithMessage("addEvent()", function() {
526             TestCalendar.calendar.addEvent(undefined, null, null);
527         });
528         testNoExceptionWithMessage("addEvent()", function() {
529             TestCalendar.calendar.addEvent(undefined, null, undefined);
530         });
531
532         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "addEvent", 1, 1, null);
533         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "addEvent", "test", "test", null);
534         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "addEvent", 1, 1, undefined);
535         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "addEvent", "test", "test", undefined);
536         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "addEvent", 1, 1, event);
537         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "addEvent", "test", "test", event);
538     },
539
540     //Cal021
541     test_addEventWrongEventParam: function()
542     {
543         function onError(error)
544         {
545             TestEngine.test("addEvent()", (error.code == INVALID_VALUES_ERR));
546         }
547
548         function onSuccessNonExpected()
549         {
550             TestEngine.test("addEvent() non expected successCallback invoked", false);
551         }
552
553         function onUnexpectedCallback()
554         {
555             TestEngine.test("addEvent() unexpected callback", false);
556         }
557
558         var cbObj = TestEngine.registerCallback("addEvent()", onSuccessNonExpected, onError);
559         TestCalendar.calendar.addEvent(cbObj.successCallback, cbObj.errorCallback, null);
560
561         cbObj = TestEngine.registerCallback("addEvent()", onSuccessNonExpected, onError);
562         TestCalendar.calendar.addEvent(cbObj.successCallback, cbObj.errorCallback, undefined);
563
564         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "addEvent",
565             onUnexpectedCallback, onUnexpectedCallback, 22);
566         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "addEvent",
567             onUnexpectedCallback, onUnexpectedCallback, "test");
568         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "addEvent",
569             onUnexpectedCallback, onUnexpectedCallback);
570         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "addEvent",
571             onUnexpectedCallback, onUnexpectedCallback, new Date());
572     },
573
574     //Cal022
575     test_findAllEvents: function()
576     {
577         function onSuccessFindAllEvents(response)
578         {
579             TestEngine.test("Find all events", response.length > 0);
580         }
581
582         function onErrorCb()
583         {
584             TestEngine.test("Find all events", false);
585         }
586
587         var objCb = TestEngine.registerCallback("findEvents",
588             onSuccessFindAllEvents,
589             onErrorCb);
590         TestCalendar.calendar.findEvents(objCb.successCallback,
591             objCb.errorCallback);
592     },
593
594     //function called by following tests
595     test_FindEventsWithFilterSomeResults: function(filterEval)
596     {
597         function onSuccessFindAllEvents(response)
598         {
599             function onSuccessFindEventWithFilterSomeResults(response)
600             {
601                 TestEngine.log("found events: " + response.length);
602                 TestEngine.test("FindEvents with filter found results", response.length > 0);
603             }
604
605             function onErrorCb()
606             {
607                 TestEngine.test("FindEvents error callback", false);
608             }
609
610             TestEngine.test("Found any event for tests", response.length > 0);
611             if (response.length > 0) {
612                 eval(filterEval);
613                 if (filter) {
614                     for(var i in filter) {
615                         TestEngine.log("  Filter: " + i + " : " + filter[i]);
616                     }
617                 }
618                 var objCb = TestEngine.registerCallback("findEvents",
619                     onSuccessFindEventWithFilterSomeResults,
620                     onErrorCb);
621                 TestCalendar.calendar.findEvents(objCb.successCallback,
622                     objCb.errorCallback,
623                     filter);
624             }
625         }
626
627         function onErrorCb()
628         {
629             TestEngine.test("Find all events", false);
630         }
631
632         var objCb = TestEngine.registerCallback("findEvents",
633             onSuccessFindAllEvents,
634             onErrorCb);
635         TestCalendar.calendar.findEvents(objCb.successCallback,
636             objCb.errorCallback);
637         },
638
639     //Cal023
640     test_findEventsId: function()
641     {
642         TestCalendar.test_FindEventsWithFilterSomeResults(
643             "var filter = {id: response[0].id}");
644     },
645
646     //Cal024
647     test_findEventsSummary: function()
648     {
649         TestCalendar.test_FindEventsWithFilterSomeResults(
650             "var filter = {summary: response[0].summary}");
651     },
652
653     //Cal025
654     test_findEventsDescription: function()
655     {
656         TestCalendar.test_FindEventsWithFilterSomeResults(
657             "var filter = {description: response[0].description}");
658     },
659
660     //Cal026
661     test_findEventsLocation: function()
662     {
663         TestCalendar.test_FindEventsWithFilterSomeResults(
664             "var filter = {location: response[0].location}");
665     },
666
667     //Cal027
668     test_findEventsCategory: function()
669     {
670         TestCalendar.test_FindEventsWithFilterSomeResults(
671             "var filter = {category: 'SPRC'}");
672     },
673
674     //Cal028
675     test_findEventsStatus: function()
676     {
677         TestCalendar.test_FindEventsWithFilterSomeResults(
678             "var filter = {status: [response[0].status]}");
679     },
680
681     //Cal029
682     test_findEventsFullStartTime: function()
683     {
684         TestCalendar.test_FindEventsWithFilterSomeResults(
685             "var filter = {initialStartDate: response[0].startTime, endStartDate: response[0].startTime}");
686     },
687
688     //Cal030
689     test_findEventsInitialStartDate: function()
690     {
691         TestCalendar.test_FindEventsWithFilterSomeResults(
692             "var filter = {initialStartDate: response[0].startTime, endStartDate: null}");
693     },
694
695     //Cal031
696     test_findEventsEndStartDate: function()
697     {
698         TestCalendar.test_FindEventsWithFilterSomeResults(
699             "var filter = {initialStartDate: null, endStartDate: response[0].startTime}");
700     },
701
702     //Cal032
703     test_findEventsEmptyFilter: function()
704     {
705         TestCalendar.test_FindEventsWithFilterSomeResults("var filter = {}");
706     },
707
708     //function called by following tests
709     test_FindEventsWithFilterNoResults: function(filter)
710     {
711         function onSuccessFindEventWithFilterNoResults(response)
712         {
713             TestEngine.test("FindEvents with filter not found results", response.length == 0);
714         }
715
716         function onErrorCb()
717         {
718             TestEngine.test("FindEvents error callback", false);
719         }
720
721         if(filter) {
722             for(var i in filter) {
723                 TestEngine.log("  Filter: " + i + " : " + filter[i]);
724             }
725         }
726         var objCb = TestEngine.registerCallback("findEvents",
727             onSuccessFindEventWithFilterNoResults,
728             onErrorCb);
729         TestCalendar.calendar.findEvents(objCb.successCallback,
730             objCb.errorCallback,
731             filter);
732     },
733
734     //Cal033
735     test_findEventsFullStartTimeNoResults: function()
736     {
737         TestCalendar.test_FindEventsWithFilterNoResults(
738             {initialStartDate: new Date(1980, 11, 30, 1, 0),
739              endStartDate: new Date(1980, 11, 30, 23, 0)});
740     },
741
742     //Cal034
743     test_findEventsLocationNoResults: function()
744     {
745         TestCalendar.test_FindEventsWithFilterNoResults(
746             {location:"non existing location"});
747     },
748
749     //Cal035
750     test_findEventsSummaryNoResults: function()
751     {
752         TestCalendar.test_FindEventsWithFilterNoResults(
753             {summary:'non existing summary'});
754     },
755
756     //Cal036
757     test_findEventsDescriptionNoResults: function()
758     {
759         TestCalendar.test_FindEventsWithFilterNoResults(
760             {description:'non existing description'});
761     },
762
763     //Cal037
764     test_findEventsIdNoResults: function()
765     {
766         TestCalendar.test_FindEventsWithFilterNoResults(
767             {id:"2000000"});
768     },
769
770     //Cal038
771     test_findEventsCategoryNoResults: function()
772     {
773         TestCalendar.test_FindEventsWithFilterNoResults(
774             {category:'non existing category'});
775     },
776
777     //Cal039
778     test_findEventsNoParams: function()
779     {
780         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "findEvents");
781     },
782
783     //Cal040
784     test_findEventsNoCallbacksParams: function()
785     {
786         testNoExceptionWithMessage("findEvents() null callbacks",
787             function()
788             {
789                 TestCalendar.calendar.findEvents(null, null);
790             }
791         );
792         testNoExceptionWithMessage("findEvents() undefined callbacks",
793             function()
794             {
795                 TestCalendar.calendar.findEvents(undefined, undefined);
796             }
797         );
798         testNoExceptionWithMessage("findEvents() undefined success callback, null error callback",
799             function()
800             {
801                 TestCalendar.calendar.findEvents(undefined, null);
802             }
803         );
804         testNoExceptionWithMessage("findEvents() null success callback, undefined error callback",
805             function()
806             {
807                 TestCalendar.calendar.findEvents(null, undefined);
808             }
809         );
810         testNoExceptionWithMessage("findEvents() undefined success callback, missing error callback",
811             function()
812             {
813                 TestCalendar.calendar.findEvents(undefined);
814             }
815         );
816         testNoExceptionWithMessage("findEvents() null success callback, missing error callback",
817             function()
818             {
819                 TestCalendar.calendar.findEvents(null);
820             }
821         );
822         testNoExceptionWithMessage("findEvents() null callbacks, empty filter",
823             function()
824             {
825                 TestCalendar.calendar.findEvents(null, null, {});
826             }
827         );
828         testNoExceptionWithMessage("findEvents() undefined callbacks, empty filter",
829             function()
830             {
831                 TestCalendar.calendar.findEvents(undefined, undefined, {});
832             }
833         );
834     },
835
836     //Cal041
837     test_findEventsWrongFilterParam: function()
838     {
839         function onSuccess(response)
840         {
841             TestEngine.test("findEvents() success callback invoked", true);
842         }
843
844         function onError(response)
845         {
846             TestEngine.test("findEvents() error callback invoked", false);
847         }
848
849         var objCb = TestEngine.registerCallback("Find events with undefined filter param",
850             onSuccess,
851             onError);
852         TestCalendar.calendar.findEvents(objCb.successCallback,
853             objCb.errorCallback, null);
854
855         objCb = TestEngine.registerCallback("Find events with undefined filter param",
856             onSuccess,
857             onError);
858         TestCalendar.calendar.findEvents(objCb.successCallback,
859             objCb.errorCallback, undefined);
860     },
861
862     //this function is called by following tests
863     updateEvent: function(newValues)
864     {
865         function onErrorCb()
866         {
867             TestEngine.test("Find all events", false);
868         }
869
870         function onSuccessFindAllEvents(response)
871         {
872             TestEngine.test("Find all events", response.length > 0);
873             if (response.length > 0) {
874                 var event = response[0];
875                 function onSuccessUpdateEvent1(response)
876                 {
877                     TestEngine.log("updateEvent() success callback entered entered");
878
879                     function onSuccessUpdateEvent2(response)
880                     {
881                         TestEngine.test("found updated event", response.length > 0);
882                         if (response.length > 0) {
883                             var f_flag = 0;
884                             for (var i in response) {
885                                 f_flag = 1;
886                                 for (var j in newValues) {
887                                     if (isDate(newValues[j])) {
888                                         if (response[i][j].toString() != newValues[j].toString()) {
889                                             f_flag = 0;
890                                             break;
891                                         }
892                                     }
893                                     else if (isArray(newValues[j]))
894                                     {
895                                         if (response[i][j].length != newValues[j].length ||
896                                             response[i][j][0] != newValues[j][0]) {
897                                             f_flag = 0;
898                                             break;
899                                         }
900                                     }
901                                     else {
902                                         if (response[i][j] !== newValues[j]) {
903                                             if (j == "expires" && newValues[j] == null) {
904                                                 //expires date with null should not be checked
905                                                 TestEngine.log("dupa " + j);
906                                                 continue;
907                                             }
908                                             f_flag = 0;
909                                             break;
910                                         }
911                                     }
912                                 }
913                                 if (f_flag == 1) {
914                                     break;
915                                 }
916                             }
917                             TestEngine.test("Updated event validated successfully", f_flag == 1);
918                         }
919                         else {
920                             TestEngine.test("Updated events found", false);
921                         }
922                     }
923
924                     //find updated event
925                     var objCb = TestEngine.registerCallback("findEvents",
926                         onSuccessUpdateEvent2,
927                         onErrorCb);
928                     TestCalendar.calendar.findEvents(objCb.successCallback,
929                         objCb.errorCallback, {id: event.id});
930                 }
931                 for (var i in newValues) {
932                     TestEngine.log("update property: " + i + ", new value: " + newValues[i]);
933                     event[i] = newValues[i];
934                 }
935                 var objCb = TestEngine.registerCallback("updateEvent",
936                     onSuccessUpdateEvent1,
937                     onErrorCb);
938                 TestCalendar.calendar.updateEvent(objCb.successCallback,
939                     objCb.errorCallback,
940                     event);
941             }
942         }
943
944         var objCb = TestEngine.registerCallback("findEvents",
945             onSuccessFindAllEvents,
946             onErrorCb);
947         TestCalendar.calendar.findEvents(objCb.successCallback,
948             objCb.errorCallback);
949     },
950
951     //Cal042
952     test_updateEvent1: function()
953     {
954         var newValues = {
955                 description:'updated description 1',
956                 summary:'Updated Test Event 1',
957                 startTime: new Date(2011, 01, 01, 01, 01),
958                 duration: 11,
959                 location:'London 1',
960                 categories: ["SPRC 1"],
961                 recurrence: deviceapis.pim.calendar.NO_RECURRENCE,
962                 expires: null,
963                 interval: 1,
964                 status: deviceapis.pim.calendar.TENTATIVE_STATUS,
965                 alarmTrigger: 1,
966                 alarmType: deviceapis.pim.calendar.NO_ALARM
967             };
968         TestCalendar.updateEvent(newValues)
969     },
970
971     //Cal043
972     test_updateEvent2: function()
973     {
974         var newValues = {
975                 description:'updated description 2',
976                 summary:'Updated Test Event 2',
977                 startTime: new Date(2012, 02, 02, 02, 02),
978                 duration: 22,
979                 location:'London 2',
980                 categories: ["SPRC 2"],
981                 recurrence: deviceapis.pim.calendar.DAILY_RECURRENCE,
982                 expires: null,
983                 interval: 2,
984                 status: deviceapis.pim.calendar.CONFIRMED_STATUS,
985                 alarmTrigger: 2,
986                 alarmType: deviceapis.pim.calendar.SILENT_ALARM
987             };
988         TestCalendar.updateEvent(newValues)
989     },
990
991     //Cal044
992     test_updateEvent3: function()
993     {
994         var newValues = {
995                 description:'updated description 3',
996                 summary:'Updated Test Event 3',
997                 startTime: new Date(2013, 03, 03, 03, 03),
998                 duration: 33,
999                 location:'London 3',
1000                 categories: [],
1001                 recurrence: deviceapis.pim.calendar.WEEKLY_RECURRENCE,
1002                 expires: null,
1003                 interval: 3,
1004                 status: deviceapis.pim.calendar.CANCELLED_STATUS,
1005                 alarmTrigger: 3,
1006                 alarmType: deviceapis.pim.calendar.SOUND_ALARM
1007             };
1008         TestCalendar.updateEvent(newValues)
1009     },
1010
1011     //Cal045
1012     test_updateEvent4: function()
1013     {
1014         var newValues = {
1015                 description:'updated description 4',
1016                 summary:'Updated Test Event 4',
1017                 startTime: new Date(2014, 04, 04, 04, 04),
1018                 duration: 44,
1019                 location:'London 4',
1020                 categories: ["SPRC 4"],
1021                 recurrence: deviceapis.pim.calendar.MONTHLY_RECURRENCE,
1022                 expires: new Date(2015, 03, 03, 03, 03),
1023                 interval: 4,
1024                 status: deviceapis.pim.calendar.CANCELLED_STATUS,
1025                 alarmTrigger: 4,
1026                 alarmType: deviceapis.pim.calendar.SOUND_ALARM
1027             };
1028         TestCalendar.updateEvent(newValues)
1029     },
1030
1031     //Cal046
1032     test_updateEvent5: function()
1033     {
1034         var newValues = {
1035                 description:'updated description 5',
1036                 summary:'Updated Test Event 5',
1037                 startTime: new Date(2015, 05, 05, 05, 05),
1038                 duration: 55,
1039                 location:'London 5',
1040                 categories: ["SPRC 5"],
1041                 recurrence: deviceapis.pim.calendar.YEARLY_RECURRENCE,
1042                 expires: new Date(2016, 03, 03, 03, 03),
1043                 interval: 5,
1044                 status: deviceapis.pim.calendar.CANCELLED_STATUS,
1045                 alarmTrigger: -5,
1046                 alarmType: deviceapis.pim.calendar.SOUND_ALARM
1047             };
1048         TestCalendar.updateEvent(newValues)
1049     },
1050
1051     //Cal047
1052     test_updateEventNoParams: function()
1053     {
1054         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "updateEvent");
1055     },
1056
1057     //Cal048
1058     test_updateEventNullCallbacksParams: function()
1059     {
1060         var event = TestCalendar.createTestEvent();
1061         testNoExceptionWithMessage("updateEvent() null callbacks",
1062             function()
1063             {
1064                 TestCalendar.calendar.updateEvent(null, null, event);
1065             }
1066         );
1067         testNoExceptionWithMessage("updateEvent() undefined callbacks",
1068             function()
1069             {
1070                 TestCalendar.calendar.updateEvent(undefined, undefined, event);
1071             }
1072         );
1073         testNoExceptionWithMessage("updateEvent() undefined success callback, null error callback",
1074             function()
1075             {
1076                 TestCalendar.calendar.updateEvent(undefined, null, event);
1077             }
1078         );
1079         testNoExceptionWithMessage("updateEvent() null success callback, undefined error callback",
1080             function()
1081             {
1082                 TestCalendar.calendar.updateEvent(null, undefined, event);
1083             }
1084         );
1085         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "updateEvent", 1, undefined, event);
1086         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "updateEvent", "test", undefined, event);
1087         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "updateEvent", undefined, 1, event);
1088         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "updateEvent", undefined, "test", event);
1089     },
1090
1091     //Cal049
1092     test_updateEventWrongEventParam: function()
1093     {
1094         function onUnexpectedCallback()
1095         {
1096             TestEngine.test("updateEvent() unexpected callback", false);
1097         }
1098         function onSuccess()
1099         {
1100             TestEngine.test("updateEvent() unexpected success callback invoked", false);
1101         }
1102
1103         function onError(response)
1104         {
1105             TestEngine.test("updateEvent() error callback invoked", response.code == INVALID_VALUES_ERR);
1106         }
1107
1108         var objCb = TestEngine.registerCallback("Update event with undefined filter param",
1109             onSuccess,
1110             onError);
1111         TestCalendar.calendar.updateEvent(objCb.successCallback,
1112             objCb.errorCallback, null);
1113
1114         objCb = TestEngine.registerCallback("Update event with undefined filter param",
1115             onSuccess,
1116             onError);
1117         TestCalendar.calendar.updateEvent(objCb.successCallback,
1118             objCb.errorCallback, undefined);
1119
1120         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "updateEvent",
1121             onUnexpectedCallback, onUnexpectedCallback, 22);
1122         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "updateEvent",
1123             onUnexpectedCallback, onUnexpectedCallback, "test");
1124         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "updateEvent",
1125             onUnexpectedCallback, onUnexpectedCallback);
1126         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "updateEvent",
1127             onUnexpectedCallback, onUnexpectedCallback, new Date());
1128     },
1129
1130     //Cal050
1131     test_deleteEvent: function()
1132     {
1133         var foundEventsFlag = 0;
1134
1135         function onError()
1136         {
1137             TestEngine.test("deleteEvent() error callback invoked", false);
1138         }
1139
1140         function onSuccessDeleteEvent()
1141         {
1142             TestEngine.test("deleteEvent() success callback invoked", true);
1143             findEvents();
1144         }
1145
1146         function onSuccessFindEvents(response)
1147         {
1148             TestEngine.log("deleteEvent() callback entered");
1149             if (foundEventsFlag == 0) {
1150                 //this validation is only for the first call
1151                 TestEngine.test("Events for delete found", response.length > 0);
1152             }
1153             foundEventsFlag = 1;
1154             if (response.length > 0) {
1155                 var objCb = TestEngine.registerCallback("deleteEvents",
1156                     onSuccessDeleteEvent,
1157                     onError);
1158                 TestCalendar.calendar.deleteEvent(objCb.successCallback,
1159                     objCb.errorCallback, response[0].id);
1160             }
1161             else {
1162                 TestEngine.test("All events deleted", true);
1163             }
1164         }
1165
1166         function findEvents()
1167         {
1168             //find all events
1169             var objCb = TestEngine.registerCallback("deleteEvent",
1170                 onSuccessFindEvents,
1171                 onError);
1172             TestCalendar.calendar.findEvents(objCb.successCallback,
1173                 objCb.errorCallback);
1174         }
1175         //recursively delete all events
1176         findEvents();
1177     },
1178
1179     //Cal051
1180     test_deleteEventNoParams: function()
1181     {
1182         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "deleteEvent");
1183     },
1184
1185     //Cal052
1186     test_deleteEventNullCallbacksParams: function()
1187     {
1188         testNoExceptionWithMessage("deleteEvent() null callbacks",
1189             function()
1190             {
1191                 TestCalendar.calendar.deleteEvent(null, null, "1");
1192             }
1193         );
1194         testNoExceptionWithMessage("deleteEvent() undefined callbacks",
1195             function()
1196             {
1197                 TestCalendar.calendar.deleteEvent(undefined, undefined, event);
1198             }
1199         );
1200         testNoExceptionWithMessage("deleteEvent() undefined success callback, null error callback",
1201             function()
1202             {
1203                 TestCalendar.calendar.deleteEvent(undefined, null, event);
1204             }
1205         );
1206         testNoExceptionWithMessage("deleteEvent() null success callback, undefined error callback",
1207             function()
1208             {
1209                 TestCalendar.calendar.deleteEvent(null, undefined, event);
1210             }
1211         );
1212         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "deleteEvent", 1, undefined, "1");
1213         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "deleteEvent", "test", undefined, "1");
1214         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "deleteEvent", undefined, 1, "1");
1215         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "deleteEvent", undefined, "test", "1");
1216     },
1217
1218     //Cal053
1219     test_deleteEventWrongEventParam: function()
1220     {
1221         function onUnexpectedCallback()
1222         {
1223             TestEngine.test("deleteEvent() unexpected callback", false);
1224         }
1225         function onSuccess()
1226         {
1227             TestEngine.test("deleteEvent() unexpected success callback invoked", false);
1228         }
1229
1230         function onError(response)
1231         {
1232             TestEngine.test("deleteEvent() error callback invoked", response.code == NOT_FOUND_ERR);
1233         }
1234
1235         var objCb = TestEngine.registerCallback("Delete event with null filter param",
1236             onSuccess,
1237             onError);
1238         TestCalendar.calendar.deleteEvent(objCb.successCallback,
1239             objCb.errorCallback, null);
1240
1241         objCb = TestEngine.registerCallback("Delete event with undefined filter param",
1242             onSuccess,
1243             onError);
1244         TestCalendar.calendar.deleteEvent(objCb.successCallback,
1245             objCb.errorCallback, undefined);
1246
1247         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "deleteEvent",
1248                 onUnexpectedCallback, onUnexpectedCallback, 22);
1249         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "deleteEvent",
1250                 onUnexpectedCallback, onUnexpectedCallback);
1251         TestEngine.catchErrorType("code", TYPE_MISMATCH_ERR, TestCalendar.calendar, "deleteEvent",
1252                 onUnexpectedCallback, onUnexpectedCallback, new Date());
1253     },
1254
1255     test_concatCategoryArray: function()
1256     {
1257         var category1 = "SPRC category";
1258         var category2 = "test";
1259         var category3 = "test2";
1260         var category4 = "test aaa";
1261         var event = TestCalendar.createTestEvent();
1262         TestEngine.test("category array is empty", event.categories.length === 0);
1263         event.categories[0] = category1;
1264         TestEngine.test("category array has one element", event.categories.length === 1);
1265         TestEngine.test("category array has proper value", event.categories[0] === category1);
1266         var concatArray = event.categories.concat([category2, category3]);
1267         TestEngine.test("concatenated category array has three elements", concatArray.length === 3);
1268         TestEngine.test("concatenated category array has proper value [0]", concatArray[0] === category1);
1269         TestEngine.test("concatenated category array has proper value [1]", concatArray[1] === category2);
1270         TestEngine.test("concatenated category array has proper value [2]", concatArray[2] === category3);
1271         concatArray = event.categories.concat([category2, category3], [category4]);
1272         TestEngine.test("concatenated category array has four elements", concatArray.length === 4);
1273         TestEngine.test("concatenated category array has proper value [0]", concatArray[0] === category1);
1274         TestEngine.test("concatenated category array has proper value [1]", concatArray[1] === category2);
1275         TestEngine.test("concatenated category array has proper value [2]", concatArray[2] === category3);
1276         TestEngine.test("concatenated category array has proper value [3]", concatArray[3] === category4);
1277         TestEngine.test("category array still has one element", event.categories.length === 1);
1278     },
1279
1280     test_joinCategoryArray: function()
1281     {
1282         var category1 = "category0";
1283         var category2 = "category1";
1284         var category3 = "category2";
1285         var event = TestCalendar.createTestEvent();
1286         TestEngine.test("category array is empty", event.categories.length === 0);
1287         event.categories[0] = category1;
1288         event.categories[1] = category2;
1289         event.categories[2] = category3;
1290         TestEngine.test("category array has three elements", event.categories.length === 3);
1291         TestEngine.test("joining with default separator", event.categories.join()  === category1 + "," + category2 + "," + category3);
1292         TestEngine.test("joining with space separator", event.categories.join(" ") === category1 + " " + category2 + " " + category3);
1293         TestEngine.test("joining with longer string separator", event.categories.join(" how about ") === category1 + " how about " + category2 + " how about " + category3);
1294         TestEngine.test("category array still has three elements", event.categories.length === 3);
1295     },
1296
1297     test_popCategoryArray: function()
1298     {
1299         var category1 = "category0";
1300         var category2 = "category1";
1301         var category3 = "category2";
1302         var event = TestCalendar.createTestEvent();
1303         TestEngine.test("category array is empty", event.categories.length === 0);
1304         event.categories[0] = category1;
1305         event.categories[1] = category2;
1306         event.categories[2] = category3;
1307         TestEngine.test("category array has three elements", event.categories.length === 3);
1308         TestEngine.test("poped element has correct value", event.categories.pop() === category3);
1309         TestEngine.test("category array has three elements", event.categories.length === 2);
1310         TestEngine.test("poped element has correct value", event.categories.pop() === category2);
1311         TestEngine.test("category array has three elements", event.categories.length === 1);
1312         TestEngine.test("poped element has correct value", event.categories.pop() === category1);
1313         TestEngine.test("category array has three elements", event.categories.length === 0);
1314         TestEngine.test("poped element has correct value", event.categories.pop() === undefined);
1315         TestEngine.test("poped element has correct value", event.categories.pop() === undefined);
1316     },
1317
1318     test_pushCategoryArray: function()
1319     {
1320         var category1 = "category0";
1321         var category2 = "category1";
1322         var category3 = "category2";
1323         var event = TestCalendar.createTestEvent();
1324         TestEngine.test("category array is empty", event.categories.length === 0);
1325         event.categories.push(category1);
1326         event.categories.push(category2);
1327         event.categories.push(category3);
1328         TestEngine.test("category array has three elements", event.categories.length === 3);
1329         TestEngine.test("array element [0] has correct value", event.categories[0] === category1);
1330         TestEngine.test("array element [1] has correct value", event.categories[1] === category2);
1331         TestEngine.test("array element [2] has correct value", event.categories[2] === category3);
1332     },
1333
1334     test_reverseCategoryArray: function()
1335     {
1336         var category1 = "category0";
1337         var category2 = "category1";
1338         var category3 = "category2";
1339         var category4 = "category3";
1340         var event = TestCalendar.createTestEvent();
1341         TestEngine.test("category array is empty", event.categories.length === 0);
1342         event.categories.push(category1);
1343         event.categories.push(category2);
1344         event.categories.push(category3);
1345         event.categories.push(category4);
1346         event.categories.reverse();
1347         TestEngine.test("category array has four elements", event.categories.length === 4);
1348         TestEngine.test("array element [0] has correct value", event.categories[0] === category4);
1349         TestEngine.test("array element [1] has correct value", event.categories[1] === category3);
1350         TestEngine.test("array element [2] has correct value", event.categories[2] === category2);
1351         TestEngine.test("array element [3] has correct value", event.categories[3] === category1);
1352     },
1353
1354     test_shiftCategoryArray: function()
1355     {
1356         var category1 = "category0";
1357         var category2 = "category1";
1358         var category3 = "category2";
1359         var event = TestCalendar.createTestEvent();
1360         TestEngine.test("category array is empty", event.categories.length === 0);
1361         event.categories[0] = category1;
1362         event.categories[1] = category2;
1363         event.categories[2] = category3;
1364         TestEngine.test("category array has three elements", event.categories.length === 3);
1365         TestEngine.test("shifted element has correct value", event.categories.shift() === category1);
1366         TestEngine.test("category array has three elements", event.categories.length === 2);
1367         TestEngine.test("shifted element has correct value", event.categories.shift() === category2);
1368         TestEngine.test("category array has three elements", event.categories.length === 1);
1369         TestEngine.test("shifted element has correct value", event.categories.shift() === category3);
1370         TestEngine.test("category array has three elements", event.categories.length === 0);
1371         TestEngine.test("shifted element has correct value", event.categories.shift() === undefined);
1372         TestEngine.test("shifted element has correct value", event.categories.shift() === undefined);
1373     },
1374
1375     test_sliceCategoryArray: function()
1376     {
1377         var category1 = "category0";
1378         var category2 = "category1";
1379         var category3 = "category2";
1380         var event = TestCalendar.createTestEvent();
1381         TestEngine.test("category array is empty", event.categories.length === 0);
1382         event.categories[0] = category1;
1383         event.categories[1] = category2;
1384         event.categories[2] = category3;
1385         TestEngine.test("category array has three elements", event.categories.length === 3);
1386         var slice = event.categories.slice(0, 2);
1387         TestEngine.test("slice array has correct number of elements", slice.length === 3);
1388         slice = event.categories.slice(0, 1);
1389         TestEngine.test("slice array has correct number of elements", slice.length === 2);
1390         slice = event.categories.slice(0, 0);
1391         TestEngine.test("slice array has correct number of elements", slice.length === 1);
1392         slice = event.categories.slice(0);
1393         TestEngine.test("slice array has correct number of elements", slice.length === 3);
1394         slice = event.categories.slice(1);
1395         TestEngine.test("slice array has correct number of elements", slice.length === 2);
1396         slice = event.categories.slice(2);
1397         TestEngine.test("slice array has correct number of elements", slice.length === 1);
1398         slice = event.categories.slice(3);
1399         TestEngine.test("slice array has correct number of elements", slice.length === 0);
1400     },
1401
1402     test_sortCategoryArray: function()
1403     {
1404         var category1 = "category0";
1405         var category2 = "category1";
1406         var category3 = "category2";
1407         var event = TestCalendar.createTestEvent();
1408         TestEngine.test("category array is empty", event.categories.length === 0);
1409         event.categories[0] = category3;
1410         event.categories[1] = category2;
1411         event.categories[2] = category1;
1412         TestEngine.test("category array has three elements", event.categories.length === 3);
1413         event.categories.sort();
1414         TestEngine.test("category array has three elements", event.categories.length === 3);
1415         TestEngine.test("array element [0] has correct value", event.categories[0] === category1);
1416         TestEngine.test("array element [1] has correct value", event.categories[1] === category2);
1417         TestEngine.test("array element [2] has correct value", event.categories[2] === category3);
1418     },
1419
1420     test_toStringCategoryArray: function()
1421     {
1422         var category1 = "category0";
1423         var category2 = "category1";
1424         var category3 = "category2";
1425         var event = TestCalendar.createTestEvent();
1426         TestEngine.test("category array is empty", event.categories.length === 0);
1427         event.categories[0] = category1;
1428         event.categories[1] = category2;
1429         event.categories[2] = category3;
1430         TestEngine.test("category array has three elements", event.categories.length === 3);
1431         TestEngine.test("toString return correct value", event.categories.join() === category1 + "," + category2 + "," + category3);
1432     }
1433 };
1434 //=============================================================================
1435 TestEngine.setTestSuiteName("[WAC2.0][Calendar]");
1436 ////Cal001
1437 //TestEngine.addTest(true,TestCalendar.test_modulePresence, "[WAC2.0][Calendar] Test calendar module presence");
1438 ////Cal002
1439 //TestEngine.addTest(true,TestCalendar.test_calendarManagerConstants, "[WAC2.0][Calendar] Calendar manager constants");
1440 ////Cal003
1441 TestEngine.addTest(true,TestCalendar.test_getCalendar, "[WAC2.0][Calendar] Get calendar");
1442 ////Cal004
1443 //TestEngine.addTest(true,TestCalendar.test_getCalendarNoCallbacks, "[WAC2.0][Calendar] Get calendar with no callbacks");
1444 ////Cal005
1445 //TestEngine.addTest(true,TestCalendar.test_getCalendarInvalidCallbacks, "[WAC2.0][Calendar] Get calendar with invalid callbacks");
1446 ////Cal006
1447 //TestEngine.addTest(true,TestCalendar.test_calendarMethodsPresence, "[WAC2.0][Calendar] Calendar methods presence");
1448 ////Cal007
1449 //TestEngine.addTest(true,TestCalendar.test_getCalendarName, "[WAC2.0][Calendar] Get calendar name");
1450 ////Cal008
1451 //TestEngine.addTest(true,TestCalendar.test_getCalendarType, "[WAC2.0][Calendar] Get calendar type");
1452 ////Cal009
1453 //TestEngine.addTest(true,TestCalendar.test_createEmptyEvent, "[WAC2.0][Calendar] Create empty event");
1454 ////Cal010
1455 //TestEngine.addTest(true,TestCalendar.test_eventAttributes, "[WAC2.0][Calendar] event attributes");
1456 ////Cal011
1457 //TestEngine.addTest(true,TestCalendar.test_createEvent, "[WAC2.0][Calendar] Create event");
1458 //
1459 ////Cal012
1460 //TestEngine.addTest(true,TestCalendar.test_addEvent1, "[WAC2.0][Calendar] Add event 1");
1461 ////Cal013
1462 //TestEngine.addTest(true,TestCalendar.test_addEvent2, "[WAC2.0][Calendar] Add event 2");
1463 ////Cal014
1464 //TestEngine.addTest(true,TestCalendar.test_addEvent3, "[WAC2.0][Calendar] Add event 3");
1465 ////Cal015
1466 //TestEngine.addTest(true,TestCalendar.test_addEvent4, "[WAC2.0][Calendar] Add event 4");
1467 ////Cal016
1468 //TestEngine.addTest(true,TestCalendar.test_addEvent5, "[WAC2.0][Calendar] Add event 5");
1469 ////Cal017
1470 //TestEngine.addTest(true,TestCalendar.test_addEvent6, "[WAC2.0][Calendar] Add event 6");
1471 ////Cal019
1472 //TestEngine.addTest(true,TestCalendar.test_addEventNoParams, "[WAC2.0][Calendar] Add event with no params");
1473 ////Cal020
1474 //TestEngine.addTest(true,TestCalendar.test_addEventInvalidCallbacksParams, "[WAC2.0][Calendar] Add event with wrong callbacks");
1475 ////Cal021
1476 //TestEngine.addTest(true,TestCalendar.test_addEventWrongEventParam, "[WAC2.0][Calendar] Add event with wrong event param");
1477 //
1478 ////Cal022
1479 //TestEngine.addTest(true,TestCalendar.test_findAllEvents, "[WAC2.0][Calendar] Find all events");
1480 ////Cal023
1481 //TestEngine.addTest(true,TestCalendar.test_findEventsId, "[WAC2.0][Calendar] Find events, filter: id");
1482 ////Cal024
1483 //TestEngine.addTest(true,TestCalendar.test_findEventsSummary, "[WAC2.0][Calendar] Find events, filter: summary");
1484 ////Cal025
1485 //TestEngine.addTest(true,TestCalendar.test_findEventsDescription, "[WAC2.0][Calendar] Find events, filter: description");
1486 ////Cal026
1487 //TestEngine.addTest(true,TestCalendar.test_findEventsLocation, "[WAC2.0][Calendar] Find events, filter: location");
1488 ////Cal027
1489 //TestEngine.addTest(true,TestCalendar.test_findEventsCategory, "[WAC2.0][Calendar] Find events, filter: category");
1490 ////Cal028
1491 //TestEngine.addTest(true,TestCalendar.test_findEventsStatus, "[WAC2.0][Calendar] Find events, filter: status");
1492 ////Cal029
1493 //TestEngine.addTest(true,TestCalendar.test_findEventsFullStartTime, "[WAC2.0][Calendar] Find events, filter: initialStartDate and endStartDate");
1494 ////Cal030
1495 //TestEngine.addTest(true,TestCalendar.test_findEventsInitialStartDate, "[WAC2.0][Calendar] Find events, filter: initialStartDate");
1496 ////Cal031
1497 //TestEngine.addTest(true,TestCalendar.test_findEventsEndStartDate, "[WAC2.0][Calendar] Find events, filter: endStartDate");
1498 ////Cal032
1499 //TestEngine.addTest(true,TestCalendar.test_findEventsEmptyFilter, "[WAC2.0][Calendar] Find events, filter: empty filter");
1500 ////Cal033
1501 //TestEngine.addTest(true,TestCalendar.test_findEventsFullStartTimeNoResults, "[WAC2.0][Calendar] Find events, no results, filter: initialStartDate and endStartDate");
1502 ////Cal034
1503 //TestEngine.addTest(true,TestCalendar.test_findEventsLocationNoResults, "[WAC2.0][Calendar] Find events, no results, filter: location");
1504 ////Cal035
1505 //TestEngine.addTest(true,TestCalendar.test_findEventsSummaryNoResults, "[WAC2.0][Calendar] Find events, no results, filter: summary");
1506 ////Cal036
1507 //TestEngine.addTest(true,TestCalendar.test_findEventsDescriptionNoResults, "[WAC2.0][Calendar] Find events, no results, filter: description");
1508 ////Cal037
1509 //TestEngine.addTest(true,TestCalendar.test_findEventsIdNoResults, "[WAC2.0][Calendar] Find events, no results, filter: id");
1510 ////Cal038
1511 //TestEngine.addTest(true,TestCalendar.test_findEventsCategoryNoResults, "[WAC2.0][Calendar] Find events, no results, filter: category");
1512 ////Cal039
1513 //TestEngine.addTest(true,TestCalendar.test_findEventsNoParams, "[WAC2.0][Calendar] Find events with no params");
1514 ////Cal040
1515 //TestEngine.addTest(true,TestCalendar.test_findEventsNoCallbacksParams, "[WAC2.0][Calendar] Find events with no callbacks");
1516 ////Cal041
1517 //TestEngine.addTest(true,TestCalendar.test_findEventsWrongFilterParam, "[WAC2.0][Calendar] Find events with wrong filter param");
1518 //
1519 ////Cal042
1520 //TestEngine.addTest(true,TestCalendar.test_updateEvent1, "[WAC2.0][Calendar] Update event 1");
1521 ////Cal043
1522 //TestEngine.addTest(true,TestCalendar.test_updateEvent2, "[WAC2.0][Calendar] Update event 2");
1523 ////Cal044
1524 //TestEngine.addTest(true,TestCalendar.test_updateEvent3, "[WAC2.0][Calendar] Update event 3");
1525 ////Cal045
1526 //TestEngine.addTest(true,TestCalendar.test_updateEvent4, "[WAC2.0][Calendar] Update event 4");
1527 ////Cal046
1528 //TestEngine.addTest(true,TestCalendar.test_updateEvent5, "[WAC2.0][Calendar] Update event 5");
1529 ////Cal047
1530 //TestEngine.addTest(true,TestCalendar.test_updateEventNoParams, "[WAC2.0][Calendar] Update event with no params");
1531 ////Cal048
1532 //TestEngine.addTest(true,TestCalendar.test_updateEventNullCallbacksParams, "[WAC2.0][Calendar] Update event with wrong callbacks");
1533 ////Cal049
1534 //TestEngine.addTest(true,TestCalendar.test_updateEventWrongEventParam, "[WAC2.0][Calendar] Update event with wrong event param");
1535 //
1536 ////Cal050
1537 //TestEngine.addTest(true,TestCalendar.test_deleteEvent, "[WAC2.0][Calendar] Delete event");
1538 ////Cal051
1539 //TestEngine.addTest(true,TestCalendar.test_deleteEventNoParams, "[WAC2.0][Calendar] Delete event with no params");
1540 ////Cal052
1541 //TestEngine.addTest(true,TestCalendar.test_deleteEventNullCallbacksParams, "[WAC2.0][Calendar] Delete event with wrong callbacks");
1542 ////Cal053
1543 //TestEngine.addTest(true,TestCalendar.test_deleteEventWrongEventParam, "[WAC2.0][Calendar] Delete event with wrong event param");
1544 //
1545 ////Cal050
1546 //TestEngine.addTest(true,TestCalendar.test_concatCategoryArray, "[WAC2.0][Calendar] Concat category array");
1547 ////Cal051
1548 //TestEngine.addTest(true,TestCalendar.test_joinCategoryArray, "[WAC2.0][Calendar] Join category array");
1549 ////Cal052
1550 //TestEngine.addTest(true,TestCalendar.test_popCategoryArray, "[WAC2.0][Calendar] Pop category array");
1551 ////Cal053
1552 //TestEngine.addTest(true,TestCalendar.test_pushCategoryArray, "[WAC2.0][Calendar] Push category array");
1553 ////Cal054
1554 //TestEngine.addTest(true,TestCalendar.test_reverseCategoryArray, "[WAC2.0][Calendar] Reverse category array");
1555 ////Cal055
1556 //TestEngine.addTest(true,TestCalendar.test_shiftCategoryArray, "[WAC2.0][Calendar] Shift category array");
1557 ////Cal056
1558 //TestEngine.addTest(true,TestCalendar.test_sliceCategoryArray, "[WAC2.0][Calendar] Slice category array");
1559 ////Cal057
1560 //TestEngine.addTest(true,TestCalendar.test_sortCategoryArray, "[WAC2.0][Calendar] Sort category array");
1561 ////Cal058
1562 //TestEngine.addTest(true,TestCalendar.test_toStringCategoryArray, "[WAC2.0][Calendar] toString category array");
1563
1564 //=============================================================================
1565
1566 function testNoExceptionWithMessage(message, fun) {
1567     var testResult = true;
1568     try
1569     {
1570         fun();
1571     }
1572     catch (e)
1573     {
1574         testResult = false;
1575     }
1576     TestEngine.test(message, testResult);
1577 }