Back to index

salome-med  6.5.0
MEDMEMTest_VtkMeshDriver.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_VtkMeshDriver.hxx>
00024 #include <MEDMEM_MedMeshDriver.hxx>
00025 #include <MEDMEM_Mesh.hxx>
00026 
00027 // use this define to enable lines, execution of which leads to Segmentation Fault
00028 //#define ENABLE_FAULTS
00029 
00030 // use this define to enable CPPUNIT asserts and fails, showing bugs
00031 //#define ENABLE_FORCED_FAILURES
00032 
00033 using namespace std;
00034 using namespace MEDMEM;
00035 
00053 void MEDMEMTest::testVtkMeshDriver()
00054 {
00055   MESH * aMesh = new MESH;
00056 
00057   string filename_rd               = getResourceFile("pointe.med");
00058   string emptyfilename             = "";
00059   string meshname_rd               = "maa1";
00060   string meshname                  = "MyMesh";
00061   string fileNotExistsName         = "/path_not_exists/file_not_exists.vtk";
00062   string filename                  = makeTmpFile("my_pointe.vtk");
00063 
00064   MEDMEMTest_TmpFilesRemover aRemover;
00065   aRemover.Register(filename);
00066 
00067   {
00068     //Creation a invalid Vtk driver
00069     VTK_MESH_DRIVER *aInvalidVtkDriver = new VTK_MESH_DRIVER(fileNotExistsName, aMesh);
00070 
00071     //Trying open not existing file
00072     CPPUNIT_ASSERT_THROW(aInvalidVtkDriver->open(), MEDEXCEPTION);
00073     CPPUNIT_ASSERT_THROW(aInvalidVtkDriver->openConst(), MEDEXCEPTION);
00074 
00075     CPPUNIT_ASSERT_NO_THROW(delete aInvalidVtkDriver);
00076   }
00077 
00078   {
00079     //Create Vtk driver with empty file name
00080     VTK_MESH_DRIVER *aEmptyVtkDriver = new VTK_MESH_DRIVER(emptyfilename, aMesh);
00081 
00082     //Test open() and openConst() methods with empty file name
00083     CPPUNIT_ASSERT_THROW(aEmptyVtkDriver->open(), MEDEXCEPTION);
00084     CPPUNIT_ASSERT_THROW(aEmptyVtkDriver->openConst(), MEDEXCEPTION);
00085 
00086     delete aEmptyVtkDriver;
00087   }
00088 
00089   //Creation corect driver
00090   VTK_MESH_DRIVER *aVtkDriver = new VTK_MESH_DRIVER(filename, aMesh);
00091   CPPUNIT_ASSERT(aVtkDriver);
00092 
00093   //Create a Mesh
00094   MED_MESH_RDONLY_DRIVER *aMedMeshRdDriver22 = new MED_MESH_RDONLY_DRIVER(filename_rd, aMesh);
00095   aMedMeshRdDriver22->open();
00096   aMedMeshRdDriver22->setMeshName(meshname_rd);
00097 
00098   //Test openConst() and closeConst() methods
00099   CPPUNIT_ASSERT_NO_THROW(aVtkDriver->openConst());
00100   CPPUNIT_ASSERT_NO_THROW(aVtkDriver->closeConst());
00101 
00102   //Test open() method
00103   CPPUNIT_ASSERT_NO_THROW(aVtkDriver->open());
00104 
00105   //Trying open file secondary
00106   // (NOT!!! BUG) No exception on attempt to open a file for the second time
00107   //CPPUNIT_ASSERT_NO_THROW(aVtkDriver->open());
00108 
00109   //Test read method
00110   CPPUNIT_ASSERT_THROW(aVtkDriver->read(), MEDEXCEPTION);
00111 
00112   //Trying write empty mesh
00113   CPPUNIT_ASSERT_THROW(aVtkDriver->write(), MEDEXCEPTION);
00114 
00115   //Read mesh from Med file
00116   aMedMeshRdDriver22->read();
00117 
00118   //Check mesh
00119   CPPUNIT_ASSERT(aMesh);
00120 
00121   //Test SetMeshName and getMeshName methods
00122   CPPUNIT_ASSERT_NO_THROW(aVtkDriver->setMeshName(meshname));
00123   CPPUNIT_ASSERT_EQUAL(meshname, aVtkDriver->getMeshName());
00124 
00125   //Test write method
00126   CPPUNIT_ASSERT_NO_THROW(aVtkDriver->write());
00127 
00128   //Test close method
00129   CPPUNIT_ASSERT_NO_THROW(aVtkDriver->close());
00130 
00131   //Test Default constructor
00132   VTK_MESH_DRIVER aVtkDriverCpy_1;
00133 
00134   //Test copy constructor
00135   VTK_MESH_DRIVER aVtkDriverCpy_2 (*aVtkDriver);
00136 
00137   //Test (bool operator ==) defined in GENDRIVER class
00138   //CPPUNIT_ASSERT(aVtkDriverCpy_2.GENDRIVER::operator==(aVtkDriver));
00139 
00140   //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx
00141   //ostringstream ostr1, ostr2;
00142   //ostr1 << aVtkDriverCpy_2;
00143   //ostr2 << aVtkDriver;
00144   //CPPUNIT_ASSERT(ostr1.str() != "");
00145   //CPPUNIT_ASSERT_EQUAL(ostr1.str(), ostr2.str());
00146 
00147   //Delete objects
00148   delete aVtkDriver;
00149   delete aMedMeshRdDriver22;
00150   aMesh->removeReference();
00151 }