Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 56 lines (48 sloc) 1.588 kb
b2683f2 @mrdomino start message module
authored
1 <!doctype html>
2 <title>message test</title>
3 <script src="../closure-library/closure/goog/base.js"></script>
4 <script src="deps.js"></script>
5 <script>
6 goog.require('message');
7
8 goog.require('goog.functions');
9 goog.require('goog.testing.jsunit');
10 </script>
11 <body>
12 <script>
13
14 function testDecodeEncodeIsIdentity() {
15 var enc_dec = goog.functions.compose(message.decode, message.encode);
16 assertEquals("", enc_dec(""));
17 assertEquals("secret", enc_dec("secret"));
18 assertEquals("bob dole", enc_dec("bob dole"));
e91069a @mrdomino encode yields arraybuffer
authored
19 assertEquals("‘te�st’", enc_dec("‘te�st’"));
b2683f2 @mrdomino start message module
authored
20 assertThrows(goog.partial(message.encode, null));
21 }
22
e91069a @mrdomino encode yields arraybuffer
authored
23 function testEncodeYieldsArrayBuffer() {
24 var encoded = message.encode("secret message");
25 var view = new Uint8Array(encoded);
26 assertTrue(view.length > 0);
27 var x = view[view.length - 1];
28 view[view.length - 1] ^= 0x01;
29 assertNotEquals(x, view[view.length - 1]);
30 }
31
a937cc6 @mrdomino Message module works.
authored
32 function testVerifyDetectsMessageChanges() {
33 var encoded = message.encode("secret message");
34 assertTrue(message.verify(encoded));
35 var view = new Uint8Array(encoded);
36 view[view.length - 1] ^= 0x01;
37 assertFalse(message.verify(encoded));
38 assertThrows(goog.partial(message.decode, encoded));
39 }
40
41 function testEncodeEmbedsVersion() {
42 var encoded = message.encode("kwijibo");
43 var view = new Uint8Array(encoded);
44 assertEquals(0x01, view[0]);
45 }
46
47 function testVerifyRejectsBadVersions() {
48 var encoded = message.encode("bob");
49 assertTrue(message.verify(encoded));
50 var view = new Uint8Array(encoded);
51 view[0] = 0x02;
52 assertFalse(message.verify(encoded));
53 }
54
b2683f2 @mrdomino start message module
authored
55 </script>
Something went wrong with that request. Please try again.