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 .
22 #include <sal/types.h>
23 #include <cppunit/TestAssert.h>
24 #include <cppunit/TestFixture.h>
25 #include <cppunit/extensions/HelperMacros.h>
26 #include <cppunit/plugin/TestPlugIn.h>
27 #include <rtl/ustring.hxx>
29 #include <osl/test/uniquepipename.hxx>
30 #include <osl/thread.hxx>
32 #include <osl/pipe.hxx>
42 /** print last error of pipe system.
44 static void printPipeError( ::osl::Pipe
const & aPipe
)
46 oslPipeError nError
= aPipe
.getError( );
47 printf("#printPipeError# " );
50 printf("Success!\n" );
52 case osl_Pipe_E_NotFound
:
53 printf("The returned error is: Not found!\n" );
55 case osl_Pipe_E_AlreadyExists
:
56 printf("The returned error is: Already exist!\n" );
58 case osl_Pipe_E_NoProtocol
:
59 printf("The returned error is: No protocol!\n" );
61 case osl_Pipe_E_NetworkReset
:
62 printf("The returned error is: Network reset!\n" );
64 case osl_Pipe_E_ConnectionAbort
:
65 printf("The returned error is: Connection aborted!\n" );
67 case osl_Pipe_E_ConnectionReset
:
68 printf("The returned error is: Connection reset!\n" );
70 case osl_Pipe_E_NoBufferSpace
:
71 printf("The returned error is: No buffer space!\n" );
73 case osl_Pipe_E_TimedOut
:
74 printf("The returned error is: Timeout!\n" );
76 case osl_Pipe_E_ConnectionRefused
:
77 printf("The returned error is: Connection refused!\n" );
79 case osl_Pipe_E_invalidError
:
80 printf("The returned error is: Invalid error!\n" );
83 printf("The returned error is: Number %d, Unknown Error\n", nError
);
88 // pipe name and transfer contents
90 constexpr OUStringLiteral
aTestPipeName(u
"testpipe2");
91 constexpr OUStringLiteral
aTestPipe1(u
"testpipe1");
93 constexpr OStringLiteral
m_pTestString1("Sun Microsystems");
94 constexpr OStringLiteral
m_pTestString2("test pipe PASS/OK");
96 // test code start here
101 // most return value -1 denote a fail of operation.
103 #define OSL_PIPE_FAIL -1
105 /** testing the methods:
107 inline Pipe(const OUString& strName, oslPipeOptions Options);
108 inline Pipe(const OUString& strName, oslPipeOptions Options,const Security & rSecurity);
109 inline Pipe(const Pipe& pipe);
110 inline Pipe(oslPipe pipe, __sal_NoAcquire noacquire );
111 inline Pipe(oslPipe Pipe);
113 class ctors
: public CppUnit::TestFixture
116 bool bRes
, bRes1
, bRes2
;
123 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, yet no case to test.",
127 void ctors_name_option( )
129 /// create a named pipe.
130 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
131 ::osl::Pipe
aAssignPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
);
133 bRes
= aPipe
.is( ) && aAssignPipe
.is( );
135 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name and option.",
139 void ctors_name_option_security( )
141 /// create a security pipe.
142 const ::osl::Security rSecurity
;
143 ::osl::Pipe
aSecurityPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
, rSecurity
);
145 bRes
= aSecurityPipe
.is( );
147 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name, option and security, the test of security is not implemented yet.",
154 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
155 /// create a pipe using copy constructor.
156 ::osl::Pipe
aCopyPipe( aPipe
);
158 bRes
= aCopyPipe
.is( ) && aCopyPipe
== aPipe
;
160 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test copy constructor.",
164 /* Note: DO NOT DO THIS - I have very deliberately caused send to FAIL, *on purpose* as this is the
165 only sane way to test noacquire. This is a terrible misuse of no-acquire, but in this case is
166 needed only so we can test to make sure no-acquire is working!
168 void ctors_no_acquire( )
171 OUString
aPipeName(test::uniquePipeName(aTestPipeName
));
172 oslPipe
handle(osl_createPipe(aPipeName
.pData
, osl_Pipe_CREATE
, nullptr));
173 /// constructs a pipe reference without acquiring the handle.
174 std::unique_ptr
<osl::Pipe
> xNoAcquirePipe(new osl::Pipe(handle
, SAL_NO_ACQUIRE
));
176 StreamPipe
aStreamPipe(handle
);
177 xNoAcquirePipe
.reset();
178 int nRet
= aStreamPipe
.send("a", 1);
185 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no acquire of handle, deleted nonacquired pipe but could still send on original pipe!.",
189 void ctors_acquire( )
191 /// create a base pipe.
192 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
193 /// constructs two pipes, the second acquires the first pipe's handle.
194 ::osl::Pipe
aAcquirePipe( aPipe
.getHandle( ) );
195 ::osl::Pipe
aAcquirePipe1( nullptr );
197 bRes
= aAcquirePipe
.is();
198 bRes1
= aAcquirePipe1
.is();
199 bRes2
= aPipe
== aAcquirePipe
;
201 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with acquire of handle, original pipe does not exist.",
203 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with acquire of handle, copied pipe does not exist",
206 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test pipes should have same handle", bRes2
);
209 CPPUNIT_TEST_SUITE( ctors
);
210 CPPUNIT_TEST( ctors_none
);
211 CPPUNIT_TEST( ctors_name_option
);
212 CPPUNIT_TEST( ctors_name_option_security
);
213 CPPUNIT_TEST( ctors_copy
);
214 CPPUNIT_TEST( ctors_no_acquire
);
215 CPPUNIT_TEST( ctors_acquire
);
216 CPPUNIT_TEST_SUITE_END( );
219 /** testing the method:
220 inline sal_Bool SAL_CALL is() const;
222 class is
: public CppUnit::TestFixture
229 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), check if the pipe is a valid one.", !aPipe
.is( ) );
234 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
236 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), a normal pipe creation.", aPipe
.is( ) );
241 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
244 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), an invalid case.", !aPipe
.is( ) );
249 ::osl::Pipe
aPipe( nullptr );
251 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), an invalid constructor.", !aPipe
.is( ) );
254 CPPUNIT_TEST_SUITE( is
);
255 CPPUNIT_TEST( is_001
);
256 CPPUNIT_TEST( is_002
);
257 CPPUNIT_TEST( is_003
);
258 CPPUNIT_TEST( is_004
);
259 CPPUNIT_TEST_SUITE_END( );
262 /** testing the methods:
263 inline sal_Bool create( const OUString & strName,
264 oslPipeOptions Options, const Security &rSec );
265 nline sal_Bool create( const OUString & strName,
266 oslPipeOptions Options = osl_Pipe_OPEN );
268 class create
: public CppUnit::TestFixture
275 security create only be tested creation, security section is
279 void create_named_security_001( )
283 bRes
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
, rSec
);
284 bRes1
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
, rSec
);
287 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.",
289 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.",
293 void create_named_security_002( )
296 ::osl::Pipe aPipe
, aPipe1
;
297 bRes
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
, rSec
);
298 bRes1
= aPipe1
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
, rSec
);
301 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.",
303 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.",
307 void create_named_001( )
310 bRes
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
311 bRes1
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
314 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.",
316 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.",
320 void create_named_002( )
322 ::osl::Pipe aPipe
, aPipe1
;
323 bRes
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
324 bRes1
= aPipe1
.create( test::uniquePipeName(aTestPipeName
) );
327 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.",
329 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.",
333 void create_named_003( )
336 bRes
= aPipe
.create( test::uniquePipeName(aTestPipeName
) );
339 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test default option is open.",
343 CPPUNIT_TEST_SUITE( create
);
344 CPPUNIT_TEST( create_named_security_001
);
345 CPPUNIT_TEST( create_named_security_002
);
346 CPPUNIT_TEST( create_named_001
);
347 CPPUNIT_TEST( create_named_002
);
348 CPPUNIT_TEST( create_named_003
);
349 CPPUNIT_TEST_SUITE_END( );
352 /** testing the method:
353 inline void SAL_CALL clear();
355 class clear
: public CppUnit::TestFixture
363 aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
367 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test clear.",
371 CPPUNIT_TEST_SUITE( clear
);
372 CPPUNIT_TEST( clear_001
);
373 CPPUNIT_TEST_SUITE_END( );
376 /** testing the methods:
377 inline Pipe& SAL_CALL operator= (const Pipe& pipe);
378 inline Pipe& SAL_CALL operator= (const oslPipe pipe );
380 class assign
: public CppUnit::TestFixture
387 ::osl::Pipe aPipe
, aPipe1
;
388 aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
391 bRes1
= aPipe
== aPipe1
;
395 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with reference.",
397 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with reference.",
401 void assign_handle( )
403 ::osl::Pipe aPipe
, aPipe1
;
404 aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
405 aPipe1
= aPipe
.getHandle( );
407 bRes1
= aPipe
== aPipe1
;
411 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with handle.",
413 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with handle.",
417 CPPUNIT_TEST_SUITE( assign
);
418 CPPUNIT_TEST( assign_ref
);
419 CPPUNIT_TEST( assign_handle
);
420 CPPUNIT_TEST_SUITE_END( );
423 /** testing the method:
424 inline sal_Bool SAL_CALL isValid() const;
425 isValid( ) has not been implemented under the following platforms, please refer to osl/pipe.hxx
428 /** testing the method:
429 inline sal_Bool SAL_CALL operator==( const Pipe& rPipe ) const;
431 class isEqual
: public CppUnit::TestFixture
439 aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
440 bRes
= aPipe
== aPipe
; // NOLINT(misc-redundant-expression)
443 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(), compare itself.",
449 ::osl::Pipe aPipe
, aPipe1
, aPipe2
;
450 aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
453 aPipe2
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
455 bRes
= aPipe
== aPipe1
;
456 bRes1
= aPipe
== aPipe2
;
461 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(),create one copy instance, and compare.",
463 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(),create one copy instance, and compare.",
467 CPPUNIT_TEST_SUITE( isEqual
);
468 CPPUNIT_TEST( isEqual_001
);
469 CPPUNIT_TEST( isEqual_002
);
470 CPPUNIT_TEST_SUITE_END( );
473 /** testing the method:
474 inline void SAL_CALL close();
476 class close
: public CppUnit::TestFixture
483 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipe1
), osl_Pipe_CREATE
);
490 CPPUNIT_ASSERT_MESSAGE( "#test comment#: difference between close and clear.",
492 CPPUNIT_ASSERT_MESSAGE( "#test comment#: difference between close and clear.",
498 ::osl::StreamPipe
aPipe( test::uniquePipeName(aTestPipe1
), osl_Pipe_CREATE
);
500 int nRet
= aPipe
.send( m_pTestString1
.getStr(), 3 );
502 CPPUNIT_ASSERT_EQUAL_MESSAGE( "#test comment#: use after close.",
503 OSL_PIPE_FAIL
, nRet
);
506 CPPUNIT_TEST_SUITE( close
);
507 CPPUNIT_TEST( close_001
);
508 CPPUNIT_TEST( close_002
);
509 CPPUNIT_TEST_SUITE_END( );
512 /** testing the method:
513 inline oslPipeError SAL_CALL accept(StreamPipe& Connection);
514 please refer to StreamPipe::recv
517 /** testing the method:
518 inline oslPipeError SAL_CALL getError() const;
520 class getError
: public CppUnit::TestFixture
527 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
);
528 oslPipeError nError
= aPipe
.getError( );
529 printPipeError( aPipe
);
532 CPPUNIT_ASSERT_MESSAGE( "#test comment#: open a non-exist pipe.",
533 nError
!= osl_Pipe_E_None
);
538 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
539 ::osl::Pipe
aPipe1( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
540 oslPipeError nError
= aPipe
.getError( );
541 printPipeError( aPipe
);
545 CPPUNIT_ASSERT_MESSAGE( "#test comment#: create an already exist pipe.",
546 nError
!= osl_Pipe_E_None
);
549 CPPUNIT_TEST_SUITE( getError
);
550 CPPUNIT_TEST( getError_001
);
551 CPPUNIT_TEST( getError_002
);
552 CPPUNIT_TEST_SUITE_END( );
555 /** testing the method:
556 inline oslPipe SAL_CALL getHandle() const;
558 class getHandle
: public CppUnit::TestFixture
563 void getHandle_equalityOperatorAgainstSelf( )
565 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
);
566 bRes
= aPipe
== aPipe
.getHandle( );
569 CPPUNIT_ASSERT_MESSAGE( "#test comment#: one pipe should equal to its handle.",
573 void getHandle_equalityOperatorAgainstDerivedPipe( )
575 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
576 ::osl::Pipe
aPipe1( aPipe
.getHandle( ) );
577 bRes
= aPipe
== aPipe1
;
581 CPPUNIT_ASSERT_MESSAGE( "#test comment#: one pipe derived from another pipe's handle.",
585 CPPUNIT_TEST_SUITE( getHandle
);
586 CPPUNIT_TEST( getHandle_equalityOperatorAgainstSelf
);
587 CPPUNIT_TEST( getHandle_equalityOperatorAgainstDerivedPipe
);
588 CPPUNIT_TEST_SUITE_END( );
591 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::ctors
);
592 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::is
);
593 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::create
);
594 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::clear
);
595 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::assign
);
596 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::isEqual
);
597 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::close
);
598 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::getError
);
599 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::getHandle
);
601 } // namespace osl_Pipe
603 namespace osl_StreamPipe
606 /** testing the methods:
608 inline StreamPipe(oslPipe Pipe);
609 inline StreamPipe(const StreamPipe& Pipe);
610 inline StreamPipe(const OUString& strName, oslPipeOptions Options = osl_Pipe_OPEN);
611 inline StreamPipe(const OUString& strName, oslPipeOptions Options, const Security &rSec );
612 inline StreamPipe( oslPipe pipe, __sal_NoAcquire noacquire );
614 class ctors
: public CppUnit::TestFixture
622 ::osl::StreamPipe
aStreamPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
623 // create an unattached pipe.
624 ::osl::StreamPipe aStreamPipe1
;
625 bRes
= aStreamPipe1
.is( );
627 // assign it and check.
628 aStreamPipe1
= aStreamPipe
;
629 bRes1
= aStreamPipe1
.is( );
630 aStreamPipe
.clear( );
631 aStreamPipe1
.clear( );
633 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, before and after assign.",
635 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, before and after assign.",
642 ::osl::StreamPipe
aStreamPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
643 // create a pipe with last handle.
644 ::osl::StreamPipe
aStreamPipe1( aStreamPipe
.getHandle( ) );
645 bRes
= aStreamPipe1
.is( ) && aStreamPipe
== aStreamPipe1
;
646 aStreamPipe
.clear( );
647 aStreamPipe1
.clear( );
649 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with other's handle.",
656 ::osl::StreamPipe
aStreamPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
657 // create an unattached pipe.
658 ::osl::StreamPipe
aStreamPipe1( aStreamPipe
);
659 bRes
= aStreamPipe1
.is( ) && aStreamPipe
== aStreamPipe1
;
660 aStreamPipe
.clear( );
661 aStreamPipe1
.clear( );
663 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test copy constructor.",
667 void ctors_name_option( )
670 ::osl::StreamPipe
aStreamPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
671 // create an unattached pipe.
672 ::osl::StreamPipe
aStreamPipe1( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
);
673 bRes
= aStreamPipe1
.is( ) && aStreamPipe
.is( );
674 aStreamPipe
.clear( );
675 aStreamPipe1
.clear( );
677 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name and option.",
681 void ctors_name_option_security( )
683 /// create a security pipe.
684 const ::osl::Security rSecurity
;
685 ::osl::StreamPipe
aSecurityPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
, rSecurity
);
687 bRes
= aSecurityPipe
.is( );
688 aSecurityPipe
.clear( );
690 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name, option and security, the test of security is not implemented yet.",
696 When test the following constructor, don't know how to test the
697 acquire and no acquire action. possible plans:
698 1.release one handle and check the other( did not success since the
699 other still exist and valid. )
700 2. release one handle twice to see getLastError( )(the getLastError
701 always returns invalidError(LINUX)).
704 void ctors_no_acquire( )
707 ::osl::StreamPipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
708 osl_acquirePipe(aPipe
.getHandle());
709 // constructs a pipe reference without acquiring the handle.
710 ::osl::StreamPipe
aNoAcquirePipe( aPipe
.getHandle( ), SAL_NO_ACQUIRE
);
712 bRes
= aNoAcquirePipe
.is( );
715 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no acquire of handle, only validation test, do not know how to test no acquire.",
719 CPPUNIT_TEST_SUITE( ctors
);
720 CPPUNIT_TEST( ctors_none
);
721 CPPUNIT_TEST( ctors_handle
);
722 CPPUNIT_TEST( ctors_copy
);
723 CPPUNIT_TEST( ctors_name_option
);
724 CPPUNIT_TEST( ctors_name_option_security
);
725 CPPUNIT_TEST( ctors_no_acquire
);
726 CPPUNIT_TEST_SUITE_END( );
729 /** testing the methods:
730 inline StreamPipe & SAL_CALL operator=(oslPipe Pipe);
731 inline StreamPipe& SAL_CALL operator=(const Pipe& pipe);
732 mindy: not implemented in osl/pipe.hxx, so remove the cases
735 /** wait _nSec seconds.
737 static void thread_sleep( sal_uInt32 _nSec
)
739 /// print statement in thread process must use fflush() to force display.
742 osl::Thread::wait(std::chrono::seconds(_nSec
));
744 // test read/write & send/recv data to pipe
748 class Pipe_DataSink_Thread
: public Thread
752 Pipe_DataSink_Thread( ) { }
755 void SAL_CALL
run( ) override
757 printf("open pipe\n");
758 ::osl::StreamPipe
aSenderPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
); // test::uniquePipeName(aTestPipeName) is a string = "TestPipe"
759 if ( !aSenderPipe
.is() )
761 printf("pipe open failed! \n");
766 sal_Int32 nChars
= aSenderPipe
.read( buf
, m_pTestString1
.getLength() + 1 );
769 printf("read failed! \n");
772 buf
[sizeof(buf
)-1] = '\0';
773 printf("buffer is %s \n", buf
);
775 nChars
= aSenderPipe
.send( m_pTestString2
.getStr(), m_pTestString2
.getLength() + 1 );
778 printf("client send failed! \n");
786 class Pipe_DataSource_Thread
: public Thread
790 ::osl::Pipe aListenPipe
;
791 ::osl::StreamPipe aConnectionPipe
;
792 Pipe_DataSource_Thread( )
794 printf("create pipe\n");
795 aListenPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
797 virtual ~Pipe_DataSource_Thread( ) override
802 void SAL_CALL
run( ) override
806 if ( !aListenPipe
.is() )
808 printf("pipe create failed! \n");
812 //start server and wait for connection.
814 if ( aListenPipe
.accept( aConnectionPipe
) != osl_Pipe_E_None
)
816 printf("pipe accept failed!");
821 sal_Int32 nChars
= aConnectionPipe
.write( m_pTestString1
.getStr(), m_pTestString1
.getLength() + 1 );
824 printf("server write failed! \n");
828 nChars
= aConnectionPipe
.recv( buf
, 256 );
832 printf("server receive failed! \n");
835 buf
[sizeof(buf
)-1] = '\0';
836 printf("received message is: %s\n", buf
);
843 /** testing the method: read/write/send/recv and Pipe::accept
845 class recv
: public CppUnit::TestFixture
853 Pipe_DataSource_Thread myDataSourceThread
;
854 Pipe_DataSink_Thread myDataSinkThread
;
855 myDataSourceThread
.create( );
857 myDataSinkThread
.create( );
859 //wait until the thread terminate
860 myDataSinkThread
.join( );
861 myDataSourceThread
.join( );
863 int nCompare1
= strcmp( myDataSinkThread
.buf
, m_pTestString1
.getStr() );
864 int nCompare2
= strcmp( myDataSourceThread
.buf
, m_pTestString2
.getStr() );
865 CPPUNIT_ASSERT_EQUAL_MESSAGE( "test send/recv/write/read.", 0, nCompare1
);
866 CPPUNIT_ASSERT_EQUAL_MESSAGE( "test send/recv/write/read.", 0, nCompare2
);
868 //close pipe when accept
873 Pipe_DataSource_Thread myDataSourceThread
;
874 Pipe_DataSink_Thread myDataSinkThread
;
875 myDataSourceThread
.create( );
877 myDataSourceThread
.aListenPipe
.close();
878 myDataSourceThread
.join( );
879 //no condition judgment here, if the case could finish executing within 1 or 2 seconds, it passes.
882 CPPUNIT_TEST_SUITE( recv
);
883 CPPUNIT_TEST( recv_001
);
884 CPPUNIT_TEST( recv_002
);
885 CPPUNIT_TEST_SUITE_END( );
888 CPPUNIT_TEST_SUITE_REGISTRATION(osl_StreamPipe::ctors
);
889 //CPPUNIT_TEST_SUITE_REGISTRATION(osl_StreamPipe::assign);
890 CPPUNIT_TEST_SUITE_REGISTRATION(osl_StreamPipe::recv
);
892 } // namespace osl_StreamPipe
894 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */