Salome HOME
27355adbaab1d40200fcee6714305faf8e75217a
[modules/yacs.git] / src / py2yacs / Test / test_py2yacs.cxx
1 // Copyright (C) 2017-2023  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 #include <iostream>
20 #include <fstream>
21 #include <sstream>
22 #include <cerrno>
23 #include "py2yacs.hxx"
24 #include "RuntimeSALOME.hxx"
25
26 /*
27 #include "Proc.hxx"
28 #include "Node.hxx"
29 #include "CORBAPorts.hxx"
30 #include "InputPort.hxx"
31 #include "Executor.hxx"
32 */
33
34 int main(int argc, char *argv[])
35 {
36   if (argc != 4)
37   {
38     std::cerr << "Usage: " <<  argv[0] << " pythonfile funcname outfile" << std::endl;
39     return 1;
40   }
41   YACS::ENGINE::RuntimeSALOME::setRuntime();
42   //Py_Initialize();
43   Py2yacs parser;
44   std::ifstream file_stream(argv[1]);
45   if(!file_stream)
46   {
47     std::cerr << "Error when opening file " << argv[1]
48              << ": " << strerror(errno)
49              << std::endl;
50     return 1;
51   }
52   std::stringstream buffer;
53   buffer << file_stream.rdbuf();
54   try
55   {
56     parser.load(buffer.str());
57     parser.save(argv[3], argv[2]);
58     
59     /*
60     YACS::ENGINE::Proc* p = parser.createProc(argv[2]);
61     //p->setInPortValue("Schema.default_name", "a", "42.");
62     YACS::ENGINE::Node* n = p->getChildByShortName("default_name");
63     //YACS::ENGINE::Node* n = p->nodeMap["default_name"];
64     if(!n)
65       std::cerr << "Node not found." << std::endl;
66     else
67       n->getInputPort("a")->edInit(42.);
68     p->saveSchema(argv[3]);
69     
70     YACS::ENGINE::Executor executor;
71     executor.RunW(p, 0);
72     n->getOutputPort("x")->dump();
73     */
74   }
75   catch(Py2yacsException& e)
76   {
77     std::cerr << e.what() << std::endl;
78   }
79   YACS::ENGINE::getRuntime()->fini();
80   //Py_Finalize();
81 }