Kaydet (Commit) 11cbce37 authored tarafından Noel Grandin's avatar Noel Grandin

cleanup OInterfaceContainer2 unit tests

remove unused code and actually hook up the tests
in testifcontainer.cxx

Change-Id: I9694ebe44f1e8eed3d72373d62424345f899c8e6
üst 3dc37e97
...@@ -34,8 +34,6 @@ using namespace com::sun::star; ...@@ -34,8 +34,6 @@ using namespace com::sun::star;
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
using namespace com::sun::star::lang; using namespace com::sun::star::lang;
class ContainerListener;
struct ContainerStats { struct ContainerStats {
int m_nAlive; int m_nAlive;
int m_nDisposed; int m_nDisposed;
...@@ -131,72 +129,6 @@ namespace comphelper_ifcontainer ...@@ -131,72 +129,6 @@ namespace comphelper_ifcontainer
delete pContainer; delete pContainer;
} }
template < typename ContainerType, typename ContainedType >
void doContainerTest(const ContainedType *pTypes)
{
ContainerStats aStats;
ContainerType *pContainer;
pContainer = new ContainerType(m_aGuard);
int i;
Reference<XEventListener> xRefs[nTests * 2];
// add these interfaces
for (i = 0; i < nTests * 2; i++)
{
xRefs[i] = new ContainerListener(&aStats);
pContainer->addInterface(pTypes[i / 2], xRefs[i]);
}
// check it is all there
for (i = 0; i < nTests; i++)
{
cppu::OInterfaceContainerHelper *pHelper;
pHelper = pContainer->getContainer(pTypes[i]);
CPPUNIT_ASSERT_MESSAGE("no helper", pHelper != nullptr);
Sequence<Reference< XInterface > > aSeq = pHelper->getElements();
CPPUNIT_ASSERT_MESSAGE("wrong num elements", aSeq.getLength() == 2);
CPPUNIT_ASSERT_MESSAGE("match", aSeq[0] == xRefs[i*2]);
CPPUNIT_ASSERT_MESSAGE("match", aSeq[1] == xRefs[i*2+1]);
}
// remove every other interface
for (i = 0; i < nTests; i++)
pContainer->removeInterface(pTypes[i], xRefs[i*2+1]);
// check it is half there
for (i = 0; i < nTests; i++)
{
cppu::OInterfaceContainerHelper *pHelper;
pHelper = pContainer->getContainer(pTypes[i]);
CPPUNIT_ASSERT_MESSAGE("no helper", pHelper != nullptr);
Sequence<Reference< XInterface > > aSeq = pHelper->getElements();
CPPUNIT_ASSERT_MESSAGE("wrong num elements", aSeq.getLength() == 1);
CPPUNIT_ASSERT_MESSAGE("match", aSeq[0] == xRefs[i*2]);
}
// remove the 1st half of the rest
for (i = 0; i < nTests / 2; i++)
pContainer->removeInterface(pTypes[i], xRefs[i*2]);
// check it is half there
for (i = 0; i < nTests / 2; i++)
{
cppu::OInterfaceContainerHelper *pHelper;
pHelper = pContainer->getContainer(pTypes[i]);
CPPUNIT_ASSERT_MESSAGE("no helper", pHelper != nullptr);
Sequence<Reference< XInterface > > aSeq = pHelper->getElements();
CPPUNIT_ASSERT_MESSAGE("wrong num elements", aSeq.getLength() == 0);
}
delete pContainer;
}
// Automatic registration code // Automatic registration code
CPPUNIT_TEST_SUITE(IfTest); CPPUNIT_TEST_SUITE(IfTest);
CPPUNIT_TEST(testCreateDispose); CPPUNIT_TEST(testCreateDispose);
......
...@@ -17,21 +17,34 @@ ...@@ -17,21 +17,34 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include "cppunit/TestAssert.h"
#include "cppunit/TestFixture.h"
#include "cppunit/extensions/HelperMacros.h"
#include "cppunit/plugin/TestPlugIn.h"
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <cppuhelper/implbase1.hxx> #include <cppuhelper/implbase1.hxx>
#include <com/sun/star/beans/XVetoableChangeListener.hpp> #include <com/sun/star/beans/XVetoableChangeListener.hpp>
using namespace ::cppu;
using namespace ::osl; using namespace ::osl;
using namespace ::com::sun::star::lang; using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::beans; using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
namespace
{
class TestListener : public WeakImplHelper1< XVetoableChangeListener > class TestInterfaceContainer2: public CppUnit::TestFixture
{
public:
void test1();
CPPUNIT_TEST_SUITE(TestInterfaceContainer2);
CPPUNIT_TEST(test1);
CPPUNIT_TEST_SUITE_END();
};
class TestListener : public cppu::WeakImplHelper1< XVetoableChangeListener >
{ {
public: public:
// Methods // Methods
...@@ -47,12 +60,12 @@ public: ...@@ -47,12 +60,12 @@ public:
} }
}; };
void test_interfacecontainer() void TestInterfaceContainer2::test1()
{ {
Mutex mutex; Mutex mutex;
{ {
OInterfaceContainerHelper helper( mutex ); comphelper::OInterfaceContainerHelper2 helper( mutex );
Reference< XVetoableChangeListener > r1 = new TestListener(); Reference< XVetoableChangeListener > r1 = new TestListener();
Reference< XVetoableChangeListener > r2 = new TestListener(); Reference< XVetoableChangeListener > r2 = new TestListener();
...@@ -66,7 +79,7 @@ void test_interfacecontainer() ...@@ -66,7 +79,7 @@ void test_interfacecontainer()
} }
{ {
OInterfaceContainerHelper helper( mutex ); comphelper::OInterfaceContainerHelper2 helper( mutex );
Reference< XVetoableChangeListener > r1 = new TestListener(); Reference< XVetoableChangeListener > r1 = new TestListener();
Reference< XVetoableChangeListener > r2 = new TestListener(); Reference< XVetoableChangeListener > r2 = new TestListener();
...@@ -76,7 +89,7 @@ void test_interfacecontainer() ...@@ -76,7 +89,7 @@ void test_interfacecontainer()
helper.addInterface( r2 ); helper.addInterface( r2 );
helper.addInterface( r3 ); helper.addInterface( r3 );
OInterfaceIteratorHelper iterator( helper ); comphelper::OInterfaceIteratorHelper2 iterator( helper );
while( iterator.hasMoreElements() ) while( iterator.hasMoreElements() )
static_cast<XVetoableChangeListener*>(iterator.next())->vetoableChange( PropertyChangeEvent() ); static_cast<XVetoableChangeListener*>(iterator.next())->vetoableChange( PropertyChangeEvent() );
...@@ -85,7 +98,7 @@ void test_interfacecontainer() ...@@ -85,7 +98,7 @@ void test_interfacecontainer()
} }
{ {
OInterfaceContainerHelper helper( mutex ); comphelper::OInterfaceContainerHelper2 helper( mutex );
Reference< XVetoableChangeListener > r1 = new TestListener(); Reference< XVetoableChangeListener > r1 = new TestListener();
Reference< XVetoableChangeListener > r2 = new TestListener(); Reference< XVetoableChangeListener > r2 = new TestListener();
...@@ -95,7 +108,7 @@ void test_interfacecontainer() ...@@ -95,7 +108,7 @@ void test_interfacecontainer()
helper.addInterface( r2 ); helper.addInterface( r2 );
helper.addInterface( r3 ); helper.addInterface( r3 );
OInterfaceIteratorHelper iterator( helper ); comphelper::OInterfaceIteratorHelper2 iterator( helper );
static_cast<XVetoableChangeListener*>(iterator.next())->vetoableChange( PropertyChangeEvent() ); static_cast<XVetoableChangeListener*>(iterator.next())->vetoableChange( PropertyChangeEvent() );
iterator.remove(); iterator.remove();
...@@ -104,12 +117,12 @@ void test_interfacecontainer() ...@@ -104,12 +117,12 @@ void test_interfacecontainer()
static_cast<XVetoableChangeListener*>(iterator.next())->vetoableChange( PropertyChangeEvent() ); static_cast<XVetoableChangeListener*>(iterator.next())->vetoableChange( PropertyChangeEvent() );
iterator.remove(); iterator.remove();
OSL_ASSERT( helper.getLength() == 0 ); CPPUNIT_ASSERT( helper.getLength() == 0 );
helper.disposeAndClear( EventObject() ); helper.disposeAndClear( EventObject() );
} }
{ {
OInterfaceContainerHelper helper( mutex ); comphelper::OInterfaceContainerHelper2 helper( mutex );
Reference< XVetoableChangeListener > r1 = new TestListener(); Reference< XVetoableChangeListener > r1 = new TestListener();
Reference< XVetoableChangeListener > r2 = new TestListener(); Reference< XVetoableChangeListener > r2 = new TestListener();
...@@ -120,7 +133,7 @@ void test_interfacecontainer() ...@@ -120,7 +133,7 @@ void test_interfacecontainer()
helper.addInterface( r3 ); helper.addInterface( r3 );
{ {
OInterfaceIteratorHelper iterator( helper ); comphelper::OInterfaceIteratorHelper2 iterator( helper );
while( iterator.hasMoreElements() ) while( iterator.hasMoreElements() )
{ {
Reference< XVetoableChangeListener > r = static_cast<XVetoableChangeListener*>(iterator.next()); Reference< XVetoableChangeListener > r = static_cast<XVetoableChangeListener*>(iterator.next());
...@@ -128,13 +141,13 @@ void test_interfacecontainer() ...@@ -128,13 +141,13 @@ void test_interfacecontainer()
iterator.remove(); iterator.remove();
} }
} }
OSL_ASSERT( helper.getLength() == 2 ); CPPUNIT_ASSERT( helper.getLength() == 2 );
{ {
OInterfaceIteratorHelper iterator( helper ); comphelper::OInterfaceIteratorHelper2 iterator( helper );
while( iterator.hasMoreElements() ) while( iterator.hasMoreElements() )
{ {
Reference< XVetoableChangeListener > r = static_cast<XVetoableChangeListener*>(iterator.next()); Reference< XVetoableChangeListener > r = static_cast<XVetoableChangeListener*>(iterator.next());
OSL_ASSERT( r != r1 && ( r == r2 || r == r3 ) ); CPPUNIT_ASSERT( r != r1 && ( r == r2 || r == r3 ) );
} }
} }
...@@ -142,4 +155,8 @@ void test_interfacecontainer() ...@@ -142,4 +155,8 @@ void test_interfacecontainer()
} }
} }
CPPUNIT_TEST_SUITE_REGISTRATION(TestInterfaceContainer2);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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