1 | <!DOCTYPE html>
|
---|
2 | <html>
|
---|
3 | <head>
|
---|
4 | <link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
|
---|
5 | <script src='../editor/assets/jquery.js'></script>
|
---|
6 | <!-- svgutils.js depends on these two... mock out? -->
|
---|
7 | <script type='text/javascript' src='../editor/src/browser.js'></script>
|
---|
8 | <script type='text/javascript' src='../editor/src/svgtransformlist.js'></script>
|
---|
9 | <script type='text/javascript' src='../editor/src/svgutils.js'></script>
|
---|
10 | <script type='text/javascript' src='qunit/qunit.js'></script>
|
---|
11 | <script type='text/javascript'>
|
---|
12 | $(function() {
|
---|
13 | // log function
|
---|
14 | QUnit.log = function(result, message) {
|
---|
15 | if (window.console && window.console.log) {
|
---|
16 | window.console.log(result +' :: '+ message);
|
---|
17 | }
|
---|
18 | };
|
---|
19 |
|
---|
20 | var svgns = 'http://www.w3.org/2000/svg';
|
---|
21 | var svg = document.createElementNS(svgns, 'svg');
|
---|
22 |
|
---|
23 | module('svgedit.utilities');
|
---|
24 |
|
---|
25 | test('Test svgedit.utilities package', function() {
|
---|
26 | expect(3);
|
---|
27 |
|
---|
28 | ok(svgedit.utilities);
|
---|
29 | ok(svgedit.utilities.toXml);
|
---|
30 | equals(typeof svgedit.utilities.toXml, typeof function(){});
|
---|
31 | });
|
---|
32 |
|
---|
33 | test('Test svgedit.utilities.toXml() function', function() {
|
---|
34 | expect(6);
|
---|
35 | var toXml = svgedit.utilities.toXml;
|
---|
36 |
|
---|
37 | equals(toXml('a'), 'a');
|
---|
38 | equals(toXml('ABC_'), 'ABC_');
|
---|
39 | equals(toXml('PB&J'), 'PB&J');
|
---|
40 | equals(toXml('2 < 5'), '2 < 5');
|
---|
41 | equals(toXml('5 > 2'), '5 > 2');
|
---|
42 | equals(toXml('\'<&>"'), '\'<&>"');
|
---|
43 | });
|
---|
44 |
|
---|
45 | test('Test svgedit.utilities.fromXml() function', function() {
|
---|
46 | expect(6);
|
---|
47 | var fromXml = svgedit.utilities.fromXml;
|
---|
48 |
|
---|
49 | equals(fromXml('a'), 'a');
|
---|
50 | equals(fromXml('ABC_'), 'ABC_');
|
---|
51 | equals(fromXml('PB&J'), 'PB&J');
|
---|
52 | equals(fromXml('2 < 5'), '2 < 5');
|
---|
53 | equals(fromXml('5 > 2'), '5 > 2');
|
---|
54 | equals(fromXml('<&>'), '<&>');
|
---|
55 | });
|
---|
56 |
|
---|
57 | test('Test svgedit.utilities.encode64() function', function() {
|
---|
58 | expect(4);
|
---|
59 | var encode64 = svgedit.utilities.encode64;
|
---|
60 |
|
---|
61 | equals(encode64('abcdef'), 'YWJjZGVm');
|
---|
62 | equals(encode64('12345'), 'MTIzNDU=');
|
---|
63 | equals(encode64(' '), 'IA==');
|
---|
64 | equals(encode64('`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?'), 'YH4hQCMkJV4mKigpLV89K1t7XX1cfDs6JyIsPC4+Lz8=');
|
---|
65 | });
|
---|
66 |
|
---|
67 | test('Test svgedit.utilities.decode64() function', function() {
|
---|
68 | expect(4);
|
---|
69 | var decode64 = svgedit.utilities.decode64;
|
---|
70 |
|
---|
71 | equals(decode64('YWJjZGVm'), 'abcdef');
|
---|
72 | equals(decode64('MTIzNDU='), '12345');
|
---|
73 | equals(decode64('IA=='), ' ');
|
---|
74 | equals(decode64('YH4hQCMkJV4mKigpLV89K1t7XX1cfDs6JyIsPC4+Lz8='), '`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?');
|
---|
75 | });
|
---|
76 |
|
---|
77 | test('Test svgedit.utilities.convertToXMLReferences() function', function() {
|
---|
78 | expect(1);
|
---|
79 |
|
---|
80 | var convert = svgedit.utilities.convertToXMLReferences;
|
---|
81 | equals(convert('ABC'), 'ABC');
|
---|
82 | // equals(convert('ÃBC'), 'ÀBC');
|
---|
83 | });
|
---|
84 |
|
---|
85 | test('Test svgedit.utilities.bboxToObj() function', function() {
|
---|
86 | expect(5);
|
---|
87 | var bboxToObj = svgedit.utilities.bboxToObj;
|
---|
88 |
|
---|
89 | var rect = svg.createSVGRect();
|
---|
90 | rect.x = 1;
|
---|
91 | rect.y = 2;
|
---|
92 | rect.width = 3;
|
---|
93 | rect.height = 4;
|
---|
94 |
|
---|
95 | var obj = bboxToObj(rect);
|
---|
96 | equals(typeof obj, typeof {});
|
---|
97 | equals(obj.x, 1);
|
---|
98 | equals(obj.y, 2);
|
---|
99 | equals(obj.width, 3);
|
---|
100 | equals(obj.height, 4);
|
---|
101 | });
|
---|
102 |
|
---|
103 |
|
---|
104 | test("Test getUrlFromAttr", function() {
|
---|
105 | expect(4);
|
---|
106 |
|
---|
107 | equal(svgedit.utilities.getUrlFromAttr("url(#foo)"), "#foo");
|
---|
108 | equal(svgedit.utilities.getUrlFromAttr("url(somefile.svg#foo)"), "somefile.svg#foo");
|
---|
109 | equal(svgedit.utilities.getUrlFromAttr("url('#foo')"), "#foo");
|
---|
110 | equal(svgedit.utilities.getUrlFromAttr('url("#foo")'), "#foo");
|
---|
111 | });
|
---|
112 |
|
---|
113 | test("Test getPathBBox", function() {
|
---|
114 | if(svgedit.browser.supportsPathBBox()) return;
|
---|
115 | var doc = svgedit.utilities.text2xml('<svg></svg>');
|
---|
116 | var path = doc.createElementNS(svgns, 'path');
|
---|
117 | path.setAttributeNS(null, 'd', 'm0,0l5,0l0,5l-5,0l0,-5z');
|
---|
118 | var bb = svgedit.utilities.getPathBBox(path);
|
---|
119 | equals(typeof bb, 'object', 'BBox returned object');
|
---|
120 | ok(bb.x && !isNaN(bb.x));
|
---|
121 | ok(bb.y && !isNaN(bb.y));
|
---|
122 | });
|
---|
123 |
|
---|
124 | });
|
---|
125 | </script>
|
---|
126 | </head>
|
---|
127 | <body>
|
---|
128 | <h1 id='qunit-header'>Unit Tests for svgutils.js</h1>
|
---|
129 | <h2 id='qunit-banner'></h2>
|
---|
130 | <h2 id='qunit-userAgent'></h2>
|
---|
131 | <ol id='qunit-tests'>
|
---|
132 | </ol>
|
---|
133 | </body>
|
---|
134 | </html>
|
---|