Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ippResponseParserTestCase.cpp

Go to the documentation of this file.
00001 #include "ippResponseParserTestCase.h"
00002 #include "ippdme/Parser/ippResponseParser.h"
00003 #include "ippdme/Response/ippSetPropEResponse.h"
00004 #include "ippdme/Response/ippGetPropResponse.h"
00005 #include "ippTestFolder.h"
00006 #include "ippMemoryLeakDetector.h"
00007 #include <fstream>
00008 
00009 CXXTEST_ENUM_TRAITS( ippResponseNameType,
00010                      CXXTEST_ENUM_MEMBER( ippResponseNameType_ERROR)
00011                      CXXTEST_ENUM_MEMBER( Ack )
00012                      CXXTEST_ENUM_MEMBER( Complete )
00013                      CXXTEST_ENUM_MEMBER( DataAlign )
00014                      CXXTEST_ENUM_MEMBER( DataCenterPart )
00015                      CXXTEST_ENUM_MEMBER( DataChangeToolE )
00016                      CXXTEST_ENUM_MEMBER( DataEnumProp )
00017                      CXXTEST_ENUM_MEMBER( DataGetChangeToolAction )
00018                      CXXTEST_ENUM_MEMBER( DataGetCoordSystem )
00019                      CXXTEST_ENUM_MEMBER( DataGetCsyTransformation )
00020                      CXXTEST_ENUM_MEMBER( DataGetDMEVersion )
00021                      CXXTEST_ENUM_MEMBER( DataGetErrStatusE )
00022                      CXXTEST_ENUM_MEMBER( DataGetMachineClass )
00023                      CXXTEST_ENUM_MEMBER( DataGetProp )
00024                      CXXTEST_ENUM_MEMBER( DataGoToE )
00025                      CXXTEST_ENUM_MEMBER( DataIsHomed )
00026                      CXXTEST_ENUM_MEMBER( DataIsUserEnabled )
00027                      CXXTEST_ENUM_MEMBER( DataKeyPressE )
00028                      CXXTEST_ENUM_MEMBER( DataOnMoveReportE )
00029                      CXXTEST_ENUM_MEMBER( DataPtMeasOrGet )
00030                      CXXTEST_ENUM_MEMBER( DataPtMeasE )
00031                      CXXTEST_ENUM_MEMBER( DataScan )
00032                      CXXTEST_ENUM_MEMBER( DataSetPropE )
00033                      CXXTEST_ENUM_MEMBER( DataString )
00034                      CXXTEST_ENUM_MEMBER( DataTiltCenterPart )
00035                      CXXTEST_ENUM_MEMBER( DataTiltPart )
00036                      CXXTEST_ENUM_MEMBER( ErrorError )
00037                      CXXTEST_ENUM_MEMBER( ippResponseNameType_MAXVALUE));
00038 
00039 void TestResponsesOnFile(
00040   LPCTSTR filename,
00041   int expected_parsing_error = 0
00042  )
00043 {
00044 
00045   int counter = 0;
00046   
00047   const int IPP_MAXSTRINGSIZE = 65535;
00048   char buf[IPP_MAXSTRINGSIZE];
00049  
00050   //xx std::cout << "parsing file : " << filename  << std::endl;
00051 
00052   std::ifstream input;
00053   input.open(filename);
00054   IPP_UTEST_ASSERT(!input.bad());
00055   if (input.bad()) return;
00056 
00057   while(!input.eof()) {
00058 
00059     std::string str;
00060     input.getline(buf,IPP_MAXSTRINGSIZE);
00061 
00062     size_t l = strlen(buf);
00063     buf[l] =13;
00064     buf[l+1] =10;
00065     buf[l+2] =0;
00066 
00067     str = buf;
00068     if (str.find("\\")==0 || str.find(":")==0 || str.length()==2) {
00069     } else {
00070 
00071       ippMemoryLeakDetector _leakDetector;
00072 
00073       ippResponseParser responseParser;
00074 
00075       responseParser.setInput(str.c_str());
00076       ippResponsePtr response = responseParser.parseResponse();
00077       
00078       if (expected_parsing_error>0){ 
00079         if (!response.get()) {
00080           counter++; // we just want to record  the number of failure in this case
00081         } else {
00082           //xx if(response->getResponseName() != Ack && response->getResponseName() != Complete) {
00083           //xx   std::cout << " success with " << str.c_str() << std::endl; 
00084           //xx }
00085         }
00086       } else {
00087         IPP_UTEST_ASSERT(response.get());
00088         if (!response.get()) {
00089           // 
00090           std::cout << " filename : " << filename << std::endl;
00091           std::cout << " parsing  : " << str.c_str() << std::endl;
00092           std::cout << " Error    : " << responseParser.getErrorMessageString() << std::endl;
00093         }
00094     }
00095 
00096     }
00097   }
00098   if (expected_parsing_error) { 
00099     if (expected_parsing_error!=counter) {
00100       std::cout << "parsing file : " << filename  << std::endl;
00101     }
00102     IPP_UTEST_ASSERT_EQUALS(expected_parsing_error,counter);
00103   }
00104 }
00105 
00106 void ippResponseParserTestCase::testOnSampleResFile()
00107 {
00108   ippTestFolder folder;
00109   bool bSuccess = folder.find_first_file(test_file_folder().c_str(),"*.res");
00110   IPP_UTEST_ASSERT(bSuccess);
00111 
00112   while(bSuccess) {
00113     
00114     std::string filename = folder.current_filename();
00115 
00116     if (filename.find("checkerCmdErrors.res")!=std::string::npos ) { 
00117       TestResponsesOnFile(filename.c_str(),12);
00118     }  else if (filename.find("parserResErrors.res")!=std::string::npos  ) { 
00119       TestResponsesOnFile(filename.c_str(),129);
00120     } else if (filename.find("numbersErrorCmd.res")!=std::string::npos  ) { 
00121       TestResponsesOnFile(filename.c_str(),7);
00122     } else if (filename.find("numbersErrorRes.res")!=std::string::npos  ) { 
00123       TestResponsesOnFile(filename.c_str(),7);
00124     } else {
00125       TestResponsesOnFile(filename.c_str());
00126     }
00127 
00128     bSuccess = folder.next();
00129   }
00130 
00131 }
00132 
00133 void ippResponseParserTestCase::testOnMoveReportE()
00134 {
00135   ippMemoryLeakDetector _leakDetector;
00136 
00137   ippResponseParser responseParser;
00138 
00139   responseParser.setInput("E0010 # R(0),X(1),Y(2),Z(3),Tool.A(4),Tool.B(5),Tool.C(6)\r\n");
00140   ippResponsePtr response = responseParser.parseResponse();
00141   IPP_UTEST_ASSERT(response.get());
00142   IPP_UTEST_ASSERT_EQUALS(DataOnMoveReportE,response->getResponseName());
00143   
00144 }
00145 
00146 void ippResponseParserTestCase::testOnMoveReportE_bad_string()
00147 {
00148   ippMemoryLeakDetector _leakDetector;
00149 
00150   ippResponseParser responseParser;
00151   // the input string has a unexpected comma at the end : parsing should fail
00152   responseParser.setInput("E0010 # X(3), Y(4) ,\r\n");
00153   ippResponsePtr response = responseParser.parseResponse();
00154   IPP_UTEST_ASSERT(!response.get());
00155   
00156   // the input string has no comma between the two arguments
00157   responseParser.setInput("E0010 # X(3) Y(4)\r\n");
00158   response = responseParser.parseResponse();
00159   IPP_UTEST_ASSERT(!response.get());
00160 }
00161 
00162 void ippResponseParserTestCase::testPtMeas()
00163 {
00164   ippMemoryLeakDetector _leakDetector;
00165 
00166   ippResponseParser responseParser;
00167 
00168   responseParser.setInput("E0000 # PtMeas(Z(+.197),X(-2.6),Y(0.78),Tool.A(90),Tool.B(0),Tool.C(0),ER(4))\r\n");
00169   ippResponsePtr response = responseParser.parseResponse();
00170   IPP_UTEST_ASSERT_EQUALS(DataPtMeasE,response->getResponseName());
00171   IPP_UTEST_ASSERT(response.get());
00172 }
00173 
00174 void ippResponseParserTestCase::testSetPropEResponse()
00175 {
00176   ippMemoryLeakDetector _leakDetector;
00177   ippResponseParser responseParser;
00178 
00179   responseParser.setInput("E0000 # SetProp(Tool.GoToPar.Speed(55))\r\n");
00180   ippResponsePtr response = responseParser.parseResponse();
00181   IPP_UTEST_ASSERT(response.get());
00182   IPP_UTEST_ASSERT_EQUALS(DataSetPropE,response->getResponseName());
00183   
00184   responseParser.setInput("E0000 # SetProp(Tool.GoToPar.Speed.Act(55))\r\n");
00185   response = responseParser.parseResponse();
00186   IPP_UTEST_ASSERT(response.get());
00187   IPP_UTEST_ASSERT_EQUALS(DataSetPropE,response->getResponseName());
00188 
00189   responseParser.setInput("E0000 # SetProp(Part.Temperature(55))\r\n");
00190   response = responseParser.parseResponse();
00191   IPP_UTEST_ASSERT(response.get());
00192   IPP_UTEST_ASSERT_EQUALS(DataSetPropE,response->getResponseName());
00193 
00194 }
00195 
00196 void ippResponseParserTestCase::testSetPropEResponseMulti()
00197 {
00198   ippMemoryLeakDetector _leakDetector;
00199   ippResponseParser responseParser;
00200 
00201   responseParser.setInput("E0000 # SetProp(Tool.GoToPar.Speed(55), Part.Temperature(55), Tool.PtMeasPar.Accel(45.))\r\n");
00202   ippResponsePtr response = responseParser.parseResponse();
00203   
00204   IPP_UTEST_ASSERT(response.get());
00205   IPP_UTEST_ASSERT_EQUALS(DataSetPropE,response->getResponseName());
00206 
00207   ippSetPropEResponseConstPtr r = static_cast<ippSetPropEResponse*>(response.get());
00208   IPP_UTEST_ASSERT_EQUALS(3,r->getNumberProps());
00209 
00210 }
00211 
00212 void ippResponseParserTestCase::testSetPropEResponse_bad_string()
00213 {
00214   ippMemoryLeakDetector _leakDetector;
00215 
00216   ippResponseParser responseParser;
00217   // the input string has a missing closing parenthesis at the end=> parsing should fail
00218   responseParser.setInput("E0000 # SetProp(Tool.GoToPar.Speed.Act(2)\r\n");
00219   ippResponsePtr response = responseParser.parseResponse();
00220   IPP_UTEST_ASSERT(!response.get());
00221 
00222   responseParser.setInput("E0000 # SetProp(Tool.GoToPar.Speed.Act(2)FoundTool.GoToPar.Speed.Act(2))\r\n");
00223   response = responseParser.parseResponse();
00224   IPP_UTEST_ASSERT(!response.get());
00225 
00226   responseParser.setInput("E0000 # SetProp(Tool.GoToPar.Speed.Act(2),FoundTool.GoToPar.Speed.Act(2)\r\n");
00227   response = responseParser.parseResponse();
00228   IPP_UTEST_ASSERT(!response.get());
00229 }
00230 
00231 void ippResponseParserTestCase::testToolCollisionVolume()
00232 {
00233 
00234   ippMemoryLeakDetector _leakDetector;
00235 
00236   ippResponseParser responseParser;
00237   responseParser.setInput("00090 # Tool.CollisionVolume(OBB,150,10,530,50,50,500, 1,0,0, 0,1,0, 0,0,1)\r\n");
00238   ippResponsePtr response = responseParser.parseResponse();
00239   IPP_UTEST_ASSERT(response.get());
00240    
00241 
00242 }

Generated on Wed Nov 8 00:20:07 2006 for IPPDME by  doxygen 1.4.1