31 using namespace boost;
35 #include <boost/shared_ptr.hpp> 38 #define MULTILINE_STRING(...) #__VA_ARGS__ 48 PluginLoader::Instance()->loadService(
"scripting",tc);
50 boost::shared_ptr<Scripting> sc = tc->getProvider<
Scripting>(
"scripting");
52 BOOST_CHECK ( sc->ready() );
58 BOOST_CHECK( sc->hasProgram(
"Foo") );
59 BOOST_REQUIRE( sc->startProgram(
"Foo") );
60 BOOST_CHECK( sc->isProgramRunning(
"Foo") );
63 while(sc->isProgramRunning(
"Foo")) {
69 BOOST_CHECK( sc->isProgramRunning(
"Foo") == false );
70 BOOST_CHECK( sc->inProgramError(
"Foo") == false );
71 BOOST_CHECK( ret == 10.0 );
77 PluginLoader::Instance()->loadService(
"scripting",tc);
79 boost::shared_ptr<Scripting> sc = tc->getProvider<
Scripting>(
"scripting");
81 BOOST_CHECK ( sc->ready() );
88 BOOST_CHECK_EQUAL( i, 1);
96 BOOST_CHECK_EQUAL( i, 10);
100 var
int x = 1, y = 2;
106 BOOST_CHECK_EQUAL( i, 2);
110 var
int x = 1, y = 2;
115 BOOST_CHECK_EQUAL( i, 3);
119 var
int whilex, whiley\n
122 while whilex != whiley {
126 BOOST_CHECK_EQUAL( i, 3);
130 var
int x = 10, y = 20;
131 for( x = 0; x != y; x = x + 1) {
134 BOOST_CHECK_EQUAL( i, 19);
139 forx = 10; fory = 20;
140 for( forx = 0; forx != fory; forx = forx + 1) {
143 BOOST_CHECK_EQUAL( i, 19);
147 export
function adder(
int a,
int b) {
152 BOOST_CHECK_EQUAL( i, 11);
154 export
void adder2(
int a,
int b) {
159 BOOST_CHECK_EQUAL( i, 15);
161 export
int adder3(
int a,
int b) {
164 test.i = adder3(6,10)\n
166 BOOST_CHECK_EQUAL( i, 16);
173 rt_script.start();;;;
174 while( rt_script.isRunning() ) {
178 BOOST_CHECK_EQUAL( sc->getProgramStatus(
"rt_script"), ProgramInterface::Status::stopped );
179 BOOST_CHECK_EQUAL( i, -6);
199 RootMachine RTState rt_state;
202 while( !rt_state.inFinalState() ) {
206 BOOST_CHECK_EQUAL( sc->getStateMachineState(
"rt_state"),
"fini" );
207 BOOST_CHECK_EQUAL( i, -2);
212 PluginLoader::Instance()->loadService(
"scripting",tc);
214 boost::shared_ptr<Scripting> sc = tc->getProvider<
Scripting>(
"scripting");
216 BOOST_CHECK ( sc->ready() );
226 BOOST_CHECK_EQUAL( i, 0);
227 BOOST_CHECK( tc->provides(
"scripting")->hasMember(
"func1"));
231 export
void efunc1(
void) {
234 BOOST_CHECK_EQUAL( i, 0);
235 BOOST_CHECK( tc->provides()->hasMember(
"efunc1"));
242 BOOST_CHECK_EQUAL( i, 0);
243 BOOST_CHECK( tc->provides(
"scripting")->hasMember(
"lfunc1"));
247 global
void gfunc1(
void) {
250 BOOST_CHECK_EQUAL( i, 0);
251 BOOST_CHECK( GlobalService::Instance()->provides()->hasMember(
"gfunc1"));
258 BOOST_CHECK_EQUAL( i, 0);
259 BOOST_CHECK( tc->provides(
"scripting")->hasMember(
"func2"));
266 BOOST_CHECK_EQUAL( i, 0);
267 BOOST_CHECK( tc->provides(
"scripting")->hasMember(
"efunc2"));
274 BOOST_CHECK_EQUAL( i, 0);
275 BOOST_CHECK( tc->provides(
"scripting")->hasMember(
"gfunc2"));
282 BOOST_CHECK_EQUAL( i, 0);
283 BOOST_CHECK( tc->provides(
"scripting")->hasMember(
"lfunc2"));
286 BOOST_REQUIRE( sc->eval(
"func1()") );
287 BOOST_CHECK_EQUAL( i, 1);
290 BOOST_REQUIRE( sc->eval(
"efunc1()") );
291 BOOST_CHECK_EQUAL( i, 2);
294 BOOST_REQUIRE( sc->eval(
"gfunc1()") );
295 BOOST_CHECK_EQUAL( i, 3);
298 BOOST_REQUIRE( sc->eval(
"lfunc1()") );
299 BOOST_CHECK_EQUAL( i, 4);
302 BOOST_REQUIRE( sc->eval(
"func2()") );
303 BOOST_CHECK_EQUAL( i, 5);
306 BOOST_REQUIRE( sc->eval(
"efunc2()") );
307 BOOST_CHECK_EQUAL( i, 6);
310 BOOST_REQUIRE( sc->eval(
"gfunc2()") );
311 BOOST_CHECK_EQUAL( i, 7);
314 BOOST_REQUIRE( sc->eval(
"lfunc2()") );
315 BOOST_CHECK_EQUAL( i, 8);
318 BOOST_CHECK( !sc->eval(
"call func1()") );
319 BOOST_CHECK_EQUAL( i, 8);
322 BOOST_CHECK( !sc->eval(
"call efunc1()") );
323 BOOST_CHECK_EQUAL( i, 8);
331 BOOST_CHECK_EQUAL( i, 8);
332 BOOST_CHECK( tc->provides(
"scripting")->hasMember(
"func1"));
334 BOOST_REQUIRE( sc->eval(
"func1()") );
335 BOOST_CHECK_EQUAL( i, 10);
339 export
void efunc1(
void) {
343 BOOST_CHECK_EQUAL( i, 10);
344 BOOST_CHECK( tc->provides()->hasMember(
"efunc1"));
346 BOOST_REQUIRE( sc->eval(
"efunc1()") );
347 BOOST_CHECK_EQUAL( i, 12);
351 global
void gfunc1(
void) {
355 BOOST_CHECK_EQUAL( i, 12);
356 BOOST_CHECK( GlobalService::Instance()->provides()->hasMember(
"gfunc1"));
358 BOOST_REQUIRE( sc->eval(
"gfunc1()") );
359 BOOST_CHECK_EQUAL( i, 14);
364 PluginLoader::Instance()->loadService(
"scripting",tc);
370 boost::shared_ptr<Scripting> sc = tc->getProvider<
Scripting>(
"scripting");
372 BOOST_CHECK ( sc->ready() );
380 test.printNumber(
"[ENTER func1()] CycleCounter = ", CycleCounter);
384 test.printNumber(
"[EXIT func1()] CycleCounter = ", CycleCounter);
386 BOOST_CHECK_EQUAL( i, 0);
387 BOOST_CHECK( tc->provides(
"scripting")->hasMember(
"func1"));
392 test.printNumber(
"[ENTER func2()] CycleCounter = ", CycleCounter);
396 test.printNumber(
"[EXIT func2()] CycleCounter = ", CycleCounter);
398 BOOST_CHECK_EQUAL( i, 0);
399 BOOST_CHECK( tc->provides(
"scripting")->hasMember(
"func2"));
402 BOOST_REQUIRE( sc->eval(
"func1()") );
403 BOOST_CHECK_EQUAL( i, 2);
406 BOOST_REQUIRE( sc->eval(
"func2()") );
407 BOOST_CHECK_EQUAL( i, 6);
A hierarchical StateMachine which is loaded in the Program Processor.
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
BOOST_AUTO_TEST_CASE(TestGetProvider)
Tests the scripting service's functions.
#define MULTILINE_STRING(...)
#define BOOST_AUTO_TEST_SUITE_END()
int usleep(unsigned int us)
static void yield(TaskContext *tc)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
static bool trigger(TaskContext *tc)