1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testpipe.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sal.hxx"
40 #include <osl/process.h>
41 #include <rtl/ustring.h>
43 // eindeutiger Name f�r die Pipe
44 const char pszPipeName
[] = "TestPipe";
45 const char szTestString
[] = "This is a test";
52 // osl specific variables
55 oslProcess Process
= NULL
;
56 oslProcessError ProcessError
;
57 oslProcessInfo ProcessInfo
;
59 void fail( const char * pszText
, int retval
)
61 fprintf( stderr
, "TestPipe Server: %s", pszText
);
62 fprintf( stderr
, "TestPipe Server: test failed, ErrNo: %d.\n", retval
);
64 if( Process
) osl_freeProcessHandle( Process
);
71 * Teste die Pipe-Implementation in osl
74 int main (int argc
, const char *argv
[])
77 rtl_uString
* ustrPipeName
=0;
78 rtl_uString
* ustrExeName
=0;
81 rtl_uString_newFromAscii(&ustrPipeName
,pszPipeName
);
82 rtl_uString_newFromAscii(&ustrExeName
, "//./tmp/testpip2.exe");
84 Pipe
= osl_createPipe( ustrPipeName
, osl_Pipe_CREATE
, 0 );
87 fail( "unable to create Pipe.\n",
88 osl_getLastPipeError(NULL
));
90 // starte client process
91 ProcessError
= osl_executeProcess( ustrExeName
,
102 if( ProcessError
!= osl_Process_E_None
)
103 fail( "unable to start client.\n", ProcessError
);
105 // wait for connection
106 C1Pipe
= osl_acceptPipe( Pipe
);
109 fail( "unable to connect to client.\n",
110 osl_getLastPipeError( Pipe
));
116 n
= strlen( cp
) + 1;
121 n
= sizeof(szTestString
);
124 // sende TestString zum Client
125 nChars
= osl_sendPipe( C1Pipe
, cp
, n
);
128 fail( "unable to write on pipe.\n",
129 osl_getLastPipeError( Pipe
) );
131 // empfange Daten vom Server
132 nChars
= osl_receivePipe( C1Pipe
, szBuffer
, 256 );
135 fail( "unable to read from pipe.\n",
136 osl_getLastPipeError( C1Pipe
) );
138 printf( "TestPipe Server: received data: %s.\n", szBuffer
);
140 // warte bis das Client-Programm sich beendet
141 ProcessError
= osl_joinProcess( Process
);
143 if( ProcessError
!= osl_Process_E_None
)
144 fail( "unable to wait for client.\n",
147 // ermittle den R�ckgabewert des Client-Programms
148 ProcessInfo
.Size
= sizeof( ProcessInfo
);
150 ProcessError
= osl_getProcessInfo( Process
, osl_Process_EXITCODE
, &ProcessInfo
);
152 if( ProcessError
!= osl_Process_E_None
)
153 fail( "unable to receive return value of client process.\n",
156 if( ProcessInfo
.Code
!= 0 )
157 fail( "client aborted.\n", ProcessInfo
.Code
);
159 // gib das Handle fuer den Client-Prozess frei
160 osl_freeProcessHandle( Process
);
162 // schliesse die Pipes
163 osl_destroyPipe( C1Pipe
);
164 osl_destroyPipe( Pipe
);
166 printf( "TestPipe Server: test passed.\n" );