123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- /*=========================================================================
- Library: CTK
- Copyright (c) Kitware Inc.
- Licensed 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.txt
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =========================================================================*/
- // Qt includes
- #include <QDebug>
- #include <QApplication>
- // CTKVTK includes
- #include "ctkVTKObjectTestHelper.h"
- // VTK includes
- #include <vtkObject.h>
- //------------------------------------------------------------------------------
- class ctkVTKObjectTestPrivate
- {
- public:
- ctkVTKObjectTestPrivate();
- int PublicSlotCalled ;
- int ProtectedSlotCalled;
- int PrivateSlotCalled;
- };
- //------------------------------------------------------------------------------
- ctkVTKObjectTestPrivate::ctkVTKObjectTestPrivate()
- {
- this->PublicSlotCalled = 0;
- this->ProtectedSlotCalled = 0;
- this->PrivateSlotCalled = 0;
- }
- //------------------------------------------------------------------------------
- ctkVTKObjectTest::ctkVTKObjectTest(QObject* parentObject)
- : QObject(parentObject)
- , d_ptr(new ctkVTKObjectTestPrivate)
- {
- }
- //------------------------------------------------------------------------------
- ctkVTKObjectTest::~ctkVTKObjectTest()
- {
- }
- //------------------------------------------------------------------------------
- bool ctkVTKObjectTest::test()
- {
- Q_D(ctkVTKObjectTest);
- // should do nothing but shouldn't fail neither
- qDebug() << "The following can generate error message.";
- qDebug() << "Disconnect:";
- this->qvtkDisconnect(0, static_cast<unsigned long>(-1), this, SLOT(onVTKObjectModifiedPublic()));
- qDebug() << "Connect:";
- QString connection = this->qvtkConnect(0, static_cast<unsigned long>(-1), this, SLOT(onVTKObjectModifiedPublic()));
- if (!connection.isEmpty())
- {
- qDebug() << "ctkVTKObject::qvtkConnect() failed: "<< connection;
- return false;
- }
- qDebug() << "Reconnect:";
- connection = this->qvtkReconnect(0, 0, static_cast<unsigned long>(-1), this, SLOT(onVTKObjectModifiedPublic()));
- if (!connection.isEmpty())
- {
- qDebug() << "ctkVTKObject::qvtkReconnect() failed: "<< connection;
- return false;
- }
- qDebug() << "End of possible error messages.";
-
- vtkObject* object = vtkObject::New();
- connection = this->qvtkConnect(object, vtkCommand::ModifiedEvent,
- this, SLOT(onVTKObjectModifiedPublic()));
- if (connection.isEmpty() || object->GetReferenceCount() != 1)
- {
- qDebug() << "ctkVTKObject::qvtkConnect() failed: "<< connection;
- return false;
- }
- object->Modified();
- if (d->PublicSlotCalled != 1)
- {
- qDebug() << "qvtkConnect failed";
- return false;
- }
-
- this->resetSlotCalls();
- // should do nothing...
- connection = this->qvtkConnect(object, vtkCommand::ModifiedEvent,
- this, SLOT(onVTKObjectModifiedPublic()));
- if (!connection.isEmpty())
- {
- qDebug() << __LINE__ << "ctkVTKObject::qvtkConnect() failed: "<< connection;
- return false;
- }
- object->Modified();
-
- if (d->PublicSlotCalled != 1)
- {
- qDebug() << __LINE__ << "qvtkConnect failed";
- return false;
- }
- this->resetSlotCalls();
- this->qvtkDisconnect(object, vtkCommand::WarningEvent,
- this, SLOT(onVTKObjectModifiedPublic()));
- object->Modified();
- if (d->PublicSlotCalled != 1)
- {
- qDebug() << __LINE__ << "qvtkDisconnect failed" << d->PublicSlotCalled;
- return false;
- }
- this->resetSlotCalls();
- this->qvtkDisconnect(object, vtkCommand::ModifiedEvent,
- this, SLOT(onVTKObjectModifiedPublic()));
- QCoreApplication::instance()->processEvents();
- object->Modified();
- if (d->PublicSlotCalled != 0)
- {
- qDebug() << __LINE__ << "qvtkDisconnect failed" << d->PublicSlotCalled;
- return false;
- }
- this->resetSlotCalls();
-
- // Set a new connection (protected)
- connection = this->qvtkConnect(object, vtkCommand::ModifiedEvent,
- this, SLOT(onVTKObjectModifiedProtected()));
- if (connection.isEmpty())
- {
- qDebug() << __LINE__ << "ctkVTKObject::qvtkConnect() failed: "<< connection;
- return false;
- }
- object->Modified();
-
- if (d->ProtectedSlotCalled != 1)
- {
- qDebug() << __LINE__ << "ctkVTKObject::qvtkConnect failed" << d->ProtectedSlotCalled;
- return false;
- }
- this->resetSlotCalls();
- // remove the connection using flags, 0 means any event, qt object or slot
- this->qvtkDisconnect(object, vtkCommand::NoEvent, 0, 0);
- object->Modified();
- if (d->ProtectedSlotCalled != 0)
- {
- qDebug() << __LINE__ << "qvtkDisconnect failed" << d->ProtectedSlotCalled;
- return false;
- }
- this->resetSlotCalls();
- // Set new connections
- this->qvtkConnect(object, vtkCommand::ModifiedEvent,
- this, SLOT(onVTKObjectModifiedProtected()));
- this->qvtkConnect(object, vtkCommand::ModifiedEvent,
- this, SLOT(onVTKObjectModifiedPrivate()));
- object->Modified();
- if (d->ProtectedSlotCalled != 1 ||
- d->PrivateSlotCalled != 1)
- {
- qDebug() << __LINE__ << "qvtkConnect failed"
- << d->ProtectedSlotCalled
- << d->PrivateSlotCalled;
- return false;
- }
- this->resetSlotCalls();
- // remove the connection using flags, 0 means any event, qt object or slot
- this->qvtkDisconnect(object, vtkCommand::ModifiedEvent, this, 0);
- object->Modified();
- if (d->ProtectedSlotCalled != 0 || d->PrivateSlotCalled != 0)
- {
- qDebug() << __LINE__ << "qvtkDisconnect failed"
- << d->ProtectedSlotCalled
- << d->PrivateSlotCalled;
- return false;
- }
- this->resetSlotCalls();
- // Set new connections
- this->qvtkConnect(object, vtkCommand::ModifiedEvent,
- this, SLOT(onVTKObjectModifiedPublic()));
- this->qvtkConnect(object, vtkCommand::WarningEvent,
- this, SLOT(onVTKObjectModifiedPublic()));
- int disconnected = this->qvtkDisconnect(object, vtkCommand::NoEvent,
- this, SLOT(onVTKObjectModifiedPublic()));
- if (disconnected != 2)
- {
- qDebug() << __LINE__ << "qvtkDisconnect failed" << disconnected;
- return false;
- }
- object->InvokeEvent(vtkCommand::ModifiedEvent, 0);
- object->InvokeEvent(vtkCommand::WarningEvent, 0);
- if (d->PublicSlotCalled != 0)
- {
- qDebug() << __LINE__ << "qvtkConnect failed"
- << d->PublicSlotCalled;
- return false;
- }
- this->resetSlotCalls();
- disconnected = this->qvtkDisconnectAll();
- if (disconnected != 0)
- {
- qDebug() << __LINE__ << "qvtkDisconnectAll failed" << disconnected;
- return false;
- }
- this->qvtkConnect(object, vtkCommand::ModifiedEvent,
- this, SLOT(deleteConnection()));
- object->InvokeEvent(vtkCommand::ModifiedEvent, 0);
- object->Delete();
-
- return true;
- }
- //------------------------------------------------------------------------------
- void ctkVTKObjectTest::resetSlotCalls()
- {
- Q_D(ctkVTKObjectTest);
- d->PublicSlotCalled = 0;
- d->ProtectedSlotCalled = 0;
- d->PrivateSlotCalled = 0;
- }
- //------------------------------------------------------------------------------
- void ctkVTKObjectTest::emitSignalEmitted()
- {
- emit signalEmitted();
- }
- //------------------------------------------------------------------------------
- void ctkVTKObjectTest::onVTKObjectModifiedPublic()
- {
- Q_D(ctkVTKObjectTest);
- //qDebug() << __FUNCTION__;
- d->PublicSlotCalled = true;
- }
- //------------------------------------------------------------------------------
- void ctkVTKObjectTest::deleteConnection()
- {
- //qDebug() << __FUNCTION__;
- this->qvtkDisconnect(0, vtkCommand::NoEvent, 0, 0);
- }
- //------------------------------------------------------------------------------
- void ctkVTKObjectTest::onVTKObjectModifiedProtected()
- {
- Q_D(ctkVTKObjectTest);
- //qDebug() << __FUNCTION__;
- d->ProtectedSlotCalled = true;
- }
- //------------------------------------------------------------------------------
- void ctkVTKObjectTest::onVTKObjectModifiedPrivate()
- {
- Q_D(ctkVTKObjectTest);
- //qDebug() << __FUNCTION__;
- d->PrivateSlotCalled = true;
- }
|