Skip to content

Commit

Permalink
ENH: Add testing for ctkVTKConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
finetjul committed Jun 25, 2010
1 parent 001445a commit c6ba76d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Libs/Visualization/VTK/Core/Testing/Cpp/CMakeLists.txt
Expand Up @@ -39,6 +39,7 @@ CONFIGURE_FILE(

CREATE_TEST_SOURCELIST(Tests ${KIT}CppTests.cpp
ctkVTKCommandOptionsTest1.cpp
ctkVTKConnectionTest1.cpp
ctkVTKObjectTest1.cpp
#EXTRA_INCLUDE TestingMacros.h
)
Expand Down Expand Up @@ -66,6 +67,7 @@ ENDMACRO( SIMPLE_TEST )
#

SIMPLE_TEST( ctkVTKObjectTest1 )
SIMPLE_TEST( ctkVTKConnectionTest1 )

ADD_TEST( ctkVTKCommandOptionsTest1 ${KIT_TESTS}
ctkVTKCommandOptionsTest1 --help )
Expand Down
89 changes: 89 additions & 0 deletions Libs/Visualization/VTK/Core/Testing/Cpp/ctkVTKConnectionTest1.cpp
@@ -0,0 +1,89 @@

// Qt includes
#include <QApplication>
#include <QDebug>
#include <QWidget>

// CTKVTK includes
#include "ctkVTKConnection.h"

// STD includes
#include <cstdlib>
#include <iostream>

// VTK includes
#include <vtkCallbackCommand.h>
#include <vtkCommand.h>
#include <vtkObject.h>
#include <vtkSmartPointer.h>
#include <vtkTimerLog.h>

void doit(vtkObject* obj, unsigned long event, void* client_data, void* param)
{
QWidget* w = reinterpret_cast<QWidget*>(client_data);
w->setFocus();
}

int ctkVTKConnectionTest1( int argc, char * argv [] )
{
QApplication app(argc, argv);
vtkObject* obj = vtkObject::New();
QWidget topLevelWidget;

int objects = 1000;
int events = 100;

for (int i = 0; i < objects; ++i)
{
ctkVTKConnection* objectTest = new ctkVTKConnection(&topLevelWidget);
objectTest->SetParameters(obj, vtkCommand::ModifiedEvent,
&topLevelWidget, SLOT(setFocus()));
objectTest->setEnabled(true);
}
vtkSmartPointer<vtkTimerLog> timerLog =
vtkSmartPointer<vtkTimerLog>::New();

timerLog->StartTimer();
for (int i = 0; i < events; ++i)
{
obj->Modified();
}
timerLog->StopTimer();

double t1 = timerLog->GetElapsedTime();
qDebug() << events << "events listened by" << objects << "objects (ctkVTKConnection): " << t1 << "seconds";

obj->Delete();

vtkObject* obj2 = vtkObject::New();
for (int i = 0; i < objects; ++i)
{
vtkCallbackCommand* callback = vtkCallbackCommand::New();
callback->SetClientData(&topLevelWidget);
callback->SetCallback(doit);

obj2->AddObserver(vtkCommand::ModifiedEvent, callback);
callback->Delete();
}
vtkSmartPointer<vtkTimerLog> timerLog2 =
vtkSmartPointer<vtkTimerLog>::New();
timerLog2->StartTimer();
for (int i = 0; i < events; ++i)
{
obj2->Modified();
}
timerLog2->StopTimer();

double t2 = timerLog2->GetElapsedTime();
qDebug() << events << "events listened by" << objects <<"objects (vtkCallbacks): " << t2 << "seconds";
double ratio = t1 / t2;
qDebug() << "ctkVTKConnection / vtkCallbacks: " << ratio;
// Ideally a ratio of 2 (a callback and a signal/slot connection is used
// is used in ctkVTKConnection
if (ratio > 2.5)
{
return EXIT_FAILURE;
}
obj2->Delete();
return EXIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion Libs/Visualization/VTK/Core/ctkVTKConnection.h
Expand Up @@ -49,7 +49,7 @@ Q_OBJECT

///
void SetParameters(vtkObject* vtk_obj, unsigned long vtk_event,
const QObject* qt_obj, QString qt_slot, float priority);
const QObject* qt_obj, QString qt_slot, float priority = 0.f);

///
/// Check the validity of the parameters. Parameters must be valid to add
Expand Down

0 comments on commit c6ba76d

Please sign in to comment.