38 SimulationThread::Instance()->stop();
42 ScriptingService::shared_ptr
sa;
54 string prog = string(
"function foo { \n")
55 +
" do test.assert( test.isTrue( true ) )\n" 67 string prog = string(
"int foo { \n")
68 +
" test.assert( test.isTrue( true ) )\n" 73 +
" test.assert(true);\n" 75 +
" test.assert(true);\n" 84 string prog = string(
"export function foo { \n")
85 +
" do test.assert( test.isTrue( true ) )\n" 87 +
"export function foo_args() { \n" 88 +
" do test.assert( test.isTrue( true ) )\n" 92 +
" do this.foo_args()\n" 109 string prog = string(
"export function foo { \n")
111 +
" do test.assert( test.isTrue( true ) )\n" 113 +
"export int foo_ret(double d) { \n" 115 +
" if (true) then\n" 120 +
"export int foo_args(double d, int v) { \n" 122 +
" var double r = 10\n" 123 +
" if ( d == 3.0 && v == 6) then\n" 136 BOOST_CHECK(
foo.ready() );
144 BOOST_CHECK(
foo.ready() );
152 BOOST_CHECK(
foo.ready() );
161 BOOST_CHECK( foo_ret.ready() );
165 BOOST_CHECK_EQUAL( i, 3 );
171 BOOST_CHECK( foo_ret.ready() );
180 BOOST_CHECK( foo_ret.ready() );
185 BOOST_CHECK_EQUAL( i, 3 );
192 BOOST_CHECK( foo_args.ready() );
195 i = foo_args(-3.0, -6);
196 BOOST_CHECK_EQUAL( i, -1);
199 i = foo_args(3.0, 6);
200 BOOST_CHECK_EQUAL( i, +1);
207 BOOST_CHECK( foo_args.ready() );
209 foo_args.send(-3.0, -6);
210 foo_args.send(3.0, 6);
217 BOOST_CHECK( foo_args.ready() );
222 BOOST_CHECK_EQUAL( i, -1);
225 sh = foo_args.send(3.0, 6);
227 BOOST_CHECK_EQUAL( i, +1);
238 string prog = string(
"export function foo { \n")
239 +
" do test.assert( test.isTrue( true ) )\n" 241 +
"export int foo_ret() { \n" 242 +
" if (true) then\n" 247 +
"export int foo_args(double d, int v) { \n" 248 +
" do test.assert( test.isTrue( true ) )\n" 249 +
" if ( d == 3.0 && v == 6) then\n" 257 +
" this.foo_ret()\n" 258 +
" this.foo_args(3.0,6)\n" 259 +
" test.assertEqual(this.foo_ret(), 3 )\n" 260 +
" test.assertEqual(this.foo_args(3.0,6), 1)\n" 261 +
" test.assertEqual(this.foo_args(0.0,0), -1)\n" 273 string prog = string(
"export function foo { \n")
274 +
" while (true) { do nothing }\n" 289 string prog = string(
"export function foo { \n")
301 prog = string(
"function foo { \n")
315 BOOST_CHECK_MESSAGE(
false,
"Recursive 'call' function was accepted, while it is illegal." );
317 BOOST_CHECK_MESSAGE(
false ,
"Recursive 'do' function was accepted, while it is illegal.");
322 string prog = string(
"function foo(int a, string b, bool c) { \n")
323 +
" do test.assert( test.isTrue( true ) )\n" 326 +
" do test.assert(false)\n" 329 +
" call foo( 1, \"hello\", true)\n" 338 string prog = string(
"export function foo { \n")
339 +
" var double a = 1.234\n" 340 +
" var double b = 4.321\n" 341 +
" do test.assert( a == 1.234 )\n" 342 +
" do test.assert( b == 4.321 )\n" 345 +
" do test.assert( a == 2.134 )\n" 346 +
" do test.assert( b == 3.421 )\n" 349 +
" var double b = 1.234\n" 350 +
" var double a = 4.321\n" 352 +
" do test.assert( b == 1.234 )\n" 353 +
" do test.assert( a == 4.321 )\n" 357 +
" do test.assert( b == 1.0 )\n" 358 +
" do test.assert( a == 0.0 )\n" 370 string(
"export function fooA(int a, string b, bool c) { \n")
371 +
" do test.assertMsg( c, \"c not true\" )\n" 372 +
" do test.assertMsg( a == 1, \"a not 1\" )\n" 373 +
" do test.assertMsg( b == \"A\", \"b not A\" )\n" 375 +
"export function fooB(int a, string b, bool c) { \n" 376 +
" do test.assertMsg( !c, \"c not false\" )\n" 377 +
" do test.assertMsg( a == -1, \"a not -1\" )\n" 378 +
" do test.assertMsg( b == \"B\", \"b not B\" )\n" 379 +
" do fooA(1, \"A\", true)\n" 382 +
" do fooA(1, \"A\", true)\n" 383 +
" do fooB(-1, \"B\", false)\n" 396 string(
"function fooA(int a, string b, bool c) { \n")
397 +
" do test.assert( c )\n" 398 +
" do test.assert( a == 1 )\n" 399 +
" do test.assert( b == \"A\" )\n" 401 +
"function fooB(int a, string b, bool c) { \n" 402 +
" do test.assert( !c )\n" 404 +
" var string s = \"A\"\n" 405 +
" var bool tf = true\n" 406 +
" call fooA(i, s, tf)\n" 407 +
" do test.assert( a == -1 )\n" 408 +
" do test.assert( b == \"B\" )\n" 411 +
" call fooA(1, \"A\", true)\n" 412 +
" call fooB(-1, \"B\", false)\n" 426 string(
"export function fooA { \n")
427 +
" do test.assert( false )\n" 429 +
"export function fooB { \n" 433 +
" var bool success = false\n" 436 +
" set success = true\n" 437 +
" do test.assertMsg(success,\"Program script did not detect exported function failure.\")\n" 438 +
" set success = false\n" 441 +
" set success = true\n" 442 +
" do test.assertMsg(success,\"Program script did not detect exported function failure.\")\n" 460 BOOST_REQUIRE_MESSAGE(
false , exc.
what() );
463 BOOST_REQUIRE_MESSAGE(
false,
"Unknown exception thrown by Parser.");
465 if ( pg_list.empty() )
472 BOOST_REQUIRE(
sa->loadProgram( *pg_list.begin() ) );
473 BOOST_CHECK(
sa->getProgram( (*pg_list.begin())->getName() )->start() );
475 BOOST_CHECK( SimulationThread::Instance()->run(1000) );
478 stringstream errormsg;
479 errormsg <<
" on line " <<
sa->getProgram(
"x")->getLineNumber() <<
" of program 'x' (or of a function 'called' by x)."<<
endl;
480 BOOST_REQUIRE_MESSAGE(
sa->getProgramStatus(
"x") != ProgramInterface::Status::error ,
"Runtime Error Status encountered" + errormsg.str());
481 BOOST_REQUIRE_MESSAGE(
sa->getProgramStatus(
"x") == ProgramInterface::Status::stopped,
"Program stalled" + errormsg.str() );
487 BOOST_REQUIRE(
sa->getProgram(prog_name) );
488 sa->getProgram( prog_name )->stop();
489 sa->unloadProgram( prog_name );
const std::string what() const
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
#define BOOST_AUTO_TEST_SUITE_END()
boost::shared_ptr< ProgramInterface > ProgramInterfacePtr
bool setActivity(base::ActivityInterface *new_act)
void doFunction(const std::string &prog, TaskContext *, bool test=true)
The SendHandle is used to collect the result values of an asynchronous invocation. The template argument Signature must have the same type as the method being invoked.
std::vector< ProgramInterfacePtr > ParsedPrograms
BOOST_AUTO_TEST_CASE(testSimpleFunction)
ScriptingService::shared_ptr sa
This class is the public interface to the Orocos Program Parser Framework. It parsers Orocos program ...
basic_ostreams & endl(basic_ostreams &s)
OperationInterfacePart * getOperation(std::string name)
ParsedPrograms parseProgram(const std::string &s, TaskContext *, const std::string &filename="stream")
Reads out the string, parses it, and returns a new ProgramGraph.
void finishFunction(TaskContext *, std::string)
SendStatus collect() const
void loopProgram(ProgramInterfacePtr)
const ExecutionEngine * engine() const