Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/yacs.git] / src / engine / Test / RuntimeForEngineIntegrationTest.cxx
1 // Copyright (C) 2006-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "RuntimeForEngineIntegrationTest.hxx"
21 #include "ComponentInstanceTest.hxx"
22 #include "ToyNode.hxx"
23 #include "TypeCode.hxx"
24 #include <sstream>
25
26 using namespace std;
27 using namespace YACS::ENGINE;
28
29 void RuntimeForEngineIntegrationTest::setRuntime()
30 {
31   if (! Runtime::_singleton)
32     Runtime::_singleton = new RuntimeForEngineIntegrationTest;
33 }
34
35 ElementaryNode* RuntimeForEngineIntegrationTest::createNode(const string& implementation, const string& name) throw(Exception)
36 {
37   if (implementation == ToyNode::MY_IMPL_NAME)
38     return new ToyNode(name);
39   else if(implementation == LimitNode::MY_IMPL_NAME)
40     return new LimitNode(name);
41   string what="RuntimeForEngineIntegrationTest does not handle this implementation: " + implementation;
42   throw Exception(what);
43 }
44
45 InputPort* RuntimeForEngineIntegrationTest::createInputPort(const string& name, const string& impl, Node * node, TypeCode * type)
46 {
47   if(impl == ToyNode::MY_IMPL_NAME)
48     {
49       if(type->kind()!=Double)
50         throw Exception("Invalid type");
51       return new InputToyPort(name, node);
52     }
53   else if(impl == LimitNode::MY_IMPL_NAME)
54     throw Exception("InputPort creation not allowed for LimitNode");
55   ostringstream msg;
56   msg << "Cannot create " << impl << " OutputPort" ;
57   throw Exception(msg.str());
58 }
59
60 OutputPort* RuntimeForEngineIntegrationTest::createOutputPort(const string& name, const string& impl, Node * node, TypeCode * type)
61 {
62   if(impl == ToyNode::MY_IMPL_NAME)
63     {
64       if(type->kind()!=Double && type->kind()!=Int)
65         throw Exception("Invalid type");
66       return new OutputToyPort(name, node, type);
67     }
68   else if(impl == LimitNode::MY_IMPL_NAME)
69     throw Exception("OutputPort creation not allowed for LimitNode");
70   stringstream msg;
71   msg << "Cannot create " << impl << " OutputPort" ;
72   throw Exception(msg.str());
73 }
74
75 InputPort* RuntimeForEngineIntegrationTest::adapt(InputPort* source, const string& impl,TypeCode * type,bool init) throw (ConversionException)
76 {
77   return new ProxyPort(source);
78 }
79
80 InputPort* RuntimeForEngineIntegrationTest::adapt(InPropertyPort* source, const std::string& impl, TypeCode * type, bool init) throw (ConversionException)
81 {
82   return adapt((InputPort *)source, impl, type, init);
83 }
84
85 ComponentInstance* RuntimeForEngineIntegrationTest::createComponentInstance(const std::string& name, const std::string& kind)
86 {
87   if(kind==ToyNode1S::KIND)
88     return new ComponentInstanceTest1(name);
89   else if(kind==ToyNode2S::KIND)
90     return new ComponentInstanceTest2(name);
91   else
92     {
93       string msg("RuntimeForEngineIntegrationTest::createComponentInstance : Unable to crate component with kind \"");
94       msg+=kind; msg+="\"";
95       throw Exception(msg);
96     }
97 }