Back to index

salome-med  6.5.0
MEDMEMTest_DriverFactory.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/Message.h>
00022 #include <cppunit/TestAssert.h>
00023 
00024 #include "MEDMEM_DriverFactory.hxx"
00025 #include "MEDMEM_Field.hxx"
00026 #include "MEDMEM_GenDriver.hxx"
00027 #include "MEDMEM_GibiMeshDriver.hxx"
00028 #include "MEDMEM_MedFieldDriver.hxx"
00029 #include "MEDMEM_MedMeshDriver.hxx"
00030 #include "MEDMEM_Mesh.hxx"
00031 #include "MEDMEM_PorflowMeshDriver.hxx"
00032 #include "MEDMEM_STRING.hxx"
00033 #include "MEDMEM_Support.hxx"
00034 #include "MEDMEM_VtkFieldDriver.hxx"
00035 #include "MEDMEM_VtkMedDriver.hxx"
00036 #include "MEDMEM_VtkMeshDriver.hxx"
00037 
00038 #include <sstream>
00039 #include <cmath>
00040 
00041 // use this define to enable lines, execution of which leads to Segmentation Fault
00042 //#define ENABLE_FAULTS
00043 
00044 // use this define to enable CPPUNIT asserts and fails, showing bugs
00045 //#define ENABLE_FORCED_FAILURES
00046 
00047 using namespace std;
00048 using namespace MEDMEM;
00049 
00050 // #9: MEDMEM_DriverFactory.hxx  }  MEDMEMTest_DriverFactory.cxx
00051 
00083 void MEDMEMTest::testDriverFactory()
00084 {
00086   // Test 1: getMedFileVersionForWriting & setMedFileVersionForWriting //
00088 
00089   // Obsolete, removed
00090 
00092   // Test 1b: getVtkBinaryFormatForWriting & setVtkBinaryFormatForWriting //
00094 
00095   // save current format
00096   bool wasBinary = DRIVERFACTORY::getVtkBinaryFormatForWriting();
00097 
00098   // check changing format
00099   DRIVERFACTORY::setVtkBinaryFormatForWriting( !wasBinary );
00100   CPPUNIT_ASSERT(DRIVERFACTORY::getVtkBinaryFormatForWriting() == !wasBinary);
00101 
00102   // restore default version preference
00103   DRIVERFACTORY::setVtkBinaryFormatForWriting(wasBinary);
00104 
00106   // Test 2: deduceDriverTypeFromFileName //
00108   CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("test.med")   == MED_DRIVER);
00109   CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t.st.sauve") == GIBI_DRIVER);
00110   CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t.st.sauv")  == GIBI_DRIVER);
00111   CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t.st.cnc")   == PORFLOW_DRIVER);
00112   CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t.st.inp")   == PORFLOW_DRIVER);
00113   CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t.st.xyz")   == PORFLOW_DRIVER);
00114   CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t.st.vtk")   == VTK_DRIVER);
00115   CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t_st_med")   == NO_DRIVER);
00116   CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t.st.med1")  == NO_DRIVER);
00117 
00119   // Test building drivers for different types of files //
00121   GENDRIVER * aDriver = NULL;
00122 
00124   // Test 3: buildDriverForMed //
00126 
00127   // Obsolete, removed
00128 
00130   // Test 4: buildDriverForMesh //
00132   MESH *mesh=new MESH;
00133 
00134   // 4.1: MED_DRIVER
00135 
00136   // rdonly
00137   aDriver = DRIVERFACTORY::buildDriverForMesh
00138     (MED_DRIVER, "anyfile", mesh, "my driver name", MED_EN::RDONLY);
00139   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00140   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDONLY);
00141 
00142 
00143   MED_MESH_RDONLY_DRIVER * aMedRDriverForMesh = dynamic_cast<MED_MESH_RDONLY_DRIVER *> (aDriver);
00144   CPPUNIT_ASSERT(aMedRDriverForMesh);
00145   CPPUNIT_ASSERT(aMedRDriverForMesh->getMeshName() == "my driver name");
00146 
00147 
00148   delete aDriver; aDriver=0;
00149 
00150   // wronly
00151   aDriver = DRIVERFACTORY::buildDriverForMesh
00152     (MED_DRIVER, "anyfile", mesh, "my driver name", MED_EN::WRONLY);
00153   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00154   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::WRONLY);
00155 
00156   MED_MESH_WRONLY_DRIVER * aMedWDriverForMesh = dynamic_cast<MED_MESH_WRONLY_DRIVER *> (aDriver);
00157   CPPUNIT_ASSERT(aMedWDriverForMesh);
00158   CPPUNIT_ASSERT(aMedWDriverForMesh->getMeshName() == "my driver name");
00159 
00160   delete aDriver; aDriver=0;
00161 
00162   // rdwr
00163   aDriver = DRIVERFACTORY::buildDriverForMesh
00164     (MED_DRIVER, "anyfile", mesh, "my driver name", MED_EN::RDWR);
00165   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00166   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDWR);
00167 
00168   MED_MESH_RDWR_DRIVER * aMedRWDriverForMesh = dynamic_cast<MED_MESH_RDWR_DRIVER *> (aDriver);
00169   CPPUNIT_ASSERT(aMedRWDriverForMesh);
00170   CPPUNIT_ASSERT(aMedRWDriverForMesh->getMeshName() == "my driver name");
00171 
00172   delete aDriver; aDriver=0;
00173 
00174   // 4.2: GIBI_DRIVER
00175 
00176   // rdonly
00177   aDriver = DRIVERFACTORY::buildDriverForMesh
00178     (GIBI_DRIVER, "anyfile", mesh, "my driver name", MED_EN::RDONLY);
00179   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00180   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDONLY);
00181 
00182   GIBI_MESH_RDONLY_DRIVER * aGibiDriverForMesh = dynamic_cast<GIBI_MESH_RDONLY_DRIVER *> (aDriver);
00183   CPPUNIT_ASSERT(aGibiDriverForMesh);
00184 
00185   delete aDriver; aDriver=0;
00186 
00187   // wronly
00188   aDriver = DRIVERFACTORY::buildDriverForMesh
00189     (GIBI_DRIVER, "anyfile", mesh, "my driver name", MED_EN::WRONLY);
00190   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00191   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::WRONLY);
00192 
00193   GIBI_MESH_WRONLY_DRIVER * aGibiWRDriverForMesh = dynamic_cast<GIBI_MESH_WRONLY_DRIVER*>(aDriver);
00194   CPPUNIT_ASSERT(aGibiWRDriverForMesh);
00195   delete aDriver; aDriver=0;
00196 
00197   // rdwr
00198   aDriver = DRIVERFACTORY::buildDriverForMesh
00199     (GIBI_DRIVER, "anyfile", mesh, "my driver name", MED_EN::RDWR);
00200   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00201   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDWR);
00202 
00203   GIBI_MESH_RDWR_DRIVER * aGibiRWDriverForMesh = dynamic_cast<GIBI_MESH_RDWR_DRIVER*>(aDriver);
00204   CPPUNIT_ASSERT(aGibiRWDriverForMesh);
00205   delete aDriver; aDriver=0;
00206 
00207   // 4.3: PORFLOW_DRIVER
00208 
00209   // rdonly
00210   aDriver = DRIVERFACTORY::buildDriverForMesh
00211     (PORFLOW_DRIVER, "anyfile", mesh, "my driver name", MED_EN::RDONLY);
00212   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00213   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDONLY);
00214 
00215   PORFLOW_MESH_RDONLY_DRIVER * aPorflowDriverForMesh = dynamic_cast<PORFLOW_MESH_RDONLY_DRIVER *> (aDriver);
00216   CPPUNIT_ASSERT(aPorflowDriverForMesh);
00217 
00218   delete aDriver; aDriver=0;
00219 
00220   // wronly
00221   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMesh(PORFLOW_DRIVER, "anyfile", mesh,
00222                                                          "my driver name", MED_EN::WRONLY),
00223                        MED_EXCEPTION);
00224   // rdwr
00225   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMesh(PORFLOW_DRIVER, "anyfile", mesh,
00226                                                          "my driver name", MED_EN::RDWR),
00227                        MED_EXCEPTION);
00228 
00229   // 4.4: VTK_DRIVER
00230 
00231   // rdonly
00232   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMesh(VTK_DRIVER, "anyfile", mesh,
00233                                                          "my driver name", MED_EN::RDONLY),
00234                        MED_EXCEPTION);
00235 
00236   // wronly
00237   aDriver = DRIVERFACTORY::buildDriverForMesh
00238     (VTK_DRIVER, "anyfile", mesh, "my driver name", MED_EN::WRONLY);
00239   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00240   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::WRONLY);
00241 
00242   VTK_MESH_DRIVER * aVtkDriverForMesh = dynamic_cast<VTK_MESH_DRIVER *> (aDriver);
00243   CPPUNIT_ASSERT(aVtkDriverForMesh);
00244 
00245   delete aDriver; aDriver=0;
00246 
00247   // rdwr
00248   aDriver = DRIVERFACTORY::buildDriverForMesh
00249     (VTK_DRIVER, "anyfile", mesh, "my driver name", MED_EN::RDWR);
00250   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00251   // next string is commented by skl since VTK driver is 
00252   // created without mode
00253   //CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDWR);
00254 
00255   aVtkDriverForMesh = dynamic_cast<VTK_MESH_DRIVER *> (aDriver);
00256   CPPUNIT_ASSERT(aVtkDriverForMesh);
00257 
00258   delete aDriver; aDriver=0;
00259 
00260   // 4.5: ASCII_DRIVER
00261   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMesh(ASCII_DRIVER, "anyfile", mesh,
00262                                                          "my driver name", MED_EN::RDONLY),
00263                        MED_EXCEPTION);
00264 
00265   // 4.6: NO_DRIVER
00266   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMesh(NO_DRIVER, "anyfile", mesh,
00267                                                          "my driver name", MED_EN::RDONLY),
00268                        MED_EXCEPTION);
00269 
00271   // Test 5: buildDriverForField //
00273   FIELD<double> *field=new FIELD<double>();
00274 
00275   // 5.1: MED_DRIVER
00276 
00277   // rdonly
00278   aDriver = DRIVERFACTORY::buildDriverForField(MED_DRIVER, "anyfile", field, MED_EN::RDONLY);
00279   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00280   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDONLY);
00281 
00282   MED_FIELD_RDONLY_DRIVER<double> * aMedRDriverForField =
00283     dynamic_cast<MED_FIELD_RDONLY_DRIVER<double> *> (aDriver);
00284   CPPUNIT_ASSERT(aMedRDriverForField);
00285 
00286   delete aDriver; aDriver=0;
00287 
00288   // wronly
00289   aDriver = DRIVERFACTORY::buildDriverForField(MED_DRIVER, "anyfile", field, MED_EN::WRONLY);
00290   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00291   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::WRONLY);
00292 
00293   MED_FIELD_WRONLY_DRIVER<double> * aMedWDriverForField =
00294     dynamic_cast<MED_FIELD_WRONLY_DRIVER<double> *> (aDriver);
00295   CPPUNIT_ASSERT(aMedWDriverForField);
00296 
00297   delete aDriver; aDriver=0;
00298 
00299   // rdwr
00300   aDriver = DRIVERFACTORY::buildDriverForField(MED_DRIVER, "anyfile", field, MED_EN::RDWR);
00301   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00302   CPPUNIT_ASSERT_EQUAL(MED_EN::RDWR,aDriver->getAccessMode());
00303 
00304   MED_FIELD_RDWR_DRIVER<double> * aMedRWDriverForField =
00305     dynamic_cast<MED_FIELD_RDWR_DRIVER<double> *> (aDriver);
00306   CPPUNIT_ASSERT(aMedRWDriverForField);
00307 
00308   delete aDriver; aDriver=0;
00309 
00310   // 5.2: GIBI_DRIVER
00311 
00312   // rdonly
00313   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(GIBI_DRIVER, "anyfile", field, MED_EN::RDONLY),
00314                        MED_EXCEPTION);
00315   // wronly
00316   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(GIBI_DRIVER, "anyfile", field, MED_EN::WRONLY),
00317                        MED_EXCEPTION);
00318   // rdwr
00319   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(GIBI_DRIVER, "anyfile", field, MED_EN::RDWR),
00320                        MED_EXCEPTION);
00321 
00322   // 5.3: PORFLOW_DRIVER
00323 
00324   // rdonly
00325   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(PORFLOW_DRIVER, "anyfile",
00326                                                           field, MED_EN::RDONLY),
00327                        MED_EXCEPTION);
00328   // wronly
00329   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(PORFLOW_DRIVER, "anyfile",
00330                                                           field, MED_EN::WRONLY),
00331                        MED_EXCEPTION);
00332   // rdwr
00333   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(PORFLOW_DRIVER, "anyfile",
00334                                                           field, MED_EN::RDWR),
00335                        MED_EXCEPTION);
00336 
00337   // 5.4: VTK_DRIVER
00338 
00339   // rdonly
00340   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(VTK_DRIVER, "anyfile", field, MED_EN::RDONLY),
00341                        MED_EXCEPTION);
00342 
00343   // wronly
00344   aDriver = DRIVERFACTORY::buildDriverForField(VTK_DRIVER, "anyfile", field, MED_EN::WRONLY);
00345   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00346   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::WRONLY);
00347 
00348   VTK_FIELD_DRIVER<double> * aVtkDriverForField = dynamic_cast<VTK_FIELD_DRIVER<double> *> (aDriver);
00349   CPPUNIT_ASSERT(aVtkDriverForField);
00350 
00351   delete aDriver; aDriver=0;
00352 
00353   // rdwr
00354   aDriver = DRIVERFACTORY::buildDriverForField(VTK_DRIVER, "anyfile", field, MED_EN::RDWR);
00355   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00356   // next string is commented by skl since VTK driver is 
00357   // created without mode
00358   //CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDWR);
00359 
00360   aVtkDriverForField = dynamic_cast<VTK_FIELD_DRIVER<double> *> (aDriver);
00361   CPPUNIT_ASSERT(aVtkDriverForField);
00362 
00363   delete aDriver; aDriver=0;
00364 
00365   // 5.5: ASCII_DRIVER
00366 
00367   // rdonly
00368   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(ASCII_DRIVER, "anyfile", field, MED_EN::RDONLY),
00369                        MED_EXCEPTION);
00370   // rdwr
00371   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(ASCII_DRIVER, "anyfile", field, MED_EN::RDWR),
00372                        MED_EXCEPTION);
00373 
00374   // wronly
00375   // it throws on empty field
00376   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(ASCII_DRIVER, "anyfile", field, MED_EN::WRONLY),
00377                        MED_EXCEPTION);
00378 
00379   // now try with valid field
00380   string filename  = getResourceFile("pointe.med");
00381   string meshname  = "maa1";
00382   string fieldname = "fieldcelldoublescalar";
00383   FIELD<double> * aField1 = new FIELD<double>(MED_DRIVER, filename, fieldname);
00384   const SUPPORT * aSupport = aField1->getSupport();
00385   MESH * aMesh = new MESH (MED_DRIVER, filename, aSupport->getMeshName());
00386   aSupport->setMesh(aMesh);
00387 
00388   aDriver = DRIVERFACTORY::buildDriverForField(ASCII_DRIVER, "anyfile", aField1, MED_EN::WRONLY);
00389   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00390   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::WRONLY);
00391 
00392   // it works!
00393   //aDriver->open();
00394   //aDriver->write();
00395   //aDriver->close();
00396 
00397   ASCII_FIELD_DRIVER<double> * anAsciiDriverForField =
00398     dynamic_cast<ASCII_FIELD_DRIVER<double> *> (aDriver);
00399   CPPUNIT_ASSERT(anAsciiDriverForField);
00400 
00401   delete aDriver; aDriver=0;
00402 
00403   aField1->removeReference();
00404   aMesh->removeReference();
00405 
00406   // 5.6: NO_DRIVER
00407   CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(NO_DRIVER, "anyfile", field, MED_EN::RDONLY),
00408                        MED_EXCEPTION);
00409 
00411   // Test 6: buildMedDriverFromFile //
00413   string aFileName1 = getResourceFile("pointe.med");
00414   string aFileName2 = getResourceFile("polyedres.med");
00415   medFileVersion version1, version2;
00416 
00417   try {
00418     version1 = getMedFileVersion(aFileName1);
00419   } catch (MEDEXCEPTION & ex) {
00420     version1 = MED_EN::V22;
00421   }
00422 
00423   try {
00424     version2 = getMedFileVersion(aFileName2);
00425   } catch (MEDEXCEPTION & ex) {
00426     version2 = MED_EN::V22;
00427   }
00428 
00429   // 6.1. Med file V2.1
00430   string aFileName21 = aFileName1;
00431   if (version1 == MED_EN::V21 || version2 == MED_EN::V21) {
00432     if (version1 == MED_EN::V22)
00433       aFileName21 = aFileName2;
00434 
00435   }
00436 
00437 //   // 6.2. Med file V2.2
00438   string aFileName22 = aFileName2;
00439   if (version2 == MED_EN::V22 || version1 == MED_EN::V22) {
00440     if (version2 == MED_EN::V21)
00441       aFileName22 = aFileName1;
00442 
00443   }
00444 
00446   // Test 7: buildMeshDriverFromFile //
00448 
00449   // 7.1. Med file V2.1
00450   if (version1 == MED_EN::V21 || version2 == MED_EN::V21) {
00451     // Obsolete, removed
00452   }
00453 
00454   // 7.2. Med file V2.2
00455   if (version2 == MED_EN::V22 || version1 == MED_EN::V22) {
00456     // rdonly
00457     aDriver = DRIVERFACTORY::buildMeshDriverFromFile(aFileName22, mesh, MED_EN::RDONLY);
00458     CPPUNIT_ASSERT(aDriver->getFileName() == aFileName22);
00459     CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDONLY);
00460 
00461     MED_MESH_RDONLY_DRIVER * aMeshRDriverForMed22 = dynamic_cast<MED_MESH_RDONLY_DRIVER *> (aDriver);
00462     CPPUNIT_ASSERT(aMeshRDriverForMed22);
00463 
00464     delete aDriver; aDriver=0;
00465 
00466     // wronly
00467     aDriver = DRIVERFACTORY::buildMeshDriverFromFile(aFileName22, mesh, MED_EN::WRONLY);
00468     CPPUNIT_ASSERT(aDriver->getFileName() == aFileName22);
00469     CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::WRONLY);
00470 
00471     MED_MESH_WRONLY_DRIVER * aMeshWDriverForMed22 = dynamic_cast<MED_MESH_WRONLY_DRIVER *> (aDriver);
00472     CPPUNIT_ASSERT(aMeshWDriverForMed22);
00473 
00474     delete aDriver; aDriver=0;
00475 
00476     // rdwr
00477     aDriver = DRIVERFACTORY::buildMeshDriverFromFile(aFileName22, mesh, MED_EN::RDWR);
00478     CPPUNIT_ASSERT(aDriver->getFileName() == aFileName22);
00479     CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDWR);
00480 
00481     MED_MESH_RDWR_DRIVER * aMeshRWDriverForMed22 = dynamic_cast<MED_MESH_RDWR_DRIVER *> (aDriver);
00482     CPPUNIT_ASSERT(aMeshRWDriverForMed22);
00483 
00484     delete aDriver; aDriver=0;
00485   }
00486 
00488   // Test 8: buildFieldDriverFromFile //
00490 
00491   // 8.1. Med file V2.1
00492   if (version1 == MED_EN::V21 || version2 == MED_EN::V21) {
00493     // rdonly
00494     aDriver = DRIVERFACTORY::buildFieldDriverFromFile(aFileName21, field, MED_EN::RDONLY);
00495     CPPUNIT_ASSERT(aDriver->getFileName() == aFileName21);
00496     CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDONLY);
00497 
00498     delete aDriver; aDriver=0;
00499 
00500     // wronly
00501     aDriver = DRIVERFACTORY::buildFieldDriverFromFile(aFileName21, field, MED_EN::WRONLY);
00502     CPPUNIT_ASSERT(aDriver->getFileName() == aFileName21);
00503     CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::WRONLY);
00504 
00505     delete aDriver; aDriver=0;
00506 
00507     // rdwr
00508     aDriver = DRIVERFACTORY::buildFieldDriverFromFile(aFileName21, field, MED_EN::RDWR);
00509     CPPUNIT_ASSERT(aDriver->getFileName() == aFileName21);
00510     CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDWR); // see MEDMEM_define.hxx
00511 
00512     delete aDriver; aDriver=0;
00513   }
00514 
00515   // 8.2. Med file V2.2
00516   if (version2 == MED_EN::V22 || version1 == MED_EN::V22) {
00517     // rdonly
00518     aDriver = DRIVERFACTORY::buildFieldDriverFromFile(aFileName22, field, MED_EN::RDONLY);
00519     CPPUNIT_ASSERT(aDriver->getFileName() == aFileName22);
00520     CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDONLY);
00521 
00522     MED_FIELD_RDONLY_DRIVER<double> * aFieldRDriverForMed22 =
00523       dynamic_cast<MED_FIELD_RDONLY_DRIVER<double> *> (aDriver);
00524     CPPUNIT_ASSERT(aFieldRDriverForMed22);
00525 
00526     delete aDriver; aDriver=0;
00527 
00528     // wronly
00529     aDriver = DRIVERFACTORY::buildFieldDriverFromFile(aFileName22, field, MED_EN::WRONLY);
00530     CPPUNIT_ASSERT(aDriver->getFileName() == aFileName22);
00531     CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::WRONLY);
00532 
00533     MED_FIELD_WRONLY_DRIVER<double> * aFieldWDriverForMed22 =
00534       dynamic_cast<MED_FIELD_WRONLY_DRIVER<double> *> (aDriver);
00535     CPPUNIT_ASSERT(aFieldWDriverForMed22);
00536 
00537     delete aDriver; aDriver=0;
00538 
00539     // rdwr
00540     aDriver = DRIVERFACTORY::buildFieldDriverFromFile(aFileName22, field, MED_EN::RDWR);
00541     CPPUNIT_ASSERT(aDriver->getFileName() == aFileName22);
00542     CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDWR); // see MEDMEM_define.hxx
00543 
00544     MED_FIELD_RDWR_DRIVER<double> * aFieldRWDriverForMed22 =
00545       dynamic_cast<MED_FIELD_RDWR_DRIVER<double> *> (aDriver);
00546     CPPUNIT_ASSERT(aFieldRWDriverForMed22);
00547 
00548     delete aDriver; aDriver=0;
00549   }
00550 
00552   // Test 9: buildConcreteMedDriverForMesh //
00554 
00555   // 9.1. V2.1
00556 
00557   // rdonly
00558   CPPUNIT_ASSERT_THROW(aDriver = DRIVERFACTORY::buildConcreteMedDriverForMesh("anyfile", mesh, "my driver name",
00559                                                                               MED_EN::RDONLY, MED_EN::V21),
00560                        MED_EXCEPTION);
00561   delete aDriver; aDriver=0;
00562 
00563   // wronly
00564   CPPUNIT_ASSERT_THROW(aDriver = DRIVERFACTORY::buildConcreteMedDriverForMesh("anyfile", mesh, "my driver name",
00565                                                                               MED_EN::WRONLY, MED_EN::V21),
00566                        MED_EXCEPTION);
00567 
00568   delete aDriver; aDriver=0;
00569 
00570   // rdwr
00571   CPPUNIT_ASSERT_THROW(aDriver = DRIVERFACTORY::buildConcreteMedDriverForMesh("anyfile", mesh, "my driver name",
00572                                                                               MED_EN::RDWR, MED_EN::V21),
00573                        MED_EXCEPTION);
00574 
00575   delete aDriver; aDriver=0;
00576 
00577   // 9.2. V2.2
00578 
00579   // rdonly
00580   aDriver = DRIVERFACTORY::buildConcreteMedDriverForMesh("anyfile", mesh, "my driver name",
00581                                                          MED_EN::RDONLY, MED_EN::V22);
00582   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00583   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDONLY);
00584 
00585   MED_MESH_RDONLY_DRIVER * aMeshRDriverForMed22 = dynamic_cast<MED_MESH_RDONLY_DRIVER *> (aDriver);
00586   CPPUNIT_ASSERT(aMeshRDriverForMed22);
00587   CPPUNIT_ASSERT(aMeshRDriverForMed22->getMeshName() == "my driver name");
00588 
00589   delete aDriver; aDriver=0;
00590 
00591   // wronly
00592   aDriver = DRIVERFACTORY::buildConcreteMedDriverForMesh("anyfile", mesh, "my driver name",
00593                                                          MED_EN::WRONLY, MED_EN::V22);
00594   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00595   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::WRONLY);
00596 
00597   MED_MESH_WRONLY_DRIVER * aMeshWDriverForMed22 = dynamic_cast<MED_MESH_WRONLY_DRIVER *> (aDriver);
00598   CPPUNIT_ASSERT(aMeshWDriverForMed22);
00599   CPPUNIT_ASSERT(aMeshWDriverForMed22->getMeshName() == "my driver name");
00600 
00601   delete aDriver; aDriver=0;
00602 
00603   // rdwr
00604   aDriver = DRIVERFACTORY::buildConcreteMedDriverForMesh("anyfile", mesh, "my driver name",
00605                                                          MED_EN::RDWR, MED_EN::V22);
00606   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00607   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDWR);
00608 
00609   MED_MESH_RDWR_DRIVER * aMeshRWDriverForMed22 = dynamic_cast<MED_MESH_RDWR_DRIVER *> (aDriver);
00610   CPPUNIT_ASSERT(aMeshRWDriverForMed22);
00611   CPPUNIT_ASSERT(aMeshRWDriverForMed22->getMeshName() == "my driver name");
00612   mesh->removeReference();
00613   delete aDriver; aDriver=0;
00614 
00616   // Test 10: buildConcreteMedDriverForField //
00618 
00619   // 10.1. V2.1
00620 
00621   // rdonly
00622   CPPUNIT_ASSERT_THROW(aDriver = DRIVERFACTORY::buildConcreteMedDriverForField("anyfile", field, MED_EN::RDONLY, MED_EN::V21),
00623                        MED_EXCEPTION);
00624   delete aDriver; aDriver=0;
00625 
00626   // wronly
00627   CPPUNIT_ASSERT_THROW(aDriver = DRIVERFACTORY::buildConcreteMedDriverForField("anyfile", field, MED_EN::WRONLY, MED_EN::V21),
00628                        MED_EXCEPTION);
00629   delete aDriver; aDriver=0;
00630 
00631   // rdwr
00632   CPPUNIT_ASSERT_THROW(aDriver = DRIVERFACTORY::buildConcreteMedDriverForField("anyfile", field, MED_EN::RDWR, MED_EN::V21), MED_EXCEPTION);
00633   delete aDriver; aDriver=0;
00634 
00635   // 10.2. V2.2
00636 
00637   // rdonly
00638   aDriver = DRIVERFACTORY::buildConcreteMedDriverForField("anyfile", field, MED_EN::RDONLY, MED_EN::V22);
00639   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00640   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDONLY);
00641 
00642   MED_FIELD_RDONLY_DRIVER<double> * aFieldRDriverForMed22 =
00643     dynamic_cast<MED_FIELD_RDONLY_DRIVER<double> *> (aDriver);
00644   CPPUNIT_ASSERT(aFieldRDriverForMed22);
00645 
00646   delete aDriver; aDriver=0;
00647 
00648   // wronly
00649   aDriver = DRIVERFACTORY::buildConcreteMedDriverForField("anyfile", field, MED_EN::WRONLY, MED_EN::V22);
00650   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00651   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::WRONLY);
00652 
00653   MED_FIELD_WRONLY_DRIVER<double> * aFieldWDriverForMed22 =
00654     dynamic_cast<MED_FIELD_WRONLY_DRIVER<double> *> (aDriver);
00655   CPPUNIT_ASSERT(aFieldWDriverForMed22);
00656 
00657   delete aDriver; aDriver=0;
00658 
00659   // rdwr
00660   aDriver = DRIVERFACTORY::buildConcreteMedDriverForField("anyfile", field, MED_EN::RDWR, MED_EN::V22);
00661   field->removeReference();
00662   CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile");
00663   CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::RDWR); // see MEDMEM_define.hxx
00664 
00665   MED_FIELD_RDWR_DRIVER<double> * aFieldRWDriverForMed22 =
00666     dynamic_cast<MED_FIELD_RDWR_DRIVER<double> *> (aDriver);
00667   CPPUNIT_ASSERT(aFieldRWDriverForMed22);
00668 
00669   delete aDriver; aDriver=0;
00670 }