- convert svgutils_test.html from utf8 to iso-8859-1 (Western) encoding,

so that tools such as grep don't consider it a binary file.
- add <title> to test pages, to make html valid
- harmonize indentation: 2 spaces
- harmonize all empty html elements' closing tags
  to be on the same line as the opening tag



git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2418 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Waldir Pimenta 2013-02-17 17:28:19 +00:00
parent 164b22d0c1
commit 3d71cdf27b
12 changed files with 2087 additions and 2091 deletions

View File

@ -1,82 +1,82 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script>
// Mock for browser.js
window.svgEditor = {ready:function(){}};
</script>
<script src='../editor/contextmenu.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
<title>Unit Tests for contextmenu.js</title>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script>
// Mock for browser.js
window.svgEditor = {ready:function(){}};
</script>
<script src='../editor/contextmenu.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
function tearDown(){
svgedit.contextmenu.resetCustomMenus();
}
function tearDown(){
svgedit.contextmenu.resetCustomMenus();
}
module('svgedit.contextmenu');
module('svgedit.contextmenu');
test('Test svgedit.contextmenu package', function() {
expect(4);
test('Test svgedit.contextmenu package', function() {
expect(4);
ok(svgedit.contextmenu,"contextmenu registered correctly");
ok(svgedit.contextmenu.add,"contextmenu.add registered correctly");
ok(svgedit.contextmenu.hasCustomHandler,"contextmenu hasCustomHandler registered correctly");
ok(svgedit.contextmenu.getCustomHandler,"contextmenu getCustomHandler registered correctly");
});
ok(svgedit.contextmenu,"contextmenu registered correctly");
ok(svgedit.contextmenu.add,"contextmenu.add registered correctly");
ok(svgedit.contextmenu.hasCustomHandler,"contextmenu hasCustomHandler registered correctly");
ok(svgedit.contextmenu.getCustomHandler,"contextmenu getCustomHandler registered correctly");
});
test('Test svgedit.contextmenu does not add invalid menu item', function() {
expect(3);
test('Test svgedit.contextmenu does not add invalid menu item', function() {
expect(3);
svgedit.contextmenu.add({id:"justanid"});
ok(!svgedit.contextmenu.hasCustomHandler("justanid"),"menu item with just an id is invalid");
svgedit.contextmenu.add({id:"justanid"});
ok(!svgedit.contextmenu.hasCustomHandler("justanid"),"menu item with just an id is invalid");
svgedit.contextmenu.add({id:"idandlabel",label:"anicelabel"});
ok(!svgedit.contextmenu.hasCustomHandler("idandlabel"),"menu item with just an id and label is invalid");
svgedit.contextmenu.add({id:"idandlabel",label:"anicelabel"});
ok(!svgedit.contextmenu.hasCustomHandler("idandlabel"),"menu item with just an id and label is invalid");
svgedit.contextmenu.add({id:"idandlabel",label:"anicelabel",action:'notafunction'});
ok(!svgedit.contextmenu.hasCustomHandler("idandlabel"),"menu item with action that is not a function is invalid");
});
svgedit.contextmenu.add({id:"idandlabel",label:"anicelabel",action:'notafunction'});
ok(!svgedit.contextmenu.hasCustomHandler("idandlabel"),"menu item with action that is not a function is invalid");
});
test('Test svgedit.contextmenu adds valid menu item', function() {
expect(2);
test('Test svgedit.contextmenu adds valid menu item', function() {
expect(2);
var validItem = {id:"valid",label:"anicelabel",action:function(){alert('testing')}};
svgedit.contextmenu.add(validItem);
var validItem = {id:"valid",label:"anicelabel",action:function(){alert('testing')}};
svgedit.contextmenu.add(validItem);
ok(svgedit.contextmenu.hasCustomHandler("valid"),"Valid menu item is added.");
equals(svgedit.contextmenu.getCustomHandler("valid"),validItem.action,"Valid menu action is added.");
tearDown();
});
ok(svgedit.contextmenu.hasCustomHandler("valid"),"Valid menu item is added.");
equals(svgedit.contextmenu.getCustomHandler("valid"),validItem.action,"Valid menu action is added.");
tearDown();
});
test('Test svgedit.contextmenu rejects valid duplicate menu item id', function() {
expect(1);
test('Test svgedit.contextmenu rejects valid duplicate menu item id', function() {
expect(1);
var validItem1 = {id:"valid",label:"anicelabel",action:function(){alert('testing')}};
var validItem2 = {id:"valid",label:"anicelabel",action:function(){alert('testingtwice')}};
svgedit.contextmenu.add(validItem1);
svgedit.contextmenu.add(validItem2);
var validItem1 = {id:"valid",label:"anicelabel",action:function(){alert('testing')}};
var validItem2 = {id:"valid",label:"anicelabel",action:function(){alert('testingtwice')}};
svgedit.contextmenu.add(validItem1);
svgedit.contextmenu.add(validItem2);
equals(svgedit.contextmenu.getCustomHandler("valid"),validItem1.action,"duplicate menu item is rejected.");
tearDown();
});
});
</script>
equals(svgedit.contextmenu.getCustomHandler("valid"),validItem1.action,"duplicate menu item is rejected.");
tearDown();
});
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for contextmenu.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='svgroot' style='visibility:hidden'></div>
<h1 id='qunit-header'>Unit Tests for contextmenu.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'></ol>
<div id='svgroot' style='visibility:hidden'></div>
</body>
</html>

View File

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Unit Tests for coords.js</title>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script type='text/javascript' src='../editor/jquery.js'></script>
<script type='text/javascript' src='../editor/svgedit.js'></script>
@ -326,8 +327,7 @@
<h1 id='qunit-header'>Unit Tests for svgedit.coords</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<ol id='qunit-tests'></ol>
<div id='svgroot' style='visibility:hidden'></div>
</body>
</html>

View File

@ -1,535 +1,534 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script src='../editor/browser.js'></script>
<script src='../editor/svgutils.js'></script>
<script src='../editor/draw.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
var NS = svgedit.NS;
var NONCE = 'foo';
var LAYER1 = 'Layer 1';
var LAYER2 = 'Layer 2';
var LAYER3 = 'Layer 3';
var svg = document.createElementNS(NS.SVG, 'svg');
// Set up <svg> with nonce.
var svg_n = document.createElementNS(NS.SVG, 'svg');
svg_n.setAttributeNS(NS.XMLNS, 'xmlns:se', NS.SE);
svg_n.setAttributeNS(NS.SE, 'se:nonce', NONCE);
var setupSvgWith3Layers = function(svgElem) {
var layer1 = document.createElementNS(NS.SVG, 'g');
var layer1_title = document.createElementNS(NS.SVG, 'title');
layer1_title.appendChild(document.createTextNode(LAYER1));
layer1.appendChild(layer1_title);
svgElem.appendChild(layer1);
var layer2 = document.createElementNS(NS.SVG, 'g');
var layer2_title = document.createElementNS(NS.SVG, 'title');
layer2_title.appendChild(document.createTextNode(LAYER2));
layer2.appendChild(layer2_title);
svgElem.appendChild(layer2);
var layer3 = document.createElementNS(NS.SVG, 'g');
var layer3_title = document.createElementNS(NS.SVG, 'title');
layer3_title.appendChild(document.createTextNode(LAYER3));
layer3.appendChild(layer3_title);
svgElem.appendChild(layer3);
};
var cleanupSvg = function(svgElem) {
while(svgElem.firstChild) {svgElem.removeChild(svgElem.firstChild);}
};
test('Test draw module', function() {
expect(4);
ok(svgedit.draw);
equals(typeof svgedit.draw, typeof {});
ok(svgedit.draw.Drawing);
equals(typeof svgedit.draw.Drawing, typeof function(){});
});
test('Test document creation', function() {
expect(3);
try {
var doc = new svgedit.draw.Drawing();
ok(false, 'Created drawing without a valid <svg> element');
} catch(e) {
ok(true);
}
try {
var doc = new svgedit.draw.Drawing(svg);
ok(doc);
equals(typeof doc, typeof {});
} catch(e) {
ok(false, 'Could not create document from valid <svg> element: ' + e)
}
});
<title>Unit Tests for draw.js</title>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script src='../editor/browser.js'></script>
<script src='../editor/svgutils.js'></script>
<script src='../editor/draw.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
var NS = svgedit.NS;
var NONCE = 'foo';
var LAYER1 = 'Layer 1';
var LAYER2 = 'Layer 2';
var LAYER3 = 'Layer 3';
var svg = document.createElementNS(NS.SVG, 'svg');
// Set up <svg> with nonce.
var svg_n = document.createElementNS(NS.SVG, 'svg');
svg_n.setAttributeNS(NS.XMLNS, 'xmlns:se', NS.SE);
svg_n.setAttributeNS(NS.SE, 'se:nonce', NONCE);
var setupSvgWith3Layers = function(svgElem) {
var layer1 = document.createElementNS(NS.SVG, 'g');
var layer1_title = document.createElementNS(NS.SVG, 'title');
layer1_title.appendChild(document.createTextNode(LAYER1));
layer1.appendChild(layer1_title);
svgElem.appendChild(layer1);
var layer2 = document.createElementNS(NS.SVG, 'g');
var layer2_title = document.createElementNS(NS.SVG, 'title');
layer2_title.appendChild(document.createTextNode(LAYER2));
layer2.appendChild(layer2_title);
svgElem.appendChild(layer2);
var layer3 = document.createElementNS(NS.SVG, 'g');
var layer3_title = document.createElementNS(NS.SVG, 'title');
layer3_title.appendChild(document.createTextNode(LAYER3));
layer3.appendChild(layer3_title);
svgElem.appendChild(layer3);
};
var cleanupSvg = function(svgElem) {
while(svgElem.firstChild) {svgElem.removeChild(svgElem.firstChild);}
};
test('Test draw module', function() {
expect(4);
ok(svgedit.draw);
equals(typeof svgedit.draw, typeof {});
ok(svgedit.draw.Drawing);
equals(typeof svgedit.draw.Drawing, typeof function(){});
});
test('Test document creation', function() {
expect(3);
try {
var doc = new svgedit.draw.Drawing();
ok(false, 'Created drawing without a valid <svg> element');
} catch(e) {
ok(true);
}
try {
var doc = new svgedit.draw.Drawing(svg);
ok(doc);
equals(typeof doc, typeof {});
} catch(e) {
ok(false, 'Could not create document from valid <svg> element: ' + e)
}
});
test('Test nonce', function() {
expect(7);
test('Test nonce', function() {
expect(7);
var doc = new svgedit.draw.Drawing(svg);
equals(doc.getNonce(), "");
var doc = new svgedit.draw.Drawing(svg);
equals(doc.getNonce(), "");
doc = new svgedit.draw.Drawing(svg_n);
equals(doc.getNonce(), NONCE);
equals(doc.getSvgElem().getAttributeNS(NS.SE, 'nonce'), NONCE);
doc = new svgedit.draw.Drawing(svg_n);
equals(doc.getNonce(), NONCE);
equals(doc.getSvgElem().getAttributeNS(NS.SE, 'nonce'), NONCE);
doc.clearNonce();
ok(!doc.getNonce());
ok(!doc.getSvgElem().getAttributeNS(NS.SE, 'se:nonce'));
doc.clearNonce();
ok(!doc.getNonce());
ok(!doc.getSvgElem().getAttributeNS(NS.SE, 'se:nonce'));
doc.setNonce(NONCE);
equals(doc.getNonce(), NONCE);
equals(doc.getSvgElem().getAttributeNS(NS.SE, 'nonce'), NONCE);
});
doc.setNonce(NONCE);
equals(doc.getNonce(), NONCE);
equals(doc.getSvgElem().getAttributeNS(NS.SE, 'nonce'), NONCE);
});
test('Test getId() and getNextId() without nonce', function() {
expect(7);
test('Test getId() and getNextId() without nonce', function() {
expect(7);
var elem2 = document.createElementNS(NS.SVG, 'circle');
elem2.id = 'svg_2';
svg.appendChild(elem2);
var elem2 = document.createElementNS(NS.SVG, 'circle');
elem2.id = 'svg_2';
svg.appendChild(elem2);
var doc = new svgedit.draw.Drawing(svg);
var doc = new svgedit.draw.Drawing(svg);
equals(doc.getId(), "svg_0");
equals(doc.getId(), "svg_0");
equals(doc.getNextId(), "svg_1");
equals(doc.getId(), "svg_1");
equals(doc.getNextId(), "svg_1");
equals(doc.getId(), "svg_1");
equals(doc.getNextId(), "svg_3");
equals(doc.getId(), "svg_3");
equals(doc.getNextId(), "svg_3");
equals(doc.getId(), "svg_3");
equals(doc.getNextId(), "svg_4");
equals(doc.getId(), "svg_4");
// clean out svg document
cleanupSvg(svg);
});
equals(doc.getNextId(), "svg_4");
equals(doc.getId(), "svg_4");
// clean out svg document
cleanupSvg(svg);
});
test('Test getId() and getNextId() with prefix without nonce', function() {
expect(7);
test('Test getId() and getNextId() with prefix without nonce', function() {
expect(7);
var prefix = 'Bar-';
var doc = new svgedit.draw.Drawing(svg, prefix);
var prefix = 'Bar-';
var doc = new svgedit.draw.Drawing(svg, prefix);
equals(doc.getId(), prefix+"0");
equals(doc.getId(), prefix+"0");
equals(doc.getNextId(), prefix+"1");
equals(doc.getId(), prefix+"1");
equals(doc.getNextId(), prefix+"1");
equals(doc.getId(), prefix+"1");
equals(doc.getNextId(), prefix+"2");
equals(doc.getId(), prefix+"2");
equals(doc.getNextId(), prefix+"2");
equals(doc.getId(), prefix+"2");
equals(doc.getNextId(), prefix+"3");
equals(doc.getId(), prefix+"3");
equals(doc.getNextId(), prefix+"3");
equals(doc.getId(), prefix+"3");
cleanupSvg(svg);
});
cleanupSvg(svg);
});
test('Test getId() and getNextId() with nonce', function() {
expect(7);
test('Test getId() and getNextId() with nonce', function() {
expect(7);
var prefix = "svg_" + NONCE;
var prefix = "svg_" + NONCE;
var elem2 = document.createElementNS(NS.SVG, 'circle');
elem2.id = prefix+'_2';
svg_n.appendChild(elem2);
var elem2 = document.createElementNS(NS.SVG, 'circle');
elem2.id = prefix+'_2';
svg_n.appendChild(elem2);
var doc = new svgedit.draw.Drawing(svg_n);
var doc = new svgedit.draw.Drawing(svg_n);
equals(doc.getId(), prefix+"_0");
equals(doc.getId(), prefix+"_0");
equals(doc.getNextId(), prefix+"_1");
equals(doc.getId(), prefix+"_1");
equals(doc.getNextId(), prefix+"_1");
equals(doc.getId(), prefix+"_1");
equals(doc.getNextId(), prefix+"_3");
equals(doc.getId(), prefix+"_3");
equals(doc.getNextId(), prefix+"_3");
equals(doc.getId(), prefix+"_3");
equals(doc.getNextId(), prefix+"_4");
equals(doc.getId(), prefix+"_4");
equals(doc.getNextId(), prefix+"_4");
equals(doc.getId(), prefix+"_4");
cleanupSvg(svg_n);
});
cleanupSvg(svg_n);
});
test('Test getId() and getNextId() with prefix with nonce', function() {
expect(7);
test('Test getId() and getNextId() with prefix with nonce', function() {
expect(7);
var PREFIX = 'Bar-';
var doc = new svgedit.draw.Drawing(svg_n, PREFIX);
var PREFIX = 'Bar-';
var doc = new svgedit.draw.Drawing(svg_n, PREFIX);
var prefix = PREFIX + NONCE + "_";
equals(doc.getId(), prefix+"0");
var prefix = PREFIX + NONCE + "_";
equals(doc.getId(), prefix+"0");
equals(doc.getNextId(), prefix+"1");
equals(doc.getId(), prefix+"1");
equals(doc.getNextId(), prefix+"1");
equals(doc.getId(), prefix+"1");
equals(doc.getNextId(), prefix+"2");
equals(doc.getId(), prefix+"2");
equals(doc.getNextId(), prefix+"2");
equals(doc.getId(), prefix+"2");
equals(doc.getNextId(), prefix+"3");
equals(doc.getId(), prefix+"3");
equals(doc.getNextId(), prefix+"3");
equals(doc.getId(), prefix+"3");
cleanupSvg(svg_n);
});
cleanupSvg(svg_n);
});
test('Test releaseId()', function() {
expect(6);
test('Test releaseId()', function() {
expect(6);
var doc = new svgedit.draw.Drawing(svg);
var doc = new svgedit.draw.Drawing(svg);
var firstId = doc.getNextId();
var secondId = doc.getNextId();
var firstId = doc.getNextId();
var secondId = doc.getNextId();
var result = doc.releaseId(firstId);
ok(result);
equals(doc.getNextId(), firstId);
equals(doc.getNextId(), "svg_3");
var result = doc.releaseId(firstId);
ok(result);
equals(doc.getNextId(), firstId);
equals(doc.getNextId(), "svg_3");
ok(!doc.releaseId("bad-id"));
ok(doc.releaseId(firstId));
ok(!doc.releaseId(firstId));
ok(!doc.releaseId("bad-id"));
ok(doc.releaseId(firstId));
ok(!doc.releaseId(firstId));
cleanupSvg(svg);
});
cleanupSvg(svg);
});
test('Test getNumLayers', function() {
expect(3);
var drawing = new svgedit.draw.Drawing(svg);
equals(typeof drawing.getNumLayers, typeof function() {});
equals(drawing.getNumLayers(), 0);
test('Test getNumLayers', function() {
expect(3);
var drawing = new svgedit.draw.Drawing(svg);
equals(typeof drawing.getNumLayers, typeof function() {});
equals(drawing.getNumLayers(), 0);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
setupSvgWith3Layers(svg);
drawing.identifyLayers();
equals(drawing.getNumLayers(), 3);
equals(drawing.getNumLayers(), 3);
cleanupSvg(svg);
});
cleanupSvg(svg);
});
test('Test hasLayer', function() {
expect(5);
test('Test hasLayer', function() {
expect(5);
setupSvgWith3Layers(svg);
var drawing = new svgedit.draw.Drawing(svg);
drawing.identifyLayers();
setupSvgWith3Layers(svg);
var drawing = new svgedit.draw.Drawing(svg);
drawing.identifyLayers();
equals(typeof drawing.hasLayer, typeof function() {});
ok(!drawing.hasLayer('invalid-layer'));
equals(typeof drawing.hasLayer, typeof function() {});
ok(!drawing.hasLayer('invalid-layer'));
ok(drawing.hasLayer(LAYER3));
ok(drawing.hasLayer(LAYER2));
ok(drawing.hasLayer(LAYER1));
ok(drawing.hasLayer(LAYER3));
ok(drawing.hasLayer(LAYER2));
ok(drawing.hasLayer(LAYER1));
cleanupSvg(svg);
});
cleanupSvg(svg);
});
test('Test identifyLayers() with empty document', function() {
expect(9);
test('Test identifyLayers() with empty document', function() {
expect(9);
var drawing = new svgedit.draw.Drawing(svg);
// By default, an empty document gets an empty group created.
drawing.identifyLayers();
var drawing = new svgedit.draw.Drawing(svg);
// By default, an empty document gets an empty group created.
drawing.identifyLayers();
// Check that <svg> element now has one child node
ok(drawing.getSvgElem().hasChildNodes());
equals(drawing.getSvgElem().childNodes.length, 1);
// Check that <svg> element now has one child node
ok(drawing.getSvgElem().hasChildNodes());
equals(drawing.getSvgElem().childNodes.length, 1);
// Check that all_layers is correctly set up.
equals(drawing.getNumLayers(), 1);
var empty_layer = drawing.all_layers[0][1];
ok(empty_layer);
equals(empty_layer, drawing.getSvgElem().firstChild);
equals(empty_layer.tagName, 'g');
ok(empty_layer.hasChildNodes());
equals(empty_layer.childNodes.length, 1);
var firstChild = empty_layer.childNodes.item(0);
equals(firstChild.tagName, 'title');
// Check that all_layers is correctly set up.
equals(drawing.getNumLayers(), 1);
var empty_layer = drawing.all_layers[0][1];
ok(empty_layer);
equals(empty_layer, drawing.getSvgElem().firstChild);
equals(empty_layer.tagName, 'g');
ok(empty_layer.hasChildNodes());
equals(empty_layer.childNodes.length, 1);
var firstChild = empty_layer.childNodes.item(0);
equals(firstChild.tagName, 'title');
cleanupSvg(svg);
});
cleanupSvg(svg);
});
test('Test identifyLayers() with some layers', function() {
expect(5);
test('Test identifyLayers() with some layers', function() {
expect(5);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
equals(svg.childNodes.length, 3);
equals(svg.childNodes.length, 3);
drawing.identifyLayers();
drawing.identifyLayers();
equals(drawing.getNumLayers(), 3);
equals(drawing.all_layers[0][1], svg.childNodes.item(0));
equals(drawing.all_layers[1][1], svg.childNodes.item(1));
equals(drawing.all_layers[2][1], svg.childNodes.item(2));
equals(drawing.getNumLayers(), 3);
equals(drawing.all_layers[0][1], svg.childNodes.item(0));
equals(drawing.all_layers[1][1], svg.childNodes.item(1));
equals(drawing.all_layers[2][1], svg.childNodes.item(2));
cleanupSvg(svg);
});
cleanupSvg(svg);
});
test('Test identifyLayers() with some layers and orphans', function() {
expect(10);
test('Test identifyLayers() with some layers and orphans', function() {
expect(10);
setupSvgWith3Layers(svg);
setupSvgWith3Layers(svg);
var orphan1 = document.createElementNS(NS.SVG, 'rect');
var orphan2 = document.createElementNS(NS.SVG, 'rect');
svg.appendChild(orphan1);
svg.appendChild(orphan2);
var orphan1 = document.createElementNS(NS.SVG, 'rect');
var orphan2 = document.createElementNS(NS.SVG, 'rect');
svg.appendChild(orphan1);
svg.appendChild(orphan2);
equals(svg.childNodes.length, 5);
equals(svg.childNodes.length, 5);
var drawing = new svgedit.draw.Drawing(svg);
drawing.identifyLayers();
var drawing = new svgedit.draw.Drawing(svg);
drawing.identifyLayers();
equals(drawing.getNumLayers(), 4);
equals(drawing.all_layers[0][1], svg.childNodes.item(0));
equals(drawing.all_layers[1][1], svg.childNodes.item(1));
equals(drawing.all_layers[2][1], svg.childNodes.item(2));
equals(drawing.all_layers[3][1], svg.childNodes.item(3));
equals(drawing.getNumLayers(), 4);
equals(drawing.all_layers[0][1], svg.childNodes.item(0));
equals(drawing.all_layers[1][1], svg.childNodes.item(1));
equals(drawing.all_layers[2][1], svg.childNodes.item(2));
equals(drawing.all_layers[3][1], svg.childNodes.item(3));
var layer4 = drawing.all_layers[3][1];
equals(layer4.tagName, 'g');
equals(layer4.childNodes.length, 3);
equals(layer4.childNodes.item(1), orphan1);
equals(layer4.childNodes.item(2), orphan2);
var layer4 = drawing.all_layers[3][1];
equals(layer4.tagName, 'g');
equals(layer4.childNodes.length, 3);
equals(layer4.childNodes.item(1), orphan1);
equals(layer4.childNodes.item(2), orphan2);
cleanupSvg(svg);
});
cleanupSvg(svg);
});
test('Test getLayerName()', function() {
expect(4);
test('Test getLayerName()', function() {
expect(4);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
drawing.identifyLayers();
equals(drawing.getNumLayers(), 3);
equals(drawing.getLayerName(0), LAYER1);
equals(drawing.getLayerName(1), LAYER2);
equals(drawing.getLayerName(2), LAYER3);
equals(drawing.getNumLayers(), 3);
equals(drawing.getLayerName(0), LAYER1);
equals(drawing.getLayerName(1), LAYER2);
equals(drawing.getLayerName(2), LAYER3);
cleanupSvg(svg);
});
cleanupSvg(svg);
});
test('Test getCurrentLayer()', function() {
expect(4);
test('Test getCurrentLayer()', function() {
expect(4);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.getCurrentLayer);
equals(typeof drawing.getCurrentLayer, typeof function(){});
ok(drawing.getCurrentLayer());
equals(drawing.getCurrentLayer(), drawing.all_layers[2][1]);
});
ok(drawing.getCurrentLayer);
equals(typeof drawing.getCurrentLayer, typeof function(){});
ok(drawing.getCurrentLayer());
equals(drawing.getCurrentLayer(), drawing.all_layers[2][1]);
});
test('Test setCurrentLayer() and getCurrentLayerName()', function() {
expect(6);
test('Test setCurrentLayer() and getCurrentLayerName()', function() {
expect(6);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.setCurrentLayer);
equals(typeof drawing.setCurrentLayer, typeof function(){});
ok(drawing.setCurrentLayer);
equals(typeof drawing.setCurrentLayer, typeof function(){});
drawing.setCurrentLayer(LAYER2);
equals(drawing.getCurrentLayerName(LAYER2), LAYER2);
equals(drawing.getCurrentLayer(), drawing.all_layers[1][1]);
drawing.setCurrentLayer(LAYER2);
equals(drawing.getCurrentLayerName(LAYER2), LAYER2);
equals(drawing.getCurrentLayer(), drawing.all_layers[1][1]);
drawing.setCurrentLayer(LAYER3);
equals(drawing.getCurrentLayerName(LAYER3), LAYER3);
equals(drawing.getCurrentLayer(), drawing.all_layers[2][1]);
drawing.setCurrentLayer(LAYER3);
equals(drawing.getCurrentLayerName(LAYER3), LAYER3);
equals(drawing.getCurrentLayer(), drawing.all_layers[2][1]);
cleanupSvg(svg);
});
cleanupSvg(svg);
});
test('Test createLayer()', function() {
expect(6);
test('Test createLayer()', function() {
expect(6);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.createLayer);
equals(typeof drawing.createLayer, typeof function(){});
ok(drawing.createLayer);
equals(typeof drawing.createLayer, typeof function(){});
var NEW_LAYER_NAME = 'Layer A';
var layer_g = drawing.createLayer(NEW_LAYER_NAME);
equals(4, drawing.getNumLayers());
equals(layer_g, drawing.getCurrentLayer());
equals(NEW_LAYER_NAME, drawing.getCurrentLayerName());
equals(NEW_LAYER_NAME, drawing.getLayerName(3));
var NEW_LAYER_NAME = 'Layer A';
var layer_g = drawing.createLayer(NEW_LAYER_NAME);
equals(4, drawing.getNumLayers());
equals(layer_g, drawing.getCurrentLayer());
equals(NEW_LAYER_NAME, drawing.getCurrentLayerName());
equals(NEW_LAYER_NAME, drawing.getLayerName(3));
cleanupSvg(svg);
});
cleanupSvg(svg);
});
test('Test getLayerVisibility()', function() {
expect(5);
test('Test getLayerVisibility()', function() {
expect(5);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.getLayerVisibility);
equals(typeof drawing.getLayerVisibility, typeof function(){});
ok(drawing.getLayerVisibility(LAYER1));
ok(drawing.getLayerVisibility(LAYER2));
ok(drawing.getLayerVisibility(LAYER3));
ok(drawing.getLayerVisibility);
equals(typeof drawing.getLayerVisibility, typeof function(){});
ok(drawing.getLayerVisibility(LAYER1));
ok(drawing.getLayerVisibility(LAYER2));
ok(drawing.getLayerVisibility(LAYER3));
cleanupSvg(svg);
});
cleanupSvg(svg);
});
test('Test setLayerVisibility()', function() {
expect(6);
test('Test setLayerVisibility()', function() {
expect(6);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.setLayerVisibility);
equals(typeof drawing.setLayerVisibility, typeof function(){});
ok(drawing.setLayerVisibility);
equals(typeof drawing.setLayerVisibility, typeof function(){});
drawing.setLayerVisibility(LAYER3, false);
drawing.setLayerVisibility(LAYER2, true);
drawing.setLayerVisibility(LAYER1, false);
drawing.setLayerVisibility(LAYER3, false);
drawing.setLayerVisibility(LAYER2, true);
drawing.setLayerVisibility(LAYER1, false);
ok(!drawing.getLayerVisibility(LAYER1));
ok(drawing.getLayerVisibility(LAYER2));
ok(!drawing.getLayerVisibility(LAYER3));
ok(!drawing.getLayerVisibility(LAYER1));
ok(drawing.getLayerVisibility(LAYER2));
ok(!drawing.getLayerVisibility(LAYER3));
drawing.setLayerVisibility(LAYER3, 'test-string');
ok(!drawing.getLayerVisibility(LAYER3));
drawing.setLayerVisibility(LAYER3, 'test-string');
ok(!drawing.getLayerVisibility(LAYER3));
cleanupSvg(svg);
});
cleanupSvg(svg);
});
test('Test getLayerOpacity()', function() {
expect(5);
test('Test getLayerOpacity()', function() {
expect(5);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.getLayerOpacity);
equals(typeof drawing.getLayerOpacity, typeof function(){});
ok(drawing.getLayerOpacity(LAYER1) == 1.0);
ok(drawing.getLayerOpacity(LAYER2) == 1.0);
ok(drawing.getLayerOpacity(LAYER3) == 1.0);
ok(drawing.getLayerOpacity);
equals(typeof drawing.getLayerOpacity, typeof function(){});
ok(drawing.getLayerOpacity(LAYER1) == 1.0);
ok(drawing.getLayerOpacity(LAYER2) == 1.0);
ok(drawing.getLayerOpacity(LAYER3) == 1.0);
cleanupSvg(svg);
});
cleanupSvg(svg);
});
test('Test setLayerOpacity()', function() {
expect(6);
test('Test setLayerOpacity()', function() {
expect(6);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
ok(drawing.setLayerOpacity);
equals(typeof drawing.setLayerOpacity, typeof function(){});
ok(drawing.setLayerOpacity);
equals(typeof drawing.setLayerOpacity, typeof function(){});
drawing.setLayerOpacity(LAYER1, 0.4);
drawing.setLayerOpacity(LAYER2, 'invalid-string');
drawing.setLayerOpacity(LAYER3, -1.4);
drawing.setLayerOpacity(LAYER1, 0.4);
drawing.setLayerOpacity(LAYER2, 'invalid-string');
drawing.setLayerOpacity(LAYER3, -1.4);
ok(drawing.getLayerOpacity(LAYER1) == 0.4);
QUnit.log('layer2 opacity', drawing.getLayerOpacity(LAYER2));
ok(drawing.getLayerOpacity(LAYER2) == 1.0);
ok(drawing.getLayerOpacity(LAYER3) == 1.0);
ok(drawing.getLayerOpacity(LAYER1) == 0.4);
QUnit.log('layer2 opacity', drawing.getLayerOpacity(LAYER2));
ok(drawing.getLayerOpacity(LAYER2) == 1.0);
ok(drawing.getLayerOpacity(LAYER3) == 1.0);
drawing.setLayerOpacity(LAYER3, 100);
ok(drawing.getLayerOpacity(LAYER3) == 1.0);
drawing.setLayerOpacity(LAYER3, 100);
ok(drawing.getLayerOpacity(LAYER3) == 1.0);
cleanupSvg(svg);
});
cleanupSvg(svg);
});
test('Test deleteCurrentLayer()', function() {
expect(6);
test('Test deleteCurrentLayer()', function() {
expect(6);
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
var drawing = new svgedit.draw.Drawing(svg);
setupSvgWith3Layers(svg);
drawing.identifyLayers();
drawing.setCurrentLayer(LAYER2);
drawing.setCurrentLayer(LAYER2);
var curLayer = drawing.getCurrentLayer();
equals(curLayer, drawing.all_layers[1][1]);
var deletedLayer = drawing.deleteCurrentLayer();
var curLayer = drawing.getCurrentLayer();
equals(curLayer, drawing.all_layers[1][1]);
var deletedLayer = drawing.deleteCurrentLayer();
equals(curLayer, deletedLayer);
equals(2, drawing.getNumLayers());
equals(LAYER1, drawing.all_layers[0][0]);
equals(LAYER3, drawing.all_layers[1][0]);
equals(drawing.getCurrentLayer(), drawing.all_layers[1][1]);
});
equals(curLayer, deletedLayer);
equals(2, drawing.getNumLayers());
equals(LAYER1, drawing.all_layers[0][0]);
equals(LAYER3, drawing.all_layers[1][0]);
equals(drawing.getCurrentLayer(), drawing.all_layers[1][1]);
});
test('Test svgedit.draw.randomizeIds()', function() {
expect(9);
test('Test svgedit.draw.randomizeIds()', function() {
expect(9);
// Confirm in LET_DOCUMENT_DECIDE mode that the document decides
// if there is a nonce.
var drawing = new svgedit.draw.Drawing(svg_n.cloneNode(true));
ok(!!drawing.getNonce());
// Confirm in LET_DOCUMENT_DECIDE mode that the document decides
// if there is a nonce.
var drawing = new svgedit.draw.Drawing(svg_n.cloneNode(true));
ok(!!drawing.getNonce());
drawing = new svgedit.draw.Drawing(svg.cloneNode(true));
ok(!drawing.getNonce());
drawing = new svgedit.draw.Drawing(svg.cloneNode(true));
ok(!drawing.getNonce());
// Confirm that a nonce is set once we're in ALWAYS_RANDOMIZE mode.
svgedit.draw.randomizeIds(true, drawing);
ok(!!drawing.getNonce());
// Confirm that a nonce is set once we're in ALWAYS_RANDOMIZE mode.
svgedit.draw.randomizeIds(true, drawing);
ok(!!drawing.getNonce());
// Confirm new drawings in ALWAYS_RANDOMIZE mode have a nonce.
drawing = new svgedit.draw.Drawing(svg.cloneNode(true));
ok(!!drawing.getNonce());
// Confirm new drawings in ALWAYS_RANDOMIZE mode have a nonce.
drawing = new svgedit.draw.Drawing(svg.cloneNode(true));
ok(!!drawing.getNonce());
drawing.clearNonce();
ok(!drawing.getNonce());
drawing.clearNonce();
ok(!drawing.getNonce());
// Confirm new drawings in NEVER_RANDOMIZE mode do not have a nonce
// but that their se:nonce attribute is left alone.
svgedit.draw.randomizeIds(false, drawing);
ok(!drawing.getNonce());
ok(!!drawing.getSvgElem().getAttributeNS(NS.SE, 'nonce'));
// Confirm new drawings in NEVER_RANDOMIZE mode do not have a nonce
// but that their se:nonce attribute is left alone.
svgedit.draw.randomizeIds(false, drawing);
ok(!drawing.getNonce());
ok(!!drawing.getSvgElem().getAttributeNS(NS.SE, 'nonce'));
drawing = new svgedit.draw.Drawing(svg.cloneNode(true));
ok(!drawing.getNonce());
drawing = new svgedit.draw.Drawing(svg.cloneNode(true));
ok(!drawing.getNonce());
drawing = new svgedit.draw.Drawing(svg_n.cloneNode(true));
ok(!drawing.getNonce());
});
drawing = new svgedit.draw.Drawing(svg_n.cloneNode(true));
ok(!drawing.getNonce());
});
});
</script>
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for draw.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='anchor' style='visibility:hidden'>
</div>
<h1 id='qunit-header'>Unit Tests for draw.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'></ol>
<div id='anchor' style='visibility:hidden'></div>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -1,138 +1,138 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script src='../editor/math.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
<title>Unit Tests for math.js</title>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script src='../editor/math.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
var svg = document.createElementNS(svgedit.NS.SVG, 'svg');
var svg = document.createElementNS(svgedit.NS.SVG, 'svg');
module('svgedit.math');
module('svgedit.math');
test('Test svgedit.math package', function() {
expect(7);
test('Test svgedit.math package', function() {
expect(7);
ok(svgedit.math);
ok(svgedit.math.transformPoint);
ok(svgedit.math.isIdentity);
ok(svgedit.math.matrixMultiply);
equals(typeof svgedit.math.transformPoint, typeof function(){});
equals(typeof svgedit.math.isIdentity, typeof function(){});
equals(typeof svgedit.math.matrixMultiply, typeof function(){});
});
ok(svgedit.math);
ok(svgedit.math.transformPoint);
ok(svgedit.math.isIdentity);
ok(svgedit.math.matrixMultiply);
equals(typeof svgedit.math.transformPoint, typeof function(){});
equals(typeof svgedit.math.isIdentity, typeof function(){});
equals(typeof svgedit.math.matrixMultiply, typeof function(){});
});
test('Test svgedit.math.transformPoint() function', function() {
expect(6);
var transformPoint = svgedit.math.transformPoint;
test('Test svgedit.math.transformPoint() function', function() {
expect(6);
var transformPoint = svgedit.math.transformPoint;
var m = svg.createSVGMatrix();
m.a = 1; m.b = 0;
m.c = 0; m.d = 1;
m.e = 0; m.f = 0;
var pt = transformPoint(100, 200, m);
equals(pt.x, 100);
equals(pt.y, 200);
var m = svg.createSVGMatrix();
m.a = 1; m.b = 0;
m.c = 0; m.d = 1;
m.e = 0; m.f = 0;
var pt = transformPoint(100, 200, m);
equals(pt.x, 100);
equals(pt.y, 200);
m.e = 300; m.f = 400;
pt = transformPoint(100, 200, m);
equals(pt.x, 400);
equals(pt.y, 600);
m.e = 300; m.f = 400;
pt = transformPoint(100, 200, m);
equals(pt.x, 400);
equals(pt.y, 600);
m.a = 0.5; m.b = 0.75;
m.c = 1.25; m.d = 2;
pt = transformPoint(100, 200, m);
equals(pt.x, 100 * m.a + 200 * m.c + m.e);
equals(pt.y, 100 * m.b + 200 * m.d + m.f);
});
m.a = 0.5; m.b = 0.75;
m.c = 1.25; m.d = 2;
pt = transformPoint(100, 200, m);
equals(pt.x, 100 * m.a + 200 * m.c + m.e);
equals(pt.y, 100 * m.b + 200 * m.d + m.f);
});
test('Test svgedit.math.isIdentity() function', function() {
expect(2);
test('Test svgedit.math.isIdentity() function', function() {
expect(2);
ok(svgedit.math.isIdentity(svg.createSVGMatrix()));
ok(svgedit.math.isIdentity(svg.createSVGMatrix()));
var m = svg.createSVGMatrix();
m.a = 1; m.b = 0;
m.c = 0; m.d = 1;
m.e = 0; m.f = 0;
ok(svgedit.math.isIdentity(m));
});
var m = svg.createSVGMatrix();
m.a = 1; m.b = 0;
m.c = 0; m.d = 1;
m.e = 0; m.f = 0;
ok(svgedit.math.isIdentity(m));
});
test('Test svgedit.math.matrixMultiply() function', function() {
expect(5);
var mult = svgedit.math.matrixMultiply;
var isIdentity = svgedit.math.isIdentity;
test('Test svgedit.math.matrixMultiply() function', function() {
expect(5);
var mult = svgedit.math.matrixMultiply;
var isIdentity = svgedit.math.isIdentity;
// translate there and back
var tr_1 = svg.createSVGMatrix().translate(100,50),
tr_2 = svg.createSVGMatrix().translate(-90,0),
tr_3 = svg.createSVGMatrix().translate(-10,-50),
I = mult(tr_1,tr_2,tr_3);
ok(isIdentity(I), 'Expected identity matrix when translating there and back');
// translate there and back
var tr_1 = svg.createSVGMatrix().translate(100,50),
tr_2 = svg.createSVGMatrix().translate(-90,0),
tr_3 = svg.createSVGMatrix().translate(-10,-50),
I = mult(tr_1,tr_2,tr_3);
ok(isIdentity(I), 'Expected identity matrix when translating there and back');
// rotate there and back
// TODO: currently Mozilla fails this when rotating back at -50 and then -40 degrees
// (b and c are *almost* zero, but not zero)
var rot_there = svg.createSVGMatrix().rotate(90),
rot_back = svg.createSVGMatrix().rotate(-90); // TODO: set this to -50
rot_back_more = svg.createSVGMatrix().rotate(0); // TODO: set this to -40
I = mult(rot_there, rot_back, rot_back_more);
ok(isIdentity(I), 'Expected identity matrix when rotating there and back');
// rotate there and back
// TODO: currently Mozilla fails this when rotating back at -50 and then -40 degrees
// (b and c are *almost* zero, but not zero)
var rot_there = svg.createSVGMatrix().rotate(90),
rot_back = svg.createSVGMatrix().rotate(-90); // TODO: set this to -50
rot_back_more = svg.createSVGMatrix().rotate(0); // TODO: set this to -40
I = mult(rot_there, rot_back, rot_back_more);
ok(isIdentity(I), 'Expected identity matrix when rotating there and back');
// scale up and down
var scale_up = svg.createSVGMatrix().scale(4),
scale_down = svg.createSVGMatrix().scaleNonUniform(0.25,1);
scale_down_more = svg.createSVGMatrix().scaleNonUniform(1,0.25);
I = mult(scale_up, scale_down, scale_down_more);
ok(isIdentity(I), 'Expected identity matrix when scaling up and down');
// scale up and down
var scale_up = svg.createSVGMatrix().scale(4),
scale_down = svg.createSVGMatrix().scaleNonUniform(0.25,1);
scale_down_more = svg.createSVGMatrix().scaleNonUniform(1,0.25);
I = mult(scale_up, scale_down, scale_down_more);
ok(isIdentity(I), 'Expected identity matrix when scaling up and down');
// test multiplication with its inverse
I = mult(rot_there, rot_there.inverse());
ok(isIdentity(I), 'Expected identity matrix when multiplying a matrix by its inverse');
I = mult(rot_there.inverse(), rot_there);
ok(isIdentity(I), 'Expected identity matrix when multiplying a matrix by its inverse');
});
// test multiplication with its inverse
I = mult(rot_there, rot_there.inverse());
ok(isIdentity(I), 'Expected identity matrix when multiplying a matrix by its inverse');
I = mult(rot_there.inverse(), rot_there);
ok(isIdentity(I), 'Expected identity matrix when multiplying a matrix by its inverse');
});
test('Test svgedit.math.transformBox() function', function() {
expect(12);
var transformBox = svgedit.math.transformBox;
test('Test svgedit.math.transformBox() function', function() {
expect(12);
var transformBox = svgedit.math.transformBox;
var m = svg.createSVGMatrix();
m.a = 1; m.b = 0;
m.c = 0; m.d = 1;
m.e = 0; m.f = 0;
var m = svg.createSVGMatrix();
m.a = 1; m.b = 0;
m.c = 0; m.d = 1;
m.e = 0; m.f = 0;
var r = transformBox(10, 10, 200, 300, m);
equals(r.tl.x, 10);
equals(r.tl.y, 10);
equals(r.tr.x, 210);
equals(r.tr.y, 10);
equals(r.bl.x, 10);
equals(r.bl.y, 310);
equals(r.br.x, 210);
equals(r.br.y, 310);
equals(r.aabox.x, 10);
equals(r.aabox.y, 10);
equals(r.aabox.width, 200);
equals(r.aabox.height, 300);
});
});
</script>
var r = transformBox(10, 10, 200, 300, m);
equals(r.tl.x, 10);
equals(r.tl.y, 10);
equals(r.tr.x, 210);
equals(r.tr.y, 10);
equals(r.bl.x, 10);
equals(r.bl.y, 310);
equals(r.br.x, 210);
equals(r.br.y, 310);
equals(r.aabox.x, 10);
equals(r.aabox.y, 10);
equals(r.aabox.width, 200);
equals(r.aabox.height, 300);
});
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for math.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<h1 id='qunit-header'>Unit Tests for math.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'></ol>
</body>
</html>

View File

@ -1,28 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/path.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
});
</script>
<title>Unit Tests for path.js</title>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/path.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for path.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='anchor' style='visibility:hidden'>
</div>
<ol id='qunit-tests'></ol>
<div id='anchor' style='visibility:hidden'></div>
</body>
</html>

View File

@ -1,16 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script src='../editor/browser.js'></script>
<script src='../editor/svgutils.js'></script>
<script src='../editor/sanitize.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
<title>Unit Tests for sanitize.js</title>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script src='../editor/browser.js'></script>
<script src='../editor/svgutils.js'></script>
<script src='../editor/sanitize.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
@ -39,9 +40,7 @@ $(function() {
<h1 id='qunit-header'>Unit Tests for sanitize.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='anchor' style='visibility:hidden'>
</div>
<ol id='qunit-tests'></ol>
<div id='anchor' style='visibility:hidden'></div>
</body>
</html>

View File

@ -1,152 +1,152 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script src='../editor/browser.js'></script>
<script src='../editor/math.js'></script>
<script src='../editor/svgutils.js'></script>
<script src='../editor/select.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
<title>Unit Tests for select.js</title>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script src='../editor/browser.js'></script>
<script src='../editor/math.js'></script>
<script src='../editor/svgutils.js'></script>
<script src='../editor/select.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
module('svgedit.select');
module('svgedit.select');
var sandbox = document.getElementById('sandbox');
var svgroot;
var svgcontent;
var rect;
var mockConfig = {
dimensions: [640,480]
};
var mockFactory = {
createSVGElement: function(jsonMap) {
var elem = document.createElementNS(svgedit.NS.SVG, jsonMap['element']);
for (var attr in jsonMap['attr']) {
elem.setAttribute(attr, jsonMap['attr'][attr]);
}
return elem;
},
svgRoot: function() { return svgroot; },
svgContent: function() { return svgcontent; }
};
var sandbox = document.getElementById('sandbox');
var svgroot;
var svgcontent;
var rect;
var mockConfig = {
dimensions: [640,480]
};
var mockFactory = {
createSVGElement: function(jsonMap) {
var elem = document.createElementNS(svgedit.NS.SVG, jsonMap['element']);
for (var attr in jsonMap['attr']) {
elem.setAttribute(attr, jsonMap['attr'][attr]);
}
return elem;
},
svgRoot: function() { return svgroot; },
svgContent: function() { return svgcontent; }
};
function setUp() {
svgroot = mockFactory.createSVGElement({
'element': 'svg',
'attr': {'id': 'svgroot'}
});
svgcontent = svgroot.appendChild(
mockFactory.createSVGElement({
'element': 'svg',
'attr': {'id': 'svgcontent'}
})
);
rect = svgcontent.appendChild(
mockFactory.createSVGElement({
'element': 'rect',
'attr': {
'id': 'rect',
'x': '50',
'y': '75',
'width': '200',
'height': '100'
}
})
);
sandbox.appendChild(svgroot);
}
function setUp() {
svgroot = mockFactory.createSVGElement({
'element': 'svg',
'attr': {'id': 'svgroot'}
});
svgcontent = svgroot.appendChild(
mockFactory.createSVGElement({
'element': 'svg',
'attr': {'id': 'svgcontent'}
})
);
rect = svgcontent.appendChild(
mockFactory.createSVGElement({
'element': 'rect',
'attr': {
'id': 'rect',
'x': '50',
'y': '75',
'width': '200',
'height': '100'
}
})
);
sandbox.appendChild(svgroot);
}
function setUpWithInit() {
setUp();
svgedit.select.init(mockConfig, mockFactory);
}
function tearDown() {
while (sandbox.hasChildNodes()) {
sandbox.removeChild(sandbox.firstChild);
}
}
function setUpWithInit() {
setUp();
svgedit.select.init(mockConfig, mockFactory);
}
function tearDown() {
while (sandbox.hasChildNodes()) {
sandbox.removeChild(sandbox.firstChild);
}
}
test('Test svgedit.select package', function() {
expect(10);
test('Test svgedit.select package', function() {
expect(10);
ok(svgedit.select);
ok(svgedit.select.Selector);
ok(svgedit.select.SelectorManager);
ok(svgedit.select.init);
ok(svgedit.select.getSelectorManager);
equals(typeof svgedit.select, typeof {});
equals(typeof svgedit.select.Selector, typeof function(){});
equals(typeof svgedit.select.SelectorManager, typeof function(){});
equals(typeof svgedit.select.init, typeof function(){});
equals(typeof svgedit.select.getSelectorManager, typeof function(){});
});
test('Test Selector DOM structure', function() {
expect(24);
ok(svgedit.select);
ok(svgedit.select.Selector);
ok(svgedit.select.SelectorManager);
ok(svgedit.select.init);
ok(svgedit.select.getSelectorManager);
equals(typeof svgedit.select, typeof {});
equals(typeof svgedit.select.Selector, typeof function(){});
equals(typeof svgedit.select.SelectorManager, typeof function(){});
equals(typeof svgedit.select.init, typeof function(){});
equals(typeof svgedit.select.getSelectorManager, typeof function(){});
});
test('Test Selector DOM structure', function() {
expect(24);
setUp();
setUp();
ok(svgroot);
ok(svgroot.hasChildNodes());
ok(svgroot);
ok(svgroot.hasChildNodes());
// Verify non-existence of Selector DOM nodes
equals(svgroot.childNodes.length, 1);
equals(svgroot.childNodes.item(0), svgcontent);
ok(!svgroot.querySelector('#selectorParentGroup'));
// Verify non-existence of Selector DOM nodes
equals(svgroot.childNodes.length, 1);
equals(svgroot.childNodes.item(0), svgcontent);
ok(!svgroot.querySelector('#selectorParentGroup'));
svgedit.select.init(mockConfig, mockFactory);
svgedit.select.init(mockConfig, mockFactory);
equals(svgroot.childNodes.length, 3);
equals(svgroot.childNodes.length, 3);
// Verify existence of canvas background.
var cb = svgroot.childNodes.item(0);
ok(cb);
equals(cb.id, 'canvasBackground');
// Verify existence of canvas background.
var cb = svgroot.childNodes.item(0);
ok(cb);
equals(cb.id, 'canvasBackground');
ok(svgroot.childNodes.item(1));
equals(svgroot.childNodes.item(1), svgcontent);
ok(svgroot.childNodes.item(1));
equals(svgroot.childNodes.item(1), svgcontent);
// Verify existence of selectorParentGroup.
var spg = svgroot.childNodes.item(2);
ok(spg);
equals(svgroot.querySelector('#selectorParentGroup'), spg);
equals(spg.id, 'selectorParentGroup');
equals(spg.tagName, 'g');
// Verify existence of selectorParentGroup.
var spg = svgroot.childNodes.item(2);
ok(spg);
equals(svgroot.querySelector('#selectorParentGroup'), spg);
equals(spg.id, 'selectorParentGroup');
equals(spg.tagName, 'g');
// Verify existence of all grip elements.
ok(spg.querySelector('#selectorGrip_resize_nw'));
ok(spg.querySelector('#selectorGrip_resize_n'));
ok(spg.querySelector('#selectorGrip_resize_ne'));
ok(spg.querySelector('#selectorGrip_resize_e'));
ok(spg.querySelector('#selectorGrip_resize_se'));
ok(spg.querySelector('#selectorGrip_resize_s'));
ok(spg.querySelector('#selectorGrip_resize_sw'));
ok(spg.querySelector('#selectorGrip_resize_w'));
ok(spg.querySelector('#selectorGrip_rotateconnector'));
ok(spg.querySelector('#selectorGrip_rotate'));
// Verify existence of all grip elements.
ok(spg.querySelector('#selectorGrip_resize_nw'));
ok(spg.querySelector('#selectorGrip_resize_n'));
ok(spg.querySelector('#selectorGrip_resize_ne'));
ok(spg.querySelector('#selectorGrip_resize_e'));
ok(spg.querySelector('#selectorGrip_resize_se'));
ok(spg.querySelector('#selectorGrip_resize_s'));
ok(spg.querySelector('#selectorGrip_resize_sw'));
ok(spg.querySelector('#selectorGrip_resize_w'));
ok(spg.querySelector('#selectorGrip_rotateconnector'));
ok(spg.querySelector('#selectorGrip_rotate'));
tearDown();
});
tearDown();
});
});
</script>
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for select.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='sandbox'></div>
<h1 id='qunit-header'>Unit Tests for select.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'></ol>
<div id='sandbox'></div>
</body>
</html>

View File

@ -1,415 +1,415 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script>
// Mock for browser.js
svgedit.browser = {};
svgedit.browser.supportsNativeTransformLists = function() { return false;}
</script>
<script src='../editor/svgtransformlist.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
var NS = svgedit.NS;
var svgroot = document.getElementById('svgroot');
var svgcontent, rect, circle;
var NEAR_ZERO = 5e-6; // 0.000005, Firefox fails at higher levels of precision.
function almostEquals(a, b, msg) {
msg = msg || (a + ' did not equal ' + b);
ok(Math.abs(a - b) < NEAR_ZERO, msg);
}
function checkOutOfBoundsException(obj, fn, arg1) {
var caughtException = false;
try {
obj[fn](arg1);
}
catch(e) {
if (e.code == 1) {
caughtException = true;
}
}
ok(caughtException, 'Caugh an INDEX_SIZE_ERR exception');
}
function setUp() {
svgcontent = svgroot.appendChild(document.createElementNS(NS.SVG, 'svg'));
rect = svgcontent.appendChild(document.createElementNS(NS.SVG, 'rect'));
rect.id = 'r';
circle = svgcontent.appendChild(document.createElementNS(NS.SVG, 'circle'));
circle.id = 'c';
}
function tearDown() {
svgedit.transformlist.resetListMap();
while (svgroot.hasChildNodes()) {
svgroot.removeChild(svgroot.firstChild);
}
}
module('svgedit.svgtransformlist');
test('Test svgedit.transformlist package', function() {
expect(2);
ok(svgedit.transformlist);
ok(svgedit.transformlist.getTransformList);
});
test('Test svgedit.transformlist.getTransformList() function', function() {
expect(4);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var cxform = svgedit.transformlist.getTransformList(circle);
ok(rxform);
ok(cxform);
equals(typeof rxform, typeof {});
equals(typeof cxform, typeof {});
tearDown();
});
test('Test SVGTransformList.numberOfItems property', function() {
expect(2);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
equals(typeof rxform.numberOfItems, typeof 0);
equals(rxform.numberOfItems, 0);
tearDown();
});
test('Test SVGTransformList.initialize()', function() {
expect(6);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var cxform = svgedit.transformlist.getTransformList(circle);
var t = svgcontent.createSVGTransform();
ok(t);
ok(rxform.initialize);
equals(typeof rxform.initialize, typeof function(){});
rxform.initialize(t);
equals(rxform.numberOfItems, 1);
equals(cxform.numberOfItems, 0);
// If a transform was already in a transform list, this should
// remove it from its old list and add it to this list.
cxform.initialize(t);
// This also fails in Firefox native.
// equals(rxform.numberOfItems, 0, 'Did not remove transform from list before initializing another transformlist');
equals(cxform.numberOfItems, 1);
tearDown();
});
test('Test SVGTransformList.appendItem() and getItem()', function() {
expect(12);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var cxform = svgedit.transformlist.getTransformList(circle);
var t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform(),
t3 = svgcontent.createSVGTransform();
ok(rxform.appendItem);
ok(rxform.getItem);
equals(typeof rxform.appendItem, typeof function(){});
equals(typeof rxform.getItem, typeof function(){});
rxform.appendItem(t1);
rxform.appendItem(t2);
rxform.appendItem(t3);
equals(rxform.numberOfItems, 3);
var rxf = rxform.getItem(0);
equals(rxf, t1);
equals(rxform.getItem(1), t2);
equals(rxform.getItem(2), t3);
checkOutOfBoundsException(rxform, 'getItem', -1);
checkOutOfBoundsException(rxform, 'getItem', 3);
cxform.appendItem(t1);
// These also fail in Firefox native.
// equals(rxform.numberOfItems, 2, 'Did not remove a transform from a list before appending it to a new transformlist');
// equals(rxform.getItem(0), t2, 'Found the wrong transform in a transformlist');
// equals(rxform.getItem(1), t3, 'Found the wrong transform in a transformlist');
equals(cxform.numberOfItems, 1);
equals(cxform.getItem(0), t1);
tearDown();
});
test('Test SVGTransformList.removeItem()', function() {
expect(7);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform();
ok(rxform.removeItem);
equals(typeof rxform.removeItem, typeof function(){});
rxform.appendItem(t1);
rxform.appendItem(t2);
var removedTransform = rxform.removeItem(0);
equals(rxform.numberOfItems, 1);
equals(removedTransform, t1);
equals(rxform.getItem(0), t2);
checkOutOfBoundsException(rxform, 'removeItem', -1);
checkOutOfBoundsException(rxform, 'removeItem', 1);
tearDown();
});
test('Test SVGTransformList.replaceItem()', function() {
expect(8);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var cxform = svgedit.transformlist.getTransformList(circle);
ok(rxform.replaceItem);
equals(typeof rxform.replaceItem, typeof function(){});
var t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform(),
t3 = svgcontent.createSVGTransform();
rxform.appendItem(t1);
rxform.appendItem(t2);
cxform.appendItem(t3);
var newItem = rxform.replaceItem(t3, 0);
equals(rxform.numberOfItems, 2);
equals(newItem, t3);
equals(rxform.getItem(0), t3);
equals(rxform.getItem(1), t2);
// Fails in Firefox native
// equals(cxform.numberOfItems, 0);
// test replaceItem within a list
rxform.appendItem(t1);
rxform.replaceItem(t1, 0);
// Fails in Firefox native
// equals(rxform.numberOfItems, 2);
equals(rxform.getItem(0), t1);
equals(rxform.getItem(1), t2);
tearDown();
});
test('Test SVGTransformList.insertItemBefore()', function() {
expect(10);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var cxform = svgedit.transformlist.getTransformList(circle);
ok(rxform.insertItemBefore);
equals(typeof rxform.insertItemBefore, typeof function(){});
var t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform(),
t3 = svgcontent.createSVGTransform();
rxform.appendItem(t1);
rxform.appendItem(t2);
cxform.appendItem(t3);
var newItem = rxform.insertItemBefore(t3, 0);
equals(rxform.numberOfItems, 3);
equals(newItem, t3);
equals(rxform.getItem(0), t3);
equals(rxform.getItem(1), t1);
equals(rxform.getItem(2), t2);
// Fails in Firefox native
// equals(cxform.numberOfItems, 0);
rxform.insertItemBefore(t2, 1);
// Fails in Firefox native (they make copies of the transforms)
// equals(rxform.numberOfItems, 3);
equals(rxform.getItem(0), t3);
equals(rxform.getItem(1), t2);
equals(rxform.getItem(2), t1);
tearDown();
});
test('Test SVGTransformList.init() for translate(200,100)', function() {
expect(8);
setUp();
rect.setAttribute('transform', 'translate(200,100)');
var rxform = svgedit.transformlist.getTransformList(rect);
equals(1, rxform.numberOfItems);
var translate = rxform.getItem(0);
equals(translate.type, 2);
var m = translate.matrix;
equals(m.a, 1);
equals(m.b, 0);
equals(m.c, 0);
equals(m.d, 1);
equals(m.e, 200);
equals(m.f, 100);
tearDown();
});
test('Test SVGTransformList.init() for scale(4)', function() {
expect(8);
setUp();
rect.setAttribute('transform', 'scale(4)');
var rxform = svgedit.transformlist.getTransformList(rect);
equals(1, rxform.numberOfItems);
var scale = rxform.getItem(0);
equals(3, scale.type);
var m = scale.matrix;
equals(m.a, 4);
equals(m.b, 0);
equals(m.c, 0);
equals(m.d, 4);
equals(m.e, 0);
equals(m.f, 0);
tearDown();
});
test('Test SVGTransformList.init() for scale(4,3)', function() {
expect(8);
setUp();
rect.setAttribute('transform', 'scale(4,3)');
var rxform = svgedit.transformlist.getTransformList(rect);
equals(1, rxform.numberOfItems);
var scale = rxform.getItem(0);
equals(3, scale.type);
var m = scale.matrix;
equals(m.a, 4);
equals(m.b, 0);
equals(m.c, 0);
equals(m.d, 3);
equals(m.e, 0);
equals(m.f, 0);
tearDown();
});
test('Test SVGTransformList.init() for rotate(45)', function() {
expect(9);
setUp();
rect.setAttribute('transform', 'rotate(45)');
var rxform = svgedit.transformlist.getTransformList(rect);
equals(1, rxform.numberOfItems);
var rotate = rxform.getItem(0);
equals(4, rotate.type);
equals(45, rotate.angle);
var m = rotate.matrix;
almostEquals(m.a, 1/Math.sqrt(2));
almostEquals(m.b, 1/Math.sqrt(2));
almostEquals(m.c, -1/Math.sqrt(2));
almostEquals(m.d, 1/Math.sqrt(2));
equals(m.e, 0);
equals(m.f, 0);
tearDown();
});
test('Test SVGTransformList.init() for rotate(45, 100, 200)', function() {
expect(9);
setUp();
rect.setAttribute('transform', 'rotate(45, 100, 200)');
var rxform = svgedit.transformlist.getTransformList(rect);
equals(1, rxform.numberOfItems);
var rotate = rxform.getItem(0);
equals(4, rotate.type);
equals(45, rotate.angle);
var m = rotate.matrix;
almostEquals(m.a, 1/Math.sqrt(2));
almostEquals(m.b, 1/Math.sqrt(2));
almostEquals(m.c, -1/Math.sqrt(2));
almostEquals(m.d, 1/Math.sqrt(2));
var r = svgcontent.createSVGMatrix();
r.a = 1/Math.sqrt(2); r.b = 1/Math.sqrt(2);
r.c = -1/Math.sqrt(2); r.d = 1/Math.sqrt(2);
var t = svgcontent.createSVGMatrix();
t.e = -100; t.f = -200;
var t_ = svgcontent.createSVGMatrix();
t_.e = 100; t_.f = 200;
var result = t_.multiply(r).multiply(t);
<title>Unit Tests for svgtransformlist.js</title>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script>
// Mock for browser.js
svgedit.browser = {};
svgedit.browser.supportsNativeTransformLists = function() { return false;}
</script>
<script src='../editor/svgtransformlist.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
var NS = svgedit.NS;
var svgroot = document.getElementById('svgroot');
var svgcontent, rect, circle;
var NEAR_ZERO = 5e-6; // 0.000005, Firefox fails at higher levels of precision.
function almostEquals(a, b, msg) {
msg = msg || (a + ' did not equal ' + b);
ok(Math.abs(a - b) < NEAR_ZERO, msg);
}
function checkOutOfBoundsException(obj, fn, arg1) {
var caughtException = false;
try {
obj[fn](arg1);
}
catch(e) {
if (e.code == 1) {
caughtException = true;
}
}
ok(caughtException, 'Caugh an INDEX_SIZE_ERR exception');
}
function setUp() {
svgcontent = svgroot.appendChild(document.createElementNS(NS.SVG, 'svg'));
rect = svgcontent.appendChild(document.createElementNS(NS.SVG, 'rect'));
rect.id = 'r';
circle = svgcontent.appendChild(document.createElementNS(NS.SVG, 'circle'));
circle.id = 'c';
}
function tearDown() {
svgedit.transformlist.resetListMap();
while (svgroot.hasChildNodes()) {
svgroot.removeChild(svgroot.firstChild);
}
}
module('svgedit.svgtransformlist');
test('Test svgedit.transformlist package', function() {
expect(2);
ok(svgedit.transformlist);
ok(svgedit.transformlist.getTransformList);
});
test('Test svgedit.transformlist.getTransformList() function', function() {
expect(4);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var cxform = svgedit.transformlist.getTransformList(circle);
ok(rxform);
ok(cxform);
equals(typeof rxform, typeof {});
equals(typeof cxform, typeof {});
tearDown();
});
test('Test SVGTransformList.numberOfItems property', function() {
expect(2);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
equals(typeof rxform.numberOfItems, typeof 0);
equals(rxform.numberOfItems, 0);
tearDown();
});
test('Test SVGTransformList.initialize()', function() {
expect(6);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var cxform = svgedit.transformlist.getTransformList(circle);
var t = svgcontent.createSVGTransform();
ok(t);
ok(rxform.initialize);
equals(typeof rxform.initialize, typeof function(){});
rxform.initialize(t);
equals(rxform.numberOfItems, 1);
equals(cxform.numberOfItems, 0);
// If a transform was already in a transform list, this should
// remove it from its old list and add it to this list.
cxform.initialize(t);
// This also fails in Firefox native.
// equals(rxform.numberOfItems, 0, 'Did not remove transform from list before initializing another transformlist');
equals(cxform.numberOfItems, 1);
tearDown();
});
test('Test SVGTransformList.appendItem() and getItem()', function() {
expect(12);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var cxform = svgedit.transformlist.getTransformList(circle);
var t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform(),
t3 = svgcontent.createSVGTransform();
ok(rxform.appendItem);
ok(rxform.getItem);
equals(typeof rxform.appendItem, typeof function(){});
equals(typeof rxform.getItem, typeof function(){});
rxform.appendItem(t1);
rxform.appendItem(t2);
rxform.appendItem(t3);
equals(rxform.numberOfItems, 3);
var rxf = rxform.getItem(0);
equals(rxf, t1);
equals(rxform.getItem(1), t2);
equals(rxform.getItem(2), t3);
checkOutOfBoundsException(rxform, 'getItem', -1);
checkOutOfBoundsException(rxform, 'getItem', 3);
cxform.appendItem(t1);
// These also fail in Firefox native.
// equals(rxform.numberOfItems, 2, 'Did not remove a transform from a list before appending it to a new transformlist');
// equals(rxform.getItem(0), t2, 'Found the wrong transform in a transformlist');
// equals(rxform.getItem(1), t3, 'Found the wrong transform in a transformlist');
equals(cxform.numberOfItems, 1);
equals(cxform.getItem(0), t1);
tearDown();
});
test('Test SVGTransformList.removeItem()', function() {
expect(7);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform();
ok(rxform.removeItem);
equals(typeof rxform.removeItem, typeof function(){});
rxform.appendItem(t1);
rxform.appendItem(t2);
var removedTransform = rxform.removeItem(0);
equals(rxform.numberOfItems, 1);
equals(removedTransform, t1);
equals(rxform.getItem(0), t2);
checkOutOfBoundsException(rxform, 'removeItem', -1);
checkOutOfBoundsException(rxform, 'removeItem', 1);
tearDown();
});
test('Test SVGTransformList.replaceItem()', function() {
expect(8);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var cxform = svgedit.transformlist.getTransformList(circle);
ok(rxform.replaceItem);
equals(typeof rxform.replaceItem, typeof function(){});
var t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform(),
t3 = svgcontent.createSVGTransform();
rxform.appendItem(t1);
rxform.appendItem(t2);
cxform.appendItem(t3);
var newItem = rxform.replaceItem(t3, 0);
equals(rxform.numberOfItems, 2);
equals(newItem, t3);
equals(rxform.getItem(0), t3);
equals(rxform.getItem(1), t2);
// Fails in Firefox native
// equals(cxform.numberOfItems, 0);
// test replaceItem within a list
rxform.appendItem(t1);
rxform.replaceItem(t1, 0);
// Fails in Firefox native
// equals(rxform.numberOfItems, 2);
equals(rxform.getItem(0), t1);
equals(rxform.getItem(1), t2);
tearDown();
});
test('Test SVGTransformList.insertItemBefore()', function() {
expect(10);
setUp();
var rxform = svgedit.transformlist.getTransformList(rect);
var cxform = svgedit.transformlist.getTransformList(circle);
ok(rxform.insertItemBefore);
equals(typeof rxform.insertItemBefore, typeof function(){});
var t1 = svgcontent.createSVGTransform(),
t2 = svgcontent.createSVGTransform(),
t3 = svgcontent.createSVGTransform();
rxform.appendItem(t1);
rxform.appendItem(t2);
cxform.appendItem(t3);
var newItem = rxform.insertItemBefore(t3, 0);
equals(rxform.numberOfItems, 3);
equals(newItem, t3);
equals(rxform.getItem(0), t3);
equals(rxform.getItem(1), t1);
equals(rxform.getItem(2), t2);
// Fails in Firefox native
// equals(cxform.numberOfItems, 0);
rxform.insertItemBefore(t2, 1);
// Fails in Firefox native (they make copies of the transforms)
// equals(rxform.numberOfItems, 3);
equals(rxform.getItem(0), t3);
equals(rxform.getItem(1), t2);
equals(rxform.getItem(2), t1);
tearDown();
});
test('Test SVGTransformList.init() for translate(200,100)', function() {
expect(8);
setUp();
rect.setAttribute('transform', 'translate(200,100)');
var rxform = svgedit.transformlist.getTransformList(rect);
equals(1, rxform.numberOfItems);
var translate = rxform.getItem(0);
equals(translate.type, 2);
var m = translate.matrix;
equals(m.a, 1);
equals(m.b, 0);
equals(m.c, 0);
equals(m.d, 1);
equals(m.e, 200);
equals(m.f, 100);
tearDown();
});
test('Test SVGTransformList.init() for scale(4)', function() {
expect(8);
setUp();
rect.setAttribute('transform', 'scale(4)');
var rxform = svgedit.transformlist.getTransformList(rect);
equals(1, rxform.numberOfItems);
var scale = rxform.getItem(0);
equals(3, scale.type);
var m = scale.matrix;
equals(m.a, 4);
equals(m.b, 0);
equals(m.c, 0);
equals(m.d, 4);
equals(m.e, 0);
equals(m.f, 0);
tearDown();
});
test('Test SVGTransformList.init() for scale(4,3)', function() {
expect(8);
setUp();
rect.setAttribute('transform', 'scale(4,3)');
var rxform = svgedit.transformlist.getTransformList(rect);
equals(1, rxform.numberOfItems);
var scale = rxform.getItem(0);
equals(3, scale.type);
var m = scale.matrix;
equals(m.a, 4);
equals(m.b, 0);
equals(m.c, 0);
equals(m.d, 3);
equals(m.e, 0);
equals(m.f, 0);
tearDown();
});
test('Test SVGTransformList.init() for rotate(45)', function() {
expect(9);
setUp();
rect.setAttribute('transform', 'rotate(45)');
var rxform = svgedit.transformlist.getTransformList(rect);
equals(1, rxform.numberOfItems);
var rotate = rxform.getItem(0);
equals(4, rotate.type);
equals(45, rotate.angle);
var m = rotate.matrix;
almostEquals(m.a, 1/Math.sqrt(2));
almostEquals(m.b, 1/Math.sqrt(2));
almostEquals(m.c, -1/Math.sqrt(2));
almostEquals(m.d, 1/Math.sqrt(2));
equals(m.e, 0);
equals(m.f, 0);
tearDown();
});
test('Test SVGTransformList.init() for rotate(45, 100, 200)', function() {
expect(9);
setUp();
rect.setAttribute('transform', 'rotate(45, 100, 200)');
var rxform = svgedit.transformlist.getTransformList(rect);
equals(1, rxform.numberOfItems);
var rotate = rxform.getItem(0);
equals(4, rotate.type);
equals(45, rotate.angle);
var m = rotate.matrix;
almostEquals(m.a, 1/Math.sqrt(2));
almostEquals(m.b, 1/Math.sqrt(2));
almostEquals(m.c, -1/Math.sqrt(2));
almostEquals(m.d, 1/Math.sqrt(2));
var r = svgcontent.createSVGMatrix();
r.a = 1/Math.sqrt(2); r.b = 1/Math.sqrt(2);
r.c = -1/Math.sqrt(2); r.d = 1/Math.sqrt(2);
var t = svgcontent.createSVGMatrix();
t.e = -100; t.f = -200;
var t_ = svgcontent.createSVGMatrix();
t_.e = 100; t_.f = 200;
var result = t_.multiply(r).multiply(t);
almostEquals(m.e, result.e);
almostEquals(m.f, result.f);
tearDown();
});
test('Test SVGTransformList.init() for matrix(1, 2, 3, 4, 5, 6)', function() {
expect(8);
setUp();
rect.setAttribute('transform', 'matrix(1,2,3,4,5,6)');
var rxform = svgedit.transformlist.getTransformList(rect);
equals(1, rxform.numberOfItems);
var mt = rxform.getItem(0);
equals(1, mt.type);
var m = mt.matrix;
equals(m.a, 1);
equals(m.b, 2);
equals(m.c, 3);
equals(m.d, 4);
equals(m.e, 5);
equals(m.f, 6);
almostEquals(m.e, result.e);
almostEquals(m.f, result.f);
tearDown();
});
test('Test SVGTransformList.init() for matrix(1, 2, 3, 4, 5, 6)', function() {
expect(8);
setUp();
rect.setAttribute('transform', 'matrix(1,2,3,4,5,6)');
var rxform = svgedit.transformlist.getTransformList(rect);
equals(1, rxform.numberOfItems);
var mt = rxform.getItem(0);
equals(1, mt.type);
var m = mt.matrix;
equals(m.a, 1);
equals(m.b, 2);
equals(m.c, 3);
equals(m.d, 4);
equals(m.e, 5);
equals(m.f, 6);
tearDown();
});
tearDown();
});
});
</script>
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for svgtransformlist.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='svgroot' style='visibility:hidden'></div>
<h1 id='qunit-header'>Unit Tests for svgtransformlist.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'></ol>
<div id='svgroot' style='visibility:hidden'></div>
</body>
</html>

View File

@ -1,133 +1,133 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<!-- svgutils.js depends on these two... mock out? -->
<script src='../editor/browser.js'></script>
<script src='../editor/svgtransformlist.js'></script>
<script src='../editor/svgutils.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
<title>Unit Tests for svgutils.js</title>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<!-- svgutils.js depends on these two... mock out? -->
<script src='../editor/browser.js'></script>
<script src='../editor/svgtransformlist.js'></script>
<script src='../editor/svgutils.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
var svg = document.createElementNS(svgedit.NS.SVG, 'svg');
var svg = document.createElementNS(svgedit.NS.SVG, 'svg');
module('svgedit.utilities');
module('svgedit.utilities');
test('Test svgedit.utilities package', function() {
expect(3);
test('Test svgedit.utilities package', function() {
expect(3);
ok(svgedit.utilities);
ok(svgedit.utilities.toXml);
equals(typeof svgedit.utilities.toXml, typeof function(){});
});
ok(svgedit.utilities);
ok(svgedit.utilities.toXml);
equals(typeof svgedit.utilities.toXml, typeof function(){});
});
test('Test svgedit.utilities.toXml() function', function() {
expect(6);
var toXml = svgedit.utilities.toXml;
test('Test svgedit.utilities.toXml() function', function() {
expect(6);
var toXml = svgedit.utilities.toXml;
equals(toXml('a'), 'a');
equals(toXml('ABC_'), 'ABC_');
equals(toXml('PB&J'), 'PB&amp;J');
equals(toXml('2 < 5'), '2 &lt; 5');
equals(toXml('5 > 2'), '5 &gt; 2');
equals(toXml('\'<&>"'), '\'&lt;&amp;&gt;"');
});
equals(toXml('a'), 'a');
equals(toXml('ABC_'), 'ABC_');
equals(toXml('PB&J'), 'PB&amp;J');
equals(toXml('2 < 5'), '2 &lt; 5');
equals(toXml('5 > 2'), '5 &gt; 2');
equals(toXml('\'<&>"'), '\'&lt;&amp;&gt;"');
});
test('Test svgedit.utilities.fromXml() function', function() {
expect(6);
var fromXml = svgedit.utilities.fromXml;
test('Test svgedit.utilities.fromXml() function', function() {
expect(6);
var fromXml = svgedit.utilities.fromXml;
equals(fromXml('a'), 'a');
equals(fromXml('ABC_'), 'ABC_');
equals(fromXml('PB&amp;J'), 'PB&J');
equals(fromXml('2 &lt; 5'), '2 < 5');
equals(fromXml('5 &gt; 2'), '5 > 2');
equals(fromXml('&lt;&amp;&gt;'), '<&>');
});
equals(fromXml('a'), 'a');
equals(fromXml('ABC_'), 'ABC_');
equals(fromXml('PB&amp;J'), 'PB&J');
equals(fromXml('2 &lt; 5'), '2 < 5');
equals(fromXml('5 &gt; 2'), '5 > 2');
equals(fromXml('&lt;&amp;&gt;'), '<&>');
});
test('Test svgedit.utilities.encode64() function', function() {
expect(4);
var encode64 = svgedit.utilities.encode64;
test('Test svgedit.utilities.encode64() function', function() {
expect(4);
var encode64 = svgedit.utilities.encode64;
equals(encode64('abcdef'), 'YWJjZGVm');
equals(encode64('12345'), 'MTIzNDU=');
equals(encode64(' '), 'IA==');
equals(encode64('`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?'), 'YH4hQCMkJV4mKigpLV89K1t7XX1cfDs6JyIsPC4+Lz8=');
});
equals(encode64('abcdef'), 'YWJjZGVm');
equals(encode64('12345'), 'MTIzNDU=');
equals(encode64(' '), 'IA==');
equals(encode64('`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?'), 'YH4hQCMkJV4mKigpLV89K1t7XX1cfDs6JyIsPC4+Lz8=');
});
test('Test svgedit.utilities.decode64() function', function() {
expect(4);
var decode64 = svgedit.utilities.decode64;
test('Test svgedit.utilities.decode64() function', function() {
expect(4);
var decode64 = svgedit.utilities.decode64;
equals(decode64('YWJjZGVm'), 'abcdef');
equals(decode64('MTIzNDU='), '12345');
equals(decode64('IA=='), ' ');
equals(decode64('YH4hQCMkJV4mKigpLV89K1t7XX1cfDs6JyIsPC4+Lz8='), '`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?');
});
equals(decode64('YWJjZGVm'), 'abcdef');
equals(decode64('MTIzNDU='), '12345');
equals(decode64('IA=='), ' ');
equals(decode64('YH4hQCMkJV4mKigpLV89K1t7XX1cfDs6JyIsPC4+Lz8='), '`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?');
});
test('Test svgedit.utilities.convertToXMLReferences() function', function() {
expect(1);
test('Test svgedit.utilities.convertToXMLReferences() function', function() {
expect(1);
var convert = svgedit.utilities.convertToXMLReferences;
equals(convert('ABC'), 'ABC');
// equals(convert('ÀBC'), '&#192;BC');
});
var convert = svgedit.utilities.convertToXMLReferences;
equals(convert('ABC'), 'ABC');
// equals(convert('ÀBC'), '&#192;BC');
});
test('Test svgedit.utilities.bboxToObj() function', function() {
expect(5);
var bboxToObj = svgedit.utilities.bboxToObj;
test('Test svgedit.utilities.bboxToObj() function', function() {
expect(5);
var bboxToObj = svgedit.utilities.bboxToObj;
var rect = svg.createSVGRect();
rect.x = 1;
rect.y = 2;
rect.width = 3;
rect.height = 4;
var rect = svg.createSVGRect();
rect.x = 1;
rect.y = 2;
rect.width = 3;
rect.height = 4;
var obj = bboxToObj(rect);
equals(typeof obj, typeof {});
equals(obj.x, 1);
equals(obj.y, 2);
equals(obj.width, 3);
equals(obj.height, 4);
});
var obj = bboxToObj(rect);
equals(typeof obj, typeof {});
equals(obj.x, 1);
equals(obj.y, 2);
equals(obj.width, 3);
equals(obj.height, 4);
});
test("Test getUrlFromAttr", function() {
expect(4);
test("Test getUrlFromAttr", function() {
expect(4);
equal(svgedit.utilities.getUrlFromAttr("url(#foo)"), "#foo");
equal(svgedit.utilities.getUrlFromAttr("url(somefile.svg#foo)"), "somefile.svg#foo");
equal(svgedit.utilities.getUrlFromAttr("url('#foo')"), "#foo");
equal(svgedit.utilities.getUrlFromAttr('url("#foo")'), "#foo");
});
equal(svgedit.utilities.getUrlFromAttr("url(#foo)"), "#foo");
equal(svgedit.utilities.getUrlFromAttr("url(somefile.svg#foo)"), "somefile.svg#foo");
equal(svgedit.utilities.getUrlFromAttr("url('#foo')"), "#foo");
equal(svgedit.utilities.getUrlFromAttr('url("#foo")'), "#foo");
});
test("Test getPathBBox", function() {
if(svgedit.browser.supportsPathBBox()) return;
var doc = svgedit.utilities.text2xml('<svg></svg>');
var path = doc.createElementNS(svgedit.NS.SVG, 'path');
path.setAttributeNS(null, 'd', 'm0,0l5,0l0,5l-5,0l0,-5z');
var bb = svgedit.utilities.getPathBBox(path);
equals(typeof bb, 'object', 'BBox returned object');
ok(bb.x && !isNaN(bb.x));
ok(bb.y && !isNaN(bb.y));
});
test("Test getPathBBox", function() {
if(svgedit.browser.supportsPathBBox()) return;
var doc = svgedit.utilities.text2xml('<svg></svg>');
var path = doc.createElementNS(svgedit.NS.SVG, 'path');
path.setAttributeNS(null, 'd', 'm0,0l5,0l0,5l-5,0l0,-5z');
var bb = svgedit.utilities.getPathBBox(path);
equals(typeof bb, 'object', 'BBox returned object');
ok(bb.x && !isNaN(bb.x));
ok(bb.y && !isNaN(bb.y));
});
});
</script>
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for svgutils.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<h1 id='qunit-header'>Unit Tests for svgutils.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'></ol>
</body>
</html>

View File

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Unit Tests for SvgCanvas</title>
<link rel="stylesheet" href="qunit/qunit.css" type="text/css"/>
<script src="../editor/jquery.js"></script>
<script src="../editor/jquerybbq/jquery.bbq.min.js"></script>
@ -22,248 +23,248 @@
<script src="qunit/qunit.js"></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
// helper functions
var isIdentity = function(m) {
return (m.a == 1 && m.b == 0 && m.c == 0 && m.d == 1 && m.e == 0 && m.f == 0);
};
var matrixString = function(m) {
return [m.a,m.b,m.c,m.d,m.e,m.f].join(',');
}
// helper functions
var isIdentity = function(m) {
return (m.a == 1 && m.b == 0 && m.c == 0 && m.d == 1 && m.e == 0 && m.f == 0);
};
var matrixString = function(m) {
return [m.a,m.b,m.c,m.d,m.e,m.f].join(',');
}
var svgCanvas = new $.SvgCanvas(document.getElementById("svgcanvas"), {
canvas_expansion: 3,
dimensions: [640,480],
initFill: {
color: 'FF0000', // solid red
opacity: 1
},
initStroke: {
width: 5,
color: '000000', // solid black
opacity: 1
},
initOpacity: 1,
imgPath: 'images/',
langPath: 'locale/',
extPath: 'extensions/',
extensions: ['ext-arrows.js', 'ext-connector.js', 'ext-eyedropper.js'],
initTool: 'select',
wireframe: false
}),
svgroot = document.getElementById("svgroot"),
svgdoc = svgroot.documentElement,
svgns = "http://www.w3.org/2000/svg",
xlinkns = "http://www.w3.org/1999/xlink";
var svgCanvas = new $.SvgCanvas(document.getElementById("svgcanvas"), {
canvas_expansion: 3,
dimensions: [640,480],
initFill: {
color: 'FF0000', // solid red
opacity: 1
},
initStroke: {
width: 5,
color: '000000', // solid black
opacity: 1
},
initOpacity: 1,
imgPath: 'images/',
langPath: 'locale/',
extPath: 'extensions/',
extensions: ['ext-arrows.js', 'ext-connector.js', 'ext-eyedropper.js'],
initTool: 'select',
wireframe: false
}),
svgroot = document.getElementById("svgroot"),
svgdoc = svgroot.documentElement,
svgns = "http://www.w3.org/2000/svg",
xlinkns = "http://www.w3.org/1999/xlink";
module("Basic Module");
module("Basic Module");
test("Test existence of SvgCanvas object", function() {
expect(1);
equal(typeof {}, typeof svgCanvas);
});
module("Path Module");
test("Test path conversion from absolute to relative", function() {
expect(6);
var convert = svgCanvas.pathActions.convertPath;
test("Test existence of SvgCanvas object", function() {
expect(1);
equal(typeof {}, typeof svgCanvas);
});
module("Path Module");
test("Test path conversion from absolute to relative", function() {
expect(6);
var convert = svgCanvas.pathActions.convertPath;
// TODO: Test these paths:
// "m400.00491,625.01379a1.78688,1.78688 0 1 1-3.57373,0a1.78688,1.78688 0 1 13.57373,0z"
// "m36.812,15.8566c-28.03099,0 -26.28099,12.15601 -26.28099,12.15601l0.03099,12.59399h26.75v3.781h-37.37399c0,0 -17.938,-2.034 -133.00001,26.25c115.06201,28.284 130.71801,27.281 130.71801,27.281h9.34399v-13.125c0,0 -0.504,-15.656 15.40601,-15.656h26.532c0,0 14.90599,0.241 14.90599,-14.406v-24.219c0,0 2.263,-14.65601 -27.032,-14.65601zm-14.75,8.4684c2.662,0 4.813,2.151 4.813,4.813c0,2.661 -2.151,4.812 -4.813,4.812c-2.661,0 -4.812,-2.151 -4.812,-4.812c0,-2.662 2.151,-4.813 4.812,-4.813z"
// "m 0,0 l 200,0 l 0,100 L 0,100"
svgCanvas.setSvgString("<svg xmlns='http://www.w3.org/2000/svg' width='400' x='300'>" +
"<path id='p1' d='M100,100 L200,100 L100,100Z'/>" +
"<path id='p2' d='m 0,0 l 200,0 l 0,100 L 0,100'/>" +
"</svg>");
var p1 = document.getElementById("p1"),
p2 = document.getElementById("p2"),
d_abs = p1.getAttribute("d"),
seglist = p1.pathSegList,
curseg = null;
equal(p1.nodeName, "path", "Expected 'path', got");
equal(seglist.numberOfItems, 4, "Number of segments before conversion");
// verify segments before conversion
curseg = seglist.getItem(0);
equal(curseg.pathSegTypeAsLetter.toUpperCase(), "M", "Before conversion, segment #1 type");
curseg = seglist.getItem(1);
equal(curseg.pathSegTypeAsLetter.toUpperCase(), "L", "Before conversion, segment #2 type");
curseg = seglist.getItem(3);
equal(curseg.pathSegTypeAsLetter.toUpperCase(), "Z", "Before conversion, segment #3 type" + d_abs);
// convert and verify segments
var d = convert(p1, true);
equal(d, "m100,100l100,0l-100,0z", "Converted path to relative string");
// TODO: see why this isn't working in SVG-edit
d = convert(p2, true);
QUnit.log(d);
d = convert(p2, false);
QUnit.log(d);
});
module("Import Module");
test("Test import use", function() {
expect(3);
svgCanvas.setSvgString("<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='400' x='300'>" +
"<rect id='the-rect' width='200' height='200'/>" +
"<use id='the-use' xlink:href='#the-rect'/>" +
"<use id='foreign-use' xlink:href='somefile.svg#the-rect'/>" +
"<use id='no-use'/>" +
"</svg>");
var u = document.getElementById("the-use"),
fu = document.getElementById("foreign-use"),
nfu = document.getElementById("no-use");
equal((u && u.nodeName == "use"), true, "Did not import <use> element");
equal(fu, null, "Removed <use> element that had a foreign href");
equal(nfu, null, "Removed <use> element that had no href");
});
// This test shows that an element with an invalid attribute is still parsed in properly
// and only the attribute is not imported
test("Test invalid attribute", function() {
expect(2);
svgCanvas.setSvgString('<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg">'+
'<text x="182.75" y="173.5" id="the-text" fill="#008000" font-size="150" font-family="serif" text-anchor="middle" d="M116,222 L110,108">words</text>' +
'</svg>');
var t = document.getElementById("the-text");
equal(true, (t && t.nodeName == "text"), "Did not import <text> element");
equal(null, t.getAttribute("d"), "Imported a <text> with a d attribute");
});
// This test makes sure import/export properly handles namespaced attributes
test("Test importing/exporting namespaced attributes", function() {
expect(5);
var setStr = svgCanvas.setSvgString('<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:se="http://svg-edit.googlecode.com" xmlns:foo="http://example.com">'+
'<image xlink:href="../editor/images/logo.png"/>' +
'<polyline id="se_test_elem" se:foo="bar" foo:bar="baz"/>' +
'</svg>');
var attrVal = document.getElementById('se_test_elem').getAttributeNS("http://svg-edit.googlecode.com", "foo");
equal(attrVal === "bar", true, "Preserved namespaced attribute on import");
//
// console.log('getSvgString' in svgCanvas)
// TODO: Test these paths:
// "m400.00491,625.01379a1.78688,1.78688 0 1 1-3.57373,0a1.78688,1.78688 0 1 13.57373,0z"
// "m36.812,15.8566c-28.03099,0 -26.28099,12.15601 -26.28099,12.15601l0.03099,12.59399h26.75v3.781h-37.37399c0,0 -17.938,-2.034 -133.00001,26.25c115.06201,28.284 130.71801,27.281 130.71801,27.281h9.34399v-13.125c0,0 -0.504,-15.656 15.40601,-15.656h26.532c0,0 14.90599,0.241 14.90599,-14.406v-24.219c0,0 2.263,-14.65601 -27.032,-14.65601zm-14.75,8.4684c2.662,0 4.813,2.151 4.813,4.813c0,2.661 -2.151,4.812 -4.813,4.812c-2.661,0 -4.812,-2.151 -4.812,-4.812c0,-2.662 2.151,-4.813 4.812,-4.813z"
// "m 0,0 l 200,0 l 0,100 L 0,100"
svgCanvas.setSvgString("<svg xmlns='http://www.w3.org/2000/svg' width='400' x='300'>" +
"<path id='p1' d='M100,100 L200,100 L100,100Z'/>" +
"<path id='p2' d='m 0,0 l 200,0 l 0,100 L 0,100'/>" +
"</svg>");
var p1 = document.getElementById("p1"),
p2 = document.getElementById("p2"),
d_abs = p1.getAttribute("d"),
seglist = p1.pathSegList,
curseg = null;
equal(p1.nodeName, "path", "Expected 'path', got");
equal(seglist.numberOfItems, 4, "Number of segments before conversion");
// verify segments before conversion
curseg = seglist.getItem(0);
equal(curseg.pathSegTypeAsLetter.toUpperCase(), "M", "Before conversion, segment #1 type");
curseg = seglist.getItem(1);
equal(curseg.pathSegTypeAsLetter.toUpperCase(), "L", "Before conversion, segment #2 type");
curseg = seglist.getItem(3);
equal(curseg.pathSegTypeAsLetter.toUpperCase(), "Z", "Before conversion, segment #3 type" + d_abs);
// convert and verify segments
var d = convert(p1, true);
equal(d, "m100,100l100,0l-100,0z", "Converted path to relative string");
// TODO: see why this isn't working in SVG-edit
d = convert(p2, true);
QUnit.log(d);
d = convert(p2, false);
QUnit.log(d);
});
module("Import Module");
test("Test import use", function() {
expect(3);
svgCanvas.setSvgString("<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='400' x='300'>" +
"<rect id='the-rect' width='200' height='200'/>" +
"<use id='the-use' xlink:href='#the-rect'/>" +
"<use id='foreign-use' xlink:href='somefile.svg#the-rect'/>" +
"<use id='no-use'/>" +
"</svg>");
var u = document.getElementById("the-use"),
fu = document.getElementById("foreign-use"),
nfu = document.getElementById("no-use");
equal((u && u.nodeName == "use"), true, "Did not import <use> element");
equal(fu, null, "Removed <use> element that had a foreign href");
equal(nfu, null, "Removed <use> element that had no href");
});
// This test shows that an element with an invalid attribute is still parsed in properly
// and only the attribute is not imported
test("Test invalid attribute", function() {
expect(2);
svgCanvas.setSvgString('<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg">'+
'<text x="182.75" y="173.5" id="the-text" fill="#008000" font-size="150" font-family="serif" text-anchor="middle" d="M116,222 L110,108">words</text>' +
'</svg>');
var t = document.getElementById("the-text");
equal(true, (t && t.nodeName == "text"), "Did not import <text> element");
equal(null, t.getAttribute("d"), "Imported a <text> with a d attribute");
});
// This test makes sure import/export properly handles namespaced attributes
test("Test importing/exporting namespaced attributes", function() {
expect(5);
var setStr = svgCanvas.setSvgString('<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:se="http://svg-edit.googlecode.com" xmlns:foo="http://example.com">'+
'<image xlink:href="../editor/images/logo.png"/>' +
'<polyline id="se_test_elem" se:foo="bar" foo:bar="baz"/>' +
'</svg>');
var attrVal = document.getElementById('se_test_elem').getAttributeNS("http://svg-edit.googlecode.com", "foo");
equal(attrVal === "bar", true, "Preserved namespaced attribute on import");
//
//console.log('getSvgString' in svgCanvas)
var output = svgCanvas.getSvgString();
// } catch(e) {console.log(e)}
// console.log('output',output);
var has_xlink = output.indexOf('xmlns:xlink="http://www.w3.org/1999/xlink"') !== -1;
var has_se = output.indexOf('xmlns:se=') !== -1;
var has_foo = output.indexOf('xmlns:foo=') !== -1;
var has_attr = output.indexOf('se:foo="bar"') !== -1;
equal(has_attr, true, "Preserved namespaced attribute on export");
equal(has_xlink, true, "Included xlink: xmlns");
equal(has_se, true, "Included se: xmlns");
equal(has_foo, false, "Did not include foo: xmlns");
});
test("Test import math elements inside a foreignObject", function() {
expect(4);
var set = svgCanvas.setSvgString('<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg" xmlns:se="http://svg-edit.googlecode.com" xmlns:xlink="http://www.w3.org/1999/xlink">'+
'<foreignObject id="fo" width="24" height="26" font-size="24"><math id="m" display="inline" xmlns="http://www.w3.org/1998/Math/MathML">'+
'<msub>'+
'<mi>A</mi>'+
'<mn>0</mn>'+
'</msub>'+
'</math>'+
'</foreignObject>'+
'</svg>');
var fo = document.getElementById('fo');
// we cannot use getElementById('math') because not all browsers understand MathML and do not know to use the @id attribute
// see Bug https://bugs.webkit.org/show_bug.cgi?id=35042
var math = fo.firstChild;
equal(!!math, true, "Math element exists");
equal(math.nodeName, 'math', "Math element has the proper nodeName");
equal(math.getAttribute('id'), 'm', "Math element has an id");
equal(math.namespaceURI, "http://www.w3.org/1998/Math/MathML", "Preserved MathML namespace");
});
test("Test importing SVG into existing drawing", function() {
expect(3);
var doc = svgCanvas.setSvgString('<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg">'+
'<g><title>Layer 1</title>'+
'<circle cx="200" cy="200" r="50" fill="blue"/>'+
'<ellipse cx="300" cy="100" rx="40" ry="30" fill="green"/>'+
'</g>'+
'</svg>');
svgCanvas.importSvgString('<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">'+
'<circle cx="50" cy="50" r="40" fill="yellow"/>'+
'<rect width="20" height="20" fill="blue"/>'+
'</svg>');
var svgcontent = document.getElementById("svgcontent"),
circles = svgcontent.getElementsByTagNameNS(svgns, "circle"),
rects = svgcontent.getElementsByTagNameNS(svgns, "rect"),
ellipses = svgcontent.getElementsByTagNameNS(svgns, "ellipse");
equal(circles.length, 2, "Found two circles upon importing");
equal(rects.length, 1, "Found one rectangle upon importing");
equal(ellipses.length, 1, "Found one ellipse upon importing");
});
var output = svgCanvas.getSvgString();
//} catch(e) {console.log(e)}
//console.log('output',output);
var has_xlink = output.indexOf('xmlns:xlink="http://www.w3.org/1999/xlink"') !== -1;
var has_se = output.indexOf('xmlns:se=') !== -1;
var has_foo = output.indexOf('xmlns:foo=') !== -1;
var has_attr = output.indexOf('se:foo="bar"') !== -1;
equal(has_attr, true, "Preserved namespaced attribute on export");
equal(has_xlink, true, "Included xlink: xmlns");
equal(has_se, true, "Included se: xmlns");
equal(has_foo, false, "Did not include foo: xmlns");
});
test("Test import math elements inside a foreignObject", function() {
expect(4);
var set = svgCanvas.setSvgString('<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg" xmlns:se="http://svg-edit.googlecode.com" xmlns:xlink="http://www.w3.org/1999/xlink">'+
'<foreignObject id="fo" width="24" height="26" font-size="24"><math id="m" display="inline" xmlns="http://www.w3.org/1998/Math/MathML">'+
'<msub>'+
'<mi>A</mi>'+
'<mn>0</mn>'+
'</msub>'+
'</math>'+
'</foreignObject>'+
'</svg>');
var fo = document.getElementById('fo');
// we cannot use getElementById('math') because not all browsers understand MathML and do not know to use the @id attribute
// see Bug https://bugs.webkit.org/show_bug.cgi?id=35042
var math = fo.firstChild;
equal(!!math, true, "Math element exists");
equal(math.nodeName, 'math', "Math element has the proper nodeName");
equal(math.getAttribute('id'), 'm', "Math element has an id");
equal(math.namespaceURI, "http://www.w3.org/1998/Math/MathML", "Preserved MathML namespace");
});
test("Test importing SVG into existing drawing", function() {
expect(3);
var doc = svgCanvas.setSvgString('<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg">'+
'<g><title>Layer 1</title>'+
'<circle cx="200" cy="200" r="50" fill="blue"/>'+
'<ellipse cx="300" cy="100" rx="40" ry="30" fill="green"/>'+
'</g>'+
'</svg>');
svgCanvas.importSvgString('<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">'+
'<circle cx="50" cy="50" r="40" fill="yellow"/>'+
'<rect width="20" height="20" fill="blue"/>'+
'</svg>');
var svgcontent = document.getElementById("svgcontent"),
circles = svgcontent.getElementsByTagNameNS(svgns, "circle"),
rects = svgcontent.getElementsByTagNameNS(svgns, "rect"),
ellipses = svgcontent.getElementsByTagNameNS(svgns, "ellipse");
equal(circles.length, 2, "Found two circles upon importing");
equal(rects.length, 1, "Found one rectangle upon importing");
equal(ellipses.length, 1, "Found one ellipse upon importing");
});
test("Test importing SVG remaps IDs", function() {
expect(6);
var doc = svgCanvas.setSvgString('<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg">'+
'<g><title>Layer 1</title>'+
'<ellipse id="svg_1" cx="200" cy="200" rx="50" ry="20" fill="blue"/>'+
'<ellipse id="svg_2" cx="300" cy="100" rx="40" ry="30" fill="green"/>'+
'<ellipse id="svg_3" cx="300" cy="100" rx="40" ry="30" fill="green"/>'+
'</g>'+
'</svg>');
svgCanvas.importSvgString('<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg" xmlns:xl="http://www.w3.org/1999/xlink">'+
'<defs>'+
'<linearGradient id="svg_2">'+
'<stop stop-color="red" offset="0"/>'+
'<stop stop-color="green" offset="1"/>'+
'</linearGradient>'+
'<rect id="svg_3" width="20" height="20" fill="blue" stroke="url(#svg_2)"/>'+
'</defs>'+
'<circle id="svg_1" cx="50" cy="50" r="40" fill="url(#svg_2)"/>'+
'<use id="svg_4" width="30" height="30" xl:href="#svg_3"/>'+
'</svg>');
var svgcontent = document.getElementById("svgcontent"),
circles = svgcontent.getElementsByTagNameNS(svgns, "circle"),
rects = svgcontent.getElementsByTagNameNS(svgns, "rect"),
ellipses = svgcontent.getElementsByTagNameNS(svgns, "ellipse"),
defs = svgcontent.getElementsByTagNameNS(svgns, "defs"),
grads = svgcontent.getElementsByTagNameNS(svgns, "linearGradient"),
uses = svgcontent.getElementsByTagNameNS(svgns, "use");
notEqual(circles.item(0).id, "svg_1", "Circle not re-identified");
notEqual(rects.item(0).id, "svg_3", "Rectangle not re-identified");
// // TODO: determine why this test fails in WebKit browsers
// equal(grads.length, 1, "Linear gradient imported");
var grad = defs.item(0).firstChild;
notEqual(grad.id, "svg_2", "Linear gradient not re-identified");
notEqual(circles.item(0).getAttribute("fill"), "url(#svg_2)", "Circle fill value not remapped");
notEqual(rects.item(0).getAttribute("stroke"), "url(#svg_2)", "Rectangle stroke value not remapped");
notEqual(uses.item(0).getAttributeNS(xlinkns, "href"), "#svg_3");
});
test("Test importing SVG remaps IDs", function() {
expect(6);
var doc = svgCanvas.setSvgString('<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg">'+
'<g><title>Layer 1</title>'+
'<ellipse id="svg_1" cx="200" cy="200" rx="50" ry="20" fill="blue"/>'+
'<ellipse id="svg_2" cx="300" cy="100" rx="40" ry="30" fill="green"/>'+
'<ellipse id="svg_3" cx="300" cy="100" rx="40" ry="30" fill="green"/>'+
'</g>'+
'</svg>');
svgCanvas.importSvgString('<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg" xmlns:xl="http://www.w3.org/1999/xlink">'+
'<defs>'+
'<linearGradient id="svg_2">'+
'<stop stop-color="red" offset="0"/>'+
'<stop stop-color="green" offset="1"/>'+
'</linearGradient>'+
'<rect id="svg_3" width="20" height="20" fill="blue" stroke="url(#svg_2)"/>'+
'</defs>'+
'<circle id="svg_1" cx="50" cy="50" r="40" fill="url(#svg_2)"/>'+
'<use id="svg_4" width="30" height="30" xl:href="#svg_3"/>'+
'</svg>');
var svgcontent = document.getElementById("svgcontent"),
circles = svgcontent.getElementsByTagNameNS(svgns, "circle"),
rects = svgcontent.getElementsByTagNameNS(svgns, "rect"),
ellipses = svgcontent.getElementsByTagNameNS(svgns, "ellipse"),
defs = svgcontent.getElementsByTagNameNS(svgns, "defs"),
grads = svgcontent.getElementsByTagNameNS(svgns, "linearGradient"),
uses = svgcontent.getElementsByTagNameNS(svgns, "use");
notEqual(circles.item(0).id, "svg_1", "Circle not re-identified");
notEqual(rects.item(0).id, "svg_3", "Rectangle not re-identified");
// TODO: determine why this test fails in WebKit browsers
//equal(grads.length, 1, "Linear gradient imported");
var grad = defs.item(0).firstChild;
notEqual(grad.id, "svg_2", "Linear gradient not re-identified");
notEqual(circles.item(0).getAttribute("fill"), "url(#svg_2)", "Circle fill value not remapped");
notEqual(rects.item(0).getAttribute("stroke"), "url(#svg_2)", "Rectangle stroke value not remapped");
notEqual(uses.item(0).getAttributeNS(xlinkns, "href"), "#svg_3");
});
});
</script>
</head>
@ -271,14 +272,13 @@
<h1 id="qunit-header">Unit Tests for SvgCanvas</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests">
</ol>
<ol id="qunit-tests"></ol>
<div id="svg_editor">
<div id="workarea">
<div id="svgcanvas" style="visibility:hidden"></div>
</div>
<div id="tools_left"></div>
<div class="tools_flyout"></div>
<div id="workarea">
<div id="svgcanvas" style="visibility:hidden"></div>
</div>
<div id="tools_left"></div>
<div class="tools_flyout"></div>
</div>
</body>
</html>
</html>

View File

@ -1,106 +1,105 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script src='../editor/units.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
<title>Unit Tests for units.js</title>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<script src='../editor/units.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(result, message) {
if (window.console && window.console.log) {
window.console.log(result +' :: '+ message);
}
};
function setUp() {
svgedit.units.init({
getBaseUnit: function() { return "cm"; },
getHeight: function() { return 600; },
getWidth: function() { return 800; },
getRoundDigits: function() { return 4; },
getElement: function(elementId){ return document.getElementById(elementId); }
});
}
function setUp() {
svgedit.units.init({
getBaseUnit: function() { return "cm"; },
getHeight: function() { return 600; },
getWidth: function() { return 800; },
getRoundDigits: function() { return 4; },
getElement: function(elementId){ return document.getElementById(elementId); }
});
}
test('Test svgedit.units package', function() {
expect(2);
ok(svgedit.units);
equals(typeof svgedit.units, typeof {});
});
test('Test svgedit.units package', function() {
expect(2);
ok(svgedit.units);
equals(typeof svgedit.units, typeof {});
});
test('Test svgedit.units.shortFloat()', function() {
expect(7);
test('Test svgedit.units.shortFloat()', function() {
expect(7);
setUp();
setUp();
ok(svgedit.units.shortFloat);
equals(typeof svgedit.units.shortFloat, typeof function(){});
ok(svgedit.units.shortFloat);
equals(typeof svgedit.units.shortFloat, typeof function(){});
var shortFloat = svgedit.units.shortFloat;
equals(shortFloat(0.00000001), 0);
equals(shortFloat(1), 1);
equals(shortFloat(3.45678), 3.4568);
equals(shortFloat(1.23443), 1.2344);
equals(shortFloat(1.23455), 1.2346);
});
var shortFloat = svgedit.units.shortFloat;
equals(shortFloat(0.00000001), 0);
equals(shortFloat(1), 1);
equals(shortFloat(3.45678), 3.4568);
equals(shortFloat(1.23443), 1.2344);
equals(shortFloat(1.23455), 1.2346);
});
test('Test svgedit.units.isValidUnit()', function() {
expect(18);
test('Test svgedit.units.isValidUnit()', function() {
expect(18);
setUp();
setUp();
ok(svgedit.units.isValidUnit);
equals(typeof svgedit.units.isValidUnit, typeof function(){});
ok(svgedit.units.isValidUnit);
equals(typeof svgedit.units.isValidUnit, typeof function(){});
var isValidUnit = svgedit.units.isValidUnit;
ok(isValidUnit("0"));
ok(isValidUnit("1"));
ok(isValidUnit("1.1"));
ok(isValidUnit("-1.1"));
ok(isValidUnit(".6mm"));
ok(isValidUnit("-.6cm"));
ok(isValidUnit("6000in"));
ok(isValidUnit("6px"));
ok(isValidUnit("6.3pc"));
ok(isValidUnit("-0.4em"));
ok(isValidUnit("-0.ex"));
ok(isValidUnit("40.123%"));
var isValidUnit = svgedit.units.isValidUnit;
ok(isValidUnit("0"));
ok(isValidUnit("1"));
ok(isValidUnit("1.1"));
ok(isValidUnit("-1.1"));
ok(isValidUnit(".6mm"));
ok(isValidUnit("-.6cm"));
ok(isValidUnit("6000in"));
ok(isValidUnit("6px"));
ok(isValidUnit("6.3pc"));
ok(isValidUnit("-0.4em"));
ok(isValidUnit("-0.ex"));
ok(isValidUnit("40.123%"));
equals(isValidUnit("id","uniqueId",document.getElementById("uniqueId")), true);
equals(isValidUnit("id","newId",document.getElementById("uniqueId")), true);
equals(isValidUnit("id","uniqueId"), false);
equals(isValidUnit("id","uniqueId",document.getElementById("nonUniqueId")), false);
});
equals(isValidUnit("id","uniqueId",document.getElementById("uniqueId")), true);
equals(isValidUnit("id","newId",document.getElementById("uniqueId")), true);
equals(isValidUnit("id","uniqueId"), false);
equals(isValidUnit("id","uniqueId",document.getElementById("nonUniqueId")), false);
});
test('Test svgedit.units.convertUnit()', function() {
expect(4);
test('Test svgedit.units.convertUnit()', function() {
expect(4);
setUp();
setUp();
ok(svgedit.units.convertUnit);
equals(typeof svgedit.units.convertUnit, typeof function(){});
// cm in default setup
equals(svgedit.units.convertUnit(42), 1.1113);
equals(svgedit.units.convertUnit(42, 'px'), 42);
});
});
</script>
ok(svgedit.units.convertUnit);
equals(typeof svgedit.units.convertUnit, typeof function(){});
// cm in default setup
equals(svgedit.units.convertUnit(42), 1.1113);
equals(svgedit.units.convertUnit(42, 'px'), 42);
});
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for units.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'>
</ol>
<div id='anchor' style='visibility:hidden'>
</div>
<div id="elementsContainer">
<div id='uniqueId' style='visibility:hidden'></div>
<div id='nonUniqueId' style='visibility:hidden'></div>
</div>
</div>
<h1 id='qunit-header'>Unit Tests for units.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'></ol>
<div id='anchor' style='visibility:hidden'></div>
<div id="elementsContainer">
<div id='uniqueId' style='visibility:hidden'></div>
<div id='nonUniqueId' style='visibility:hidden'></div>
</div>
</div>
</body>
</html>