1 if(!dojo._hasResource["dojox.encoding.tests.compression.lzw"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.encoding.tests.compression.lzw"] = true;
3 dojo.provide("dojox.encoding.tests.compression.lzw");
4 dojo.require("dojox.encoding.compression.lzw");
5 dojo.require("dojox.encoding.bits");
8 var msg1 = "The rain in Spain falls mainly on the plain.";
9 var msg2 = "The rain in Spain falls mainly on the plain.1";
10 var msg3 = "The rain in Spain falls mainly on the plain.ab";
11 var msg4 = "The rain in Spain falls mainly on the plain.!@#";
12 var dc = dojox.encoding.compression, dcb = dojox.encoding.bits, dcl = dc.lzw;
14 var s2b = function(s){
16 for(var i = 0; i < s.length; ++i){
17 b.push(s.charCodeAt(i));
22 var b2s = function(b){
24 dojo.forEach(b, function(c){ s.push(String.fromCharCode(c)); });
28 var encode = function(msg){
29 var x = new dcb.OutputStream(), encoder = new dcl.Encoder(128);
30 dojo.forEach(s2b(msg), function(v){ encoder.encode(v, x); });
32 console.debug("bits =", x.getWidth());
36 var decode = function(n, buf){
37 var x = new dcb.InputStream(buf, buf.length * 8), decoder = new dcl.Decoder(128), t = [], w = 0;
39 var v = decoder.decode(x);
46 tests.register("dojox.encoding.tests.compression.lzw", [
47 function testLzwMsg1(t){ t.assertEqual(msg1, decode(msg1.length, encode(msg1))); },
48 function testLzwMsg2(t){ t.assertEqual(msg2, decode(msg2.length, encode(msg2))); },
49 function testLzwMsg3(t){ t.assertEqual(msg3, decode(msg3.length, encode(msg3))); },
50 function testLzwMsg4(t){ t.assertEqual(msg4, decode(msg4.length, encode(msg4))); }