1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "YACSPMMLBasicsTest1.hxx"
23 #include "PMMLlib.hxx"
25 #include "yacsconfig.h"
26 #include "RuntimeSALOME.hxx"
27 #include "PythonPorts.hxx"
28 #include "CORBAPorts.hxx"
29 #include "parsers.hxx"
31 #include "Exception.hxx"
32 #include "Executor.hxx"
33 #include "parsers.hxx"
41 #define access _access
47 #include "YacsTrace.hxx"
49 using namespace YACS::ENGINE;
53 int driverTest(Proc* &p, const char* schema)
55 DEBTRACE("+++++++++++++++++++ BEGIN test " << schema);
56 RuntimeSALOME::setRuntime();
63 p=loader.load(schema);
64 DEBTRACE("Proc *p = " << p);
65 std::ofstream f("toto");
68 DEBTRACE("+++++++++++++++++++ BEGIN execution " << schema);
70 DEBTRACE("+++++++++++++++++++ END execution " << schema);
71 std::ofstream g("titi");
74 DEBTRACE("+++++++++++++++++++ END test " << schema);
77 catch (YACS::Exception& e)
79 DEBTRACE("YACS exception caught: ");
81 DEBTRACE("+++++++++++++++++++ END test in error " << schema);
84 catch (const std::ios_base::failure&)
86 DEBTRACE("io failure");
87 DEBTRACE("+++++++++++++++++++ END test in error " << schema);
90 catch(CORBA::SystemException& ex)
92 DEBTRACE("Caught a CORBA::SystemException.");
95 CORBA::TypeCode_var tc = tmp.type();
96 const char *p = tc->name();
105 DEBTRACE("+++++++++++++++++++ END test in error " << schema);
108 catch(omniORB::fatalException& fe)
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);
119 DEBTRACE("Caught unknown exception.");
120 DEBTRACE("+++++++++++++++++++ END test in error " << schema);
126 void YACSPMMLBasicsTest1::setUp()
128 resourcesDir = "samples/";
131 void YACSPMMLBasicsTest1::tearDown()
136 void YACSPMMLBasicsTest1::testYACSdriverLinearRegression()
138 std::string xmlFilename = resourcesDir + "schemaLR2.xml";
140 int ret = driverTest(p, xmlFilename.c_str() );
141 CPPUNIT_ASSERT(ret == 0);
142 DEBTRACE("Proc *p = " << p);
143 CPPUNIT_ASSERT(p != 0);
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"));
155 void YACSPMMLBasicsTest1::testYACSdriverNeuralNetwork()
157 std::string xmlFilename = resourcesDir + "schemaANN2.xml";
159 int ret = driverTest(p, xmlFilename.c_str() );
160 CPPUNIT_ASSERT(ret == 0);
161 DEBTRACE("Proc *p = " << p);
162 CPPUNIT_ASSERT(p != 0);
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"));
174 void YACSPMMLBasicsTest1::testYACSdriver_LRANN()
176 std::string xmlFilename = resourcesDir + "schemaANNLR2.xml";
178 int ret = driverTest(p, xmlFilename.c_str() );
179 CPPUNIT_ASSERT(ret == 0);
180 DEBTRACE("Proc *p = " << p);
181 CPPUNIT_ASSERT(p != 0);
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"));
193 void YACSPMMLBasicsTest1::testYACSdriver_PmmlDoesNotExist()
195 std::string xmlFilename = resourcesDir + "schemaPmmlDoesNotExist.xml";
197 int ret = driverTest(p, xmlFilename.c_str() );
198 CPPUNIT_ASSERT(ret == 0);
199 DEBTRACE("Proc *p = " << p);
200 CPPUNIT_ASSERT(p != 0);
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"));