135 lines
4.2 KiB
HTML
135 lines
4.2 KiB
HTML
<!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<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');
|
||
|
||
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('<27>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(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>
|
||
</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>
|