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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
// **********************************************************************
//
// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
(function(module, require, exports)
{
var Ice = require("ice").Ice;
var IceSSL = require("ice").IceSSL;
var Test = require("Test").Test;
var Promise = Ice.Promise;
function allTests(communicator, out)
{
var p = new Ice.Promise();
var test = function(b)
{
if(!b)
{
try
{
throw new Error("test failed");
}
catch(err)
{
p.fail(err);
throw err;
}
}
};
var base, testIntf;
var defaultHost = communicator.getProperties().getPropertyWithDefault("Ice.Default.Host");
return Promise.try(
function()
{
out.write("testing proxy endpoint information... ");
var ref = "test -t:default -h tcphost -p 10000 -t 1200 -z --sourceAddress 10.10.10.10:" +
"opaque -e 1.8 -t 100 -v ABCD";
var p1 = communicator.stringToProxy(ref);
var endps = p1.ice_getEndpoints();
var ipEndpoint = endps[0].getInfo();
test(ipEndpoint.host == "tcphost");
test(ipEndpoint.port == 10000);
test(ipEndpoint.timeout == 1200);
test(ipEndpoint.sourceAddress == "10.10.10.10");
test(ipEndpoint.compress);
test(!ipEndpoint.datagram());
test(ipEndpoint.type() == Ice.TCPEndpointType && !ipEndpoint.secure() ||
ipEndpoint.type() == Ice.WSEndpointType && !ipEndpoint.secure() ||
ipEndpoint.type() == Ice.WSSEndpointType && ipEndpoint.secure());
var opaqueEndpoint = endps[1].getInfo();
test(opaqueEndpoint.rawEncoding.equals(new Ice.EncodingVersion(1, 8)));
}
).then(
function()
{
out.writeLine("ok");
out.write("testing connection endpoint information... ");
base = communicator.stringToProxy("test:default -p 12010");
testIntf = Test.TestIntfPrx.uncheckedCast(base);
var ipinfo;
return base.ice_getConnection().then(
function(conn)
{
ipinfo = conn.getEndpoint().getInfo();
test(ipinfo.port == 12010);
test(!ipinfo.compress);
test(ipinfo.host == defaultHost);
return testIntf.getEndpointInfoAsContext();
}
).then(
function(ctx)
{
test(ctx.get("host") == ipinfo.host);
test(ctx.get("compress") == "false");
var port = parseInt(ctx.get("port"));
test(port > 0);
}
);
}
).then(
function()
{
out.writeLine("ok");
out.write("testing connection information... ");
var info, ctx, connection;
return base.ice_getConnection().then(
function(conn)
{
connection = conn;
connection.setBufferSize(1024, 2048);
info = connection.getInfo();
test(!info.incoming);
test(info.adapterName.length === 0);
if(connection.type() != "ws" && connection.type() != "wss")
{
test(info.localPort > 0);
}
test(info.remotePort == 12010);
if(defaultHost == "127.0.0.1")
{
test(info.remoteAddress == defaultHost);
if(connection.type() != "ws" && connection.type() != "wss")
{
test(info.localAddress == defaultHost);
}
}
//test(info.rcvSize >= 1024);
test(info.sndSize >= 2048);
return testIntf.getConnectionInfoAsContext();
}
).then(
function(c)
{
ctx = c;
test(ctx.get("incoming") == "true");
test(ctx.get("adapterName") == "TestAdapter");
if(connection.type() != "ws" && connection.type() != "wss")
{
test(ctx.get("remoteAddress") == info.localAddress);
test(ctx.get("localAddress") == info.remoteAddress);
test(parseInt(ctx.get("remotePort")) == info.localPort);
test(parseInt(ctx.get("localPort")) == info.remotePort);
}
if(connection.type() == "ws" || connection.type() == "wss")
{
//test(info.headers["Upgrade"] == "websocket");
//test(info.headers.get("Connection") == "Upgrade");
//test(info.headers.get("Sec-WebSocket-Protocol") == "ice.zeroc.com");
//test(info.headers.get("Sec-WebSocket-Accept") != null);
test(ctx.get("ws.Upgrade") == "websocket");
test(ctx.get("ws.Connection") == "Upgrade");
test(ctx.get("ws.Sec-WebSocket-Protocol") == "ice.zeroc.com");
test(ctx.get("ws.Sec-WebSocket-Version") == "13");
test(ctx.get("ws.Sec-WebSocket-Key") !== null);
}
}
);
}
).then(
function()
{
out.writeLine("ok");
return testIntf.shutdown();
}
);
}
var run = function(out, id)
{
var communicator = Ice.initialize(id);
return Promise.try(
function()
{
return allTests(communicator, out);
}
).finally(
function()
{
communicator.destroy();
}
);
};
exports.__test__ = run;
exports.__runServer__ = true;
}
(typeof(global) !== "undefined" && typeof(global.process) !== "undefined" ? module : undefined,
typeof(global) !== "undefined" && typeof(global.process) !== "undefined" ? require : window.Ice.__require,
typeof(global) !== "undefined" && typeof(global.process) !== "undefined" ? exports : window));
|