52 void doProgram(
const std::string& prog,
TaskContext*,
bool test=
true );
61 BOOST_REQUIRE( tc->start() );
62 tc->provides()->addService( sa );
63 tc->provides()->addAttribute(
"tvar_i", var_i);
64 tc->provides()->addAttribute(
"tss", tss);
65 tc->provides()->addConstant(
"tconst_i", const_i);
89 pg_list = parser.parseProgram( prog, tc );
95 if ( !pg_list.empty() )
103 string prog =
"program x { return \n }";
104 this->doProgram( prog, tc );
105 this->finishProgram( tc,
"x");
112 string prog =
"program x { not_exist = 10\n }";
115 BOOST_CHECK( pg_list.empty() );
116 BOOST_REQUIRE( tc->provides()->hasService(
"x") ==
false);
118 BOOST_CHECK( sa->runScript(prog) ==
false);
119 BOOST_REQUIRE( tc->provides()->hasService(
"x") ==
false);
125 string prog =
"tvar_i = 33\n program x { not_exist = 10\n } \n tvar_i = 66\n";
126 BOOST_CHECK( sa->eval(prog) ==
false);
127 BOOST_CHECK_EQUAL( var_i, 33 );
128 BOOST_REQUIRE( tc->provides()->hasService(
"x") ==
false);
136 string prog = string(
"/** This is the test_getProgramText to parse */\nprogram x { \n")
140 this->doProgram( prog, tc );
141 BOOST_CHECK_EQUAL( sa->getProgramText(
"x"), prog );
142 this->finishProgram( tc,
"x");
151 string prog = string(
"/** This is the test_getProgramText_runScript to parse */\nprogram x { \n")
155 string evaled = string(
"tvar_i = 33\n") + prog +
"tvar_i = 66\n";
157 BOOST_CHECK( sa->eval(evaled) ==
true);
158 BOOST_CHECK_EQUAL( sa->getProgramText(
"x"), evaled +
"\n" );
165 string prog = string(
"program x { \n")
167 +
" do test.assert( true )\n" 168 +
" do test.increase()\n" 169 +
" do test.resetI()\n" 170 +
" do test.assert( test.isTrue( true ) )\n" 171 +
" do test.assert( test.i == 0 )\n" 172 +
" do test.increase()\n" 173 +
" do test.assert( test.i == 1 )\n" 174 +
" do test.resetI()\n" 175 +
" do test.assert( test.i == 0 )\n" 176 +
" if test.increase() + test.increase() + test.increase() != 6 then \n " 177 +
" do test.assert( false )\n" 178 +
" do test.assert( test.isTrue( true ) )\n" 179 +
" do test.resetI()\n" 180 +
" do test.assert( test.i == 0 )\n" 181 +
" if test.increase() + test.increase() + test.increase() != 6 then \n " 182 +
" do test.assert( false )\n" 185 +
" do test.assert(false)" 188 this->doProgram( prog, tc );
189 this->finishProgram( tc,
"x");
195 string prog = string(
"program x { do test.fail();}");
197 this->doProgram( prog, tc,
false );
199 BOOST_CHECK( sa->getProgramStatus(
"x") == ProgramInterface::Status::error );
201 this->finishProgram( tc,
"x");
206 string prog = string(
"program x { \n")
207 +
"if test.isTrue(true) then \n" 208 +
" do test.good() \n" 210 +
" do test.fail() \n" 211 +
"if test.isTrue(false) then \n" 212 +
" do test.fail() \n" 214 +
" do test.good() \n" 215 +
"if test.isTrue(true) then \n" 216 +
" if test.isTrue(true) then \n" 217 +
" if test.isTrue(false) then \n" 218 +
" do test.fail() \n" 220 +
" if test.isTrue(false) then \n" 221 +
" do test.fail() \n" 223 +
" do test.good() \n" 225 +
" do test.fail() \n" 227 +
" do test.fail() \n" 228 +
"var bool trig = false \n" 229 +
"do test.resetI()\n" 230 +
"while test.increase() != 100 && !trig \n" 231 +
" if test.i == 50 then \n" 232 +
" set trig = true \n" 233 +
"if test.i != 51 then \n" 234 +
" do test.fail() \n" 235 +
"do test.resetI()\n" 236 +
"set trig = false\n" 237 +
"for (var int j = 0; j != 100 && !trig ; set j = test.increase() )\n" 238 +
" if j == 50 then \n" 239 +
" set trig = true \n" 244 this->doProgram( prog, tc );
245 this->finishProgram( tc,
"x");
251 string prog = string(
"program x { \n")
252 +
"do test.resetI()\n" 253 +
"while (test.increase() != 100)\n" 254 +
" if test.i == 50 then {\n" 256 +
" do test.fail() \n" 258 +
"if test.i != 50 then \n" 259 +
" do test.fail() \n" 260 +
"do test.resetI()\n" 261 +
"for (var int j = 0; j != 100 ; set j = test.increase() )\n" 262 +
" if j != 50 then \n" 266 +
" do test.fail() \n" 268 +
"if test.i != 50 then \n" 269 +
" do test.fail() \n" 270 +
"do test.resetI()\n" 271 +
"while test.increase() != 100 {\n" 272 +
" while test.increase() != 100 \n" 273 +
" if test.i == 50 then {\n" 275 +
" do test.fail() \n" 277 +
" if test.i != 50 then \n" 278 +
" do test.fail() \n" 279 +
" if test.i == 50 then \n" 281 +
" do test.fail() \n" 283 +
"if test.i != 50 then \n" 284 +
" do test.fail() \n" 287 this->doProgram( prog, tc );
288 this->finishProgram( tc,
"x");
294 string prog = string(
"program x { \n")
295 +
"do test.resetI()\n" 297 +
"while (test.increase() != 100) {\n" 299 +
"if test.i != 100 then \n" 300 +
" do test.fail() \n" 301 +
"do test.resetI()\n" 303 +
"while (test.increase() != 200) {\n" 304 +
" while (test.i < 100) {\n" 305 +
" test.increase()\n" 307 +
" if test.i < 100 then \n" 308 +
" do test.fail() \n" 310 +
"if test.i != 200 then \n" 311 +
" do test.fail() \n" 312 +
"do test.resetI()\n" 314 +
"for (var int j = 0; j != 100 ; j = test.increase() ) {\n" 316 +
"if test.i != 100 then \n" 317 +
" do test.fail() \n" 318 +
"if j != 100 then \n" 319 +
" do test.fail() \n" 320 +
"do test.resetI()\n" 322 +
"for ( j = 0; j != 100 ; j = test.increase() ) {\n" 323 +
" for (var int j2 = 0; j2 != 100 ; j2 = j2 + 1 ) {\n" 325 +
" if j2 != 100 then \n" 326 +
" do test.fail() \n" 328 +
"if test.i != 100 then \n" 329 +
" do test.fail() \n" 330 +
"if j != 100 then \n" 331 +
" do test.fail() \n" 332 +
"if j2 != 100 then \n" 333 +
" do test.fail() \n" 334 +
"do test.resetI()\n" 336 +
"while (test.increase() != 200) {\n" 337 +
" for (var int j3 = 0; j3 != 100 ; j3 = j3 + 1 ) {\n" 340 +
"if test.i != 200 then \n" 341 +
" do test.fail() \n" 342 +
"if j3 != 100 then \n" 343 +
" do test.fail() \n" 344 +
"do test.resetI()\n" 346 +
"while (test.increase() != 200) {\n" 347 +
" for (var int j3b = 0; j3b != 100 ; j3b = j3b + 1 ) {\n" 348 +
" if j3b == 50 then break \n" 350 +
" if j3b != 50 then \n" 351 +
" do test.fail() \n" 353 +
"if test.i != 200 then \n" 354 +
" do test.fail() \n" 355 +
"if j3b != 50 then \n" 356 +
" do test.fail() \n" 357 +
"do test.resetI()\n" 359 +
"for (var int j4 = 0; j4 != 100 ; j4 = j4 + 1 ) {\n" 361 +
" while (test.increase() != 200) {\n" 364 +
"if test.i != 200 then \n" 365 +
" do test.fail() \n" 366 +
"if j4 != 100 then \n" 367 +
" do test.fail() \n" 368 +
"do test.resetI()\n" 370 +
"for (var int j5 = 0; j5 != 100 ; j5 = j5 + 1 ) {\n" 372 +
" while (test.increase() != 200) {\n" 373 +
" if test.i == 50 then break \n" 375 +
" if test.i != 50 then test.fail() \n" 377 +
"if test.i != 50 then \n" 378 +
" do test.fail() \n" 379 +
"if j5 != 100 then {\n" 380 +
" do test.print(\" j5 is:\" + j5 ) \n" 381 +
" do test.fail() \n" 383 +
"do test.resetI()\n" 385 this->doProgram( prog, tc );
386 this->finishProgram( tc,
"x");
392 string prog = string(
"program x { do test.good()\n")
393 +
" && test.good() \n" 394 +
" && test.good() \n" 396 this->doProgram( prog, tc );
397 this->finishProgram( tc,
"x");
403 string prog = string(
"program progtry { try test.fail()\n")
404 +
"try test.good() \n" 405 +
" && test.fail() \n" 406 +
" && test.good() \n" 407 +
"try test.good() \n" 408 +
" && test.fail() \n" 409 +
"try test.good() \n" 410 +
" && test.fail() \n" 411 +
" && test.fail() catch { \n" 412 +
" try test.good() \n" 413 +
" && test.good() \n" 414 +
" && test.good() catch {\n" 415 +
" do test.fail()\n" 418 +
"do test.resetI() \n" 419 +
"try test.good() \n" 420 +
" && test.fail() \n" 421 +
" && test.good() catch { \n" 422 +
" do test.increase()\n" 424 +
"if test.i == 0 then\n" 425 +
" do test.fail()\n" 427 this->doProgram( prog, tc );
428 this->finishProgram( tc,
"progtry");
434 string prog = string(
"program y { do test.good() \n")
435 +
" do test.resetI()\n" 436 +
" do test.assert( test.i == 0 )\n" 439 string prog2 = string(
"program x {\n")
440 +
" do test.assert( test.i == 0 )\n" 441 +
" do test.increase()\n" 442 +
" do test.assert( test.i == 1 )\n" 445 +
" do test.assert( test.i == 0 )\n" 447 +
" do test.increase()\n" 450 +
" do test.assert( y.isPaused() )\n" 451 +
" do test.assert( test.i == 1 )\n" 454 +
" do test.assert( test.i == 1 )\n" 457 +
" do test.assertEqual( test.i, 0 )\n" 462 +
" do test.assert( !y.isRunning() )\n" 465 this->doProgram( prog, tc );
466 this->doProgram( prog2, tc );
467 this->finishProgram( tc,
"x");
468 this->finishProgram( tc,
"y");
474 string prog = string(
"export function foo {\n")
475 +
" do test.assert( tvar_i == +2 ) \n" 476 +
" do test.assert( tvar_i != tconst_i ) \n" 477 +
" set tvar_i = +4\n" 478 +
" do test.assert( tvar_i == +4 ) \n" 481 +
"do test.assert( tvar_i == -1 ) \n" 482 +
"do test.assert( tvar_i == tconst_i ) \n" 483 +
"set tvar_i = +2\n" 484 +
"do test.assert( tvar_i == +2 )\n" 486 +
"do test.assert( tvar_i == +4 ) \n" 488 this->doProgram( prog, tc );
489 BOOST_REQUIRE_EQUAL( 4, var_i );
490 this->finishProgram( tc,
"x");
496 string prog = string(
"export function foo(int arg) {\n")
497 +
" do test.assert( tvar_i == arg ) \n" 498 +
" do test.assert( tvar_i != tconst_i ) \n" 499 +
" set tvar_i = tvar_i+2\n" 500 +
" do test.assert( tvar_i == arg + 2 ) \n" 503 +
"do test.assert( tvar_i == -1 ) \n" 504 +
"do test.assert( tvar_i == tconst_i ) \n" 505 +
"set tvar_i = +2\n" 506 +
"var SendHandle sh\n" 507 +
"sh = foo.send(tvar_i)\n" 508 +
"while(sh.collectIfDone() != SendSuccess)\n" 510 +
"do test.assert( sh.collectIfDone() == SendSuccess )\n" 511 +
"do test.assert( tvar_i == +4 )\n" 514 +
"var SendHandle sh1, sh2\n" 515 +
"sh1 = foo.send(tvar_i)\n" 516 +
"sh2 = foo.send(tvar_i + 2)\n" 517 +
"while(sh2.collectIfDone() != SendSuccess)\n" 519 +
"do test.assert( tvar_i == +8 )\n" 520 +
"do test.assert( sh1.collectIfDone() == SendSuccess )\n" 521 +
"do test.assert( sh2.collectIfDone() == SendSuccess )\n" 522 +
"do test.assert( tvar_i == +8 )\n" 524 this->doProgram( prog, tc );
525 BOOST_REQUIRE_EQUAL( 8, var_i );
526 this->finishProgram( tc,
"x");
532 string prog = string(
"export function foo(int arg) {\n")
533 +
" do test.assert( tvar_i == arg ) \n" 534 +
" do test.assert( tvar_i != tconst_i ) \n" 535 +
" set tvar_i = tvar_i+2\n" 536 +
" do test.assert( tvar_i == arg + 2 ) \n" 539 +
"do test.assert( tvar_i == -1 ) \n" 540 +
"do test.assert( tvar_i == tconst_i ) \n" 541 +
"set tvar_i = +2\n" 542 +
"while (tvar_i != +6) {\n" 543 +
" tss = foo.cmd(tvar_i)\n" 544 +
" do test.assert( tss == SendSuccess )\n" 546 +
"do test.assert( tvar_i == +6 )\n" 547 +
"tss = foo.cmd(tvar_i)\n" 548 +
"do test.assert( tvar_i == +8 )\n" 549 +
"do test.assert( tss == SendSuccess )\n" 551 this->doProgram( prog, tc );
552 BOOST_REQUIRE_EQUAL( 8, var_i );
553 this->finishProgram( tc,
"x");
559 string prog = string(
"")
561 +
"test.assertEqual( test.i, 0 )\n" 562 +
"test.increaseCmd.send() \n" 564 +
"test.assertEqual( test.i, 1 )\n" 566 +
"test.assertEqual( test.i, 1 )\n" 568 +
"var SendHandle sh\n" 569 +
"set sh = test.increaseCmd.send()\n" 570 +
"test.assertEqual( test.i, 1 )\n" 573 +
"while (sh.collectIfDone(r) != SendSuccess)\n" 575 +
"test.assertEqual( r , 2 )\n" 576 +
"test.assertEqual( test.i, 2 )\n" 578 +
"set sh = test.increaseCmd.send()\n" 580 +
"while (sh.collectIfDone(tvar_i) != SendSuccess)\n" 582 +
"test.assertEqual( tvar_i, 3 )\n" 584 this->doProgram( prog, tc );
585 BOOST_REQUIRE_EQUAL( i, 3 );
586 BOOST_REQUIRE_EQUAL( var_i, 3 );
587 this->finishProgram( tc,
"x");
593 string prog = string(
"")
595 +
"test.assertEqual( test.i, 0 )\n" 596 +
"var SendStatus ss\n" 597 +
"tss = test.increaseCmd.cmd() \n" 598 +
"test.assert( tss == SendSuccess )\n" 599 +
"test.assertEqual( test.i, 1 )\n" 600 +
"ss = test.increaseCmd.cmd()\n" 601 +
"test.assert( ss == SendSuccess )\n" 602 +
"test.assertEqual( test.i , 2 )\n" 604 +
"tss = methods.vo0.cmd() \n" 605 +
"test.assert( tss == SendSuccess )\n" 606 +
"ss = methods.vo0.cmd()\n" 607 +
"test.assert( ss == SendSuccess )\n" 609 this->doProgram( prog, tc );
611 BOOST_CHECK_EQUAL( i, 2 );
612 this->finishProgram( tc,
"x");
619 BOOST_CHECK( tc->engine() );
623 pg_list = parser.parseProgram( prog, tc );
627 BOOST_REQUIRE_MESSAGE(
false, exc.
what() );
629 if ( pg_list.empty() )
631 BOOST_REQUIRE_MESSAGE(
false,
"No program could be found by the parser." );
635 sa->loadProgram( pi );
636 BOOST_CHECK( pi->start() );
640 stringstream errormsg;
641 errormsg <<
" on line " << pi->getLineNumber() <<
"."<<
endl;
642 BOOST_REQUIRE_MESSAGE( pi->getStatus() != ProgramInterface::Status::error ,
"Runtime error encountered" + errormsg.str());
643 BOOST_CHECK_MESSAGE( pi->getStatus() == ProgramInterface::Status::stopped ,
"Program stalled " + errormsg.str());
658 while ( loops-- != 0 ) {
659 while ( !f->isStopped() && !f->inError() )
669 BOOST_REQUIRE( sa->getProgram(prog_name) );
670 BOOST_CHECK( sa->getProgram( prog_name )->stop() );
671 BOOST_CHECK( sa->unloadProgram( prog_name ) );
const std::string what() const
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
boost::shared_ptr< ScriptingService > shared_ptr
void loopProgram(ProgramInterfacePtr)
#define BOOST_AUTO_TEST_SUITE_END()
void finishProgram(TaskContext *, std::string)
ScriptingService::shared_ptr sa
boost::shared_ptr< ProgramInterface > ProgramInterfacePtr
#define BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(test_name, n)
std::vector< ProgramInterfacePtr > ParsedPrograms
BOOST_AUTO_TEST_CASE(testEmptyProgram)
basic_ostreams & endl(basic_ostreams &s)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.