47 ScriptingService::shared_ptr
sa;
48 void executePrograms(
const std::string& prog);
49 void executeStates(
const std::string& state);
56 BOOST_REQUIRE( tc->start() );
57 SimulationThread::Instance()->stop();
71 size_t strCapacity=str.
get().capacity();
73 BOOST_CHECK_EQUAL( str.
get().size() , 10 );
79 BOOST_CHECK_EQUAL( str.
get().size() , 5 );
80 BOOST_CHECK_EQUAL( str.
get().capacity() , strCapacity );
84 BOOST_CHECK_EQUAL( copy.get().size() , 0 );
91 BOOST_CHECK_EQUAL( copy.get().size(), 5 );
94 BOOST_CHECK_EQUAL( copy.get(), str.
get() );
100 BOOST_CHECK_EQUAL( str.
get().size() , 5 );
101 BOOST_CHECK_EQUAL( str.
get().capacity() , strCapacity );
102 BOOST_CHECK_EQUAL( copy.get(), str.
get() );
108 strCapacity=str.
get().capacity();
110 BOOST_CHECK_EQUAL( str.
get().size() , 5 );
117 act->readArguments();
118 BOOST_CHECK( act->execute() );
121 BOOST_CHECK_EQUAL( copy.get().size(), 5 );
124 BOOST_CHECK_EQUAL( copy.get(), str.
get() );
126 copy.set() =
"world";
129 act = str.
getDataSource()->updateAction( copy.getDataSource().get() );
131 act->readArguments();
132 BOOST_CHECK( act->execute() );
135 BOOST_CHECK_EQUAL( str.
get().size() , 5 );
136 BOOST_CHECK_EQUAL( str.
get().capacity() , strCapacity );
137 BOOST_CHECK_EQUAL( copy.get(), str.
get() );
146 string(
"var int i2 = -1, j = 10, k; set k = 20\n") +
147 "do test.assert( i2 == -1 ) ; do test.assert( j == 10 ); do test.assert(k == 20)\n" +
148 "var double d = 10.0\n"+
149 "do test.assert( d == 10.0 )\n" +
150 "var bool b = false\n"+
151 "do test.assert( b == false )\n" +
152 "var string s=\"string\"\n"+
153 "do test.assert( s == \"string\" )\n" +
154 "const int ic = i2\n" +
155 "do test.assert( ic == 0 )\n" +
156 "const double dc = 10.0\n"+
157 "do test.assert( dc == 10.0 )\n" +
158 "const bool bc = true && false\n"+
159 "do test.assert( bc == false )\n" +
160 "const string sc= \"hello\"\n"+
161 "do test.assert( sc == \"hello\" )\n" +
162 "var array ar(10)\n"+
163 "do test.assert( ar.size == 10)\n"+
165 "do test.assert( ar.capacity == 10)\n"+
171 "do test.assert( ar[0] == 0.0 )\n"+
172 "do test.assert( ar[1] == 1.0 )\n"+
173 "do test.assert( ar[2] == 0.2 )\n"+
174 "do test.assert( ar[8] == 0.8 )\n"+
176 "do test.assert( ar[9] == 9.0 )\n"+
177 "do test.assert( ar[10] == 0.0 )\n"+
178 "var array ar1 = array(12,2.0)\n"+
179 "do test.assert(ar1.size == 12)\n"+
181 "do test.assert(ar1[0] == 2.0)\n"+
182 "var array ar2 = array(5,3.0)\n"+
183 "do test.assert(ar2.size == 5)\n"+
184 "do test.assert(ar2[0] == 3.0)\n"+
185 "var array ar3(3) = array(2.0,3.0,4.0)\n"+
186 "do test.assert(ar3.size == 3)\n"+
188 "do test.assert(ar3[0]==2.0)\n"+
189 "do test.assert(ar3[1]==3.0)\n"+
190 "do test.assert(ar3[2]==4.0)\n"+
191 "var array ar4 = array(2.0,3.0,4.0,5.0)\n"+
192 "do test.assert(ar4.size == 4)\n"+
193 "do test.assert(ar4[0]==2.0)\n"+
194 "do test.assert(ar4[1]==3.0)\n"+
195 "do test.assert(ar4[2]==4.0)\n"+
196 "do test.assert(ar4[3]==5.0)\n"+
197 "var string str(10)\n"+
198 "var int strCapacity = str.capacity\n" 202 "do test.assertEqual( str.size, 10)\n"+
204 "set str = \"hello\"\n"+
207 "do test.assertEqual( str.size, 5)\n"+
208 "do test.assertEqual( str.capacity, strCapacity)\n"+
209 "set str[0] = 'a'\n"+
210 "set str[1] = 'b'\n"+
211 "set str[2] = 'c'\n"+
212 "do test.assert( str[0] == 'a' )\n"+
213 "do test.assert( str[1] == 'b' )\n"+
214 "do test.assert( str[2] == 'c' )\n"+
215 "do test.assert( str == \"abclo\" )\n"+
216 "do test.assert( str[20] == '\\0' )\n"+
218 "do test.assert( str[8] == '\\0' )\n"+
219 "do test.assert( str[9] == '\\0' )\n"+
220 "do test.assert( str[10] == '\\0' )\n"+
222 "set ar2 = array(10.,5.)\n"+
223 "do test.assertEqual( ar2.size, 2)\n"+
224 "do test.assertEqual( ar2.capacity, 5)\n"+
225 "do test.assert( ar2[0] == 10.0 )\n"+
226 "do test.assert( ar2[1] == 5.0 )\n"+
227 "set ar3 = array(10.)\n"+
228 "do test.assert( ar3.size == 1)\n"+
230 "do test.assert( ar3.capacity >= 1)\n"+
231 "do test.assert( ar3[0] == 10.0 )\n"+
232 "set ar4 = array(2, 7.)\n"+
233 "do test.assert( ar4.size == 2)\n"+
234 "do test.assert( ar4.capacity >= 2)\n"+
235 "do test.assert( ar4[0] == 7.0 )\n"+
236 "do test.assert( ar4[1] == 7.0 )\n"+
239 "do test.assert( ar2.size == 2)\n"+
240 "do test.assert( ar2.capacity >= 5)\n"+
242 "do test.assert( ar2[0] == 7.0 )\n"+
243 "do test.assert( ar2[1] == 7.0 )\n"+
244 "do test.assert( ar.capacity == 10)\n"+
245 "var array ar7(7) = array(7)\n"+
248 "do test.assert( ar.size == 7)\n"+
250 "do test.assertEqual( ar.capacity, 10)\n"+
252 "do test.assert( ar2[0] == 7.0 )\n"+
253 "do test.assert( ar2[1] == 7.0 )\n"+
254 "var astruct aVar\n" +
256 "var astruct bVar\n" +
258 "do test.assertMsg(aVar.a == 42, \"aVar.a != 42 assignement failed - testTypes\")\n" +
260 "do test.assertMsg(bVar.a == 42, \"bVar.a != 42 assignement failed - testTypes\")\n" +
263 string state = string(
"StateMachine X { initial state Init { entry {\n")
266 +
"final state Fini {} }\n" 267 +
"RootMachine X x\n";
269 string prog = string(
"program x {\n") + test +
"}\n";
271 executePrograms(prog);
272 executeStates(state);
279 Types()->type(
"astruct")->addAlias(
"aalias2");
281 BOOST_CHECK(
Types()->type(
"astruct") != 0 );
282 BOOST_CHECK(
Types()->type(
"aalias1") != 0 );
283 BOOST_CHECK(
Types()->type(
"aalias2") != 0 );
285 BOOST_CHECK_EQUAL(
Types()->type(
"astruct"),
Types()->type(
"aalias1") );
286 BOOST_CHECK_EQUAL(
Types()->type(
"astruct"),
Types()->type(
"aalias2") );
288 BOOST_CHECK_EQUAL(
"astruct",
Types()->type(
"astruct")->getTypeNames()[0] );
289 BOOST_CHECK_EQUAL(
"aalias1",
Types()->type(
"astruct")->getTypeNames()[1] );
290 BOOST_CHECK_EQUAL(
"aalias2",
Types()->type(
"astruct")->getTypeNames()[2] );
297 string(
"var char c = char('c');\n") +
300 "var char d = char('d');\n" +
303 "set c = char('a');\n" +
304 "do test.assert( char('a') == c ); \n" +
305 "do test.assert( c != d ); \n" +
306 "do test.assert( c < d ); \n" +
307 "do test.assert( c <= d ); \n" +
308 "do test.assert( d > c ); \n" +
309 "do test.assert( d >= c ); \n" +
311 "do test.assert( c == d ); \n" +
312 "do test.assert( char('a') == d ); \n" +
313 "do test.assert( char('a') == char('a') ); \n" +
314 "do test.assert( char('a') != char('b') ); \n" +
315 "do test.assert( char('a') < char('b') ); \n" +
316 "do test.assert( char('a') <= char('b') ); \n" +
317 "do test.assert( char('a') <= char('a') ); \n" +
318 "do test.assert( char('z') > char('w') ); \n" +
319 "do test.assert( char('z') >= char('w') ); \n" +
320 "do test.assert( char('z') >= char('z') ); \n" 323 string state = string(
"StateMachine X { initial state Init { entry {\n")
326 +
"final state Fini {} }\n" 327 +
"RootMachine X x\n";
329 string prog = string(
"program x {\n") + test +
"}\n";
331 executePrograms(prog);
332 executeStates(state);
340 string prog = string(
"program x {\n") +
342 "var char c = 'c'\n" +
343 "var double d = 10.0*i\n"+
344 "do test.assert( d == 30.0 )\n" +
345 "var bool b = false\n"+
346 "var string s=\"string\"\n"+
347 "set b = b || b && true && false || true\n"+
348 "try test.assertMsg( s == \"string\", \"Unexpected string:\'\" + s +\"' instead of 'string'\")\n"+
349 "set s = \" \" + s + \" \"\n"+
350 "try test.assertMsg( s == \" string \", \"Unexpected string:\'\" + s +\"' instead of ' string '\")\n"+
351 "set s = s + int(10)\n"+
352 "try test.assertMsg( s == \" string 10\", \"Unexpected string:\'\" + s +\"' instead of ' string 10'\")\n"+
353 "set s = s + \" \" + false\n"+
354 "do test.assertMsg( s == \" string 10 false\", \"Unexpected string:\'\" + s +\"' instead of ' string 10 false'\")\n"+
355 "set b = b\n ||\n b\n &&\n true\n && false\n || true\n"+
356 "do test.assert( b == false )\n" +
357 "var array a1 = array(2, 7.)\n"+
358 "do test.assert( a1.size == 2 )\n" +
359 "do test.assert( a1.capacity == 2 )\n" +
363 executePrograms(prog);
377 string prog = string(
"program x {\n") +
378 "var matrix m = matrix(8,array(10))\n" +
379 "test.assertMsg(m.size == 8, \"Matrix column size is wrong.\")\n" +
380 "test.assertMsg(m[0].size == 10, \"Matrix row size is wrong.\")\n" +
384 "m[8][10] = 6.33\n" +
385 "test.assertMsg(m[0][0] == 3.33, \"Matrix element assignment failed.\")\n"+
386 "test.assertMsg(m[1][1] == 4.33, \"Matrix element assignment failed.\")\n"+
387 "test.assertMsg(m[2][2] == 5.33, \"Matrix element assignment failed.\")\n"+
388 "test.assertMsg(m[8][10] == 6.33, \"Matrix element assignment failed.\")\n"+
389 "var matrix m2 = m;\n" 390 "test.assertMsg(m2[0][0] == 3.33, \"Matrix assignment failed.\")\n"+
391 "test.assertMsg(m2[1][1] == 4.33, \"Matrix assignment failed.\")\n"+
392 "test.assertMsg(m2[2][2] == 5.33, \"Matrix assignment failed.\")\n"+
393 "test.assertMsg(m2[8][10] == 6.33, \"Matrix assignment failed.\")\n"+
394 "var cstructv structv = cstructv(3)\n"+
395 "structv[1].a.b = 3.33\n"+
396 "test.assertMsg(structv[1].a.b == 3.33, \"Sequence of struct element assignment failed.\")\n"+
397 "structv[1].av[3].b = 4.33\n"+
398 "test.assertMsg(structv[1].av[3].b == 4.33, \"Sequence of struct element assignment failed.\")\n"+
401 executePrograms(prog);
410 string prog = string(
"program x {\n") +
411 "var int i = 3.0\n" +
412 "var double d = float(10.0*i)\n"+
413 "do test.assert( float(d) == float(30.0) )\n" +
414 "var float f = 5\n" +
415 "set f = double(5) * double(-1) + i\n" +
418 "set i = double(float(int(f)))\n" +
419 "set f = int(float(double(int(3.333))))\n" +
420 "do test.assert( f == 3 )\n" +
423 executePrograms(prog);
431 string prog = string(
"program x {\n") +
432 "var llong ll = 9223372036854775807ll\n" +
433 "do test.assert( -(ll + 2) == 9223372036854775807ll )\n" +
434 "var ullong ull = 18446744073709551615ull\n" +
435 "do test.assert( ull + 1 == 0 )\n" +
436 "var double d = ll\n" +
437 "do test.assert( d == 9.223372036854775807e+18 )\n" +
439 "do test.assert( ll == 3ll )\n" +
441 "do test.assert( ll == -1ll )\n" +
442 "set ll = int(-1000)\n" +
443 "do test.assert( ll == -1000ll )\n" +
444 "set ull = int(1000)\n" +
445 "do test.assert( ull == 1000ull )\n" +
446 "set ull = uint(1000)\n" +
447 "do test.assert( ull == 1000ull )\n" +
448 "set ull = llong(12345)\n" +
449 "do test.assert( ull == 12345ull )\n" +
452 executePrograms(prog);
460 string prog = string(
"program x {\n") +
461 "var uint i = 0xabc\n" +
462 "test.assert( i == 0xabc )\n"+
463 "test.assert( i == 2748 )\n"+
465 "test.assert( i == 0Xcba )\n"+
466 "test.assert( i == 3258 )\n"+
468 "test.assert( i == 0XABC )\n"+
469 "test.assert( i == 2748 )\n"+
471 "test.assert( i == 0xCBA )\n"+
472 "test.assert( i == 3258 )\n"+
475 executePrograms(prog);
483 string prog = string(
"program x {\n") +
484 "do test.assert( Double1 == 1.234 )\n" +
485 "do test.assert( Double2 == 2.234 )\n" +
486 "do test.assert( Double3 == 3.234 )\n" +
487 "do test.assert( Collection.Double1 == 1.234 )\n" +
488 "do test.assert( Collection.Double3 == 3.234 )\n" +
489 "do test.assert( Collection.Collection.Double1 == 1.234 )\n" +
490 "do test.assert( Collection.Collection.Collection.Double3 == 3.234 )\n" +
491 "do test.assert( V[0] == 4.0 )\n" +
492 "do test.assert( V[1] == 4.0 )\n" +
493 "do test.assert( V[2] == 4.0 )\n" +
494 "do test.assert( V[3] == 4.0 )\n" +
496 "set Double1 = 4.321\n" +
497 "set Double2 = Double1\n" +
499 "set Collection.Double3 = 0.3\n" +
500 "set V[0] = 0.321\n" +
501 "set V[1] = 1.321\n" +
502 "set V[2] = 2.321\n" +
503 "set V[3] = 3.321\n" +
504 "do test.assert( Double1 == 4.321 )\n" +
505 "do test.assert( Double2 == 4.321 )\n" +
506 "do test.assert( Double3 == 0.3 )\n" +
507 "set Collection.Collection.Collection.Double3 = 3.0\n" +
508 "do test.assert( Double3 == 3.0 )\n" +
518 pb.
value().addProperty( pd1 );
519 pb.
value().addProperty( pd3 );
520 pb.
value().addProperty( pb );
522 tc->properties()->addProperty( pd1 );
523 tc->properties()->addProperty( pd2 );
524 tc->properties()->addProperty( pd3 );
525 tc->properties()->addProperty( pb );
526 tc->properties()->addProperty( pv );
529 executePrograms(prog);
531 BOOST_CHECK_EQUAL( 4.321, pd1.
get() );
532 BOOST_CHECK_EQUAL( 3.0, pd3.
get() );
533 BOOST_CHECK_EQUAL( 0.321, pv.
value()[0] );
534 BOOST_CHECK_EQUAL( 1.321, pv.
value()[1] );
535 BOOST_CHECK_EQUAL( 2.321, pv.
value()[2] );
536 BOOST_CHECK_EQUAL( 3.321, pv.
value()[3] );
541 string prog = string(
"program x {\n") +
542 "do test.assert( 6/2*4 == 12 )\n" +
543 "do test.assert( 6*2/4 == 3 )\n" +
544 "do test.assert( 3+2*5 == 13)\n" +
545 "do test.assert( 3 < 2 != 5 > 1)\n" +
546 "do test.assert( 3*2 <= 12/2 )\n" +
547 "do test.assert( 3*2 < 6+1 )\n" +
548 "do test.assert( 6 - 9 % 2*3 == 15/3 % 3 + 1 )\n" +
549 "do test.assert( 3*(2+1) == 9 )\n" +
550 "do test.assert( 1 - 1 + 5 == 5 )\n" +
552 " a = b = c = 3;\n" +
553 "do test.assertEqual( a, 3 )\n" +
554 "do test.assertEqual( b, 3 )\n" +
555 "do test.assertEqual( c, 3 )\n" +
558 executePrograms(prog);
563 GlobalsRepository::Instance()->setValue(
new Constant<double>(
"cd_num", 3.33));
564 GlobalsRepository::Instance()->setValue(
new Constant<string>(
"c_string",
"Hello World!"));
566 string prog = string(
"program x {\n") +
567 "do test.assert( cd_num == 3.33 )\n" +
568 "do test.assert( cd_num == d_num )\n" +
569 "do test.assert( c_string == \"Hello World!\")\n" +
570 "set d_num = 6.66\n" +
571 "do test.assert( d_num == 6.66 )\n" +
574 executePrograms(prog);
579 BOOST_CHECK (GlobalsRepository::Instance()->getValue(
"NewData") );
580 BOOST_CHECK (GlobalsRepository::Instance()->getValue(
"OldData") );
581 BOOST_CHECK (GlobalsRepository::Instance()->getValue(
"NoData") );
582 BOOST_CHECK (GlobalsRepository::Instance()->getValue(
"WriteSuccess") );
583 BOOST_CHECK (GlobalsRepository::Instance()->getValue(
"WriteFailure") );
584 BOOST_CHECK (GlobalsRepository::Instance()->getValue(
"NotConnected") );
585 string prog = string(
"program x {\n") +
586 "do test.assert( NewData )\n" +
587 "do test.assert( OldData )\n" +
588 "do test.assert( !bool(NoData) )\n" +
589 "do test.assert( NewData > NoData )\n" +
590 "do test.assert( NewData > OldData )\n" +
591 "do test.assert( OldData > NoData )\n" +
592 "do test.assert( OldData == OldData )\n" +
593 "if ( bool(NewData) && OldData ) then {\n" +
595 " do test.assert(false)\n" +
597 "if ( bool(NoData) ) then {\n" +
598 " do test.assert(false)\n" +
600 "if ( !bool(NoData) ) then {} else {\n" +
601 " do test.assert(false)\n" +
605 executePrograms(prog);
611 BOOST_CHECK( tc->engine() );
615 pg_list = parser.parseProgram( prog, tc );
619 BOOST_REQUIRE_MESSAGE(
false , exc.
what());
621 if ( pg_list.empty() )
623 BOOST_REQUIRE(
false &&
"Got empty test program." );
626 BOOST_CHECK( sa->loadProgram( *pg_list.begin() ) );
627 BOOST_CHECK( (*pg_list.begin())->start() );
629 BOOST_CHECK( SimulationThread::Instance()->run(1000) );
631 if ( (*pg_list.begin())->inError() ) {
632 stringstream errormsg;
633 errormsg <<
" Program error on line " << (*pg_list.begin())->getLineNumber() <<
"."<<
endl;
634 BOOST_CHECK_MESSAGE(
false, errormsg.str() );
637 if ( (*pg_list.begin())->isRunning() ) {
638 stringstream errormsg;
639 errormsg <<
" Program still running on line " << (*pg_list.begin())->getLineNumber() <<
"."<<
endl;
640 BOOST_CHECK_MESSAGE(
false, errormsg.str() );
643 if ( (*pg_list.begin())->isStopped() == false ) {
644 stringstream errormsg;
645 errormsg <<
" Program not stopped on line " << (*pg_list.begin())->getLineNumber() <<
"."<<
endl;
646 BOOST_CHECK_MESSAGE(
false , errormsg.str() );
648 BOOST_CHECK( (*pg_list.begin())->stop() );
649 BOOST_CHECK( sa->unloadProgram( (*pg_list.begin())->getName() ) );
654 BOOST_CHECK( tc->engine() );
657 pg_list = parser.parseStateMachine( state, tc );
661 BOOST_REQUIRE_MESSAGE(
false , exc.
what());
663 if ( pg_list.empty() )
665 BOOST_REQUIRE_MESSAGE(
false,
"Parser returned no state machines to execute." );
668 BOOST_CHECK( sa->loadStateMachine( *pg_list.begin() ) );
669 BOOST_CHECK( (*pg_list.begin())->activate() );
670 BOOST_CHECK( (*pg_list.begin())->start() );
672 BOOST_CHECK( SimulationThread::Instance()->run(1000) );
673 if ( (*pg_list.begin())->inError() ) {
674 stringstream errormsg;
675 errormsg <<
" State error on line " << (*pg_list.begin())->getLineNumber() <<
"."<<
endl;
676 BOOST_CHECK_MESSAGE(
false , errormsg.str());
679 BOOST_CHECK( (*pg_list.begin())->stop() );
680 BOOST_CHECK( SimulationThread::Instance()->run(100) );
681 BOOST_CHECK( (*pg_list.begin())->deactivate() );
683 sa->unloadStateMachine( (*pg_list.begin())->getName() );
const std::string what() const
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
DataSourceType get() const
#define BOOST_AUTO_TEST_SUITE_END()
base::DataSourceBase::shared_ptr getDataSource() const
void executeStates(const std::string &state)
std::vector< ProgramInterfacePtr > ParsedPrograms
Based on the software pattern 'command', this interface allows execution of action objects...
This class is the public interface to the Orocos Program Parser Framework. It parsers Orocos program ...
TypeInfoRepository::shared_ptr Types()
basic_ostreams & endl(basic_ostreams &s)
BOOST_AUTO_TEST_CASE(testStringCapacity)
Tests the preservation of the capacity of a string in the type system.
std::vector< ParsedStateMachinePtr > ParsedStateMachines
ScriptingService::shared_ptr sa
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.