Back to index

salome-med  6.5.0
MEDMEMTest_MedFieldDriver.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDMEMTest.hxx"
00021 #include <cppunit/TestAssert.h>
00022 
00023 #include <MEDMEM_Field.hxx>
00024 #include <MEDMEM_MedFieldDriver.hxx>
00025 
00026 // use this define to enable lines, execution of which leads to Segmentation Fault
00027 //#define ENABLE_FAULTS
00028 
00029 // use this define to enable CPPUNIT asserts and fails, showing bugs
00030 //#define ENABLE_FORCED_FAILURES
00031 
00074 void MEDMEMTest::testMedFieldDriver()
00075 {
00076   FIELD<int> *aField                = new FIELD<int>();
00077   FIELD<int> *aField_1              = new FIELD<int>();
00078   FIELD<double> *aField_2           = new FIELD<double>();
00079   string filename_rd                = getResourceFile("pointe.med");
00080   string filenameWithOutFileds      = getResourceFile("mesh.med");
00081   string filenameWithOutFileds_rdwr = makeTmpFile("mesh.med", filenameWithOutFileds);
00082   string fileldnotexist             = "anyfield";
00083   string fieldname                  = "fieldnodeint";
00084   string fieldname_cpy              = fieldname + "_cpy";
00085   string fileNotExist_rd            = "notExist22.med";
00086   string emptyfilename              = "";
00087 
00088   string filename_wr                = makeTmpFile("myWrField_pointe22.med", filename_rd);
00089   string fileNotExist_wr            = "/path_not_exist/file_not_exist.med";
00090   string emptyfile_wr               = makeTmpFile("myWrField_pointe_empty22.med");
00091   string other_file                 = getResourceFile("cube_hexa8.med");
00092   string other_file_wr              = makeTmpFile("myWRcube_hexa8.med", other_file);
00093 
00094   string filename_rdwr              = makeTmpFile("myRdWrField_pointe22.med", filename_rd);
00095   string emptyfile_rdwr             = makeTmpFile("myRdWrField_pointe_empty22.med");
00096   string fieldnameDouble            = "fieldnodedouble";
00097   string fieldnameDouble_cpy        = fieldnameDouble + "_cpy";
00098 
00099   // To remove tmp files from disk
00100   MEDMEMTest_TmpFilesRemover aRemover;
00101   aRemover.Register(filename_wr);
00102   aRemover.Register(emptyfile_wr);
00103   aRemover.Register(other_file_wr);
00104   aRemover.Register(filename_rdwr);
00105   aRemover.Register(emptyfile_rdwr);
00106   aRemover.Register(filenameWithOutFileds_rdwr);
00107 
00108   //--------------------------Test READ ONLY part------------------------------//
00109 
00111   //  TEST1: Open not existing file  //
00113 
00114   //Creation Invalid Read Only MedFieldDriver22 (file not exist)
00115   MED_FIELD_RDONLY_DRIVER<int> *aInvalidMedRdFieldDriver22_1 =
00116     new MED_FIELD_RDONLY_DRIVER<int>(fileNotExist_rd, aField);
00117   //Trying open not existing file
00118   CPPUNIT_ASSERT_THROW(aInvalidMedRdFieldDriver22_1->open(), MEDEXCEPTION);
00119 
00121   //  TEST2: Open file with empty file name  ///
00123 
00124   //Creation Invalid Read Only MedFieldDriver22 (empty file name)
00125   MED_FIELD_RDONLY_DRIVER<int> *aInvalidMedRdFieldDriver22_2 =
00126     new MED_FIELD_RDONLY_DRIVER<int>(emptyfilename, aField);
00127   //Trying file with empty name
00128   CPPUNIT_ASSERT_THROW(aInvalidMedRdFieldDriver22_2->open(), MEDEXCEPTION);
00129 
00131   //  TEST3: Reading field from file without fields  //
00133   MED_FIELD_RDONLY_DRIVER<int> *aInvalidMedRdFieldDriver22_3 =
00134     new MED_FIELD_RDONLY_DRIVER<int>(filenameWithOutFileds, aField);
00135   aInvalidMedRdFieldDriver22_3->open();
00136   aInvalidMedRdFieldDriver22_3->setFieldName(fieldname);
00137   //Trying read field from file
00138   CPPUNIT_ASSERT_THROW(aInvalidMedRdFieldDriver22_3->read(), MEDEXCEPTION);
00139   aInvalidMedRdFieldDriver22_3->close();
00140 
00142   //  TEST4: Main test  //
00144   //Creation correct Read Only MedFieldDriver22
00145   MED_FIELD_RDONLY_DRIVER<int> *aMedRdFieldDriver22 =
00146     new MED_FIELD_RDONLY_DRIVER<int>(filename_rd, aField);
00147 
00148   //Check driver
00149   CPPUNIT_ASSERT(aMedRdFieldDriver22);
00150 
00151   //Trying read field before open file
00152   CPPUNIT_ASSERT_THROW(aMedRdFieldDriver22->read(),MEDEXCEPTION);
00153 
00154   //Test open() method
00155   try
00156   {
00157     aMedRdFieldDriver22->open();
00158   }
00159   catch(MEDEXCEPTION &e)
00160   {
00161     CPPUNIT_FAIL(e.what());
00162   }
00163   catch( ... )
00164   {
00165     CPPUNIT_FAIL("Unknown exception");
00166   }
00167 
00168   //#ifdef ENABLE_FORCED_FAILURES
00169   //Trying open file secondary.
00170   //CPPUNIT_ASSERT_THROW(aMedRdFieldDriver22->open(), MEDEXCEPTION);
00171   CPPUNIT_ASSERT_NO_THROW(aMedRdFieldDriver22->open());
00172   // (BUG) No exception in this case
00173   //#endif
00174 
00175   //Trying read field form file if it name is empty
00176   CPPUNIT_ASSERT_THROW(aMedRdFieldDriver22->read(), MEDEXCEPTION);
00177 
00178   //Test setFieldName() and getFieldName()
00179   try
00180   {
00181     aMedRdFieldDriver22->setFieldName(fileldnotexist);
00182   }
00183   catch(MEDEXCEPTION &e)
00184   {
00185     CPPUNIT_FAIL(e.what());
00186   }
00187   catch( ... )
00188   {
00189     CPPUNIT_FAIL("Unknown exception");
00190   }
00191   CPPUNIT_ASSERT_EQUAL(fileldnotexist, aMedRdFieldDriver22->getFieldName());
00192 
00193   //Trying read not existing field from file
00194   CPPUNIT_ASSERT_THROW(aMedRdFieldDriver22->read(), MEDEXCEPTION);
00195 
00196   //Test read() method
00197   aMedRdFieldDriver22->setFieldName(fieldname);
00198   try
00199   {
00200     aMedRdFieldDriver22->read();
00201   }
00202   catch(MEDEXCEPTION &e)
00203   {
00204     CPPUNIT_FAIL(e.what());
00205   }
00206   catch( ... )
00207   {
00208     CPPUNIT_FAIL("Unknown exception");
00209   }
00210 
00211   //Test write() method for READ ONLY driver
00212   CPPUNIT_ASSERT_THROW(aMedRdFieldDriver22->write(), MEDEXCEPTION);
00213 
00214   //Test close() method
00215   try
00216   {
00217     aMedRdFieldDriver22->close();
00218   }
00219   catch(MEDEXCEPTION &e)
00220   {
00221     CPPUNIT_FAIL(e.what());
00222   }
00223   catch( ... )
00224   {
00225     CPPUNIT_FAIL("Unknown exception");
00226   }
00227 
00228   //Default constructor
00229   MED_FIELD_RDONLY_DRIVER<int> aMedRdFieldDriver22Cpy_1;
00230 
00231   //Test (void operator =) defined in GENDRIVER class in MEDMEM_GenDriver.hxx
00232   aMedRdFieldDriver22Cpy_1 = *aMedRdFieldDriver22;
00233 
00234   //Test (bool operator ==) defined GENDRIVER class in MEDMEM_GenDriver.hxx
00235   CPPUNIT_ASSERT(aMedRdFieldDriver22Cpy_1 ==  *aMedRdFieldDriver22);
00236 
00237   //Test copy constructorg
00238   MED_FIELD_RDONLY_DRIVER<int> aMedRdFieldDriver22Cpy_2 (*aMedRdFieldDriver22);
00239   CPPUNIT_ASSERT_EQUAL(aMedRdFieldDriver22Cpy_2, *aMedRdFieldDriver22);
00240 
00241   //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx
00242   ostringstream rostr1, rostr2;
00243   rostr1<<aMedRdFieldDriver22Cpy_1;
00244   rostr2<<aMedRdFieldDriver22Cpy_2;
00245   CPPUNIT_ASSERT(rostr1.str() != "");
00246   CPPUNIT_ASSERT(rostr1.str() == rostr2.str());
00247 
00248 
00249   //--------------------------Test WRITE ONLY part------------------------------//
00250 
00252   //  TEST1: Open not existing file  //
00254 
00255   //Creation Invalid Write Only MedFieldDriver22 (file not exist)
00256   MED_FIELD_WRONLY_DRIVER<int> *aInvalidMedWrFieldDriver22_1 =
00257     new MED_FIELD_WRONLY_DRIVER<int>(fileNotExist_wr, aField_1);
00258   //Trying open not existing file
00259   CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver22_1->open(), MEDEXCEPTION);
00260 
00262   //  TEST2: Open file with empty file name  //
00264   //Creation Invalid Write Only MedFieldDriver22 (empty file name)
00265   MED_FIELD_WRONLY_DRIVER<int> *aInvalidMedWrFieldDriver22_2 =
00266     new MED_FIELD_WRONLY_DRIVER<int>(emptyfilename, aField_1);
00267   //Trying open not existing file and file with empty name
00268   CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver22_2->open(), MEDEXCEPTION);
00269 
00271   //  TEST3: Writing field in empty file without mesh  //
00273   //Creation Invalid Write Only MedFieldDriver22
00274    MED_FIELD_WRONLY_DRIVER<int> *aInvalidMedWrFieldDriver22_3 =
00275      new MED_FIELD_WRONLY_DRIVER<int>(emptyfile_wr, aField);
00276 
00277   aInvalidMedWrFieldDriver22_3->open();
00278   //#ifdef ENABLE_FORCED_FAILURES
00279   //CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver22_3->write(), MEDEXCEPTION);
00280   CPPUNIT_ASSERT_NO_THROW(aInvalidMedWrFieldDriver22_3->write());
00281   //(Bug) No Exception in this case
00282   aInvalidMedWrFieldDriver22_3->close();
00283   //#endif
00284 
00286   //  TEST4: Writing field in the other file  //
00288 
00289   //Creation Invalid Write Only MedFieldDriver22
00290   MED_FIELD_WRONLY_DRIVER<int> *aInvalidMedWrFieldDriver22_4 =
00291     new MED_FIELD_WRONLY_DRIVER<int>(other_file_wr, aField);
00292   aInvalidMedWrFieldDriver22_4->open();
00293   //#ifdef ENABLE_FORCED_FAILURES
00294   //CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver22_4->write(), MEDEXCEPTION);
00295   CPPUNIT_ASSERT_NO_THROW(aInvalidMedWrFieldDriver22_4->write());
00296   //(Bug) No Exception in this case
00297   //#endif
00298 
00300   //  TEST5: Main test  //
00302 
00303   //Creation correct Write Only MedFieldDriver22
00304   MED_FIELD_WRONLY_DRIVER<int> *aMedWrFieldDriver22 =
00305     new MED_FIELD_WRONLY_DRIVER<int>(filename_wr, aField);
00306 
00307   //Check driver
00308   CPPUNIT_ASSERT(aMedWrFieldDriver22);
00309 
00310   //Trying write field before open file
00311   //#ifdef ENABLE_FORCED_FAILURES
00312   CPPUNIT_ASSERT_THROW(aMedWrFieldDriver22->write(),MEDEXCEPTION);
00313   // (BUG) No exception in this case
00314   //#endif
00315 
00316   //Test open() method
00317   try
00318   {
00319     aMedWrFieldDriver22->open();
00320   }
00321   catch(MEDEXCEPTION &e)
00322   {
00323     CPPUNIT_FAIL(e.what());
00324   }
00325   catch( ... )
00326   {
00327     CPPUNIT_FAIL("Unknown exception");
00328   }
00329 
00330   //#ifdef ENABLE_FORCED_FAILURES
00331   //Trying open file secondary.
00332   //CPPUNIT_ASSERT_THROW(aMedWrFieldDriver22->open(), MEDEXCEPTION);
00333   CPPUNIT_ASSERT_NO_THROW(aMedWrFieldDriver22->open());
00334   // (BUG) No exception in this case
00335   //#endif
00336 
00337   //Test setFieldName() and getFieldName
00338   aField->setName(fieldname_cpy);
00339   try
00340   {
00341     aMedWrFieldDriver22->setFieldName(fieldname_cpy);
00342   }
00343   catch(MEDEXCEPTION &e)
00344   {
00345     CPPUNIT_FAIL(e.what());
00346   }
00347   catch( ... )
00348   {
00349     CPPUNIT_FAIL("Unknown exception");
00350   }
00351   CPPUNIT_ASSERT_EQUAL(fieldname_cpy, aMedWrFieldDriver22->getFieldName());
00352 
00353   //Test write() method
00354   try
00355   {
00356     aMedWrFieldDriver22->write();
00357   }
00358   catch(MEDEXCEPTION &e)
00359   {
00360     CPPUNIT_FAIL(e.what());
00361   }
00362   catch( ... )
00363   {
00364     CPPUNIT_FAIL("Unknown exception");
00365   }
00366 
00367   //Test read() method for Write only part
00368   CPPUNIT_ASSERT_THROW(aMedWrFieldDriver22->read(),MEDEXCEPTION);
00369 
00370   //Test close() method
00371   try
00372   {
00373     aMedWrFieldDriver22->close();
00374   }
00375   catch(MEDEXCEPTION &e)
00376   {
00377     CPPUNIT_FAIL(e.what());
00378   }
00379   catch( ... )
00380   {
00381     CPPUNIT_FAIL("Unknown exception");
00382   }
00383 
00384   //Default constructor
00385   MED_FIELD_WRONLY_DRIVER<int> aMedWrFieldDriver22Cpy_1;
00386 
00387   //Test (void operator =) defined in GENDRIVER class
00388   aMedWrFieldDriver22Cpy_1 = *aMedWrFieldDriver22;
00389 
00390   //Test (bool operator ==) defined in GENDRIVER class
00391   CPPUNIT_ASSERT(aMedWrFieldDriver22Cpy_1.GENDRIVER::operator==(*aMedWrFieldDriver22));
00392 
00393   //Test copy constructor
00394   MED_FIELD_WRONLY_DRIVER<int> aMedWrFieldDriver22Cpy_2 (*aMedWrFieldDriver22);
00395   CPPUNIT_ASSERT_EQUAL(aMedWrFieldDriver22Cpy_2, *aMedWrFieldDriver22);
00396 
00397   //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx
00398   ostringstream wostr1, wostr2;
00399   wostr1 << aMedWrFieldDriver22Cpy_1;
00400   wostr2 << aMedWrFieldDriver22Cpy_2;
00401   CPPUNIT_ASSERT(wostr1.str() != "");
00402   CPPUNIT_ASSERT(wostr1.str() == wostr2.str());
00403 
00404 
00405   //--------------------------Test READ/WRITE part------------------------------//
00406 
00408   //  TEST1: Open not existing file  //
00410 
00411   //Creation Invalid Read/Write MedFieldDriver22 (file not exist)
00412   MED_FIELD_RDWR_DRIVER<int> *aInvalidMedRdWrFieldDriver22_1 =
00413     new MED_FIELD_RDWR_DRIVER<int>(fileNotExist_wr, aField_1);
00414   //Trying open not existing file
00415   CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver22_1->open(), MEDEXCEPTION);
00416 
00418   //  TEST2: Open file with empty file name  //
00420   //Creation Invalid Read/Write MedFieldDriver22 (empty file name)
00421   MED_FIELD_RDWR_DRIVER<int> *aInvalidMedRdWrFieldDriver22_2 =
00422     new MED_FIELD_RDWR_DRIVER<int>(emptyfilename, aField_1);
00423   //Trying open not existing file and file with empty name
00424   CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver22_2->open(), MEDEXCEPTION);
00425 
00427   //  TEST3: Reading field from file without fields  //
00429   MED_FIELD_RDWR_DRIVER<int> *aInvalidMedRdWrFieldDriver22_3 =
00430     new MED_FIELD_RDWR_DRIVER<int>(filenameWithOutFileds_rdwr, aField_1);
00431   aInvalidMedRdWrFieldDriver22_3->open();
00432   aInvalidMedRdWrFieldDriver22_3->setFieldName(fieldname);
00433   //Trying read field from file
00434   CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver22_3->read(), MEDEXCEPTION);
00435   aInvalidMedRdWrFieldDriver22_3->close();
00436 
00438   //  TEST4: Writing field in empty file without mesh  //
00440 
00441   //Creation Invalid Read/Write MedFieldDriver22
00442    MED_FIELD_RDWR_DRIVER<int> *aInvalidMedRdWrFieldDriver22_4 =
00443      new MED_FIELD_RDWR_DRIVER<int>(emptyfile_rdwr, aField);
00444 
00445   aInvalidMedRdWrFieldDriver22_4->open();
00446   //#ifdef ENABLE_FORCED_FAILURES
00447   //  CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver22_4->write(), MEDEXCEPTION);
00448   // (BUG) No exception in this case
00449   //#endif
00450 
00452   //  TEST6: Writing field in the other file  //
00454 
00455   //Creation Invalid Read/Write MedFieldDriver22
00456   MED_FIELD_RDWR_DRIVER<int> *aInvalidMedRdWrFieldDriver22_5 =
00457     new MED_FIELD_RDWR_DRIVER<int>(other_file_wr, aField);
00458   aInvalidMedRdWrFieldDriver22_5->open();
00459   //#ifdef ENABLE_FORCED_FAILURES
00460   //CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver22_5->write(), MEDEXCEPTION);
00461   // (BUG) No exception in this case
00462   //#endif
00463 
00465   //  TEST7: Main test  //
00467 
00468   //Creation correct Read/Write MedFieldDriver22
00469   MED_FIELD_RDWR_DRIVER<double> *aMedRdWrFieldDriver22 =
00470     new MED_FIELD_RDWR_DRIVER<double>(filename_rdwr, aField_2);
00471 
00472   //Check driver
00473   CPPUNIT_ASSERT(aMedRdWrFieldDriver22);
00474 
00475   //Trying read/write field before open file
00476   CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver22->read(),MEDEXCEPTION);
00477   CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver22->write(),MEDEXCEPTION);
00478 
00479   //Test open() method
00480   try
00481   {
00482     aMedRdWrFieldDriver22->open();
00483   }
00484   catch(MEDEXCEPTION &e)
00485   {
00486     CPPUNIT_FAIL(e.what());
00487   }
00488   catch( ... )
00489   {
00490     CPPUNIT_FAIL("Unknown exception");
00491   }
00492 
00493   //#ifdef ENABLE_FORCED_FAILURES
00494   //Trying open file secondary.
00495   //CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver22->open(), MEDEXCEPTION);
00496   CPPUNIT_ASSERT_NO_THROW(aMedRdWrFieldDriver22->open());
00497   // (BUG) No exception in this case
00498   //#endif
00499 
00500   //Trying read field from file if field name is empty
00501   CPPUNIT_ASSERT_THROW(aMedRdFieldDriver22->read(), MEDEXCEPTION);
00502 
00503   //Test setFieldName() and getFieldName
00504   try
00505   {
00506     aMedRdWrFieldDriver22->setFieldName(fileldnotexist);
00507   }
00508   catch(MEDEXCEPTION &e)
00509   {
00510     CPPUNIT_FAIL(e.what());
00511   }
00512   catch( ... )
00513   {
00514     CPPUNIT_FAIL("Unknown exception");
00515   }
00516   CPPUNIT_ASSERT_EQUAL(fileldnotexist, aMedRdWrFieldDriver22->getFieldName());
00517 
00518   //Trying read not existing field from file
00519   CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver22->read(), MEDEXCEPTION);
00520 
00521   //Test read() method
00522   aMedRdWrFieldDriver22->setFieldName(fieldnameDouble);
00523   try
00524   {
00525     aMedRdWrFieldDriver22->read();
00526   }
00527   catch(MEDEXCEPTION &e)
00528   {
00529     CPPUNIT_FAIL(e.what());
00530   }
00531   catch( ... )
00532   {
00533     CPPUNIT_FAIL("Unknown exception");
00534   }
00535 
00536   //Trying write field in the file with empty name
00537   aField_2->setName(emptyfilename);
00538   aMedRdWrFieldDriver22->setFieldName(emptyfilename);
00539   CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver22->write(), MEDEXCEPTION);
00540 
00541   //Test write() method
00542   aField_2->setName(fieldnameDouble_cpy);
00543   aMedRdWrFieldDriver22->setFieldName(fieldnameDouble_cpy);
00544   try
00545   {
00546     aMedRdWrFieldDriver22->write();
00547   }
00548   catch(MEDEXCEPTION &e)
00549   {
00550     CPPUNIT_FAIL(e.what());
00551   }
00552   catch( ... )
00553   {
00554     CPPUNIT_FAIL("Unknown exception");
00555   }
00556 
00557   //Test close() method
00558   try
00559   {
00560     aMedRdWrFieldDriver22->close();
00561   }
00562   catch(MEDEXCEPTION &e)
00563   {
00564     CPPUNIT_FAIL(e.what());
00565   }
00566   catch( ... )
00567   {
00568     CPPUNIT_FAIL("Unknown exception");
00569   }
00570 
00571   //Default constructor
00572   MED_FIELD_RDWR_DRIVER<double> aMedRdWrFieldDriver22Cpy_1;
00573 
00574   //Test (void operator =) defined in GENDRIVER class
00575   aMedRdWrFieldDriver22Cpy_1 = *aMedRdWrFieldDriver22;
00576 
00577   //Test (bool operator ==) defined in GENDRIVER class
00578   CPPUNIT_ASSERT(aMedRdWrFieldDriver22Cpy_1.GENDRIVER::operator==(*aMedRdWrFieldDriver22));
00579 
00580   //Test copy constructor
00581   MED_FIELD_RDWR_DRIVER<double> aMedRdWrFieldDriver22Cpy_2 (*aMedRdWrFieldDriver22);
00582   CPPUNIT_ASSERT_EQUAL(aMedRdWrFieldDriver22Cpy_2, *aMedRdWrFieldDriver22);
00583 
00584   //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx
00585   ostringstream rwostr1, rwostr2;
00586   rwostr1 << aMedRdWrFieldDriver22Cpy_1;
00587   rwostr2 << aMedRdWrFieldDriver22Cpy_2;
00588   CPPUNIT_ASSERT(rwostr1.str() != "");
00589   CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str());
00590 
00592   // Test for the issue 0021211. Check that a support of partial field
00593   // (group or family) is restored at reading
00594   {
00595     string filenameRDWR = makeTmpFile("filenameRDWR.med");
00596     aRemover.Register(filenameRDWR);
00597 
00598     MESH* mesh = new MESH(MED_DRIVER, filenameWithOutFileds, "Mesh 1");
00599     mesh->setName("UniqueMeshName");
00600     //mesh->setMeshDimension(3); need to make mdump work on 2D mesh in 3D space
00601 
00602     FAMILY* family = const_cast<FAMILY*>( mesh->getFamily( MED_EDGE, 1 ));
00603     family->setName( healName( family->getName() ));
00604 
00605     // mesh is 2D, make a field on the 1st FAMILY of segments
00606     FIELD<double>* field = new FIELD<double>( family, /*NumberOfComponents=*/1);
00607     field->setName( "FieldOnFamily");
00608     field->setComponentsNames(&fileldnotexist);
00609     field->setComponentsDescriptions(&fileldnotexist);
00610     field->setMEDComponentsUnits(&fileldnotexist);
00611     double* vals = const_cast<double*>( field->getValue() );
00612     const int nbVals = family->getNumberOfElements( MED_ALL_ELEMENTS );
00613     for ( int i = 0; i < nbVals; ++i ) vals[i] = i;
00614 
00615     // store the mesh and the field in a file
00616     int drv = mesh->addDriver( MED_DRIVER, filenameRDWR, mesh->getName() );
00617     CPPUNIT_ASSERT_NO_THROW( mesh->write(drv) );
00618     drv = field->addDriver( MED_DRIVER, filenameRDWR, field->getName() );
00619     CPPUNIT_ASSERT_NO_THROW( field->write(drv) );
00620 
00621     // Check 1) read the field back and check it's support
00622     string familyName = family->getName();
00623     const SUPPORT* supOnAll = mesh->getSupportOnAll( family->getEntity() );
00624     FIELD<double>* field2 =
00625       new FIELD<double>( supOnAll, MED_DRIVER, filenameRDWR, field->getName());
00626     const SUPPORT* support2 = field2->getSupport();
00627     CPPUNIT_ASSERT( support2 == family );
00628     CPPUNIT_ASSERT_EQUAL( familyName, support2->getName() ); // name must not change
00629 
00630     // Check 2) if a support with name corresponding to a profile is not found,
00631     // the new SUPPORT must not have name "SupportOnAll_MED_entity"
00632     ((FAMILY*)family)->setName("setName");
00633     FIELD<double>* field3 =
00634       new FIELD<double>( supOnAll, MED_DRIVER, filenameRDWR, field->getName());
00635     const SUPPORT* support3 = field3->getSupport();
00636     CPPUNIT_ASSERT( support3 != family );
00637     CPPUNIT_ASSERT( support3->getName() != supOnAll->getName());
00638 
00639     // delete
00640     field->removeReference();
00641     field2->removeReference();
00642     field3->removeReference();
00643     mesh->removeReference();
00644   }
00645   // End Test for the issue 0021211
00647 
00648   //Delete all objects
00649   aField->removeReference();
00650   aField_1->removeReference();
00651   aField_2->removeReference();
00652 
00653   delete aInvalidMedRdFieldDriver22_1;
00654   delete aInvalidMedRdFieldDriver22_2;
00655   delete aInvalidMedRdFieldDriver22_3;
00656   delete aMedRdFieldDriver22;
00657 
00658   delete aInvalidMedWrFieldDriver22_1;
00659   delete aInvalidMedWrFieldDriver22_2;
00660   delete aInvalidMedWrFieldDriver22_3;
00661   delete aInvalidMedWrFieldDriver22_4;
00662   delete aMedWrFieldDriver22;
00663 
00664   delete aInvalidMedRdWrFieldDriver22_1;
00665   delete aInvalidMedRdWrFieldDriver22_2;
00666   delete aInvalidMedRdWrFieldDriver22_3;
00667   delete aInvalidMedRdWrFieldDriver22_4;
00668   delete aInvalidMedRdWrFieldDriver22_5;
00669   delete aMedRdWrFieldDriver22;
00670 }