Back to index

salome-med  6.5.0
MEDMEMTest_TopLevel.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_TopLevel.hxx>
00024 #include <MEDMEM_MedFieldDriver.hxx>
00025 #include <MEDMEM_Field.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 using namespace MED_EN;
00036 
00045 void MEDMEMTest::testTopLevel()
00046 {
00047   string filename_rd                = getResourceFile("pointe.med");
00048   string filename22_rd              = getResourceFile("pointe.med");
00049   string filenameMesh_wr            = makeTmpFile("myMesh.med");
00050   string filenameMed_wr             = makeTmpFile("myMed.med");
00051   string filenameField_wr           = makeTmpFile("myField.med");
00052   string fileNotExist_rd            = "/notExist.med";
00053   string fileNotExist_wr            = "/path_not_exist/file_not_exist.med";
00054   string meshname                   = "maa1";
00055   string meshname_not_exist         = "anymesh";
00056   string fieldname_not_exist        = "anyfield";
00057   string fieldname                  = "fieldnodedouble";
00058 
00059   // To remove tmp files from disk
00060   MEDMEMTest_TmpFilesRemover aRemover;
00061   aRemover.Register(filenameMesh_wr);
00062   aRemover.Register(filenameMed_wr);
00063   aRemover.Register(filenameField_wr);
00064 
00066   //Test Read Part //
00068   {
00069     CPPUNIT_ASSERT_THROW(readMeshInFile(fileNotExist_rd, meshname), MEDEXCEPTION);
00070     CPPUNIT_ASSERT_THROW(readFieldInFile<double>(fileNotExist_rd, fieldname), MEDEXCEPTION);
00071 
00072     //Trying read not existing mesh from file
00073     CPPUNIT_ASSERT_THROW(readMeshInFile(filename_rd, meshname_not_exist), MEDEXCEPTION);
00074 
00075     //Trying read not existing field from file
00076     CPPUNIT_ASSERT_THROW(readFieldInFile<double>(filename_rd, fieldname_not_exist), MEDEXCEPTION);
00077 
00078     //Test readMeshInFile() method
00079     {
00080       MESH * aMesh = NULL;
00081       CPPUNIT_ASSERT_NO_THROW(aMesh = readMeshInFile(filename22_rd, meshname));
00082       CPPUNIT_ASSERT(aMesh);
00083       aMesh->removeReference();
00084     }
00085 
00086     //Test readFieldInFile() method
00087     {
00088       FIELD<double> * aField = NULL;
00089       CPPUNIT_ASSERT_NO_THROW(aField = readFieldInFile<double>(filename22_rd, fieldname));
00090       CPPUNIT_ASSERT(aField);
00091       aField->removeReference();
00092     }
00093   }
00094 
00096   //Test Write Part //
00098   {
00099     //Create a FIELD
00100     FIELD<double> *aField_1 = new FIELD<double>();
00101 
00102     MED_FIELD_RDONLY_DRIVER<double> *aMedRdFieldDriver22 =
00103       new MED_FIELD_RDONLY_DRIVER<double>(filename22_rd, aField_1);
00104     aMedRdFieldDriver22->setFieldName(fieldname);
00105     aMedRdFieldDriver22->open();
00106     aMedRdFieldDriver22->read();
00107     aMedRdFieldDriver22->close();
00108 
00109     //Create a MESH
00110     MESH * aMesh = MEDMEMTest_createTestMesh();
00111     CPPUNIT_ASSERT_THROW(writeMeshToFile(aMesh, fileNotExist_wr), MEDEXCEPTION);
00112 
00113     //Trying write mesh in the file with empty name
00114     aMesh->setName("");
00115     CPPUNIT_ASSERT_THROW(writeMeshToFile(aMesh, filenameField_wr), MEDEXCEPTION);
00116 
00117     //Test writeMeshToFile() method
00118     aMesh->setName(meshname);
00119     CPPUNIT_ASSERT_NO_THROW(writeMeshToFile(aMesh, filenameMesh_wr));
00120 
00121     aField_1->removeReference();
00122     aMesh->removeReference();
00123   }
00124 }