00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #define _CRT_SECURE_NO_DEPRECATE
00012
00013 #include "ippCommandParserTestCase.h"
00014 #include "ippMemoryLeakDetector.h"
00015
00016 #include "ippdme/Parser/ippCommandParser.h"
00017 #include "ippdme/Command/ippCommand.h"
00018 #include "ippdme/ippCommandNameType.h"
00019
00020 #include "ippdme/ippError.h"
00021 #include "ippUtest.h"
00022 #include "ippTestFolder.h"
00023
00024 #ifdef GetProp
00025 #undef GetProp
00026 #endif
00027
00028 namespace CxxTest {
00029
00030
00031 CXXTEST_TEMPLATE_INSTANTIATION
00032 class ValueTraits<ippParserCmdErrorId>
00033 {
00034 ippParserCmdErrorId _t;
00035 std::ostringstream _s;
00036 public:
00037 ValueTraits(ippParserCmdErrorId t )
00038 :_t(t)
00039 {
00040 _s << getIppErr(_t).asInteger() << std::endl;
00041 }
00042 ValueTraits( const ValueTraits<ippParserCmdErrorId>& t ) ;
00043 const char *asString( void ) const {
00044 return toString(_t) ;
00045 }
00046 };
00047
00048
00049
00050 CXXTEST_TEMPLATE_INSTANTIATION
00051 class ValueTraits<ippCommandNameType>
00052 {
00053 ippCommandNameType _t;
00054 public:
00055 ValueTraits( ippCommandNameType t )
00056 :_t(t)
00057 { }
00058 ValueTraits( const ValueTraits<ippCommandNameType>& t ) ;
00059 const char *asString( void ) const { return getCommandNameString(_t); }
00060 };
00061
00062 }
00063
00064
00065
00066
00067 #define IPP_END_STRING "\r\n"
00068
00069 void ippCommandParserTestCase::setUp()
00070 {
00071
00072
00073
00074 }
00075 void ippCommandParserTestCase::tearDown()
00076 {
00077 }
00078
00079
00080 void ippCommandParserTestCase::test1 ()
00081 {
00082 ippMemoryLeakDetector _leakDetector;
00083
00084 ippCommandParser cmdParser;
00085
00086 ippCommandConstPtr pCommand;
00087
00088 cmdParser.setInput("00001 StartSession()"IPP_END_STRING);
00089 cmdParser.parseTag();
00090 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 1);
00091 pCommand = cmdParser.parseCommand();
00092 IPP_UTEST_ASSERT_EQUALS(pCommand->getCommandName(), StartSession);
00093
00094 cmdParser.setInput("00099 EndSession()"IPP_END_STRING);
00095 cmdParser.parseTag();
00096 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 99);
00097 pCommand = cmdParser.parseCommand();
00098 IPP_UTEST_ASSERT_EQUALS(pCommand->getCommandName(), EndSession);
00099
00100 }
00101
00102
00103 void ippCommandParserTestCase::testInvalidCommands()
00104 {
00105 ippMemoryLeakDetector _leakDetector;
00106
00107 ippCommandParser cmdParser;
00108
00109 ippCommandPtr pCommand=NULL;
00110
00111
00112 cmdParser.setInput("00001 StartSession(23.0)"IPP_END_STRING);
00113 cmdParser.parseTag();
00114 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 1);
00115 pCommand = cmdParser.parseCommand();
00116 IPP_UTEST_ASSERT(!pCommand);
00117 IPP_UTEST_ASSERT_EQUALS(cmdParser.getParserErr(),MUST_HAVE_NO_ARGUMENTS);
00118
00119
00120 cmdParser.setInput("00001 EndSession(\"a\")"IPP_END_STRING);
00121 cmdParser.parseTag();
00122 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 1);
00123 pCommand = cmdParser.parseCommand();
00124 IPP_UTEST_ASSERT(!pCommand);
00125 IPP_UTEST_ASSERT_EQUALS(cmdParser.getParserErr(),MUST_HAVE_NO_ARGUMENTS);
00126
00127
00128 cmdParser.setInput("00001 OnPtMeasReport(X,Y)"IPP_END_STRING);
00129 cmdParser.parseTag();
00130 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 1);
00131 pCommand = cmdParser.parseCommand();
00132 IPP_UTEST_ASSERT(!pCommand);
00133 IPP_UTEST_ASSERT_EQUALS(cmdParser.getParserErr(),BAD_ARGUMENTS);
00134
00135
00136 cmdParser.setInput("00001 OnPtMeasReport(X(),X())"IPP_END_STRING);
00137 cmdParser.parseTag();
00138 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 1);
00139 pCommand = cmdParser.parseCommand();
00140 IPP_UTEST_ASSERT(!pCommand);
00141 IPP_UTEST_ASSERT_EQUALS(cmdParser.getParserErr(),X_ARGUMENT_USED_TWICE);
00142
00143
00144 cmdParser.setInput("00001 OnPtMeasReport()"IPP_END_STRING);
00145 cmdParser.parseTag();
00146 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 1);
00147 pCommand = cmdParser.parseCommand();
00148 IPP_UTEST_ASSERT(!pCommand);
00149 IPP_UTEST_ASSERT_EQUALS(cmdParser.getParserErr(),BAD_ARGUMENTS);
00150
00151 cmdParser.setInput("00001 OnPtMeasReport(X(),Y,)"IPP_END_STRING);
00152 cmdParser.parseTag();
00153 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 1);
00154 pCommand = cmdParser.parseCommand();
00155 IPP_UTEST_ASSERT(!pCommand);
00156 IPP_UTEST_ASSERT_EQUALS(cmdParser.getParserErr(),BAD_ARGUMENTS);
00157
00158 }
00159
00160 void ippCommandParserTestCase::testOnMoveReportE()
00161 {
00162 ippMemoryLeakDetector _leakDetector;
00163
00164 ippCommandParser cmdParser;
00165
00166 ippCommandPtr pCommand=NULL;
00167
00168 cmdParser.setInput("E0025 OnMoveReportE(Y(),Time(0.5))"IPP_END_STRING);
00169 pCommand = cmdParser.parseCommand();
00170 IPP_UTEST_ASSERT(pCommand);
00171 IPP_UTEST_ASSERT_EQUALS(cmdParser.getParserErr(),OK);
00172
00173 }
00174 void ippCommandParserTestCase::testOnPtMeas()
00175 {
00176 ippMemoryLeakDetector _leakDetector;
00177
00178 ippCommandParser cmdParser;
00179
00180 ippCommandPtr pCommand=NULL;
00181
00182
00183 cmdParser.setInput("00025 PtMeas(X(1.0),Y(2.))"IPP_END_STRING);
00184 pCommand = cmdParser.parseCommand();
00185 IPP_UTEST_ASSERT(pCommand);
00186 IPP_UTEST_ASSERT_EQUALS(cmdParser.getParserErr(),OK);
00187
00188
00189 cmdParser.setInput("00025 PtMeas(X(1.0),Y(2.),IJK(0.,1.,2.))"IPP_END_STRING);
00190 pCommand = cmdParser.parseCommand();
00191 IPP_UTEST_ASSERT(pCommand);
00192 IPP_UTEST_ASSERT_EQUALS(cmdParser.getParserErr(),OK);
00193
00194
00195 cmdParser.setInput("00025 PtMeas(X(1.0),IJK(0.,1.,2.),Y(2.))"IPP_END_STRING);
00196 pCommand = cmdParser.parseCommand();
00197 IPP_UTEST_ASSERT(pCommand);
00198 IPP_UTEST_ASSERT_EQUALS(cmdParser.getParserErr(),OK);
00199 }
00200
00201 void ippCommandParserTestCase::testOnPtMeasReport()
00202 {
00203 ippMemoryLeakDetector _leakDetector;
00204
00205 ippCommandParser cmdParser;
00206
00207 ippCommandPtr pCommand=NULL;
00208
00209 cmdParser.setInput("00001 OnPtMeasReport(Y())"IPP_END_STRING);
00210 cmdParser.parseTag();
00211 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 1);
00212 pCommand = cmdParser.parseCommand();
00213 IPP_UTEST_ASSERT(pCommand);
00214 IPP_UTEST_ASSERT_EQUALS(cmdParser.getParserErr(),OK);
00215
00216
00217 cmdParser.setInput("00001 OnPtMeasReport(Y(),X())"IPP_END_STRING);
00218 cmdParser.parseTag();
00219 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 1);
00220 pCommand = cmdParser.parseCommand();
00221 IPP_UTEST_ASSERT(pCommand);
00222 IPP_UTEST_ASSERT_EQUALS(cmdParser.getParserErr(),OK);
00223
00224
00225 cmdParser.setInput("00001 OnPtMeasReport(Y(),Tool.B())"IPP_END_STRING);
00226 cmdParser.parseTag();
00227 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 1);
00228 pCommand = cmdParser.parseCommand();
00229 IPP_UTEST_ASSERT(pCommand);
00230 IPP_UTEST_ASSERT_EQUALS(cmdParser.getParserErr(),OK);
00231
00232
00233 cmdParser.setInput("00001 OnPtMeasReport(Tool.B(),Y())"IPP_END_STRING);
00234 cmdParser.parseTag();
00235 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 1);
00236 pCommand = cmdParser.parseCommand();
00237 IPP_UTEST_ASSERT(pCommand);
00238 IPP_UTEST_ASSERT_EQUALS(cmdParser.getParserErr(),OK);
00239 }
00240
00241 void ippCommandParserTestCase::testGetProp()
00242 {
00243 ippCommandParser cmdParser;
00244
00245 {
00246
00247 cmdParser.setInput("00060 GetProp(Tool.PtMeasPar.Approach(), Tool.PtMeasPar.Retract(), Tool.PtMeasPar.Search())"IPP_END_STRING);
00248 cmdParser.parseTag();
00249 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 60);
00250 ippCommandPtr command= cmdParser.parseCommand();
00251 IPP_UTEST_ASSERT_EQUALS(command->getCommandName(), ipp::GetProp);
00252 }
00254 {
00255 cmdParser.setInput("00025 GetProp(Tool.X.Accel())\r\n");
00256 ippCommandPtr command= cmdParser.parseCommand();
00257 IPP_UTEST_ASSERT(!command);
00258 }
00259
00260
00261 }
00262 #include "ippdme/Command/ippGoToCommand.h"
00263
00264 void ippCommandParserTestCase::testCommandWithArguments()
00265 {
00266 ippMemoryLeakDetector _leakDetector;
00267
00268 ippCommandParser cmdParser;
00269
00270 ippCommandPtr pCommand=NULL;
00271
00272 cmdParser.setInput("00070 GoTo(X(20), Y(40), Z(60))"IPP_END_STRING);
00273 cmdParser.parseTag();
00274 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 70);
00275 pCommand = cmdParser.parseCommand();
00276 IPP_UTEST_ASSERT_EQUALS(pCommand->getCommandName(), ipp::GoTo);
00277 ippGoToCommandPtr pGotoCommand = static_cast<ippGoToCommand*>(pCommand.get());
00278 IPP_UTEST_ASSERT_EQUALS(pGotoCommand->getX() ,20.0)
00279 IPP_UTEST_ASSERT_EQUALS(pGotoCommand->getY() ,40.0)
00280 IPP_UTEST_ASSERT_EQUALS(pGotoCommand->getZ() ,60.0)
00281
00282 cmdParser.setInput("00040 SetProp(Tool.GoToPar.Accel(50.0))"IPP_END_STRING);
00283 cmdParser.parseTag();
00284 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 40);
00285 pCommand = cmdParser.parseCommand();
00286 IPP_UTEST_ASSERT_EQUALS(pCommand->getCommandName(), ipp::SetProp );
00287
00288 }
00289
00290 void ippCommandParserTestCase::testScanOnCurve_BadFormat()
00291 {
00292 ippMemoryLeakDetector _leakDetector;
00293 ippCommandParser cmdParser;
00294 {
00295
00296
00297 ippCommandPtr pCommand;
00298
00299 cmdParser.setInput("00070 ScanOnCurve(Closed(0),"
00300 "Format(X(),Y(),Z(),wrong,stuff),"
00301 "Data(10.0))"IPP_END_STRING);
00302 cmdParser.parseTag();
00303 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 70);
00304 pCommand = cmdParser.parseCommand();
00305 IPP_UTEST_ASSERT(!pCommand);
00306 IPP_UTEST_ASSERT_EQUALS(BAD_SYNTAX_FOR_FORMAT_IN_SCANONCURVE,cmdParser.getParserErr());
00307 }
00308 }
00309
00310 void ippCommandParserTestCase::testScanOnCurve_Format1_OK()
00311 {
00312 ippMemoryLeakDetector _leakDetector;
00313 ippCommandParser cmdParser;
00314
00315 ippCommandPtr pCommand;
00316 cmdParser.setInput("00070 ScanOnCurve(Closed(0),"
00317 "Format(X(),Y(),Z(),IJK(),tag),"
00318 "Data(1.,2.,3.,0.,0.,1.,555,1.,2.,3.,0.,0.,1.,666))"IPP_END_STRING);
00319 cmdParser.parseTag();
00320 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 70);
00321 pCommand = cmdParser.parseCommand();
00322 IPP_UTEST_ASSERT(pCommand);
00323 if (!pCommand) return;
00324 IPP_UTEST_ASSERT_EQUALS(pCommand->getCommandName(), ipp::ScanOnCurve);
00325 }
00326
00327 void ippCommandParserTestCase::testScanOnCurve_Format1_BadData()
00328 {
00329 ippMemoryLeakDetector _leakDetector;
00330 ippCommandParser cmdParser;
00331
00332 ippCommandPtr pCommand;
00333 cmdParser.setInput("00070 ScanOnCurve(Closed(0),"
00334 "Format(X(),Y(),Z(),IJK(),tag,pi,pj,pk),"
00335 "Data(1., 2., 2. , 0,0,1, 555,0,0,1,"
00336 "1., 2., 2. , 0,0,1, 555,0,0,1,0,0,0"
00337 "))"IPP_END_STRING);
00338 cmdParser.parseTag();
00339 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 70);
00340 pCommand = cmdParser.parseCommand();
00341 IPP_UTEST_ASSERT(!pCommand);
00342 IPP_UTEST_ASSERT_EQUALS(BAD_NUMBER_OF_ARGUMENT_FOR_DATA_IN_SCANONCURVE,cmdParser.getParserErr());
00343 }
00344
00345 void ippCommandParserTestCase::testScanOnCurve_Format2_OK()
00346 {
00347 ippMemoryLeakDetector _leakDetector;
00348 ippCommandParser cmdParser;
00349
00350 ippCommandPtr pCommand;
00351 cmdParser.setInput("00070 ScanOnCurve(Closed(0),"
00352 "Format(X(),Y(),Z(),IJK(),tag,pi,pj,pk),"
00353 "Data(1.,2.,3.,0.,0.,1.,3.,4.,5.,555,1.,2.,3.,0.,0.,1.,3.,4.,5.,666))"IPP_END_STRING);
00354 cmdParser.parseTag();
00355 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 70);
00356 pCommand = cmdParser.parseCommand();
00357 IPP_UTEST_ASSERT(pCommand);
00358 if (!pCommand) return;
00359 IPP_UTEST_ASSERT_EQUALS(pCommand->getCommandName(), ipp::ScanOnCurve);
00360 }
00361
00362 void ippCommandParserTestCase::testScanOnCurve_Format2_BadData()
00363 {
00364 ippMemoryLeakDetector _leakDetector;
00365 ippCommandParser cmdParser;
00366
00367 ippCommandPtr pCommand;
00368 cmdParser.setInput("00070 ScanOnCurve(Closed(0),"
00369 "Format(X(),Y(),Z(),IJK(),tag,pi,pj,pk),"
00370 "Data(1.,2.,3.,0.,0.,1.,3.,4.,5.,555,1.,2.,3.,0.,0.,1.,3.,4.,5.,666,99999,99999))"IPP_END_STRING);
00371 cmdParser.parseTag();
00372 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 70);
00373 pCommand = cmdParser.parseCommand();
00374 IPP_UTEST_ASSERT(!pCommand);
00375 IPP_UTEST_ASSERT_EQUALS(BAD_NUMBER_OF_ARGUMENT_FOR_DATA_IN_SCANONCURVE,cmdParser.getParserErr());
00376 }
00377
00378 void ippCommandParserTestCase::testScanOnCurve_Format3_OK()
00379 {
00380 ippMemoryLeakDetector _leakDetector;
00381 ippCommandParser cmdParser;
00382
00383 ippCommandPtr pCommand;
00384 cmdParser.setInput("00070 ScanOnCurve(Closed(0),"
00385 "Format(X(),Y(),Z(),IJK(),tag,pi,pj,pk,si,sj,sk),"
00386 "Data(1.,2.,3.,0.,0.,1.,3.,4.,5.,6.,7.,8.,555,1.,2.,3.,0.,0.,1.,3.,4.,5.,6.,7.,8.,666))"IPP_END_STRING);
00387 cmdParser.parseTag();
00388 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 70);
00389 pCommand = cmdParser.parseCommand();
00390 IPP_UTEST_ASSERT(pCommand);
00391 if (!pCommand) return;
00392 IPP_UTEST_ASSERT_EQUALS(pCommand->getCommandName(), ipp::ScanOnCurve);
00393 }
00394
00395 void ippCommandParserTestCase::testScanOnCurve_Format3_BadData()
00396 {
00397 ippMemoryLeakDetector _leakDetector;
00398 ippCommandParser cmdParser;
00399
00400 ippCommandPtr pCommand;
00401 cmdParser.setInput("00070 ScanOnCurve(Closed(0),"
00402 "Format(X(),Y(),Z(),IJK(),tag,pi,pj,pk,si,sj,sk),"
00403 "Data(1.,2.,3.,0.,0.,1.,3.,4.,5.,6.,7.,8.,555,1.,2.,3.,0.,0.,1.,3.,4.,5.,6.,7.,8.,666,99999,99999))"IPP_END_STRING);
00404 cmdParser.parseTag();
00405 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 70);
00406 pCommand = cmdParser.parseCommand();
00407 IPP_UTEST_ASSERT(!pCommand);
00408 IPP_UTEST_ASSERT_EQUALS(BAD_NUMBER_OF_ARGUMENT_FOR_DATA_IN_SCANONCURVE,cmdParser.getParserErr());
00409 }
00410
00411 void ippCommandParserTestCase::testScanOnCurve_Format1_very_long_input()
00412 {
00413 ippMemoryLeakDetector _leakDetector;
00414 ippCommandParser cmdParser;
00415
00416 ippCommandPtr pCommand;
00417 cmdParser.setInput("00070 ScanOnCurve(Closed(0),"
00418 "Format(X(),Y(),Z(),IJK(),tag),"
00419 "Data(1.,2.,3.,0.,0.,1.,555,"
00420 "1.,2.,3.,0.,0.,1.,600,"
00421 "1.,2.,3.,0.,0.,1.,601,"
00422 "1.,2.,3.,0.,0.,1.,602,"
00423 "1.,2.,3.,0.,0.,1.,603,"
00424 "1.,2.,3.,0.,0.,1.,604,"
00425 "1.,2.,3.,0.,0.,1.,605,"
00426 "1.,2.,3.,0.,0.,1.,606,"
00427 "1.,2.,3.,0.,0.,1.,607,"
00428 "1.,2.,3.,0.,0.,1.,608,"
00429 "1.,2.,3.,0.,0.,1.,609,"
00430 "1.,2.,3.,0.,0.,1.,610,"
00431 "1.,2.,3.,0.,0.,1.,611,"
00432 "1.,2.,3.,0.,0.,1.,612,"
00433 "1.,2.,3.,0.,0.,1.,613,"
00434 "1.,2.,3.,0.,0.,1.,614,"
00435 "1.,2.,3.,0.,0.,1.,615,"
00436 "1.,2.,3.,0.,0.,1.,616,"
00437 "1.,2.,3.,0.,0.,1.,617,"
00438 "1.,2.,3.,0.,0.,1.,618,"
00439 "1.,2.,3.,0.,0.,1.,619,"
00440 "1.,2.,3.,0.,0.,1.,620,"
00441 "1.,2.,3.,0.,0.,1.,621,"
00442 "1.,2.,3.,0.,0.,1.,622,"
00443 "1.,2.,3.,0.,0.,1.,623,"
00444 "1.,2.,3.,0.,0.,1.,624,"
00445 "1.,2.,3.,0.,0.,1.,625,"
00446 "1.,2.,3.,0.,0.,1.,626,"
00447 "1.,2.,3.,0.,0.,1.,627,"
00448 "1.,2.,3.,0.,0.,1.,628,"
00449 "1.,2.,3.,0.,0.,1.,629,"
00450 "1.,2.,3.,0.,0.,1.,630,"
00451 "1.,2.,3.,0.,0.,1.,631,"
00452 "1.,2.,3.,0.,0.,1.,632,"
00453 "1.,2.,3.,0.,0.,1.,633,"
00454 "1.,2.,3.,0.,0.,1.,634,"
00455 "1.,2.,3.,0.,0.,1.,635,"
00456 "1.,2.,3.,0.,0.,1.,636,"
00457 "1.,2.,3.,0.,0.,1.,637,"
00458 "1.,2.,3.,0.,0.,1.,638,"
00459 "1.,2.,3.,0.,0.,1.,639,"
00460
00461 "1.,2.,3.,0.,0.,1.,640,"
00462 "1.,2.,3.,0.,0.,1.,641,"
00463 "1.,2.,3.,0.,0.,1.,642,"
00464 "1.,2.,3.,0.,0.,1.,643,"
00465 "1.,2.,3.,0.,0.,1.,644,"
00466 "1.,2.,3.,0.,0.,1.,645,"
00467 "1.,2.,3.,0.,0.,1.,646,"
00468 "1.,2.,3.,0.,0.,1.,647,"
00469 "1.,2.,3.,0.,0.,1.,648,"
00470 "1.,2.,3.,0.,0.,1.,649,"
00471
00472 "1.,2.,3.,0.,0.,1.,650,"
00473 "1.,2.,3.,0.,0.,1.,651,"
00474 "1.,2.,3.,0.,0.,1.,652,"
00475 "1.,2.,3.,0.,0.,1.,653,"
00476 "1.,2.,3.,0.,0.,1.,654,"
00477 "1.,2.,3.,0.,0.,1.,655,"
00478 "1.,2.,3.,0.,0.,1.,656,"
00479 "1.,2.,3.,0.,0.,1.,657,"
00480 "1.,2.,3.,0.,0.,1.,658,"
00481 "1.,2.,3.,0.,0.,1.,659,"
00482
00483 "1.,2.,3.,0.,0.,1.,666))"IPP_END_STRING);
00484 cmdParser.parseTag();
00485 IPP_UTEST_ASSERT_EQUALS(cmdParser.getTag(), 70);
00486 pCommand = cmdParser.parseCommand();
00487 IPP_UTEST_ASSERT(pCommand);
00488 if (!pCommand) return;
00489 IPP_UTEST_ASSERT_EQUALS(pCommand->getCommandName(), ipp::ScanOnCurve);
00490 }
00491
00492
00493
00494
00495
00496
00497 #include <fstream>
00498 bool _verbose = false;
00499 void TestCommandsOnFile(
00500 LPCTSTR filename,
00501 int expected_parsing_error = 0
00502 )
00503 {
00504
00505 int counter = 0;
00506
00507 const int IPP_MAXSTRINGSIZE = 65535;
00508 char buf[IPP_MAXSTRINGSIZE];
00509
00510
00511
00512 std::ifstream input;
00513 input.open(filename);
00514 IPP_UTEST_ASSERT(!input.bad());
00515 if (input.bad()) return;
00516 int line =0;
00517 while(!input.eof()) {
00518 std::string str;
00519 input.getline(buf,IPP_MAXSTRINGSIZE);
00520
00521 line++;
00522 size_t l = strlen(buf);
00523 buf[l] =13;
00524 buf[l+1] =10;
00525 buf[l+2] =0;
00526
00527 str = buf;
00528 if (str.find("\\")==0 || str.find(":")==0 || str.length()==2) {
00529 } else {
00530
00531 ippMemoryLeakDetector _leakDetector;
00532
00533 ippCommandParser cmdParser;
00534
00535 cmdParser.setInput(str.c_str());
00536 ippCommandPtr command = cmdParser.parseCommand();
00537
00538 if (expected_parsing_error>0){
00539 if (!command.get()) {
00540 counter++;
00541
00542 if (0 && _verbose) {
00543 std::cout << filename <<"(" << line << ")" << std::endl;
00544 std::cout << " parsing : " << str.c_str() << std::endl;
00545 std::cout << " Error : " << cmdParser.getErrorMessageString() << std::endl;
00546 }
00547 } else {
00548 if (command->getCommandName() !=ClearAllErrors && _verbose) {
00549 std::cout << filename <<"(" << line << ")" << std::endl;
00550 std::cout << " parsing : " << str.c_str() << std::endl;
00551 std::cout << " Error : " << cmdParser.getErrorMessageString() << std::endl;
00552 }
00553 }
00554 } else {
00555 IPP_UTEST_ASSERT(command.get());
00556 if (!command.get()) {
00557
00558 std::cout << filename <<"(" << line << ")" << std::endl;
00559 std::cout << " parsing : " << str.c_str() << std::endl;
00560 std::cout << " Error : " << cmdParser.getErrorMessageString() << std::endl;
00561 }
00562 }
00563
00564 }
00565 }
00566 if (expected_parsing_error) {
00567 IPP_UTEST_ASSERT_EQUALS(expected_parsing_error,counter);
00568 if (counter!= expected_parsing_error ){
00569 std::cout << filename <<"(" << line << ")" << std::endl;
00570 }
00571 }
00572 }
00573
00574
00575
00576 void ippCommandParserTestCase::testOnSamplePRGFileI()
00577 {
00578
00579 ippTestFolder folder;
00580 bool bSuccess = folder.find_first_file(test_file_folder().c_str(),"*.prg");
00581 IPP_UTEST_ASSERT(bSuccess);
00582
00583 while(bSuccess) {
00584
00585 std::string filename = folder.current_filename();
00586
00587 if (filename.find("checkerCmdErrors.prg")!=std::string::npos ) {
00588 TestCommandsOnFile(filename.c_str(),1);
00589 } else if (filename.find("parserCmdErrors.prg")!=std::string::npos ) {
00590 TestCommandsOnFile(filename.c_str(),260);
00591 } else if (filename.find("numbersErrorCmd.prg")!=std::string::npos ) {
00592 TestCommandsOnFile(filename.c_str(),7);
00593 } else {
00594 TestCommandsOnFile(filename.c_str());
00595 }
00596
00597 bSuccess = folder.next();
00598 }
00599 }
00600
00601
00602