1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: osl_Pipe.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sal.hxx"
34 //------------------------------------------------------------------------
36 //------------------------------------------------------------------------
38 #include <cppunit/simpleheader.hxx>
39 #include <sal/types.h>
40 #include <rtl/ustring.hxx>
42 #ifndef _OSL_THREAD_HXX
43 #include <osl/thread.hxx>
46 #ifndef _OSL_MUTEX_HXX
47 #include <osl/mutex.hxx>
50 #ifndef _OSL_MUTEX_HXX
51 #include <osl/pipe.hxx>
62 //------------------------------------------------------------------------
64 //------------------------------------------------------------------------
66 /** print Boolean value.
68 inline void printBool( sal_Bool bOk
)
70 t_print("#printBool# " );
71 ( sal_True
== bOk
) ? t_print("YES!\n" ): t_print("NO!\n" );
74 /** print a UNI_CODE String.
76 inline void printUString( const ::rtl::OUString
& str
)
80 t_print("#printUString_u# " );
81 aString
= ::rtl::OUStringToOString( str
, RTL_TEXTENCODING_ASCII_US
);
82 t_print("%s\n", aString
.getStr( ) );
85 /** print last error of pipe system.
87 inline void printPipeError( ::osl::Pipe aPipe
)
89 oslPipeError nError
= aPipe
.getError( );
90 t_print("#printPipeError# " );
93 t_print("Success!\n" );
95 case osl_Pipe_E_NotFound
:
96 t_print("The returned error is: Not found!\n" );
98 case osl_Pipe_E_AlreadyExists
:
99 t_print("The returned error is: Already exist!\n" );
101 case osl_Pipe_E_NoProtocol
:
102 t_print("The returned error is: No protocol!\n" );
104 case osl_Pipe_E_NetworkReset
:
105 t_print("The returned error is: Network reset!\n" );
107 case osl_Pipe_E_ConnectionAbort
:
108 t_print("The returned error is: Connection aborted!\n" );
110 case osl_Pipe_E_ConnectionReset
:
111 t_print("The returned error is: Connection reset!\n" );
113 case osl_Pipe_E_NoBufferSpace
:
114 t_print("The returned error is: No buffer space!\n" );
116 case osl_Pipe_E_TimedOut
:
117 t_print("The returned error is: Timeout!\n" );
119 case osl_Pipe_E_ConnectionRefused
:
120 t_print("The returned error is: Connection refused!\n" );
122 case osl_Pipe_E_invalidError
:
123 t_print("The returned error is: Invalid error!\n" );
126 t_print("The returned error is: Number %d, Unknown Error\n", nError
);
133 //------------------------------------------------------------------------
134 // pipe name and transfer contents
135 //------------------------------------------------------------------------
136 const rtl::OUString aTestPipeName
= rtl::OUString::createFromAscii( "testpipe2" );
137 const rtl::OUString aTestPipe1
= rtl::OUString::createFromAscii( "testpipe1" );
138 const rtl::OUString aTestString
= rtl::OUString::createFromAscii( "Sun Microsystems" );
140 const OString
m_pTestString1("Sun Microsystems");
141 const OString
m_pTestString2("test pipe PASS/OK");
143 //------------------------------------------------------------------------
144 // test code start here
145 //------------------------------------------------------------------------
150 //------------------------------------------------------------------------
151 // most return value -1 denote a fail of operation.
152 //------------------------------------------------------------------------
153 #define OSL_PIPE_FAIL -1
155 /** testing the methods:
157 inline Pipe(const ::rtl::OUString& strName, oslPipeOptions Options);
158 inline Pipe(const ::rtl::OUString& strName, oslPipeOptions Options,const Security & rSecurity);
159 inline Pipe(const Pipe& pipe);
160 inline Pipe(oslPipe pipe, __sal_NoAcquire noacquire );
161 inline Pipe(oslPipe Pipe);
163 class ctors
: public CppUnit::TestFixture
166 sal_Bool bRes
, bRes1
;
181 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, yet no case to test.",
185 void ctors_name_option( )
187 /// create a named pipe.
188 ::osl::Pipe
aPipe( aTestPipeName
, osl_Pipe_CREATE
);
189 ::osl::Pipe
aAssignPipe( aTestPipeName
, osl_Pipe_OPEN
);
191 bRes
= aPipe
.is( ) && aAssignPipe
.is( );
193 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name and option.",
197 void ctors_name_option_security( )
199 /// create a security pipe.
200 const ::osl::Security rSecurity
;
201 ::osl::Pipe
aSecurityPipe( aTestPipeName
, osl_Pipe_CREATE
, rSecurity
);
203 bRes
= aSecurityPipe
.is( );
205 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name, option and security, the test of security is not implemented yet.",
212 ::osl::Pipe
aPipe( aTestPipeName
, osl_Pipe_CREATE
);
213 /// create a pipe using copy constructor.
214 ::osl::Pipe
aCopyPipe( aPipe
);
216 bRes
= aCopyPipe
.is( ) && aCopyPipe
== aPipe
;
218 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test copy constructor.",
224 When test the following two constructors, don't know how to test the
225 acquire and no acquire action. possible plans:
226 1.release one handle and check the other( did not success since the
227 other still exist and valid. )
228 2. release one handle twice to see getLastError( )(the getLastError
229 always returns invalidError(LINUX)).
232 void ctors_no_acquire( )
235 ::osl::Pipe
aPipe( aTestPipeName
, osl_Pipe_CREATE
);
236 /// constructs a pipe reference without acquiring the handle.
237 ::osl::Pipe
aNoAcquirePipe( aPipe
.getHandle( ), SAL_NO_ACQUIRE
);
239 bRes
= aNoAcquirePipe
.is( );
241 ///bRes1 = aNoAcquirePipe.is( );
244 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no aquire of handle, only validation test, do not know how to test no acquire.",
248 void ctors_acquire( )
250 /// create a base pipe.
251 ::osl::Pipe
aPipe( aTestPipeName
, osl_Pipe_CREATE
);
252 /// constructs two pipes without acquiring the handle on the base pipe.
253 ::osl::Pipe
aAcquirePipe( aPipe
.getHandle( ) );
254 ::osl::Pipe
aAcquirePipe1( NULL
);
256 bRes
= aAcquirePipe
.is( );
257 bRes1
= aAcquirePipe1
.is( );
259 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no aquire of handle.only validation test, do not know how to test no acquire.",
260 sal_True
== bRes
&& sal_False
== bRes1
);
263 CPPUNIT_TEST_SUITE( ctors
);
264 CPPUNIT_TEST( ctors_none
);
265 CPPUNIT_TEST( ctors_name_option
);
266 CPPUNIT_TEST( ctors_name_option_security
);
267 CPPUNIT_TEST( ctors_copy
);
268 CPPUNIT_TEST( ctors_no_acquire
);
269 CPPUNIT_TEST( ctors_acquire
);
270 CPPUNIT_TEST_SUITE_END( );
274 /** testing the method:
275 inline sal_Bool SAL_CALL is() const;
277 class is
: public CppUnit::TestFixture
284 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), check if the pipe is a valid one.", sal_False
== aPipe
.is( ) );
289 ::osl::Pipe
aPipe( aTestPipeName
, osl_Pipe_CREATE
);
291 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), a normal pipe creation.", sal_True
== aPipe
.is( ) );
296 ::osl::Pipe
aPipe( aTestPipeName
, osl_Pipe_CREATE
);
299 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), an invalid case.", sal_False
== aPipe
.is( ) );
304 ::osl::Pipe
aPipe( NULL
);
306 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), an invalid constructor.", sal_False
== aPipe
.is( ) );
309 CPPUNIT_TEST_SUITE( is
);
310 CPPUNIT_TEST( is_001
);
311 CPPUNIT_TEST( is_002
);
312 CPPUNIT_TEST( is_003
);
313 CPPUNIT_TEST( is_004
);
314 CPPUNIT_TEST_SUITE_END( );
318 /** testing the methods:
319 inline sal_Bool create( const ::rtl::OUString & strName,
320 oslPipeOptions Options, const Security &rSec );
321 nline sal_Bool create( const ::rtl::OUString & strName,
322 oslPipeOptions Options = osl_Pipe_OPEN );
324 class create
: public CppUnit::TestFixture
327 sal_Bool bRes
, bRes1
;
331 security create only be tested creation, security section is
335 void create_named_security_001( )
339 bRes
= aPipe
.create( aTestPipeName
, osl_Pipe_CREATE
, rSec
);
340 bRes1
= aPipe
.create( aTestPipeName
, osl_Pipe_CREATE
, rSec
);
343 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.",
344 sal_True
== bRes
&& sal_False
== bRes1
);
347 void create_named_security_002( )
350 ::osl::Pipe aPipe
, aPipe1
;
351 bRes
= aPipe
.create( aTestPipeName
, osl_Pipe_CREATE
, rSec
);
352 bRes1
= aPipe1
.create( aTestPipeName
, osl_Pipe_OPEN
, rSec
);
355 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.",
356 sal_True
== bRes
&& sal_True
== bRes1
);
359 void create_named_001( )
362 bRes
= aPipe
.create( aTestPipeName
, osl_Pipe_CREATE
);
363 bRes1
= aPipe
.create( aTestPipeName
, osl_Pipe_CREATE
);
366 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.",
367 sal_True
== bRes
&& sal_False
== bRes1
);
370 void create_named_002( )
372 ::osl::Pipe aPipe
, aPipe1
;
373 bRes
= aPipe
.create( aTestPipeName
, osl_Pipe_CREATE
);
374 bRes1
= aPipe1
.create( aTestPipeName
, osl_Pipe_OPEN
);
377 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.",
378 sal_True
== bRes
&& sal_True
== bRes1
);
381 void create_named_003( )
384 bRes
= aPipe
.create( aTestPipeName
);
387 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test default option is open.",
391 CPPUNIT_TEST_SUITE( create
);
392 CPPUNIT_TEST( create_named_security_001
);
393 CPPUNIT_TEST( create_named_security_002
);
394 CPPUNIT_TEST( create_named_001
);
395 CPPUNIT_TEST( create_named_002
);
396 CPPUNIT_TEST( create_named_003
);
397 CPPUNIT_TEST_SUITE_END( );
401 /** testing the method:
402 inline void SAL_CALL clear();
404 class clear
: public CppUnit::TestFixture
407 sal_Bool bRes
, bRes1
;
412 aPipe
.create( aTestPipeName
, osl_Pipe_CREATE
);
416 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test clear.",
420 CPPUNIT_TEST_SUITE( clear
);
421 CPPUNIT_TEST( clear_001
);
422 CPPUNIT_TEST_SUITE_END( );
426 /** testing the methods:
427 inline Pipe& SAL_CALL operator= (const Pipe& pipe);
428 inline Pipe& SAL_CALL operator= (const oslPipe pipe );
430 class assign
: public CppUnit::TestFixture
433 sal_Bool bRes
, bRes1
;
437 ::osl::Pipe aPipe
, aPipe1
;
438 aPipe
.create( aTestPipeName
, osl_Pipe_CREATE
);
441 bRes1
= aPipe
== aPipe1
;
445 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with reference.",
446 sal_True
== bRes
&& sal_True
== bRes1
);
449 void assign_handle( )
451 ::osl::Pipe aPipe
, aPipe1
;
452 aPipe
.create( aTestPipeName
, osl_Pipe_CREATE
);
453 aPipe1
= aPipe
.getHandle( );
455 bRes1
= aPipe
== aPipe1
;
459 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with handle.",
460 sal_True
== bRes
&& sal_True
== bRes1
);
463 CPPUNIT_TEST_SUITE( assign
);
464 CPPUNIT_TEST( assign_ref
);
465 CPPUNIT_TEST( assign_handle
);
466 CPPUNIT_TEST_SUITE_END( );
470 /** testing the method:
471 inline sal_Bool SAL_CALL isValid() const;
472 isValid( ) has not been implemented under the following platforms, please refer to osl/pipe.hxx
474 /*class isValid : public CppUnit::TestFixture
477 sal_Bool bRes, bRes1;
481 CPPUNIT_ASSERT_MESSAGE( "#test comment#: isValid() has not been implemented on all platforms.",
485 CPPUNIT_TEST_SUITE( isValid );
486 CPPUNIT_TEST( isValid_001 );
487 CPPUNIT_TEST_SUITE_END( );
488 };*/ // class isValid
491 /** testing the method:
492 inline sal_Bool SAL_CALL operator==( const Pipe& rPipe ) const;
494 class isEqual
: public CppUnit::TestFixture
497 sal_Bool bRes
, bRes1
;
502 aPipe
.create( aTestPipeName
, osl_Pipe_CREATE
);
503 bRes
= aPipe
== aPipe
;
506 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(), compare its self.",
512 ::osl::Pipe aPipe
, aPipe1
, aPipe2
;
513 aPipe
.create( aTestPipeName
, osl_Pipe_CREATE
);
516 aPipe2
.create( aTestPipeName
, osl_Pipe_CREATE
);
518 bRes
= aPipe
== aPipe1
;
519 bRes1
= aPipe
== aPipe2
;
524 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(),create one copy instance, and compare.",
525 sal_True
== bRes
&& sal_False
== bRes1
);
528 CPPUNIT_TEST_SUITE( isEqual
);
529 CPPUNIT_TEST( isEqual_001
);
530 CPPUNIT_TEST( isEqual_002
);
531 CPPUNIT_TEST_SUITE_END( );
535 /** testing the method:
536 inline void SAL_CALL close();
538 class close
: public CppUnit::TestFixture
541 sal_Bool bRes
, bRes1
;
545 ::osl::Pipe
aPipe( aTestPipe1
, osl_Pipe_CREATE
);
552 CPPUNIT_ASSERT_MESSAGE( "#test comment#: difference between close and clear.",
553 sal_True
== bRes
&& sal_False
== bRes1
);
558 ::osl::StreamPipe
aPipe( aTestPipe1
, osl_Pipe_CREATE
);
560 int nRet
= aPipe
.send( m_pTestString1
.getStr(), 3 );
562 CPPUNIT_ASSERT_MESSAGE( "#test comment#: use after close.",
563 OSL_PIPE_FAIL
== nRet
);
566 CPPUNIT_TEST_SUITE( close
);
567 CPPUNIT_TEST( close_001
);
568 CPPUNIT_TEST( close_002
);
569 CPPUNIT_TEST_SUITE_END( );
573 /** testing the method:
574 inline oslPipeError SAL_CALL accept(StreamPipe& Connection);
575 please refer to StreamPipe::recv
577 /* class accept : public CppUnit::TestFixture
580 sal_Bool bRes, bRes1;
585 // CPPUNIT_ASSERT_MESSAGE( "#test comment#: accept, untested.", 1 == 1 );
586 //CPPUNIT_ASSERT_STUB();
589 CPPUNIT_TEST_SUITE( accept );
590 CPPUNIT_TEST( accept_001 );
591 CPPUNIT_TEST_SUITE_END( );
595 /** testing the method:
596 inline oslPipeError SAL_CALL getError() const;
598 class getError
: public CppUnit::TestFixture
601 sal_Bool bRes
, bRes1
;
604 { 0, osl_Pipe_E_None }, // no error
605 { EPROTOTYPE, osl_Pipe_E_NoProtocol }, // Protocol wrong type for socket
606 { ENOPROTOOPT, osl_Pipe_E_NoProtocol }, // Protocol not available
607 { EPROTONOSUPPORT, osl_Pipe_E_NoProtocol }, // Protocol not supported
608 { ESOCKTNOSUPPORT, osl_Pipe_E_NoProtocol }, // Socket type not supported
609 { EPFNOSUPPORT, osl_Pipe_E_NoProtocol }, // Protocol family not supported
610 { EAFNOSUPPORT, osl_Pipe_E_NoProtocol }, // Address family not supported by
612 { ENETRESET, osl_Pipe_E_NetworkReset }, // Network dropped connection because
614 { ECONNABORTED, osl_Pipe_E_ConnectionAbort }, // Software caused connection abort
615 { ECONNRESET, osl_Pipe_E_ConnectionReset }, // Connection reset by peer
616 { ENOBUFS, osl_Pipe_E_NoBufferSpace }, // No buffer space available
617 { ETIMEDOUT, osl_Pipe_E_TimedOut }, // Connection timed out
618 { ECONNREFUSED, osl_Pipe_E_ConnectionRefused }, // Connection refused
619 { -1, osl_Pipe_E_invalidError }
621 did not define osl_Pipe_E_NotFound, osl_Pipe_E_AlreadyExists
626 ::osl::Pipe
aPipe( aTestPipeName
, osl_Pipe_OPEN
);
627 oslPipeError nError
= aPipe
.getError( );
628 printPipeError( aPipe
);
631 CPPUNIT_ASSERT_MESSAGE( "#test comment#: open a non-exist pipe. not passed in (W32)(LINUX)(UNX).",
632 osl_Pipe_E_invalidError
== nError
);
637 ::osl::Pipe
aPipe( aTestPipeName
, osl_Pipe_CREATE
);
638 ::osl::Pipe
aPipe1( aTestPipeName
, osl_Pipe_CREATE
);
639 oslPipeError nError
= aPipe
.getError( );
640 printPipeError( aPipe
);
644 CPPUNIT_ASSERT_MESSAGE( "#test comment#: create an already exist pipe.not passed in (W32)(LINUX)(UNX).",
645 osl_Pipe_E_invalidError
== nError
);
648 CPPUNIT_TEST_SUITE( getError
);
649 CPPUNIT_TEST( getError_001
);
650 CPPUNIT_TEST( getError_002
);
651 CPPUNIT_TEST_SUITE_END( );
655 /** testing the method:
656 inline oslPipe SAL_CALL getHandle() const;
658 class getHandle
: public CppUnit::TestFixture
661 sal_Bool bRes
, bRes1
;
663 void getHandle_001( )
665 ::osl::Pipe
aPipe( aTestPipeName
, osl_Pipe_OPEN
);
666 bRes
= aPipe
== aPipe
.getHandle( );
669 CPPUNIT_ASSERT_MESSAGE( "#test comment#: one pipe should equal to its handle.",
673 void getHandle_002( )
675 ::osl::Pipe
aPipe( aTestPipeName
, osl_Pipe_CREATE
);
676 ::osl::Pipe
aPipe1( aPipe
.getHandle( ) );
677 bRes
= aPipe
== aPipe1
;
681 CPPUNIT_ASSERT_MESSAGE( "#test comment#: one pipe derived from another pipe's handle.",
685 CPPUNIT_TEST_SUITE( getHandle
);
686 CPPUNIT_TEST( getHandle_001
);
687 CPPUNIT_TEST( getHandle_002
);
688 CPPUNIT_TEST_SUITE_END( );
689 }; // class getHandle
692 // -----------------------------------------------------------------------------
693 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::ctors
, "osl_Pipe");
694 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::is
, "osl_Pipe");
695 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::create
, "osl_Pipe");
696 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::clear
, "osl_Pipe");
697 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::assign
, "osl_Pipe");
698 //CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::isValid, "osl_Pipe");
699 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::isEqual
, "osl_Pipe");
700 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::close
, "osl_Pipe");
701 //CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::accept, "osl_Pipe");
702 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::getError
, "osl_Pipe");
703 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_Pipe::getHandle
, "osl_Pipe");
704 // -----------------------------------------------------------------------------
706 } // namespace osl_Pipe
709 namespace osl_StreamPipe
712 /** testing the methods:
714 inline StreamPipe(oslPipe Pipe);;
715 inline StreamPipe(const StreamPipe& Pipe);
716 inline StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options = osl_Pipe_OPEN);
717 inline StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options, const Security &rSec );
718 inline StreamPipe( oslPipe pipe, __sal_NoAcquire noacquire );
720 class ctors
: public CppUnit::TestFixture
723 sal_Bool bRes
, bRes1
;
728 ::osl::StreamPipe
aStreamPipe( aTestPipeName
, osl_Pipe_CREATE
);
729 // create an unattached pipe.
730 ::osl::StreamPipe aStreamPipe1
;
731 bRes
= aStreamPipe1
.is( );
733 // assign it and check.
734 aStreamPipe1
= aStreamPipe
;
735 bRes1
= aStreamPipe1
.is( );
736 aStreamPipe
.clear( );
737 aStreamPipe1
.clear( );
739 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, before and after assign.",
740 sal_False
== bRes
&& sal_True
== bRes1
);
746 ::osl::StreamPipe
aStreamPipe( aTestPipeName
, osl_Pipe_CREATE
);
747 // create a pipe with last handle.
748 ::osl::StreamPipe
aStreamPipe1( aStreamPipe
.getHandle( ) );
749 bRes
= aStreamPipe1
.is( ) && aStreamPipe
== aStreamPipe1
;
750 aStreamPipe
.clear( );
751 aStreamPipe1
.clear( );
753 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with other's handle.",
760 ::osl::StreamPipe
aStreamPipe( aTestPipeName
, osl_Pipe_CREATE
);
761 // create an unattached pipe.
762 ::osl::StreamPipe
aStreamPipe1( aStreamPipe
);
763 bRes
= aStreamPipe1
.is( ) && aStreamPipe
== aStreamPipe1
;
764 aStreamPipe
.clear( );
765 aStreamPipe1
.clear( );
767 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test copy constructor.",
771 void ctors_name_option( )
774 ::osl::StreamPipe
aStreamPipe( aTestPipeName
, osl_Pipe_CREATE
);
775 // create an unattached pipe.
776 ::osl::StreamPipe
aStreamPipe1( aTestPipeName
, osl_Pipe_OPEN
);
777 bRes
= aStreamPipe1
.is( ) && aStreamPipe
.is( );
778 aStreamPipe
.clear( );
779 aStreamPipe1
.clear( );
781 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name and option.",
785 void ctors_name_option_security( )
787 /// create a security pipe.
788 const ::osl::Security rSecurity
;
789 ::osl::StreamPipe
aSecurityPipe( aTestPipeName
, osl_Pipe_CREATE
, rSecurity
);
791 bRes
= aSecurityPipe
.is( );
792 aSecurityPipe
.clear( );
794 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name, option and security, the test of security is not implemented yet.",
800 When test the following constructor, don't know how to test the
801 acquire and no acquire action. possible plans:
802 1.release one handle and check the other( did not success since the
803 other still exist and valid. )
804 2. release one handle twice to see getLastError( )(the getLastError
805 always returns invalidError(LINUX)).
808 void ctors_no_acquire( )
811 ::osl::StreamPipe
aPipe( aTestPipeName
, osl_Pipe_CREATE
);
812 // constructs a pipe reference without acquiring the handle.
813 ::osl::StreamPipe
aNoAcquirePipe( aPipe
.getHandle( ), SAL_NO_ACQUIRE
);
815 bRes
= aNoAcquirePipe
.is( );
817 // bRes1 = aNoAcquirePipe.is( );
819 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no aquire of handle, only validation test, do not know how to test no acquire.",
823 CPPUNIT_TEST_SUITE( ctors
);
824 CPPUNIT_TEST( ctors_none
);
825 CPPUNIT_TEST( ctors_handle
);
826 CPPUNIT_TEST( ctors_copy
);
827 CPPUNIT_TEST( ctors_name_option
);
828 CPPUNIT_TEST( ctors_name_option_security
);
829 CPPUNIT_TEST( ctors_no_acquire
);
830 CPPUNIT_TEST_SUITE_END( );
834 /** testing the methods:
835 inline StreamPipe & SAL_CALL operator=(oslPipe Pipe);
836 inline StreamPipe& SAL_CALL operator=(const Pipe& pipe);
837 mindy: not implementated in osl/pipe.hxx, so remove the cases
840 class assign : public CppUnit::TestFixture
843 sal_Bool bRes, bRes1;
847 ::osl::StreamPipe aPipe, aPipe1;
848 aPipe.create( aTestPipeName, osl_Pipe_CREATE );
851 bRes1 = aPipe == aPipe1;
855 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with reference.",
856 sal_True == bRes && sal_True == bRes1 );
859 void assign_handle( )
861 ::osl::StreamPipe * pPipe = new ::osl::StreamPipe( aTestPipeName, osl_Pipe_CREATE );
862 ::osl::StreamPipe * pAssignPipe = new ::osl::StreamPipe;
863 *pAssignPipe = pPipe->getHandle( );
865 bRes = pAssignPipe->is( );
866 bRes1 = ( *pPipe == *pAssignPipe );
871 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with handle., seems not implemented under (LINUX)(W32)",
872 sal_True == bRes && sal_True == bRes1 );
875 CPPUNIT_TEST_SUITE( assign );
876 CPPUNIT_TEST( assign_ref );
877 CPPUNIT_TEST( assign_handle );
878 CPPUNIT_TEST_SUITE_END( );
882 /** wait _nSec seconds.
884 void thread_sleep( sal_Int32 _nSec
)
886 /// print statement in thread process must use fflush() to force display.
887 // t_print("wait %d seconds. ", _nSec );
891 Sleep( _nSec
* 1000 );
893 #if ( defined UNX ) || ( defined OS2 ) //Unix
896 // t_print("done\n" );
898 // test read/write & send/recv data to pipe
899 // -----------------------------------------------------------------------------
901 class Pipe_DataSink_Thread
: public Thread
905 Pipe_DataSink_Thread( ) { }
907 ~Pipe_DataSink_Thread( )
913 sal_Int32 nChars
= 0;
915 t_print("open pipe\n");
916 ::osl::StreamPipe
aSenderPipe( aTestPipeName
, osl_Pipe_OPEN
); // aTestPipeName is a string = "TestPipe"
917 if ( aSenderPipe
.is() == sal_False
)
919 t_print("pipe open failed! \n");
924 nChars
= aSenderPipe
.read( buf
, m_pTestString1
.getLength() + 1 );
927 t_print("read failed! \n");
930 t_print("buffer is %s \n", buf
);
932 nChars
= aSenderPipe
.send( m_pTestString2
.getStr(), m_pTestString2
.getLength() + 1 );
935 t_print("client send failed! \n");
943 // -----------------------------------------------------------------------------
945 class Pipe_DataSource_Thread
: public Thread
949 //::osl::StreamPipe aListenPipe; //( aTestPipeName, osl_Pipe_CREATE );
950 ::osl::Pipe aListenPipe
;
951 ::osl::StreamPipe aConnectionPipe
;
952 Pipe_DataSource_Thread( )
954 t_print("create pipe\n");
955 aListenPipe
.create( aTestPipeName
, osl_Pipe_CREATE
);
957 ~Pipe_DataSource_Thread( )
966 //::osl::StreamPipe aListenPipe( aTestPipeName, osl_Pipe_CREATE );
968 if ( aListenPipe
.is() == sal_False
)
970 t_print("pipe create failed! \n");
974 //::osl::StreamPipe aConnectionPipe;
976 //start server and wait for connection.
978 if ( osl_Pipe_E_None
!= aListenPipe
.accept( aConnectionPipe
) )
980 t_print("pipe accept failed!");
985 nChars
= aConnectionPipe
.write( m_pTestString1
.getStr(), m_pTestString1
.getLength() + 1 );
988 t_print("server write failed! \n");
992 nChars
= aConnectionPipe
.recv( buf
, 256 );
996 t_print("server receive failed! \n");
1000 t_print("received message is: %s\n", buf
);
1001 //aConnectionPipe.close();
1006 /** testing the method: read/write/send/recv and Pipe::accept
1008 class recv
: public CppUnit::TestFixture
1011 sal_Bool bRes
, bRes1
;
1016 Pipe_DataSource_Thread myDataSourceThread
;
1017 Pipe_DataSink_Thread myDataSinkThread
;
1018 myDataSourceThread
.create( );
1020 myDataSinkThread
.create( );
1022 //wait until the thread terminate
1023 myDataSinkThread
.join( );
1024 myDataSourceThread
.join( );
1026 int nCompare1
= strcmp( myDataSinkThread
.buf
, m_pTestString1
.getStr() );
1027 int nCompare2
= strcmp( myDataSourceThread
.buf
, m_pTestString2
.getStr() );
1028 CPPUNIT_ASSERT_MESSAGE( "test send/recv/write/read.", nCompare1
== 0 && nCompare2
== 0 );
1030 //close pipe when accept
1035 Pipe_DataSource_Thread myDataSourceThread
;
1036 Pipe_DataSink_Thread myDataSinkThread
;
1037 myDataSourceThread
.create( );
1039 myDataSourceThread
.aListenPipe
.close();
1040 myDataSourceThread
.join( );
1041 //no condition judgement here, if the case could finish excuting within 1 or 2 seconds, it passes.
1044 CPPUNIT_TEST_SUITE( recv
);
1045 CPPUNIT_TEST( recv_001
);
1046 CPPUNIT_TEST( recv_002
);
1047 CPPUNIT_TEST_SUITE_END( );
1050 // -----------------------------------------------------------------------------
1051 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_StreamPipe::ctors
, "osl_StreamPipe");
1052 //CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_StreamPipe::assign, "osl_StreamPipe");
1053 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_StreamPipe::recv
, "osl_StreamPipe");
1054 // -----------------------------------------------------------------------------
1056 } // namespace osl_StreamPipe
1059 // -----------------------------------------------------------------------------
1061 // this macro creates an empty function, which will called by the RegisterAllFunctions()
1062 // to let the user the possibility to also register some functions by hand.