typekit_scripting_test.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include <rtt/os/main.h>
00003 #include <rtt/plugin/PluginLoader.hpp>
00004 #include <rtt/scripting/ScriptingService.hpp>
00005 #include <rtt/TaskContext.hpp>
00006 
00007 
00008 void throw_function() {
00009     throw std::exception();
00010 }
00011 
00012 class KDLPluginScriptingTest : public testing::Test {
00013 
00014 protected:
00015     KDLPluginScriptingTest():
00016         tc("test")
00017     {
00018     }
00019 
00020     virtual void SetUp() {
00021         ASSERT_TRUE(RTT::plugin::PluginLoader::Instance()->loadTypekit("kdl_typekit",RTT::plugin::PluginLoader::Instance()->getPluginPath())) << "Failed to load kdl typekit";
00022         ASSERT_TRUE(tc.loadService("scripting")) << "Unable to load scripting service";
00023         scripting = boost::dynamic_pointer_cast<RTT::scripting::ScriptingService>( tc.provides()->getService("scripting") );
00024         ASSERT_TRUE(scripting) << "Failed to get loaded scripting service";
00025 
00026         tc.addOperation("throw",&throw_function);
00027         tc.setPeriod(0.01);
00028         ASSERT_TRUE(scripting->loadPrograms("./typekit-test.ops",false)) << "Failed to load test program";
00029         ASSERT_TRUE(tc.start()) << "Failed to start TaskContext";
00030     }
00031     virtual void TearDown() {
00032     }
00033     
00034     RTT::TaskContext tc;
00035     RTT::scripting::ScriptingService::shared_ptr scripting;
00036 };
00037 
00038 TEST_F(KDLPluginScriptingTest, ScriptTest) {
00039     std::vector<std::string> programs = scripting->getProgramList();
00040 
00041     for(std::vector<std::string>::const_iterator it = programs.begin(); it != programs.end(); ++it) {
00042         RTT::scripting::ProgramInterfacePtr program = scripting->getProgram(*it);
00043         ASSERT_TRUE(program) << "Failed to get program " << *it;
00044         ASSERT_TRUE(program->start());
00045         while(program->isRunning()) {
00046             ASSERT_FALSE(program->inError()) << "Program " << *it << " failed on line " << program->getLineNumber();
00047             usleep(1000);
00048         }
00049         ASSERT_FALSE(program->inError()) << "Program " << *it << " failed on line " << program->getLineNumber();
00050     }
00051 }
00052 
00053 int ORO_main(int argc, char **argv){
00054     testing::InitGoogleTest(&argc,argv);
00055     return RUN_ALL_TESTS();
00056 }
00057 


kdl_typekit
Author(s): Steven Bellens, Ruben Smits
autogenerated on Fri May 17 2019 02:37:38