merge the formfield patch from ooo-build
[ooovba.git] / sal / qa / osl / pipe / osl_Pipe.cxx
bloba9c5abbfb651c39bc1e20586447fd46a99701b4c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: osl_Pipe.cxx,v $
10 * $Revision: 1.8 $
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 //------------------------------------------------------------------------
35 // include files
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>
44 #endif
46 #ifndef _OSL_MUTEX_HXX
47 #include <osl/mutex.hxx>
48 #endif
50 #ifndef _OSL_MUTEX_HXX
51 #include <osl/pipe.hxx>
52 #endif
53 #include <osl/time.h>
55 #ifdef UNX
56 #include <unistd.h>
57 #endif
59 using namespace osl;
60 using namespace rtl;
62 //------------------------------------------------------------------------
63 // helper functions
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 )
78 rtl::OString aString;
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# " );
91 switch ( nError ) {
92 case osl_Pipe_E_None:
93 t_print("Success!\n" );
94 break;
95 case osl_Pipe_E_NotFound:
96 t_print("The returned error is: Not found!\n" );
97 break;
98 case osl_Pipe_E_AlreadyExists:
99 t_print("The returned error is: Already exist!\n" );
100 break;
101 case osl_Pipe_E_NoProtocol:
102 t_print("The returned error is: No protocol!\n" );
103 break;
104 case osl_Pipe_E_NetworkReset:
105 t_print("The returned error is: Network reset!\n" );
106 break;
107 case osl_Pipe_E_ConnectionAbort:
108 t_print("The returned error is: Connection aborted!\n" );
109 break;
110 case osl_Pipe_E_ConnectionReset:
111 t_print("The returned error is: Connection reset!\n" );
112 break;
113 case osl_Pipe_E_NoBufferSpace:
114 t_print("The returned error is: No buffer space!\n" );
115 break;
116 case osl_Pipe_E_TimedOut:
117 t_print("The returned error is: Timeout!\n" );
118 break;
119 case osl_Pipe_E_ConnectionRefused:
120 t_print("The returned error is: Connection refused!\n" );
121 break;
122 case osl_Pipe_E_invalidError:
123 t_print("The returned error is: Invalid error!\n" );
124 break;
125 default:
126 t_print("The returned error is: Number %d, Unknown Error\n", nError );
127 break;
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 //------------------------------------------------------------------------
147 namespace osl_Pipe
150 //------------------------------------------------------------------------
151 // most return value -1 denote a fail of operation.
152 //------------------------------------------------------------------------
153 #define OSL_PIPE_FAIL -1
155 /** testing the methods:
156 inline Pipe();
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
165 public:
166 sal_Bool bRes, bRes1;
168 void setUp( )
172 void tearDown( )
176 void ctors_none( )
178 ::osl::Pipe aPipe;
179 bRes = aPipe.is( );
181 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, yet no case to test.",
182 sal_False == bRes );
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.",
194 sal_True == bRes );
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.",
206 sal_True == bRes );
209 void ctors_copy( )
211 /// create a pipe.
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.",
219 sal_True == bRes );
222 /** tester comment:
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( )
234 /// create a pipe.
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( );
240 ///aPipe.clear( );
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.",
245 sal_True == bRes );
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( );
271 }; // class ctors
274 /** testing the method:
275 inline sal_Bool SAL_CALL is() const;
277 class is : public CppUnit::TestFixture
279 public:
280 void is_001( )
282 ::osl::Pipe aPipe;
284 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), check if the pipe is a valid one.", sal_False == aPipe.is( ) );
287 void is_002( )
289 ::osl::Pipe aPipe( aTestPipeName, osl_Pipe_CREATE );
291 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), a normal pipe creation.", sal_True == aPipe.is( ) );
294 void is_003( )
296 ::osl::Pipe aPipe( aTestPipeName, osl_Pipe_CREATE );
297 aPipe.clear( );
299 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), an invalid case.", sal_False == aPipe.is( ) );
302 void is_004( )
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( );
315 }; // class is
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
326 public:
327 sal_Bool bRes, bRes1;
329 /** tester comment:
331 security create only be tested creation, security section is
332 untested yet.
335 void create_named_security_001( )
337 const Security rSec;
338 ::osl::Pipe aPipe;
339 bRes = aPipe.create( aTestPipeName, osl_Pipe_CREATE, rSec );
340 bRes1 = aPipe.create( aTestPipeName, osl_Pipe_CREATE, rSec );
341 aPipe.clear( );
343 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.",
344 sal_True == bRes && sal_False == bRes1);
347 void create_named_security_002( )
349 const Security rSec;
350 ::osl::Pipe aPipe, aPipe1;
351 bRes = aPipe.create( aTestPipeName, osl_Pipe_CREATE, rSec );
352 bRes1 = aPipe1.create( aTestPipeName, osl_Pipe_OPEN, rSec );
353 aPipe.clear( );
355 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.",
356 sal_True == bRes && sal_True == bRes1);
359 void create_named_001( )
361 ::osl::Pipe aPipe;
362 bRes = aPipe.create( aTestPipeName, osl_Pipe_CREATE );
363 bRes1 = aPipe.create( aTestPipeName, osl_Pipe_CREATE );
364 aPipe.clear( );
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 );
375 aPipe.clear( );
377 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.",
378 sal_True == bRes && sal_True == bRes1);
381 void create_named_003( )
383 ::osl::Pipe aPipe;
384 bRes = aPipe.create( aTestPipeName );
385 aPipe.clear( );
387 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test default option is open.",
388 sal_False == bRes );
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( );
398 }; // class create
401 /** testing the method:
402 inline void SAL_CALL clear();
404 class clear : public CppUnit::TestFixture
406 public:
407 sal_Bool bRes, bRes1;
409 void clear_001( )
411 ::osl::Pipe aPipe;
412 aPipe.create( aTestPipeName, osl_Pipe_CREATE );
413 aPipe.clear( );
414 bRes = aPipe.is( );
416 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test clear.",
417 sal_False == bRes );
420 CPPUNIT_TEST_SUITE( clear );
421 CPPUNIT_TEST( clear_001 );
422 CPPUNIT_TEST_SUITE_END( );
423 }; // class clear
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
432 public:
433 sal_Bool bRes, bRes1;
435 void assign_ref( )
437 ::osl::Pipe aPipe, aPipe1;
438 aPipe.create( aTestPipeName, osl_Pipe_CREATE );
439 aPipe1 = aPipe;
440 bRes = aPipe1.is( );
441 bRes1 = aPipe == aPipe1;
442 aPipe.close( );
443 aPipe1.close( );
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( );
454 bRes = aPipe1.is( );
455 bRes1 = aPipe == aPipe1;
456 aPipe.close( );
457 aPipe1.close( );
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( );
467 }; // class assign
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
476 public:
477 sal_Bool bRes, bRes1;
479 void isValid_001( )
481 CPPUNIT_ASSERT_MESSAGE( "#test comment#: isValid() has not been implemented on all platforms.",
482 sal_False );
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
496 public:
497 sal_Bool bRes, bRes1;
499 void isEqual_001( )
501 ::osl::Pipe aPipe;
502 aPipe.create( aTestPipeName, osl_Pipe_CREATE );
503 bRes = aPipe == aPipe;
504 aPipe.close( );
506 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(), compare its self.",
507 sal_True == bRes );
510 void isEqual_002( )
512 ::osl::Pipe aPipe, aPipe1, aPipe2;
513 aPipe.create( aTestPipeName, osl_Pipe_CREATE );
515 aPipe1 = aPipe;
516 aPipe2.create( aTestPipeName, osl_Pipe_CREATE );
518 bRes = aPipe == aPipe1;
519 bRes1 = aPipe == aPipe2;
520 aPipe.close( );
521 aPipe1.close( );
522 aPipe2.close( );
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( );
532 }; // class isEqual
535 /** testing the method:
536 inline void SAL_CALL close();
538 class close : public CppUnit::TestFixture
540 public:
541 sal_Bool bRes, bRes1;
543 void close_001( )
545 ::osl::Pipe aPipe( aTestPipe1, osl_Pipe_CREATE );
546 aPipe.close( );
547 bRes = aPipe.is( );
549 aPipe.clear( );
550 bRes1 = aPipe.is( );
552 CPPUNIT_ASSERT_MESSAGE( "#test comment#: difference between close and clear.",
553 sal_True == bRes && sal_False == bRes1);
556 void close_002( )
558 ::osl::StreamPipe aPipe( aTestPipe1, osl_Pipe_CREATE );
559 aPipe.close( );
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( );
570 }; // class close
573 /** testing the method:
574 inline oslPipeError SAL_CALL accept(StreamPipe& Connection);
575 please refer to StreamPipe::recv
577 /* class accept : public CppUnit::TestFixture
579 public:
580 sal_Bool bRes, bRes1;
582 void accept_001( )
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( );
592 };*/ // class accept
595 /** testing the method:
596 inline oslPipeError SAL_CALL getError() const;
598 class getError : public CppUnit::TestFixture
600 public:
601 sal_Bool bRes, bRes1;
603 PipeError[]= {
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
611 // protocol family
612 { ENETRESET, osl_Pipe_E_NetworkReset }, // Network dropped connection because
613 // of reset
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
624 void getError_001( )
626 ::osl::Pipe aPipe( aTestPipeName, osl_Pipe_OPEN );
627 oslPipeError nError = aPipe.getError( );
628 printPipeError( aPipe );
629 aPipe.clear( );
631 CPPUNIT_ASSERT_MESSAGE( "#test comment#: open a non-exist pipe. not passed in (W32)(LINUX)(UNX).",
632 osl_Pipe_E_invalidError == nError );
635 void getError_002( )
637 ::osl::Pipe aPipe( aTestPipeName, osl_Pipe_CREATE );
638 ::osl::Pipe aPipe1( aTestPipeName, osl_Pipe_CREATE );
639 oslPipeError nError = aPipe.getError( );
640 printPipeError( aPipe );
641 aPipe.clear( );
642 aPipe1.clear( );
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( );
652 }; // class getError
655 /** testing the method:
656 inline oslPipe SAL_CALL getHandle() const;
658 class getHandle : public CppUnit::TestFixture
660 public:
661 sal_Bool bRes, bRes1;
663 void getHandle_001( )
665 ::osl::Pipe aPipe( aTestPipeName, osl_Pipe_OPEN );
666 bRes = aPipe == aPipe.getHandle( );
667 aPipe.clear( );
669 CPPUNIT_ASSERT_MESSAGE( "#test comment#: one pipe should equal to its handle.",
670 sal_True == bRes );
673 void getHandle_002( )
675 ::osl::Pipe aPipe( aTestPipeName, osl_Pipe_CREATE );
676 ::osl::Pipe aPipe1( aPipe.getHandle( ) );
677 bRes = aPipe == aPipe1;
678 aPipe.clear( );
679 aPipe1.clear( );
681 CPPUNIT_ASSERT_MESSAGE( "#test comment#: one pipe derived from another pipe's handle.",
682 sal_True == bRes );
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:
713 inline StreamPipe();
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
722 public:
723 sal_Bool bRes, bRes1;
725 void ctors_none( )
727 // create a pipe.
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 );
743 void ctors_handle( )
745 // create a pipe.
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.",
754 sal_True == bRes );
757 void ctors_copy( )
759 // create a pipe.
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.",
768 sal_True == bRes );
771 void ctors_name_option( )
773 // create a pipe.
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.",
782 sal_True == bRes );
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.",
795 sal_True == bRes );
798 /** tester comment:
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( )
810 // create a pipe.
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( );
816 aPipe.clear( );
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.",
820 sal_True == bRes );
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( );
831 }; // class ctors
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
842 public:
843 sal_Bool bRes, bRes1;
845 void assign_ref( )
847 ::osl::StreamPipe aPipe, aPipe1;
848 aPipe.create( aTestPipeName, osl_Pipe_CREATE );
849 aPipe1 = aPipe;
850 bRes = aPipe1.is( );
851 bRes1 = aPipe == aPipe1;
852 aPipe.close( );
853 aPipe1.close( );
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 );
867 pPipe->close( );
869 delete 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( );
879 };*/ // class assign
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 );
888 fflush(stdout);
890 #ifdef WNT //Windows
891 Sleep( _nSec * 1000 );
892 #endif
893 #if ( defined UNX ) || ( defined OS2 ) //Unix
894 sleep( _nSec );
895 #endif
896 // t_print("done\n" );
898 // test read/write & send/recv data to pipe
899 // -----------------------------------------------------------------------------
901 class Pipe_DataSink_Thread : public Thread
903 public:
904 sal_Char buf[256];
905 Pipe_DataSink_Thread( ) { }
907 ~Pipe_DataSink_Thread( )
910 protected:
911 void SAL_CALL run( )
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");
921 else
923 t_print("read\n");
924 nChars = aSenderPipe.read( buf, m_pTestString1.getLength() + 1 );
925 if ( nChars < 0 )
927 t_print("read failed! \n");
928 return;
930 t_print("buffer is %s \n", buf);
931 t_print("send\n");
932 nChars = aSenderPipe.send( m_pTestString2.getStr(), m_pTestString2.getLength() + 1 );
933 if ( nChars < 0 )
935 t_print("client send failed! \n");
936 return;
943 // -----------------------------------------------------------------------------
945 class Pipe_DataSource_Thread : public Thread
947 public:
948 sal_Char buf[256];
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( )
959 aListenPipe.close();
961 protected:
962 void SAL_CALL run( )
964 //create pipe.
965 sal_Int32 nChars;
966 //::osl::StreamPipe aListenPipe( aTestPipeName, osl_Pipe_CREATE );
967 t_print("listen\n");
968 if ( aListenPipe.is() == sal_False )
970 t_print("pipe create failed! \n");
972 else
974 //::osl::StreamPipe aConnectionPipe;
976 //start server and wait for connection.
977 t_print("accept\n");
978 if ( osl_Pipe_E_None != aListenPipe.accept( aConnectionPipe ) )
980 t_print("pipe accept failed!");
981 return;
983 t_print("write\n");
984 // write to pipe
985 nChars = aConnectionPipe.write( m_pTestString1.getStr(), m_pTestString1.getLength() + 1 );
986 if ( nChars < 0)
988 t_print("server write failed! \n");
989 return;
991 t_print("recv\n");
992 nChars = aConnectionPipe.recv( buf, 256 );
994 if ( nChars < 0)
996 t_print("server receive failed! \n");
997 return;
999 //thread_sleep( 2 );
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
1010 public:
1011 sal_Bool bRes, bRes1;
1013 void recv_001( )
1015 //launch threads.
1016 Pipe_DataSource_Thread myDataSourceThread;
1017 Pipe_DataSink_Thread myDataSinkThread;
1018 myDataSourceThread.create( );
1019 thread_sleep( 1 );
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
1031 void recv_002()
1033 thread_sleep( 1 );
1035 Pipe_DataSource_Thread myDataSourceThread;
1036 Pipe_DataSink_Thread myDataSinkThread;
1037 myDataSourceThread.create( );
1038 thread_sleep( 1 );
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( );
1048 }; // class recv
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.
1063 NOADDITIONAL;