Kaydet (Commit) 88b9ee66 authored tarafından Daniel Boelzle's avatar Daniel Boelzle

better test

üst e4814d8c
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: test_di.cxx,v $ * $RCSfile: test_di.cxx,v $
* *
* $Revision: 1.3 $ * $Revision: 1.4 $
* *
* last change: $Author: jl $ $Date: 2001-03-12 13:28:13 $ * last change: $Author: dbo $ $Date: 2001-03-13 10:05:20 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -189,12 +189,25 @@ void assign( test::TestData & rData, ...@@ -189,12 +189,25 @@ void assign( test::TestData & rData,
rData.Sequence = rSequence; rData.Sequence = rSequence;
} }
//==================================================================================================
class TestDummy : public OWeakObject
{
public:
sal_Int32 getRefCount() const
{ return m_refCount; }
virtual ~TestDummy()
{ OSL_TRACE( "> scalar TestDummy dtor <\n" ); }
};
//================================================================================================== //==================================================================================================
class Test_Impl : public cppu::WeakImplHelper1< XLanguageBindingTest > class Test_Impl : public cppu::WeakImplHelper1< XLanguageBindingTest >
{ {
test::TestData _aData, _aStructData; test::TestData _aData, _aStructData;
public: public:
sal_Int32 getRefCount() const
{ return m_refCount; }
virtual ~Test_Impl() virtual ~Test_Impl()
{ OSL_TRACE( "> scalar Test_Impl dtor <\n" ); } { OSL_TRACE( "> scalar Test_Impl dtor <\n" ); }
...@@ -383,39 +396,41 @@ test::TestData Test_Impl::getValues( sal_Bool& bBool, sal_Unicode& cChar, sal_In ...@@ -383,39 +396,41 @@ test::TestData Test_Impl::getValues( sal_Bool& bBool, sal_Unicode& cChar, sal_In
} }
//================================================================================================== //==================================================================================================
sal_Bool performTest( const Reference<XLanguageBindingTest > & xLBT ) static sal_Bool performTest(
const Reference< XLanguageBindingTest > & xLBT,
const Reference< XInterface > & xDummyInterface )
{ {
OSL_ENSURE( xLBT.is(), "### no test interface!" ); OSL_ENSURE( xLBT.is() && xDummyInterface.is(), "### no test interfaces!" );
if (xLBT.is()) if (xLBT.is() && xDummyInterface.is())
{ {
// this data is never ever granted access to by calls other than equals(), assign()! // this data is never ever granted access to by calls other than equals(), assign()!
test::TestData aData; // test against this data test::TestData aData; // test against this data
Reference<XInterface > xI( *new OWeakObject() );
assign( (test::TestElement &)aData, assign( (test::TestElement &)aData,
sal_True, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, sal_True, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
0x123456789abcdef0, 0xfedcba9876543210, 0x123456789abcdef0, 0xfedcba9876543210,
(float)17.0815, 3.1415926359, TestEnum_LOLA, (float)17.0815, 3.1415926359, TestEnum_LOLA,
OUString::createFromAscii("dumdidum"), xI, OUString::createFromAscii("dumdidum"), xDummyInterface,
Any( &xI, ::getCppuType( (const Reference<XInterface > *)0 ) ) ); makeAny( xDummyInterface ) );
OSL_ENSURE( aData.Any == xI, "### unexpected any!" );
OSL_ENSURE( !(aData.Any != xI), "### unexpected any!" );
aData.Sequence = Sequence<test::TestElement >( (const test::TestElement *)&aData, 1 ); aData.Sequence = Sequence<test::TestElement >( (const test::TestElement *)&aData, 1 );
// aData complete OSL_ENSURE( aData.Any == xDummyInterface, "### unexpected any!" );
OSL_ENSURE( !(aData.Any != xDummyInterface), "### unexpected any!" );
// aData complete ==> never touched again
//================================================================================ //================================================================================
// this is a manually copy of aData for first setting... // this is a manually copy of aData for first setting...
test::TestData aSetData; test::TestData aSetData0( aData ); // copy ctor
// assignment
test::TestData aSetData1 = aSetData0;
test::TestData aSetData;
assign( (test::TestElement &)aSetData, assign( (test::TestElement &)aSetData,
aData.Bool, aData.Char, aData.Byte, aData.Short, aData.UShort, aSetData1.Bool, aSetData1.Char, aSetData1.Byte, aSetData1.Short, aSetData1.UShort,
aData.Long, aData.ULong, aData.Hyper, aData.UHyper, aData.Float, aData.Double, aSetData1.Long, aSetData1.ULong, aSetData1.Hyper, aSetData1.UHyper,
aData.Enum, aData.String, xI, aSetData1.Float, aSetData1.Double,
Any( &xI, ::getCppuType( (const Reference<XInterface > *)0 ) ) ); aSetData1.Enum, aSetData1.String, aSetData1.Interface, aSetData1.Any );
// switch over to new sequence allocation
aSetData.Sequence = Sequence<test::TestElement >( (const test::TestElement *)&aSetData, 1 ); aSetData.Sequence = Sequence<test::TestElement >( (const test::TestElement *)&aSetData, 1 );
xLBT->setValues( xLBT->setValues(
...@@ -577,42 +592,48 @@ sal_Bool raiseException( const Reference< XLanguageBindingTest > & xLBT ) ...@@ -577,42 +592,48 @@ sal_Bool raiseException( const Reference< XLanguageBindingTest > & xLBT )
//================================================================================================== //==================================================================================================
void test_di(void) void test_di(void)
{ {
Test_Impl * p = new Test_Impl(); TestDummy * p = new TestDummy();
Reference< XInterface > x( *p ); Reference< XInterface > xDummy( *p );
{ {
Reference<XLanguageBindingTest > xOriginal( x, UNO_QUERY ); Test_Impl * p = new Test_Impl();
Reference<XLanguageBindingTest > xLBT; Reference< XInterface > x( *p );
{
Reference<XLanguageBindingTest > xOriginal( x, UNO_QUERY );
Reference<XLanguageBindingTest > xLBT;
uno_Environment * pCppEnv1 = 0; uno_Environment * pCppEnv1 = 0;
uno_Environment * pCppEnv2 = 0; uno_Environment * pCppEnv2 = 0;
OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
uno_getEnvironment( &pCppEnv1, aCppEnvTypeName.pData, 0 ); uno_getEnvironment( &pCppEnv1, aCppEnvTypeName.pData, 0 );
uno_createEnvironment( &pCppEnv2, aCppEnvTypeName.pData, 0 ); // anonymous uno_createEnvironment( &pCppEnv2, aCppEnvTypeName.pData, 0 ); // anonymous
Mapping aMapping( pCppEnv1, pCppEnv2, OUString::createFromAscii("prot") ); Mapping aMapping( pCppEnv1, pCppEnv2, OUString( RTL_CONSTASCII_USTRINGPARAM("prot") ) );
aMapping.mapInterface( (void **)&xLBT, xOriginal.get(), ::getCppuType( &xOriginal ) ); aMapping.mapInterface( (void **)&xLBT, xOriginal.get(), ::getCppuType( &xOriginal ) );
OSL_ENSURE( aMapping.is(), "### cannot get mapping!" ); OSL_ENSHURE( aMapping.is(), "### cannot get mapping!" );
(*pCppEnv2->release)( pCppEnv2 ); (*pCppEnv2->release)( pCppEnv2 );
(*pCppEnv1->release)( pCppEnv1 ); (*pCppEnv1->release)( pCppEnv1 );
OSL_ASSERT( xLBT.is() ); OSL_ASSERT( xLBT.is() );
if (xLBT.is() && performTest( xLBT )) if (xLBT.is() && performTest( xLBT, xDummy ))
{ {
if (raiseException( xLBT )) if (raiseException( xLBT ))
{ {
printf( "> dynamic invocation test succeeded!\n" ); printf( "> dynamic invocation test succeeded!\n" );
} }
else else
{ {
printf( "> exception test failed!\n" ); printf( "> exception test failed!\n" );
}
}
else
{
printf( "> dynamic invocation test failed!\n" );
}
} }
OSL_ENSURE( p->getRefCount() == 1, "### test object ref count > 1 !" );
} }
else OSL_ENSURE( p->getRefCount() == 1, "### dummy object ref count > 1 !" );
{
printf( "> dynamic invocation test failed!\n" );
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment