1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
36 #include <osl/process.h>
37 #include <rtl/ustring.h>
39 // clear Name for the Pipe
40 const char pszPipeName
[] = "TestPipe";
41 const char szTestString
[] = "This is a test";
48 // osl specific variables
51 oslProcess Process
= NULL
;
52 oslProcessError ProcessError
;
53 oslProcessInfo ProcessInfo
;
55 void fail( const char * pszText
, int retval
)
57 fprintf( stderr
, "TestPipe Server: %s", pszText
);
58 fprintf( stderr
, "TestPipe Server: test failed, ErrNo: %d.\n", retval
);
60 if( Process
) osl_freeProcessHandle( Process
);
67 * Test the Pipe-Implementation in osl
70 int main (int argc
, const char *argv
[])
73 rtl_uString
* ustrPipeName
=0;
74 rtl_uString
* ustrExeName
=0;
77 rtl_uString_newFromAscii(&ustrPipeName
,pszPipeName
);
78 rtl_uString_newFromAscii(&ustrExeName
, "//./tmp/testpip2.exe");
80 Pipe
= osl_createPipe( ustrPipeName
, osl_Pipe_CREATE
, 0 );
83 fail( "unable to create Pipe.\n",
84 osl_getLastPipeError(NULL
));
86 // start client process
87 ProcessError
= osl_executeProcess( ustrExeName
,
97 if( ProcessError
!= osl_Process_E_None
)
98 fail( "unable to start client.\n", ProcessError
);
100 // wait for connection
101 C1Pipe
= osl_acceptPipe( Pipe
);
104 fail( "unable to connect to client.\n",
105 osl_getLastPipeError( Pipe
));
111 n
= strlen( cp
) + 1;
116 n
= sizeof(szTestString
);
119 // send TestString to Client
120 nChars
= osl_sendPipe( C1Pipe
, cp
, n
);
123 fail( "unable to write on pipe.\n",
124 osl_getLastPipeError( Pipe
) );
126 // receive data from the server
127 nChars
= osl_receivePipe( C1Pipe
, szBuffer
, 256 );
130 fail( "unable to read from pipe.\n",
131 osl_getLastPipeError( C1Pipe
) );
133 printf( "TestPipe Server: received data: %s.\n", szBuffer
);
135 // wait until the client-program terminates
136 ProcessError
= osl_joinProcess( Process
);
138 if( ProcessError
!= osl_Process_E_None
)
139 fail( "unable to wait for client.\n",
142 // investigate the return-value of the client-program
143 ProcessInfo
.Size
= sizeof( ProcessInfo
);
145 ProcessError
= osl_getProcessInfo( Process
, osl_Process_EXITCODE
, &ProcessInfo
);
147 if( ProcessError
!= osl_Process_E_None
)
148 fail( "unable to receive return value of client process.\n",
151 if( ProcessInfo
.Code
!= 0 )
152 fail( "client aborted.\n", ProcessInfo
.Code
);
154 // give the handle for the free client-process
155 osl_freeProcessHandle( Process
);
158 osl_releasePipe( C1Pipe
);
159 osl_releasePipe( Pipe
);
161 printf( "TestPipe Server: test passed.\n" );
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */