Skip to content
Snippets Groups Projects
Commit 2465c99f authored by David Gobbi's avatar David Gobbi
Browse files

Fix X BadRequest errors in TestInteractorStyleImageProperty.

This test was crashing once or twice a week on certain Linux machines.
I have rewritten it so that it only creates and maps one window.

Change-Id: Ia5d2f2d4617afd93013440bb13f5a3de9a730d02
parent 9c18166e
No related branches found
No related tags found
No related merge requests found
......@@ -26,7 +26,7 @@
#include "vtkTestUtilities.h"
#include "vtkTextMapper.h"
int TestInteractorStyleImagePropertyInternal(int argc, char *argv[], int sliceOrder)
int TestInteractorStyleImageProperty(int argc, char *argv[])
{
vtkSmartPointer<vtkPNGReader> reader =
vtkSmartPointer<vtkPNGReader>::New();
......@@ -71,29 +71,8 @@ int TestInteractorStyleImagePropertyInternal(int argc, char *argv[], int sliceOr
textActor->SetMapper(text);
textActor->PickableOff();
switch(sliceOrder)
{
case 0:
//Adding the slice to the renderer before the other prop.
renderer->AddViewProp(imageSlice);
renderer->AddViewProp(textActor);
break;
case 1:
//Only add the slice if there should not be a prop.
renderer->AddViewProp(imageSlice);
break;
case 2:
//Adding the slice to the renderer after the other prop.
renderer->AddViewProp(textActor);
renderer->AddViewProp(imageSlice);
break;
default:
cerr << "Invalid sliceOrder parameter in TestInteractorStyleImagePropertyInternal." << std::endl;
return 1;
}
renderer->AddViewProp(imageSlice);
renderer->AddViewProp(textActor);
vtkSmartPointer<vtkInteractorStyleImage> style =
vtkSmartPointer<vtkInteractorStyleImage>::New();
......@@ -103,40 +82,50 @@ int TestInteractorStyleImagePropertyInternal(int argc, char *argv[], int sliceOr
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindowInteractor->Initialize();
//The StartWindowLevel event is not activated until the function
//OnLeftButtonDown is called. Call it to force the event to trigger
//the chain of methods to set the ImageProperty.
style->OnLeftButtonDown();
if (!style->GetCurrentImageProperty())
{
cerr << "TestInteractorStyleImagePropertyInternal failed with sliceOrder parameter " << sliceOrder << "." << std::endl;
return 1;
}
// Returns 1 on failure, 0 on success.
return 0;
}
int TestInteractorStyleImageProperty(int argc, char *argv[])
{
bool res = true;
// Tests with slice before prop.
if (TestInteractorStyleImagePropertyInternal(argc, argv, 0) != 0)
{
res = false;
}
// Tests with no additional prop.
if (TestInteractorStyleImagePropertyInternal(argc, argv, 1) != 0)
{
res = false;
}
// Tests with slice after prop.
if (TestInteractorStyleImagePropertyInternal(argc, argv, 2) != 0)
for (int sliceOrder = 0; sliceOrder < 4; sliceOrder++)
{
res = false;
renderer->RemoveAllViewProps();
switch(sliceOrder)
{
case 0:
//Adding the slice to the renderer before the other prop.
renderer->AddViewProp(imageSlice);
renderer->AddViewProp(textActor);
break;
case 1:
//Only add the slice if there should not be a prop.
renderer->AddViewProp(imageSlice);
break;
case 2:
//Adding the slice to the renderer after the other prop.
renderer->AddViewProp(textActor);
renderer->AddViewProp(imageSlice);
break;
case 3:
//No slice, so no image property should be found.
renderer->AddViewProp(textActor);
break;
}
renderWindowInteractor->Render();
//The StartWindowLevel event is not activated until the function
//OnLeftButtonDown is called. Call it to force the event to trigger
//the chain of methods to set the ImageProperty.
style->OnLeftButtonDown();
bool foundProperty = (style->GetCurrentImageProperty() == property);
style->OnLeftButtonUp();
if (!foundProperty ^ (sliceOrder == 3))
{
cerr << "TestInteractorStyleImagePropertyInternal failed with sliceOrder parameter " << sliceOrder << "." << std::endl;
return EXIT_FAILURE;
}
}
return (res ? EXIT_SUCCESS : EXIT_FAILURE);
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment