svnno****@sourc*****
svnno****@sourc*****
2011年 1月 24日 (月) 23:33:08 JST
Revision: 2326 http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=2326 Author: dhrname Date: 2011-01-24 23:33:08 +0900 (Mon, 24 Jan 2011) Log Message: ----------- Added Paths: ----------- trunk/Spec/spec/SvgDomSpec.js Copied: trunk/Spec/spec/SvgDomSpec.js (from rev 2323, trunk/Spec/SvgDomSpec.js) =================================================================== --- trunk/Spec/spec/SvgDomSpec.js (rev 0) +++ trunk/Spec/spec/SvgDomSpec.js 2011-01-24 14:33:08 UTC (rev 2326) @@ -0,0 +1,317 @@ +/*SIE-SVG without Plugin under LGPL2.1 & GPL2.0 & Mozilla Public Lisence + *公式ページは http://sie.sourceforge.jp/ + */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla SVG Cairo Renderer project. + * + * The Initial Developer of the Original Code is IBM Corporation. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Parts of this file contain code derived from the following files(s) + * of the Mozilla SVG project (these parts are Copyright (C) by their + * respective copyright-holders): + * layout/svg/renderer/src/libart/nsSVGLibartBPathBuilder.cpp + * + * Contributor(s):DHRNAME revulo bellbind + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. + * See W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ +/* + *Copyright (c) 2008-2010 Pivotal Labs + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +describe("SVG Spec in JavaScript", function() { + /*Refer to W3C SVG1.1 (second edition)*/ + var doc, svg; + beforeEach(function() { + /*前もって実行しておく変数(The variable 'doc' is a document node, and the 'svg' is a root element node.)*/ + doc = DOMImplementation.createDocument("http://www.w3.org/2000/svg", "svg"); + svg = doc.documentElement; + }); + describe("SVG Unit :: SVG Length", function() { + var s; + beforeEach(function() { + s = svg.createSVGLength(); + }); + /*まずは、あるべきデフォルト値かどうかをチェックしていく(Checking the default value of a SVGLength interface.)*/ + it("for the default value on the property of SVGLength", function() { + /*See http://www.w3.org/TR/SVG/struct.html#InterfaceSVGDocument + * *createSVGLength() + * *Creates an SVGLength object outside of any document trees. The object is initialized to the value of 0 user units. + *see also http://www.w3.org/TR/SVG/types.html#InterfaceSVGLength + * *SVG_LENGTHTYPE_NUMBER (unsigned short) + * *No unit type was provided (i.e., a unitless value was specified), which indicates a value in user units. + */ + expect(s.value).toEqual(0); + expect(s.valueInSpecifiedUnits).toEqual(0); + expect(s.unitType).toEqual(1); + }); + /*境界条件を調べておく (limit value analysis)*/ + it("should be this for the value, when it calls a newValueSpecifiedUnits method", function() { + var t = [Number.MAX_VALUE, Number.MIN_VALUE, 0, Number.MAX_VALUE/2, Number.MIN_VALUE/2]; + for (var i=0,tli=t.length;i<tli;++i) { + s.newValueSpecifiedUnits(1, t[i]); + expect(s.valueInSpecifiedUnits).toEqual(t[i]); + expect(s.value).toEqual(t[i]); + expect(s.valueAsString).toEqual(t[i]+""); + expect(s.unitType).toEqual(1); + } + t = null; + }); + /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/ + it("should be this for the value, when it calls a newValueSpecifiedUnits method", function() { + var t = [Math.PI, 10/3], num = (t[0]+"").length - 1; //無理数を作って、ぎりぎりの有効数字の桁数numをはじき出しておく + for (var i=1;i<num;++i) { + t[t.length] = Math.pow(10, i); + t[t.length] = Math.pow(10, -i); + t[t.length] = Math.pow(10, i); + t[t.length] = Math.pow(10, -i); + } + for (var i=0,tli=t.length;i<tli;++i) { + s.newValueSpecifiedUnits(1, t[i]); + expect(s.valueInSpecifiedUnits).toEqual(t[i]); + expect(s.value).toEqual(t[i]); + expect(s.valueAsString).toEqual(t[i]+""); + expect(s.unitType).toEqual(1); + } + t = null; + }); + /*同値分割をして、無効同値クラスを調べておく (equivalence partitioning, the following is the invalid partion)*/ + it("should throw a DOMException 'Not Supported Error', when it calls a newValueSpecifiedUnits method", function() { + var t = [Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY, Number.NaN, {}, [], "", "1", "-1", undefined, null, 0, -1, 11, 1.1, 10.1]; + for (var i=0,tli=t.length;i<tli;++i) { + var ti = t[i], sn = function() { + s.newValueSpecifiedUnits(ti, 0); + }; + expect(sn).toThrow(); + ti = sn = null; + } + t = null; + }); + /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/ + it("should be this for the value, when it calls a convertToSpecifiedUnits method", function() { + var unit = ["", "%", "em", "ex", "px", "cm", "mm", "in", "pt", "pc"]; + for (var i=1,tli=11;i<tli;++i) { + s.convertToSpecifiedUnits(i); + expect(s.valueInSpecifiedUnits).toEqual(0); + expect(s.value).toEqual(0); + expect(s.valueAsString).toEqual("0" + unit[i-1]); + expect(s.unitType).toEqual(i); + } + unit = null; + }); + /*同値分割をして、無効同値クラスを調べておく (equivalence partitioning, the following is the invalid partion)*/ + it("should throw a DOMException 'Not Supported Error', when it calls a convertToSpecifiedUnits method", function() { + var t = [Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY, Number.NaN, {}, [], "", "1", "-1", undefined, null, 0, -1, 11, 1.1, 10.1]; + for (var i=0,tli=t.length;i<tli;++i) { + var ti = t[i], sn = function() { + s.convertToSpecifiedUnits(ti); + }; + expect(sn).toThrow(); + ti = sn = null; + } + t = null; + }); + }); + describe("SVG Unit :: SVG Matrix", function() { + var s; + beforeEach(function() { + s = svg.createSVGMatrix(); + }); + it("for the default value on the property of SVGMatrix", function() { + /*See http://www.w3.org/TR/SVG/struct.html#InterfaceSVGSVGElement + * *The object is initialized to the identity matrix. + *以下では、createSVGElementが単位行列を返しているかどうかをチェック + */ + expect(s.a).toEqual(1); + expect(s.b).toEqual(0); + expect(s.c).toEqual(0); + expect(s.d).toEqual(1); + expect(s.e).toEqual(0); + expect(s.f).toEqual(0); + }); + /*境界条件を調べておく (limit value analysis about a 'multiply')*/ + it("should be this for the value, when it calls a 'multiply' method", function() { + var t = [Number.MAX_VALUE, Number.MIN_VALUE, 0, Number.MAX_VALUE/2, Number.MIN_VALUE/2, 0]; + for (var i=0,tli=t.length;i<tli;++i) { + var n = svg.createSVGMatrix(); + n.a = t[i]; + n.b = t[i]; + n.c = t[i]; + n.d = t[i]; + n.e = t[i]; + s.multiply(n); + n = null; + } + t = null; + }); + it("should return the SVGMatrix Object, when it calls a 'multiply' method", function() { + var t = s.multiply(svg.createSVGMatrix()); + expect(t.a).toEqual(1); + expect(t.b).toEqual(0); + expect(t.c).toEqual(0); + expect(t.d).toEqual(1); + expect(t.e).toEqual(0); + expect(t.f).toEqual(0); + /*See http://www.w3.org/TR/SVG/coords.html#InterfaceSVGMatrix + * *..returning the resulting new matrix. + *以下では新しいSVGMatrixオブジェクトを返しているかどうかをチェック + */ + expect(t).toNotBe(s); + var u = svg.createSVGMatrix(); + t.a = u.a = 2; + t.b = u.b = 2; + t.c = u.c = 2; + t.d = u.d = 2; + t.e = u.e = 2; + t.f = u.f = 2; + var m = t.multiply(u); + expect(m.a).toEqual(8); + expect(m.b).toEqual(8); + expect(m.c).toEqual(8); + expect(m.d).toEqual(8); + expect(m.e).toEqual(10); + expect(m.f).toEqual(10); + }); + /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/ + it("should be this for the value", function() { + var t = [Math.PI, 10/3], num = (t[0]+"").length - 1; //無理数を作って、ぎりぎりの有効数字の桁数numをはじき出しておく + for (var i=1;i<num;++i) { + t[t.length] = Math.pow(10, i); + t[t.length] = Math.pow(10, -i); + t[t.length] = Math.pow(10, i); + t[t.length] = Math.pow(10, -i); + } + for (var i=0,tli=t.length;i<tli;++i) { + var n = svg.createSVGMatrix(), ti = t[i]; + n.a = ti; + n.b = ti; + n.c = ti; + n.d = ti; + n.e = ti; + n.f = ti; + var d = s.multiply(n); + /*注:sが単位行列であることに注意すること (Note that the variable 's' is a identity matrix)*/ + expect(d.a).toEqual(ti); + expect(d.b).toEqual(ti); + expect(d.c).toEqual(ti); + expect(d.d).toEqual(ti); + expect(d.e).toEqual(ti); + expect(d.f).toEqual(ti); + n = d = null; + } + t = null; + }); + /*同値分割をして、無効同値クラスを調べておく (equivalence partitioning, the following is the invalid partion)*/ + it("should throw an Error, when it calls a 'multiply' method", function() { + var t = [Number.NEGATIVE_INFINITY, + Number.POSITIVE_INFINITY, + Number.NaN, + undefined]; + for (var i=0,tli=t.length;i<tli;++i) { + var ti = t[i], sn = function() { + var n = svg.createSVGMatrix(); + n.a = 0; + n.b = 0; + n.c = 0; + n.d = 0; + n.e = 0; + n.f = ti; + s.multiply(n); + }; + expect(sn).toThrow(); + ti = sn = null; + } + t = null; + }); + /*逆行列に関する境界条件を調べておく (limit value analysis about a 'inverse')*/ + it("should be this for the value, when it calls a 'inverse' method", function() { + var si = s.inverse(), t = [s.multiply(si), si.multiply(s)]; + s.a = -1; + si = s.inverse(); + t[t.length] = s.multiply(si); + t[t.length] = si.multiply(s); + s.a = 1; + s.d = -1; + si = s.inverse(); + t[t.length] = s.multiply(si); + t[t.length] = si.multiply(s); + s.b = -1; + s.c = 1; + s.d = 1; + si = s.inverse(); + t[t.length] = s.multiply(si); + t[t.length] = si.multiply(s); + s.b = 1; + s.c = -1; + si = s.inverse(); + t[t.length] = s.multiply(si); + t[t.length] = si.multiply(s); + for (var i=0;i<t.length;++i) { + var d = t[i]; + expect(d.a).toEqual(1); + expect(d.b).toEqual(0); + expect(d.c).toEqual(0); + expect(d.d).toEqual(1); + expect(d.e).toEqual(0); + expect(d.f).toEqual(0); + d = null; + } + si = t = null; + }); + }); +}); \ No newline at end of file