blob: acf4ba9fafa459fd77edd75c3c8e6fe111f48d58 [file] [log] [blame]
<svg xmlns="http://www.w3.org/2000/svg">
<g id='log' />
<script>
<![CDATA[
if (window.testRunner)
testRunner.dumpAsText();
var svgNS = "http://www.w3.org/2000/svg";
var pathElement = document.createElementNS(svgNS, 'path');
var errorTolerance = .1;
var logOffset = 20;
function result(didPass, string) {
var newText = document.createElementNS(svgNS, "text");
newText.setAttribute("x", 10);
newText.setAttribute("y", logOffset);
logOffset += 20;
newText.textContent = string;
var newTspan = document.createElementNS(svgNS, "tspan");
if (didPass) {
newTspan.textContent = "PASS: ";
newTspan.style.fill = "green";
} else {
newTspan.textContent = "FAIL: ";
newTspan.style.fill = "red";
}
newText.insertBefore(newTspan, newText.firstChild);
document.getElementById('log').appendChild(newText);
}
function expectLength(path, expectedLength) {
pathElement.setAttribute("d", path);
var actualLength;
try {
actualLength = pathElement.getTotalLength();
if (Math.abs(actualLength - expectedLength) < errorTolerance)
result(true, path + "\" = " + actualLength);
else
result(false, path + "\" expected: " + expectedLength + " actual: " + actualLength);
} catch(e) {
result(false, path + "\" expected: " + expectedLength + " got exception: " + e);
}
}
var errorCount = 0;
// Tests go here:
expectLength('M 0 0 L 100 0 L 100 100 L 0 100 Z', 400);
expectLength('M 0 0 l 100 0 l 0 100 l -100 0 Z', 400);
expectLength('M 0 0 t 0 100', 100);
expectLength('M 0 0 Q 55 50 100 100', 141.4); // I'm not sure if this is actually right
]]>
</script>
</svg>