1 #!/usr/bin/env smbscript
3 test echo pipe calls from ejs
6 var options = GetOptions(ARGV,
9 "POPT_COMMON_CREDENTIALS");
10 if (options == undefined) {
11 println("Failed to parse options");
15 libinclude("base.js");
18 generate a ramp as an integer array
20 function ramp_array(N)
23 var data = datablob_init();
27 return data.blobFromArray(a);
32 test the echo_AddOne interface
34 function test_AddOne(echo)
38 print("Testing echo_AddOne\n");
42 status = echo.echo_AddOne(io);
43 check_status_ok(status);
44 assert(io.output.out_data == i + 1);
49 test the echo_EchoData interface
51 function test_EchoData(echo)
55 print("Testing echo_EchoData\n");
57 for (i=0; i<30; i=i+5) {
59 io.input.in_data = ramp_array(i);
60 status = echo.echo_EchoData(io);
61 check_status_ok(status);
62 assert(true == echo.blobCompare(io.input.in_data, io.output.out_data));
68 test the echo_SinkData interface
70 function test_SinkData(echo)
74 print("Testing echo_SinkData\n");
76 for (i=0; i<30; i=i+5) {
78 io.input.data = ramp_array(i);
79 status = echo.echo_SinkData(io);
80 check_status_ok(status);
86 test the echo_SourceData interface
88 function test_SourceData(echo)
92 print("Testing echo_SourceData\n");
94 for (i=0; i<30; i=i+5) {
96 status = echo.echo_SourceData(io);
97 check_status_ok(status);
98 correct = ramp_array(i);
99 assert(true == echo.blobCompare(correct, io.output.data));
105 test the echo_TestCall interface
107 function test_TestCall(echo)
111 print("Testing echo_TestCall\n");
113 io.input.s1 = "my test string";
114 status = echo.echo_TestCall(io);
115 check_status_ok(status);
116 assert("this is a test string" == io.output.s2);
120 test the echo_TestCall2 interface
122 function test_TestCall2(echo)
126 print("Testing echo_TestCall2\n");
130 status = echo.echo_TestCall2(io);
131 check_status_ok(status);
136 test the echo_TestSleep interface
138 function test_TestSleep(echo)
142 print("Testing echo_TestSleep\n");
144 io.input.seconds = 1;
145 status = echo.echo_TestSleep(io);
146 check_status_ok(status);
150 test the echo_TestEnum interface
152 function test_TestEnum(echo)
156 print("Testing echo_TestEnum\n");
158 io.input.foo1 = echo.ECHO_ENUM1;
159 io.input.foo2 = new Object();
160 io.input.foo2.e1 = echo.ECHO_ENUM1;
161 io.input.foo2.e2 = echo.ECHO_ENUM1_32;
162 io.input.foo3 = new Object();
163 io.input.foo3.e1 = echo.ECHO_ENUM2;
164 status = echo.echo_TestEnum(io);
165 check_status_ok(status);
166 assert(io.output.foo1 == echo.ECHO_ENUM1);
167 assert(io.output.foo2.e1 == echo.ECHO_ENUM2);
168 assert(io.output.foo2.e2 == echo.ECHO_ENUM1_32);
169 assert(io.output.foo3.e1 == echo.ECHO_ENUM2);
173 test the echo_TestSurrounding interface
175 function test_TestSurrounding(echo)
179 print("Testing echo_TestSurrounding\n");
181 io.input.data = new Object();
182 io.input.data.x = 10;
183 io.input.data.surrounding = new Array(10);
184 status = echo.echo_TestSurrounding(io);
185 check_status_ok(status);
186 assert(io.output.data.surrounding.length == 20);
187 check_array_zero(io.output.data.surrounding);
191 test the echo_TestDoublePointer interface
193 function test_TestDoublePointer(echo)
197 print("Testing echo_TestDoublePointer\n");
200 status = echo.echo_TestDoublePointer(io);
201 check_status_ok(status);
202 assert(io.input.data == io.input.data);
206 if (options.ARGV.length != 1) {
207 println("Usage: echo.js <BINDING>");
210 var binding = options.ARGV[0];
211 var echo = rpcecho_init();
214 print("Connecting to " + binding + "\n");
215 status = echo.connect(binding);
216 if (status.is_ok != true) {
217 printf("Failed to connect to %s - %s\n", binding, status.errstr);
224 test_SourceData(echo);
226 test_TestCall2(echo);
227 test_TestSleep(echo);
229 test_TestSurrounding(echo);
230 test_TestDoublePointer(echo);