From 24f6c999bc8106e39ed005a3889b3f1b1ef9abec Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 25 Aug 2011 12:37:57 +0000 Subject: [PATCH] Correction of bug on copyTinyAttrFrom. --- .../MEDCouplingTimeDiscretization.cxx | 52 +++++++++++-------- .../MEDCouplingTimeDiscretization.hxx | 8 +-- .../Test/MEDCouplingBasicsTest.hxx | 2 + .../Test/MEDCouplingBasicsTest4.cxx | 15 ++++++ src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 10 ++++ 5 files changed, 60 insertions(+), 27 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index c4b277a2c..9800c8baf 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -62,7 +62,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::New(TypeOfTimeDisc } } -void MEDCouplingTimeDiscretization::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) +void MEDCouplingTimeDiscretization::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception) { _time_tolerance=other._time_tolerance; _time_unit=other._time_unit; @@ -1273,13 +1273,15 @@ bool MEDCouplingWithTimeStep::isEqualWithoutConsideringStr(const MEDCouplingTime return MEDCouplingTimeDiscretization::isEqualWithoutConsideringStr(other,prec); } -void MEDCouplingWithTimeStep::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) +void MEDCouplingWithTimeStep::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception) { MEDCouplingTimeDiscretization::copyTinyAttrFrom(other); - const MEDCouplingWithTimeStep& otherC=dynamic_cast(other); - _time=otherC._time; - _iteration=otherC._iteration; - _order=otherC._order; + const MEDCouplingWithTimeStep *otherC=dynamic_cast(&other); + if(!otherC) + throw INTERP_KERNEL::Exception("MEDCouplingWithTimeStep::copyTinyAttrFrom : mismatch of time discretization !"); + _time=otherC->_time; + _iteration=otherC->_iteration; + _order=otherC->_order; } MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::aggregate(const MEDCouplingTimeDiscretization *other) const @@ -1527,16 +1529,18 @@ MEDCouplingConstOnTimeInterval::MEDCouplingConstOnTimeInterval():_start_time(0.) { } -void MEDCouplingConstOnTimeInterval::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) +void MEDCouplingConstOnTimeInterval::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception) { MEDCouplingTimeDiscretization::copyTinyAttrFrom(other); - const MEDCouplingConstOnTimeInterval& otherC=dynamic_cast(other); - _start_time=otherC._start_time; - _end_time=otherC._end_time; - _start_iteration=otherC._start_iteration; - _end_iteration=otherC._end_iteration; - _start_order=otherC._start_order; - _end_order=otherC._end_order; + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(&other); + if(!otherC) + throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::copyTinyAttrFrom : mismatch of time discretization !"); + _start_time=otherC->_start_time; + _end_time=otherC->_end_time; + _start_iteration=otherC->_start_iteration; + _end_iteration=otherC->_end_iteration; + _start_order=otherC->_start_order; + _end_order=otherC->_end_order; } void MEDCouplingConstOnTimeInterval::getTinySerializationIntInformation(std::vector& tinyInfo) const @@ -1967,22 +1971,24 @@ void MEDCouplingTwoTimeSteps::updateTime() const updateTimeWith(*_end_array); } -void MEDCouplingTwoTimeSteps::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) +void MEDCouplingTwoTimeSteps::copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception) { MEDCouplingTimeDiscretization::copyTinyAttrFrom(other); - const MEDCouplingTwoTimeSteps& otherC=dynamic_cast(other); - _start_time=otherC._start_time; - _end_time=otherC._end_time; - _start_iteration=otherC._start_iteration; - _end_iteration=otherC._end_iteration; - _start_order=otherC._start_order; - _end_order=otherC._end_order; + const MEDCouplingTwoTimeSteps *otherC=dynamic_cast(&other); + if(!otherC) + throw INTERP_KERNEL::Exception("MEDCouplingTwoTimeSteps::copyTinyAttrFrom : mismatch of time discretization !"); + _start_time=otherC->_start_time; + _end_time=otherC->_end_time; + _start_iteration=otherC->_start_iteration; + _end_iteration=otherC->_end_iteration; + _start_order=otherC->_start_order; + _end_order=otherC->_end_order; } void MEDCouplingTwoTimeSteps::copyTinyStringsFrom(const MEDCouplingTimeDiscretization& other) { MEDCouplingTimeDiscretization::copyTinyStringsFrom(other); - const MEDCouplingTwoTimeSteps* otherC=dynamic_cast(&other); + const MEDCouplingTwoTimeSteps *otherC=dynamic_cast(&other); if(!otherC) throw INTERP_KERNEL::Exception("Trying to operate copyTinyStringsFrom on different field type (two times//one time) !"); if(_end_array && otherC->_end_array) diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index 79a5bf04a..513f4179d 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -42,7 +42,7 @@ namespace ParaMEDMEM static MEDCouplingTimeDiscretization *New(TypeOfTimeDiscretization type); void setTimeUnit(const char *unit) { _time_unit=unit; } const char *getTimeUnit() const { return _time_unit.c_str(); } - virtual void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other); + virtual void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception); virtual void copyTinyStringsFrom(const MEDCouplingTimeDiscretization& other); virtual void checkCoherency() const throw(INTERP_KERNEL::Exception); virtual bool areCompatible(const MEDCouplingTimeDiscretization *other) const; @@ -214,7 +214,7 @@ namespace ParaMEDMEM public: MEDCouplingWithTimeStep(); std::string getStringRepr() const; - void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other); + void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception); TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } MEDCouplingTimeDiscretization *aggregate(const MEDCouplingTimeDiscretization *other) const; MEDCouplingTimeDiscretization *aggregate(const std::vector& other) const; @@ -278,7 +278,7 @@ namespace ParaMEDMEM MEDCouplingConstOnTimeInterval(const MEDCouplingConstOnTimeInterval& other, bool deepCpy); public: MEDCouplingConstOnTimeInterval(); - void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other); + void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception); void getTinySerializationIntInformation(std::vector& tinyInfo) const; void getTinySerializationDbleInformation(std::vector& tinyInfo) const; void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); @@ -348,7 +348,7 @@ namespace ParaMEDMEM ~MEDCouplingTwoTimeSteps(); public: void updateTime() const; - void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other); + void copyTinyAttrFrom(const MEDCouplingTimeDiscretization& other) throw(INTERP_KERNEL::Exception); void copyTinyStringsFrom(const MEDCouplingTimeDiscretization& other); const DataArrayDouble *getEndArray() const; DataArrayDouble *getEndArray(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index b41d28db3..41054dcb0 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -233,6 +233,7 @@ namespace ParaMEDMEM CPPUNIT_TEST( testNormMax1 ); CPPUNIT_TEST( testFindAndCorrectBadOriented3DExtrudedCells1 ); CPPUNIT_TEST( testConvertExtrudedPolyhedra1 ); + CPPUNIT_TEST( testNonRegressionCopyTinyStrings ); //MEDCouplingBasicsTestInterp.cxx CPPUNIT_TEST( test2DInterpP0P0_1 ); CPPUNIT_TEST( test2DInterpP0P0PL_1 ); @@ -492,6 +493,7 @@ namespace ParaMEDMEM void testNormMax1(); void testFindAndCorrectBadOriented3DExtrudedCells1(); void testConvertExtrudedPolyhedra1(); + void testNonRegressionCopyTinyStrings(); //MEDCouplingBasicsTestInterp.cxx void test2DInterpP0P0_1(); void test2DInterpP0P0PL_1(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index 347ff8847..252cdf096 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -1632,3 +1632,18 @@ void MEDCouplingBasicsTest::testConvertExtrudedPolyhedra1() // m->decrRef(); } + +void MEDCouplingBasicsTest::testNonRegressionCopyTinyStrings() +{ + MEDCouplingUMesh *m=build2DTargetMesh_1(); + MEDCouplingFieldDouble *f1=m->getMeasureField(true); + f1->getArray()->setInfoOnComponent(0,"P [N/m^2]"); + DataArrayDouble *bary=m->getBarycenterAndOwner(); + MEDCouplingFieldDouble *f2=f1->buildNewTimeReprFromThis(ONE_TIME,false); + f2->setArray(bary); + CPPUNIT_ASSERT_THROW(f2->copyTinyAttrFrom(f1),INTERP_KERNEL::Exception); + m->decrRef(); + f1->decrRef(); + bary->decrRef(); + f2->decrRef(); +} diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index eb314eb2e..c8eb3270b 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -7817,6 +7817,16 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(expected2,dai.getValues()); m.checkCoherency2() pass + + def testNonRegressionCopyTinyStrings(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f1=m.getMeasureField(True) + f1.getArray().setInfoOnComponent(0,"P [N/m^2]") + bary=m.getBarycenterAndOwner() + f2=f1.buildNewTimeReprFromThis(ONE_TIME,False) + f2.setArray(bary) + self.assertRaises(InterpKernelException,f2.copyTinyAttrFrom,f1) + pass def setUp(self): pass -- 2.39.2