Version: 9.16.0
YACSPMMLBasicsTest1.cxx
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF
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// Author : InckA
20
21
23#include "PMMLlib.hxx"
24
25#include "yacsconfig.h"
26#include "RuntimeSALOME.hxx"
27#include "PythonPorts.hxx"
28#include "CORBAPorts.hxx"
29#include "parsers.hxx"
30#include "Proc.hxx"
31#include "Exception.hxx"
32#include "Executor.hxx"
33#include "parsers.hxx"
34
35#include <iostream>
36#include <fstream>
37#include <stdlib.h>
38#ifdef WIN32
39#include <io.h>
40#define F_OK 0
41#define access _access
42#else
43#include <unistd.h>
44#endif
45
46#define _DEVDEBUG_
47#include "YacsTrace.hxx"
48
49using namespace YACS::ENGINE;
50using namespace YACS;
51using namespace std;
52
53int driverTest(Proc* &p, const char* schema)
54{
55 DEBTRACE("+++++++++++++++++++ BEGIN test " << schema);
56 RuntimeSALOME::setRuntime();
57
59 Executor executor;
60
61 try
62 {
63 p=loader.load(schema);
64 DEBTRACE("Proc *p = " << p);
65 std::ofstream f("toto");
66 p->writeDot(f);
67 f.close();
68 DEBTRACE("+++++++++++++++++++ BEGIN execution " << schema);
69 executor.RunW(p,0);
70 DEBTRACE("+++++++++++++++++++ END execution " << schema);
71 std::ofstream g("titi");
72 p->writeDot(g);
73 g.close();
74 DEBTRACE("+++++++++++++++++++ END test " << schema);
75 return 0;
76 }
77 catch (YACS::Exception& e)
78 {
79 DEBTRACE("YACS exception caught: ");
80 DEBTRACE(e.what());
81 DEBTRACE("+++++++++++++++++++ END test in error " << schema);
82 return 1;
83 }
84 catch (const std::ios_base::failure&)
85 {
86 DEBTRACE("io failure");
87 DEBTRACE("+++++++++++++++++++ END test in error " << schema);
88 return 1;
89 }
90 catch(CORBA::SystemException& ex)
91 {
92 DEBTRACE("Caught a CORBA::SystemException.");
93 CORBA::Any tmp;
94 tmp <<= ex;
95 CORBA::TypeCode_var tc = tmp.type();
96 const char *p = tc->name();
97 if ( *p != '\0' )
98 {
99 DEBTRACE(p);
100 }
101 else
102 {
103 DEBTRACE(tc->id());
104 }
105 DEBTRACE("+++++++++++++++++++ END test in error " << schema);
106 return 1;
107 }
108 catch(omniORB::fatalException& fe)
109 {
110 DEBTRACE("Caught omniORB::fatalException:" );
111 DEBTRACE(" file: " << fe.file());
112 DEBTRACE(" line: " << fe.line());
113 DEBTRACE(" mesg: " << fe.errmsg());
114 DEBTRACE("+++++++++++++++++++ END test in error " << schema);
115 return 1;
116 }
117 catch(...)
118 {
119 DEBTRACE("Caught unknown exception.");
120 DEBTRACE("+++++++++++++++++++ END test in error " << schema);
121 return 1;
122 }
123}
124
125
127{
128 resourcesDir = "samples/";
129}
130
132{
133}
134
135
137{
138 std::string xmlFilename = resourcesDir + "schemaLR2.xml";
139 Proc *p = 0;
140 int ret = driverTest(p, xmlFilename.c_str() );
141 CPPUNIT_ASSERT(ret == 0);
142 DEBTRACE("Proc *p = " << p);
143 CPPUNIT_ASSERT(p != 0);
144 if (p)
145 {
146 YACS::ENGINE::Node* node = p->nodeMap[string("PyGetRes")];
147 YACS::ENGINE::OutputPort* outputPort = node->getOutputPort(string("res"));
148 string str = outputPort->getAsString();
149 DEBTRACE("str = " << str);
150 CPPUNIT_ASSERT_EQUAL(str, string("True"));
151 delete p;
152 }
153}
154
156{
157 std::string xmlFilename = resourcesDir + "schemaANN2.xml";
158 Proc *p = 0;
159 int ret = driverTest(p, xmlFilename.c_str() );
160 CPPUNIT_ASSERT(ret == 0);
161 DEBTRACE("Proc *p = " << p);
162 CPPUNIT_ASSERT(p != 0);
163 if (p)
164 {
165 YACS::ENGINE::Node* node = p->nodeMap[string("PyGetRes")];
166 YACS::ENGINE::OutputPort* outputPort = node->getOutputPort(string("res"));
167 string str = outputPort->getAsString();
168 DEBTRACE("str = " << str);
169 CPPUNIT_ASSERT_EQUAL(str, string("True"));
170 delete p;
171 }
172}
173
175{
176 std::string xmlFilename = resourcesDir + "schemaANNLR2.xml";
177 Proc *p = 0;
178 int ret = driverTest(p, xmlFilename.c_str() );
179 CPPUNIT_ASSERT(ret == 0);
180 DEBTRACE("Proc *p = " << p);
181 CPPUNIT_ASSERT(p != 0);
182 if (p)
183 {
184 YACS::ENGINE::Node* node = p->nodeMap[string("PyGetRes")];
185 YACS::ENGINE::OutputPort* outputPort = node->getOutputPort(string("res"));
186 string str = outputPort->getAsString();
187 DEBTRACE("str = " << str);
188 CPPUNIT_ASSERT_EQUAL(str, string("True"));
189 delete p;
190 }
191}
192
194{
195 std::string xmlFilename = resourcesDir + "schemaPmmlDoesNotExist.xml";
196 Proc *p = 0;
197 int ret = driverTest(p, xmlFilename.c_str() );
198 CPPUNIT_ASSERT(ret == 0);
199 DEBTRACE("Proc *p = " << p);
200 CPPUNIT_ASSERT(p != 0);
201 if (p)
202 {
203 YACS::ENGINE::Node* node = p->nodeMap[string("PyGetRes")];
204 YACS::ENGINE::OutputPort* outputPort = node->getOutputPort(string("res"));
205 string str = outputPort->getAsString();
206 DEBTRACE("str = " << str);
207 CPPUNIT_ASSERT_EQUAL(str, string("None"));
208 delete p;
209 }
210}
211
Header de la classe PMMLlib.
int driverTest(Proc *&p, const char *schema)
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
virtual std::string getAsString()
returns port value as a string that can be used in a GUI for example
Definition: DataPort.cxx:84
Threaded Executor.
Definition: Executor.hxx:63
void RunW(Scheduler *graph, int debug=0, bool fromScratch=true)
Definition: Executor.cxx:1833
Base class for all nodes.
Definition: Node.hxx:70
virtual OutputPort * getOutputPort(const std::string &name) const =0
Base class for all schema objects.
Definition: Proc.hxx:44
std::map< std::string, Node * > nodeMap
Definition: Proc.hxx:87
virtual void writeDot(std::ostream &os) const
Dump to the input stream a dot representation of the node.
Definition: Proc.cxx:86
const char * what(void) const noexcept
Definition: Exception.cxx:50
Proc * p
Definition: driver.cxx:216
YACS::YACSLoader::YACSLoader * loader
Definition: yacs_clt.cxx:31