Skip to content

Commit

Permalink
Merge topic 'UnifyErrorTestingMacros'
Browse files Browse the repository at this point in the history
a5fd4df ENH: Unify error/warning testing

Acked-by: Kitware Robot <[email protected]>
Merge-request: !2270
  • Loading branch information
lorensen authored and kwrobot committed Dec 20, 2016
2 parents 8fa1512 + a5fd4df commit 4a3bd17
Show file tree
Hide file tree
Showing 25 changed files with 178 additions and 670 deletions.
22 changes: 2 additions & 20 deletions Charts/Core/Testing/Cxx/TestBoxPlot2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,6 @@

#include "vtkTestErrorObserver.h"

#define CHECK_ERROR_MSG(observer, msg) \
{ \
std::string expectedMsg(msg); \
if (!observer->GetError()) \
{ \
std::cout << "ERROR: Failed to catch any error. Expected the error message to contain \"" << expectedMsg << std::endl; \
} \
else \
{ \
std::string gotMsg(observer->GetErrorMessage()); \
if (gotMsg.find(expectedMsg) == std::string::npos) \
{ \
std::cout << "ERROR: Error message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \
} \
} \
} \
observer->Clear()

//----------------------------------------------------------------------------
int TestBoxPlot2(int , char* [])
{
Expand Down Expand Up @@ -155,7 +137,7 @@ int TestBoxPlot2(int , char* [])

// Detect bad input error message from PlotBox
view->Render();
CHECK_ERROR_MSG(errorObserver, "Input table must contain 5 rows per column");
int status = errorObserver->CheckErrorMessage("Input table must contain 5 rows per column");

// Now render a valid plot
vtkTable *outTable = quartiles->GetOutput();
Expand All @@ -164,5 +146,5 @@ int TestBoxPlot2(int , char* [])

view->GetInteractor()->Start();

return EXIT_SUCCESS;
return status;
}
22 changes: 2 additions & 20 deletions Common/Core/Testing/Cxx/TestSparseArrayValidation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,6 @@
#include <iostream>
#include <stdexcept>

#define CHECK_ERROR_MSG(observer, msg) \
{ \
std::string expectedMsg(msg); \
if (!observer->GetError()) \
{ \
std::cout << "ERROR: Failed to catch any error. Expected the error message to contain \"" << expectedMsg << std::endl; \
} \
else \
{ \
std::string gotMsg(observer->GetErrorMessage()); \
if (gotMsg.find(expectedMsg) == std::string::npos) \
{ \
std::cout << "ERROR: Error message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \
} \
} \
} \
observer->Clear()

#define test_expression(expression) \
{ \
if(!(expression)) \
Expand Down Expand Up @@ -76,8 +58,8 @@ int TestSparseArrayValidation(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
array->AddValue(1, 2, 2);
array->AddValue(0, 0, 4);
test_expression(!array->Validate());
CHECK_ERROR_MSG(errorObserver,
"Array contains 1 duplicate coordinates");
int status = 0;
status += errorObserver->CheckErrorMessage("Array contains 1 duplicate coordinates");

array->Clear();
array->AddValue(0, 0, 1);
Expand Down
25 changes: 2 additions & 23 deletions Common/DataModel/Testing/Cxx/UnitTestImplicitDataSet.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@

static vtkSmartPointer<vtkImageData> MakeVolume(int, int, int);

#define CHECK_ERROR_MSG(errorObserver, msg, status) \
{ \
std::string expectedMsg(msg); \
if (!errorObserver->GetError()) \
{ \
std::cout << "Failed to catch any error. Expected the error message to contain \"" << expectedMsg << std::endl; \
status++; \
} \
else \
{ \
std::string gotMsg(errorObserver->GetErrorMessage()); \
if (gotMsg.find(expectedMsg) == std::string::npos) \
{ \
std::cout << "Error message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \
status++; \
} \
} \
} \
errorObserver->Clear()

int UnitTestImplicitDataSet (int, char*[])
{
int status = 0;
Expand All @@ -64,16 +44,15 @@ int UnitTestImplicitDataSet (int, char*[])

// Test error messages
std::cout << "Testing errors...";
int status1 = 0;
vtkSmartPointer<vtkTest::ErrorObserver> errorObserver =
vtkSmartPointer<vtkTest::ErrorObserver>::New();
impVol->AddObserver(vtkCommand::ErrorEvent, errorObserver);
impVol->EvaluateFunction(0.0, 0.0, 0.0);
CHECK_ERROR_MSG(errorObserver, "Can't evaluate function: either data set is missing or data set has no point data", status1);
int status1 = errorObserver->CheckErrorMessage("Can't evaluate function: either data set is missing or data set has no point data");
double zero[3], zg[3];;
zero[0] = zero[1] = zero[2] = 0.0;
impVol->EvaluateGradient(zero, zg);
CHECK_ERROR_MSG(errorObserver, "Can't evaluate gradient: either data set is missing or data set has no point data", status1);
status1 += errorObserver->CheckErrorMessage("Can't evaluate gradient: either data set is missing or data set has no point data");
if (status1)
{
std::cout << "Failed" << std::endl;
Expand Down
25 changes: 2 additions & 23 deletions Common/DataModel/Testing/Cxx/UnitTestImplicitVolume.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@

static vtkSmartPointer<vtkImageData> MakeVolume(int, int, int);

#define CHECK_ERROR_MSG(errorObserver, msg, status) \
{ \
std::string expectedMsg(msg); \
if (!errorObserver->GetError()) \
{ \
std::cout << "Failed to catch any error. Expected the error message to contain \"" << expectedMsg << std::endl; \
status++; \
} \
else \
{ \
std::string gotMsg(errorObserver->GetErrorMessage()); \
if (gotMsg.find(expectedMsg) == std::string::npos) \
{ \
std::cout << "Error message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \
status++; \
} \
} \
} \
errorObserver->Clear()

int UnitTestImplicitVolume (int, char*[])
{
int status = 0;
Expand All @@ -64,16 +44,15 @@ int UnitTestImplicitVolume (int, char*[])

//. Test error messages
std::cout << "Testing errors...";
int status1 = 0;
vtkSmartPointer<vtkTest::ErrorObserver> errorObserver =
vtkSmartPointer<vtkTest::ErrorObserver>::New();
impVol->AddObserver(vtkCommand::ErrorEvent, errorObserver);
impVol->EvaluateFunction(0.0, 0.0, 0.0);
CHECK_ERROR_MSG(errorObserver, "Can't evaluate function: either volume is missing or volume has no point data", status1);
int status1 = errorObserver->CheckErrorMessage("Can't evaluate function: either volume is missing or volume has no point data");
double zero[3], zg[3];;
zero[0] = zero[1] = zero[2] = 0.0;
impVol->EvaluateGradient(zero, zg);
CHECK_ERROR_MSG(errorObserver, "Can't evaluate gradient: either volume is missing or volume has no point data", status1);
status1 += errorObserver->CheckErrorMessage("Can't evaluate gradient: either volume is missing or volume has no point data");
if (status1)
{
std::cout << "Failed" << std::endl;
Expand Down
28 changes: 4 additions & 24 deletions Common/DataModel/Testing/Cxx/UnitTestPlanesIntersection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,6 @@
#include <sstream>
static vtkSmartPointer<vtkTetra> MakeTetra();

#define CHECK_ERROR_MSG(msg, status) \
{ \
std::string expectedMsg(msg); \
if (!errorObserver->GetError()) \
{ \
std::cout << "Failed to catch any error. Expected the error message to contain \"" << expectedMsg << std::endl; \
status++; \
} \
else \
{ \
std::string gotMsg(errorObserver->GetErrorMessage()); \
if (gotMsg.find(expectedMsg) == std::string::npos) \
{ \
std::cout << "Error message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \
status++; \
} \
} \
} \
errorObserver->Clear()

int UnitTestPlanesIntersection(int, char*[])
{
int status = 0;
Expand Down Expand Up @@ -312,7 +292,7 @@ int UnitTestPlanesIntersection(int, char*[])
vtkSmartPointer<vtkPlanesIntersection>::New();
empty->AddObserver(vtkCommand::ErrorEvent, errorObserver);
empty->GetRegionVertices(&v, 0);
CHECK_ERROR_MSG("invalid region", status3);
status3 += errorObserver->CheckErrorMessage("invalid region");

if (status3)
{
Expand Down Expand Up @@ -415,7 +395,7 @@ int UnitTestPlanesIntersection(int, char*[])
}
else
{
CHECK_ERROR_MSG("invalid region - less than 4 planes", status1);
status1 += errorObserver->CheckErrorMessage("invalid region - less than 4 planes");
}

// Invalid Region
Expand Down Expand Up @@ -447,7 +427,7 @@ int UnitTestPlanesIntersection(int, char*[])
}
else
{
CHECK_ERROR_MSG("Invalid region: zero-volume intersection", status1);
status1 += errorObserver->CheckErrorMessage("Invalid region: zero-volume intersection");
}
vtkSmartPointer<vtkPlanesIntersection> invalidBox =
vtkSmartPointer<vtkPlanesIntersection>::New();
Expand Down Expand Up @@ -493,7 +473,7 @@ int UnitTestPlanesIntersection(int, char*[])
}
else
{
CHECK_ERROR_MSG("invalid box", status1);
status1 += errorObserver->CheckErrorMessage("invalid box");
}

if (status1)
Expand Down
26 changes: 2 additions & 24 deletions Common/ExecutionModel/Testing/Cxx/UnitTestSimpleScalarTree.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,6 @@

static vtkSmartPointer<vtkImageData> MakeImage(int, int, int);

#define CHECK_ERROR_MSG(errorObserver, msg, status) \
{ \
std::string expectedMsg(msg); \
if (!errorObserver->GetError()) \
{ \
std::cout << "Failed to catch any error. Expected the error message to contain \"" << expectedMsg << std::endl; \
status++; \
} \
else \
{ \
std::string gotMsg(errorObserver->GetErrorMessage()); \
if (gotMsg.find(expectedMsg) == std::string::npos) \
{ \
std::cout << "Error message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \
status++; \
} \
} \
} \
errorObserver->Clear()

int UnitTestSimpleScalarTree(int, char*[])
{
int status = 0;
Expand All @@ -61,10 +41,9 @@ int UnitTestSimpleScalarTree(int, char*[])
std::cout << "Passed" << std::endl;

std::cout << "Testing no data error...";
int status1 = 0;
stree->AddObserver(vtkCommand::ErrorEvent, errorObserver);
stree->BuildTree();
CHECK_ERROR_MSG(errorObserver, "No data to build tree with", status1);
int status1 = errorObserver->CheckErrorMessage("No data to build tree with");
if (status1)
{
status++;
Expand All @@ -76,13 +55,12 @@ int UnitTestSimpleScalarTree(int, char*[])
}

std::cout << "Testing no scalar data error...";
int status2 = 0;
vtkSmartPointer<vtkSphereSource> aSphere =
vtkSmartPointer<vtkSphereSource>::New();
aSphere->Update();
stree->SetDataSet(aSphere->GetOutput());
stree->BuildTree();
CHECK_ERROR_MSG(errorObserver, "No scalar data to build trees with", status2);
int status2 = errorObserver->CheckErrorMessage("No scalar data to build trees with");
if (status2)
{
status++;
Expand Down
Loading

0 comments on commit 4a3bd17

Please sign in to comment.