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"
31 //------------------------------------------------------------------------
33 //------------------------------------------------------------------------
35 #include "cppunit/TestAssert.h"
36 #include "cppunit/TestFixture.h"
37 #include "cppunit/extensions/HelperMacros.h"
38 #include "cppunit/plugin/TestPlugIn.h"
39 #include "test/uniquepipename.hxx"
40 #include <sal/types.h>
41 #include <rtl/ustring.hxx>
43 #ifndef _OSL_THREAD_HXX
44 #include <osl/thread.hxx>
47 #ifndef _OSL_MUTEX_HXX
48 #include <osl/mutex.hxx>
51 #ifndef _OSL_MUTEX_HXX
52 #include <osl/pipe.hxx>
64 //------------------------------------------------------------------------
66 //------------------------------------------------------------------------
68 /** print Boolean value.
70 inline void printBool( sal_Bool bOk
)
72 printf("#printBool# " );
73 ( sal_True
== bOk
) ? printf("YES!\n" ): printf("NO!\n" );
76 /** print a UNI_CODE String.
78 inline void printUString( const ::rtl::OUString
& str
)
82 printf("#printUString_u# " );
83 aString
= ::rtl::OUStringToOString( str
, RTL_TEXTENCODING_ASCII_US
);
84 printf("%s\n", aString
.getStr( ) );
87 /** print last error of pipe system.
89 inline void printPipeError( ::osl::Pipe aPipe
)
91 oslPipeError nError
= aPipe
.getError( );
92 printf("#printPipeError# " );
95 printf("Success!\n" );
97 case osl_Pipe_E_NotFound
:
98 printf("The returned error is: Not found!\n" );
100 case osl_Pipe_E_AlreadyExists
:
101 printf("The returned error is: Already exist!\n" );
103 case osl_Pipe_E_NoProtocol
:
104 printf("The returned error is: No protocol!\n" );
106 case osl_Pipe_E_NetworkReset
:
107 printf("The returned error is: Network reset!\n" );
109 case osl_Pipe_E_ConnectionAbort
:
110 printf("The returned error is: Connection aborted!\n" );
112 case osl_Pipe_E_ConnectionReset
:
113 printf("The returned error is: Connection reset!\n" );
115 case osl_Pipe_E_NoBufferSpace
:
116 printf("The returned error is: No buffer space!\n" );
118 case osl_Pipe_E_TimedOut
:
119 printf("The returned error is: Timeout!\n" );
121 case osl_Pipe_E_ConnectionRefused
:
122 printf("The returned error is: Connection refused!\n" );
124 case osl_Pipe_E_invalidError
:
125 printf("The returned error is: Invalid error!\n" );
128 printf("The returned error is: Number %d, Unknown Error\n", nError
);
135 //------------------------------------------------------------------------
136 // pipe name and transfer contents
137 //------------------------------------------------------------------------
138 const rtl::OUString aTestPipeName
= rtl::OUString::createFromAscii( "testpipe2" );
139 const rtl::OUString aTestPipe1
= rtl::OUString::createFromAscii( "testpipe1" );
140 const rtl::OUString aTestString
= rtl::OUString::createFromAscii( "Sun Microsystems" );
142 const OString
m_pTestString1("Sun Microsystems");
143 const OString
m_pTestString2("test pipe PASS/OK");
145 //------------------------------------------------------------------------
146 // test code start here
147 //------------------------------------------------------------------------
152 //------------------------------------------------------------------------
153 // most return value -1 denote a fail of operation.
154 //------------------------------------------------------------------------
155 #define OSL_PIPE_FAIL -1
157 /** testing the methods:
159 inline Pipe(const ::rtl::OUString& strName, oslPipeOptions Options);
160 inline Pipe(const ::rtl::OUString& strName, oslPipeOptions Options,const Security & rSecurity);
161 inline Pipe(const Pipe& pipe);
162 inline Pipe(oslPipe pipe, __sal_NoAcquire noacquire );
163 inline Pipe(oslPipe Pipe);
165 class ctors
: public CppUnit::TestFixture
168 sal_Bool bRes
, bRes1
;
183 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, yet no case to test.",
187 void ctors_name_option( )
189 /// create a named pipe.
190 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
191 ::osl::Pipe
aAssignPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
);
193 bRes
= aPipe
.is( ) && aAssignPipe
.is( );
195 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name and option.",
199 void ctors_name_option_security( )
201 /// create a security pipe.
202 const ::osl::Security rSecurity
;
203 ::osl::Pipe
aSecurityPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
, rSecurity
);
205 bRes
= aSecurityPipe
.is( );
207 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name, option and security, the test of security is not implemented yet.",
214 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
215 /// create a pipe using copy constructor.
216 ::osl::Pipe
aCopyPipe( aPipe
);
218 bRes
= aCopyPipe
.is( ) && aCopyPipe
== aPipe
;
220 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test copy constructor.",
226 When test the following two constructors, don't know how to test the
227 acquire and no acquire action. possible plans:
228 1.release one handle and check the other( did not success since the
229 other still exist and valid. )
230 2. release one handle twice to see getLastError( )(the getLastError
231 always returns invalidError(LINUX)).
234 void ctors_no_acquire( )
237 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
238 /// constructs a pipe reference without acquiring the handle.
239 ::osl::Pipe
aNoAcquirePipe( aPipe
.getHandle( ), SAL_NO_ACQUIRE
);
241 bRes
= aNoAcquirePipe
.is( );
243 ///bRes1 = aNoAcquirePipe.is( );
246 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no aquire of handle, only validation test, do not know how to test no acquire.",
250 void ctors_acquire( )
252 /// create a base pipe.
253 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
254 /// constructs two pipes without acquiring the handle on the base pipe.
255 ::osl::Pipe
aAcquirePipe( aPipe
.getHandle( ) );
256 ::osl::Pipe
aAcquirePipe1( NULL
);
258 bRes
= aAcquirePipe
.is( );
259 bRes1
= aAcquirePipe1
.is( );
261 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no aquire of handle.only validation test, do not know how to test no acquire.",
262 sal_True
== bRes
&& sal_False
== bRes1
);
265 CPPUNIT_TEST_SUITE( ctors
);
266 CPPUNIT_TEST( ctors_none
);
267 CPPUNIT_TEST( ctors_name_option
);
268 CPPUNIT_TEST( ctors_name_option_security
);
269 CPPUNIT_TEST( ctors_copy
);
270 CPPUNIT_TEST( ctors_no_acquire
);
271 CPPUNIT_TEST( ctors_acquire
);
272 CPPUNIT_TEST_SUITE_END( );
276 /** testing the method:
277 inline sal_Bool SAL_CALL is() const;
279 class is
: public CppUnit::TestFixture
286 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), check if the pipe is a valid one.", sal_False
== aPipe
.is( ) );
291 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
293 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), a normal pipe creation.", sal_True
== aPipe
.is( ) );
298 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
301 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), an invalid case.", sal_False
== aPipe
.is( ) );
306 ::osl::Pipe
aPipe( NULL
);
308 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), an invalid constructor.", sal_False
== aPipe
.is( ) );
311 CPPUNIT_TEST_SUITE( is
);
312 CPPUNIT_TEST( is_001
);
313 CPPUNIT_TEST( is_002
);
314 CPPUNIT_TEST( is_003
);
315 CPPUNIT_TEST( is_004
);
316 CPPUNIT_TEST_SUITE_END( );
320 /** testing the methods:
321 inline sal_Bool create( const ::rtl::OUString & strName,
322 oslPipeOptions Options, const Security &rSec );
323 nline sal_Bool create( const ::rtl::OUString & strName,
324 oslPipeOptions Options = osl_Pipe_OPEN );
326 class create
: public CppUnit::TestFixture
329 sal_Bool bRes
, bRes1
;
333 security create only be tested creation, security section is
337 void create_named_security_001( )
341 bRes
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
, rSec
);
342 bRes1
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
, rSec
);
345 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.",
346 sal_True
== bRes
&& sal_False
== bRes1
);
349 void create_named_security_002( )
352 ::osl::Pipe aPipe
, aPipe1
;
353 bRes
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
, rSec
);
354 bRes1
= aPipe1
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
, rSec
);
357 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.",
358 sal_True
== bRes
&& sal_True
== bRes1
);
361 void create_named_001( )
364 bRes
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
365 bRes1
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
368 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.",
369 sal_True
== bRes
&& sal_False
== bRes1
);
372 void create_named_002( )
374 ::osl::Pipe aPipe
, aPipe1
;
375 bRes
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
376 bRes1
= aPipe1
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
);
379 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.",
380 sal_True
== bRes
&& sal_True
== bRes1
);
383 void create_named_003( )
386 bRes
= aPipe
.create( test::uniquePipeName(aTestPipeName
) );
389 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test default option is open.",
393 CPPUNIT_TEST_SUITE( create
);
394 CPPUNIT_TEST( create_named_security_001
);
395 CPPUNIT_TEST( create_named_security_002
);
396 CPPUNIT_TEST( create_named_001
);
397 CPPUNIT_TEST( create_named_002
);
398 CPPUNIT_TEST( create_named_003
);
399 CPPUNIT_TEST_SUITE_END( );
403 /** testing the method:
404 inline void SAL_CALL clear();
406 class clear
: public CppUnit::TestFixture
409 sal_Bool bRes
, bRes1
;
414 aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
418 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test clear.",
422 CPPUNIT_TEST_SUITE( clear
);
423 CPPUNIT_TEST( clear_001
);
424 CPPUNIT_TEST_SUITE_END( );
428 /** testing the methods:
429 inline Pipe& SAL_CALL operator= (const Pipe& pipe);
430 inline Pipe& SAL_CALL operator= (const oslPipe pipe );
432 class assign
: public CppUnit::TestFixture
435 sal_Bool bRes
, bRes1
;
439 ::osl::Pipe aPipe
, aPipe1
;
440 aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
443 bRes1
= aPipe
== aPipe1
;
447 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with reference.",
448 sal_True
== bRes
&& sal_True
== bRes1
);
451 void assign_handle( )
453 ::osl::Pipe aPipe
, aPipe1
;
454 aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
455 aPipe1
= aPipe
.getHandle( );
457 bRes1
= aPipe
== aPipe1
;
461 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with handle.",
462 sal_True
== bRes
&& sal_True
== bRes1
);
465 CPPUNIT_TEST_SUITE( assign
);
466 CPPUNIT_TEST( assign_ref
);
467 CPPUNIT_TEST( assign_handle
);
468 CPPUNIT_TEST_SUITE_END( );
472 /** testing the method:
473 inline sal_Bool SAL_CALL isValid() const;
474 isValid( ) has not been implemented under the following platforms, please refer to osl/pipe.hxx
476 /*class isValid : public CppUnit::TestFixture
479 sal_Bool bRes, bRes1;
483 CPPUNIT_ASSERT_MESSAGE( "#test comment#: isValid() has not been implemented on all platforms.",
487 CPPUNIT_TEST_SUITE( isValid );
488 CPPUNIT_TEST( isValid_001 );
489 CPPUNIT_TEST_SUITE_END( );
490 };*/ // class isValid
493 /** testing the method:
494 inline sal_Bool SAL_CALL operator==( const Pipe& rPipe ) const;
496 class isEqual
: public CppUnit::TestFixture
499 sal_Bool bRes
, bRes1
;
504 aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
505 bRes
= aPipe
== aPipe
;
508 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(), compare its self.",
514 ::osl::Pipe aPipe
, aPipe1
, aPipe2
;
515 aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
518 aPipe2
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
520 bRes
= aPipe
== aPipe1
;
521 bRes1
= aPipe
== aPipe2
;
526 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(),create one copy instance, and compare.",
527 sal_True
== bRes
&& sal_False
== bRes1
);
530 CPPUNIT_TEST_SUITE( isEqual
);
531 CPPUNIT_TEST( isEqual_001
);
532 CPPUNIT_TEST( isEqual_002
);
533 CPPUNIT_TEST_SUITE_END( );
537 /** testing the method:
538 inline void SAL_CALL close();
540 class close
: public CppUnit::TestFixture
543 sal_Bool bRes
, bRes1
;
547 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipe1
), osl_Pipe_CREATE
);
554 CPPUNIT_ASSERT_MESSAGE( "#test comment#: difference between close and clear.",
555 sal_True
== bRes
&& sal_False
== bRes1
);
560 ::osl::StreamPipe
aPipe( test::uniquePipeName(aTestPipe1
), osl_Pipe_CREATE
);
562 int nRet
= aPipe
.send( m_pTestString1
.getStr(), 3 );
564 CPPUNIT_ASSERT_MESSAGE( "#test comment#: use after close.",
565 OSL_PIPE_FAIL
== nRet
);
568 CPPUNIT_TEST_SUITE( close
);
569 CPPUNIT_TEST( close_001
);
570 CPPUNIT_TEST( close_002
);
571 CPPUNIT_TEST_SUITE_END( );
575 /** testing the method:
576 inline oslPipeError SAL_CALL accept(StreamPipe& Connection);
577 please refer to StreamPipe::recv
579 /* class accept : public CppUnit::TestFixture
582 sal_Bool bRes, bRes1;
587 // CPPUNIT_ASSERT_MESSAGE( "#test comment#: accept, untested.", 1 == 1 );
588 //CPPUNIT_ASSERT_STUB();
591 CPPUNIT_TEST_SUITE( accept );
592 CPPUNIT_TEST( accept_001 );
593 CPPUNIT_TEST_SUITE_END( );
597 /** testing the method:
598 inline oslPipeError SAL_CALL getError() const;
600 class getError
: public CppUnit::TestFixture
603 sal_Bool bRes
, bRes1
;
606 { 0, osl_Pipe_E_None }, // no error
607 { EPROTOTYPE, osl_Pipe_E_NoProtocol }, // Protocol wrong type for socket
608 { ENOPROTOOPT, osl_Pipe_E_NoProtocol }, // Protocol not available
609 { EPROTONOSUPPORT, osl_Pipe_E_NoProtocol }, // Protocol not supported
610 { ESOCKTNOSUPPORT, osl_Pipe_E_NoProtocol }, // Socket type not supported
611 { EPFNOSUPPORT, osl_Pipe_E_NoProtocol }, // Protocol family not supported
612 { EAFNOSUPPORT, osl_Pipe_E_NoProtocol }, // Address family not supported by
614 { ENETRESET, osl_Pipe_E_NetworkReset }, // Network dropped connection because
616 { ECONNABORTED, osl_Pipe_E_ConnectionAbort }, // Software caused connection abort
617 { ECONNRESET, osl_Pipe_E_ConnectionReset }, // Connection reset by peer
618 { ENOBUFS, osl_Pipe_E_NoBufferSpace }, // No buffer space available
619 { ETIMEDOUT, osl_Pipe_E_TimedOut }, // Connection timed out
620 { ECONNREFUSED, osl_Pipe_E_ConnectionRefused }, // Connection refused
621 { -1, osl_Pipe_E_invalidError }
623 did not define osl_Pipe_E_NotFound, osl_Pipe_E_AlreadyExists
628 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
);
629 oslPipeError nError
= aPipe
.getError( );
630 printPipeError( aPipe
);
633 CPPUNIT_ASSERT_MESSAGE( "#test comment#: open a non-exist pipe.",
634 nError
!= osl_Pipe_E_None
);
639 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
640 ::osl::Pipe
aPipe1( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
641 oslPipeError nError
= aPipe
.getError( );
642 printPipeError( aPipe
);
646 CPPUNIT_ASSERT_MESSAGE( "#test comment#: create an already exist pipe.",
647 nError
!= osl_Pipe_E_None
);
650 CPPUNIT_TEST_SUITE( getError
);
651 CPPUNIT_TEST( getError_001
);
652 CPPUNIT_TEST( getError_002
);
653 CPPUNIT_TEST_SUITE_END( );
657 /** testing the method:
658 inline oslPipe SAL_CALL getHandle() const;
660 class getHandle
: public CppUnit::TestFixture
663 sal_Bool bRes
, bRes1
;
665 void getHandle_001( )
667 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
);
668 bRes
= aPipe
== aPipe
.getHandle( );
671 CPPUNIT_ASSERT_MESSAGE( "#test comment#: one pipe should equal to its handle.",
675 void getHandle_002( )
677 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
678 ::osl::Pipe
aPipe1( aPipe
.getHandle( ) );
679 bRes
= aPipe
== aPipe1
;
683 CPPUNIT_ASSERT_MESSAGE( "#test comment#: one pipe derived from another pipe's handle.",
687 CPPUNIT_TEST_SUITE( getHandle
);
688 CPPUNIT_TEST( getHandle_001
);
689 CPPUNIT_TEST( getHandle_002
);
690 CPPUNIT_TEST_SUITE_END( );
691 }; // class getHandle
694 // -----------------------------------------------------------------------------
695 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::ctors
);
696 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::is
);
697 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::create
);
698 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::clear
);
699 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::assign
);
700 //CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::isValid);
701 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::isEqual
);
702 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::close
);
703 //CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::accept);
704 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::getError
);
705 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::getHandle
);
706 // -----------------------------------------------------------------------------
708 } // namespace osl_Pipe
711 namespace osl_StreamPipe
714 /** testing the methods:
716 inline StreamPipe(oslPipe Pipe);;
717 inline StreamPipe(const StreamPipe& Pipe);
718 inline StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options = osl_Pipe_OPEN);
719 inline StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options, const Security &rSec );
720 inline StreamPipe( oslPipe pipe, __sal_NoAcquire noacquire );
722 class ctors
: public CppUnit::TestFixture
725 sal_Bool bRes
, bRes1
;
730 ::osl::StreamPipe
aStreamPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
731 // create an unattached pipe.
732 ::osl::StreamPipe aStreamPipe1
;
733 bRes
= aStreamPipe1
.is( );
735 // assign it and check.
736 aStreamPipe1
= aStreamPipe
;
737 bRes1
= aStreamPipe1
.is( );
738 aStreamPipe
.clear( );
739 aStreamPipe1
.clear( );
741 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, before and after assign.",
742 sal_False
== bRes
&& sal_True
== bRes1
);
748 ::osl::StreamPipe
aStreamPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
749 // create a pipe with last handle.
750 ::osl::StreamPipe
aStreamPipe1( aStreamPipe
.getHandle( ) );
751 bRes
= aStreamPipe1
.is( ) && aStreamPipe
== aStreamPipe1
;
752 aStreamPipe
.clear( );
753 aStreamPipe1
.clear( );
755 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with other's handle.",
762 ::osl::StreamPipe
aStreamPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
763 // create an unattached pipe.
764 ::osl::StreamPipe
aStreamPipe1( aStreamPipe
);
765 bRes
= aStreamPipe1
.is( ) && aStreamPipe
== aStreamPipe1
;
766 aStreamPipe
.clear( );
767 aStreamPipe1
.clear( );
769 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test copy constructor.",
773 void ctors_name_option( )
776 ::osl::StreamPipe
aStreamPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
777 // create an unattached pipe.
778 ::osl::StreamPipe
aStreamPipe1( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
);
779 bRes
= aStreamPipe1
.is( ) && aStreamPipe
.is( );
780 aStreamPipe
.clear( );
781 aStreamPipe1
.clear( );
783 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name and option.",
787 void ctors_name_option_security( )
789 /// create a security pipe.
790 const ::osl::Security rSecurity
;
791 ::osl::StreamPipe
aSecurityPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
, rSecurity
);
793 bRes
= aSecurityPipe
.is( );
794 aSecurityPipe
.clear( );
796 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name, option and security, the test of security is not implemented yet.",
802 When test the following constructor, don't know how to test the
803 acquire and no acquire action. possible plans:
804 1.release one handle and check the other( did not success since the
805 other still exist and valid. )
806 2. release one handle twice to see getLastError( )(the getLastError
807 always returns invalidError(LINUX)).
810 void ctors_no_acquire( )
813 ::osl::StreamPipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
814 // constructs a pipe reference without acquiring the handle.
815 ::osl::StreamPipe
aNoAcquirePipe( aPipe
.getHandle( ), SAL_NO_ACQUIRE
);
817 bRes
= aNoAcquirePipe
.is( );
819 // bRes1 = aNoAcquirePipe.is( );
821 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no aquire of handle, only validation test, do not know how to test no acquire.",
825 CPPUNIT_TEST_SUITE( ctors
);
826 CPPUNIT_TEST( ctors_none
);
827 CPPUNIT_TEST( ctors_handle
);
828 CPPUNIT_TEST( ctors_copy
);
829 CPPUNIT_TEST( ctors_name_option
);
830 CPPUNIT_TEST( ctors_name_option_security
);
831 CPPUNIT_TEST( ctors_no_acquire
);
832 CPPUNIT_TEST_SUITE_END( );
836 /** testing the methods:
837 inline StreamPipe & SAL_CALL operator=(oslPipe Pipe);
838 inline StreamPipe& SAL_CALL operator=(const Pipe& pipe);
839 mindy: not implementated in osl/pipe.hxx, so remove the cases
842 class assign : public CppUnit::TestFixture
845 sal_Bool bRes, bRes1;
849 ::osl::StreamPipe aPipe, aPipe1;
850 aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE );
853 bRes1 = aPipe == aPipe1;
857 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with reference.",
858 sal_True == bRes && sal_True == bRes1 );
861 void assign_handle( )
863 ::osl::StreamPipe * pPipe = new ::osl::StreamPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE );
864 ::osl::StreamPipe * pAssignPipe = new ::osl::StreamPipe;
865 *pAssignPipe = pPipe->getHandle( );
867 bRes = pAssignPipe->is( );
868 bRes1 = ( *pPipe == *pAssignPipe );
873 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with handle., seems not implemented under (LINUX)(W32)",
874 sal_True == bRes && sal_True == bRes1 );
877 CPPUNIT_TEST_SUITE( assign );
878 CPPUNIT_TEST( assign_ref );
879 CPPUNIT_TEST( assign_handle );
880 CPPUNIT_TEST_SUITE_END( );
884 /** wait _nSec seconds.
886 void thread_sleep( sal_Int32 _nSec
)
888 /// print statement in thread process must use fflush() to force display.
889 // printf("wait %d seconds. ", _nSec );
893 Sleep( _nSec
* 1000 );
895 #if ( defined UNX ) || ( defined OS2 ) //Unix
898 // printf("done\n" );
900 // test read/write & send/recv data to pipe
901 // -----------------------------------------------------------------------------
903 class Pipe_DataSink_Thread
: public Thread
907 Pipe_DataSink_Thread( ) { }
909 ~Pipe_DataSink_Thread( )
915 sal_Int32 nChars
= 0;
917 printf("open pipe\n");
918 ::osl::StreamPipe
aSenderPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
); // test::uniquePipeName(aTestPipeName) is a string = "TestPipe"
919 if ( aSenderPipe
.is() == sal_False
)
921 printf("pipe open failed! \n");
926 nChars
= aSenderPipe
.read( buf
, m_pTestString1
.getLength() + 1 );
929 printf("read failed! \n");
932 printf("buffer is %s \n", buf
);
934 nChars
= aSenderPipe
.send( m_pTestString2
.getStr(), m_pTestString2
.getLength() + 1 );
937 printf("client send failed! \n");
945 // -----------------------------------------------------------------------------
947 class Pipe_DataSource_Thread
: public Thread
951 //::osl::StreamPipe aListenPipe; //( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE );
952 ::osl::Pipe aListenPipe
;
953 ::osl::StreamPipe aConnectionPipe
;
954 Pipe_DataSource_Thread( )
956 printf("create pipe\n");
957 aListenPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
959 ~Pipe_DataSource_Thread( )
968 //::osl::StreamPipe aListenPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE );
970 if ( aListenPipe
.is() == sal_False
)
972 printf("pipe create failed! \n");
976 //::osl::StreamPipe aConnectionPipe;
978 //start server and wait for connection.
980 if ( osl_Pipe_E_None
!= aListenPipe
.accept( aConnectionPipe
) )
982 printf("pipe accept failed!");
987 nChars
= aConnectionPipe
.write( m_pTestString1
.getStr(), m_pTestString1
.getLength() + 1 );
990 printf("server write failed! \n");
994 nChars
= aConnectionPipe
.recv( buf
, 256 );
998 printf("server receive failed! \n");
1001 //thread_sleep( 2 );
1002 printf("received message is: %s\n", buf
);
1003 //aConnectionPipe.close();
1008 /** testing the method: read/write/send/recv and Pipe::accept
1010 class recv
: public CppUnit::TestFixture
1013 sal_Bool bRes
, bRes1
;
1018 Pipe_DataSource_Thread myDataSourceThread
;
1019 Pipe_DataSink_Thread myDataSinkThread
;
1020 myDataSourceThread
.create( );
1022 myDataSinkThread
.create( );
1024 //wait until the thread terminate
1025 myDataSinkThread
.join( );
1026 myDataSourceThread
.join( );
1028 int nCompare1
= strcmp( myDataSinkThread
.buf
, m_pTestString1
.getStr() );
1029 int nCompare2
= strcmp( myDataSourceThread
.buf
, m_pTestString2
.getStr() );
1030 CPPUNIT_ASSERT_MESSAGE( "test send/recv/write/read.", nCompare1
== 0 && nCompare2
== 0 );
1032 //close pipe when accept
1037 Pipe_DataSource_Thread myDataSourceThread
;
1038 Pipe_DataSink_Thread myDataSinkThread
;
1039 myDataSourceThread
.create( );
1041 myDataSourceThread
.aListenPipe
.close();
1042 myDataSourceThread
.join( );
1043 //no condition judgement here, if the case could finish excuting within 1 or 2 seconds, it passes.
1046 CPPUNIT_TEST_SUITE( recv
);
1047 CPPUNIT_TEST( recv_001
);
1048 CPPUNIT_TEST( recv_002
);
1049 CPPUNIT_TEST_SUITE_END( );
1052 // -----------------------------------------------------------------------------
1053 CPPUNIT_TEST_SUITE_REGISTRATION(osl_StreamPipe::ctors
);
1054 //CPPUNIT_TEST_SUITE_REGISTRATION(osl_StreamPipe::assign);
1055 CPPUNIT_TEST_SUITE_REGISTRATION(osl_StreamPipe::recv
);
1056 // -----------------------------------------------------------------------------
1058 } // namespace osl_StreamPipe
1060 CPPUNIT_PLUGIN_IMPLEMENT();