Start on a svgutils unit test file
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1856 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
9fa4764f41
commit
711346f109
|
@ -213,4 +213,22 @@ svgedit.math.snapToAngle = function(x1,y1,x2,y2) {
|
||||||
return {x:x, y:y, a:snapangle};
|
return {x:x, y:y, a:snapangle};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Function: rectsIntersect
|
||||||
|
// Check if two rectangles (BBoxes objects) intersect each other
|
||||||
|
//
|
||||||
|
// Paramaters:
|
||||||
|
// r1 - The first BBox-like object
|
||||||
|
// r2 - The second BBox-like object
|
||||||
|
//
|
||||||
|
// Returns:
|
||||||
|
// Boolean that's true if rectangles intersect
|
||||||
|
svgedit.math.rectsIntersect = function(r1, r2) {
|
||||||
|
return r2.x < (r1.x+r1.width) &&
|
||||||
|
(r2.x+r2.width) > r1.x &&
|
||||||
|
r2.y < (r1.y+r1.height) &&
|
||||||
|
(r2.y+r2.height) > r1.y;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
})();
|
})();
|
|
@ -1503,7 +1503,7 @@ var getIntersectionList = this.getIntersectionList = function(rect) {
|
||||||
var i = curBBoxes.length;
|
var i = curBBoxes.length;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
if(!rubberBBox.width || !rubberBBox.width) continue;
|
if(!rubberBBox.width || !rubberBBox.width) continue;
|
||||||
if (svgedit.utilities.rectsIntersect(rubberBBox, curBBoxes[i].bbox)) {
|
if (svgedit.math.rectsIntersect(rubberBBox, curBBoxes[i].bbox)) {
|
||||||
resultList.push(curBBoxes[i].elem);
|
resultList.push(curBBoxes[i].elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4660,7 +4660,7 @@ var textActions = canvas.textActions = function() {
|
||||||
|
|
||||||
// TODO: Find a way to make this work: Use transformed BBox instead of evt.target
|
// TODO: Find a way to make this work: Use transformed BBox instead of evt.target
|
||||||
// if(last_x === mouse_x && last_y === mouse_y
|
// if(last_x === mouse_x && last_y === mouse_y
|
||||||
// && !svgedit.utilities.rectsIntersect(transbb, {x: pt.x, y: pt.y, width:0, height:0})) {
|
// && !svgedit.math.rectsIntersect(transbb, {x: pt.x, y: pt.y, width:0, height:0})) {
|
||||||
// textActions.toSelectMode(true);
|
// textActions.toSelectMode(true);
|
||||||
// }
|
// }
|
||||||
if(last_x === mouse_x && last_y === mouse_y && evt.target !== curtext) {
|
if(last_x === mouse_x && last_y === mouse_y && evt.target !== curtext) {
|
||||||
|
@ -6123,7 +6123,7 @@ var pathActions = this.pathActions = function() {
|
||||||
height: 0
|
height: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
var sel = svgedit.utilities.rectsIntersect(rbb, pt_bb);
|
var sel = svgedit.math.rectsIntersect(rbb, pt_bb);
|
||||||
|
|
||||||
this.select(sel);
|
this.select(sel);
|
||||||
//Note that addPtsToSelection is not being run
|
//Note that addPtsToSelection is not being run
|
||||||
|
|
|
@ -183,22 +183,6 @@ svgedit.utilities.convertToXMLReferences = function(input) {
|
||||||
return output;
|
return output;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: rectsIntersect
|
|
||||||
// Check if two rectangles (BBoxes objects) intersect each other
|
|
||||||
//
|
|
||||||
// Paramaters:
|
|
||||||
// r1 - The first BBox-like object
|
|
||||||
// r2 - The second BBox-like object
|
|
||||||
//
|
|
||||||
// Returns:
|
|
||||||
// Boolean that's true if rectangles intersect
|
|
||||||
svgedit.utilities.rectsIntersect = function(r1, r2) {
|
|
||||||
return r2.x < (r1.x+r1.width) &&
|
|
||||||
(r2.x+r2.width) > r1.x &&
|
|
||||||
r2.y < (r1.y+r1.height) &&
|
|
||||||
(r2.y+r2.height) > r1.y;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Function: text2xml
|
// Function: text2xml
|
||||||
// Cross-browser compatible method of converting a string to an XML tree
|
// Cross-browser compatible method of converting a string to an XML tree
|
||||||
// found this function here: http://groups.google.com/group/jquery-dev/browse_thread/thread/c6d11387c580a77f
|
// found this function here: http://groups.google.com/group/jquery-dev/browse_thread/thread/c6d11387c580a77f
|
||||||
|
@ -332,6 +316,8 @@ svgedit.utilities.findDefs = function(svgElement) {
|
||||||
return defs;
|
return defs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO(codedread): Consider moving the next to functions to bbox.js
|
||||||
|
|
||||||
// Function: svgedit.utilities.getPathBBox
|
// Function: svgedit.utilities.getPathBBox
|
||||||
// Get correct BBox for a path in Webkit
|
// Get correct BBox for a path in Webkit
|
||||||
// Converted from code found here:
|
// Converted from code found here:
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
<h1>All SVG-edit Tests</h1>
|
<h1>All SVG-edit Tests</h1>
|
||||||
<p>This file frames all SVG-edit test pages. This should only include tests known to work. If a test is broken in this page, it is possible that <em>YOU</em> broke it. Please do not submit code that breaks any of these tests.</p>
|
<p>This file frames all SVG-edit test pages. This should only include tests known to work. If a test is broken in this page, it is possible that <em>YOU</em> broke it. Please do not submit code that breaks any of these tests.</p>
|
||||||
<iframe src='svgtransformlist_test.html' width='100%' height='300'></iframe>
|
<iframe src='svgtransformlist_test.html' width='100%' height='300'></iframe>
|
||||||
|
<iframe src='svgutils_test.html' width='100%' height='300'></iframe>
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
window.setTimeout(function() {
|
window.setTimeout(function() {
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
|
||||||
|
<script src='../editor/jquery.js'></script>
|
||||||
|
<!-- svgutils.js depends on these two... mock out? -->
|
||||||
|
<script type='text/javascript' src='../editor/browsersupport.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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module('svgedit.utilities Module');
|
||||||
|
|
||||||
|
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='), '`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</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>
|
Loading…
Reference in New Issue