From: Anthony Geay Date: Thu, 6 Sep 2018 08:48:27 +0000 (+0200) Subject: [EDF17719] : Comparison between 2 objects is now a user defined function called ... X-Git-Tag: V9_1_0~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c2c1a75bf40fde2010d34d07f999ffb7e6b13304;p=modules%2Fkernel.git [EDF17719] : Comparison between 2 objects is now a user defined function called "comptchev" instead of SHA1 --- diff --git a/idl/SALOME_SDS.idl b/idl/SALOME_SDS.idl index 09401cd00..97ed6aa90 100644 --- a/idl/SALOME_SDS.idl +++ b/idl/SALOME_SDS.idl @@ -140,7 +140,7 @@ module SALOME void fetchAndGetAccessOfVar(in string varName, out string access, out ByteVec data) raises (SALOME::SALOME_Exception); Transaction createRdOnlyVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception); Transaction createRdExtVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception); - Transaction createRdExtVarFreeStyleTransac(in string varName, in ByteVec constValue, in ByteVec sha1) raises (SALOME::SALOME_Exception); + Transaction createRdExtVarFreeStyleTransac(in string varName, in ByteVec constValue, in string compareFuncContent) raises (SALOME::SALOME_Exception); Transaction createRdExtInitVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception); Transaction createRdWrVarTransac(in string varName, in ByteVec constValue) raises (SALOME::SALOME_Exception); Transaction addKeyValueInVarHard(in string varName, in ByteVec keyValue, in ByteVec constValue) raises (SALOME::SALOME_Exception); diff --git a/src/SALOMESDS/SALOMESDS_Auto.hxx b/src/SALOMESDS/SALOMESDS_Auto.hxx new file mode 100644 index 000000000..a9220f518 --- /dev/null +++ b/src/SALOMESDS/SALOMESDS_Auto.hxx @@ -0,0 +1,47 @@ +// Copyright (C) 2018 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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, 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 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony GEAY (EDF R&D) + +#pragma once + +#include "Python.h" + +namespace SALOME +{ + class AutoPyRef + { + public: + AutoPyRef(PyObject *pyobj=nullptr):_pyobj(pyobj) { } + ~AutoPyRef() { release(); } + AutoPyRef(const AutoPyRef& other):_pyobj(other._pyobj) { if(_pyobj) Py_XINCREF(_pyobj); } + AutoPyRef(AutoPyRef&& other):_pyobj(other._pyobj) { other._pyobj=nullptr; } + AutoPyRef& operator=(const AutoPyRef& other) { if(_pyobj==other._pyobj) return *this; release(); _pyobj=other._pyobj; Py_XINCREF(_pyobj); return *this; } + AutoPyRef& operator=(AutoPyRef&& other) { if(_pyobj==other._pyobj) return *this; release(); _pyobj=other._pyobj; other._pyobj=nullptr; return *this; } + operator PyObject *() { return _pyobj; } + void set(PyObject *pyobj) { if(pyobj==_pyobj) return ; release(); _pyobj=pyobj; } + PyObject *get() { return _pyobj; } + bool isNull() const { return _pyobj==nullptr; } + PyObject *retn() { if(_pyobj) Py_XINCREF(_pyobj); return _pyobj; } + private: + void release() { if(_pyobj) Py_XDECREF(_pyobj); _pyobj=nullptr; } + private: + PyObject *_pyobj; + }; +} + diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index 4476e1333..d8b70ef3a 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -604,11 +604,11 @@ void DataScopeServerTransaction::createRdExtVarInternal(const std::string& varNa _vars.push_back(p); } -void DataScopeServerTransaction::createRdExtVarFreeStyleInternal(const std::string& varName, const SALOME::ByteVec& constValue, std::vector&& sha1) +void DataScopeServerTransaction::createRdExtVarFreeStyleInternal(const std::string& varName, const SALOME::ByteVec& constValue, std::string&& compareFuncContent, SALOME::AutoPyRef&& compareFunc) { if(!isExistingVar(varName)) { - PickelizedPyObjRdExtFreeStyleServer *tmp(new PickelizedPyObjRdExtFreeStyleServer(this,varName,constValue,std::move(sha1))); + PickelizedPyObjRdExtFreeStyleServer *tmp(new PickelizedPyObjRdExtFreeStyleServer(this,varName,constValue,std::move(compareFuncContent),std::move(compareFunc))); CORBA::Object_var ret(tmp->activate()); std::pair< SALOME::BasicDataServer_var, BasicDataServer * > p(SALOME::BasicDataServer::_narrow(ret),tmp); _vars.push_back(p); @@ -626,10 +626,26 @@ void DataScopeServerTransaction::createRdExtVarFreeStyleInternal(const std::stri if(!ds2) { std::ostringstream oss; - oss << "DataScopeServerTransaction::createRdExtVarFreeStyleInternal : varname \"" << varName << "\" already exists with a non RdExtFreeStyle type !"; + oss << "DataScopeServerTransaction::createRdExtVarFreeStyleInternal : varname \"" << varName << "\" already exists with a non Sha1Keeper type !"; throw Exception(oss.str()); } - ds2->checkSha1(varName,sha1); + PickelizedPyObjServer *ds3(dynamic_cast(ds)); + if(!ds3) + { + std::ostringstream oss; + oss << "DataScopeServerTransaction::createRdExtVarFreeStyleInternal : varname \"" << varName << "\" already exists with a non PickelizedPyObjServer type !"; + throw Exception(oss.str()); + } + std::vector constValueAsCpp; + Transaction::FromByteSeqToVB(constValue,constValueAsCpp); + SALOME::AutoPyRef newObj(PickelizedPyObjServer::GetPyObjFromPickled(constValueAsCpp,this)); + if(newObj.isNull()) + { + std::ostringstream oss; + oss << "DataScopeServerTransaction::createRdExtVarFreeStyleInternal : varname \"" << varName << "\" already exists but input pickelized object is not loadable !"; + throw Exception(oss.str()); + } + ds2->checkSame(varName,compareFuncContent,ds3->getPyObj(),newObj); } } @@ -667,9 +683,9 @@ SALOME::Transaction_ptr DataScopeServerTransaction::createRdExtVarTransac(const return SALOME::Transaction::_narrow(obj); } -SALOME::Transaction_ptr DataScopeServerTransaction::createRdExtVarFreeStyleTransac(const char *varName, const SALOME::ByteVec& constValue, const SALOME::ByteVec& sha1) +SALOME::Transaction_ptr DataScopeServerTransaction::createRdExtVarFreeStyleTransac(const char *varName, const SALOME::ByteVec& constValue, const char *compareFuncContent) {// no check on varName done here. Will be done on perform - TransactionRdExtVarFreeStyleCreate *ret(new TransactionRdExtVarFreeStyleCreate(this,varName,constValue,sha1)); + TransactionRdExtVarFreeStyleCreate *ret(new TransactionRdExtVarFreeStyleCreate(this,varName,constValue,compareFuncContent)); CORBA::Object_var obj(ret->activate()); return SALOME::Transaction::_narrow(obj); } diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index 58b16e57e..47135c422 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -28,6 +28,7 @@ #include "SALOMESDS_RefCountServ.hxx" #include "SALOMESDS_AutoRefCountPtr.hxx" #include "SALOMESDS_BasicDataServer.hxx" +#include "SALOMESDS_Auto.hxx" #include "SALOMESDS_Defines.hxx" #include @@ -144,7 +145,7 @@ namespace SALOMESDS ~DataScopeServerTransaction(); void createRdOnlyVarInternal(const std::string& varName, const SALOME::ByteVec& constValue); void createRdExtVarInternal(const std::string& varName, const SALOME::ByteVec& constValue); - void createRdExtVarFreeStyleInternal(const std::string& varName, const SALOME::ByteVec& constValue, std::vector&& sha1); + void createRdExtVarFreeStyleInternal(const std::string& varName, const SALOME::ByteVec& constValue, std::string&& compareFuncContent, SALOME::AutoPyRef&& compareFunc); void createRdExtInitVarInternal(const std::string& varName, const SALOME::ByteVec& constValue); void createRdWrVarInternal(const std::string& varName, const SALOME::ByteVec& constValue); PortableServer::POA_var getPOA4KeyWaiter() const { return _poa_for_key_waiter; } @@ -158,7 +159,7 @@ namespace SALOMESDS void fetchAndGetAccessOfVar(const char *varName, CORBA::String_out access, SALOME::ByteVec_out data); SALOME::Transaction_ptr createRdOnlyVarTransac(const char *varName, const SALOME::ByteVec& constValue); SALOME::Transaction_ptr createRdExtVarTransac(const char *varName, const SALOME::ByteVec& constValue); - SALOME::Transaction_ptr createRdExtVarFreeStyleTransac(const char *varName, const SALOME::ByteVec& constValue, const SALOME::ByteVec& sha1); + SALOME::Transaction_ptr createRdExtVarFreeStyleTransac(const char *varName, const SALOME::ByteVec& constValue, const char *compareFuncContent); SALOME::Transaction_ptr createRdExtInitVarTransac(const char *varName, const SALOME::ByteVec& constValue); SALOME::Transaction_ptr createRdWrVarTransac(const char *varName, const SALOME::ByteVec& constValue); SALOME::Transaction_ptr addKeyValueInVarHard(const char *varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value); diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.cxx index 1d0afd7cf..41a241142 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.cxx @@ -79,5 +79,5 @@ PyObject *PickelizedPyObjRdExtInitServer::DeepCopyPyObj(PyObject *pyobj) PickelizedPyObjRdExtServer *PickelizedPyObjRdExtInitFreeStyleServer::buildStdInstanceFrom(const std::string& varName) { PyObject *pyobj(this->getPyObj()); Py_XINCREF(pyobj); - return new PickelizedPyObjRdExtFreeStyleServer(getFather(),varName,pyobj,std::move(_sha1)); + return new PickelizedPyObjRdExtFreeStyleServer(getFather(),varName,pyobj,std::move(_cmp_func_content),std::move(_cmp_func)); } diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.hxx index d9e4213e2..2580bc567 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.hxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtInitServer.hxx @@ -62,7 +62,7 @@ namespace SALOMESDS class PickelizedPyObjRdExtInitFreeStyleServer : public PickelizedPyObjRdExtInitServer, public Sha1Keeper { public: - PickelizedPyObjRdExtInitFreeStyleServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj, std::vector&& sha1):PickelizedPyObjRdExtInitServer(father,varName,obj),Sha1Keeper(std::move(sha1)) { } + PickelizedPyObjRdExtInitFreeStyleServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj, std::string&& compareFuncContent, SALOME::AutoPyRef&& compareFunc):PickelizedPyObjRdExtInitServer(father,varName,obj),Sha1Keeper(std::move(compareFuncContent),std::move(compareFunc)) { } PickelizedPyObjRdExtServer *buildStdInstanceFrom(const std::string& varName) override; }; } diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx index 674efef0f..d1e5a751a 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.cxx @@ -154,5 +154,5 @@ std::string PickelizedPyObjRdExtServer::getAccessStr() const PickelizedPyObjRdExtInitServer *PickelizedPyObjRdExtFreeStyleServer::buildInitInstanceFrom(const std::string& varName) { PyObject *pyobj(this->getPyObj()); Py_XINCREF(pyobj); - return new PickelizedPyObjRdExtInitFreeStyleServer(getFather(),varName,pyobj,std::move(_sha1)); + return new PickelizedPyObjRdExtInitFreeStyleServer(getFather(),varName,pyobj,std::move(_cmp_func_content),std::move(_cmp_func)); } diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx index c4fbf3a9a..aad56c9e2 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjRdExtServer.hxx @@ -55,8 +55,8 @@ namespace SALOMESDS class PickelizedPyObjRdExtFreeStyleServer : public PickelizedPyObjRdExtServer, public Sha1Keeper { public: - PickelizedPyObjRdExtFreeStyleServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value, std::vector&& sha1):PickelizedPyObjRdExtServer(father,varName,value),Sha1Keeper(std::move(sha1)) { } - PickelizedPyObjRdExtFreeStyleServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj, std::vector&& sha1):PickelizedPyObjRdExtServer(father,varName,obj),Sha1Keeper(std::move(sha1)) { } + PickelizedPyObjRdExtFreeStyleServer(DataScopeServerBase *father, const std::string& varName, const SALOME::ByteVec& value, std::string&& compareFuncContent, SALOME::AutoPyRef&& compareFunc):PickelizedPyObjRdExtServer(father,varName,value),Sha1Keeper(std::move(compareFuncContent),std::move(compareFunc)) { } + PickelizedPyObjRdExtFreeStyleServer(DataScopeServerBase *father, const std::string& varName, PyObject *obj, std::string&& compareFuncContent, SALOME::AutoPyRef&& compareFunc):PickelizedPyObjRdExtServer(father,varName,obj),Sha1Keeper(std::move(compareFuncContent),std::move(compareFunc)) { } PickelizedPyObjRdExtInitServer *buildInitInstanceFrom(const std::string& varName) override; }; } diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx index 6257bbaac..012310069 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx @@ -135,7 +135,7 @@ PyObject *PickelizedPyObjServer::GetPyObjFromPickled(const std::vectorgetPickler(),"loads")); PyObject *args(PyTuple_New(1)); PyTuple_SetItem(args,0,pickledDataPy); diff --git a/src/SALOMESDS/SALOMESDS_Sha1Keeper.cxx b/src/SALOMESDS/SALOMESDS_Sha1Keeper.cxx index 10a4153e5..8f63555db 100644 --- a/src/SALOMESDS/SALOMESDS_Sha1Keeper.cxx +++ b/src/SALOMESDS/SALOMESDS_Sha1Keeper.cxx @@ -23,11 +23,27 @@ #include -void SALOMESDS::Sha1Keeper::checkSha1(const std::string& varName, const std::vector& sha1) const +void SALOMESDS::Sha1Keeper::checkSame(const std::string& varName,const std::string& compareFuncContent, PyObject *oldObj, PyObject *newObj) { - if(sha1!=_sha1) + if(compareFuncContent!=_cmp_func_content) { - std::ostringstream oss; oss << "PickelizedPyObjRdExtFreeStyleServer::checkSha1 : SHA1 check fails ! Attempt of corruption of rdext data ! It means that var \"" << varName << "\" has been created but with an initial value different from the new value !"; + std::ostringstream oss; oss << "PickelizedPyObjRdExtFreeStyleServer::checkSame : content of compare func are not exactly the same ! It should !"; + throw Exception(oss.str()); + } + SALOME::AutoPyRef resu(PyObject_CallFunctionObjArgs(_cmp_func,oldObj,newObj,nullptr)); + if(resu.isNull()) + { + std::ostringstream oss; oss << "PickelizedPyObjRdExtFreeStyleServer::checkSame : evaluation of function failed !"; + throw Exception(oss.str()); + } + if(resu.get()!=Py_False && resu.get()!=Py_True) + { + std::ostringstream oss; oss << "PickelizedPyObjRdExtFreeStyleServer::checkSame : evaluation of function is OK but a boolean is expected !"; + throw Exception(oss.str()); + } + if(resu.get()==Py_False) + { + std::ostringstream oss; oss << "PickelizedPyObjRdExtFreeStyleServer::checkSame : comparison function returns False. 2 pybjects are considered different -> createRdExtVarFreeStyleTransac fails !"; throw Exception(oss.str()); } } diff --git a/src/SALOMESDS/SALOMESDS_Sha1Keeper.hxx b/src/SALOMESDS/SALOMESDS_Sha1Keeper.hxx index 497e2066c..913a78540 100644 --- a/src/SALOMESDS/SALOMESDS_Sha1Keeper.hxx +++ b/src/SALOMESDS/SALOMESDS_Sha1Keeper.hxx @@ -20,6 +20,8 @@ #pragma once +#include "SALOMESDS_Auto.hxx" + #include #include @@ -28,12 +30,12 @@ namespace SALOMESDS class Sha1Keeper { public: - Sha1Keeper(std::vector&& sha1):_sha1(std::move(sha1)) { } - void checkSha1(const std::string& varName, const std::vector& sha1) const; + Sha1Keeper(std::string&& compareFuncContent, SALOME::AutoPyRef&& compareFunc):_cmp_func_content(std::move(compareFuncContent)),_cmp_func(std::move(compareFunc)) { } + void checkSame(const std::string& varName,const std::string& compareFuncContent, PyObject *oldObj, PyObject *newObj); virtual ~Sha1Keeper() { } protected: - //! This sha1 is a discriminant key that allows RdExt "FreeStyle" methods to ensure that a "creation" over an already present var is legal or illegal. - std::vector _sha1; + std::string _cmp_func_content; + SALOME::AutoPyRef _cmp_func; }; } diff --git a/src/SALOMESDS/SALOMESDS_Transaction.cxx b/src/SALOMESDS/SALOMESDS_Transaction.cxx index 29d9a3ed8..61e720a3c 100644 --- a/src/SALOMESDS/SALOMESDS_Transaction.cxx +++ b/src/SALOMESDS/SALOMESDS_Transaction.cxx @@ -87,9 +87,28 @@ void TransactionRdExtVarCreate::perform() _dsct->createRdExtVarInternal(_var_name,data2); } -TransactionRdExtVarFreeStyleCreate::TransactionRdExtVarFreeStyleCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue, const SALOME::ByteVec& sha1):TransactionRdExtVarCreate(dsct,varName,constValue) +TransactionRdExtVarFreeStyleCreate::TransactionRdExtVarFreeStyleCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue, const char *compareFuncContent):_cmp_func_content(compareFuncContent),_cmp_func(nullptr),TransactionRdExtVarCreate(dsct,varName,constValue) { - FromByteSeqToVB(sha1,_sha1); + constexpr char EXPECTED_COMPARE_FUNC_NAME[]="comptchev"; + SALOME::AutoPyRef context(PyDict_New()); + SALOME::AutoPyRef res(PyRun_String(compareFuncContent,Py_file_input,_dsct->getGlobals(),context)); + if(res.isNull()) + { + std::ostringstream oss; oss << "TransactionRdExtVarFreeStyleCreate ctor : Fail to parse and evaluate \"" << compareFuncContent << "\" as python function !"; + throw Exception(oss.str()); + } + PyObject *func(PyDict_GetItemString(context,EXPECTED_COMPARE_FUNC_NAME));//borrowed + if(!func) + { + std::ostringstream oss; oss << "TransactionRdExtVarFreeStyleCreate ctor : Parsing of func is OK but not func called \"" << EXPECTED_COMPARE_FUNC_NAME << "\" is the given parsed string !"; + throw Exception(oss.str()); + } + _cmp_func = func; Py_XINCREF(func); + if(PyDict_DelItemString(context,EXPECTED_COMPARE_FUNC_NAME)!=0) + { + std::ostringstream oss; oss << "TransactionRdExtVarFreeStyleCreate ctor : Internal error during suppression of \"" << EXPECTED_COMPARE_FUNC_NAME << "\" key that exepect to be present ! Smells bad !"; + throw Exception(oss.str()); + } } void TransactionRdExtVarFreeStyleCreate::prepareRollBackInCaseOfFailure() @@ -100,7 +119,7 @@ void TransactionRdExtVarFreeStyleCreate::perform() { SALOME::ByteVec data2; FromVBToByteSeq(_data,data2); - _dsct->createRdExtVarFreeStyleInternal(_var_name,data2,std::move(_sha1)); + _dsct->createRdExtVarFreeStyleInternal(_var_name,data2,std::move(_cmp_func_content),std::move(_cmp_func)); } void TransactionRdExtInitVarCreate::perform() diff --git a/src/SALOMESDS/SALOMESDS_Transaction.hxx b/src/SALOMESDS/SALOMESDS_Transaction.hxx index 4152bebd4..3ddbc8204 100644 --- a/src/SALOMESDS/SALOMESDS_Transaction.hxx +++ b/src/SALOMESDS/SALOMESDS_Transaction.hxx @@ -27,6 +27,7 @@ #include "SALOMESDS_Defines.hxx" #include "SALOMESDS_Exception.hxx" #include "SALOMESDS_DataServerManager.hxx" +#include "SALOMESDS_Auto.hxx" #include #include @@ -86,11 +87,12 @@ namespace SALOMESDS class TransactionRdExtVarFreeStyleCreate : public TransactionRdExtVarCreate { public: - TransactionRdExtVarFreeStyleCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue, const SALOME::ByteVec& sha1); + TransactionRdExtVarFreeStyleCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue, const char *compareFuncContent); void prepareRollBackInCaseOfFailure(); void perform(); protected: - std::vector _sha1; + std::string _cmp_func_content; + SALOME::AutoPyRef _cmp_func; }; class TransactionRdExtInitVarCreate : public TransactionVarCreate diff --git a/src/SALOMESDS/TestSalomeSDS.py b/src/SALOMESDS/TestSalomeSDS.py index 442007ebf..a9458376a 100644 --- a/src/SALOMESDS/TestSalomeSDS.py +++ b/src/SALOMESDS/TestSalomeSDS.py @@ -349,7 +349,10 @@ class SalomeSDSTest(unittest.TestCase): pass def testTransaction8(self): - """ EDF 16833 """ + """ EDF 16833 and EDF17719 """ + funcContent="""def comptchev(a,b): + return "d" not in a +""" scopeName="ScopePP" dsm=salome.naming_service.Resolve("/DataServerManager") dsm.cleanScopesInNS() @@ -360,24 +363,33 @@ class SalomeSDSTest(unittest.TestCase): value={"a":1,"b":2} value2={'a':1,'c':3,'b':2} + value3={'a':1,'c':3,'b':2,'d':4} varName="abc" - t0=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),"sha1".encode()) # sha1 is the key used to compare the initial value + t0=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),funcContent) # sha1 is the key used to compare the initial value dss.atomicApply([t0]) self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value) t1=dss.addMultiKeyValueSession(varName) t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("c"),obj2Str(3)) dss.atomicApply([t1]) self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value2) - t2=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),"sha1".encode()) # key is the same as original one -> OK + t2=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),funcContent) # func says OK this is the same (even if it is not the case) as original one -> OK dss.atomicApply([t2]) self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value2) # value2 remains untouched - t3=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),"sha2".encode()) - self.assertRaises(SALOME.SALOME_Exception,dss.atomicApply,[t3]) # sha2 != sha1 -> rejected + t3=dss.addMultiKeyValueSession(varName) + t3.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("d"),obj2Str(4)) + dss.atomicApply([t3]) + self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value3) + t4=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),funcContent) + self.assertRaises(SALOME.SALOME_Exception,dss.atomicApply,[t4]) # d is in dict pointed by var. Func returns false -> rejected + self.assertRaises(SALOME.SALOME_Exception,dss.fetchSerializedContent,varName) # creation in the previous line fails -> the var has been removed pass def testTransaction9(self): - """ EDF 16833 : use case 2. Trying to createRdExt during add key session""" + """ EDF 16833 and EDF17719 : use case 2. Trying to createRdExt during add key session""" + funcContent="""def comptchev(a,b): + return a==b +""" scopeName="ScopePP" dsm=salome.naming_service.Resolve("/DataServerManager") dsm.cleanScopesInNS() @@ -390,11 +402,11 @@ class SalomeSDSTest(unittest.TestCase): value2={'a':1,'c':3,'b':2} varName="abc" - t0=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),"sha1".encode()) + t0=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),funcContent) dss.atomicApply([t0]) self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value) t1=dss.addMultiKeyValueSession(varName) - t2=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),"sha1".encode()) + t2=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),funcContent) dss.atomicApply([t2]) self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value) t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("c"),obj2Str(3))