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