1 // Copyright (C) 2007-2014 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()
129 const char* p = std::getenv("YACS_ROOT_DIR");
130 std::string strP("");
132 strP = std::string(p);
134 throw std::string("unable to get YACS_ROOT_DIR");
136 resourcesDir += "/share/salome/yacssamples/";
138 resourcesDir = getenv("YACS_ROOT_DIR");
139 resourcesDir += "/share/salome/yacssamples/";
143 void YACSPMMLBasicsTest1::tearDown()
148 void YACSPMMLBasicsTest1::testYACSdriverLinearRegression()
150 std::string xmlFilename = resourcesDir + "schemaLR2.xml";
152 int ret = driverTest(p, xmlFilename.c_str() );
153 CPPUNIT_ASSERT(ret == 0);
154 DEBTRACE("Proc *p = " << p);
155 CPPUNIT_ASSERT(p != 0);
158 YACS::ENGINE::Node* node = p->nodeMap[string("PyGetRes")];
159 YACS::ENGINE::OutputPort* outputPort = node->getOutputPort(string("res"));
160 string str = outputPort->getAsString();
161 CPPUNIT_ASSERT_EQUAL(str, string("True"));
166 void YACSPMMLBasicsTest1::testYACSdriverNeuralNetwork()
168 std::string xmlFilename = resourcesDir + "schemaANN2.xml";
170 int ret = driverTest(p, xmlFilename.c_str() );
171 CPPUNIT_ASSERT(ret == 0);
172 DEBTRACE("Proc *p = " << p);
173 CPPUNIT_ASSERT(p != 0);
176 YACS::ENGINE::Node* node = p->nodeMap[string("PyGetRes")];
177 YACS::ENGINE::OutputPort* outputPort = node->getOutputPort(string("res"));
178 string str = outputPort->getAsString();
179 CPPUNIT_ASSERT_EQUAL(str, string("True"));
184 void YACSPMMLBasicsTest1::testYACSdriver_LRANN()
186 std::string xmlFilename = resourcesDir + "schemaANNLR2.xml";
188 int ret = driverTest(p, xmlFilename.c_str() );
189 CPPUNIT_ASSERT(ret == 0);
190 DEBTRACE("Proc *p = " << p);
191 CPPUNIT_ASSERT(p != 0);
194 YACS::ENGINE::Node* node = p->nodeMap[string("PyGetRes")];
195 YACS::ENGINE::OutputPort* outputPort = node->getOutputPort(string("res"));
196 string str = outputPort->getAsString();
197 CPPUNIT_ASSERT_EQUAL(str, string("True"));
202 void YACSPMMLBasicsTest1::testYACSdriver_PmmlDoesNotExist()
204 std::string xmlFilename = resourcesDir + "schemaPmmlDoesNotExist.xml";
206 int ret = driverTest(p, xmlFilename.c_str() );
207 CPPUNIT_ASSERT(ret == 0);
208 DEBTRACE("Proc *p = " << p);
209 CPPUNIT_ASSERT(p != 0);
212 YACS::ENGINE::Node* node = p->nodeMap[string("PyGetRes")];
213 YACS::ENGINE::OutputPort* outputPort = node->getOutputPort(string("res"));
214 string str = outputPort->getAsString();
215 CPPUNIT_ASSERT_EQUAL(str, string("None"));