/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/** print last error of pipe system.
*/ staticvoid printPipeError( ::osl::Pipe const & aPipe )
{
oslPipeError nError = aPipe.getError( );
printf("#printPipeError# " ); switch ( nError ) { case osl_Pipe_E_None:
printf("Success!\n" ); break; case osl_Pipe_E_NotFound:
printf("The returned error is: Not found!\n" ); break; case osl_Pipe_E_AlreadyExists:
printf("The returned error is: Already exist!\n" ); break; case osl_Pipe_E_NoProtocol:
printf("The returned error is: No protocol!\n" ); break; case osl_Pipe_E_NetworkReset:
printf("The returned error is: Network reset!\n" ); break; case osl_Pipe_E_ConnectionAbort:
printf("The returned error is: Connection aborted!\n" ); break; case osl_Pipe_E_ConnectionReset:
printf("The returned error is: Connection reset!\n" ); break; case osl_Pipe_E_NoBufferSpace:
printf("The returned error is: No buffer space!\n" ); break; case osl_Pipe_E_TimedOut:
printf("The returned error is: Timeout!\n" ); break; case osl_Pipe_E_ConnectionRefused:
printf("The returned error is: Connection refused!\n" ); break; case osl_Pipe_E_invalidError:
printf("The returned error is: Invalid error!\n" ); break; default:
printf("The returned error is: Number %d, Unknown Error\n", nError ); break;
}
}
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name, option and security, the test of security is not implemented yet.",
bRes );
}
void ctors_copy( )
{ /// create a pipe.
::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); /// create a pipe using copy constructor.
::osl::Pipe aCopyPipe( aPipe );
bRes = aCopyPipe.is( ) && aCopyPipe == aPipe;
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test copy constructor.",
bRes );
}
/* Note: DO NOT DO THIS - I have very deliberately caused send to FAIL, *on purpose* as this is the only sane way to test noacquire. This is a terrible misuse of no-acquire, but in this case is needed only so we can test to make sure no-acquire is working!
*/ void ctors_no_acquire( )
{ /// create a pipe.
OUString aPipeName(test::uniquePipeName(aTestPipeName));
oslPipe handle(osl_createPipe(aPipeName.pData, osl_Pipe_CREATE, nullptr)); /// constructs a pipe reference without acquiring the handle.
std::unique_ptr<osl::Pipe> xNoAcquirePipe(new osl::Pipe(handle, SAL_NO_ACQUIRE));
StreamPipe aStreamPipe(handle);
xNoAcquirePipe.reset(); int nRet = aStreamPipe.send("a", 1);
if (nRet >= 0)
bRes = false; else
bRes = true;
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no acquire of handle, deleted nonacquired pipe but could still send on original pipe!.",
bRes );
}
void ctors_acquire( )
{ /// create a base pipe.
::osl::Pipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); /// constructs two pipes, the second acquires the first pipe's handle.
::osl::Pipe aAcquirePipe( aPipe.getHandle( ) );
::osl::Pipe aAcquirePipe1( nullptr );
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with acquire of handle, original pipe does not exist.",
bRes );
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with acquire of handle, copied pipe does not exist",
!bRes1 );
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test pipes should have same handle", bRes2);
}
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with reference.",
bRes );
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with reference.",
bRes1 );
}
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with handle.",
bRes );
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test assign with handle.",
bRes1 );
}
/** testing the method: inline sal_Bool SAL_CALL isValid() const; isValid( ) has not been implemented under the following platforms, please refer to osl/pipe.hxx
*/
/** testing the method: inline sal_Bool SAL_CALL operator==( const Pipe& rPipe ) const;
*/ class isEqual : public CppUnit::TestFixture
{ public: bool bRes, bRes1;
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(),create one copy instance, and compare.",
bRes );
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test isEqual(),create one copy instance, and compare.",
!bRes1 );
}
CPPUNIT_ASSERT_MESSAGE( "#test comment#: difference between close and clear.",
bRes);
CPPUNIT_ASSERT_MESSAGE( "#test comment#: difference between close and clear.",
!bRes1);
}
// assign it and check.
aStreamPipe1 = aStreamPipe;
bRes1 = aStreamPipe1.is( );
aStreamPipe.clear( );
aStreamPipe1.clear( );
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, before and after assign.",
!bRes );
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no parameter, before and after assign.",
bRes1 );
}
void ctors_handle( )
{ // create a pipe.
::osl::StreamPipe aStreamPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE ); // create a pipe with last handle.
::osl::StreamPipe aStreamPipe1( aStreamPipe.getHandle( ) );
bRes = aStreamPipe1.is( ) && aStreamPipe == aStreamPipe1;
aStreamPipe.clear( );
aStreamPipe1.clear( );
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with other's handle.",
bRes );
}
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with name, option and security, the test of security is not implemented yet.",
bRes );
}
/** tester comment:
When test the following constructor, don't know how to test the acquire and no acquire action. possible plans: 1.release one handle and check the other( did not success since the other still exist and valid. ) 2. release one handle twice to see getLastError( )(the getLastError always returns invalidError(LINUX)).
*/
void ctors_no_acquire( )
{ // create a pipe.
::osl::StreamPipe aPipe( test::uniquePipeName(aTestPipeName), osl_Pipe_CREATE );
osl_acquirePipe(aPipe.getHandle()); // constructs a pipe reference without acquiring the handle.
::osl::StreamPipe aNoAcquirePipe( aPipe.getHandle( ), SAL_NO_ACQUIRE );
bRes = aNoAcquirePipe.is( );
aPipe.clear( );
CPPUNIT_ASSERT_MESSAGE( "#test comment#: test constructor with no acquire of handle, only validation test, do not know how to test no acquire.",
bRes );
}
/** testing the methods: inline StreamPipe & SAL_CALL operator=(oslPipe Pipe); inline StreamPipe& SAL_CALL operator=(const Pipe& pipe); mindy: not implemented in osl/pipe.hxx, so remove the cases
*/
/** wait _nSec seconds.
*/ staticvoid thread_sleep( sal_uInt32 _nSec )
{ /// print statement in thread process must use fflush() to force display.
fflush(stdout);
osl::Thread::wait(std::chrono::seconds(_nSec));
} // test read/write & send/recv data to pipe
namespace {
class Pipe_DataSink_Thread : public Thread
{ public: char buf[256];
Pipe_DataSink_Thread( ) { }
Pipe_DataSource_Thread myDataSourceThread;
Pipe_DataSink_Thread myDataSinkThread;
myDataSourceThread.create( );
thread_sleep( 1 );
myDataSourceThread.aListenPipe.close();
myDataSourceThread.join( ); //no condition judgment here, if the case could finish executing within 1 or 2 seconds, it passes.
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.