]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/Test/RuntimeForEngineIntegrationTest.cxx
Salome HOME
Work in progress : workload manager engine test ok
[modules/yacs.git] / src / engine / Test / RuntimeForEngineIntegrationTest.cxx
1 // Copyright (C) 2006-2019  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 std::vector< std::pair<std::string,int> > RuntimeForEngineIntegrationTest::getCatalogOfComputeNodes() const
38 {
39   std::vector< std::pair<std::string,int> > result(1);
40   std::pair<std::string,int> localhost;
41   localhost.first = "localhost";
42   localhost.second = 8;
43   result[0] = localhost;
44   return result;
45 //  throw Exception("RuntimeForEngineTest::getCatalogOfComputeNodes : not implemented !");
46 }
47
48 ElementaryNode* RuntimeForEngineIntegrationTest::createNode(const std::string& implementation, const std::string& name) throw (YACS::Exception)
49 {
50   if (implementation == ToyNode::MY_IMPL_NAME)
51     return new ToyNode(name);
52   else if(implementation == LimitNode::MY_IMPL_NAME)
53     return new LimitNode(name);
54   std::string what="RuntimeForEngineIntegrationTest does not handle this implementation: " + implementation;
55   throw YACS::Exception(what);
56 }
57
58 InputPort* RuntimeForEngineIntegrationTest::createInputPort(const std::string& name, const std::string& impl, Node * node, TypeCode * type)
59 {
60   if(impl == ToyNode::MY_IMPL_NAME)
61     {
62       if(type->kind()!=Double)
63         throw Exception("Invalid type");
64       return new InputToyPort(name, node);
65     }
66   else if(impl == LimitNode::MY_IMPL_NAME)
67     throw Exception("InputPort creation not allowed for LimitNode");
68   std::ostringstream msg;
69   msg << "Cannot create " << impl << " OutputPort" ;
70   throw YACS::Exception(msg.str());
71 }
72
73 OutputPort* RuntimeForEngineIntegrationTest::createOutputPort(const std::string& name, const std::string& impl, Node * node, TypeCode * type)
74 {
75   if(impl == ToyNode::MY_IMPL_NAME)
76     {
77       if(type->kind()!=Double && type->kind()!=Int)
78         throw Exception("Invalid type");
79       return new OutputToyPort(name, node, type);
80     }
81   else if(impl == LimitNode::MY_IMPL_NAME)
82     throw Exception("OutputPort creation not allowed for LimitNode");
83   std::stringstream msg;
84   msg << "Cannot create " << impl << " OutputPort" ;
85   throw Exception(msg.str());
86 }
87
88 InputPort* RuntimeForEngineIntegrationTest::adapt(InputPort* source, const std::string& impl,TypeCode * type,bool init) throw (ConversionException)
89 {
90   return new ProxyPort(source);
91 }
92
93 InputPort* RuntimeForEngineIntegrationTest::adapt(InPropertyPort* source, const std::string& impl, TypeCode * type, bool init) throw (ConversionException)
94 {
95   return adapt((InputPort *)source, impl, type, init);
96 }
97
98 ComponentInstance* RuntimeForEngineIntegrationTest::createComponentInstance(const std::string& name, const std::string& kind)
99 {
100   if(kind==ToyNode1S::KIND)
101     return new ComponentInstanceTest1(name);
102   else if(kind==ToyNode2S::KIND)
103     return new ComponentInstanceTest2(name);
104   else
105     {
106       std::string msg("RuntimeForEngineIntegrationTest::createComponentInstance : Unable to crate component with kind \"");
107       msg+=kind; msg+="\"";
108       throw Exception(msg);
109     }
110 }