1 // Copyright (C) 2007-2015 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 CPPUNIT_ASSERT_EQUAL(str, string("True"));
154 void YACSPMMLBasicsTest1::testYACSdriverNeuralNetwork()
156 std::string xmlFilename = resourcesDir + "schemaANN2.xml";
158 int ret = driverTest(p, xmlFilename.c_str() );
159 CPPUNIT_ASSERT(ret == 0);
160 DEBTRACE("Proc *p = " << p);
161 CPPUNIT_ASSERT(p != 0);
164 YACS::ENGINE::Node* node = p->nodeMap[string("PyGetRes")];
165 YACS::ENGINE::OutputPort* outputPort = node->getOutputPort(string("res"));
166 string str = outputPort->getAsString();
167 CPPUNIT_ASSERT_EQUAL(str, string("True"));
172 void YACSPMMLBasicsTest1::testYACSdriver_LRANN()
174 std::string xmlFilename = resourcesDir + "schemaANNLR2.xml";
176 int ret = driverTest(p, xmlFilename.c_str() );
177 CPPUNIT_ASSERT(ret == 0);
178 DEBTRACE("Proc *p = " << p);
179 CPPUNIT_ASSERT(p != 0);
182 YACS::ENGINE::Node* node = p->nodeMap[string("PyGetRes")];
183 YACS::ENGINE::OutputPort* outputPort = node->getOutputPort(string("res"));
184 string str = outputPort->getAsString();
185 CPPUNIT_ASSERT_EQUAL(str, string("True"));
190 void YACSPMMLBasicsTest1::testYACSdriver_PmmlDoesNotExist()
192 std::string xmlFilename = resourcesDir + "schemaPmmlDoesNotExist.xml";
194 int ret = driverTest(p, xmlFilename.c_str() );
195 CPPUNIT_ASSERT(ret == 0);
196 DEBTRACE("Proc *p = " << p);
197 CPPUNIT_ASSERT(p != 0);
200 YACS::ENGINE::Node* node = p->nodeMap[string("PyGetRes")];
201 YACS::ENGINE::OutputPort* outputPort = node->getOutputPort(string("res"));
202 string str = outputPort->getAsString();
203 CPPUNIT_ASSERT_EQUAL(str, string("None"));