2011-02-02 17:28:43 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
2013-02-17 17:28:19 +00:00
|
|
|
<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);
|
|
|
|
}
|
|
|
|
};
|
2011-02-02 17:28:43 +00:00
|
|
|
|
2013-02-17 17:28:19 +00:00
|
|
|
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); }
|
|
|
|
});
|
|
|
|
}
|
2013-02-14 12:18:13 +00:00
|
|
|
|
2013-02-17 17:28:19 +00:00
|
|
|
test('Test svgedit.units package', function() {
|
|
|
|
expect(2);
|
|
|
|
ok(svgedit.units);
|
|
|
|
equals(typeof svgedit.units, typeof {});
|
|
|
|
});
|
2011-02-02 17:28:43 +00:00
|
|
|
|
2013-02-17 17:28:19 +00:00
|
|
|
test('Test svgedit.units.shortFloat()', function() {
|
|
|
|
expect(7);
|
2011-02-02 17:28:43 +00:00
|
|
|
|
2013-02-17 17:28:19 +00:00
|
|
|
setUp();
|
2013-02-14 12:18:13 +00:00
|
|
|
|
2013-02-17 17:28:19 +00:00
|
|
|
ok(svgedit.units.shortFloat);
|
|
|
|
equals(typeof svgedit.units.shortFloat, typeof function(){});
|
2011-02-02 17:28:43 +00:00
|
|
|
|
2013-02-17 17:28:19 +00:00
|
|
|
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);
|
|
|
|
});
|
2011-02-02 17:32:52 +00:00
|
|
|
|
2013-02-17 17:28:19 +00:00
|
|
|
test('Test svgedit.units.isValidUnit()', function() {
|
|
|
|
expect(18);
|
2011-02-02 17:32:52 +00:00
|
|
|
|
2013-02-17 17:28:19 +00:00
|
|
|
setUp();
|
2013-02-14 12:18:13 +00:00
|
|
|
|
2013-02-17 17:28:19 +00:00
|
|
|
ok(svgedit.units.isValidUnit);
|
|
|
|
equals(typeof svgedit.units.isValidUnit, typeof function(){});
|
2011-02-02 17:32:52 +00:00
|
|
|
|
2013-02-17 17:28:19 +00:00
|
|
|
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%"));
|
2012-05-25 04:04:22 +00:00
|
|
|
|
2013-02-17 17:28:19 +00:00
|
|
|
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);
|
|
|
|
});
|
2012-05-25 04:04:22 +00:00
|
|
|
|
2013-02-17 17:28:19 +00:00
|
|
|
test('Test svgedit.units.convertUnit()', function() {
|
|
|
|
expect(4);
|
2013-02-14 12:18:13 +00:00
|
|
|
|
2013-02-17 17:28:19 +00:00
|
|
|
setUp();
|
2013-02-14 12:18:13 +00:00
|
|
|
|
2013-02-17 17:28:19 +00:00
|
|
|
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>
|
2013-02-14 12:18:13 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
2013-02-17 17:28:19 +00:00
|
|
|
<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>
|
2013-02-14 12:18:13 +00:00
|
|
|
</body>
|
2011-02-02 17:28:43 +00:00
|
|
|
</html>
|