2012-05-17 22:50:00 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
|
2012-07-25 06:32:18 +00:00
|
|
|
<script src='../editor/assets/jquery.js'></script>
|
2012-05-17 22:50:00 +00:00
|
|
|
<!-- svgutils.js depends on these two... mock out? -->
|
|
|
|
<script type='text/javascript' src='../editor/browser.js'></script>
|
|
|
|
<script type='text/javascript' src='../editor/svgtransformlist.js'></script>
|
|
|
|
<script type='text/javascript' src='../editor/svgutils.js'></script>
|
|
|
|
<script type='text/javascript' src='qunit/qunit.js'></script>
|
|
|
|
<script type='text/javascript'>
|
|
|
|
$(function() {
|
|
|
|
// log function
|
|
|
|
QUnit.log = function(result, message) {
|
|
|
|
if (window.console && window.console.log) {
|
|
|
|
window.console.log(result +' :: '+ message);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var svgns = 'http://www.w3.org/2000/svg';
|
|
|
|
var svg = document.createElementNS(svgns, 'svg');
|
|
|
|
|
|
|
|
module('svgedit.utilities');
|
|
|
|
|
|
|
|
test('Test svgedit.utilities package', function() {
|
|
|
|
expect(3);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
equals(toXml('a'), 'a');
|
|
|
|
equals(toXml('ABC_'), 'ABC_');
|
|
|
|
equals(toXml('PB&J'), 'PB&J');
|
|
|
|
equals(toXml('2 < 5'), '2 < 5');
|
|
|
|
equals(toXml('5 > 2'), '5 > 2');
|
|
|
|
equals(toXml('\'<&>"'), '\'<&>"');
|
|
|
|
});
|
|
|
|
|
|
|
|
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&J'), 'PB&J');
|
|
|
|
equals(fromXml('2 < 5'), '2 < 5');
|
|
|
|
equals(fromXml('5 > 2'), '5 > 2');
|
|
|
|
equals(fromXml('<&>'), '<&>');
|
|
|
|
});
|
|
|
|
|
|
|
|
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=');
|
|
|
|
});
|
|
|
|
|
|
|
|
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='), '`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Test svgedit.utilities.convertToXMLReferences() function', function() {
|
|
|
|
expect(1);
|
|
|
|
|
|
|
|
var convert = svgedit.utilities.convertToXMLReferences;
|
|
|
|
equals(convert('ABC'), 'ABC');
|
|
|
|
// equals(convert('ÀBC'), 'ÀBC');
|
|
|
|
});
|
|
|
|
|
|
|
|
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 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);
|
|
|
|
|
|
|
|
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(svgns, '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>
|
|
|
|
</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>
|
|
|
|
</body>
|
|
|
|
</html>
|