Moving test subdirectory from mozilla/calendar/base/test to mozilla/calendar/test; rearranging structure for use with jsDriver.pl. Not part of the build.
git-svn-id: svn://10.0.0.236/trunk@167008 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
7535247bdc
commit
beac48c42a
82
mozilla/calendar/test/Makefile.in
Normal file
82
mozilla/calendar/test/Makefile.in
Normal file
@ -0,0 +1,82 @@
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is the Oracle Corporation code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Oracle Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 2004
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Dan Mosedale <dan.mosedale@oracle.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
RUN = $(DIST)/bin/run-mozilla.sh
|
||||
XPCSHELL = $(DIST)/bin/xpcshell
|
||||
|
||||
# once we land the necessary changes in the canonical copy of jsDriver.pl,
|
||||
# we should add that file to the calendar CVS module, and then switch to the
|
||||
# commented-out version here
|
||||
#
|
||||
#JSDRIVER = $(topsrcdir)/js/tests/jsDriver.pl
|
||||
#
|
||||
JSDRIVER = $(srcdir)/jsDriver.pl
|
||||
|
||||
PROVIDER_TESTS = getEvents.js
|
||||
PROVIDERS = memory caldav
|
||||
REDIRECTERR = 2>/dev/null
|
||||
GARBAGE += results*.html
|
||||
|
||||
# for running xpcshell with the calshell objects loaded in
|
||||
#
|
||||
.PHONY: calshell
|
||||
calshell:
|
||||
$(RUN) $(XPCSHELL) -f $(srcdir)/homegrown/shell.js -f -
|
||||
|
||||
.PHONY: test-providers
|
||||
test-providers:
|
||||
|
||||
.PHONY: test-misc
|
||||
test-misc:
|
||||
|
||||
# run all the tests
|
||||
#
|
||||
.PHONY: test
|
||||
test: test-providers test-misc
|
||||
env MOZILLA_FIVE_HOME=$(DIST)/bin LD_LIBRARY_PATH=$(DIST)/bin \
|
||||
$(JSDRIVER) --confail --engine=xpcshell --testpath=$(srcdir) \
|
||||
$(REDIRECTERR)
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
// here's our event, ics-style
|
||||
|
||||
const icsEvent = "BEGIN:VCALENDAR
|
||||
PRODID:-//ORACLE//NONSGML CSDK 9.0.5 - CalDAVServlet 9.0.5//EN
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:uuid:1103314036911
|
||||
ORGANIZER;X-ORACLE-GUID=E93594067928763EE0305794071A39A4;CN=Dan Mosedale:
|
||||
mailto:dan.mosedale@oracle.com
|
||||
SEQUENCE:0
|
||||
DTSTAMP:20041223T032127Z
|
||||
CREATED:20041217T200716Z
|
||||
DTSTART:20041215T160000Z
|
||||
DTEND:20041215T170000Z
|
||||
X-ORACLE-EVENTINSTANCE-GUID:I1+1093+1+1+440626036
|
||||
X-ORACLE-EVENT-GUID:E1+1093+1+440626036
|
||||
X-ORACLE-EVENTTYPE:APPOINTMENT
|
||||
TRANSP:OPAQUE
|
||||
SUMMARY:monkey
|
||||
STATUS:CONFIRMED
|
||||
PRIORITY:0
|
||||
CLASS:PUBLIC
|
||||
ATTENDEE;X-ORACLE-PERSONAL-COMMENT-ISDIRTY=TRUE;X-ORACLE-SHOWASFREE=BUSY;
|
||||
X-ORACLE-GUID=E93594067928763EE0305794071A39A4;CUTYPE=INDIVIDUAL;RSVP=FA
|
||||
LSE;CN=Dan Mosedale;PARTSTAT=ACCEPTED:mailto:dan.mosedale@oracle.com
|
||||
BEGIN:VALARM
|
||||
TRIGGER:-P0DT0H10M0S
|
||||
ACTION:DISPLAY
|
||||
DESCRIPTION:monkey
|
||||
END:VALARM
|
||||
BEGIN:VALARM
|
||||
TRIGGER:-P0DT0H10M0S
|
||||
ACTION:AUDIO
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
";
|
||||
|
||||
|
||||
var cal = createInstance("@mozilla.org/calendar/calendar;1?type=caldav",
|
||||
CI.calICalendar);
|
||||
cal.uri = URLFromSpec(calendarUri);
|
||||
|
||||
var listener = new calOpListener();
|
||||
|
||||
cal.getItem("20041119T052348Z-100040d-1-248609e9-Oracle", listener);
|
||||
|
||||
if (!done)
|
||||
runEventPump();
|
||||
12
mozilla/calendar/test/homegrown/memory/getEvents.js
Normal file
12
mozilla/calendar/test/homegrown/memory/getEvents.js
Normal file
@ -0,0 +1,12 @@
|
||||
var cal = createInstance("@mozilla.org/calendar/calendar;1?type="
|
||||
+ calendarType, CI.calICalendar);
|
||||
cal.uri = URLFromSpec(calendarUri);
|
||||
|
||||
var listener = new calOpListener();
|
||||
|
||||
cal.getItems(CI.calICalendar.ITEM_FILTER_COMPLETED_ALL |
|
||||
CI.calICalendar.ITEM_FILTER_TYPE_EVENT, 0,
|
||||
null, null, listener);
|
||||
|
||||
if (!done)
|
||||
runEventPump();
|
||||
4
mozilla/calendar/test/homegrown/memory/shell.js
Normal file
4
mozilla/calendar/test/homegrown/memory/shell.js
Normal file
@ -0,0 +1,4 @@
|
||||
calendarType = "memory";
|
||||
|
||||
calendarUri = "http://this/doesn't/matter/on/memory/calendar/";
|
||||
|
||||
156
mozilla/calendar/test/homegrown/misc/attendee.js
Normal file
156
mozilla/calendar/test/homegrown/misc/attendee.js
Normal file
@ -0,0 +1,156 @@
|
||||
var eventClass = C.classes["@mozilla.org/calendar/event;1"];
|
||||
var eventIID = C.interfaces.calIEvent;
|
||||
|
||||
var attendeeClass = C.classes["@mozilla.org/calendar/attendee;1"];
|
||||
var attendeeIID = C.interfaces.calIAttendee;
|
||||
|
||||
dump("* Creating event.\n");
|
||||
var e = eventClass.createInstance(eventIID);
|
||||
dump("* Creating attendee.\n");
|
||||
var a1 = attendeeClass.createInstance(attendeeIID);
|
||||
dump("* Testing attendee set/get.\n");
|
||||
var properties = ["id", "commonName", "rsvp", "role", "participationStatus",
|
||||
"userType"];
|
||||
var values = ["myid", "mycn", true, attendeeIID.ROLE_CHAIR,
|
||||
attendeeIID.PARTSTAT_DECLINED,
|
||||
attendeeIID.CUTYPE_RESOURCE];
|
||||
if (properties.length != values.length)
|
||||
throw "Test bug: mismatched properties and values arrays!";
|
||||
|
||||
for (var i = 0; i < properties.length; i++) {
|
||||
a1[properties[i]] = values[i];
|
||||
if (a1[properties[i]] != values[i]) {
|
||||
throw "FAILED! " + properties[i] + " not set to " + values[i];
|
||||
}
|
||||
}
|
||||
|
||||
dump("* Adding attendee to event.\n");
|
||||
e.addAttendee(a1);
|
||||
dump("* Adding 2nd attendee to event.\n");
|
||||
var a2 = attendeeClass.createInstance(attendeeIID);
|
||||
a2.id = "myid2";
|
||||
e.addAttendee(a2);
|
||||
|
||||
dump("* Finding by ID.\n");
|
||||
|
||||
function findById(id, a) {
|
||||
var foundAttendee = e.getAttendeeById(id);
|
||||
if (foundAttendee != a) {
|
||||
throw "FAILED! wrong attendee returned for + '" +
|
||||
id + "' (got " + foundAttendee + ", expected " + a + ")";
|
||||
}
|
||||
}
|
||||
|
||||
findById("myid", a1);
|
||||
findById("myid2", a2);
|
||||
|
||||
dump("* Searching getAttendees results\n");
|
||||
var found1, found2;
|
||||
|
||||
function findAttendeesInResults(expectedCount) {
|
||||
if (expectedCount == undefined)
|
||||
throw "TEST BUG: expectedCount not passed to findAttendeesInResults";
|
||||
var countObj = {};
|
||||
dump(" Getting all attendees.\n");
|
||||
var allAttendees = e.getAttendees(countObj);
|
||||
if (countObj.value != allAttendees.length) {
|
||||
throw "FAILED! out count (" + countObj.value + ") != .length (" +
|
||||
allAttendees.length + ")";
|
||||
}
|
||||
|
||||
if (allAttendees.length != expectedCount) {
|
||||
throw "FAILED! expected to get back " + expectedCount +
|
||||
" attendees, got " + allAttendees.length;
|
||||
}
|
||||
|
||||
found1 = false, found2 = false;
|
||||
for (var i = 0; i < expectedCount; i++) {
|
||||
if (allAttendees[i] == a1)
|
||||
found1 = true;
|
||||
else if (allAttendees[i] == a2)
|
||||
found2 = true;
|
||||
else {
|
||||
throw "FAILED! unknown attendee " + allAttendees[i] +
|
||||
" (we added " + a1 + " and " + a2 + + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
findAttendeesInResults(2);
|
||||
if (!found1)
|
||||
throw "FAILED! didn't find attendee1 (" + a1 + ") in results";
|
||||
if (!found2)
|
||||
throw "FAILED! didn't find attendee2 (" + a2 + ") in results";
|
||||
|
||||
dump("* Removing attendee.\n");
|
||||
e.removeAttendee(a1);
|
||||
if (e.getAttendeeById(a1.id) != null)
|
||||
throw "FAILED! got back removed attendee " + a1 + " by id";
|
||||
findById("myid2", a2);
|
||||
found1 = false, found2 = false;
|
||||
findAttendeesInResults(1);
|
||||
if (found1)
|
||||
throw "FAILED! found removed attendee " + a1 + " in getAttendees results";
|
||||
if (!found2) {
|
||||
throw "FAILED! didn't find remaining attendee " + a2 +
|
||||
" in getAttendees results";
|
||||
}
|
||||
|
||||
dump("* Readding attendee.\n");
|
||||
e.addAttendee(a1);
|
||||
findById("myid", a1);
|
||||
findById("myid2", a2);
|
||||
findAttendeesInResults(2);
|
||||
if (!found1)
|
||||
throw "FAILED! didn't find attendee1 (" + a1 + ") in results";
|
||||
if (!found2)
|
||||
throw "FAILED! didn't find attendee2 (" + a2 + ") in results";
|
||||
|
||||
dump("* Making attendee immutable.\n");
|
||||
a1.makeImmutable();
|
||||
function testImmutability(a) {
|
||||
if (a.isMutable) {
|
||||
throw "FAILED! Attendee " + a +
|
||||
" should be immutable, but claims otherwise";
|
||||
}
|
||||
for (var i = 0; i < properties.length; i++) {
|
||||
var old = a[properties[i]];
|
||||
var threw;
|
||||
try {
|
||||
a[properties[i]] = old + 1;
|
||||
threw = false;
|
||||
} catch (e) {
|
||||
threw = true;
|
||||
}
|
||||
if (!threw) {
|
||||
throw "FAILED! no error thrown setting " + properties[i] +
|
||||
"on immutable attendee " + a;
|
||||
}
|
||||
if (a[properties[i]] != old) {
|
||||
throw "FAILED! setting " + properties[i] + " on " + a +
|
||||
" threw, but changed value anyway!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testImmutability(a1);
|
||||
dump("* Testing cascaded immutability (event -> attendee).\n");
|
||||
e.makeImmutable();
|
||||
testImmutability(a2);
|
||||
|
||||
dump("* Testing cloning\n");
|
||||
var ec = e.clone();
|
||||
var clonedatts = ec.getAttendees({});
|
||||
var atts = e.getAttendees({});
|
||||
if (atts.length != clonedatts.length) {
|
||||
throw "FAILED! cloned event has " + clonedatts.length +
|
||||
"attendees, original had " + atts.length;
|
||||
}
|
||||
for (i = 0; i < clonedatts.length; i++) {
|
||||
if (atts[i] == clonedatts[i])
|
||||
throw "FAILED! attendee " + atts[i].id + " shared with clone!";
|
||||
if (atts[i].id != clonedatts[i].id) {
|
||||
throw "FAILED! id mismatch on index " + i + ": " +
|
||||
atts[i].id + " != " + clonedatts[i].id;
|
||||
}
|
||||
}
|
||||
dump("PASSED!\n");
|
||||
41
mozilla/calendar/test/homegrown/misc/ics-roundtrip.js
Normal file
41
mozilla/calendar/test/homegrown/misc/ics-roundtrip.js
Normal file
@ -0,0 +1,41 @@
|
||||
var eventClass = C.classes["@mozilla.org/calendar/event;1"];
|
||||
var eventIID = C.interfaces.calIEvent;
|
||||
|
||||
dump("* Creating event.\n");
|
||||
var e = eventClass.createInstance(eventIID);
|
||||
|
||||
var ics_xmas =
|
||||
'BEGIN:VCALENDAR\nPRODID:-//ORACLE//NONSGML CSDK 9.0.5 - CalDAVServlet 9.0.5//EN\nVERSION:2.0\nBEGIN:VEVENT\nUID:20041119T052239Z-1000472-1-5c0746bb-Oracle\nORGANIZER;X-ORACLE-GUID=E9359406791C763EE0305794071A39A4;CN=Simon Vaillan\n court:mailto:simon.vaillancourt@oracle.com\nSEQUENCE:0\nDTSTAMP:20041124T010028Z\nCREATED:20041119T052239Z\nX-ORACLE-EVENTINSTANCE-GUID:I1+16778354+1+1+438153759\nX-ORACLE-EVENT-GUID:E1+16778354+1+438153759\nX-ORACLE-EVENTTYPE:DAY EVENT\nTRANSP:TRANSPARENT\nSUMMARY:Christmas\nSTATUS:CONFIRMED\nPRIORITY:0\nDTSTART;VALUE=DATE:20041125\nDTEND;VALUE=DATE:20041125\nCLASS:PUBLIC\nATTENDEE;X-ORACLE-GUID=E92F51FB4A48E91CE0305794071A149C;CUTYPE=INDIVIDUAL\n ;RSVP=TRUE;CN=James Stevens;PARTSTAT=NEEDS-ACTION:mailto:james.stevens@o\n racle.com\nATTENDEE;X-ORACLE-GUID=E9359406791C763EE0305794071A39A4;CUTYPE=INDIVIDUAL\n ;RSVP=FALSE;CN=Simon Vaillancourt;PARTSTAT=ACCEPTED:mailto:simon.vaillan\n court@oracle.com\nATTENDEE;X-ORACLE-GUID=E9359406791D763EE0305794071A39A4;CUTYPE=INDIVIDUAL\n ;RSVP=TRUE;CN=Bernard Desruisseaux;PARTSTAT=NEEDS-ACTION:mailto:bernard.\n desruisseaux@oracle.com\nATTENDEE;X-ORACLE-GUID=E9359406791E763EE0305794071A39A4;CUTYPE=INDIVIDUAL\n ;RSVP=TRUE;CN=Mario Bonin;PARTSTAT=NEEDS-ACTION:mailto:mario.bonin@oracl\n e.com\nATTENDEE;X-ORACLE-GUID=E9359406791F763EE0305794071A39A4;CUTYPE=INDIVIDUAL\n ;RSVP=TRUE;CN=Jeremy Chone;PARTSTAT=NEEDS-ACTION:mailto:jeremy.chone@ora\n cle.com\nATTENDEE;X-ORACLE-PERSONAL-COMMENT-ISDIRTY=TRUE;X-ORACLE-GUID=E9359406792\n 0763EE0305794071A39A4;CUTYPE=INDIVIDUAL;RSVP=TRUE;CN=Mike Shaver;PARTSTA\n T=NEEDS-ACTION:mailto:mike.x.shaver@oracle.com\nATTENDEE;X-ORACLE-GUID=E93594067921763EE0305794071A39A4;CUTYPE=INDIVIDUAL\n ;RSVP=TRUE;CN=David Ball;PARTSTAT=NEEDS-ACTION:mailto:david.ball@oracle.\n com\nATTENDEE;X-ORACLE-GUID=E93594067922763EE0305794071A39A4;CUTYPE=INDIVIDUAL\n ;RSVP=TRUE;CN=Marten Haring;PARTSTAT=NEEDS-ACTION:mailto:marten.den.hari\n ng@oracle.com\nATTENDEE;X-ORACLE-GUID=E93594067923763EE0305794071A39A4;CUTYPE=INDIVIDUAL\n ;RSVP=TRUE;CN=Peter Egyed;PARTSTAT=NEEDS-ACTION:mailto:peter.egyed@oracl\n e.com\nATTENDEE;X-ORACLE-GUID=E93594067924763EE0305794071A39A4;CUTYPE=INDIVIDUAL\n ;RSVP=TRUE;CN=Francois Perrault;PARTSTAT=NEEDS-ACTION:mailto:francois.pe\n rrault@oracle.com\nATTENDEE;X-ORACLE-GUID=E93594067925763EE0305794071A39A4;CUTYPE=INDIVIDUAL\n ;RSVP=TRUE;CN=Vladimir Vukicevic;PARTSTAT=NEEDS-ACTION:mailto:vladimir.v\n ukicevic@oracle.com\nATTENDEE;X-ORACLE-GUID=E93594067926763EE0305794071A39A4;CUTYPE=INDIVIDUAL\n ;RSVP=TRUE;CN=Cyrus Daboo;PARTSTAT=NEEDS-ACTION:mailto:daboo@isamet.com\nATTENDEE;X-ORACLE-GUID=E93594067927763EE0305794071A39A4;CUTYPE=INDIVIDUAL\n ;RSVP=TRUE;CN=Lisa Dusseault;PARTSTAT=NEEDS-ACTION:mailto:lisa@osafounda\n tion.org\nATTENDEE;X-ORACLE-GUID=E93594067928763EE0305794071A39A4;CUTYPE=INDIVIDUAL\n ;RSVP=TRUE;CN=Dan Mosedale;PARTSTAT=NEEDS-ACTION:mailto:dan.mosedale@ora\n cle.com\nATTENDEE;X-ORACLE-GUID=E93594067929763EE0305794071A39A4;CUTYPE=INDIVIDUAL\n ;RSVP=TRUE;CN=Stuart Parmenter;PARTSTAT=NEEDS-ACTION:mailto:stuart.parme\n nter@oracle.com\nEND:VEVENT\nEND:VCALENDAR\n\n';
|
||||
|
||||
dump("* Setting ical string (xmas)\n");
|
||||
e.icalString = ics_xmas;
|
||||
dump("* Checking basic properties\n");
|
||||
var expectedProps =
|
||||
[["title", "Christmas"],
|
||||
["id", "20041119T052239Z-1000472-1-5c0746bb-Oracle"],
|
||||
["priority", 0],
|
||||
["status", "CONFIRMED"],
|
||||
["generation", 0],
|
||||
["isAllDay", true]];
|
||||
function checkProps(expectedProps, obj) {
|
||||
for (var i = 0; i < expectedProps.length; i++) {
|
||||
if (obj[expectedProps[i][0]] != expectedProps[i][1]) {
|
||||
throw "FAILED! expected " + expectedProps[i][0] + " to be " +
|
||||
expectedProps[i][1] + " but got " + obj[expectedProps[i][0]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkProps(expectedProps, e);
|
||||
|
||||
dump("* Checking start date\n");
|
||||
expectedProps =
|
||||
[["month", 10],
|
||||
["day", 25],
|
||||
["year", 2004],
|
||||
["isDate", true]];
|
||||
checkProps(expectedProps, e.startDate);
|
||||
dump("* Checking end date\n");
|
||||
checkProps(expectedProps, e.endDate);
|
||||
|
||||
dump("PASSED!\n");
|
||||
@ -0,0 +1,35 @@
|
||||
//
|
||||
// simple test bits
|
||||
//
|
||||
|
||||
|
||||
const eventContractID = "@mozilla.org/calendar/event;1";
|
||||
const eventIID = Components.interfaces.calIEvent;
|
||||
|
||||
dump ("Creating mutable event...\n");
|
||||
var me = Components.classes[eventContractID].createInstance(eventIID);
|
||||
|
||||
me.title = "Test Title";
|
||||
dump ("Title is: " + me.title + " (jsobj: " + me.wrappedJSObject.mTitle + ")\n");
|
||||
if (me.title != "Test Title") {
|
||||
throw("FAILED! Title on mutable event contained unexpected value.");
|
||||
}
|
||||
|
||||
dump ("Setting event-to be non-mutable...\n");
|
||||
me.makeImmutable();
|
||||
|
||||
dump ("Trying to set title (should fail)\n");
|
||||
try {
|
||||
// this should cause an exception
|
||||
me.title = "Fail";
|
||||
|
||||
// so we'll only get here if something is wrong, and there's no exception
|
||||
dump("FAILED\n!");
|
||||
} catch (ex) {
|
||||
}
|
||||
|
||||
if (me.title != "Test Title") {
|
||||
throw("FAILED! Title on immutable event contained unexpected value: "
|
||||
+ me.title);
|
||||
}
|
||||
|
||||
192
mozilla/calendar/test/homegrown/misc/synchronization.js
Normal file
192
mozilla/calendar/test/homegrown/misc/synchronization.js
Normal file
@ -0,0 +1,192 @@
|
||||
/*
|
||||
* This is the memory hog version. Read all events in memory, then sync
|
||||
* from there.
|
||||
* Doing it the right async way gives me too many headaches.
|
||||
*/
|
||||
|
||||
const calICalendar = Components.interfaces.calICalendar;
|
||||
|
||||
var emptyListener =
|
||||
{
|
||||
onOperationComplete: function(aCalendar, aStatus, aOperationType, aId, aDetail) {},
|
||||
onGetResult: function(aCalendar, aStatus, aItemType, aDetail, aCount, aItems) {}
|
||||
};
|
||||
|
||||
var localcal = Components.classes["@mozilla.org/calendar/calendar;1?type=memory"]
|
||||
.createInstance(Components.interfaces.calICalendar);
|
||||
var remotecal = Components.classes["@mozilla.org/calendar/calendar;1?type=memory"]
|
||||
.createInstance(Components.interfaces.calICalendar);
|
||||
var changecal = Components.classes["@mozilla.org/calendar/calendar;1?type=memory"]
|
||||
.createInstance(Components.interfaces.calICalendar);
|
||||
|
||||
|
||||
// local: B CC
|
||||
// change: A, B, C
|
||||
// remote: A, C
|
||||
// expected: B, CC
|
||||
createEvent("i2", "B", localcal);
|
||||
createEvent("i3", "CC", localcal);
|
||||
createEvent("i1", "A", remotecal);
|
||||
createEvent("i3", "C", remotecal);
|
||||
createEvent("i1", "A", changecal);
|
||||
createEvent("i2", "B", changecal);
|
||||
createEvent("i3", "C", changecal);
|
||||
|
||||
dump("Before\n");
|
||||
dumpCals();
|
||||
|
||||
// Start by getting all the items into an array
|
||||
var localItems = [];
|
||||
var remoteItems = [];
|
||||
var changeItems = [];
|
||||
|
||||
// This will get the items from the calendars into the global arrays,
|
||||
// then call doSync()
|
||||
getCalandarItems();
|
||||
|
||||
function doSync()
|
||||
{
|
||||
/*
|
||||
* forall changeEvents
|
||||
* if (!remoteEvent)
|
||||
* remoteCalendar.add(localEvent);
|
||||
* else if (remoteEvent != changedEvent)
|
||||
* conflict();
|
||||
* else if (!localEvent)
|
||||
* remoteCalendar.deleteEvent(changedEvent.id)
|
||||
*/
|
||||
|
||||
for (id in changeItems) {
|
||||
if (!remoteItems[id])
|
||||
remotecal.addItem(localItems[id].clone(), emptyListener);
|
||||
else if (!itemsAreEqual(remoteItems[id], changeItems[id]))
|
||||
dump("Conflict! wheep! "+remoteItems[id].title+" != "+changeItems[id].title+"\n");
|
||||
else if (!localItems[id]) {
|
||||
remotecal.deleteItem(remoteItems[id], emptyListener);
|
||||
delete remoteItems[id];
|
||||
}
|
||||
}
|
||||
|
||||
//dump("Halfway\n");
|
||||
//dumpCals();
|
||||
|
||||
// now for part two: remote to local
|
||||
|
||||
/*
|
||||
* forall remoteEvents
|
||||
* if (!localEvent)
|
||||
* localCalendar.add(remoteEvent);
|
||||
* else if (localEvent != remoteEvent)
|
||||
* if (!changeEvent)
|
||||
* localCalendar.modify(localEvent.id, remoteEvent);
|
||||
* else if (changeEvent == remoteEvent)
|
||||
* remoteCalendar.modify(remoteEvent.id, localEvent);
|
||||
* else
|
||||
* conflict();
|
||||
*/
|
||||
|
||||
for (id in remoteItems) {
|
||||
if (!localItems[id])
|
||||
localcal.addItem(remoteItems[i].clone(), emptyListener);
|
||||
if (!itemsAreEqual(localItems[id], remoteItems[id])) {
|
||||
if (!changeItems[id]) {
|
||||
copyItems(remoteItems[id], localItems[id]);
|
||||
localcal.modifyItem(localItems[id], emptyListener);
|
||||
} else if (itemsAreEqual(remoteItems[id], changeItems[id])) {
|
||||
copyItems(localItems[id], remoteItems[id]);
|
||||
remotecal.modifyItem(remoteItems[id], emptyListener);
|
||||
} else {
|
||||
// There is a conflict, but that was already detected before when
|
||||
// dealing with locally changed items. No need to do that again.
|
||||
//dump("Conflict\n");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
dump("After\n");
|
||||
dumpCals();
|
||||
}
|
||||
|
||||
|
||||
function itemsAreEqual(itemA, itemB)
|
||||
{
|
||||
return (itemA.id == itemB.id && itemA.title == itemB.title)
|
||||
}
|
||||
|
||||
function copyItems(aSource, aDest)
|
||||
{
|
||||
aDest.title = aSource.title;
|
||||
}
|
||||
|
||||
function createEvent(aID, aTitle, aCal)
|
||||
{
|
||||
var event = Components.classes["@mozilla.org/calendar/event;1"]
|
||||
.createInstance(Components.interfaces.calIEvent);
|
||||
event.title = aTitle;
|
||||
event.id = aID;
|
||||
aCal.addItem(event, emptyListener);
|
||||
}
|
||||
|
||||
function getCalandarItems()
|
||||
{
|
||||
var calendarsFinished = 0;
|
||||
|
||||
var getListener =
|
||||
{
|
||||
onOperationComplete: function(aCalendar, aStatus, aOperationType, aId, aDetail)
|
||||
{
|
||||
calendarsFinished++;
|
||||
if (calendarsFinished == 3) {
|
||||
doSync();
|
||||
}
|
||||
},
|
||||
onGetResult: function(aCalendar, aStatus, aItemType, aDetail, aCount, aItems)
|
||||
{
|
||||
if (aCount) {
|
||||
var ar;
|
||||
if (aCalendar == localcal)
|
||||
items = localItems;
|
||||
else if (aCalendar == remotecal)
|
||||
items = remoteItems;
|
||||
else if (aCalendar == changecal)
|
||||
items = changeItems;
|
||||
|
||||
for (var i=0; i<aCount; ++i) {
|
||||
items[aItems[i].id] = aItems[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
localcal.getItems(calICalendar.ITEM_FILTER_TYPE_ALL | calICalendar.ITEM_FILTER_COMPLETED_ALL,
|
||||
0, null, null, getListener);
|
||||
remotecal.getItems(calICalendar.ITEM_FILTER_TYPE_ALL | calICalendar.ITEM_FILTER_COMPLETED_ALL,
|
||||
0, null, null, getListener);
|
||||
changecal.getItems(calICalendar.ITEM_FILTER_TYPE_ALL | calICalendar.ITEM_FILTER_COMPLETED_ALL,
|
||||
0, null, null, getListener);
|
||||
}
|
||||
|
||||
|
||||
function dumpCals()
|
||||
{
|
||||
var dumpListener =
|
||||
{
|
||||
onOperationComplete: function(aCalendar, aStatus, aOperationType, aId, aDetail) {},
|
||||
onGetResult: function(aCalendar, aStatus, aItemType, aDetail, aCount, aItems)
|
||||
{
|
||||
for (var i=0; i<aCount; ++i) {
|
||||
dump(" "+i+" "+aItems[i].id+" "+aItems[i].title+"\n");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
dump(" Local: \n");
|
||||
localcal.getItems(calICalendar.ITEM_FILTER_TYPE_ALL | calICalendar.ITEM_FILTER_COMPLETED_ALL,
|
||||
0, null, null, dumpListener);
|
||||
dump("\n Remote: \n");
|
||||
remotecal.getItems(calICalendar.ITEM_FILTER_TYPE_ALL | calICalendar.ITEM_FILTER_COMPLETED_ALL,
|
||||
0, null, null, dumpListener);
|
||||
dump("\n");
|
||||
}
|
||||
|
||||
143
mozilla/calendar/test/homegrown/shell.js
Normal file
143
mozilla/calendar/test/homegrown/shell.js
Normal file
@ -0,0 +1,143 @@
|
||||
/* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org calendar code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Oracle Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Dan Mosedale <dan.mosedale@oracle.com>
|
||||
* Mike Shaver <mike.x.shaver@oracle.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const C = Components;
|
||||
const CI = C.interfaces;
|
||||
|
||||
const evQSvc = getService("@mozilla.org/event-queue-service;1",
|
||||
"nsIEventQueueService");
|
||||
const evQ = evQSvc.getSpecialEventQueue(CI.nsIEventQueueService.CURRENT_THREAD_EVENT_QUEUE);
|
||||
|
||||
var done = false;
|
||||
|
||||
function runEventPump()
|
||||
{
|
||||
pumpRunning = true;
|
||||
while (pumpRunning) {
|
||||
evQ.processPendingEvents();
|
||||
}
|
||||
}
|
||||
|
||||
function stopEventPump()
|
||||
{
|
||||
pumpRunning = false;
|
||||
}
|
||||
|
||||
// I wonder how many copies of this are floating around
|
||||
function findErr(result)
|
||||
{
|
||||
for (var i in C.results) {
|
||||
if (C.results[i] == result) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
dump("No result code found for " + result + "\n");
|
||||
}
|
||||
// I wonder how many copies of this are floating around
|
||||
function findIface(iface)
|
||||
{
|
||||
for (var i in CI) {
|
||||
if (iface.equals(CI[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
dump("No interface found for " + iface + "\n");
|
||||
}
|
||||
|
||||
function findOpName(op)
|
||||
{
|
||||
for (var i in CI.calIOperationListener) {
|
||||
if (op == CI.calIOperationListener[i]) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
dump("Operation type " + op + "unknown\n");
|
||||
}
|
||||
|
||||
function getService(contract, iface)
|
||||
{
|
||||
return C.classes[contract].getService(CI[iface]);
|
||||
}
|
||||
|
||||
function createInstance(contract, iface)
|
||||
{
|
||||
return C.classes[contract].createInstance(CI[iface]);
|
||||
}
|
||||
|
||||
function calOpListener() {
|
||||
}
|
||||
|
||||
calOpListener.prototype =
|
||||
{
|
||||
|
||||
onOperationComplete: function(aCalendar, aStatus, aOperationType, aId,
|
||||
aDetail) {
|
||||
dump("onOperationComplete:\n\t");
|
||||
dump(aCalendar + "\n\t" + findErr(aStatus) + "\n\t" +
|
||||
findOpName(aOperationType) + "\n\t" + aId + "\n\t" + aDetail +
|
||||
"\n");
|
||||
|
||||
stopEventPump();
|
||||
done = true;
|
||||
|
||||
if (Components.isSuccessCode(aStatus)) {
|
||||
dump("PASSED! Listener returned failure code.\n");
|
||||
} else {
|
||||
dump("FAILED! Listener returned failure code.\n");
|
||||
}
|
||||
},
|
||||
|
||||
onGetResult: function(aCalendar, aStatus, aItemType, aDetail, aCount,
|
||||
aItems) {
|
||||
dump("onGetResult: \n\t");
|
||||
dump(aCalendar + "\n\t" + findErr(aStatus) + "\n\t" + findIface(aItemType)
|
||||
+ "\n\t" + aDetail + "\n\t" + aCount + "\n\t" + aItems + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
function GETITEM(aId) {
|
||||
|
||||
}
|
||||
|
||||
const ioSvc = getService("@mozilla.org/network/io-service;1",
|
||||
"nsIIOService");
|
||||
|
||||
function URLFromSpec(spec)
|
||||
{
|
||||
return ioSvc.newURI(spec, null, null);
|
||||
}
|
||||
|
||||
1289
mozilla/calendar/test/jsDriver.pl
Executable file
1289
mozilla/calendar/test/jsDriver.pl
Executable file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user