1*87d2adbcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*87d2adbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*87d2adbcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*87d2adbcSAndrew Rist * distributed with this work for additional information 6*87d2adbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*87d2adbcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*87d2adbcSAndrew Rist * "License"); you may not use this file except in compliance 9*87d2adbcSAndrew Rist * with the License. You may obtain a copy of the License at 10*87d2adbcSAndrew Rist * 11*87d2adbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*87d2adbcSAndrew Rist * 13*87d2adbcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*87d2adbcSAndrew Rist * software distributed under the License is distributed on an 15*87d2adbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*87d2adbcSAndrew Rist * KIND, either express or implied. See the License for the 17*87d2adbcSAndrew Rist * specific language governing permissions and limitations 18*87d2adbcSAndrew Rist * under the License. 19*87d2adbcSAndrew Rist * 20*87d2adbcSAndrew Rist *************************************************************/ 21*87d2adbcSAndrew Rist 22*87d2adbcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sal.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir //------------------------------------------------------------------------ 28cdf0e10cSrcweir // include files 29cdf0e10cSrcweir //------------------------------------------------------------------------ 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include "cppunit/TestAssert.h" 32cdf0e10cSrcweir #include "cppunit/TestFixture.h" 33cdf0e10cSrcweir #include "cppunit/extensions/HelperMacros.h" 34cdf0e10cSrcweir #include "cppunit/plugin/TestPlugIn.h" 35cdf0e10cSrcweir #include "test/uniquepipename.hxx" 36cdf0e10cSrcweir #include <sal/types.h> 37cdf0e10cSrcweir #include <rtl/ustring.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir #ifndef _OSL_THREAD_HXX 40cdf0e10cSrcweir #include <osl/thread.hxx> 41cdf0e10cSrcweir #endif 42cdf0e10cSrcweir 43cdf0e10cSrcweir #ifndef _OSL_MUTEX_HXX 44cdf0e10cSrcweir #include <osl/mutex.hxx> 45cdf0e10cSrcweir #endif 46cdf0e10cSrcweir 47cdf0e10cSrcweir #ifndef _OSL_MUTEX_HXX 48cdf0e10cSrcweir #include <osl/pipe.hxx> 49cdf0e10cSrcweir #endif 50cdf0e10cSrcweir #include <osl/time.h> 51cdf0e10cSrcweir 52cdf0e10cSrcweir #ifdef UNX 53cdf0e10cSrcweir #include <unistd.h> 54cdf0e10cSrcweir #endif 55cdf0e10cSrcweir #include <string.h> 56cdf0e10cSrcweir 57cdf0e10cSrcweir using namespace osl; 58cdf0e10cSrcweir using namespace rtl; 59cdf0e10cSrcweir 60cdf0e10cSrcweir //------------------------------------------------------------------------ 61cdf0e10cSrcweir // helper functions 62cdf0e10cSrcweir //------------------------------------------------------------------------ 63cdf0e10cSrcweir 64cdf0e10cSrcweir /** print Boolean value. 65cdf0e10cSrcweir */ 66cdf0e10cSrcweir inline void printBool( sal_Bool bOk ) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir printf("#printBool# " ); 69cdf0e10cSrcweir ( sal_True == bOk ) ? printf("YES!\n" ): printf("NO!\n" ); 70cdf0e10cSrcweir } 71cdf0e10cSrcweir 72cdf0e10cSrcweir /** print a UNI_CODE String. 73cdf0e10cSrcweir */ 74cdf0e10cSrcweir inline void printUString( const ::rtl::OUString & str ) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir rtl::OString aString; 77cdf0e10cSrcweir 78cdf0e10cSrcweir printf("#printUString_u# " ); 79cdf0e10cSrcweir aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ); 80cdf0e10cSrcweir printf("%s\n", aString.getStr( ) ); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir /** print last error of pipe system. 84cdf0e10cSrcweir */ 85cdf0e10cSrcweir inline void printPipeError( ::osl::Pipe aPipe ) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir oslPipeError nError = aPipe.getError( ); 88cdf0e10cSrcweir printf("#printPipeError# " ); 89cdf0e10cSrcweir switch ( nError ) { 90cdf0e10cSrcweir case osl_Pipe_E_None: 91cdf0e10cSrcweir printf("Success!\n" ); 92cdf0e10cSrcweir break; 93cdf0e10cSrcweir case osl_Pipe_E_NotFound: 94cdf0e10cSrcweir printf("The returned error is: Not found!\n" ); 95cdf0e10cSrcweir break; 96cdf0e10cSrcweir case osl_Pipe_E_AlreadyExists: 97cdf0e10cSrcweir printf("The returned error is: Already exist!\n" ); 98cdf0e10cSrcweir break; 99cdf0e10cSrcweir case osl_Pipe_E_NoProtocol: 100cdf0e10cSrcweir printf("The returned error is: No protocol!\n" ); 101cdf0e10cSrcweir break; 102cdf0e10cSrcweir case osl_Pipe_E_NetworkReset: 103cdf0e10cSrcweir printf("The returned error is: Network reset!\n" ); 104cdf0e10cSrcweir break; 105cdf0e10cSrcweir case osl_Pipe_E_ConnectionAbort: 106cdf0e10cSrcweir printf("The returned error is: Connection aborted!\n" ); 107cdf0e10cSrcweir break; 108cdf0e10cSrcweir case osl_Pipe_E_ConnectionReset: 109cdf0e10cSrcweir printf("The returned error is: Connection reset!\n" ); 110cdf0e10cSrcweir break; 111cdf0e10cSrcweir case osl_Pipe_E_NoBufferSpace: 112cdf0e10cSrcweir printf("The returned error is: No buffer space!\n" ); 113cdf0e10cSrcweir break; 114cdf0e10cSrcweir case osl_Pipe_E_TimedOut: 115cdf0e10cSrcweir printf("The returned error is: Timeout!\n" ); 116cdf0e10cSrcweir break; 117cdf0e10cSrcweir case osl_Pipe_E_ConnectionRefused: 118cdf0e10cSrcweir printf("The returned error is: Connection refused!\n" ); 119cdf0e10cSrcweir break; 120cdf0e10cSrcweir case osl_Pipe_E_invalidError: 121cdf0e10cSrcweir printf("The returned error is: Invalid error!\n" ); 122cdf0e10cSrcweir break; 123cdf0e10cSrcweir default: 124cdf0e10cSrcweir printf("The returned error is: Number %d, Unknown Error\n", nError ); 125cdf0e10cSrcweir break; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir 130cdf0e10cSrcweir 131cdf0e10cSrcweir //------------------------------------------------------------------------ 132cdf0e10cSrcweir // pipe name and transfer contents 133cdf0e10cSrcweir //------------------------------------------------------------------------ 134cdf0e10cSrcweir const rtl::OUString aTestPipeName = rtl::OUString::createFromAscii( "testpipe2" ); 135cdf0e10cSrcweir const rtl::OUString aTestPipe1 = rtl::OUString::createFromAscii( "testpipe1" ); 136cdf0e10cSrcweir const rtl::OUString aTestString = rtl::OUString::createFromAscii( "Sun Microsystems" ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir const OString m_pTestString1("Sun Microsystems"); 139cdf0e10cSrcweir const OString m_pTestString2("test pipe PASS/OK"); 140cdf0e10cSrcweir 141cdf0e10cSrcweir //------------------------------------------------------------------------ 142cdf0e10cSrcweir // test code start here 143cdf0e10cSrcweir //------------------------------------------------------------------------ 144cdf0e10cSrcweir 145cdf0e10cSrcweir namespace osl_Pipe 146cdf0e10cSrcweir { 147cdf0e10cSrcweir 148cdf0e10cSrcweir //------------------------------------------------------------------------ 149cdf0e10cSrcweir // most return value -1 denote a fail of operation. 150cdf0e10cSrcweir //------------------------------------------------------------------------ 151cdf0e10cSrcweir #define OSL_PIPE_FAIL -1 152cdf0e10cSrcweir 153cdf0e10cSrcweir /** testing the methods: 154cdf0e10cSrcweir inline Pipe(); 155cdf0e10cSrcweir inline Pipe(const ::rtl::OUString& strName, oslPipeOptions Options); 156cdf0e10cSrcweir inline Pipe(const ::rtl::OUString& strName, oslPipeOptions Options,const Security & rSecurity); 157cdf0e10cSrcweir inline Pipe(const Pipe& pipe); 158cdf0e10cSrcweir inline Pipe(oslPipe pipe, __sal_NoAcquire noacquire ); 159cdf0e10cSrcweir inline Pipe(oslPipe Pipe); 160cdf0e10cSrcweir */ 161cdf0e10cSrcweir class ctors : public CppUnit::TestFixture 162cdf0e10cSrcweir { 163cdf0e10cSrcweir public: 164cdf0e10cSrcweir sal_Bool bRes, bRes1; 165cdf0e10cSrcweir 166cdf0e10cSrcweir void setUp( ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir void tearDown( ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir void ctors_none( ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir ::osl::Pipe aPipe; 177cdf0e10cSrcweir bRes = aPipe.is( ); 178cdf0e10cSrcweir 179cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, yet no case to test.", 180cdf0e10cSrcweir sal_False == bRes ); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir void ctors_name_option( ) 184cdf0e10cSrcweir { 185cdf0e10cSrcweir /// create a named pipe. 186cdf0e10cSrcweir ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 187cdf0e10cSrcweir ::osl::Pipe aAssignPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_OPEN ); 188cdf0e10cSrcweir 189cdf0e10cSrcweir bRes = aPipe.is( ) && aAssignPipe.is( ); 190cdf0e10cSrcweir 191cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name and option.", 192cdf0e10cSrcweir sal_True == bRes ); 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir void ctors_name_option_security( ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir /// create a security pipe. 198cdf0e10cSrcweir const ::osl::Security rSecurity; 199cdf0e10cSrcweir ::osl::Pipe aSecurityPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE, rSecurity ); 200cdf0e10cSrcweir 201cdf0e10cSrcweir bRes = aSecurityPipe.is( ); 202cdf0e10cSrcweir 203cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name, option and security, the test of security is not implemented yet.", 204cdf0e10cSrcweir sal_True == bRes ); 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir void ctors_copy( ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir /// create a pipe. 210cdf0e10cSrcweir ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 211cdf0e10cSrcweir /// create a pipe using copy constructor. 212cdf0e10cSrcweir ::osl::Pipe aCopyPipe( aPipe ); 213cdf0e10cSrcweir 214cdf0e10cSrcweir bRes = aCopyPipe.is( ) && aCopyPipe == aPipe; 215cdf0e10cSrcweir 216cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test copy constructor.", 217cdf0e10cSrcweir sal_True == bRes ); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir 220cdf0e10cSrcweir /** tester comment: 221cdf0e10cSrcweir 222cdf0e10cSrcweir When test the following two constructors, don't know how to test the 223cdf0e10cSrcweir acquire and no acquire action. possible plans: 224cdf0e10cSrcweir 1.release one handle and check the other( did not success since the 225cdf0e10cSrcweir other still exist and valid. ) 226cdf0e10cSrcweir 2. release one handle twice to see getLastError( )(the getLastError 227cdf0e10cSrcweir always returns invalidError(LINUX)). 228cdf0e10cSrcweir */ 229cdf0e10cSrcweir 230cdf0e10cSrcweir void ctors_no_acquire( ) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir /// create a pipe. 233cdf0e10cSrcweir ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 234cdf0e10cSrcweir /// constructs a pipe reference without acquiring the handle. 235cdf0e10cSrcweir ::osl::Pipe aNoAcquirePipe( aPipe.getHandle( ), SAL_NO_ACQUIRE ); 236cdf0e10cSrcweir 237cdf0e10cSrcweir bRes = aNoAcquirePipe.is( ); 238cdf0e10cSrcweir ///aPipe.clear( ); 239cdf0e10cSrcweir ///bRes1 = aNoAcquirePipe.is( ); 240cdf0e10cSrcweir 241cdf0e10cSrcweir 242cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no aquire of handle, only validation test, do not know how to test no acquire.", 243cdf0e10cSrcweir sal_True == bRes ); 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir void ctors_acquire( ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir /// create a base pipe. 249cdf0e10cSrcweir ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 250cdf0e10cSrcweir /// constructs two pipes without acquiring the handle on the base pipe. 251cdf0e10cSrcweir ::osl::Pipe aAcquirePipe( aPipe.getHandle( ) ); 252cdf0e10cSrcweir ::osl::Pipe aAcquirePipe1( NULL ); 253cdf0e10cSrcweir 254cdf0e10cSrcweir bRes = aAcquirePipe.is( ); 255cdf0e10cSrcweir bRes1 = aAcquirePipe1.is( ); 256cdf0e10cSrcweir 257cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no aquire of handle.only validation test, do not know how to test no acquire.", 258cdf0e10cSrcweir sal_True == bRes && sal_False == bRes1 ); 259cdf0e10cSrcweir } 260cdf0e10cSrcweir 261cdf0e10cSrcweir CPPUNIT_TEST_SUITE( ctors ); 262cdf0e10cSrcweir CPPUNIT_TEST( ctors_none ); 263cdf0e10cSrcweir CPPUNIT_TEST( ctors_name_option ); 264cdf0e10cSrcweir CPPUNIT_TEST( ctors_name_option_security ); 265cdf0e10cSrcweir CPPUNIT_TEST( ctors_copy ); 266cdf0e10cSrcweir CPPUNIT_TEST( ctors_no_acquire ); 267cdf0e10cSrcweir CPPUNIT_TEST( ctors_acquire ); 268cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END( ); 269cdf0e10cSrcweir }; // class ctors 270cdf0e10cSrcweir 271cdf0e10cSrcweir 272cdf0e10cSrcweir /** testing the method: 273cdf0e10cSrcweir inline sal_Bool SAL_CALL is() const; 274cdf0e10cSrcweir */ 275cdf0e10cSrcweir class is : public CppUnit::TestFixture 276cdf0e10cSrcweir { 277cdf0e10cSrcweir public: 278cdf0e10cSrcweir void is_001( ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir ::osl::Pipe aPipe; 281cdf0e10cSrcweir 282cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), check if the pipe is a valid one.", sal_False == aPipe.is( ) ); 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir void is_002( ) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 288cdf0e10cSrcweir 289cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), a normal pipe creation.", sal_True == aPipe.is( ) ); 290cdf0e10cSrcweir } 291cdf0e10cSrcweir 292cdf0e10cSrcweir void is_003( ) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 295cdf0e10cSrcweir aPipe.clear( ); 296cdf0e10cSrcweir 297cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), an invalid case.", sal_False == aPipe.is( ) ); 298cdf0e10cSrcweir } 299cdf0e10cSrcweir 300cdf0e10cSrcweir void is_004( ) 301cdf0e10cSrcweir { 302cdf0e10cSrcweir ::osl::Pipe aPipe( NULL ); 303cdf0e10cSrcweir 304cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test is(), an invalid constructor.", sal_False == aPipe.is( ) ); 305cdf0e10cSrcweir } 306cdf0e10cSrcweir 307cdf0e10cSrcweir CPPUNIT_TEST_SUITE( is ); 308cdf0e10cSrcweir CPPUNIT_TEST( is_001 ); 309cdf0e10cSrcweir CPPUNIT_TEST( is_002 ); 310cdf0e10cSrcweir CPPUNIT_TEST( is_003 ); 311cdf0e10cSrcweir CPPUNIT_TEST( is_004 ); 312cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END( ); 313cdf0e10cSrcweir }; // class is 314cdf0e10cSrcweir 315cdf0e10cSrcweir 316cdf0e10cSrcweir /** testing the methods: 317cdf0e10cSrcweir inline sal_Bool create( const ::rtl::OUString & strName, 318cdf0e10cSrcweir oslPipeOptions Options, const Security &rSec ); 319cdf0e10cSrcweir nline sal_Bool create( const ::rtl::OUString & strName, 320cdf0e10cSrcweir oslPipeOptions Options = osl_Pipe_OPEN ); 321cdf0e10cSrcweir */ 322cdf0e10cSrcweir class create : public CppUnit::TestFixture 323cdf0e10cSrcweir { 324cdf0e10cSrcweir public: 325cdf0e10cSrcweir sal_Bool bRes, bRes1; 326cdf0e10cSrcweir 327cdf0e10cSrcweir /** tester comment: 328cdf0e10cSrcweir 329cdf0e10cSrcweir security create only be tested creation, security section is 330cdf0e10cSrcweir untested yet. 331cdf0e10cSrcweir */ 332cdf0e10cSrcweir 333cdf0e10cSrcweir void create_named_security_001( ) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir const Security rSec; 336cdf0e10cSrcweir ::osl::Pipe aPipe; 337cdf0e10cSrcweir bRes = aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE, rSec ); 338cdf0e10cSrcweir bRes1 = aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE, rSec ); 339cdf0e10cSrcweir aPipe.clear( ); 340cdf0e10cSrcweir 341cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.", 342cdf0e10cSrcweir sal_True == bRes && sal_False == bRes1); 343cdf0e10cSrcweir } 344cdf0e10cSrcweir 345cdf0e10cSrcweir void create_named_security_002( ) 346cdf0e10cSrcweir { 347cdf0e10cSrcweir const Security rSec; 348cdf0e10cSrcweir ::osl::Pipe aPipe, aPipe1; 349cdf0e10cSrcweir bRes = aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE, rSec ); 350cdf0e10cSrcweir bRes1 = aPipe1.create( test::uniquePipeName(aTestPipeName), osl_Pipe_OPEN, rSec ); 351cdf0e10cSrcweir aPipe.clear( ); 352cdf0e10cSrcweir 353cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.", 354cdf0e10cSrcweir sal_True == bRes && sal_True == bRes1); 355cdf0e10cSrcweir } 356cdf0e10cSrcweir 357cdf0e10cSrcweir void create_named_001( ) 358cdf0e10cSrcweir { 359cdf0e10cSrcweir ::osl::Pipe aPipe; 360cdf0e10cSrcweir bRes = aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 361cdf0e10cSrcweir bRes1 = aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 362cdf0e10cSrcweir aPipe.clear( ); 363cdf0e10cSrcweir 364cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation.", 365cdf0e10cSrcweir sal_True == bRes && sal_False == bRes1); 366cdf0e10cSrcweir } 367cdf0e10cSrcweir 368cdf0e10cSrcweir void create_named_002( ) 369cdf0e10cSrcweir { 370cdf0e10cSrcweir ::osl::Pipe aPipe, aPipe1; 371cdf0e10cSrcweir bRes = aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 372cdf0e10cSrcweir bRes1 = aPipe1.create( test::uniquePipeName(aTestPipeName), osl_Pipe_OPEN ); 373cdf0e10cSrcweir aPipe.clear( ); 374cdf0e10cSrcweir 375cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test creation and open.", 376cdf0e10cSrcweir sal_True == bRes && sal_True == bRes1); 377cdf0e10cSrcweir } 378cdf0e10cSrcweir 379cdf0e10cSrcweir void create_named_003( ) 380cdf0e10cSrcweir { 381cdf0e10cSrcweir ::osl::Pipe aPipe; 382cdf0e10cSrcweir bRes = aPipe.create( test::uniquePipeName(aTestPipeName) ); 383cdf0e10cSrcweir aPipe.clear( ); 384cdf0e10cSrcweir 385cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test default option is open.", 386cdf0e10cSrcweir sal_False == bRes ); 387cdf0e10cSrcweir } 388cdf0e10cSrcweir 389cdf0e10cSrcweir CPPUNIT_TEST_SUITE( create ); 390cdf0e10cSrcweir CPPUNIT_TEST( create_named_security_001 ); 391cdf0e10cSrcweir CPPUNIT_TEST( create_named_security_002 ); 392cdf0e10cSrcweir CPPUNIT_TEST( create_named_001 ); 393cdf0e10cSrcweir CPPUNIT_TEST( create_named_002 ); 394cdf0e10cSrcweir CPPUNIT_TEST( create_named_003 ); 395cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END( ); 396cdf0e10cSrcweir }; // class create 397cdf0e10cSrcweir 398cdf0e10cSrcweir 399cdf0e10cSrcweir /** testing the method: 400cdf0e10cSrcweir inline void SAL_CALL clear(); 401cdf0e10cSrcweir */ 402cdf0e10cSrcweir class clear : public CppUnit::TestFixture 403cdf0e10cSrcweir { 404cdf0e10cSrcweir public: 405cdf0e10cSrcweir sal_Bool bRes, bRes1; 406cdf0e10cSrcweir 407cdf0e10cSrcweir void clear_001( ) 408cdf0e10cSrcweir { 409cdf0e10cSrcweir ::osl::Pipe aPipe; 410cdf0e10cSrcweir aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 411cdf0e10cSrcweir aPipe.clear( ); 412cdf0e10cSrcweir bRes = aPipe.is( ); 413cdf0e10cSrcweir 414cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test clear.", 415cdf0e10cSrcweir sal_False == bRes ); 416cdf0e10cSrcweir } 417cdf0e10cSrcweir 418cdf0e10cSrcweir CPPUNIT_TEST_SUITE( clear ); 419cdf0e10cSrcweir CPPUNIT_TEST( clear_001 ); 420cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END( ); 421cdf0e10cSrcweir }; // class clear 422cdf0e10cSrcweir 423cdf0e10cSrcweir 424cdf0e10cSrcweir /** testing the methods: 425cdf0e10cSrcweir inline Pipe& SAL_CALL operator= (const Pipe& pipe); 426cdf0e10cSrcweir inline Pipe& SAL_CALL operator= (const oslPipe pipe ); 427cdf0e10cSrcweir */ 428cdf0e10cSrcweir class assign : public CppUnit::TestFixture 429cdf0e10cSrcweir { 430cdf0e10cSrcweir public: 431cdf0e10cSrcweir sal_Bool bRes, bRes1; 432cdf0e10cSrcweir 433cdf0e10cSrcweir void assign_ref( ) 434cdf0e10cSrcweir { 435cdf0e10cSrcweir ::osl::Pipe aPipe, aPipe1; 436cdf0e10cSrcweir aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 437cdf0e10cSrcweir aPipe1 = aPipe; 438cdf0e10cSrcweir bRes = aPipe1.is( ); 439cdf0e10cSrcweir bRes1 = aPipe == aPipe1; 440cdf0e10cSrcweir aPipe.close( ); 441cdf0e10cSrcweir aPipe1.close( ); 442cdf0e10cSrcweir 443cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with reference.", 444cdf0e10cSrcweir sal_True == bRes && sal_True == bRes1 ); 445cdf0e10cSrcweir } 446cdf0e10cSrcweir 447cdf0e10cSrcweir void assign_handle( ) 448cdf0e10cSrcweir { 449cdf0e10cSrcweir ::osl::Pipe aPipe, aPipe1; 450cdf0e10cSrcweir aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 451cdf0e10cSrcweir aPipe1 = aPipe.getHandle( ); 452cdf0e10cSrcweir bRes = aPipe1.is( ); 453cdf0e10cSrcweir bRes1 = aPipe == aPipe1; 454cdf0e10cSrcweir aPipe.close( ); 455cdf0e10cSrcweir aPipe1.close( ); 456cdf0e10cSrcweir 457cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with handle.", 458cdf0e10cSrcweir sal_True == bRes && sal_True == bRes1 ); 459cdf0e10cSrcweir } 460cdf0e10cSrcweir 461cdf0e10cSrcweir CPPUNIT_TEST_SUITE( assign ); 462cdf0e10cSrcweir CPPUNIT_TEST( assign_ref ); 463cdf0e10cSrcweir CPPUNIT_TEST( assign_handle ); 464cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END( ); 465cdf0e10cSrcweir }; // class assign 466cdf0e10cSrcweir 467cdf0e10cSrcweir 468cdf0e10cSrcweir /** testing the method: 469cdf0e10cSrcweir inline sal_Bool SAL_CALL isValid() const; 470cdf0e10cSrcweir isValid( ) has not been implemented under the following platforms, please refer to osl/pipe.hxx 471cdf0e10cSrcweir */ 472cdf0e10cSrcweir /*class isValid : public CppUnit::TestFixture 473cdf0e10cSrcweir { 474cdf0e10cSrcweir public: 475cdf0e10cSrcweir sal_Bool bRes, bRes1; 476cdf0e10cSrcweir 477cdf0e10cSrcweir void isValid_001( ) 478cdf0e10cSrcweir { 479cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: isValid() has not been implemented on all platforms.", 480cdf0e10cSrcweir sal_False ); 481cdf0e10cSrcweir } 482cdf0e10cSrcweir 483cdf0e10cSrcweir CPPUNIT_TEST_SUITE( isValid ); 484cdf0e10cSrcweir CPPUNIT_TEST( isValid_001 ); 485cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END( ); 486cdf0e10cSrcweir };*/ // class isValid 487cdf0e10cSrcweir 488cdf0e10cSrcweir 489cdf0e10cSrcweir /** testing the method: 490cdf0e10cSrcweir inline sal_Bool SAL_CALL operator==( const Pipe& rPipe ) const; 491cdf0e10cSrcweir */ 492cdf0e10cSrcweir class isEqual : public CppUnit::TestFixture 493cdf0e10cSrcweir { 494cdf0e10cSrcweir public: 495cdf0e10cSrcweir sal_Bool bRes, bRes1; 496cdf0e10cSrcweir 497cdf0e10cSrcweir void isEqual_001( ) 498cdf0e10cSrcweir { 499cdf0e10cSrcweir ::osl::Pipe aPipe; 500cdf0e10cSrcweir aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 501cdf0e10cSrcweir bRes = aPipe == aPipe; 502cdf0e10cSrcweir aPipe.close( ); 503cdf0e10cSrcweir 504cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(), compare its self.", 505cdf0e10cSrcweir sal_True == bRes ); 506cdf0e10cSrcweir } 507cdf0e10cSrcweir 508cdf0e10cSrcweir void isEqual_002( ) 509cdf0e10cSrcweir { 510cdf0e10cSrcweir ::osl::Pipe aPipe, aPipe1, aPipe2; 511cdf0e10cSrcweir aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 512cdf0e10cSrcweir 513cdf0e10cSrcweir aPipe1 = aPipe; 514cdf0e10cSrcweir aPipe2.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 515cdf0e10cSrcweir 516cdf0e10cSrcweir bRes = aPipe == aPipe1; 517cdf0e10cSrcweir bRes1 = aPipe == aPipe2; 518cdf0e10cSrcweir aPipe.close( ); 519cdf0e10cSrcweir aPipe1.close( ); 520cdf0e10cSrcweir aPipe2.close( ); 521cdf0e10cSrcweir 522cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(),create one copy instance, and compare.", 523cdf0e10cSrcweir sal_True == bRes && sal_False == bRes1 ); 524cdf0e10cSrcweir } 525cdf0e10cSrcweir 526cdf0e10cSrcweir CPPUNIT_TEST_SUITE( isEqual ); 527cdf0e10cSrcweir CPPUNIT_TEST( isEqual_001 ); 528cdf0e10cSrcweir CPPUNIT_TEST( isEqual_002 ); 529cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END( ); 530cdf0e10cSrcweir }; // class isEqual 531cdf0e10cSrcweir 532cdf0e10cSrcweir 533cdf0e10cSrcweir /** testing the method: 534cdf0e10cSrcweir inline void SAL_CALL close(); 535cdf0e10cSrcweir */ 536cdf0e10cSrcweir class close : public CppUnit::TestFixture 537cdf0e10cSrcweir { 538cdf0e10cSrcweir public: 539cdf0e10cSrcweir sal_Bool bRes, bRes1; 540cdf0e10cSrcweir 541cdf0e10cSrcweir void close_001( ) 542cdf0e10cSrcweir { 543cdf0e10cSrcweir ::osl::Pipe aPipe( test::uniquePipeName(aTestPipe1), osl_Pipe_CREATE ); 544cdf0e10cSrcweir aPipe.close( ); 545cdf0e10cSrcweir bRes = aPipe.is( ); 546cdf0e10cSrcweir 547cdf0e10cSrcweir aPipe.clear( ); 548cdf0e10cSrcweir bRes1 = aPipe.is( ); 549cdf0e10cSrcweir 550cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: difference between close and clear.", 551cdf0e10cSrcweir sal_True == bRes && sal_False == bRes1); 552cdf0e10cSrcweir } 553cdf0e10cSrcweir 554cdf0e10cSrcweir void close_002( ) 555cdf0e10cSrcweir { 556cdf0e10cSrcweir ::osl::StreamPipe aPipe( test::uniquePipeName(aTestPipe1), osl_Pipe_CREATE ); 557cdf0e10cSrcweir aPipe.close( ); 558cdf0e10cSrcweir int nRet = aPipe.send( m_pTestString1.getStr(), 3 ); 559cdf0e10cSrcweir 560cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: use after close.", 561cdf0e10cSrcweir OSL_PIPE_FAIL == nRet ); 562cdf0e10cSrcweir } 563cdf0e10cSrcweir 564cdf0e10cSrcweir CPPUNIT_TEST_SUITE( close ); 565cdf0e10cSrcweir CPPUNIT_TEST( close_001 ); 566cdf0e10cSrcweir CPPUNIT_TEST( close_002 ); 567cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END( ); 568cdf0e10cSrcweir }; // class close 569cdf0e10cSrcweir 570cdf0e10cSrcweir 571cdf0e10cSrcweir /** testing the method: 572cdf0e10cSrcweir inline oslPipeError SAL_CALL accept(StreamPipe& Connection); 573cdf0e10cSrcweir please refer to StreamPipe::recv 574cdf0e10cSrcweir */ 575cdf0e10cSrcweir /* class accept : public CppUnit::TestFixture 576cdf0e10cSrcweir { 577cdf0e10cSrcweir public: 578cdf0e10cSrcweir sal_Bool bRes, bRes1; 579cdf0e10cSrcweir 580cdf0e10cSrcweir void accept_001( ) 581cdf0e10cSrcweir { 582cdf0e10cSrcweir 583cdf0e10cSrcweir // CPPUNIT_ASSERT_MESSAGE( "#test comment#: accept, untested.", 1 == 1 ); 584cdf0e10cSrcweir //CPPUNIT_ASSERT_STUB(); 585cdf0e10cSrcweir } 586cdf0e10cSrcweir 587cdf0e10cSrcweir CPPUNIT_TEST_SUITE( accept ); 588cdf0e10cSrcweir CPPUNIT_TEST( accept_001 ); 589cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END( ); 590cdf0e10cSrcweir };*/ // class accept 591cdf0e10cSrcweir 592cdf0e10cSrcweir 593cdf0e10cSrcweir /** testing the method: 594cdf0e10cSrcweir inline oslPipeError SAL_CALL getError() const; 595cdf0e10cSrcweir */ 596cdf0e10cSrcweir class getError : public CppUnit::TestFixture 597cdf0e10cSrcweir { 598cdf0e10cSrcweir public: 599cdf0e10cSrcweir sal_Bool bRes, bRes1; 600cdf0e10cSrcweir /* 601cdf0e10cSrcweir PipeError[]= { 602cdf0e10cSrcweir { 0, osl_Pipe_E_None }, // no error 603cdf0e10cSrcweir { EPROTOTYPE, osl_Pipe_E_NoProtocol }, // Protocol wrong type for socket 604cdf0e10cSrcweir { ENOPROTOOPT, osl_Pipe_E_NoProtocol }, // Protocol not available 605cdf0e10cSrcweir { EPROTONOSUPPORT, osl_Pipe_E_NoProtocol }, // Protocol not supported 606cdf0e10cSrcweir { ESOCKTNOSUPPORT, osl_Pipe_E_NoProtocol }, // Socket type not supported 607cdf0e10cSrcweir { EPFNOSUPPORT, osl_Pipe_E_NoProtocol }, // Protocol family not supported 608cdf0e10cSrcweir { EAFNOSUPPORT, osl_Pipe_E_NoProtocol }, // Address family not supported by 609cdf0e10cSrcweir // protocol family 610cdf0e10cSrcweir { ENETRESET, osl_Pipe_E_NetworkReset }, // Network dropped connection because 611cdf0e10cSrcweir // of reset 612cdf0e10cSrcweir { ECONNABORTED, osl_Pipe_E_ConnectionAbort }, // Software caused connection abort 613cdf0e10cSrcweir { ECONNRESET, osl_Pipe_E_ConnectionReset }, // Connection reset by peer 614cdf0e10cSrcweir { ENOBUFS, osl_Pipe_E_NoBufferSpace }, // No buffer space available 615cdf0e10cSrcweir { ETIMEDOUT, osl_Pipe_E_TimedOut }, // Connection timed out 616cdf0e10cSrcweir { ECONNREFUSED, osl_Pipe_E_ConnectionRefused }, // Connection refused 617cdf0e10cSrcweir { -1, osl_Pipe_E_invalidError } 618cdf0e10cSrcweir }; 619cdf0e10cSrcweir did not define osl_Pipe_E_NotFound, osl_Pipe_E_AlreadyExists 620cdf0e10cSrcweir */ 621cdf0e10cSrcweir 622cdf0e10cSrcweir void getError_001( ) 623cdf0e10cSrcweir { 624cdf0e10cSrcweir ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_OPEN ); 625cdf0e10cSrcweir oslPipeError nError = aPipe.getError( ); 626cdf0e10cSrcweir printPipeError( aPipe ); 627cdf0e10cSrcweir aPipe.clear( ); 628cdf0e10cSrcweir 629cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: open a non-exist pipe.", 630cdf0e10cSrcweir nError != osl_Pipe_E_None ); 631cdf0e10cSrcweir } 632cdf0e10cSrcweir 633cdf0e10cSrcweir void getError_002( ) 634cdf0e10cSrcweir { 635cdf0e10cSrcweir ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 636cdf0e10cSrcweir ::osl::Pipe aPipe1( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 637cdf0e10cSrcweir oslPipeError nError = aPipe.getError( ); 638cdf0e10cSrcweir printPipeError( aPipe ); 639cdf0e10cSrcweir aPipe.clear( ); 640cdf0e10cSrcweir aPipe1.clear( ); 641cdf0e10cSrcweir 642cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: create an already exist pipe.", 643cdf0e10cSrcweir nError != osl_Pipe_E_None ); 644cdf0e10cSrcweir } 645cdf0e10cSrcweir 646cdf0e10cSrcweir CPPUNIT_TEST_SUITE( getError ); 647cdf0e10cSrcweir CPPUNIT_TEST( getError_001 ); 648cdf0e10cSrcweir CPPUNIT_TEST( getError_002 ); 649cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END( ); 650cdf0e10cSrcweir }; // class getError 651cdf0e10cSrcweir 652cdf0e10cSrcweir 653cdf0e10cSrcweir /** testing the method: 654cdf0e10cSrcweir inline oslPipe SAL_CALL getHandle() const; 655cdf0e10cSrcweir */ 656cdf0e10cSrcweir class getHandle : public CppUnit::TestFixture 657cdf0e10cSrcweir { 658cdf0e10cSrcweir public: 659cdf0e10cSrcweir sal_Bool bRes, bRes1; 660cdf0e10cSrcweir 661cdf0e10cSrcweir void getHandle_001( ) 662cdf0e10cSrcweir { 663cdf0e10cSrcweir ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_OPEN ); 664cdf0e10cSrcweir bRes = aPipe == aPipe.getHandle( ); 665cdf0e10cSrcweir aPipe.clear( ); 666cdf0e10cSrcweir 667cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: one pipe should equal to its handle.", 668cdf0e10cSrcweir sal_True == bRes ); 669cdf0e10cSrcweir } 670cdf0e10cSrcweir 671cdf0e10cSrcweir void getHandle_002( ) 672cdf0e10cSrcweir { 673cdf0e10cSrcweir ::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 674cdf0e10cSrcweir ::osl::Pipe aPipe1( aPipe.getHandle( ) ); 675cdf0e10cSrcweir bRes = aPipe == aPipe1; 676cdf0e10cSrcweir aPipe.clear( ); 677cdf0e10cSrcweir aPipe1.clear( ); 678cdf0e10cSrcweir 679cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: one pipe derived from another pipe's handle.", 680cdf0e10cSrcweir sal_True == bRes ); 681cdf0e10cSrcweir } 682cdf0e10cSrcweir 683cdf0e10cSrcweir CPPUNIT_TEST_SUITE( getHandle ); 684cdf0e10cSrcweir CPPUNIT_TEST( getHandle_001 ); 685cdf0e10cSrcweir CPPUNIT_TEST( getHandle_002 ); 686cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END( ); 687cdf0e10cSrcweir }; // class getHandle 688cdf0e10cSrcweir 689cdf0e10cSrcweir 690cdf0e10cSrcweir // ----------------------------------------------------------------------------- 691cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::ctors); 692cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::is); 693cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::create); 694cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::clear); 695cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::assign); 696cdf0e10cSrcweir //CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::isValid); 697cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::isEqual); 698cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::close); 699cdf0e10cSrcweir //CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::accept); 700cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::getError); 701cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(osl_Pipe::getHandle); 702cdf0e10cSrcweir // ----------------------------------------------------------------------------- 703cdf0e10cSrcweir 704cdf0e10cSrcweir } // namespace osl_Pipe 705cdf0e10cSrcweir 706cdf0e10cSrcweir 707cdf0e10cSrcweir namespace osl_StreamPipe 708cdf0e10cSrcweir { 709cdf0e10cSrcweir 710cdf0e10cSrcweir /** testing the methods: 711cdf0e10cSrcweir inline StreamPipe(); 712cdf0e10cSrcweir inline StreamPipe(oslPipe Pipe);; 713cdf0e10cSrcweir inline StreamPipe(const StreamPipe& Pipe); 714cdf0e10cSrcweir inline StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options = osl_Pipe_OPEN); 715cdf0e10cSrcweir inline StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options, const Security &rSec ); 716cdf0e10cSrcweir inline StreamPipe( oslPipe pipe, __sal_NoAcquire noacquire ); 717cdf0e10cSrcweir */ 718cdf0e10cSrcweir class ctors : public CppUnit::TestFixture 719cdf0e10cSrcweir { 720cdf0e10cSrcweir public: 721cdf0e10cSrcweir sal_Bool bRes, bRes1; 722cdf0e10cSrcweir 723cdf0e10cSrcweir void ctors_none( ) 724cdf0e10cSrcweir { 725cdf0e10cSrcweir // create a pipe. 726cdf0e10cSrcweir ::osl::StreamPipe aStreamPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 727cdf0e10cSrcweir // create an unattached pipe. 728cdf0e10cSrcweir ::osl::StreamPipe aStreamPipe1; 729cdf0e10cSrcweir bRes = aStreamPipe1.is( ); 730cdf0e10cSrcweir 731cdf0e10cSrcweir // assign it and check. 732cdf0e10cSrcweir aStreamPipe1 = aStreamPipe; 733cdf0e10cSrcweir bRes1 = aStreamPipe1.is( ); 734cdf0e10cSrcweir aStreamPipe.clear( ); 735cdf0e10cSrcweir aStreamPipe1.clear( ); 736cdf0e10cSrcweir 737cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, before and after assign.", 738cdf0e10cSrcweir sal_False == bRes && sal_True == bRes1 ); 739cdf0e10cSrcweir } 740cdf0e10cSrcweir 741cdf0e10cSrcweir void ctors_handle( ) 742cdf0e10cSrcweir { 743cdf0e10cSrcweir // create a pipe. 744cdf0e10cSrcweir ::osl::StreamPipe aStreamPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 745cdf0e10cSrcweir // create a pipe with last handle. 746cdf0e10cSrcweir ::osl::StreamPipe aStreamPipe1( aStreamPipe.getHandle( ) ); 747cdf0e10cSrcweir bRes = aStreamPipe1.is( ) && aStreamPipe == aStreamPipe1; 748cdf0e10cSrcweir aStreamPipe.clear( ); 749cdf0e10cSrcweir aStreamPipe1.clear( ); 750cdf0e10cSrcweir 751cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with other's handle.", 752cdf0e10cSrcweir sal_True == bRes ); 753cdf0e10cSrcweir } 754cdf0e10cSrcweir 755cdf0e10cSrcweir void ctors_copy( ) 756cdf0e10cSrcweir { 757cdf0e10cSrcweir // create a pipe. 758cdf0e10cSrcweir ::osl::StreamPipe aStreamPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 759cdf0e10cSrcweir // create an unattached pipe. 760cdf0e10cSrcweir ::osl::StreamPipe aStreamPipe1( aStreamPipe ); 761cdf0e10cSrcweir bRes = aStreamPipe1.is( ) && aStreamPipe == aStreamPipe1; 762cdf0e10cSrcweir aStreamPipe.clear( ); 763cdf0e10cSrcweir aStreamPipe1.clear( ); 764cdf0e10cSrcweir 765cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test copy constructor.", 766cdf0e10cSrcweir sal_True == bRes ); 767cdf0e10cSrcweir } 768cdf0e10cSrcweir 769cdf0e10cSrcweir void ctors_name_option( ) 770cdf0e10cSrcweir { 771cdf0e10cSrcweir // create a pipe. 772cdf0e10cSrcweir ::osl::StreamPipe aStreamPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 773cdf0e10cSrcweir // create an unattached pipe. 774cdf0e10cSrcweir ::osl::StreamPipe aStreamPipe1( test::uniquePipeName(aTestPipeName), osl_Pipe_OPEN ); 775cdf0e10cSrcweir bRes = aStreamPipe1.is( ) && aStreamPipe.is( ); 776cdf0e10cSrcweir aStreamPipe.clear( ); 777cdf0e10cSrcweir aStreamPipe1.clear( ); 778cdf0e10cSrcweir 779cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name and option.", 780cdf0e10cSrcweir sal_True == bRes ); 781cdf0e10cSrcweir } 782cdf0e10cSrcweir 783cdf0e10cSrcweir void ctors_name_option_security( ) 784cdf0e10cSrcweir { 785cdf0e10cSrcweir /// create a security pipe. 786cdf0e10cSrcweir const ::osl::Security rSecurity; 787cdf0e10cSrcweir ::osl::StreamPipe aSecurityPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE, rSecurity ); 788cdf0e10cSrcweir 789cdf0e10cSrcweir bRes = aSecurityPipe.is( ); 790cdf0e10cSrcweir aSecurityPipe.clear( ); 791cdf0e10cSrcweir 792cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name, option and security, the test of security is not implemented yet.", 793cdf0e10cSrcweir sal_True == bRes ); 794cdf0e10cSrcweir } 795cdf0e10cSrcweir 796cdf0e10cSrcweir /** tester comment: 797cdf0e10cSrcweir 798cdf0e10cSrcweir When test the following constructor, don't know how to test the 799cdf0e10cSrcweir acquire and no acquire action. possible plans: 800cdf0e10cSrcweir 1.release one handle and check the other( did not success since the 801cdf0e10cSrcweir other still exist and valid. ) 802cdf0e10cSrcweir 2. release one handle twice to see getLastError( )(the getLastError 803cdf0e10cSrcweir always returns invalidError(LINUX)). 804cdf0e10cSrcweir */ 805cdf0e10cSrcweir 806cdf0e10cSrcweir void ctors_no_acquire( ) 807cdf0e10cSrcweir { 808cdf0e10cSrcweir // create a pipe. 809cdf0e10cSrcweir ::osl::StreamPipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 810cdf0e10cSrcweir // constructs a pipe reference without acquiring the handle. 811cdf0e10cSrcweir ::osl::StreamPipe aNoAcquirePipe( aPipe.getHandle( ), SAL_NO_ACQUIRE ); 812cdf0e10cSrcweir 813cdf0e10cSrcweir bRes = aNoAcquirePipe.is( ); 814cdf0e10cSrcweir aPipe.clear( ); 815cdf0e10cSrcweir // bRes1 = aNoAcquirePipe.is( ); 816cdf0e10cSrcweir 817cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no aquire of handle, only validation test, do not know how to test no acquire.", 818cdf0e10cSrcweir sal_True == bRes ); 819cdf0e10cSrcweir } 820cdf0e10cSrcweir 821cdf0e10cSrcweir CPPUNIT_TEST_SUITE( ctors ); 822cdf0e10cSrcweir CPPUNIT_TEST( ctors_none ); 823cdf0e10cSrcweir CPPUNIT_TEST( ctors_handle ); 824cdf0e10cSrcweir CPPUNIT_TEST( ctors_copy ); 825cdf0e10cSrcweir CPPUNIT_TEST( ctors_name_option ); 826cdf0e10cSrcweir CPPUNIT_TEST( ctors_name_option_security ); 827cdf0e10cSrcweir CPPUNIT_TEST( ctors_no_acquire ); 828cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END( ); 829cdf0e10cSrcweir }; // class ctors 830cdf0e10cSrcweir 831cdf0e10cSrcweir 832cdf0e10cSrcweir /** testing the methods: 833cdf0e10cSrcweir inline StreamPipe & SAL_CALL operator=(oslPipe Pipe); 834cdf0e10cSrcweir inline StreamPipe& SAL_CALL operator=(const Pipe& pipe); 835cdf0e10cSrcweir mindy: not implementated in osl/pipe.hxx, so remove the cases 836cdf0e10cSrcweir */ 837cdf0e10cSrcweir /* 838cdf0e10cSrcweir class assign : public CppUnit::TestFixture 839cdf0e10cSrcweir { 840cdf0e10cSrcweir public: 841cdf0e10cSrcweir sal_Bool bRes, bRes1; 842cdf0e10cSrcweir 843cdf0e10cSrcweir void assign_ref( ) 844cdf0e10cSrcweir { 845cdf0e10cSrcweir ::osl::StreamPipe aPipe, aPipe1; 846cdf0e10cSrcweir aPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 847cdf0e10cSrcweir aPipe1 = aPipe; 848cdf0e10cSrcweir bRes = aPipe1.is( ); 849cdf0e10cSrcweir bRes1 = aPipe == aPipe1; 850cdf0e10cSrcweir aPipe.close( ); 851cdf0e10cSrcweir aPipe1.close( ); 852cdf0e10cSrcweir 853cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with reference.", 854cdf0e10cSrcweir sal_True == bRes && sal_True == bRes1 ); 855cdf0e10cSrcweir } 856cdf0e10cSrcweir 857cdf0e10cSrcweir void assign_handle( ) 858cdf0e10cSrcweir { 859cdf0e10cSrcweir ::osl::StreamPipe * pPipe = new ::osl::StreamPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 860cdf0e10cSrcweir ::osl::StreamPipe * pAssignPipe = new ::osl::StreamPipe; 861cdf0e10cSrcweir *pAssignPipe = pPipe->getHandle( ); 862cdf0e10cSrcweir 863cdf0e10cSrcweir bRes = pAssignPipe->is( ); 864cdf0e10cSrcweir bRes1 = ( *pPipe == *pAssignPipe ); 865cdf0e10cSrcweir pPipe->close( ); 866cdf0e10cSrcweir 867cdf0e10cSrcweir delete pAssignPipe; 868cdf0e10cSrcweir 869cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with handle., seems not implemented under (LINUX)(W32)", 870cdf0e10cSrcweir sal_True == bRes && sal_True == bRes1 ); 871cdf0e10cSrcweir } 872cdf0e10cSrcweir 873cdf0e10cSrcweir CPPUNIT_TEST_SUITE( assign ); 874cdf0e10cSrcweir CPPUNIT_TEST( assign_ref ); 875cdf0e10cSrcweir CPPUNIT_TEST( assign_handle ); 876cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END( ); 877cdf0e10cSrcweir };*/ // class assign 878cdf0e10cSrcweir 879cdf0e10cSrcweir 880cdf0e10cSrcweir /** wait _nSec seconds. 881cdf0e10cSrcweir */ 882cdf0e10cSrcweir void thread_sleep( sal_Int32 _nSec ) 883cdf0e10cSrcweir { 884cdf0e10cSrcweir /// print statement in thread process must use fflush() to force display. 885cdf0e10cSrcweir // printf("wait %d seconds. ", _nSec ); 886cdf0e10cSrcweir fflush(stdout); 887cdf0e10cSrcweir 888cdf0e10cSrcweir #ifdef WNT //Windows 889cdf0e10cSrcweir Sleep( _nSec * 1000 ); 890cdf0e10cSrcweir #endif 891cdf0e10cSrcweir #if ( defined UNX ) || ( defined OS2 ) //Unix 892cdf0e10cSrcweir sleep( _nSec ); 893cdf0e10cSrcweir #endif 894cdf0e10cSrcweir // printf("done\n" ); 895cdf0e10cSrcweir } 896cdf0e10cSrcweir // test read/write & send/recv data to pipe 897cdf0e10cSrcweir // ----------------------------------------------------------------------------- 898cdf0e10cSrcweir 899cdf0e10cSrcweir class Pipe_DataSink_Thread : public Thread 900cdf0e10cSrcweir { 901cdf0e10cSrcweir public: 902cdf0e10cSrcweir sal_Char buf[256]; 903cdf0e10cSrcweir Pipe_DataSink_Thread( ) { } 904cdf0e10cSrcweir 905cdf0e10cSrcweir ~Pipe_DataSink_Thread( ) 906cdf0e10cSrcweir { 907cdf0e10cSrcweir } 908cdf0e10cSrcweir protected: 909cdf0e10cSrcweir void SAL_CALL run( ) 910cdf0e10cSrcweir { 911cdf0e10cSrcweir sal_Int32 nChars = 0; 912cdf0e10cSrcweir 913cdf0e10cSrcweir printf("open pipe\n"); 914cdf0e10cSrcweir ::osl::StreamPipe aSenderPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_OPEN ); // test::uniquePipeName(aTestPipeName) is a string = "TestPipe" 915cdf0e10cSrcweir if ( aSenderPipe.is() == sal_False ) 916cdf0e10cSrcweir { 917cdf0e10cSrcweir printf("pipe open failed! \n"); 918cdf0e10cSrcweir } 919cdf0e10cSrcweir else 920cdf0e10cSrcweir { 921cdf0e10cSrcweir printf("read\n"); 922cdf0e10cSrcweir nChars = aSenderPipe.read( buf, m_pTestString1.getLength() + 1 ); 923cdf0e10cSrcweir if ( nChars < 0 ) 924cdf0e10cSrcweir { 925cdf0e10cSrcweir printf("read failed! \n"); 926cdf0e10cSrcweir return; 927cdf0e10cSrcweir } 928cdf0e10cSrcweir printf("buffer is %s \n", buf); 929cdf0e10cSrcweir printf("send\n"); 930cdf0e10cSrcweir nChars = aSenderPipe.send( m_pTestString2.getStr(), m_pTestString2.getLength() + 1 ); 931cdf0e10cSrcweir if ( nChars < 0 ) 932cdf0e10cSrcweir { 933cdf0e10cSrcweir printf("client send failed! \n"); 934cdf0e10cSrcweir return; 935cdf0e10cSrcweir } 936cdf0e10cSrcweir } 937cdf0e10cSrcweir } 938cdf0e10cSrcweir 939cdf0e10cSrcweir }; 940cdf0e10cSrcweir 941cdf0e10cSrcweir // ----------------------------------------------------------------------------- 942cdf0e10cSrcweir 943cdf0e10cSrcweir class Pipe_DataSource_Thread : public Thread 944cdf0e10cSrcweir { 945cdf0e10cSrcweir public: 946cdf0e10cSrcweir sal_Char buf[256]; 947cdf0e10cSrcweir //::osl::StreamPipe aListenPipe; //( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 948cdf0e10cSrcweir ::osl::Pipe aListenPipe; 949cdf0e10cSrcweir ::osl::StreamPipe aConnectionPipe; 950cdf0e10cSrcweir Pipe_DataSource_Thread( ) 951cdf0e10cSrcweir { 952cdf0e10cSrcweir printf("create pipe\n"); 953cdf0e10cSrcweir aListenPipe.create( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 954cdf0e10cSrcweir } 955cdf0e10cSrcweir ~Pipe_DataSource_Thread( ) 956cdf0e10cSrcweir { 957cdf0e10cSrcweir aListenPipe.close(); 958cdf0e10cSrcweir } 959cdf0e10cSrcweir protected: 960cdf0e10cSrcweir void SAL_CALL run( ) 961cdf0e10cSrcweir { 962cdf0e10cSrcweir //create pipe. 963cdf0e10cSrcweir sal_Int32 nChars; 964cdf0e10cSrcweir //::osl::StreamPipe aListenPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); 965cdf0e10cSrcweir printf("listen\n"); 966cdf0e10cSrcweir if ( aListenPipe.is() == sal_False ) 967cdf0e10cSrcweir { 968cdf0e10cSrcweir printf("pipe create failed! \n"); 969cdf0e10cSrcweir } 970cdf0e10cSrcweir else 971cdf0e10cSrcweir { 972cdf0e10cSrcweir //::osl::StreamPipe aConnectionPipe; 973cdf0e10cSrcweir 974cdf0e10cSrcweir //start server and wait for connection. 975cdf0e10cSrcweir printf("accept\n"); 976cdf0e10cSrcweir if ( osl_Pipe_E_None != aListenPipe.accept( aConnectionPipe ) ) 977cdf0e10cSrcweir { 978cdf0e10cSrcweir printf("pipe accept failed!"); 979cdf0e10cSrcweir return; 980cdf0e10cSrcweir } 981cdf0e10cSrcweir printf("write\n"); 982cdf0e10cSrcweir // write to pipe 983cdf0e10cSrcweir nChars = aConnectionPipe.write( m_pTestString1.getStr(), m_pTestString1.getLength() + 1 ); 984cdf0e10cSrcweir if ( nChars < 0) 985cdf0e10cSrcweir { 986cdf0e10cSrcweir printf("server write failed! \n"); 987cdf0e10cSrcweir return; 988cdf0e10cSrcweir } 989cdf0e10cSrcweir printf("recv\n"); 990cdf0e10cSrcweir nChars = aConnectionPipe.recv( buf, 256 ); 991cdf0e10cSrcweir 992cdf0e10cSrcweir if ( nChars < 0) 993cdf0e10cSrcweir { 994cdf0e10cSrcweir printf("server receive failed! \n"); 995cdf0e10cSrcweir return; 996cdf0e10cSrcweir } 997cdf0e10cSrcweir //thread_sleep( 2 ); 998cdf0e10cSrcweir printf("received message is: %s\n", buf ); 999cdf0e10cSrcweir //aConnectionPipe.close(); 1000cdf0e10cSrcweir } 1001cdf0e10cSrcweir } 1002cdf0e10cSrcweir }; 1003cdf0e10cSrcweir 1004cdf0e10cSrcweir /** testing the method: read/write/send/recv and Pipe::accept 1005cdf0e10cSrcweir */ 1006cdf0e10cSrcweir class recv : public CppUnit::TestFixture 1007cdf0e10cSrcweir { 1008cdf0e10cSrcweir public: 1009cdf0e10cSrcweir sal_Bool bRes, bRes1; 1010cdf0e10cSrcweir 1011cdf0e10cSrcweir void recv_001( ) 1012cdf0e10cSrcweir { 1013cdf0e10cSrcweir //launch threads. 1014cdf0e10cSrcweir Pipe_DataSource_Thread myDataSourceThread; 1015cdf0e10cSrcweir Pipe_DataSink_Thread myDataSinkThread; 1016cdf0e10cSrcweir myDataSourceThread.create( ); 1017cdf0e10cSrcweir thread_sleep( 1 ); 1018cdf0e10cSrcweir myDataSinkThread.create( ); 1019cdf0e10cSrcweir 1020cdf0e10cSrcweir //wait until the thread terminate 1021cdf0e10cSrcweir myDataSinkThread.join( ); 1022cdf0e10cSrcweir myDataSourceThread.join( ); 1023cdf0e10cSrcweir 1024cdf0e10cSrcweir int nCompare1 = strcmp( myDataSinkThread.buf, m_pTestString1.getStr() ); 1025cdf0e10cSrcweir int nCompare2 = strcmp( myDataSourceThread.buf, m_pTestString2.getStr() ); 1026cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "test send/recv/write/read.", nCompare1 == 0 && nCompare2 == 0 ); 1027cdf0e10cSrcweir } 1028cdf0e10cSrcweir //close pipe when accept 1029cdf0e10cSrcweir void recv_002() 1030cdf0e10cSrcweir { 1031cdf0e10cSrcweir thread_sleep( 1 ); 1032cdf0e10cSrcweir 1033cdf0e10cSrcweir Pipe_DataSource_Thread myDataSourceThread; 1034cdf0e10cSrcweir Pipe_DataSink_Thread myDataSinkThread; 1035cdf0e10cSrcweir myDataSourceThread.create( ); 1036cdf0e10cSrcweir thread_sleep( 1 ); 1037cdf0e10cSrcweir myDataSourceThread.aListenPipe.close(); 1038cdf0e10cSrcweir myDataSourceThread.join( ); 1039cdf0e10cSrcweir //no condition judgement here, if the case could finish excuting within 1 or 2 seconds, it passes. 1040cdf0e10cSrcweir } 1041cdf0e10cSrcweir 1042cdf0e10cSrcweir CPPUNIT_TEST_SUITE( recv ); 1043cdf0e10cSrcweir CPPUNIT_TEST( recv_001 ); 1044cdf0e10cSrcweir CPPUNIT_TEST( recv_002 ); 1045cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END( ); 1046cdf0e10cSrcweir }; // class recv 1047cdf0e10cSrcweir 1048cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1049cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(osl_StreamPipe::ctors); 1050cdf0e10cSrcweir //CPPUNIT_TEST_SUITE_REGISTRATION(osl_StreamPipe::assign); 1051cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(osl_StreamPipe::recv); 1052cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1053cdf0e10cSrcweir 1054cdf0e10cSrcweir } // namespace osl_StreamPipe 1055cdf0e10cSrcweir 1056cdf0e10cSrcweir CPPUNIT_PLUGIN_IMPLEMENT(); 1057