2011-02-04 16:06:25 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
2013-10-29 03:32:01 +00:00
|
|
|
<meta charset="utf-8" />
|
2013-02-17 17:28:19 +00:00
|
|
|
<title>Unit Tests for path.js</title>
|
|
|
|
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
|
|
|
|
<script src='../editor/jquery.js'></script>
|
2014-04-07 04:51:46 +00:00
|
|
|
<script src='../editor/svgedit.js'></script>
|
2016-02-22 01:13:40 +00:00
|
|
|
<script src='../editor/pathseg.js'></script>
|
|
|
|
<script src='../editor/browser.js'></script>
|
|
|
|
<script src='../editor/svgutils.js'></script>
|
2013-02-17 17:28:19 +00:00
|
|
|
<script src='../editor/path.js'></script>
|
|
|
|
<script src='qunit/qunit.js'></script>
|
|
|
|
<script>
|
|
|
|
$(function() {
|
|
|
|
// log function
|
2014-04-07 05:33:44 +00:00
|
|
|
QUnit.log = function(details) {
|
2013-02-17 17:28:19 +00:00
|
|
|
if (window.console && window.console.log) {
|
2014-04-07 05:33:44 +00:00
|
|
|
window.console.log(details.result +' :: '+ details.message);
|
2013-02-17 17:28:19 +00:00
|
|
|
}
|
|
|
|
};
|
2016-02-22 01:13:40 +00:00
|
|
|
|
|
|
|
test('Test svgedit.path.replacePathSeg', function() {
|
|
|
|
expect(6);
|
|
|
|
|
|
|
|
var path = document.createElementNS(svgedit.NS.SVG, 'path');
|
|
|
|
path.setAttribute('d', 'M0,0 L10,11 L20,21Z');
|
|
|
|
svgedit.path.init();
|
|
|
|
svgedit.path.Path(path);
|
|
|
|
|
|
|
|
equals(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'L');
|
|
|
|
equals(path.pathSegList.getItem(1).x, 10);
|
|
|
|
equals(path.pathSegList.getItem(1).y, 11);
|
|
|
|
|
|
|
|
svgedit.path.replacePathSeg(SVGPathSeg.PATHSEG_LINETO_REL, 1, [30, 31], path);
|
|
|
|
|
|
|
|
equals(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'l');
|
|
|
|
equals(path.pathSegList.getItem(1).x, 30);
|
|
|
|
equals(path.pathSegList.getItem(1).y, 31);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Test svgedit.path.Segment.setType simple', function() {
|
|
|
|
expect(9);
|
|
|
|
|
|
|
|
var path = document.createElementNS(svgedit.NS.SVG, 'path');
|
|
|
|
path.setAttribute('d', 'M0,0 L10,11 L20,21Z');
|
|
|
|
svgedit.path.init();
|
|
|
|
svgedit.path.Path(path);
|
|
|
|
|
|
|
|
equals(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'L');
|
|
|
|
equals(path.pathSegList.getItem(1).x, 10);
|
|
|
|
equals(path.pathSegList.getItem(1).y, 11);
|
|
|
|
|
|
|
|
var segment = new svgedit.path.Segment(1, path.pathSegList.getItem(1));
|
|
|
|
segment.setType(SVGPathSeg.PATHSEG_LINETO_REL, [30, 31]);
|
|
|
|
equals(segment.item.pathSegTypeAsLetter, 'l');
|
|
|
|
equals(segment.item.x, 30);
|
|
|
|
equals(segment.item.y, 31);
|
|
|
|
|
|
|
|
// Also verify that the actual path changed.
|
|
|
|
equals(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'l');
|
|
|
|
equals(path.pathSegList.getItem(1).x, 30);
|
|
|
|
equals(path.pathSegList.getItem(1).y, 31);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Test svgedit.path.Segment.setType with control points', function() {
|
|
|
|
expect(14);
|
|
|
|
|
|
|
|
// Setup the dom for a mock control group.
|
|
|
|
var svg = document.createElementNS(svgedit.NS.SVG, 'svg');
|
|
|
|
var path = document.createElementNS(svgedit.NS.SVG, 'path');
|
|
|
|
path.setAttribute('d', 'M0,0 C11,12 13,14 15,16 Z');
|
|
|
|
svg.appendChild(path);
|
|
|
|
var selectorParentGroup = document.createElementNS(svgedit.NS.SVG, 'g');
|
|
|
|
selectorParentGroup.setAttribute('id', 'selectorParentGroup');
|
|
|
|
svg.appendChild(selectorParentGroup);
|
|
|
|
var mockContext = {
|
|
|
|
getDOMDocument: function() { return svg; },
|
|
|
|
getDOMContainer: function() { return svg; },
|
|
|
|
getSVGRoot: function() { return svg; },
|
|
|
|
getCurrentZoom: function() { return 1; }
|
|
|
|
};
|
|
|
|
svgedit.path.init(mockContext);
|
|
|
|
svgedit.utilities.init(mockContext);
|
|
|
|
var segment = new svgedit.path.Segment(1, path.pathSegList.getItem(1));
|
|
|
|
segment.path = new svgedit.path.Path(path);
|
|
|
|
|
|
|
|
equals(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'C');
|
|
|
|
equals(path.pathSegList.getItem(1).x1, 11);
|
|
|
|
equals(path.pathSegList.getItem(1).y1, 12);
|
|
|
|
equals(path.pathSegList.getItem(1).x2, 13);
|
|
|
|
equals(path.pathSegList.getItem(1).y2, 14);
|
|
|
|
equals(path.pathSegList.getItem(1).x, 15);
|
|
|
|
equals(path.pathSegList.getItem(1).y, 16);
|
|
|
|
|
|
|
|
segment.setType(SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL, [30, 31, 32, 33, 34, 35]);
|
|
|
|
equals(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'c');
|
|
|
|
equals(path.pathSegList.getItem(1).x1, 32);
|
|
|
|
equals(path.pathSegList.getItem(1).y1, 33);
|
|
|
|
equals(path.pathSegList.getItem(1).x2, 34);
|
|
|
|
equals(path.pathSegList.getItem(1).y2, 35);
|
|
|
|
equals(path.pathSegList.getItem(1).x, 30);
|
|
|
|
equals(path.pathSegList.getItem(1).y, 31);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Test svgedit.path.Segment.move', function() {
|
|
|
|
expect(6);
|
|
|
|
|
|
|
|
var path = document.createElementNS(svgedit.NS.SVG, 'path');
|
|
|
|
path.setAttribute('d', 'M0,0 L10,11 L20,21Z');
|
|
|
|
svgedit.path.init();
|
|
|
|
svgedit.path.Path(path);
|
|
|
|
|
|
|
|
equals(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'L');
|
|
|
|
equals(path.pathSegList.getItem(1).x, 10);
|
|
|
|
equals(path.pathSegList.getItem(1).y, 11);
|
|
|
|
|
|
|
|
var segment = new svgedit.path.Segment(1, path.pathSegList.getItem(1));
|
|
|
|
segment.move(-3, 4);
|
|
|
|
equals(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'L');
|
|
|
|
equals(path.pathSegList.getItem(1).x, 7);
|
|
|
|
equals(path.pathSegList.getItem(1).y, 15);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Test svgedit.path.Segment.moveCtrl', function() {
|
|
|
|
expect(14);
|
|
|
|
|
|
|
|
var path = document.createElementNS(svgedit.NS.SVG, 'path');
|
|
|
|
path.setAttribute('d', 'M0,0 C11,12 13,14 15,16 Z');
|
|
|
|
svgedit.path.init();
|
|
|
|
svgedit.path.Path(path);
|
|
|
|
|
|
|
|
equals(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'C');
|
|
|
|
equals(path.pathSegList.getItem(1).x1, 11);
|
|
|
|
equals(path.pathSegList.getItem(1).y1, 12);
|
|
|
|
equals(path.pathSegList.getItem(1).x2, 13);
|
|
|
|
equals(path.pathSegList.getItem(1).y2, 14);
|
|
|
|
equals(path.pathSegList.getItem(1).x, 15);
|
|
|
|
equals(path.pathSegList.getItem(1).y, 16);
|
|
|
|
|
|
|
|
var segment = new svgedit.path.Segment(1, path.pathSegList.getItem(1));
|
|
|
|
segment.moveCtrl(1, 100, -200);
|
|
|
|
equals(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'C');
|
|
|
|
equals(path.pathSegList.getItem(1).x1, 111);
|
|
|
|
equals(path.pathSegList.getItem(1).y1, -188);
|
|
|
|
equals(path.pathSegList.getItem(1).x2, 13);
|
|
|
|
equals(path.pathSegList.getItem(1).y2, 14);
|
|
|
|
equals(path.pathSegList.getItem(1).x, 15);
|
|
|
|
equals(path.pathSegList.getItem(1).y, 16);
|
|
|
|
});
|
2013-02-17 17:28:19 +00:00
|
|
|
});
|
|
|
|
</script>
|
2013-02-16 15:02:26 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
2011-02-04 16:06:25 +00:00
|
|
|
<h1 id='qunit-header'>Unit Tests for path.js</h1>
|
|
|
|
<h2 id='qunit-banner'></h2>
|
|
|
|
<h2 id='qunit-userAgent'></h2>
|
2013-02-17 17:28:19 +00:00
|
|
|
<ol id='qunit-tests'></ol>
|
|
|
|
<div id='anchor' style='visibility:hidden'></div>
|
2013-02-16 15:02:26 +00:00
|
|
|
</body>
|
2011-02-04 16:06:25 +00:00
|
|
|
</html>
|