2 demonstrate access to rpc calls from ejs
7 helper function to setup a rpc io object, ready for input
12 o.input = new Object();
17 generate a ramp as an integer array
19 function ramp_array(N)
30 check that a status result is OK
32 function check_status_ok(status)
34 if (status.is_ok != true) {
37 assert(status.is_ok == true);
41 check that two arrays are equal
43 function check_array_equal(a1, a2)
45 assert(a1.length == a2.length);
46 for (i=0; i<a1.length; i++) {
47 assert(a1[i] == a2[i]);
52 check that an array is all zeros
54 function check_array_zero(a)
56 for (i=0; i<a.length; i++) {
62 test the echo_AddOne interface
64 function test_AddOne(conn)
68 print("Testing echo_AddOne\n");
72 status = dcerpc_echo_AddOne(conn, io);
73 check_status_ok(status);
74 assert(io.output.out_data == i + 1);
79 test the echo_EchoData interface
81 function test_EchoData(conn)
85 print("Testing echo_EchoData\n");
87 for (i=0; i<30; i=i+5) {
89 io.input.in_data = ramp_array(i);
90 status = dcerpc_echo_EchoData(conn, io);
91 check_status_ok(status);
92 check_array_equal(io.input.in_data, io.output.out_data);
98 test the echo_SinkData interface
100 function test_SinkData(conn)
104 print("Testing echo_SinkData\n");
106 for (i=0; i<30; i=i+5) {
108 io.input.data = ramp_array(i);
109 status = dcerpc_echo_SinkData(conn, io);
110 check_status_ok(status);
116 test the echo_SourceData interface
118 function test_SourceData(conn)
122 print("Testing echo_SourceData\n");
124 for (i=0; i<30; i=i+5) {
126 status = dcerpc_echo_SourceData(conn, io);
127 check_status_ok(status);
128 correct = ramp_array(i);
129 check_array_equal(correct, io.output.data);
135 test the echo_TestCall interface
137 function test_TestCall(conn)
141 print("Testing echo_TestCall\n");
143 io.input.s1 = "my test string";
144 status = dcerpc_echo_TestCall(conn, io);
145 check_status_ok(status);
146 assert("this is a test string" == io.output.s2);
150 test the echo_TestCall2 interface
152 function test_TestCall2(conn)
156 print("Testing echo_TestCall2\n");
160 status = dcerpc_echo_TestCall2(conn, io);
161 check_status_ok(status);
166 test the echo_TestSleep interface
168 function test_TestSleep(conn)
172 print("Testing echo_TestSleep\n");
174 io.input.seconds = 1;
175 status = dcerpc_echo_TestSleep(conn, io);
176 check_status_ok(status);
180 test the echo_TestEnum interface
182 function test_TestEnum(conn)
186 print("Testing echo_TestEnum\n");
188 io.input.foo1 = ECHO_ENUM1;
189 io.input.foo2 = new Object();
190 io.input.foo2.e1 = ECHO_ENUM1;
191 io.input.foo2.e2 = ECHO_ENUM1_32;
192 io.input.foo3 = new Object();
193 io.input.foo3.e1 = ECHO_ENUM2;
194 status = dcerpc_echo_TestEnum(conn, io);
195 check_status_ok(status);
196 assert(io.output.foo1 == ECHO_ENUM1);
197 assert(io.output.foo2.e1 == ECHO_ENUM2);
198 assert(io.output.foo2.e2 == ECHO_ENUM1_32);
199 assert(io.output.foo3.e1 == ECHO_ENUM2);
203 test the echo_TestSurrounding interface
205 function test_TestSurrounding(conn)
209 print("Testing echo_TestSurrounding\n");
211 io.input.data = new Object();
212 io.input.data.x = 10;
213 io.input.data.surrounding = ramp_array(10);
214 status = dcerpc_echo_TestSurrounding(conn, io);
215 check_status_ok(status);
216 assert(io.output.data.surrounding.length == 20);
217 check_array_zero(io.output.data.surrounding);
221 test the echo_TestDoublePointer interface
223 function test_TestDoublePointer(conn)
227 print("Testing echo_TestDoublePointer\n");
230 status = dcerpc_echo_TestDoublePointer(conn, io);
231 check_status_ok(status);
232 assert(io.input.data == io.input.data);
236 if (ARGV.length == 0) {
237 print("Usage: echo.js <RPCBINDING>\n");
241 var binding = ARGV[0];
242 var conn = new Object();
244 print("Connecting to " + binding + "\n");
245 status = rpc_connect(conn, binding, "rpcecho");
246 if (status.is_ok != true) {
247 print("Failed to connect to " + binding + " - " + status.errstr + "\n");
254 test_SourceData(conn);
256 test_TestCall2(conn);
257 test_TestSleep(conn);
259 test_TestSurrounding(conn);
260 test_TestDoublePointer(conn);