Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.encoding.tests.splay"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.encoding.tests.splay"] = true;
3
dojo.provide("dojox.encoding.tests.splay");
4
dojo.require("dojox.encoding.splay");
5
dojo.require("dojox.encoding.bits");
6
 
7
(function(){
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, dcb = dc.bits;
13
 
14
	var s2b = function(s){
15
		var b = [];
16
		for(var i = 0; i < s.length; ++i){
17
			b.push(s.charCodeAt(i));
18
		}
19
		return b;
20
	};
21
 
22
	var b2s = function(b){
23
		var s = [];
24
		dojo.forEach(b, function(c){ s.push(String.fromCharCode(c)); });
25
		return s.join("");
26
	};
27
 
28
	var encode = function(msg){
29
		var x = new dcb.OutputStream(), encoder = new dc.Splay(256);
30
		dojo.forEach(s2b(msg), function(v){ encoder.encode(v, x); });
31
		console.debug("bits =", x.getWidth());
32
		return x.getBuffer();
33
	};
34
 
35
	var decode = function(n, buf){
36
		var x = new dcb.InputStream(buf, buf.length * 8), decoder = new dc.Splay(256), t = [];
37
		for(var i = 0; i < n; ++i){ t.push(decoder.decode(x)); }
38
		return b2s(t);
39
	};
40
 
41
	tests.register("dojox.encoding.tests.splay", [
42
		function testSplayMsg1(t){ t.assertEqual(msg1, decode(msg1.length, encode(msg1))); },
43
		function testSplayMsg2(t){ t.assertEqual(msg2, decode(msg2.length, encode(msg2))); },
44
		function testSplayMsg3(t){ t.assertEqual(msg3, decode(msg3.length, encode(msg3))); },
45
		function testSplayMsg4(t){ t.assertEqual(msg4, decode(msg4.length, encode(msg4))); }
46
	]);
47
})();
48
 
49
}