Back to index

salome-med  6.5.0
MEDMEMTest_VtkMedDriver.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_MedFileBrowser.hxx>
00024 #include <MEDMEM_VtkMedDriver.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 
00032 using namespace std;
00033 using namespace MEDMEM;
00034 using namespace MED_EN;
00035 
00047 void MEDMEMTest::testVtkMedDriver()
00048 {
00049   MEDFILEBROWSER *aMed     = new MEDFILEBROWSER();
00050   string filename_rd       = getResourceFile("pointe.med");
00051   string emptyfilename     = "";
00052   string fileNotExistsName = "/path_not_exists/file_not_exists.vtk";
00053   string filename_wr       = makeTmpFile( "myMED_pointe.vtk" );
00054 
00055   MEDMEMTest_TmpFilesRemover aRemover;
00056   aRemover.Register(filename_wr);
00057 
00058   //Read MED structure from file (not generic code)
00059   vector<const FIELD_*> fields;
00060   aMed->readFileStruct( filename_rd );
00061   MESH mesh(MED_DRIVER, aMed->getFileName(), aMed->getMeshNames()[0] );
00062   vector<string> fieldsNames = aMed->getFieldNames();
00063   for ( unsigned i = 0; i < fieldsNames.size(); ++i )
00064   {
00065     VEC_DT_IT_ vecDtIt = aMed->getFieldIteration( fieldsNames[i] );
00066     for ( unsigned j = 0; j < vecDtIt.size(); ++j )
00067       if ( aMed->getFieldType( fieldsNames[i] ) == MED_REEL64 )
00068         fields.push_back( new FIELD<double>(MED_DRIVER, filename_rd, fieldsNames[i],
00069                                             vecDtIt[j].dt, vecDtIt[j].it, &mesh));
00070       else
00071         fields.push_back( new FIELD<int>(MED_DRIVER, filename_rd, fieldsNames[i],
00072                                          vecDtIt[j].dt, vecDtIt[j].it, &mesh));
00073   }      
00074   
00075   //Check Med
00076   CPPUNIT_ASSERT(fields.size());
00077 
00078   //Creation incorrect Vtk Med Driver (file is not exists)
00079   VTK_MED_DRIVER *aInvalidVtkMedDriver = new VTK_MED_DRIVER(fileNotExistsName,fields);
00080 
00081   //Trying write data in the not existing file
00082   CPPUNIT_ASSERT_THROW(aInvalidVtkMedDriver->write(),MEDEXCEPTION);
00083 
00084   //Creation correct Vtk Med Driver
00085   VTK_MED_DRIVER *aVtkMedDriver = new VTK_MED_DRIVER(filename_wr ,fields);
00086 
00087   //Check driver
00088   CPPUNIT_ASSERT(aVtkMedDriver);
00089 
00090   //Test write() method
00091 
00092   CPPUNIT_ASSERT_NO_THROW(aVtkMedDriver->write());
00093 
00094 
00095   //Test BINARY write() method
00096 
00097   DRIVERFACTORY::setVtkBinaryFormatForWriting( true );
00098   CPPUNIT_ASSERT_NO_THROW( aVtkMedDriver->write() );
00099   DRIVERFACTORY::setVtkBinaryFormatForWriting( false );
00100   
00101 
00102   //Test copy constructor
00103   VTK_MED_DRIVER *aVtkMedDriverCpy = new VTK_MED_DRIVER(*aVtkMedDriver);
00104   CPPUNIT_ASSERT_EQUAL(*aVtkMedDriverCpy, *aVtkMedDriver);
00105 
00106   //Test (operator ==) defined in GENDRIVER class in MEDMEM_GenDriver.hxx
00107   CPPUNIT_ASSERT(*aVtkMedDriverCpy == *aVtkMedDriver);
00108 
00109   //Test copy() function
00110   VTK_MED_DRIVER *aVtkMedDriverCpy_1 = (VTK_MED_DRIVER*)aVtkMedDriver->copy();
00111   CPPUNIT_ASSERT_EQUAL(*aVtkMedDriverCpy_1, *aVtkMedDriver);
00112   
00113   //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx
00114   ostringstream ostr1, ostr2;
00115   ostr1<<*aVtkMedDriverCpy;
00116   ostr2<<*aVtkMedDriverCpy_1;
00117   CPPUNIT_ASSERT(ostr1.str() != "");
00118   CPPUNIT_ASSERT(ostr1.str() == ostr2.str());
00119 
00120 
00121   //Delete objects
00122   delete aInvalidVtkMedDriver;
00123   delete aVtkMedDriver;
00124   delete aVtkMedDriverCpy;
00125   delete aVtkMedDriverCpy_1;
00126   delete aMed;
00127 
00128   for ( unsigned i = 0; i < fields.size(); ++i )
00129     fields[i]->removeReference();
00130 }