| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 |
"http://www.w3.org/TR/html4/strict.dtd"> |
| 3 |
<html> |
| 4 |
<head> |
| 5 |
<title>GFX Test: Test the basic utils functions</title> |
| 6 |
<style type="text/css"> |
| 7 |
@import "../../../../dojo/resources/dojo.css"; |
| 8 |
@import "../../../../dijit/tests/css/dijitTests.css"; |
| 9 |
</style> |
| 10 |
|
| 11 |
<meta name="svg.render.forceflash" content="true"/> |
| 12 |
<script src="svgweb/src/svg.js" data-path="svgweb/src"></script> |
| 13 |
<script src="../../../../dojo/dojo.js" data-dojo-config="isDebug:true,forceGfxRenderer:'svg'" type="text/javascript"></script> |
| 14 |
|
| 15 |
<script type="text/javascript" src="../../../util/doh/runner.js"></script> |
| 16 |
<script type="text/javascript"> |
| 17 |
dojo.require("doh.runner"); |
| 18 |
dojo.require("dojox.gfx"); |
| 19 |
dojo.require("dojox.gfx.utils"); |
| 20 |
</script> |
| 21 |
<script type="text/javascript"> |
| 22 |
dojo.addOnLoad(function(){ |
| 23 |
var drawing; |
| 24 |
var ta; |
| 25 |
doh.register("GFX: Utils Tests", [ |
| 26 |
{ |
| 27 |
name: "toJson", |
| 28 |
timeout: 1000, |
| 29 |
setUp: function(){ |
| 30 |
if(!drawing){ |
| 31 |
var dn = dojo.byId("gfxObject"); |
| 32 |
drawing = dojox.gfx.createSurface(dn, 300, 300); |
| 33 |
/* SVGWEB { */ |
| 34 |
drawing.whenLoaded(function() { |
| 35 |
drawing.createRect({ |
| 36 |
width: 100, |
| 37 |
height: 100, |
| 38 |
x: 100, |
| 39 |
y: 100 |
| 40 |
}).setFill("blue").setStroke("black"); |
| 41 |
}); |
| 42 |
/* } */ |
| 43 |
} |
| 44 |
if(!ta){ |
| 45 |
ta = dojo.byId("outputArea"); |
| 46 |
} |
| 47 |
}, |
| 48 |
runTest: function(){ |
| 49 |
/* SVGWEB { */ |
| 50 |
drawing.whenLoaded(function() { |
| 51 |
var d = new doh.Deferred(); |
| 52 |
try{ |
| 53 |
var json = dojox.gfx.utils.toJson(drawing); |
| 54 |
doh.assertTrue(json != null, "Checking that non-null was returned."); |
| 55 |
ta.value = json; |
| 56 |
var obj = dojo.fromJson(json); |
| 57 |
doh.assertTrue(1, obj.length, "Checking that the json is an array of one entry."); |
| 58 |
doh.assertTrue(obj[0].shape != null, "Checking that a toplevel shape object is present."); |
| 59 |
doh.assertEqual("rect", obj[0].shape.type, "Checking that the shape type is rect."); |
| 60 |
doh.assertEqual(100, obj[0].shape.width, "Checking that the width is 100."); |
| 61 |
doh.assertEqual(100, obj[0].shape.height, "Checking that the height is 100."); |
| 62 |
d.callback(true); |
| 63 |
}catch(e){ |
| 64 |
d.errback(e); |
| 65 |
} |
| 66 |
return d; |
| 67 |
}); |
| 68 |
/* } */ |
| 69 |
} |
| 70 |
}, |
| 71 |
{ |
| 72 |
name: "fromJson", |
| 73 |
timeout: 1000, |
| 74 |
setUp: function(){ |
| 75 |
if(!drawing){ |
| 76 |
var dn = dojo.byId("gfxObject"); |
| 77 |
drawing = dojox.gfx.createSurface(dn, 300, 300); |
| 78 |
/* SVGWEB { */ |
| 79 |
drawing.whenLoaded(function() { |
| 80 |
drawing.createRect({ |
| 81 |
width: 100, |
| 82 |
height: 100, |
| 83 |
x: 100, |
| 84 |
y: 100 |
| 85 |
}).setFill("blue").setStroke("black"); |
| 86 |
}); |
| 87 |
/* } */ |
| 88 |
} |
| 89 |
if(!ta){ |
| 90 |
ta = dojo.byId("outputArea"); |
| 91 |
} |
| 92 |
}, |
| 93 |
runTest: function(){ |
| 94 |
/* SVGWEB { */ |
| 95 |
drawing.whenLoaded(function() { |
| 96 |
var d = new doh.Deferred(); |
| 97 |
try{ |
| 98 |
var json = dojox.gfx.utils.toJson(drawing); |
| 99 |
doh.assertTrue(json != null, "Checking that non-null was returned."); |
| 100 |
var targetNode = dojo.byId("scratchObject"); |
| 101 |
var tempSurface = dojox.gfx.createSurface(targetNode, 300, 300); |
| 102 |
dojox.gfx.utils.fromJson(tempSurface, json); |
| 103 |
|
| 104 |
var nsJson = dojox.gfx.utils.toJson(tempSurface); |
| 105 |
tempSurface.destroy(); |
| 106 |
|
| 107 |
var obj = dojo.fromJson(nsJson); |
| 108 |
doh.assertTrue(1, obj.length, "Checking that the json is an array of one entry."); |
| 109 |
doh.assertTrue(obj[0].shape != null, "Checking that a toplevel shape object is present."); |
| 110 |
doh.assertEqual("rect", obj[0].shape.type, "Checking that the shape type is rect."); |
| 111 |
doh.assertEqual(100, obj[0].shape.width, "Checking that the width is 100."); |
| 112 |
doh.assertEqual(100, obj[0].shape.height, "Checking that the height is 100."); |
| 113 |
d.callback(true); |
| 114 |
}catch(e){ |
| 115 |
d.errback(e); |
| 116 |
} |
| 117 |
return d; |
| 118 |
}); |
| 119 |
/* } */ |
| 120 |
} |
| 121 |
}, |
| 122 |
{ |
| 123 |
name: "toSvg", |
| 124 |
timeout: 10000, |
| 125 |
setUp: function(){ |
| 126 |
if(!drawing){ |
| 127 |
var dn = dojo.byId("gfxObject"); |
| 128 |
drawing = dojox.gfx.createSurface(dn, 300, 300); |
| 129 |
/* SVGWEB { */ |
| 130 |
drawing.whenLoaded(function() { |
| 131 |
drawing.createRect({ |
| 132 |
width: 100, |
| 133 |
height: 100, |
| 134 |
x: 100, |
| 135 |
y: 100 |
| 136 |
}).setFill("blue").setStroke("black"); |
| 137 |
}); |
| 138 |
/* } */ |
| 139 |
} |
| 140 |
if(!ta){ |
| 141 |
ta = dojo.byId("outputArea"); |
| 142 |
} |
| 143 |
}, |
| 144 |
runTest: function(){ |
| 145 |
/* SVGWEB { */ |
| 146 |
drawing.whenLoaded(function() { |
| 147 |
var d = new doh.Deferred(); |
| 148 |
var def= dojox.gfx.utils.toSvg(drawing); |
| 149 |
def.addCallback(function(svg){ |
| 150 |
try{ |
| 151 |
doh.assertTrue(svg != null, "Checking that non-null was returned."); |
| 152 |
ta.value = svg; |
| 153 |
doh.assertTrue(svg.length > 0, "Checking that svg length > 0"); |
| 154 |
doh.assertTrue(svg.toLowerCase().indexOf("<svg") === 0, "Checking that the string starts with SVG open tag."); |
| 155 |
d.callback(true); |
| 156 |
}catch(e){ |
| 157 |
d.errback(e); |
| 158 |
} |
| 159 |
}); |
| 160 |
def.addErrback(function(e){ |
| 161 |
d.errback(e); |
| 162 |
}); |
| 163 |
return d; |
| 164 |
}); |
| 165 |
/* } */ |
| 166 |
} |
| 167 |
}, |
| 168 |
{ |
| 169 |
name: "serialize/deserialize", |
| 170 |
timeout: 1000, |
| 171 |
setUp: function(){ |
| 172 |
if(!drawing){ |
| 173 |
var dn = dojo.byId("gfxObject"); |
| 174 |
drawing = dojox.gfx.createSurface(dn, 300, 300); |
| 175 |
/* SVGWEB { */ |
| 176 |
drawing.whenLoaded(function() { |
| 177 |
drawing.createRect({ |
| 178 |
width: 100, |
| 179 |
height: 100, |
| 180 |
x: 100, |
| 181 |
y: 100 |
| 182 |
}).setFill("blue").setStroke("black"); |
| 183 |
}); |
| 184 |
/* } */ |
| 185 |
} |
| 186 |
if(!ta){ |
| 187 |
ta = dojo.byId("outputArea"); |
| 188 |
} |
| 189 |
}, |
| 190 |
runTest: function(){ |
| 191 |
/* SVGWEB { */ |
| 192 |
drawing.whenLoaded(function() { |
| 193 |
var d = new doh.Deferred(); |
| 194 |
try{ |
| 195 |
var sObj = dojox.gfx.utils.serialize(drawing); |
| 196 |
doh.assertTrue(sObj != null, "Checking that non-null was returned."); |
| 197 |
|
| 198 |
//Lets try to deserialize it! |
| 199 |
var targetNode = dojo.byId("scratchObject"); |
| 200 |
var tempSurface = dojox.gfx.createSurface(targetNode, 300, 300); |
| 201 |
dojox.gfx.utils.deserialize(tempSurface, sObj); |
| 202 |
var nsJson = dojox.gfx.utils.toJson(tempSurface); |
| 203 |
tempSurface.destroy(); |
| 204 |
|
| 205 |
var obj = dojo.fromJson(nsJson); |
| 206 |
doh.assertTrue(1, obj.length, "Checking that the json is an array of one entry."); |
| 207 |
doh.assertTrue(obj[0].shape != null, "Checking that a toplevel shape object is present."); |
| 208 |
doh.assertEqual("rect", obj[0].shape.type, "Checking that the shape type is rect."); |
| 209 |
doh.assertEqual(100, obj[0].shape.width, "Checking that the width is 100."); |
| 210 |
doh.assertEqual(100, obj[0].shape.height, "Checking that the height is 100."); |
| 211 |
d.callback(true); |
| 212 |
}catch(e){ |
| 213 |
d.errback(e); |
| 214 |
} |
| 215 |
return d; |
| 216 |
}); |
| 217 |
/* } */ |
| 218 |
} |
| 219 |
} |
| 220 |
]); |
| 221 |
doh.run(); |
| 222 |
}); |
| 223 |
</script> |
| 224 |
</head> |
| 225 |
<body class="tundra"> |
| 226 |
<h1>Test of GFX Utils functions</h1> |
| 227 |
This page is intended for testing of the functions of the utils package, such as toJson, fromJson, and toSvg. |
| 228 |
<div id="gfxObject"></div> |
| 229 |
<div id="scratchObject"></div> |
| 230 |
<div> |
| 231 |
<textarea style="width: 100%; height: 300px" id="outputArea"></textarea> |
| 232 |
</div> |
| 233 |
</body> |
| 234 |
</html> |