r18161: Fix LDB build after popt changes.
[Samba/ekacnet.git] / testprogs / ejs / echo.js
blobefdbe5783d8a63ee00d6f4da5a9b1caa109e94f7
1 #!/usr/bin/env smbscript
2 /*
3         test echo pipe calls from ejs
4 */      
6 var options = GetOptions(ARGV, 
7                 "POPT_AUTOHELP",
8                 "POPT_COMMON_SAMBA",
9                 "POPT_COMMON_CREDENTIALS");
10 if (options == undefined) {
11    println("Failed to parse options");
12    return -1;
15 libinclude("base.js");
18   generate a ramp as an integer array
19  */
20 function ramp_array(N)
22         var a = new Array(N);
23         var data = datablob_init();
24         for (i=0;i<N;i++) {
25                 a[i] = i;
26         }
27         return data.blobFromArray(a);
32   test the echo_AddOne interface
34 function test_AddOne(echo)
36         var io = irpcObj();
38         print("Testing echo_AddOne\n");
40         for (i=0;i<10;i++) {
41                 io.input.in_data = i;
42                 status = echo.echo_AddOne(io);
43                 check_status_ok(status);
44                 assert(io.output.out_data == i + 1);
45         }
49   test the echo_EchoData interface
51 function test_EchoData(echo)
53         var io = irpcObj();
55         print("Testing echo_EchoData\n");
57         for (i=0; i<30; i=i+5) {
58                 io.input.len = i;
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));
63         }
68   test the echo_SinkData interface
70 function test_SinkData(echo)
72         var io = irpcObj();
74         print("Testing echo_SinkData\n");
76         for (i=0; i<30; i=i+5) {
77                 io.input.len = i;
78                 io.input.data = ramp_array(i);
79                 status = echo.echo_SinkData(io);
80                 check_status_ok(status);
81         }
86   test the echo_SourceData interface
88 function test_SourceData(echo)
90         var io = irpcObj();
92         print("Testing echo_SourceData\n");
94         for (i=0; i<30; i=i+5) {
95                 io.input.len = i;
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));
100         }
105   test the echo_TestCall interface
107 function test_TestCall(echo)
109         var io = irpcObj();
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)
124         var io = irpcObj();
126         print("Testing echo_TestCall2\n");
128         for (i=1;i<=7;i++) {
129                 io.input.level = i;
130                 status = echo.echo_TestCall2(io);
131                 check_status_ok(status);
132         }
136   test the echo_TestSleep interface
138 function test_TestSleep(echo)
140         var io = irpcObj();
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)
154         var io = irpcObj();
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)
177         var io = irpcObj();
179         print("Testing echo_TestSurrounding\n");
180         
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)
195         var io = irpcObj();
197         print("Testing echo_TestDoublePointer\n");
198         
199         io.input.data = 7;
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>");
208    return -1;
210 var binding = options.ARGV[0];
211 var echo = rpcecho_init();
212 datablob_init(echo);
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);
218    return;
221 test_AddOne(echo);
222 test_EchoData(echo);
223 test_SinkData(echo);
224 test_SourceData(echo);
225 test_TestCall(echo);
226 test_TestCall2(echo);
227 test_TestSleep(echo);
228 test_TestEnum(echo);
229 test_TestSurrounding(echo);
230 test_TestDoublePointer(echo);
232 println("All OK\n");
233 return 0;