summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorniko <niko>2012-10-09 23:35:41 (GMT)
committerniko <niko>2012-10-09 23:35:41 (GMT)
commit793b6fb9135e641f651715bd94f45a1ba3bbf617 (patch)
tree20b35e7abbec20605e768544f00606e7ff8c598b /test
parent9254ccd9792d7dee7638025f618db6d18e5a945b (diff)
downloadsynckolab-793b6fb9135e641f651715bd94f45a1ba3bbf617.tar.gz
version to 2.9.0 to show upgrade path to 3.0
Diffstat (limited to 'test')
-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
6 files changed, 264 insertions, 12 deletions
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");
+
});
+
+