r8298: - started building a library of js routines in scripting/libjs/
[kai/samba.git] / testprogs / ejs / echo.js
1 #!/usr/bin/env smbscript
2 /*
3         test echo pipe calls from ejs
4 */      
5
6 libinclude("base.js");
7
8 /*
9   generate a ramp as an integer array
10  */
11 function ramp_array(N)
12 {
13         var a = new Array(N);
14         for (i=0;i<N;i++) {
15                 a[i] = i;
16         }
17         return a;
18 }
19
20
21 /*
22   test the echo_AddOne interface
23 */
24 function test_AddOne(conn)
25 {
26         var io = irpcObj();
27
28         print("Testing echo_AddOne\n");
29
30         for (i=0;i<10;i++) {
31                 io.input.in_data = i;
32                 status = dcerpc_echo_AddOne(conn, io);
33                 check_status_ok(status);
34                 assert(io.output.out_data == i + 1);
35         }
36 }
37
38 /*
39   test the echo_EchoData interface
40 */
41 function test_EchoData(conn)
42 {
43         var io = irpcObj();
44
45         print("Testing echo_EchoData\n");
46
47         for (i=0; i<30; i=i+5) {
48                 io.input.len = i;
49                 io.input.in_data = ramp_array(i);
50                 status = dcerpc_echo_EchoData(conn, io);
51                 check_status_ok(status);
52                 check_array_equal(io.input.in_data, io.output.out_data);
53         }
54 }
55
56
57 /*
58   test the echo_SinkData interface
59 */
60 function test_SinkData(conn)
61 {
62         var io = irpcObj();
63
64         print("Testing echo_SinkData\n");
65
66         for (i=0; i<30; i=i+5) {
67                 io.input.len = i;
68                 io.input.data = ramp_array(i);
69                 status = dcerpc_echo_SinkData(conn, io);
70                 check_status_ok(status);
71         }
72 }
73
74
75 /*
76   test the echo_SourceData interface
77 */
78 function test_SourceData(conn)
79 {
80         var io = irpcObj();
81
82         print("Testing echo_SourceData\n");
83
84         for (i=0; i<30; i=i+5) {
85                 io.input.len = i;
86                 status = dcerpc_echo_SourceData(conn, io);
87                 check_status_ok(status);
88                 correct = ramp_array(i);
89                 check_array_equal(correct, io.output.data);
90         }
91 }
92
93
94 /*
95   test the echo_TestCall interface
96 */
97 function test_TestCall(conn)
98 {
99         var io = irpcObj();
100
101         print("Testing echo_TestCall\n");
102
103         io.input.s1 = "my test string";
104         status = dcerpc_echo_TestCall(conn, io);
105         check_status_ok(status);
106         assert("this is a test string" == io.output.s2);
107 }
108
109 /*
110   test the echo_TestCall2 interface
111 */
112 function test_TestCall2(conn)
113 {
114         var io = irpcObj();
115
116         print("Testing echo_TestCall2\n");
117
118         for (i=1;i<=7;i++) {
119                 io.input.level = i;
120                 status = dcerpc_echo_TestCall2(conn, io);
121                 check_status_ok(status);
122         }
123 }
124
125 /*
126   test the echo_TestSleep interface
127 */
128 function test_TestSleep(conn)
129 {
130         var io = irpcObj();
131
132         print("Testing echo_TestSleep\n");
133
134         io.input.seconds = 1;
135         status = dcerpc_echo_TestSleep(conn, io);
136         check_status_ok(status);
137 }
138
139 /*
140   test the echo_TestEnum interface
141 */
142 function test_TestEnum(conn)
143 {
144         var io = irpcObj();
145
146         print("Testing echo_TestEnum\n");
147
148         io.input.foo1 = ECHO_ENUM1;
149         io.input.foo2 = new Object();
150         io.input.foo2.e1 = ECHO_ENUM1;
151         io.input.foo2.e2 = ECHO_ENUM1_32;
152         io.input.foo3 = new Object();
153         io.input.foo3.e1 = ECHO_ENUM2;
154         status = dcerpc_echo_TestEnum(conn, io);
155         check_status_ok(status);
156         assert(io.output.foo1    == ECHO_ENUM1);
157         assert(io.output.foo2.e1 == ECHO_ENUM2);
158         assert(io.output.foo2.e2 == ECHO_ENUM1_32);
159         assert(io.output.foo3.e1 == ECHO_ENUM2);
160 }
161
162 /*
163   test the echo_TestSurrounding interface
164 */
165 function test_TestSurrounding(conn)
166 {
167         var io = irpcObj();
168
169         print("Testing echo_TestSurrounding\n");
170         
171         io.input.data = new Object();
172         io.input.data.x = 10;
173         io.input.data.surrounding = ramp_array(10);
174         status = dcerpc_echo_TestSurrounding(conn, io);
175         check_status_ok(status);
176         assert(io.output.data.surrounding.length == 20);
177         check_array_zero(io.output.data.surrounding);
178 }
179
180 /*
181   test the echo_TestDoublePointer interface
182 */
183 function test_TestDoublePointer(conn)
184 {
185         var io = irpcObj();
186
187         print("Testing echo_TestDoublePointer\n");
188         
189         io.input.data = 7;
190         status = dcerpc_echo_TestDoublePointer(conn, io);
191         check_status_ok(status);
192         assert(io.input.data == io.input.data);
193 }
194
195
196 if (ARGV.length == 0) {
197    print("Usage: echo.js <RPCBINDING>\n");
198    exit(0);
199 }
200
201 var binding = ARGV[0];
202 var conn = new Object();
203
204 print("Connecting to " + binding + "\n");
205 status = rpc_connect(conn, binding, "rpcecho");
206 if (status.is_ok != true) {
207    print("Failed to connect to " + binding + " - " + status.errstr + "\n");
208    return;
209 }
210
211 test_AddOne(conn);
212 test_EchoData(conn);
213 test_SinkData(conn);
214 test_SourceData(conn);
215 test_TestCall(conn);
216 test_TestCall2(conn);
217 test_TestSleep(conn);
218 test_TestEnum(conn);
219 test_TestSurrounding(conn);
220 test_TestDoublePointer(conn);
221
222 print("All OK\n");
223 return 0;