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 "unotest/uniquepipename.hxx"
28 #include <rtl/ustring.hxx>
30 #include <osl/thread.hxx>
32 #include <osl/mutex.hxx>
34 #include <osl/pipe.hxx>
44 using ::rtl::OUString
;
45 using ::rtl::OUStringToOString
;
50 /** print Boolean value.
52 inline void printBool( sal_Bool bOk
)
54 printf("#printBool# " );
55 ( sal_True
== bOk
) ? printf("YES!\n" ): printf("NO!\n" );
58 /** print a UNI_CODE String.
60 inline void printUString( const ::rtl::OUString
& str
)
64 printf("#printUString_u# " );
65 aString
= ::rtl::OUStringToOString( str
, RTL_TEXTENCODING_ASCII_US
);
66 printf("%s\n", aString
.getStr( ) );
69 /** print last error of pipe system.
71 inline void printPipeError( ::osl::Pipe aPipe
)
73 oslPipeError nError
= aPipe
.getError( );
74 printf("#printPipeError# " );
77 printf("Success!\n" );
79 case osl_Pipe_E_NotFound
:
80 printf("The returned error is: Not found!\n" );
82 case osl_Pipe_E_AlreadyExists
:
83 printf("The returned error is: Already exist!\n" );
85 case osl_Pipe_E_NoProtocol
:
86 printf("The returned error is: No protocol!\n" );
88 case osl_Pipe_E_NetworkReset
:
89 printf("The returned error is: Network reset!\n" );
91 case osl_Pipe_E_ConnectionAbort
:
92 printf("The returned error is: Connection aborted!\n" );
94 case osl_Pipe_E_ConnectionReset
:
95 printf("The returned error is: Connection reset!\n" );
97 case osl_Pipe_E_NoBufferSpace
:
98 printf("The returned error is: No buffer space!\n" );
100 case osl_Pipe_E_TimedOut
:
101 printf("The returned error is: Timeout!\n" );
103 case osl_Pipe_E_ConnectionRefused
:
104 printf("The returned error is: Connection refused!\n" );
106 case osl_Pipe_E_invalidError
:
107 printf("The returned error is: Invalid error!\n" );
110 printf("The returned error is: Number %d, Unknown Error\n", nError
);
115 // pipe name and transfer contents
117 const rtl::OUString
aTestPipeName("testpipe2");
118 const rtl::OUString
aTestPipe1("testpipe1");
119 const rtl::OUString
aTestString("Sun Microsystems");
121 const OString
m_pTestString1("Sun Microsystems");
122 const OString
m_pTestString2("test pipe PASS/OK");
124 // test code start here
129 // most return value -1 denote a fail of operation.
131 #define OSL_PIPE_FAIL -1
133 /** testing the methods:
135 inline Pipe(const ::rtl::OUString& strName, oslPipeOptions Options);
136 inline Pipe(const ::rtl::OUString& strName, oslPipeOptions Options,const Security & rSecurity);
137 inline Pipe(const Pipe& pipe);
138 inline Pipe(oslPipe pipe, __sal_NoAcquire noacquire );
139 inline Pipe(oslPipe Pipe);
141 class ctors
: public CppUnit::TestFixture
144 sal_Bool bRes
, bRes1
;
159 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, yet no case to test.",
163 void ctors_name_option( )
165 /// create a named pipe.
166 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
167 ::osl::Pipe
aAssignPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
);
169 bRes
= aPipe
.is( ) && aAssignPipe
.is( );
171 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name and option.",
175 void ctors_name_option_security( )
177 /// create a security pipe.
178 const ::osl::Security rSecurity
;
179 ::osl::Pipe
aSecurityPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
, rSecurity
);
181 bRes
= aSecurityPipe
.is( );
183 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name, option and security, the test of security is not implemented yet.",
190 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
191 /// create a pipe using copy constructor.
192 ::osl::Pipe
aCopyPipe( aPipe
);
194 bRes
= aCopyPipe
.is( ) && aCopyPipe
== aPipe
;
196 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test copy constructor.",
202 When test the following two constructors, don't know how to test the
203 acquire and no acquire action. possible plans:
204 1.release one handle and check the other( did not success since the
205 other still exist and valid. )
206 2. release one handle twice to see getLastError( )(the getLastError
207 always returns invalidError(LINUX)).
210 void ctors_no_acquire( )
213 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
214 /// constructs a pipe reference without acquiring the handle.
215 ::osl::Pipe
aNoAcquirePipe( aPipe
.getHandle( ), SAL_NO_ACQUIRE
);
217 bRes
= aNoAcquirePipe
.is( );
219 ///bRes1 = aNoAcquirePipe.is( );
221 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no acquire of handle, only validation test, do not know how to test no acquire.",
225 void ctors_acquire( )
227 /// create a base pipe.
228 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
229 /// constructs two pipes without acquiring the handle on the base pipe.
230 ::osl::Pipe
aAcquirePipe( aPipe
.getHandle( ) );
231 ::osl::Pipe
aAcquirePipe1( NULL
);
233 bRes
= aAcquirePipe
.is( );
234 bRes1
= aAcquirePipe1
.is( );
236 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no acquire of handle.only validation test, do not know how to test no acquire.",
237 sal_True
== bRes
&& sal_False
== bRes1
);
240 CPPUNIT_TEST_SUITE( ctors
);
241 CPPUNIT_TEST( ctors_none
);
242 CPPUNIT_TEST( ctors_name_option
);
243 CPPUNIT_TEST( ctors_name_option_security
);
244 CPPUNIT_TEST( ctors_copy
);
245 CPPUNIT_TEST( ctors_no_acquire
);
246 CPPUNIT_TEST( ctors_acquire
);
247 CPPUNIT_TEST_SUITE_END( );
250 /** testing the method:
251 inline sal_Bool SAL_CALL is() const;
253 class is
: public CppUnit::TestFixture
260 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), check if the pipe is a valid one.", sal_False
== aPipe
.is( ) );
265 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
267 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), a normal pipe creation.", sal_True
== aPipe
.is( ) );
272 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
275 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), an invalid case.", sal_False
== aPipe
.is( ) );
280 ::osl::Pipe
aPipe( NULL
);
282 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), an invalid constructor.", sal_False
== aPipe
.is( ) );
285 CPPUNIT_TEST_SUITE( is
);
286 CPPUNIT_TEST( is_001
);
287 CPPUNIT_TEST( is_002
);
288 CPPUNIT_TEST( is_003
);
289 CPPUNIT_TEST( is_004
);
290 CPPUNIT_TEST_SUITE_END( );
293 /** testing the methods:
294 inline sal_Bool create( const ::rtl::OUString & strName,
295 oslPipeOptions Options, const Security &rSec );
296 nline sal_Bool create( const ::rtl::OUString & strName,
297 oslPipeOptions Options = osl_Pipe_OPEN );
299 class create
: public CppUnit::TestFixture
302 sal_Bool bRes
, bRes1
;
306 security create only be tested creation, security section is
310 void create_named_security_001( )
314 bRes
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
, rSec
);
315 bRes1
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
, rSec
);
318 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.",
319 sal_True
== bRes
&& sal_False
== bRes1
);
322 void create_named_security_002( )
325 ::osl::Pipe aPipe
, aPipe1
;
326 bRes
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
, rSec
);
327 bRes1
= aPipe1
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
, rSec
);
330 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.",
331 sal_True
== bRes
&& sal_True
== bRes1
);
334 void create_named_001( )
337 bRes
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
338 bRes1
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
341 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.",
342 sal_True
== bRes
&& sal_False
== bRes1
);
345 void create_named_002( )
347 ::osl::Pipe aPipe
, aPipe1
;
348 bRes
= aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
349 bRes1
= aPipe1
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
);
352 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.",
353 sal_True
== bRes
&& sal_True
== bRes1
);
356 void create_named_003( )
359 bRes
= aPipe
.create( test::uniquePipeName(aTestPipeName
) );
362 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test default option is open.",
366 CPPUNIT_TEST_SUITE( create
);
367 CPPUNIT_TEST( create_named_security_001
);
368 CPPUNIT_TEST( create_named_security_002
);
369 CPPUNIT_TEST( create_named_001
);
370 CPPUNIT_TEST( create_named_002
);
371 CPPUNIT_TEST( create_named_003
);
372 CPPUNIT_TEST_SUITE_END( );
375 /** testing the method:
376 inline void SAL_CALL clear();
378 class clear
: public CppUnit::TestFixture
381 sal_Bool bRes
, bRes1
;
386 aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
390 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test clear.",
394 CPPUNIT_TEST_SUITE( clear
);
395 CPPUNIT_TEST( clear_001
);
396 CPPUNIT_TEST_SUITE_END( );
399 /** testing the methods:
400 inline Pipe& SAL_CALL operator= (const Pipe& pipe);
401 inline Pipe& SAL_CALL operator= (const oslPipe pipe );
403 class assign
: public CppUnit::TestFixture
406 sal_Bool bRes
, bRes1
;
410 ::osl::Pipe aPipe
, aPipe1
;
411 aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
414 bRes1
= aPipe
== aPipe1
;
418 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with reference.",
419 sal_True
== bRes
&& sal_True
== bRes1
);
422 void assign_handle( )
424 ::osl::Pipe aPipe
, aPipe1
;
425 aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
426 aPipe1
= aPipe
.getHandle( );
428 bRes1
= aPipe
== aPipe1
;
432 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with handle.",
433 sal_True
== bRes
&& sal_True
== bRes1
);
436 CPPUNIT_TEST_SUITE( assign
);
437 CPPUNIT_TEST( assign_ref
);
438 CPPUNIT_TEST( assign_handle
);
439 CPPUNIT_TEST_SUITE_END( );
442 /** testing the method:
443 inline sal_Bool SAL_CALL isValid() const;
444 isValid( ) has not been implemented under the following platforms, please refer to osl/pipe.hxx
447 /** testing the method:
448 inline sal_Bool SAL_CALL operator==( const Pipe& rPipe ) const;
450 class isEqual
: public CppUnit::TestFixture
453 sal_Bool bRes
, bRes1
;
458 aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
459 bRes
= aPipe
== aPipe
;
462 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(), compare its self.",
468 ::osl::Pipe aPipe
, aPipe1
, aPipe2
;
469 aPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
472 aPipe2
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
474 bRes
= aPipe
== aPipe1
;
475 bRes1
= aPipe
== aPipe2
;
480 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(),create one copy instance, and compare.",
481 sal_True
== bRes
&& sal_False
== bRes1
);
484 CPPUNIT_TEST_SUITE( isEqual
);
485 CPPUNIT_TEST( isEqual_001
);
486 CPPUNIT_TEST( isEqual_002
);
487 CPPUNIT_TEST_SUITE_END( );
490 /** testing the method:
491 inline void SAL_CALL close();
493 class close
: public CppUnit::TestFixture
496 sal_Bool bRes
, bRes1
;
500 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipe1
), osl_Pipe_CREATE
);
507 CPPUNIT_ASSERT_MESSAGE( "#test comment#: difference between close and clear.",
508 sal_True
== bRes
&& sal_False
== bRes1
);
513 ::osl::StreamPipe
aPipe( test::uniquePipeName(aTestPipe1
), osl_Pipe_CREATE
);
515 int nRet
= aPipe
.send( m_pTestString1
.getStr(), 3 );
517 CPPUNIT_ASSERT_MESSAGE( "#test comment#: use after close.",
518 OSL_PIPE_FAIL
== nRet
);
521 CPPUNIT_TEST_SUITE( close
);
522 CPPUNIT_TEST( close_001
);
523 CPPUNIT_TEST( close_002
);
524 CPPUNIT_TEST_SUITE_END( );
527 /** testing the method:
528 inline oslPipeError SAL_CALL accept(StreamPipe& Connection);
529 please refer to StreamPipe::recv
532 /** testing the method:
533 inline oslPipeError SAL_CALL getError() const;
535 class getError
: public CppUnit::TestFixture
538 sal_Bool bRes
, bRes1
;
542 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
);
543 oslPipeError nError
= aPipe
.getError( );
544 printPipeError( aPipe
);
547 CPPUNIT_ASSERT_MESSAGE( "#test comment#: open a non-exist pipe.",
548 nError
!= osl_Pipe_E_None
);
553 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
554 ::osl::Pipe
aPipe1( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
555 oslPipeError nError
= aPipe
.getError( );
556 printPipeError( aPipe
);
560 CPPUNIT_ASSERT_MESSAGE( "#test comment#: create an already exist pipe.",
561 nError
!= osl_Pipe_E_None
);
564 CPPUNIT_TEST_SUITE( getError
);
565 CPPUNIT_TEST( getError_001
);
566 CPPUNIT_TEST( getError_002
);
567 CPPUNIT_TEST_SUITE_END( );
570 /** testing the method:
571 inline oslPipe SAL_CALL getHandle() const;
573 class getHandle
: public CppUnit::TestFixture
576 sal_Bool bRes
, bRes1
;
578 void getHandle_001( )
580 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
);
581 bRes
= aPipe
== aPipe
.getHandle( );
584 CPPUNIT_ASSERT_MESSAGE( "#test comment#: one pipe should equal to its handle.",
588 void getHandle_002( )
590 ::osl::Pipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
591 ::osl::Pipe
aPipe1( aPipe
.getHandle( ) );
592 bRes
= aPipe
== aPipe1
;
596 CPPUNIT_ASSERT_MESSAGE( "#test comment#: one pipe derived from another pipe's handle.",
600 CPPUNIT_TEST_SUITE( getHandle
);
601 CPPUNIT_TEST( getHandle_001
);
602 CPPUNIT_TEST( getHandle_002
);
603 CPPUNIT_TEST_SUITE_END( );
604 }; // class getHandle
606 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::ctors
);
607 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::is
);
608 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::create
);
609 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::clear
);
610 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::assign
);
611 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::isEqual
);
612 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::close
);
613 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::getError
);
614 CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::getHandle
);
616 } // namespace osl_Pipe
618 namespace osl_StreamPipe
621 /** testing the methods:
623 inline StreamPipe(oslPipe Pipe);;
624 inline StreamPipe(const StreamPipe& Pipe);
625 inline StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options = osl_Pipe_OPEN);
626 inline StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options, const Security &rSec );
627 inline StreamPipe( oslPipe pipe, __sal_NoAcquire noacquire );
629 class ctors
: public CppUnit::TestFixture
632 sal_Bool bRes
, bRes1
;
637 ::osl::StreamPipe
aStreamPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
638 // create an unattached pipe.
639 ::osl::StreamPipe aStreamPipe1
;
640 bRes
= aStreamPipe1
.is( );
642 // assign it and check.
643 aStreamPipe1
= aStreamPipe
;
644 bRes1
= aStreamPipe1
.is( );
645 aStreamPipe
.clear( );
646 aStreamPipe1
.clear( );
648 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, before and after assign.",
649 sal_False
== bRes
&& sal_True
== bRes1
);
655 ::osl::StreamPipe
aStreamPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
656 // create a pipe with last handle.
657 ::osl::StreamPipe
aStreamPipe1( aStreamPipe
.getHandle( ) );
658 bRes
= aStreamPipe1
.is( ) && aStreamPipe
== aStreamPipe1
;
659 aStreamPipe
.clear( );
660 aStreamPipe1
.clear( );
662 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with other's handle.",
669 ::osl::StreamPipe
aStreamPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
670 // create an unattached pipe.
671 ::osl::StreamPipe
aStreamPipe1( aStreamPipe
);
672 bRes
= aStreamPipe1
.is( ) && aStreamPipe
== aStreamPipe1
;
673 aStreamPipe
.clear( );
674 aStreamPipe1
.clear( );
676 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test copy constructor.",
680 void ctors_name_option( )
683 ::osl::StreamPipe
aStreamPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
684 // create an unattached pipe.
685 ::osl::StreamPipe
aStreamPipe1( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
);
686 bRes
= aStreamPipe1
.is( ) && aStreamPipe
.is( );
687 aStreamPipe
.clear( );
688 aStreamPipe1
.clear( );
690 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name and option.",
694 void ctors_name_option_security( )
696 /// create a security pipe.
697 const ::osl::Security rSecurity
;
698 ::osl::StreamPipe
aSecurityPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
, rSecurity
);
700 bRes
= aSecurityPipe
.is( );
701 aSecurityPipe
.clear( );
703 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name, option and security, the test of security is not implemented yet.",
709 When test the following constructor, don't know how to test the
710 acquire and no acquire action. possible plans:
711 1.release one handle and check the other( did not success since the
712 other still exist and valid. )
713 2. release one handle twice to see getLastError( )(the getLastError
714 always returns invalidError(LINUX)).
717 void ctors_no_acquire( )
720 ::osl::StreamPipe
aPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
721 // constructs a pipe reference without acquiring the handle.
722 ::osl::StreamPipe
aNoAcquirePipe( aPipe
.getHandle( ), SAL_NO_ACQUIRE
);
724 bRes
= aNoAcquirePipe
.is( );
727 CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no acquire of handle, only validation test, do not know how to test no acquire.",
731 CPPUNIT_TEST_SUITE( ctors
);
732 CPPUNIT_TEST( ctors_none
);
733 CPPUNIT_TEST( ctors_handle
);
734 CPPUNIT_TEST( ctors_copy
);
735 CPPUNIT_TEST( ctors_name_option
);
736 CPPUNIT_TEST( ctors_name_option_security
);
737 CPPUNIT_TEST( ctors_no_acquire
);
738 CPPUNIT_TEST_SUITE_END( );
741 /** testing the methods:
742 inline StreamPipe & SAL_CALL operator=(oslPipe Pipe);
743 inline StreamPipe& SAL_CALL operator=(const Pipe& pipe);
744 mindy: not implementated in osl/pipe.hxx, so remove the cases
747 /** wait _nSec seconds.
749 void thread_sleep( sal_uInt32 _nSec
)
751 /// print statement in thread process must use fflush() to force display.
757 osl_waitThread(&nTV
);
759 // test read/write & send/recv data to pipe
761 class Pipe_DataSink_Thread
: public Thread
765 Pipe_DataSink_Thread( ) { }
767 ~Pipe_DataSink_Thread( )
773 printf("open pipe\n");
774 ::osl::StreamPipe
aSenderPipe( test::uniquePipeName(aTestPipeName
), osl_Pipe_OPEN
); // test::uniquePipeName(aTestPipeName) is a string = "TestPipe"
775 if ( aSenderPipe
.is() == sal_False
)
777 printf("pipe open failed! \n");
782 sal_Int32 nChars
= aSenderPipe
.read( buf
, m_pTestString1
.getLength() + 1 );
785 printf("read failed! \n");
788 printf("buffer is %s \n", buf
);
790 nChars
= aSenderPipe
.send( m_pTestString2
.getStr(), m_pTestString2
.getLength() + 1 );
793 printf("client send failed! \n");
801 class Pipe_DataSource_Thread
: public Thread
805 ::osl::Pipe aListenPipe
;
806 ::osl::StreamPipe aConnectionPipe
;
807 Pipe_DataSource_Thread( )
809 printf("create pipe\n");
810 aListenPipe
.create( test::uniquePipeName(aTestPipeName
), osl_Pipe_CREATE
);
812 ~Pipe_DataSource_Thread( )
822 if ( aListenPipe
.is() == sal_False
)
824 printf("pipe create failed! \n");
828 //start server and wait for connection.
830 if ( osl_Pipe_E_None
!= aListenPipe
.accept( aConnectionPipe
) )
832 printf("pipe accept failed!");
837 nChars
= aConnectionPipe
.write( m_pTestString1
.getStr(), m_pTestString1
.getLength() + 1 );
840 printf("server write failed! \n");
844 nChars
= aConnectionPipe
.recv( buf
, 256 );
848 printf("server receive failed! \n");
851 printf("received message is: %s\n", buf
);
856 /** testing the method: read/write/send/recv and Pipe::accept
858 class recv
: public CppUnit::TestFixture
861 sal_Bool bRes
, bRes1
;
866 Pipe_DataSource_Thread myDataSourceThread
;
867 Pipe_DataSink_Thread myDataSinkThread
;
868 myDataSourceThread
.create( );
870 myDataSinkThread
.create( );
872 //wait until the thread terminate
873 myDataSinkThread
.join( );
874 myDataSourceThread
.join( );
876 int nCompare1
= strcmp( myDataSinkThread
.buf
, m_pTestString1
.getStr() );
877 int nCompare2
= strcmp( myDataSourceThread
.buf
, m_pTestString2
.getStr() );
878 CPPUNIT_ASSERT_MESSAGE( "test send/recv/write/read.", nCompare1
== 0 && nCompare2
== 0 );
880 //close pipe when accept
885 Pipe_DataSource_Thread myDataSourceThread
;
886 Pipe_DataSink_Thread myDataSinkThread
;
887 myDataSourceThread
.create( );
889 myDataSourceThread
.aListenPipe
.close();
890 myDataSourceThread
.join( );
891 //no condition judgement here, if the case could finish excuting within 1 or 2 seconds, it passes.
894 CPPUNIT_TEST_SUITE( recv
);
895 CPPUNIT_TEST( recv_001
);
896 CPPUNIT_TEST( recv_002
);
897 CPPUNIT_TEST_SUITE_END( );
900 CPPUNIT_TEST_SUITE_REGISTRATION(osl_StreamPipe::ctors
);
901 //CPPUNIT_TEST_SUITE_REGISTRATION(osl_StreamPipe::assign);
902 CPPUNIT_TEST_SUITE_REGISTRATION(osl_StreamPipe::recv
);
904 } // namespace osl_StreamPipe
906 CPPUNIT_PLUGIN_IMPLEMENT();
908 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */