Version: 8.3.0
YACSPMMLBasicsTest1.cxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 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 // Author : InckA
20 
21 
22 #include "YACSPMMLBasicsTest1.hxx"
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 
49 using namespace YACS::ENGINE;
50 using namespace YACS;
51 using namespace std;
52 
53 int driverTest(Proc* &p, const char* schema)
54 {
55  DEBTRACE("+++++++++++++++++++ BEGIN test " << schema);
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  CPPUNIT_ASSERT_EQUAL(str, string("True"));
150  delete p;
151  }
152 }
153 
155 {
156  std::string xmlFilename = resourcesDir + "schemaANN2.xml";
157  Proc *p = 0;
158  int ret = driverTest(p, xmlFilename.c_str() );
159  CPPUNIT_ASSERT(ret == 0);
160  DEBTRACE("Proc *p = " << p);
161  CPPUNIT_ASSERT(p != 0);
162  if (p)
163  {
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"));
168  delete p;
169  }
170 }
171 
173 {
174  std::string xmlFilename = resourcesDir + "schemaANNLR2.xml";
175  Proc *p = 0;
176  int ret = driverTest(p, xmlFilename.c_str() );
177  CPPUNIT_ASSERT(ret == 0);
178  DEBTRACE("Proc *p = " << p);
179  CPPUNIT_ASSERT(p != 0);
180  if (p)
181  {
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"));
186  delete p;
187  }
188 }
189 
191 {
192  std::string xmlFilename = resourcesDir + "schemaPmmlDoesNotExist.xml";
193  Proc *p = 0;
194  int ret = driverTest(p, xmlFilename.c_str() );
195  CPPUNIT_ASSERT(ret == 0);
196  DEBTRACE("Proc *p = " << p);
197  CPPUNIT_ASSERT(p != 0);
198  if (p)
199  {
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"));
204  delete p;
205  }
206 }
207