1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDMEMTest.hxx"
21 #include <cppunit/TestAssert.h>
23 #include <MEDMEM_TopLevel.hxx>
24 #include <MEDMEM_MedFieldDriver.hxx>
25 #include <MEDMEM_Field.hxx>
27 // use this define to enable lines, execution of which leads to Segmentation Fault
28 //#define ENABLE_FAULTS
30 // use this define to enable CPPUNIT asserts and fails, showing bugs
31 //#define ENABLE_FORCED_FAILURES
34 using namespace MEDMEM;
35 using namespace MED_EN;
38 * Check methods (6), defined in MEDMEM_TopLevel.hxx:
39 * (+) MESH *readMeshInFile(const std::string& fileName, const std::string& meshName);
40 * (+) template<class T> FIELD<T> *readFieldInFile
41 * (const std::string& fileName, const std::string& fieldName);
42 * (+) void writeMeshToFile(const MESH *meshObj, const std::string& fileName);
43 * (-) template<class T> void writeFieldToFile(const FIELD<T> *fieldObj, const std::string& fileName);
45 void MEDMEMTest::testTopLevel()
47 string filename_rd = getResourceFile("pointe.med");
48 string filename22_rd = getResourceFile("pointe.med");
49 string filenameMesh_wr = makeTmpFile("myMesh.med");
50 string filenameMed_wr = makeTmpFile("myMed.med");
51 string filenameField_wr = makeTmpFile("myField.med");
52 string fileNotExist_rd = "/notExist.med";
53 string fileNotExist_wr = "/path_not_exist/file_not_exist.med";
54 string meshname = "maa1";
55 string meshname_not_exist = "anymesh";
56 string fieldname_not_exist = "anyfield";
57 string fieldname = "fieldnodedouble";
59 // To remove tmp files from disk
60 MEDMEMTest_TmpFilesRemover aRemover;
61 aRemover.Register(filenameMesh_wr);
62 aRemover.Register(filenameMed_wr);
63 aRemover.Register(filenameField_wr);
69 CPPUNIT_ASSERT_THROW(readMeshInFile(fileNotExist_rd, meshname), MEDEXCEPTION);
70 CPPUNIT_ASSERT_THROW(readFieldInFile<double>(fileNotExist_rd, fieldname), MEDEXCEPTION);
72 //Trying read not existing mesh from file
73 CPPUNIT_ASSERT_THROW(readMeshInFile(filename_rd, meshname_not_exist), MEDEXCEPTION);
75 //Trying read not existing field from file
76 CPPUNIT_ASSERT_THROW(readFieldInFile<double>(filename_rd, fieldname_not_exist), MEDEXCEPTION);
78 //Test readMeshInFile() method
81 CPPUNIT_ASSERT_NO_THROW(aMesh = readMeshInFile(filename22_rd, meshname));
82 CPPUNIT_ASSERT(aMesh);
83 aMesh->removeReference();
86 //Test readFieldInFile() method
88 FIELD<double> * aField = NULL;
89 CPPUNIT_ASSERT_NO_THROW(aField = readFieldInFile<double>(filename22_rd, fieldname));
90 CPPUNIT_ASSERT(aField);
91 aField->removeReference();
100 FIELD<double> *aField_1 = new FIELD<double>();
102 MED_FIELD_RDONLY_DRIVER<double> *aMedRdFieldDriver22 =
103 new MED_FIELD_RDONLY_DRIVER<double>(filename22_rd, aField_1);
104 aMedRdFieldDriver22->setFieldName(fieldname);
105 aMedRdFieldDriver22->open();
106 aMedRdFieldDriver22->read();
107 aMedRdFieldDriver22->close();
110 MESH * aMesh = MEDMEMTest_createTestMesh();
111 CPPUNIT_ASSERT_THROW(writeMeshToFile(aMesh, fileNotExist_wr), MEDEXCEPTION);
113 //Trying write mesh in the file with empty name
115 CPPUNIT_ASSERT_THROW(writeMeshToFile(aMesh, filenameField_wr), MEDEXCEPTION);
117 //Test writeMeshToFile() method
118 aMesh->setName(meshname);
119 CPPUNIT_ASSERT_NO_THROW(writeMeshToFile(aMesh, filenameMesh_wr));
121 aField_1->removeReference();
122 aMesh->removeReference();