summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/changelog.txt5
-rw-r--r--src/chrome/content/synckolab/addressbookTools.js21
-rw-r--r--src/chrome/content/synckolab/config.js2
-rw-r--r--src/chrome/content/synckolab/tools.js43
-rw-r--r--src/chrome/content/synckolab/wndConfig.xul2
-rw-r--r--test/lib/jsdiff.js150
-rw-r--r--test/suite.js7
-rw-r--r--test/synckolab/parser/kolab3/contactTest.js21
-rw-r--r--test/synckolab/parser/kolab3/xml/complex.vcf.mime.xml75
-rw-r--r--test/synckolab/parser/kolab3/xml/simple.vcf.mime.xml18
-rw-r--r--test/synckolab/tools/toolsTest.js5
11 files changed, 281 insertions, 68 deletions
diff --git a/src/changelog.txt b/src/changelog.txt
index 1c4eefd..0d202c6 100644
--- a/src/changelog.txt
+++ b/src/changelog.txt
@@ -1,3 +1,8 @@
+SyncKolab 2.9.0
+===============
+* Add support for kolab3
+* Add unit test framework
+
SyncKolab 2.0.2
===============
* #24933 hide folders does not work
diff --git a/src/chrome/content/synckolab/addressbookTools.js b/src/chrome/content/synckolab/addressbookTools.js
index 0af8d1d..601e958 100644
--- a/src/chrome/content/synckolab/addressbookTools.js
+++ b/src/chrome/content/synckolab/addressbookTools.js
@@ -1261,8 +1261,8 @@ synckolab.addressbookTools.list2Kolab3 = function (card, fields) {
xml += "<vlist version=\"1.0\" >\n";
xml += " <product-id>SyncKolab " + synckolab.config.version + ", Kolab resource</product-id>\n";
xml += " <uid>" + this.getUID(card) + "</uid>\n";
- xml += " <creation-date>" + synckolab.tools.text.date2String(new Date(this.getCardProperty(card, "LastModifiedDate") * 1000)) + "T" + synckolab.tools.text.time2String(new Date(this.getCardProperty(card, "LastModifiedDate") * 1000)) + "Z</creation-date>\n";
- xml += " <last-modification-date>" + synckolab.tools.text.date2String(new Date(this.getCardProperty(card, "LastModifiedDate") * 1000)) + "T" + synckolab.tools.text.time2String(new Date(this.getCardProperty(card, "LastModifiedDate") * 1000)) + "Z</last-modification-date>\n";
+ xml += " <creation-date>" + synckolab.tools.text.calDateTime2String(new Date(), false, true) + "</creation-date>\n";
+ xml += " <last-modification-date>" + synckolab.tools.text.calDateTime2String(new Date(), false, true) + "</last-modification-date>\n";
// default: public - tbird doesnt know of other types of list like private
xml += " <sensitivity>public</sensitivity>\n";
@@ -1333,8 +1333,8 @@ synckolab.addressbookTools.list2Xml = function (card, fields) {
xml += "<distribution-list version=\"1.0\" >\n";
xml += " <product-id>SyncKolab, Kolab resource</product-id>\n";
xml += " <uid>" + this.getUID(card) + "</uid>\n";
- xml += " <creation-date>" + synckolab.tools.text.date2String(new Date(this.getCardProperty(card, "LastModifiedDate") * 1000)) + "T" + synckolab.tools.text.time2String(new Date(this.getCardProperty(card, "LastModifiedDate") * 1000)) + "Z</creation-date>\n";
- xml += " <last-modification-date>" + synckolab.tools.text.date2String(new Date(this.getCardProperty(card, "LastModifiedDate") * 1000)) + "T" + synckolab.tools.text.time2String(new Date(this.getCardProperty(card, "LastModifiedDate") * 1000)) + "Z</last-modification-date>\n";
+ xml += " <creation-date>" + synckolab.tools.text.calDateTime2String(new Date(), false, true) + "</creation-date>\n";
+ xml += " <last-modification-date>" + synckolab.tools.text.calDateTime2String(new Date(), false, true) + "</last-modification-date>\n";
// default: public - tbird doesnt know of other types of list like private
xml += " <sensitivity>public</sensitivity>\n";
@@ -1499,11 +1499,11 @@ synckolab.addressbookTools.getXmlProperty = function(card, field, nodeName, node
var xml = "";
if(nodeName2) {
- xml += "<" + nodeName + ">\n";
+ xml += " <" + nodeName + ">\n";
xml += " " + synckolab.tools.text.nodeWithContent(nodeName2, this.getCardProperty(card, field));
- xml += "</" + nodeName + ">\n";
+ xml += " </" + nodeName + ">\n";
} else {
- xml += " " + synckolab.tools.text.nodeWithContent(nodeName, this.getCardProperty(card, field)) + "\n";
+ xml += " " + synckolab.tools.text.nodeWithContent(nodeName, this.getCardProperty(card, field));
}
return xml;
};
@@ -1530,9 +1530,9 @@ synckolab.addressbookTools.card2Kolab3 = function (card, skipHeader, fields) {
}
xml += "<vcard>\n";
- xml += " <uid><uri>urn:uuid:" + synckolab.tools.text.encode4XML(this.getUID(card)) + "</uri></uid>\n";
- xml += " <prodid><text>SyncKolab , Kolab resource</text></prodid>\n"; // TODO add version
- xml += " <rev><timestamp>" + synckolab.tools.text.calDateTime2String(new Date(this.getCardProperty(card, "LastModifiedDate")), false, true) + "Z</timestamp></rev>\n";
+ xml += " <uid><uri>" + synckolab.tools.text.encode4XML(this.getUID(card)) + "</uri></uid>\n";
+ xml += " <prodid><text>SyncKolab " + synckolab.config.version + ", Kolab resource</text></prodid>\n"; // TODO add version
+ xml += " <rev><timestamp>" + synckolab.tools.text.calDateTime2String(new Date(this.getCardProperty(card, "LastModifiedDate")*1000), false, true) + "Z</timestamp></rev>\n";
// ??
//xml += synckolab.tools.text.nodeWithContent("categories", this.getCardProperty(card, "Category"), false);
@@ -1554,7 +1554,6 @@ synckolab.addressbookTools.card2Kolab3 = function (card, skipHeader, fields) {
}
}
- xml += this.getXmlProperty(card, "FirstName", "given");
xml += synckolab.tools.text.nodeWithContent("organization", this.getCardProperty(card, "Company"), false);
xml += this.getXmlProperty(card, "WebPage1", "url", "uri");
diff --git a/src/chrome/content/synckolab/config.js b/src/chrome/content/synckolab/config.js
index 0902159..1157f1f 100644
--- a/src/chrome/content/synckolab/config.js
+++ b/src/chrome/content/synckolab/config.js
@@ -35,7 +35,7 @@
if(!synckolab) var synckolab={};
synckolab.config = {
- version: "3.0.0",
+ version: "2.9.0",
DEBUG_SYNCKOLAB: true,
SWITCH_TIME: 20, //wait 20ms (enough so tbird wont get unresponsive)
diff --git a/src/chrome/content/synckolab/tools.js b/src/chrome/content/synckolab/tools.js
index 6816a47..a27c7ea 100644
--- a/src/chrome/content/synckolab/tools.js
+++ b/src/chrome/content/synckolab/tools.js
@@ -1461,49 +1461,6 @@ synckolab.Node.prototype.getAttribute = function (attrName)
/**
- * compare this to another node.
- */
-synckolab.Node.prototype.isEqualNode = function(other) {
- var that = this;
- var props = ['nodeType', 'nodeName', 'nodeValue'];
- var i;
- for (i = props.length; i-- > 0;) {
- if (that[props[i]] !== other[props[i]]) {
- return false;
- }
- }
-
- // Check element attributes match
- //
- if (that.nodeType === 1) {
- if (that.attributes.length !== other.attributes.length) {
- return false;
- }
- for (i = 0; i < that.attributes.length; i++) {
- if (that.attributes[i] !== other.getAttribute(that.attributes[i].name)) {
- return false;
- }
- }
- }
-
- // Check children match, recursively
- if (that.childNodes.length !== other.childNodes.length) {
- return false;
- }
-
- for (i = that.childNodes.length; i-- > 0;){
-
- if (!new synckolab.Node(that.childNodes[i]).isEqualNode(other.childNodes[i])) {
- return false;
- }
- }
-
- return true;
-};
-
-
-
-/**
* (At least on branch 1.8), the js instanceof operator does not work to test
* interfaces on direct implementation objects, i.e. non-wrapped objects.
* This function falla back to using QueryInterface to check whether the interface
diff --git a/src/chrome/content/synckolab/wndConfig.xul b/src/chrome/content/synckolab/wndConfig.xul
index 4491cff..bfff217 100644
--- a/src/chrome/content/synckolab/wndConfig.xul
+++ b/src/chrome/content/synckolab/wndConfig.xul
@@ -4,7 +4,7 @@
<!DOCTYPE loc SYSTEM "chrome://synckolab/locale/synckolab.dtd">
-<dialog id="syncKolabConfigDlg" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="synckolab.settings.init();" buttons="accept,cancel" ondialogaccept="return synckolab.settings.savePrefs();" persist="screenX screenY" width="0" title="SyncKolab 2.0.3">
+<dialog id="syncKolabConfigDlg" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="synckolab.settings.init();" buttons="accept,cancel" ondialogaccept="return synckolab.settings.savePrefs();" persist="screenX screenY" width="0" title="SyncKolab 2.9.0">
<script type="application/x-javascript" src="chrome://synckolab/content/calendarTools.js" />
<script type="application/x-javascript" src="chrome://synckolab/content/addressbookTools.js"/>
diff --git a/test/lib/jsdiff.js b/test/lib/jsdiff.js
new file mode 100644
index 0000000..4184250
--- /dev/null
+++ b/test/lib/jsdiff.js
@@ -0,0 +1,150 @@
+/*
+ * Javascript Diff Algorithm
+ * By John Resig (http://ejohn.org/)
+ * Modified by Chu Alan "sprite"
+ *
+ * Released under the MIT license.
+ *
+ * More Info:
+ * http://ejohn.org/projects/javascript-diff-algorithm/
+ */
+
+function escape(s) {
+ return s;
+}
+
+function diffString( o, n ) {
+ o = o.replace(/\s+$/, '');
+ n = n.replace(/\s+$/, '');
+
+ var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/) );
+ var str = "";
+
+ var oSpace = o.match(/\s+/g);
+ if (oSpace == null) {
+ oSpace = ["\n"];
+ } else {
+ oSpace.push("\n");
+ }
+ var nSpace = n.match(/\s+/g);
+ if (nSpace == null) {
+ nSpace = ["\n"];
+ } else {
+ nSpace.push("\n");
+ }
+
+ if (out.n.length == 0) {
+ for (var i = 0; i < out.o.length; i++) {
+ str += '-' + escape(out.o[i]) + oSpace[i] + "-";
+ }
+ } else {
+ if (out.n[0].text == null) {
+ for (n = 0; n < out.o.length && out.o[n].text == null; n++) {
+ str += '-' + escape(out.o[n]) + oSpace[n] + "-";
+ }
+ }
+
+ for ( var i = 0; i < out.n.length; i++ ) {
+ if (out.n[i].text == null) {
+ str += '+' + escape(out.n[i]) + nSpace[i] + "+";
+ } else {
+ var pre = "";
+
+ for (n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) {
+ pre += '-' + escape(out.o[n]) + oSpace[n] + "-";
+ }
+ str += " " + out.n[i].text + nSpace[i] + pre;
+ }
+ }
+ }
+
+ return str;
+}
+
+function diffString2( o, n ) {
+ o = o.replace(/\s+$/, '');
+ n = n.replace(/\s+$/, '');
+
+ var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/) );
+
+ var oSpace = o.match(/\s+/g);
+ if (oSpace == null) {
+ oSpace = ["\n"];
+ } else {
+ oSpace.push("\n");
+ }
+ var nSpace = n.match(/\s+/g);
+ if (nSpace == null) {
+ nSpace = ["\n"];
+ } else {
+ nSpace.push("\n");
+ }
+
+ var os = "";
+ var colors = new Array();
+ for (var i = 0; i < out.o.length; i++) {
+ colors[i] = randomColor();
+
+ if (out.o[i].text != null) {
+ os += '<span style="background-color: ' +colors[i]+ '">' +
+ escape(out.o[i].text) + oSpace[i] + "</span>";
+ } else {
+ os += "<del>" + escape(out.o[i]) + oSpace[i] + "</del>";
+ }
+ }
+
+ var ns = "";
+ for (var i = 0; i < out.n.length; i++) {
+ if (out.n[i].text != null) {
+ ns += '<span style="background-color: ' +colors[out.n[i].row]+ '">' +
+ escape(out.n[i].text) + nSpace[i] + "</span>";
+ } else {
+ ns += "<ins>" + escape(out.n[i]) + nSpace[i] + "</ins>";
+ }
+ }
+
+ return { o : os , n : ns };
+}
+
+function diff( o, n ) {
+ var ns = new Object();
+ var os = new Object();
+
+ for ( var i = 0; i < n.length; i++ ) {
+ if ( ns[ n[i] ] == null )
+ ns[ n[i] ] = { rows: new Array(), o: null };
+ ns[ n[i] ].rows.push( i );
+ }
+
+ for ( var i = 0; i < o.length; i++ ) {
+ if ( os[ o[i] ] == null )
+ os[ o[i] ] = { rows: new Array(), n: null };
+ os[ o[i] ].rows.push( i );
+ }
+
+ for ( var i in ns ) {
+ if ( ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1 ) {
+ n[ ns[i].rows[0] ] = { text: n[ ns[i].rows[0] ], row: os[i].rows[0] };
+ o[ os[i].rows[0] ] = { text: o[ os[i].rows[0] ], row: ns[i].rows[0] };
+ }
+ }
+
+ for ( var i = 0; i < n.length - 1; i++ ) {
+ if ( n[i].text != null && n[i+1].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null &&
+ n[i+1] == o[ n[i].row + 1 ] ) {
+ n[i+1] = { text: n[i+1], row: n[i].row + 1 };
+ o[n[i].row+1] = { text: o[n[i].row+1], row: i + 1 };
+ }
+ }
+
+ for ( var i = n.length - 1; i > 0; i-- ) {
+ if ( n[i].text != null && n[i-1].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null &&
+ n[i-1] == o[ n[i].row - 1 ] ) {
+ n[i-1] = { text: n[i-1], row: n[i].row - 1 };
+ o[n[i].row-1] = { text: o[n[i].row-1], row: i - 1 };
+ }
+ }
+
+ return { o: o, n: n };
+}
+
diff --git a/test/suite.js b/test/suite.js
index a0faaf9..544db40 100644
--- a/test/suite.js
+++ b/test/suite.js
@@ -3,6 +3,7 @@
*/
load("test/lib/qunit-1.10.0.js");
load("test/lib/env.rhino.1.2.js");
+load("test/lib/jsdiff.js");
console = {
log: function(msg) {
@@ -38,10 +39,10 @@ QUnit.log(function(details) {
load("test/synckolab/tools/textTest.js");
load("test/synckolab/tools/toolsTest.js");
-load("test/synckolab/parser/kolab2/calendarTest.js");
-load("test/synckolab/parser/kolab2/contactTest.js");
+//load("test/synckolab/parser/kolab2/calendarTest.js");
+//load("test/synckolab/parser/kolab2/contactTest.js");
load("test/synckolab/parser/kolab3/contactTest.js");
-load("test/synckolab/parser/kolab3/calendarTest.js");
+//load("test/synckolab/parser/kolab3/calendarTest.js");
print("========================")
print("Tests Run: " + (testRuns.fail+testRuns.pass));
diff --git a/test/synckolab/parser/kolab3/contactTest.js b/test/synckolab/parser/kolab3/contactTest.js
index e268935..7eb8dc8 100644
--- a/test/synckolab/parser/kolab3/contactTest.js
+++ b/test/synckolab/parser/kolab3/contactTest.js
@@ -27,10 +27,15 @@ test("kolab3 synckolab.addressbookTools.parseMessageContent", function(){
equal(synckolab.tools.equalsObject(entry, jsonEntry), true, src);
// json -> kolab 3 xml
-
+ content = synckolab.addressbookTools.card2Kolab3(entry);
+ xmlcontent = readFile("test/synckolab/parser/kolab3/xml/"+src + ".xml");
+ if (xmlcontent.replace(/[\n\r\t ]/g, "").length != content.replace(/[\n\r\t ]/g, "").length) {
+ var diff = diffString(xmlcontent, content)
+ print("DIFF FOUND:"+ xmlcontent.replace(/[\n\r\t ]/g, "").length + " vs. "+ content.replace(/[\n\r\t ]/g, "").length +"\n" + diff);
+ }
}
});
-
+/*
var testFiles = ["simple.vcf.mime"];
@@ -47,13 +52,13 @@ test("kolab3 synckolab.addressbookTools.parseMessageContent", function(){
print(JSON.stringify(entry, null, ' '))
// json -> kolab 3 xml
content = synckolab.addressbookTools.card2Kolab3(entry);
- print(content);
- /*
- content = readFile("test/synckolab/parser/kolab3/json/"+src+".json");
- jsonEntry = JSON.parse(content);
- equal(synckolab.tools.equalsObject(entry, jsonEntry), true, src);
- */
+ xmlcontent = readFile("test/synckolab/parser/kolab3/xml/"+src + ".xml");
+ if (xmlcontent.replace(/[\n\r\t ]/g, "").length != content.replace(/[\n\r\t ]/g, "").length) {
+ var diff = diffString(xmlcontent, content)
+ print("DIFF FOUND:"+ xmlcontent.replace(/[\n\r\t ]/g, "").length + " vs. "+ content.replace(/[\n\r\t ]/g, "").length +"\n" + diff);
+ }
}
+ */
diff --git a/test/synckolab/parser/kolab3/xml/complex.vcf.mime.xml b/test/synckolab/parser/kolab3/xml/complex.vcf.mime.xml
new file mode 100644
index 0000000..b6f074b
--- /dev/null
+++ b/test/synckolab/parser/kolab3/xml/complex.vcf.mime.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
+<vcards xmlns="urn:ietf:params:xml:ns:vcard-4.0">
+<vcard>
+ <uid><uri>urn:uuid:Huu5X7hfYy</uri></uid>
+ <prodid><text>SyncKolab 3.0.0, Kolab resource</text></prodid>
+ <rev><timestamp>19700101T000000ZZ</timestamp></rev>
+ <note>
+ <text>Notes</text>
+ </note>
+ <n>
+ <given>Lastname</given>
+ <surname>Firstname</surname>
+ </n>
+ <fn><text>Displayname</text></fn>
+ <url>
+ <uri>www.homepage.org</uri>
+ </url>
+ <url>
+ <uri>www.blog.test</uri>
+ </url>
+ <impp>
+ <uri>messaging</uri>
+ </impp>
+ <title>
+ <text>Title</text>
+ </title>
+ <nickname>
+ <text>Nickname</text>
+ </nickname>
+ <bday> <date-time>2043</date-time>
+</bday>
+ <anniversary> <date-time>2009-7-28</date-time>
+</anniversary>
+ <tel>
+ <parameters><type><text>home</text></type></parameters>
+ <text>+4930-homephone</text>
+ </tel>
+ <tel>
+ <parameters><type><text>work</text></type></parameters>
+ <text>+4930-workphone</text>
+ </tel>
+ <tel>
+ <parameters><type><text>fax</text><text>work</text></type></parameters>
+ <text>+4930-fax</text>
+ </tel>
+ <tel>
+ <parameters><type><text>cell</text></type></parameters>
+ <text>+4930-mobile</text>
+ </tel>
+ <email>
+ <parameters><pref><integer>1</integer></pref></parameters>
+ <text>first@email.org</text>
+ </email>
+ <email>
+ <text>second@email.org</text>
+ </email>
+ <adr>
+ <parameters><type><text>home</text></type></parameters>
+ <street>Home Street</street>
+ <locality>Home Locality</locality>
+ <region>Home Region</region>
+ <code>Home Postal Code</code>
+ <country>Gabon</country>
+ </adr>
+ <adr>
+ <parameters><type><text>work</text></type></parameters>
+ <street>Work Street</street>
+ <locality>Work Locality</locality>
+ <region>Work Region</region>
+ <code>Work Postal Code</code>
+ <country>Azerbaijan</country>
+ </adr>
+ <x-custom><identifier>X-AllowRemoteContent</identifier><value>true</value></x-custom>
+</vcard>
+</vcards> \ No newline at end of file
diff --git a/test/synckolab/parser/kolab3/xml/simple.vcf.mime.xml b/test/synckolab/parser/kolab3/xml/simple.vcf.mime.xml
new file mode 100644
index 0000000..90b72a4
--- /dev/null
+++ b/test/synckolab/parser/kolab3/xml/simple.vcf.mime.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
+ <vcards xmlns="urn:ietf:params:xml:ns:vcard-4.0">
+ <vcard>
+ <uid><uri>urn:uuid:4xuyC0cyjV</uri></uid>
+ <prodid><text>SyncKolab 3.0.0, Kolab resource</text></prodid>
+ <rev><timestamp>19700101T000000ZZ</timestamp></rev>
+ <n>
+ <given>Krause</given>
+ <surname>Volker</surname>
+ </n>
+ <fn><text>Volker Krause</text></fn>
+ <email>
+ <parameters><pref><integer>1</integer></pref></parameters>
+ <text>vkrause@kde.org</text>
+ </email>
+ <x-custom><identifier>X-AllowRemoteContent</identifier><value>false</value></x-custom>
+ </vcard>
+ </vcards> \ No newline at end of file
diff --git a/test/synckolab/tools/toolsTest.js b/test/synckolab/tools/toolsTest.js
index fa6ff53..c534f84 100644
--- a/test/synckolab/tools/toolsTest.js
+++ b/test/synckolab/tools/toolsTest.js
@@ -9,7 +9,7 @@ load("test/lib/testOverride.js");
/**
* Test on Node
*/
-test("synckolab.tools.text.checkExist", function(){
+test("synckolab.Node", function(){
// prepare and read an xml
var content = readFile("test/synckolab/tools/data/domtest.xml");
var doc = synckolab.tools.parseXml(content);
@@ -23,4 +23,7 @@ test("synckolab.tools.text.checkExist", function(){
child = child.getNextNode();
equal(child.nodeName, "child", "dom name (child)");
equal(child.getFirstData(), "2", "child 2");
+
});
+
+