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