forked from crossbario/autobahn-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_serialization_cbor.js
87 lines (67 loc) · 2.32 KB
/
test_serialization_cbor.js
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
///////////////////////////////////////////////////////////////////////////////
//
// AutobahnJS - http://autobahn.ws, http://wamp.ws
//
// A JavaScript library for WAMP ("The Web Application Messaging Protocol").
//
// Copyright (c) Crossbar.io Technologies GmbH and contributors
//
// Licensed under the MIT License.
// http://www.opensource.org/licenses/mit-license.php
//
///////////////////////////////////////////////////////////////////////////////
var autobahn = require('./../index.js');
var testutil = require('./testutil.js');
exports.testCBORSerialization = function (testcase) {
testcase.expect(1);
var test = new testutil.Testlog("test/test_serialization_cbor.txt");
var ser = new autobahn.serializer.CBORSerializer();
var config = {
url: testutil.config.url,
realm: testutil.config.realm,
serializers: [ser]
};
var connection = new autobahn.Connection(config);
connection.onopen = function (session) {
test.log('Connected');
function echo(args) {
return args[0];
}
var endpoints = {
'com.myapp.echo': echo
};
var pl1 = [];
for (var uri in endpoints) {
pl1.push(session.register(uri, endpoints[uri]));
}
autobahn.when.all(pl1).then(
function () {
test.log("All registered.");
test.log("Serializer ID: " + session._socket.serializer.SERIALIZER_ID);
var pl2 = [];
var vals1 = [1.7, "hello", [1, 2, -3], {a: 5, b: "hello2"}, [-9007199254740991, 9007199254740991], null];
for (var i = 0; i < vals1.length; ++i) {
pl2.push(session.call('com.myapp.echo', [vals1[i]]).then(
function (res) {
test.log("Result:", res);
},
function (err) {
test.log("Error:", err.error, err.args, err.kwargs);
}
));
}
autobahn.when.all(pl2).then(function () {
test.log("All finished.");
connection.close();
var chk = test.check();
testcase.ok(!chk, chk);
testcase.done();
});
},
function () {
test.log("Registration failed!", arguments);
}
);
};
connection.open();
};