2005-07-10 04:26:54 +04:00
#!/usr/bin/env smbscript
2005-07-02 09:22:12 +04:00
/ *
2005-07-08 12:19:59 +04:00
test echo pipe calls from ejs
2005-07-02 09:22:12 +04:00
* /
2005-07-11 11:43:36 +04:00
var options = new Object ( ) ;
ok = GetOptions ( ARGV , options ,
"POPT_AUTOHELP" ,
"POPT_COMMON_SAMBA" ,
"POPT_COMMON_CREDENTIALS" ) ;
if ( ok == false ) {
println ( "Failed to parse options: " + options . ERROR ) ;
return - 1 ;
}
2005-07-11 04:23:57 +04:00
libinclude ( "base.js" ) ;
2005-07-02 09:22:12 +04:00
2005-07-07 11:43:45 +04:00
/ *
generate a ramp as an integer array
* /
function ramp _array ( N )
2005-07-02 09:22:12 +04:00
{
2005-07-07 11:43:45 +04:00
var a = new Array ( N ) ;
2005-08-17 06:56:07 +04:00
var data = datablob _init ( ) ;
2005-07-07 11:43:45 +04:00
for ( i = 0 ; i < N ; i ++ ) {
2005-07-07 11:47:30 +04:00
a [ i ] = i ;
2005-07-07 11:43:45 +04:00
}
2005-08-17 06:56:07 +04:00
return data . blobFromArray ( a ) ;
2005-07-07 11:43:45 +04:00
}
2005-07-02 09:22:12 +04:00
2005-07-07 11:43:45 +04:00
/ *
test the echo _AddOne interface
* /
2005-07-28 10:46:03 +04:00
function test _AddOne ( echo )
2005-07-07 11:43:45 +04:00
{
var io = irpcObj ( ) ;
print ( "Testing echo_AddOne\n" ) ;
2005-07-02 15:13:12 +04:00
for ( i = 0 ; i < 10 ; i ++ ) {
2005-07-07 11:43:45 +04:00
io . input . in _data = i ;
2005-07-28 10:46:03 +04:00
status = echo . echo _AddOne ( io ) ;
2005-07-07 11:43:45 +04:00
check _status _ok ( status ) ;
assert ( io . output . out _data == i + 1 ) ;
}
}
/ *
test the echo _EchoData interface
* /
2005-07-28 10:46:03 +04:00
function test _EchoData ( echo )
2005-07-07 11:43:45 +04:00
{
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 ) ;
2005-07-28 10:46:03 +04:00
status = echo . echo _EchoData ( io ) ;
2005-07-07 11:43:45 +04:00
check _status _ok ( status ) ;
2005-08-17 06:56:07 +04:00
assert ( true == echo . blobCompare ( io . input . in _data , io . output . out _data ) ) ;
2005-07-02 15:13:12 +04:00
}
2005-07-02 09:22:12 +04:00
}
2005-07-07 11:47:30 +04:00
/ *
test the echo _SinkData interface
* /
2005-07-28 10:46:03 +04:00
function test _SinkData ( echo )
2005-07-07 11:47:30 +04:00
{
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 ) ;
2005-07-28 10:46:03 +04:00
status = echo . echo _SinkData ( io ) ;
2005-07-07 11:47:30 +04:00
check _status _ok ( status ) ;
}
}
/ *
test the echo _SourceData interface
* /
2005-07-28 10:46:03 +04:00
function test _SourceData ( echo )
2005-07-07 11:47:30 +04:00
{
var io = irpcObj ( ) ;
print ( "Testing echo_SourceData\n" ) ;
for ( i = 0 ; i < 30 ; i = i + 5 ) {
io . input . len = i ;
2005-07-28 10:46:03 +04:00
status = echo . echo _SourceData ( io ) ;
2005-07-07 11:47:30 +04:00
check _status _ok ( status ) ;
correct = ramp _array ( i ) ;
2005-08-17 06:56:07 +04:00
assert ( true == echo . blobCompare ( correct , io . output . data ) ) ;
2005-07-07 11:47:30 +04:00
}
}
2005-07-07 12:21:45 +04:00
/ *
test the echo _TestCall interface
* /
2005-07-28 10:46:03 +04:00
function test _TestCall ( echo )
2005-07-07 12:21:45 +04:00
{
var io = irpcObj ( ) ;
print ( "Testing echo_TestCall\n" ) ;
io . input . s1 = "my test string" ;
2005-07-28 10:46:03 +04:00
status = echo . echo _TestCall ( io ) ;
2005-07-07 12:21:45 +04:00
check _status _ok ( status ) ;
assert ( "this is a test string" == io . output . s2 ) ;
}
2005-07-08 07:11:17 +04:00
/ *
test the echo _TestCall2 interface
* /
2005-07-28 10:46:03 +04:00
function test _TestCall2 ( echo )
2005-07-08 07:11:17 +04:00
{
var io = irpcObj ( ) ;
print ( "Testing echo_TestCall2\n" ) ;
for ( i = 1 ; i <= 7 ; i ++ ) {
io . input . level = i ;
2005-07-28 10:46:03 +04:00
status = echo . echo _TestCall2 ( io ) ;
2005-07-08 07:11:17 +04:00
check _status _ok ( status ) ;
}
}
2005-07-08 08:08:17 +04:00
/ *
test the echo _TestSleep interface
* /
2005-07-28 10:46:03 +04:00
function test _TestSleep ( echo )
2005-07-08 08:08:17 +04:00
{
var io = irpcObj ( ) ;
print ( "Testing echo_TestSleep\n" ) ;
io . input . seconds = 1 ;
2005-07-28 10:46:03 +04:00
status = echo . echo _TestSleep ( io ) ;
2005-07-08 08:08:17 +04:00
check _status _ok ( status ) ;
}
/ *
test the echo _TestEnum interface
* /
2005-07-28 10:46:03 +04:00
function test _TestEnum ( echo )
2005-07-08 08:08:17 +04:00
{
var io = irpcObj ( ) ;
print ( "Testing echo_TestEnum\n" ) ;
2005-07-15 11:18:23 +04:00
io . input . foo1 = echo . ECHO _ENUM1 ;
2005-07-08 08:08:17 +04:00
io . input . foo2 = new Object ( ) ;
2005-07-15 11:18:23 +04:00
io . input . foo2 . e1 = echo . ECHO _ENUM1 ;
io . input . foo2 . e2 = echo . ECHO _ENUM1 _32 ;
2005-07-08 08:08:17 +04:00
io . input . foo3 = new Object ( ) ;
2005-07-15 11:18:23 +04:00
io . input . foo3 . e1 = echo . ECHO _ENUM2 ;
2005-07-28 10:46:03 +04:00
status = echo . echo _TestEnum ( io ) ;
2005-07-08 08:08:17 +04:00
check _status _ok ( status ) ;
2005-07-15 11:18:23 +04:00
assert ( io . output . foo1 == echo . ECHO _ENUM1 ) ;
assert ( io . output . foo2 . e1 == echo . ECHO _ENUM2 ) ;
assert ( io . output . foo2 . e2 == echo . ECHO _ENUM1 _32 ) ;
assert ( io . output . foo3 . e1 == echo . ECHO _ENUM2 ) ;
2005-07-08 08:08:17 +04:00
}
2005-07-08 08:16:36 +04:00
/ *
test the echo _TestSurrounding interface
* /
2005-07-28 10:46:03 +04:00
function test _TestSurrounding ( echo )
2005-07-08 08:16:36 +04:00
{
var io = irpcObj ( ) ;
print ( "Testing echo_TestSurrounding\n" ) ;
io . input . data = new Object ( ) ;
io . input . data . x = 10 ;
2005-08-17 06:56:07 +04:00
io . input . data . surrounding = new Array ( 10 ) ;
2005-07-28 10:46:03 +04:00
status = echo . echo _TestSurrounding ( io ) ;
2005-07-08 08:16:36 +04:00
check _status _ok ( status ) ;
assert ( io . output . data . surrounding . length == 20 ) ;
check _array _zero ( io . output . data . surrounding ) ;
}
/ *
test the echo _TestDoublePointer interface
* /
2005-07-28 10:46:03 +04:00
function test _TestDoublePointer ( echo )
2005-07-08 08:16:36 +04:00
{
var io = irpcObj ( ) ;
print ( "Testing echo_TestDoublePointer\n" ) ;
io . input . data = 7 ;
2005-07-28 10:46:03 +04:00
status = echo . echo _TestDoublePointer ( io ) ;
2005-07-08 08:16:36 +04:00
check _status _ok ( status ) ;
assert ( io . input . data == io . input . data ) ;
}
2005-07-07 12:21:45 +04:00
2005-07-11 11:43:36 +04:00
if ( options . ARGV . length != 1 ) {
2005-07-28 10:46:03 +04:00
println ( "Usage: echo.js <BINDING>" ) ;
2005-07-11 11:43:36 +04:00
return - 1 ;
}
var binding = options . ARGV [ 0 ] ;
2005-07-28 10:46:03 +04:00
var echo = rpcecho _init ( ) ;
2005-08-17 06:56:07 +04:00
datablob _init ( echo ) ;
2005-07-07 11:43:45 +04:00
print ( "Connecting to " + binding + "\n" ) ;
2005-07-28 10:46:03 +04:00
status = echo . connect ( binding ) ;
2005-07-07 11:43:45 +04:00
if ( status . is _ok != true ) {
2005-07-28 10:46:03 +04:00
printf ( "Failed to connect to %s - %s\n" , binding , status . errstr ) ;
2005-07-07 11:43:45 +04:00
return ;
}
2005-07-28 10:46:03 +04:00
test _AddOne ( echo ) ;
test _EchoData ( echo ) ;
test _SinkData ( echo ) ;
test _SourceData ( echo ) ;
test _TestCall ( echo ) ;
test _TestCall2 ( echo ) ;
test _TestSleep ( echo ) ;
test _TestEnum ( echo ) ;
test _TestSurrounding ( echo ) ;
test _TestDoublePointer ( echo ) ;
2005-07-02 09:22:12 +04:00
2005-07-07 11:43:45 +04:00
print ( "All OK\n" ) ;
2005-07-10 04:19:41 +04:00
return 0 ;