]> SALOME platform Git repositories - modules/yacs.git/blobdiff - src/yacsloader/Test/YacsLoaderTest.cxx
Salome HOME
Optimize usage of context for PythonNode (by deleting input and output port PyObject...
[modules/yacs.git] / src / yacsloader / Test / YacsLoaderTest.cxx
index 95bd09c4cbb414835b4f0ab1462f5b3ecdd4e704..109145e8acee9f2458332a787080141c15836844 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2006-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -53,19 +53,24 @@ int driverTest(Proc* &p, const char* schema)
 
   YACSLoader loader;
   Executor executor;
-  
   try
     {
       p=loader.load(schema);
+        
+      std::cerr << __FILE__ << std::endl;
       DEBTRACE("Proc *p = " << p);
       std::ofstream f("toto");
       p->writeDot(f);
       f.close();
       DEBTRACE("+++++++++++++++++++ BEGIN execution " << schema);
+      std::cerr << __FILE__ << std::endl;    
       executor.RunW(p,0);
+      std::cerr << __FILE__ << std::endl;
+
       DEBTRACE("+++++++++++++++++++   END execution " << schema);
       std::ofstream g("titi");
       p->writeDot(g);
+      p->shutdown(10);
       g.close();
       DEBTRACE("+++++++++++++++++++ END test " << schema);
       return 0;
@@ -73,13 +78,20 @@ int driverTest(Proc* &p, const char* schema)
   catch (YACS::Exception& e)
     {
       DEBTRACE("YACS exception caught: ");
+        std::cerr << __FILE__ << std::endl;
       DEBTRACE(e.what());
+        std::cerr << __FILE__ << std::endl;
+
       DEBTRACE("+++++++++++++++++++ END test in error " << schema);
       return 1;
     }
   catch (const std::ios_base::failure&)
     {
+        std::cerr << __FILE__ << std::endl;
+
       DEBTRACE("io failure");
+  std::cerr << __FILE__ << std::endl;
+
       DEBTRACE("+++++++++++++++++++ END test in error " << schema);
       return 1;
     }
@@ -92,10 +104,13 @@ int driverTest(Proc* &p, const char* schema)
       const char *p = tc->name();
       if ( *p != '\0' )
         {
+            std::cerr << __FILE__ << std::endl;
+
           DEBTRACE(p);
         }
       else
         {
+  std::cerr << __FILE__ << std::endl;
           DEBTRACE(tc->id());
         }
       DEBTRACE("+++++++++++++++++++ END test in error " << schema);
@@ -190,6 +205,7 @@ void YacsLoaderTest::cschema()
               CPPUNIT_ASSERT_EQUAL(string("Hello Hello coucou!!"), string(text) );
             }
         }
+      p->shutdown(10);
       delete p;
     }
 #endif
@@ -223,6 +239,7 @@ void YacsLoaderTest::dschema()
               CPPUNIT_ASSERT_EQUAL( string("Hello Hello coucou!!"), string(text));
             }
         }
+      p->shutdown(10);
       delete p;
     }
 #endif
@@ -238,7 +255,7 @@ void YacsLoaderTest::eschema()
   if (p)
     {
       PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
-      char *text = PyString_AsString(data);
+      const char *text = PyUnicode_AsUTF8(data);
       CPPUNIT_ASSERT_EQUAL(string("coucoucoucoucoucoucoucou"), string(text));
       delete p;
     }
@@ -254,7 +271,7 @@ void YacsLoaderTest::fschema()
   if (p)
     {
       PyObject *data = ((OutputPyPort*)p->nodeMap["node2"]->getOutputPort("p1"))->get();
-      char *text = PyString_AsString(data);;
+      const char *text = PyUnicode_AsUTF8(data);
       CPPUNIT_ASSERT_EQUAL(string("coucoucoucoucoucoucoucou"), string(text) );
       delete p;
     }
@@ -637,7 +654,7 @@ void YacsLoaderTest::refcnt()
   ret = driverTest(p, "samples/refcnt2.xml");
   CPPUNIT_ASSERT(ret == 0);
   data = ((OutputPyPort*)p->nodeMap["b1.b.node1"]->getOutputPort("p1"))->get();
-  CPPUNIT_ASSERT(data->ob_refcnt==19);
+  CPPUNIT_ASSERT_EQUAL(data->ob_refcnt,(long int)13);
 }
 
 void YacsLoaderTest::foreachs()
@@ -647,30 +664,52 @@ void YacsLoaderTest::foreachs()
   ret = driverTest(p, "samples/foreach1.xml");
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach1.xml", ret == 0);
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach1.xml", p->getEffectiveState() == YACS::DONE);
+  delete p;
   ret = driverTest(p, "samples/foreach2.xml");
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach2.xml", ret == 0);
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach2.xml", p->getEffectiveState() == YACS::DONE );
+  delete p;
   ret = driverTest(p, "samples/foreach3.xml");
+  p->shutdown(10);
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach3.xml", ret == 1);
+  delete p;
   ret = driverTest(p, "samples/foreach4.xml");
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach4.xml", ret == 0);
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach4.xml", p->getEffectiveState() == YACS::DONE );
+  delete p;
   ret = driverTest(p, "samples/foreach5.xml");
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach5.xml", ret == 0);
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach5.xml", p->getEffectiveState() == YACS::DONE );
+  delete p;
   ret = driverTest(p, "samples/foreach6.xml");
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach6.xml", ret == 0);
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach6.xml", p->getEffectiveState() == YACS::DONE );
+  delete p;
+  ret = driverTest(p, "samples/foreach8.xml");
+  CPPUNIT_ASSERT_MESSAGE("Schema: foreach8.xml", ret == 0);
+  CPPUNIT_ASSERT_MESSAGE("Schema: foreach8.xml", p->getEffectiveState() == YACS::DONE );
+  p->shutdown(10);
+  delete p;
+  ret = driverTest(p, "samples/foreach_init2fin.xml");
+  CPPUNIT_ASSERT_MESSAGE("Schema: foreach_init2fin.xml", ret == 0);
+  CPPUNIT_ASSERT_MESSAGE("Schema: foreach_init2fin.xml", p->getEffectiveState() == YACS::DONE );
+  delete p;
+  ret = driverTest(p, "samples/foreach_init2work.xml");
+  CPPUNIT_ASSERT_MESSAGE("Schema: foreach_init2work.xml", ret == 0);
+  CPPUNIT_ASSERT_MESSAGE("Schema: foreach_init2work.xml", p->getEffectiveState() == YACS::DONE );
+  CPPUNIT_ASSERT_EQUAL(p->getOutputPort("PostProc.r")->getAsString(), std::string("108"));
+  delete p;
   if(getenv("GEOM_ROOT_DIR"))
     {
       std::string geomdir(getenv("GEOM_ROOT_DIR"));
       geomdir=geomdir+"/share/salome/resources/geom";
       if(access(geomdir.c_str(),F_OK) == 0)
-       {
-         ret = driverTest(p, "samples/foreach7.xml"); //needs GEOM_Superv component
-         CPPUNIT_ASSERT_MESSAGE("Schema: foreach7.xml", ret == 0);
-         CPPUNIT_ASSERT_MESSAGE("Schema: foreach7.xml", p->getEffectiveState() == YACS::DONE );
-       }
+      {
+        ret = driverTest(p, "samples/foreach7.xml"); //needs GEOM_Superv component
+        CPPUNIT_ASSERT_MESSAGE("Schema: foreach7.xml", ret == 0);
+        CPPUNIT_ASSERT_MESSAGE("Schema: foreach7.xml", p->getEffectiveState() == YACS::DONE );
+        delete p;
+      }
     }
 }
 
@@ -803,6 +842,22 @@ void YacsLoaderTest::optimizers()
   CPPUNIT_ASSERT(ret == 0);
   CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
   delete p;
+
+  ret = driverTest(p, "samples/optimizer_retro.xml");
+  CPPUNIT_ASSERT(ret == 0);
+  CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
+  delete p;
+
+  ret = driverTest(p, "samples/double_optimizer_py.xml");
+  CPPUNIT_ASSERT(ret == 0);
+  CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
+  delete p;
+
+  ret = driverTest(p, "samples/optimizer_pyobj.xml");
+  CPPUNIT_ASSERT(ret == 0);
+  CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
+  delete p;
+
 }
 
 void YacsLoaderTest::pyremotes()
@@ -822,3 +877,14 @@ void YacsLoaderTest::pyremotes()
   CPPUNIT_ASSERT(ret == 0);
   CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
 }
+
+void YacsLoaderTest::nonepyobj()
+{
+  Proc *p = 0;
+  int ret;
+  ret = driverTest(p, "samples/nonepyobj.xml");
+  CPPUNIT_ASSERT(ret == 0);
+  CPPUNIT_ASSERT(p->getEffectiveState() == YACS::DONE );
+  CPPUNIT_ASSERT_EQUAL(p->getOutputPort("n2.r")->getAsString(), std::string("True"));
+  delete p;
+}