summaryrefslogtreecommitdiff
path: root/testprogs/ejs/echo.js
blob: 8cdacf8fc6f3ed3b286ce5ba3e6027a925b56cb1 (plain)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
	demonstrate access to rpc calls from ejs
*/	


/*
  helper function to setup a rpc io object, ready for input
*/
function irpcObj()
{
	var o = new Object();
	o.input = new Object();
	return o;
}

/*
  generate a ramp as an integer array
 */
function ramp_array(N)
{
	var a = new Array(N);
	for (i=0;i<N;i++) {
		a[i] = i;
	}
	return a;
}


/*
  check that a status result is OK
*/
function check_status_ok(status)
{
	if (status.is_ok != true) {
		printVars(status);
	}
	assert(status.is_ok == true);
}

/*
  check that two arrays are equal
*/
function check_array_equal(a1, a2)
{
	assert(a1.length == a2.length);
	for (i=0; i<a1.length; i++) {
		assert(a1[i] == a2[i]);
	}
}

/*
  test the echo_AddOne interface
*/
function test_AddOne(conn)
{
	var io = irpcObj();

	print("Testing echo_AddOne\n");

	for (i=0;i<10;i++) {
		io.input.in_data = i;
		status = dcerpc_echo_AddOne(conn, io);
		check_status_ok(status);
		assert(io.output.out_data == i + 1);
	}
}

/*
  test the echo_EchoData interface
*/
function test_EchoData(conn)
{
	var io = irpcObj();

	print("Testing echo_EchoData\n");

	for (i=0; i<30; i=i+5) {
		io.input.len = i;
		io.input.in_data = ramp_array(i);
		status = dcerpc_echo_EchoData(conn, io);
		check_status_ok(status);
		check_array_equal(io.input.in_data, io.output.out_data);
	}
}


/*
  test the echo_SinkData interface
*/
function test_SinkData(conn)
{
	var io = irpcObj();

	print("Testing echo_SinkData\n");

	for (i=0; i<30; i=i+5) {
		io.input.len = i;
		io.input.data = ramp_array(i);
		status = dcerpc_echo_SinkData(conn, io);
		check_status_ok(status);
	}
}


/*
  test the echo_SourceData interface
*/
function test_SourceData(conn)
{
	var io = irpcObj();

	print("Testing echo_SourceData\n");

	for (i=0; i<30; i=i+5) {
		io.input.len = i;
		status = dcerpc_echo_SourceData(conn, io);
		check_status_ok(status);
		correct = ramp_array(i);
		check_array_equal(correct, io.output.data);
	}
}


/*
  test the echo_TestCall interface
*/
function test_TestCall(conn)
{
	var io = irpcObj();

	print("Testing echo_TestCall\n");

	io.input.s1 = "my test string";
	status = dcerpc_echo_TestCall(conn, io);
	check_status_ok(status);
	assert("this is a test string" == io.output.s2);
}

/*
  test the echo_TestCall2 interface
*/
function test_TestCall2(conn)
{
	var io = irpcObj();

	print("Testing echo_TestCall2\n");

	for (i=1;i<=7;i++) {
		io.input.level = i;
		status = dcerpc_echo_TestCall2(conn, io);
		check_status_ok(status);
	}
}

/*
  test the echo_TestSleep interface
*/
function test_TestSleep(conn)
{
	var io = irpcObj();

	print("Testing echo_TestSleep\n");

	io.input.seconds = 1;
	status = dcerpc_echo_TestSleep(conn, io);
	check_status_ok(status);
}

/*
  test the echo_TestEnum interface
*/
function test_TestEnum(conn)
{
	var io = irpcObj();

	print("Testing echo_TestEnum\n");

	io.input.foo1 = 1;
	io.input.foo2 = new Object();
	io.input.foo2.e1 = 1;
	io.input.foo2.e2 = 1;
	io.input.foo3 = new Object();
	io.input.foo3.e1 = 2;
	status = dcerpc_echo_TestEnum(conn, io);
	check_status_ok(status);
	assert(io.output.foo1    == 1);
	assert(io.output.foo2.e1 == 2);
	assert(io.output.foo2.e2 == 1);
	assert(io.output.foo3.e1 == 2);
}


if (ARGV.length == 0) {
   print("Usage: echo.js <RPCBINDING>\n");
   exit(0);
}

var binding = ARGV[0];
var conn = new Object();

print("Connecting to " + binding + "\n");
status = rpc_connect(conn, binding, "rpcecho");
if (status.is_ok != true) {
   print("Failed to connect to " + binding + " - " + status.errstr + "\n");
   return;
}

test_AddOne(conn);
test_EchoData(conn);
test_SinkData(conn);
test_SourceData(conn);
test_TestCall(conn);
test_TestCall2(conn);
test_TestSleep(conn);
test_TestEnum(conn);

print("All OK\n");