1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
25 #include <osl/process.h>
26 #include <rtl/ustring.h>
28 // clear Name for the Pipe
29 const char pszPipeName
[] = "TestPipe";
30 const char szTestString
[] = "This is a test";
37 // osl specific variables
40 oslProcess Process
= NULL
;
41 oslProcessError ProcessError
;
42 oslProcessInfo ProcessInfo
;
44 void fail( const char * pszText
, int retval
)
46 fprintf( stderr
, "TestPipe Server: %s", pszText
);
47 fprintf( stderr
, "TestPipe Server: test failed, ErrNo: %d.\n", retval
);
49 if( Process
) osl_freeProcessHandle( Process
);
54 * Test the Pipe-Implementation in osl
57 int main (int argc
, const char *argv
[])
60 rtl_uString
* ustrPipeName
=0;
61 rtl_uString
* ustrExeName
=0;
63 rtl_uString_newFromAscii(&ustrPipeName
,pszPipeName
);
64 rtl_uString_newFromAscii(&ustrExeName
, "//./tmp/testpip2.exe");
66 Pipe
= osl_createPipe( ustrPipeName
, osl_Pipe_CREATE
, 0 );
69 fail( "unable to create Pipe.\n",
70 osl_getLastPipeError(NULL
));
72 // start client process
73 ProcessError
= osl_executeProcess( ustrExeName
,
83 if( ProcessError
!= osl_Process_E_None
)
84 fail( "unable to start client.\n", ProcessError
);
86 // wait for connection
87 C1Pipe
= osl_acceptPipe( Pipe
);
90 fail( "unable to connect to client.\n",
91 osl_getLastPipeError( Pipe
));
101 n
= sizeof(szTestString
);
104 // send TestString to Client
105 nChars
= osl_sendPipe( C1Pipe
, cp
, n
);
108 fail( "unable to write on pipe.\n",
109 osl_getLastPipeError( Pipe
) );
111 // receive data from the server
112 nChars
= osl_receivePipe( C1Pipe
, szBuffer
, 256 );
115 fail( "unable to read from pipe.\n",
116 osl_getLastPipeError( C1Pipe
) );
118 printf( "TestPipe Server: received data: %s.\n", szBuffer
);
120 // wait until the client-program terminates
121 ProcessError
= osl_joinProcess( Process
);
123 if( ProcessError
!= osl_Process_E_None
)
124 fail( "unable to wait for client.\n",
127 // investigate the return-value of the client-program
128 ProcessInfo
.Size
= sizeof( ProcessInfo
);
130 ProcessError
= osl_getProcessInfo( Process
, osl_Process_EXITCODE
, &ProcessInfo
);
132 if( ProcessError
!= osl_Process_E_None
)
133 fail( "unable to receive return value of client process.\n",
136 if( ProcessInfo
.Code
!= 0 )
137 fail( "client aborted.\n", ProcessInfo
.Code
);
139 // give the handle for the free client-process
140 osl_freeProcessHandle( Process
);
143 osl_releasePipe( C1Pipe
);
144 osl_releasePipe( Pipe
);
146 printf( "TestPipe Server: test passed.\n" );
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */