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
);
56 * Test the Pipe-Implementation in osl
59 int main (int argc
, const char *argv
[])
62 rtl_uString
* ustrPipeName
=0;
63 rtl_uString
* ustrExeName
=0;
66 rtl_uString_newFromAscii(&ustrPipeName
,pszPipeName
);
67 rtl_uString_newFromAscii(&ustrExeName
, "//./tmp/testpip2.exe");
69 Pipe
= osl_createPipe( ustrPipeName
, osl_Pipe_CREATE
, 0 );
72 fail( "unable to create Pipe.\n",
73 osl_getLastPipeError(NULL
));
75 // start client process
76 ProcessError
= osl_executeProcess( ustrExeName
,
86 if( ProcessError
!= osl_Process_E_None
)
87 fail( "unable to start client.\n", ProcessError
);
89 // wait for connection
90 C1Pipe
= osl_acceptPipe( Pipe
);
93 fail( "unable to connect to client.\n",
94 osl_getLastPipeError( Pipe
));
100 n
= strlen( cp
) + 1;
105 n
= sizeof(szTestString
);
108 // send TestString to Client
109 nChars
= osl_sendPipe( C1Pipe
, cp
, n
);
112 fail( "unable to write on pipe.\n",
113 osl_getLastPipeError( Pipe
) );
115 // receive data from the server
116 nChars
= osl_receivePipe( C1Pipe
, szBuffer
, 256 );
119 fail( "unable to read from pipe.\n",
120 osl_getLastPipeError( C1Pipe
) );
122 printf( "TestPipe Server: received data: %s.\n", szBuffer
);
124 // wait until the client-program terminates
125 ProcessError
= osl_joinProcess( Process
);
127 if( ProcessError
!= osl_Process_E_None
)
128 fail( "unable to wait for client.\n",
131 // investigate the return-value of the client-program
132 ProcessInfo
.Size
= sizeof( ProcessInfo
);
134 ProcessError
= osl_getProcessInfo( Process
, osl_Process_EXITCODE
, &ProcessInfo
);
136 if( ProcessError
!= osl_Process_E_None
)
137 fail( "unable to receive return value of client process.\n",
140 if( ProcessInfo
.Code
!= 0 )
141 fail( "client aborted.\n", ProcessInfo
.Code
);
143 // give the handle for the free client-process
144 osl_freeProcessHandle( Process
);
147 osl_releasePipe( C1Pipe
);
148 osl_releasePipe( Pipe
);
150 printf( "TestPipe Server: test passed.\n" );
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */