Salome HOME
Revert "Synchronize adm files"
[modules/yacs.git] / src / engine / Test / RuntimeForEngineIntegrationTest.cxx
1 // Copyright (C) 2006-2014  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, or (at your option) any later version.
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 "Exception.hxx"
23 #include "ToyNode.hxx"
24 #include "TypeCode.hxx"
25 #include <sstream>
26 #include <string.h>
27
28
29 using namespace YACS::ENGINE;
30
31 void RuntimeForEngineIntegrationTest::setRuntime()
32 {
33   if (! Runtime::_singleton)
34     Runtime::_singleton = new RuntimeForEngineIntegrationTest;
35 }
36
37 ElementaryNode* RuntimeForEngineIntegrationTest::createNode(const std::string& implementation, const std::string& name) throw (YACS::Exception)
38 {
39   if (implementation == ToyNode::MY_IMPL_NAME)
40     return new ToyNode(name);
41   else if(implementation == LimitNode::MY_IMPL_NAME)
42     return new LimitNode(name);
43   std::string what="RuntimeForEngineIntegrationTest does not handle this implementation: " + implementation;
44   throw YACS::Exception(what);
45 }
46
47 InputPort* RuntimeForEngineIntegrationTest::createInputPort(const std::string& name, const std::string& impl, Node * node, TypeCode * type)
48 {
49   if(impl == ToyNode::MY_IMPL_NAME)
50     {
51       if(type->kind()!=Double)
52         throw Exception("Invalid type");
53       return new InputToyPort(name, node);
54     }
55   else if(impl == LimitNode::MY_IMPL_NAME)
56     throw Exception("InputPort creation not allowed for LimitNode");
57   std::ostringstream msg;
58   msg << "Cannot create " << impl << " OutputPort" ;
59   throw YACS::Exception(msg.str());
60 }
61
62 OutputPort* RuntimeForEngineIntegrationTest::createOutputPort(const std::string& name, const std::string& impl, Node * node, TypeCode * type)
63 {
64   if(impl == ToyNode::MY_IMPL_NAME)
65     {
66       if(type->kind()!=Double && type->kind()!=Int)
67         throw Exception("Invalid type");
68       return new OutputToyPort(name, node, type);
69     }
70   else if(impl == LimitNode::MY_IMPL_NAME)
71     throw Exception("OutputPort creation not allowed for LimitNode");
72   std::stringstream msg;
73   msg << "Cannot create " << impl << " OutputPort" ;
74   throw Exception(msg.str());
75 }
76
77 InputPort* RuntimeForEngineIntegrationTest::adapt(InputPort* source, const std::string& impl,TypeCode * type,bool init) throw (ConversionException)
78 {
79   return new ProxyPort(source);
80 }
81
82 InputPort* RuntimeForEngineIntegrationTest::adapt(InPropertyPort* source, const std::string& impl, TypeCode * type, bool init) throw (ConversionException)
83 {
84   return adapt((InputPort *)source, impl, type, init);
85 }
86
87 ComponentInstance* RuntimeForEngineIntegrationTest::createComponentInstance(const std::string& name, const std::string& kind)
88 {
89   if(kind==ToyNode1S::KIND)
90     return new ComponentInstanceTest1(name);
91   else if(kind==ToyNode2S::KIND)
92     return new ComponentInstanceTest2(name);
93   else
94     {
95       std::string msg("RuntimeForEngineIntegrationTest::createComponentInstance : Unable to crate component with kind \"");
96       msg+=kind; msg+="\"";
97       throw Exception(msg);
98     }
99 }