From a5fd4df35d45fc74098771ece53b8daeb4c151c2 Mon Sep 17 00:00:00 2001 From: Bill Lorensen Date: Fri, 16 Dec 2016 12:30:49 -0500 Subject: [PATCH] ENH: Unify error/warning testing CHECK_ERROR_MSG and CHECK_WARNING_MSG are used to check the content of error and warning messages. Error and warning code is often overlooked during testing. Over the years, these two macros have been refined to increase their utility. Tests that use the macros defined their own interpretations. Three different API's have been used in the macros. This patch replaces the CHECK_ERROR_MSG and CHECK_WARNING_MSG macros with methods for vtkTest::ErrorObserver. All tests that used the CHECK macros in one form or another have been updated to use the CheckErrorMessage and CheckWarningMessage methods. --- Charts/Core/Testing/Cxx/TestBoxPlot2.cxx | 22 +---- .../Testing/Cxx/TestSparseArrayValidation.cxx | 22 +---- .../Testing/Cxx/UnitTestImplicitDataSet.cxx | 25 +---- .../Testing/Cxx/UnitTestImplicitVolume.cxx | 25 +---- .../Cxx/UnitTestPlanesIntersection.cxx | 28 +----- .../Testing/Cxx/UnitTestSimpleScalarTree.cxx | 26 +---- .../Testing/Cxx/UnitTestFunctionParser.cxx | 98 ++++++++----------- Filters/Core/Testing/Cxx/TestGlyph3D.cxx | 22 +---- .../Core/Testing/Cxx/UnitTestMaskPoints.cxx | 23 +---- .../Core/Testing/Cxx/UnitTestMergeFilter.cxx | 24 +---- .../Cxx/UnitTestGenericGeometryFilter.cxx | 24 +---- .../Cxx/UnitTestDataSetSurfaceFilter.cxx | 55 +---------- .../Cxx/UnitTestProjectSphereFilter.cxx | 25 +---- .../Cxx/UnitTestSubdivisionFilters.cxx | 60 +----------- .../Testing/Cxx/UnitTestPMaskPoints.cxx | 20 ---- .../Testing/Cxx/TestComputeQuartiles.cxx | 35 +++---- .../Cxx/TestExtractFunctionalBagPlot.cxx | 22 +---- IO/Export/Testing/Cxx/UnitTestRIB.cxx | 57 ++--------- IO/Geometry/Testing/Cxx/TestMFIXReader.cxx | 21 +--- IO/Geometry/Testing/Cxx/UnitTestSTLWriter.cxx | 62 +++--------- .../Testing/Cxx/TestFixedWidthTextReader.cxx | 25 +---- IO/SQL/Testing/Cxx/TestSQLiteDatabase.cxx | 24 +---- IO/XML/Testing/Cxx/TestXMLReaderBadData.cxx | 23 +---- .../Cxx/vtkSeedRepresentationTest1.cxx | 24 +---- Testing/Core/vtkTestErrorObserver.h | 56 +++++++++++ 25 files changed, 178 insertions(+), 670 deletions(-) diff --git a/Charts/Core/Testing/Cxx/TestBoxPlot2.cxx b/Charts/Core/Testing/Cxx/TestBoxPlot2.cxx index 99e2f16be48..c0394ab3333 100644 --- a/Charts/Core/Testing/Cxx/TestBoxPlot2.cxx +++ b/Charts/Core/Testing/Cxx/TestBoxPlot2.cxx @@ -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* []) { @@ -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(); @@ -164,5 +146,5 @@ int TestBoxPlot2(int , char* []) view->GetInteractor()->Start(); - return EXIT_SUCCESS; + return status; } diff --git a/Common/Core/Testing/Cxx/TestSparseArrayValidation.cxx b/Common/Core/Testing/Cxx/TestSparseArrayValidation.cxx index 64ff53c15d0..a39822ecbb5 100644 --- a/Common/Core/Testing/Cxx/TestSparseArrayValidation.cxx +++ b/Common/Core/Testing/Cxx/TestSparseArrayValidation.cxx @@ -27,24 +27,6 @@ #include #include -#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)) \ @@ -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); diff --git a/Common/DataModel/Testing/Cxx/UnitTestImplicitDataSet.cxx b/Common/DataModel/Testing/Cxx/UnitTestImplicitDataSet.cxx index 7cb4796f93a..6d6faebb39a 100644 --- a/Common/DataModel/Testing/Cxx/UnitTestImplicitDataSet.cxx +++ b/Common/DataModel/Testing/Cxx/UnitTestImplicitDataSet.cxx @@ -24,26 +24,6 @@ static vtkSmartPointer 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; @@ -64,16 +44,15 @@ int UnitTestImplicitDataSet (int, char*[]) // Test error messages std::cout << "Testing errors..."; - int status1 = 0; vtkSmartPointer errorObserver = vtkSmartPointer::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; diff --git a/Common/DataModel/Testing/Cxx/UnitTestImplicitVolume.cxx b/Common/DataModel/Testing/Cxx/UnitTestImplicitVolume.cxx index edf1967d1e6..42ee12bdcbb 100644 --- a/Common/DataModel/Testing/Cxx/UnitTestImplicitVolume.cxx +++ b/Common/DataModel/Testing/Cxx/UnitTestImplicitVolume.cxx @@ -24,26 +24,6 @@ static vtkSmartPointer 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; @@ -64,16 +44,15 @@ int UnitTestImplicitVolume (int, char*[]) //. Test error messages std::cout << "Testing errors..."; - int status1 = 0; vtkSmartPointer errorObserver = vtkSmartPointer::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; diff --git a/Common/DataModel/Testing/Cxx/UnitTestPlanesIntersection.cxx b/Common/DataModel/Testing/Cxx/UnitTestPlanesIntersection.cxx index 3eaad6f52a8..9d7ef86b574 100644 --- a/Common/DataModel/Testing/Cxx/UnitTestPlanesIntersection.cxx +++ b/Common/DataModel/Testing/Cxx/UnitTestPlanesIntersection.cxx @@ -27,26 +27,6 @@ #include static vtkSmartPointer 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; @@ -312,7 +292,7 @@ int UnitTestPlanesIntersection(int, char*[]) vtkSmartPointer::New(); empty->AddObserver(vtkCommand::ErrorEvent, errorObserver); empty->GetRegionVertices(&v, 0); - CHECK_ERROR_MSG("invalid region", status3); + status3 += errorObserver->CheckErrorMessage("invalid region"); if (status3) { @@ -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 @@ -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 invalidBox = vtkSmartPointer::New(); @@ -493,7 +473,7 @@ int UnitTestPlanesIntersection(int, char*[]) } else { - CHECK_ERROR_MSG("invalid box", status1); + status1 += errorObserver->CheckErrorMessage("invalid box"); } if (status1) diff --git a/Common/ExecutionModel/Testing/Cxx/UnitTestSimpleScalarTree.cxx b/Common/ExecutionModel/Testing/Cxx/UnitTestSimpleScalarTree.cxx index 96c68be57f7..07c849f405f 100644 --- a/Common/ExecutionModel/Testing/Cxx/UnitTestSimpleScalarTree.cxx +++ b/Common/ExecutionModel/Testing/Cxx/UnitTestSimpleScalarTree.cxx @@ -26,26 +26,6 @@ static vtkSmartPointer 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; @@ -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++; @@ -76,13 +55,12 @@ int UnitTestSimpleScalarTree(int, char*[]) } std::cout << "Testing no scalar data error..."; - int status2 = 0; vtkSmartPointer aSphere = vtkSmartPointer::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++; diff --git a/Common/Misc/Testing/Cxx/UnitTestFunctionParser.cxx b/Common/Misc/Testing/Cxx/UnitTestFunctionParser.cxx index 129d82758d4..a2d4d0a11dd 100644 --- a/Common/Misc/Testing/Cxx/UnitTestFunctionParser.cxx +++ b/Common/Misc/Testing/Cxx/UnitTestFunctionParser.cxx @@ -59,25 +59,6 @@ std::cout << "PASSED\n"; \ return EXIT_SUCCESS; \ } -#define CHECK_ERROR_MSG(msg) \ - { \ - 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() SCALAR_FUNC(TestAbs,abs,std::abs); SCALAR_FUNC(TestAcos,acos,std::acos); @@ -883,7 +864,7 @@ int TestErrors() parser->SetFunction("cos(a)"); parser->SetFunction(NULL); parser->IsScalarResult(); - CHECK_ERROR_MSG("Parse: no function has been set"); + status += errorObserver->CheckErrorMessage("Parse: no function has been set"); double s = -2.0; double v[3] = {1.0, 2.0, 3.0}; @@ -896,182 +877,181 @@ int TestErrors() // addition expects either 2 vectors or 2 scalars parser->SetFunction("s + v"); parser->IsScalarResult(); - CHECK_ERROR_MSG("addition expects either 2 vectors or 2 scalars"); + status += errorObserver->CheckErrorMessage("addition expects either 2 vectors or 2 scalars"); // subtraction expects either 2 vectors or 2 scalars parser->SetFunction("s - v"); parser->IsScalarResult(); - CHECK_ERROR_MSG("subtraction expects either 2 vectors or 2 scalars"); + status += errorObserver->CheckErrorMessage("subtraction expects either 2 vectors or 2 scalars"); // multiply expecting either 2 scalars or a scalar and a vector parser->SetFunction("v * w"); parser->IsScalarResult(); - CHECK_ERROR_MSG("multiply expecting either 2 scalars or a scalar and a vector"); + status += errorObserver->CheckErrorMessage("multiply expecting either 2 scalars or a scalar and a vector"); // can't divide vectors parser->SetFunction("v / w"); parser->IsScalarResult(); - CHECK_ERROR_MSG("can't divide vectors"); + status += errorObserver->CheckErrorMessage("can't divide vectors"); // can't raise a vector to a power parser->SetFunction("v ^ 2"); parser->IsScalarResult(); - CHECK_ERROR_MSG("can't raise a vector to a power"); + status += errorObserver->CheckErrorMessage("can't raise a vector to a power"); // Vectors cannot be used in boolean expressions parser->SetFunction("v | w"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Vectors cannot be used in boolean expressions"); + status += errorObserver->CheckErrorMessage("Vectors cannot be used in boolean expressions"); // expecting a scalar, but got a vector parser->SetFunction("cos(v)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("expecting a scalar, but got a vector"); + status += errorObserver->CheckErrorMessage("expecting a scalar, but got a vector"); // can't apply min to vectors parser->SetFunction("min(v,w)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("can't apply min to vectors"); - + status += errorObserver->CheckErrorMessage("can't apply min to vectors"); // can't apply max to vectors parser->SetFunction("max(v,w)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("can't apply max to vectors"); + status += errorObserver->CheckErrorMessage("can't apply max to vectors"); // can't apply cross to scalars parser->SetFunction("cross(s,w)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("can't apply cross to scalars"); + status += errorObserver->CheckErrorMessage("can't apply cross to scalars"); // dot product does not operate on scalars parser->SetFunction("s . v"); parser->IsScalarResult(); - CHECK_ERROR_MSG("dot product does not operate on scalars"); + status += errorObserver->CheckErrorMessage("dot product does not operate on scalars"); // magnitude expects a vector, but got a scalar parser->SetFunction("mag(s)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("magnitude expects a vector, but got a scalar"); + status += errorObserver->CheckErrorMessage("magnitude expects a vector, but got a scalar"); // normalize expects a vector, but got a scalar parser->SetFunction("norm(s)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("normalize expects a vector, but got a scalar"); + status += errorObserver->CheckErrorMessage("normalize expects a vector, but got a scalar"); // first argument of if(bool,valtrue,valfalse) cannot be a vector parser->SetFunction("if(v,s,s)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("first argument of if(bool,valtrue,valfalse) cannot be a vector"); + status += errorObserver->CheckErrorMessage("first argument of if(bool,valtrue,valfalse) cannot be a vector"); // first argument of if(bool,valtrue,valfalse) cannot be a vector parser->SetFunction("if(v,s,s)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("first argument of if(bool,valtrue,valfalse) cannot be a vector"); + status += errorObserver->CheckErrorMessage("first argument of if(bool,valtrue,valfalse) cannot be a vector"); // the if function expects the second and third arguments to be either 2 vectors or 2 scalars parser->SetFunction("if(s,v,s)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("the if function expects the second and third arguments to be either 2 vectors or 2 scalars"); + status += errorObserver->CheckErrorMessage("the if function expects the second and third arguments to be either 2 vectors or 2 scalars"); // Trying to take a natural logarithm of a negative value parser->SetFunction("ln(s)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Trying to take a natural logarithm of a negative value"); + status += errorObserver->CheckErrorMessage("Trying to take a natural logarithm of a negative value"); // Trying to take a natural logarithm of a negative value parser->SetFunction("ln(s)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Trying to take a natural logarithm of a negative value"); + status += errorObserver->CheckErrorMessage("Trying to take a natural logarithm of a negative value"); // Trying to take a log10 of a negative value parser->SetFunction("log10(s)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Trying to take a log10 of a negative value"); + status += errorObserver->CheckErrorMessage("Trying to take a log10 of a negative value"); // Trying to take a square root of a negative value parser->SetFunction("sqrt(s)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Trying to take a square root of a negative value"); + status += errorObserver->CheckErrorMessage("Trying to take a square root of a negative value"); // Trying to take asin of a value < -1 or > 1 parser->SetFunction("asin(s)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Trying to take asin of a value < -1 or > 1"); + status += errorObserver->CheckErrorMessage("Trying to take asin of a value < -1 or > 1"); // Trying to take acos of a value < -1 or > 1 parser->SetFunction("acos(s)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Trying to take acos of a value < -1 or > 1"); + status += errorObserver->CheckErrorMessage("Trying to take acos of a value < -1 or > 1"); // Trying to divide by zero< parser->SetFunction("s/zero"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Trying to divide by zero"); + status += errorObserver->CheckErrorMessage("Trying to divide by zero"); // GetScalarResult: no valid scalar result parser->SetFunction("cross(v,w)"); parser->GetScalarResult(); - CHECK_ERROR_MSG("GetScalarResult: no valid scalar result"); + status += errorObserver->CheckErrorMessage("GetScalarResult: no valid scalar result"); // GetVectorResult: no valid vector result parser->SetFunction("v . w"); parser->GetVectorResult(); - CHECK_ERROR_MSG("GetVectorResult: no valid vector result"); + status += errorObserver->CheckErrorMessage("GetVectorResult: no valid vector result"); // GetScalarVariableValue: scalar variable name ... does not exist parser->GetScalarVariableValue("xyz"); - CHECK_ERROR_MSG("GetScalarVariableValue: scalar variable name"); + status += errorObserver->CheckErrorMessage("GetScalarVariableValue: scalar variable name"); // GetScalarVariableValue: scalar variable number ... does not exist parser->GetScalarVariableValue(128); - CHECK_ERROR_MSG("GetScalarVariableValue: scalar variable number"); + status += errorObserver->CheckErrorMessage("GetScalarVariableValue: scalar variable number"); // GetVectorVariableValue: vector variable name ... does not exist parser->GetVectorVariableValue("xyz"); - CHECK_ERROR_MSG("GetVectorVariableValue: vector variable name"); + status += errorObserver->CheckErrorMessage("GetVectorVariableValue: vector variable name"); // GetVectorVariableValue: vector variable number ... does not exist parser->GetVectorVariableValue(128); - CHECK_ERROR_MSG("GetVectorVariableValue: vector variable number"); + status += errorObserver->CheckErrorMessage("GetVectorVariableValue: vector variable number"); // Syntax error: expecting a variable name parser->SetFunction("acos()"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Syntax error: expecting a variable name"); + status += errorObserver->CheckErrorMessage("Syntax error: expecting a variable name"); // Parse errors parser->SetFunction("-"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Syntax error: unary minus with no operand"); + status += errorObserver->CheckErrorMessage("Syntax error: unary minus with no operand"); parser->SetFunction("s *"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Syntax error: expecting a variable name"); + status += errorObserver->CheckErrorMessage("Syntax error: expecting a variable name"); parser->SetFunction("cross(v)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Syntax Error: two parameters separated by commas expected"); + status += errorObserver->CheckErrorMessage("Syntax Error: two parameters separated by commas expected"); parser->SetFunction("if(v,s)"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Syntax Error: three parameters separated by commas expected"); + status += errorObserver->CheckErrorMessage("Syntax Error: three parameters separated by commas expected"); parser->SetFunction("s * (v + w"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Syntax Error: missing closing parenthesis"); + status += errorObserver->CheckErrorMessage("Syntax Error: missing closing parenthesis"); parser->SetFunction("v + w)*s"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Syntax Error: mismatched parenthesis"); + status += errorObserver->CheckErrorMessage("Syntax Error: mismatched parenthesis"); parser->SetFunction("s s"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Syntax error: operator expected"); + status += errorObserver->CheckErrorMessage("Syntax error: operator expected"); #if 0 parser->SetFunction("s*()"); parser->IsScalarResult(); - CHECK_ERROR_MSG("Syntax Error: empty parentheses"); + status += errorObserver->CheckErrorMessage("Syntax Error: empty parentheses"); #endif if (status== 0) diff --git a/Filters/Core/Testing/Cxx/TestGlyph3D.cxx b/Filters/Core/Testing/Cxx/TestGlyph3D.cxx index 90fc619e83c..e56daf85556 100644 --- a/Filters/Core/Testing/Cxx/TestGlyph3D.cxx +++ b/Filters/Core/Testing/Cxx/TestGlyph3D.cxx @@ -30,24 +30,6 @@ #include "vtkCamera.h" #include "vtkCommand.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() - static bool TestGlyph3D_WithBadArray() { vtkSmartPointer vectors = @@ -84,8 +66,8 @@ static bool TestGlyph3D_WithBadArray() glyph3D->AddObserver(vtkCommand::ErrorEvent,errorObserver1); glyph3D->GetExecutive()->AddObserver(vtkCommand::ErrorEvent,errorObserver2); glyph3D->Update(); - CHECK_ERROR_MSG(errorObserver1, "vtkDataArray Normals has more than 3 components"); - CHECK_ERROR_MSG(errorObserver2, "Algorithm vtkGlyph3D"); + int status = errorObserver1->CheckErrorMessage("vtkDataArray Normals has more than 3 components"); + status += errorObserver2->CheckErrorMessage("Algorithm vtkGlyph3D"); return true; } diff --git a/Filters/Core/Testing/Cxx/UnitTestMaskPoints.cxx b/Filters/Core/Testing/Cxx/UnitTestMaskPoints.cxx index a12e85f1467..1e59a57371b 100644 --- a/Filters/Core/Testing/Cxx/UnitTestMaskPoints.cxx +++ b/Filters/Core/Testing/Cxx/UnitTestMaskPoints.cxx @@ -28,26 +28,6 @@ #include #include -#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() - static vtkSmartPointer MakePolyData( unsigned int numPoints); static vtkSmartPointer MakeImageData( @@ -164,8 +144,7 @@ int UnitTestMaskPoints (int, char*[]) mask0->AddObserver(vtkCommand::ErrorEvent, errorObserver); mask0->SetInputData(MakePolyData(0)); mask0->Update(); - int status1 = 0; - CHECK_ERROR_MSG(errorObserver, "No points to mask", status1); + int status1 = errorObserver->CheckErrorMessage("No points to mask"); if (status1) { std::cout << "FAILED" << std::endl; diff --git a/Filters/Core/Testing/Cxx/UnitTestMergeFilter.cxx b/Filters/Core/Testing/Cxx/UnitTestMergeFilter.cxx index c25c7377c7f..77968f89d90 100644 --- a/Filters/Core/Testing/Cxx/UnitTestMergeFilter.cxx +++ b/Filters/Core/Testing/Cxx/UnitTestMergeFilter.cxx @@ -31,26 +31,6 @@ static vtkSmartPointer MakePointData(unsigned int numberOfPoints); static vtkSmartPointer MakeCellData(unsigned int numberOfCells); -#define CHECK_WARNING_MSG(warningObserver, msg, status) \ - { \ - std::string expectedMsg(msg); \ - if (!warningObserver->GetWarning()) \ - { \ - std::cout << "Failed to catch any warning.. Expected the warning message to contain \"" << expectedMsg << std::endl; \ - status++; \ - } \ - else \ - { \ - std::string gotMsg(warningObserver->GetWarningMessage()); \ - if (gotMsg.find(expectedMsg) == std::string::npos) \ - { \ - std::cout << "Warning message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \ - status++; \ - } \ - } \ - } \ - warningObserver->Clear() - int UnitTestMergeFilter (int, char*[]) { int status = 0; @@ -119,7 +99,7 @@ int UnitTestMergeFilter (int, char*[]) vtkSmartPointer::New(); merge0->AddObserver(vtkCommand::WarningEvent, warningObserver); merge0->Update(); - CHECK_WARNING_MSG(warningObserver, "Nothing to merge!", status0); + status0 += warningObserver->CheckWarningMessage("Nothing to merge!"); if (status0) { status++; @@ -239,7 +219,7 @@ int UnitTestMergeFilter (int, char*[]) merge1->AddField("", polyData2); merge1->Update(); - CHECK_WARNING_MSG(warningObserver, "cannot be merged", status); + status += warningObserver->CheckWarningMessage("cannot be merged"); if (status) { return EXIT_FAILURE; diff --git a/Filters/Generic/Testing/Cxx/UnitTestGenericGeometryFilter.cxx b/Filters/Generic/Testing/Cxx/UnitTestGenericGeometryFilter.cxx index 9f4b29d8116..123520fae4c 100644 --- a/Filters/Generic/Testing/Cxx/UnitTestGenericGeometryFilter.cxx +++ b/Filters/Generic/Testing/Cxx/UnitTestGenericGeometryFilter.cxx @@ -33,26 +33,6 @@ static vtkSmartPointer CreatePolyData(const int xres, const in static vtkSmartPointer CreateVertexData(); static vtkSmartPointer CreateTetraData(); -#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 UnitTestGenericGeometryFilter(int, char*[]) { const int xres = 20, yres = 10; @@ -216,11 +196,11 @@ int UnitTestGenericGeometryFilter(int, char*[]) filter->AddObserver(vtkCommand::ErrorEvent, errorObserver); filter->SetInputData (vtkSmartPointer::New()); filter->Update(); - CHECK_ERROR_MSG(errorObserver, "Number of cells is zero, no data to process.", status); + status += errorObserver->CheckErrorMessage("Number of cells is zero, no data to process."); filter->SetInputData (CreateVertexData()); filter->Update(); - CHECK_ERROR_MSG(errorObserver, "Cell of dimension 0 not handled yet.", status); + status += errorObserver->CheckErrorMessage("Cell of dimension 0 not handled yet."); if (status) { diff --git a/Filters/Geometry/Testing/Cxx/UnitTestDataSetSurfaceFilter.cxx b/Filters/Geometry/Testing/Cxx/UnitTestDataSetSurfaceFilter.cxx index 6a96008554f..bb4f1814128 100644 --- a/Filters/Geometry/Testing/Cxx/UnitTestDataSetSurfaceFilter.cxx +++ b/Filters/Geometry/Testing/Cxx/UnitTestDataSetSurfaceFilter.cxx @@ -57,46 +57,6 @@ static vtkSmartPointer CreateStructuredGrid(bool blank = false); static vtkSmartPointer CreateBadAttributes(); static vtkSmartPointer CreateGenericCellData(int cellType); -#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() - -#define CHECK_WARNING_MSG(warningObserver, msg, status) \ - { \ - std::string expectedMsg(msg); \ - if (!warningObserver->GetWarning()) \ - { \ - std::cout << "Failed to catch any warning. Expected the warning message to contain \"" << expectedMsg << std::endl; \ - status++; \ - } \ - else \ - { \ - std::string gotMsg(warningObserver->GetWarningMessage()); \ - if (gotMsg.find(expectedMsg) == std::string::npos) \ - { \ - std::cout << "Warning message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \ - status++; \ - } \ - } \ - } \ - warningObserver->Clear() - namespace test { // What to expect for a cell @@ -426,8 +386,7 @@ int UnitTestDataSetSurfaceFilter(int, char*[]) ext[4] = tmpext[4]; ext[5] = tmpext[5]; bool faces[6] = {true, true, true, true, true, true}; filter->UniformGridExecute(ugrid, polyData, ext, ext, faces); - int status1 = 0; - CHECK_ERROR_MSG(errorObserver, "Strips are not supported for uniform grid!", status1); + int status1 = errorObserver->CheckErrorMessage("Strips are not supported for uniform grid!"); if (status1) { std::cout << " FAILED." << std::endl; @@ -449,8 +408,7 @@ int UnitTestDataSetSurfaceFilter(int, char*[]) filter->AddObserver(vtkCommand::WarningEvent, warningObserver); filter->Update(); - int status1 = 0; - CHECK_WARNING_MSG(warningObserver, "Number of cells is zero, no data to process.", status1); + int status1 = warningObserver->CheckWarningMessage("Number of cells is zero, no data to process."); if (status1) { std::cout << " FAILED." << std::endl; @@ -477,8 +435,7 @@ int UnitTestDataSetSurfaceFilter(int, char*[]) vtkSmartPointer::New(); filter->DataSetExecute(ugrid, polyData); - int status1 = 0; - CHECK_WARNING_MSG(warningObserver, "Number of cells is zero, no data to process.", status1); + int status1 = warningObserver->CheckWarningMessage("Number of cells is zero, no data to process."); if (status1) { std::cout << " FAILED." << std::endl; @@ -510,8 +467,7 @@ int UnitTestDataSetSurfaceFilter(int, char*[]) filter->StructuredExecute(ugrid, polyData, ext, ext); - int status1 = 0; - CHECK_ERROR_MSG(errorObserver, "Invalid data set type: 4", status1); + int status1 = errorObserver->CheckErrorMessage("Invalid data set type: 4"); if (status1) { std::cout << " FAILED." << std::endl; @@ -535,8 +491,7 @@ int UnitTestDataSetSurfaceFilter(int, char*[]) filter->GetInput()->AddObserver(vtkCommand::ErrorEvent, errorObserver); filter->Update(); - int status1 = 0; - CHECK_ERROR_MSG(errorObserver, "Point array PointDataTestArray with 1 components, only has 2 tuples but there are 3 points", status1); + int status1 = errorObserver->CheckErrorMessage("Point array PointDataTestArray with 1 components, only has 2 tuples but there are 3 points"); if (status1) { std::cout << " FAILED." << std::endl; diff --git a/Filters/Geometry/Testing/Cxx/UnitTestProjectSphereFilter.cxx b/Filters/Geometry/Testing/Cxx/UnitTestProjectSphereFilter.cxx index e2f71198b8e..be15eb670bf 100644 --- a/Filters/Geometry/Testing/Cxx/UnitTestProjectSphereFilter.cxx +++ b/Filters/Geometry/Testing/Cxx/UnitTestProjectSphereFilter.cxx @@ -34,26 +34,6 @@ #include -#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() - static int ComparePolyData (vtkPolyData *p1, vtkPolyData *p2); int UnitTestProjectSphereFilter(int, char*[]) { @@ -97,10 +77,7 @@ int UnitTestProjectSphereFilter(int, char*[]) filter->SetInputData(badPoly); filter->Update(); - int status1 = 0; - CHECK_ERROR_MSG(errorObserver, - "Can only deal with vtkPolyData polys", - status1); + int status1 = errorObserver->CheckErrorMessage("Can only deal with vtkPolyData polys"); if (status1 == 0) { std::cout << "PASSED" << std::endl; diff --git a/Filters/Modeling/Testing/Cxx/UnitTestSubdivisionFilters.cxx b/Filters/Modeling/Testing/Cxx/UnitTestSubdivisionFilters.cxx index 4d0406ccb72..712b687f15c 100644 --- a/Filters/Modeling/Testing/Cxx/UnitTestSubdivisionFilters.cxx +++ b/Filters/Modeling/Testing/Cxx/UnitTestSubdivisionFilters.cxx @@ -31,46 +31,6 @@ #include -#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() - -#define CHECK_WARNING_MSG(warningObserver, msg, status) \ - { \ - std::string expectedMsg(msg); \ - if (!warningObserver->GetWarning()) \ - { \ - std::cout << "Failed to catch any warning. Expected the warning message to contain \"" << expectedMsg << std::endl; \ - status++; \ - } \ - else \ - { \ - std::string gotMsg(warningObserver->GetWarningMessage()); \ - if (gotMsg.find(expectedMsg) == std::string::npos) \ - { \ - std::cout << "Warning message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \ - status++; \ - } \ - } \ - } \ - warningObserver->Clear() - template int TestSubdivision(); int UnitTestSubdivisionFilters (int, char*[]) @@ -107,10 +67,7 @@ template int TestSubdivision() subdivision0->GetExecutive()->AddObserver(vtkCommand::ErrorEvent, executiveObserver); subdivision0->Update(); - int status1 = 0; - CHECK_ERROR_MSG(executiveObserver, - "has 0 connections but is not optional.", - status1); + int status1 = executiveObserver->CheckErrorMessage("has 0 connections but is not optional."); if (status1 == 0) { std::cout << "PASSED" << std::endl; @@ -132,10 +89,7 @@ template int TestSubdivision() subdivision0->SetNumberOfSubdivisions(4); subdivision0->Update(); - int status2 = 0; - CHECK_ERROR_MSG(errorObserver, - "No data to subdivide", - status2); + int status2 = errorObserver->CheckErrorMessage("No data to subdivide"); if (status2 == 0) { std::cout << "PASSED" << std::endl; @@ -200,10 +154,7 @@ template int TestSubdivision() subdivision0->SetInputData(nonManifoldPolyData); subdivision0->Modified(); subdivision0->Update(); - int status3 = 0; - CHECK_ERROR_MSG(errorObserver, - "Dataset is non-manifold and cannot be subdivided", - status3); + int status3 = errorObserver->CheckErrorMessage("Dataset is non-manifold and cannot be subdivided"); if (status3 == 0) { std::cout << "PASSED" << std::endl; @@ -234,10 +185,7 @@ template int TestSubdivision() subdivision0->SetInputData(mixedPolyData); subdivision0->Update(); - int status4 = 0; - CHECK_ERROR_MSG(errorObserver, - "only operates on triangles, but this data set has other cell types present", - status4); + int status4 = errorObserver->CheckErrorMessage("only operates on triangles, but this data set has other cell types present"); if (status4 == 0) { std::cout << "PASSED" << std::endl; diff --git a/Filters/Parallel/Testing/Cxx/UnitTestPMaskPoints.cxx b/Filters/Parallel/Testing/Cxx/UnitTestPMaskPoints.cxx index bac8c63c78c..a0bddb25847 100644 --- a/Filters/Parallel/Testing/Cxx/UnitTestPMaskPoints.cxx +++ b/Filters/Parallel/Testing/Cxx/UnitTestPMaskPoints.cxx @@ -32,26 +32,6 @@ #include #include -#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() - static vtkSmartPointer MakePolyData( unsigned int numPoints); diff --git a/Filters/Statistics/Testing/Cxx/TestComputeQuartiles.cxx b/Filters/Statistics/Testing/Cxx/TestComputeQuartiles.cxx index 8f9f6333dea..04c1e40cc75 100644 --- a/Filters/Statistics/Testing/Cxx/TestComputeQuartiles.cxx +++ b/Filters/Statistics/Testing/Cxx/TestComputeQuartiles.cxx @@ -1,3 +1,18 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: TestComputeQuartiles.cxx + + Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ + #include "vtkComputeQuartiles.h" #include "vtkDoubleArray.h" #include "vtkMultiBlockDataSet.h" @@ -8,24 +23,6 @@ #include "vtkTestErrorObserver.h" #include "vtkExecutive.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 TestComputeQuartiles(int , char * []) { @@ -74,7 +71,7 @@ int TestComputeQuartiles(int , char * []) // First verify that absence of input does not cause trouble quartiles->GetExecutive()->AddObserver(vtkCommand::ErrorEvent,errorObserver1.GetPointer()); quartiles->Update(); - CHECK_ERROR_MSG(errorObserver1, "Input port 0 of algorithm vtkComputeQuartiles"); + errorObserver1->CheckErrorMessage("Input port 0 of algorithm vtkComputeQuartiles"); // Now set the real input table quartiles->SetInputData(vtkStatisticsAlgorithm::INPUT_DATA, table.GetPointer()); diff --git a/Filters/Statistics/Testing/Cxx/TestExtractFunctionalBagPlot.cxx b/Filters/Statistics/Testing/Cxx/TestExtractFunctionalBagPlot.cxx index 207a55e02f5..4d4edde4135 100644 --- a/Filters/Statistics/Testing/Cxx/TestExtractFunctionalBagPlot.cxx +++ b/Filters/Statistics/Testing/Cxx/TestExtractFunctionalBagPlot.cxx @@ -31,24 +31,6 @@ #include -#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 message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \ - } \ - } \ - } \ - observer->Clear() - //---------------------------------------------------------------------------- const double densities[] = { 0.00013383, @@ -157,7 +139,7 @@ int TestExtractFunctionalBagPlot(int , char * []) // First verify that absence of input does not cause trouble ebp->GetExecutive()->AddObserver(vtkCommand::ErrorEvent,errorObserver1.GetPointer()); ebp->Update(); - CHECK_ERROR_MSG(errorObserver1, "Input port 0 of algorithm vtkExtractFunctionalBagPlot"); + int status = errorObserver1->CheckErrorMessage("Input port 0 of algorithm vtkExtractFunctionalBagPlot"); ebp->SetInputData(0, table.GetPointer()); ebp->SetInputData(1, inTableDensity.GetPointer()); @@ -217,5 +199,5 @@ int TestExtractFunctionalBagPlot(int , char * []) cout << "## Failure: bad values found in Q3Points or QMedPoints" << endl; return EXIT_FAILURE; } - return EXIT_SUCCESS; + return status; } diff --git a/IO/Export/Testing/Cxx/UnitTestRIB.cxx b/IO/Export/Testing/Cxx/UnitTestRIB.cxx index 4e3d3c7c2b3..9dc952335e4 100644 --- a/IO/Export/Testing/Cxx/UnitTestRIB.cxx +++ b/IO/Export/Testing/Cxx/UnitTestRIB.cxx @@ -32,46 +32,6 @@ #include -#define CHECK_ERROR_MSG(msg) \ - { \ - 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() - -#define CHECK_WARNING_MSG(msg) \ - { \ - std::string expectedMsg(msg); \ - if (!warningObserver->GetWarning()) \ - { \ - std::cout << "Failed to catch any warning. Expected the warning message to contain \"" << expectedMsg << "\"" << std::endl; \ - status++; \ - } \ - else \ - { \ - std::string gotMsg(warningObserver->GetWarningMessage()); \ - if (gotMsg.find(expectedMsg) == std::string::npos) \ - { \ - std::cout << "Warning message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \ - status++; \ - } \ - } \ - } \ - warningObserver->Clear() - #define TEST_SET_GET_VALUE( variable, command ) \ if( variable != command ) \ { \ @@ -174,15 +134,15 @@ int TestRIBProperty() vtkSmartPointer::New(); prop->AddObserver(vtkCommand::WarningEvent, warningObserver); prop->SetParameter("floatVar", "5.678"); - CHECK_WARNING_MSG("SetParameter is deprecated"); + status += warningObserver->CheckWarningMessage("SetParameter is deprecated"); TEST_SET_GET_VALUE(std::string( " \"floatVar\" [5.678]"), std::string(prop->GetParameters())); - CHECK_WARNING_MSG("GetParameters is deprecated"); + status+= warningObserver->CheckWarningMessage("GetParameters is deprecated"); prop->AddParameter("colorVar", "1 .5 .1"); - CHECK_WARNING_MSG("AddParameter is deprecated"); + status += warningObserver->CheckWarningMessage("AddParameter is deprecated"); TEST_SET_GET_VALUE(std::string( " \"floatVar\" [5.678] \"colorVar\" [1 .5 .1]"), std::string(prop->GetSurfaceShaderParameters())); @@ -369,29 +329,30 @@ int TestRIBExporter() prop->SetRepresentationToWireframe(); exporter->Update(); - CHECK_ERROR_MSG("Bad representation. Only Surface is supported."); + + status += errorObserver->CheckErrorMessage("Bad representation. Only Surface is supported."); prop->SetRepresentationToSurface(); prop2->SetRepresentationToWireframe(); exporter->Update(); - CHECK_ERROR_MSG("Bad representation. Only Surface is supported."); + status += errorObserver->CheckErrorMessage("Bad representation. Only Surface is supported."); exporter->SetFilePrefix(NULL); exporter->Update(); - CHECK_ERROR_MSG("Please specify file name for the rib file"); + status += errorObserver->CheckErrorMessage("Please specify file name for the rib file"); vtkSmartPointer ren2 = vtkSmartPointer::New (); renWin->AddRenderer(ren2); exporter->SetFilePrefix("dummy"); exporter->Update(); - CHECK_ERROR_MSG("RIB files only support one renderer per window"); + status += errorObserver->CheckErrorMessage("RIB files only support one renderer per window"); renWin->RemoveRenderer(ren2); ren1->RemoveActor(sphere); ren1->RemoveActor(strip); exporter->Update(); - CHECK_ERROR_MSG("No actors found for writing .RIB file"); + status += errorObserver->CheckErrorMessage("No actors found for writing .RIB file"); std::cout << ".PASSED" << std::endl; diff --git a/IO/Geometry/Testing/Cxx/TestMFIXReader.cxx b/IO/Geometry/Testing/Cxx/TestMFIXReader.cxx index dce39f44f5c..ce10709c0b6 100644 --- a/IO/Geometry/Testing/Cxx/TestMFIXReader.cxx +++ b/IO/Geometry/Testing/Cxx/TestMFIXReader.cxx @@ -27,24 +27,6 @@ #include #include -#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 TestMFIXReader(int argc, char *argv[]) { // Read file name. @@ -63,8 +45,7 @@ int TestMFIXReader(int argc, char *argv[]) // Update without a filename should cause an error reader->Update(); - CHECK_ERROR_MSG(errorObserver1, - "No filename specified"); + errorObserver1->CheckErrorMessage("No filename specified"); reader->SetFileName(filename); delete [] filename; diff --git a/IO/Geometry/Testing/Cxx/UnitTestSTLWriter.cxx b/IO/Geometry/Testing/Cxx/UnitTestSTLWriter.cxx index 6c0f4a33665..569f8c5cd3e 100644 --- a/IO/Geometry/Testing/Cxx/UnitTestSTLWriter.cxx +++ b/IO/Geometry/Testing/Cxx/UnitTestSTLWriter.cxx @@ -25,26 +25,6 @@ #include -#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 UnitTestSTLWriter(int argc,char *argv[]) { int status = 0; @@ -108,8 +88,7 @@ int UnitTestSTLWriter(int argc,char *argv[]) writer2->SetInputData(emptyPolyData); writer2->SetFileTypeToASCII(); writer2->Update(); - int status1 = 0; - CHECK_ERROR_MSG("No data to write", status1); + int status1 = errorObserver->CheckErrorMessage("No data to write"); if (status1) { ++status; @@ -118,8 +97,7 @@ int UnitTestSTLWriter(int argc,char *argv[]) writer2->SetInputData(emptyPolyData); writer2->SetFileTypeToBinary(); writer2->Update(); - status1 = 0; - CHECK_ERROR_MSG("No data to write", status); + status1 = errorObserver->CheckErrorMessage("No data to write"); if (status1) { ++status; @@ -129,8 +107,7 @@ int UnitTestSTLWriter(int argc,char *argv[]) writer2->SetInputConnection(sphere->GetOutputPort()); writer2->SetFileTypeToASCII(); writer2->Update(); - status1 = 0; - CHECK_ERROR_MSG("Please specify FileName to write", status); + status1 = errorObserver->CheckErrorMessage("Please specify FileName to write"); if (status1) { ++status; @@ -140,8 +117,7 @@ int UnitTestSTLWriter(int argc,char *argv[]) writer2->SetInputConnection(sphere->GetOutputPort()); writer2->SetFileTypeToBinary(); writer2->Update(); - status1 = 0; - CHECK_ERROR_MSG("Please specify FileName to write", status); + status1 = errorObserver->CheckErrorMessage("Please specify FileName to write"); if (status1) { ++status; @@ -151,8 +127,7 @@ int UnitTestSTLWriter(int argc,char *argv[]) writer2->SetInputConnection(sphere->GetOutputPort()); writer2->SetFileTypeToASCII(); writer2->Update(); - status1 = 0; - CHECK_ERROR_MSG("Couldn't open file: /", status); + status1 = errorObserver->CheckErrorMessage("Couldn't open file: /"); if (status1) { ++status; @@ -162,22 +137,19 @@ int UnitTestSTLWriter(int argc,char *argv[]) writer2->SetInputConnection(sphere->GetOutputPort()); writer2->SetFileTypeToBinary(); writer2->Update(); - status1 = 0; - CHECK_ERROR_MSG("Couldn't open file: /", status); + status1 = errorObserver->CheckErrorMessage("Couldn't open file: /"); if (status1) { ++status; } - if (vtksys::SystemTools::FileExists("/dev/full")) { writer2->SetFileName("/dev/full"); writer2->SetInputConnection(sphere->GetOutputPort()); writer2->SetFileTypeToASCII(); writer2->Update(); - status1 = 0; - CHECK_ERROR_MSG("Ran out of disk space; deleting file: /dev/full", status); + status1 = errorObserver->CheckErrorMessage("Ran out of disk space; deleting file: /dev/full"); if (status1) { ++status; @@ -185,8 +157,7 @@ int UnitTestSTLWriter(int argc,char *argv[]) writer2->SetInputConnection(stripper->GetOutputPort()); writer2->Update(); - status1 = 0; - CHECK_ERROR_MSG("Ran out of disk space; deleting file: /dev/full", status); + status1 = errorObserver->CheckErrorMessage("Ran out of disk space; deleting file: /dev/full"); if (status1) { ++status; @@ -196,15 +167,15 @@ int UnitTestSTLWriter(int argc,char *argv[]) writer2->SetInputConnection(sphere->GetOutputPort()); writer2->SetFileTypeToBinary(); writer2->Update(); - status1 = 0; - CHECK_ERROR_MSG("Ran out of disk space; deleting file: /dev/full", status); if (status1) + status1 = errorObserver->CheckErrorMessage("Ran out of disk space; deleting file: /dev/full"); + if (status1) { ++status; } writer2->SetInputConnection(stripper->GetOutputPort()); writer2->Update(); - status1 = 0; - CHECK_ERROR_MSG("Ran out of disk space; deleting file: /dev/full", status); if (status1) + status1 = errorObserver->CheckErrorMessage("Ran out of disk space; deleting file: /dev/full"); + if (status1) { ++status; } @@ -216,8 +187,7 @@ int UnitTestSTLWriter(int argc,char *argv[]) writer2->SetFileTypeToASCII(); writer2->Update(); - status1 = 0; - CHECK_ERROR_MSG("STL file only supports triangles", status); + status1 = errorObserver->CheckErrorMessage("STL file only supports triangles"); if (status1) { ++status; @@ -225,8 +195,7 @@ int UnitTestSTLWriter(int argc,char *argv[]) writer2->SetFileTypeToBinary(); writer2->Update(); - status1 = 0; - CHECK_ERROR_MSG("STL file only supports triangles", status); + status1 = errorObserver->CheckErrorMessage("STL file only supports triangles"); if (status1) { ++status; @@ -236,8 +205,7 @@ int UnitTestSTLWriter(int argc,char *argv[]) writer2->SetFileTypeToBinary(); writer2->SetHeader("solid"); writer2->Update(); - status1 = 0; - CHECK_ERROR_MSG("Invalid header for Binary STL file. Cannot start with \"solid\"", status1); + status1 = errorObserver->CheckErrorMessage("Invalid header for Binary STL file. Cannot start with \"solid\""); if (status1) { ++status; diff --git a/IO/Infovis/Testing/Cxx/TestFixedWidthTextReader.cxx b/IO/Infovis/Testing/Cxx/TestFixedWidthTextReader.cxx index 27686a742c8..7c278d77a72 100644 --- a/IO/Infovis/Testing/Cxx/TestFixedWidthTextReader.cxx +++ b/IO/Infovis/Testing/Cxx/TestFixedWidthTextReader.cxx @@ -28,24 +28,6 @@ #include #include -#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 TestFixedWidthTextReader(int argc, char *argv[]) { std::cout << "### Pass 1: No headers, field width 10, do not strip whitespace" << std::endl; @@ -65,8 +47,7 @@ int TestFixedWidthTextReader(int argc, char *argv[]) reader->SetFileName(filename); reader->SetTableErrorObserver(errorObserver1.GetPointer()); reader->Update(); - CHECK_ERROR_MSG(errorObserver1, - "Incorrect number of tuples in SetRow. Expected 4, but got 6"); + int status = errorObserver1->CheckErrorMessage("Incorrect number of tuples in SetRow. Expected 4, but got 6"); std::cout << "Printing reader info..." << std::endl; reader->Print(std::cout); @@ -120,9 +101,7 @@ int TestFixedWidthTextReader(int argc, char *argv[]) reader->SetFileName(filename); reader->SetTableErrorObserver(errorObserver1.GetPointer()); reader->Update(); - CHECK_ERROR_MSG(errorObserver1, - "Incorrect number of tuples in SetRow. Expected 4, but got 6"); - + status += errorObserver1->CheckErrorMessage("Incorrect number of tuples in SetRow. Expected 4, but got 6"); table = reader->GetOutput(); diff --git a/IO/SQL/Testing/Cxx/TestSQLiteDatabase.cxx b/IO/SQL/Testing/Cxx/TestSQLiteDatabase.cxx index 6ae1ba8e5e3..667fddf273c 100644 --- a/IO/SQL/Testing/Cxx/TestSQLiteDatabase.cxx +++ b/IO/SQL/Testing/Cxx/TestSQLiteDatabase.cxx @@ -36,24 +36,6 @@ #include -#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 TestSQLiteDatabase( int /*argc*/, char* /*argv*/[]) { bool status; @@ -101,8 +83,7 @@ int TestSQLiteDatabase( int /*argc*/, char* /*argv*/[]) cerr << "Using CREATE on an existing file should have failed but did not.\n"; return 1; } - CHECK_ERROR_MSG(errorObserver, - "You specified creating a database but the file exists"); + int status1 = errorObserver->CheckErrorMessage("You specified creating a database but the file exists"); db2->Delete(); vtkSQLiteDatabase* db3 = vtkSQLiteDatabase::SafeDownCast( vtkSQLDatabase::CreateFromURL( "sqlite://local.db" ) ); @@ -137,8 +118,7 @@ int TestSQLiteDatabase( int /*argc*/, char* /*argv*/[]) cerr << "Select query succeeded when it shouldn't have." << endl; return 1; } - CHECK_ERROR_MSG(queryObserver, - "Query is not null but prepared statement is"); + status1 += queryObserver->CheckErrorMessage("Query is not null but prepared statement is"); db4->Delete(); query4->Delete(); diff --git a/IO/XML/Testing/Cxx/TestXMLReaderBadData.cxx b/IO/XML/Testing/Cxx/TestXMLReaderBadData.cxx index 328bfa753f6..96fcbaa9dac 100644 --- a/IO/XML/Testing/Cxx/TestXMLReaderBadData.cxx +++ b/IO/XML/Testing/Cxx/TestXMLReaderBadData.cxx @@ -18,24 +18,6 @@ #include #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 TestXMLReaderBadData(int argc, char* argv[]) { // Verify input arguments @@ -64,7 +46,6 @@ int TestXMLReaderBadData(int argc, char* argv[]) reader->SetReaderErrorObserver(errorObserver1); reader->SetParserErrorObserver(errorObserver2); reader->Update(); - CHECK_ERROR_MSG(errorObserver2, - "vtkXMLDataParser"); - return EXIT_SUCCESS; + int status = errorObserver2->CheckErrorMessage("vtkXMLDataParser"); + return status; } diff --git a/Interaction/Widgets/Testing/Cxx/vtkSeedRepresentationTest1.cxx b/Interaction/Widgets/Testing/Cxx/vtkSeedRepresentationTest1.cxx index 05de88b7120..fb14d3acb50 100644 --- a/Interaction/Widgets/Testing/Cxx/vtkSeedRepresentationTest1.cxx +++ b/Interaction/Widgets/Testing/Cxx/vtkSeedRepresentationTest1.cxx @@ -27,24 +27,6 @@ #include "vtkTextActor.h" #include "vtkPointHandleRepresentation3D.h" -#define CHECK_ERROR_MSG(observer, msg) \ - { \ - std::string expectedMsg(msg); \ - if (!observer->GetError()) \ - { \ - std::cout << "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 message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \ - } \ - } \ - } \ - observer->Clear() - int vtkSeedRepresentationTest1(int , char * [] ) { vtkSmartPointer< vtkSeedRepresentation > node1 = vtkSmartPointer< vtkSeedRepresentation >::New(); @@ -63,11 +45,11 @@ int vtkSeedRepresentationTest1(int , char * [] ) node1->AddObserver(vtkCommand::ErrorEvent, errorObserver); node1->SetSeedDisplayPosition(s, pos); - CHECK_ERROR_MSG(errorObserver, "Trying to access non-existent handle"); + int status = errorObserver->CheckErrorMessage("Trying to access non-existent handle"); node1->GetSeedWorldPosition(s, pos2); - CHECK_ERROR_MSG(errorObserver, "Trying to access non-existent handle"); + status += errorObserver->CheckErrorMessage("Trying to access non-existent handle"); node1->GetSeedDisplayPosition(s,pos); - CHECK_ERROR_MSG(errorObserver, "Trying to access non-existent handle"); + status += errorObserver->CheckErrorMessage("Trying to access non-existent handle"); // set/get display and world position will fail without seeds having been // created, so add some and then do the testing of return values. diff --git a/Testing/Core/vtkTestErrorObserver.h b/Testing/Core/vtkTestErrorObserver.h index 9e587565bac..a67c6a559aa 100644 --- a/Testing/Core/vtkTestErrorObserver.h +++ b/Testing/Core/vtkTestErrorObserver.h @@ -69,10 +69,66 @@ class ErrorObserver : public ::vtkCommand { return ErrorMessage; } + std::string GetWarningMessage() { return WarningMessage; } + + /** + * Check to see if an error or warning message exists. + * Given an observer, a message and a status with an initial value, + * Returns 1 if an error does not exist, or if msg is not contained + * in the error message. + * Returns 0 if the error exists and msg is contained in the error + * message. + * If the test fails, it reports the failing message, prepended with "ERROR:". + * ctest will detect the ERROR and report a failure. + */ + int CheckErrorMessage(const std::string &expectedMsg) + { + if (!this->GetError()) + { + std::cout << "ERROR: Failed to catch any error. Expected the error message to contain \"" + << expectedMsg << std::endl; + return 1; + } + else + { + std::string gotMsg(this->GetErrorMessage()); + if (gotMsg.find(expectedMsg) == std::string::npos) + { + std::cout << "ERROR: Error message does not contain \"" << expectedMsg + << "\" got \n\"" << gotMsg << std::endl; + return 1; + } + } + this->Clear(); + return 0; + } + + int CheckWarningMessage(const std::string &expectedMsg) + { + if (!this->GetWarning()) + { + std::cout << "ERROR: Failed to catch any warning. Expected the warning message to contain \"" + << expectedMsg << std::endl; + return 1; + } + else + { + std::string gotMsg(this->GetWarningMessage()); + if (gotMsg.find(expectedMsg) == std::string::npos) + { + std::cout << "ERROR: Warning message does not contain \"" << expectedMsg + << "\" got \n\"" << gotMsg << std::endl; + return 1; + } + } + this->Clear(); + return 0; + } + private: bool Error; bool Warning;