1 // Copyright (C) 2007-2012 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_VtkMeshDriver.hxx>
24 #include <MEDMEM_MedMeshDriver.hxx>
25 #include <MEDMEM_Mesh.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;
37 * Check methods (11), defined in MEDMEM_VtkMeshDriver.hxx:
38 * class VTK_MESH_DRIVER : public GENDRIVER {
39 * (+) VTK_MESH_DRIVER();
40 * (+) VTK_MESH_DRIVER(const string & fileName, MESH * ptrMesh);
41 * (+) VTK_MESH_DRIVER(const VTK_MESH_DRIVER & driver);
42 * (+) ~VTK_MESH_DRIVER();
45 * (+) void openConst() const throw (MEDEXCEPTION);
46 * (+) void closeConst() const throw (MEDEXCEPTION);
47 * (+) void write(void) const throw (MEDEXCEPTION);
48 * (+) void read (void) throw (MEDEXCEPTION);
49 * (+) void setMeshName(const string & meshName);
50 * (+) string getMeshName() const;
53 void MEDMEMTest::testVtkMeshDriver()
55 MESH * aMesh = new MESH;
57 string filename_rd = getResourceFile("pointe.med");
58 string emptyfilename = "";
59 string meshname_rd = "maa1";
60 string meshname = "MyMesh";
61 string fileNotExistsName = "/path_not_exists/file_not_exists.vtk";
62 string filename = makeTmpFile("my_pointe.vtk");
64 MEDMEMTest_TmpFilesRemover aRemover;
65 aRemover.Register(filename);
68 //Creation a invalid Vtk driver
69 VTK_MESH_DRIVER *aInvalidVtkDriver = new VTK_MESH_DRIVER(fileNotExistsName, aMesh);
71 //Trying open not existing file
72 CPPUNIT_ASSERT_THROW(aInvalidVtkDriver->open(), MEDEXCEPTION);
73 CPPUNIT_ASSERT_THROW(aInvalidVtkDriver->openConst(), MEDEXCEPTION);
75 CPPUNIT_ASSERT_NO_THROW(delete aInvalidVtkDriver);
79 //Create Vtk driver with empty file name
80 VTK_MESH_DRIVER *aEmptyVtkDriver = new VTK_MESH_DRIVER(emptyfilename, aMesh);
82 //Test open() and openConst() methods with empty file name
83 CPPUNIT_ASSERT_THROW(aEmptyVtkDriver->open(), MEDEXCEPTION);
84 CPPUNIT_ASSERT_THROW(aEmptyVtkDriver->openConst(), MEDEXCEPTION);
86 delete aEmptyVtkDriver;
89 //Creation corect driver
90 VTK_MESH_DRIVER *aVtkDriver = new VTK_MESH_DRIVER(filename, aMesh);
91 CPPUNIT_ASSERT(aVtkDriver);
94 MED_MESH_RDONLY_DRIVER *aMedMeshRdDriver22 = new MED_MESH_RDONLY_DRIVER(filename_rd, aMesh);
95 aMedMeshRdDriver22->open();
96 aMedMeshRdDriver22->setMeshName(meshname_rd);
98 //Test openConst() and closeConst() methods
99 CPPUNIT_ASSERT_NO_THROW(aVtkDriver->openConst());
100 CPPUNIT_ASSERT_NO_THROW(aVtkDriver->closeConst());
103 CPPUNIT_ASSERT_NO_THROW(aVtkDriver->open());
105 //Trying open file secondary
106 // (NOT!!! BUG) No exception on attempt to open a file for the second time
107 //CPPUNIT_ASSERT_NO_THROW(aVtkDriver->open());
110 CPPUNIT_ASSERT_THROW(aVtkDriver->read(), MEDEXCEPTION);
112 //Trying write empty mesh
113 CPPUNIT_ASSERT_THROW(aVtkDriver->write(), MEDEXCEPTION);
115 //Read mesh from Med file
116 aMedMeshRdDriver22->read();
119 CPPUNIT_ASSERT(aMesh);
121 //Test SetMeshName and getMeshName methods
122 CPPUNIT_ASSERT_NO_THROW(aVtkDriver->setMeshName(meshname));
123 CPPUNIT_ASSERT_EQUAL(meshname, aVtkDriver->getMeshName());
126 CPPUNIT_ASSERT_NO_THROW(aVtkDriver->write());
129 CPPUNIT_ASSERT_NO_THROW(aVtkDriver->close());
131 //Test Default constructor
132 VTK_MESH_DRIVER aVtkDriverCpy_1;
134 //Test copy constructor
135 VTK_MESH_DRIVER aVtkDriverCpy_2 (*aVtkDriver);
137 //Test (bool operator ==) defined in GENDRIVER class
138 //CPPUNIT_ASSERT(aVtkDriverCpy_2.GENDRIVER::operator==(aVtkDriver));
140 //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx
141 //ostringstream ostr1, ostr2;
142 //ostr1 << aVtkDriverCpy_2;
143 //ostr2 << aVtkDriver;
144 //CPPUNIT_ASSERT(ostr1.str() != "");
145 //CPPUNIT_ASSERT_EQUAL(ostr1.str(), ostr2.str());
149 delete aMedMeshRdDriver22;
150 aMesh->removeReference();