1 // Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDMEMTest.hxx"
21 #include <cppunit/TestAssert.h>
23 #include <MEDMEM_Compatibility21_22.hxx>
24 #include <MEDMEM_VtkMedDriver.hxx>
25 #include <MEDMEM_MedMedDriver21.hxx>
26 #include <MEDMEM_Med.hxx>
28 // use this define to enable lines, execution of which leads to Segmentation Fault
29 //#define ENABLE_FAULTS
31 // use this define to enable CPPUNIT asserts and fails, showing bugs
32 #define ENABLE_FORCED_FAILURES
35 using namespace MEDMEM;
36 using namespace MED_EN;
39 * Check methods (5), defined in MEDMEM_VtkMedDriver.hxx:
40 * class VTK_MED_DRIVER : public GENDRIVER {
41 * (+) VTK_MED_DRIVER(const string & fileName, MED * const ptrMed);
42 * (+) VTK_MED_DRIVER(const VTK_MED_DRIVER & driver);
43 * (+) ~VTK_MED_DRIVER();
44 * (+) void write (void) const;
45 * (-) virtual void read (void) {};
46 * (+) GENDRIVER * copy (void) const;
49 void MEDMEMTest::testVtkMedDriver()
51 MED *aMed = new MED();
52 string data_dir = getenv("DATA_DIR");
53 string tmp_dir = getenv("TMP");
56 string filename_rd = data_dir + "/MedFiles/pointe.med";
57 string emptyfilename = "";
58 string fileNotExistsName = "/path_not_exists/file_not_exists.vtk";
59 string filename_wr = tmp_dir + "/myMED_pointe.vtk";
61 MEDMEMTest_TmpFilesRemover aRemover;
62 aRemover.Register(filename_wr);
64 //Read MED structure from file
65 MED_MED_RDONLY_DRIVER21 *aMedMedRdDriver21 = new MED_MED_RDONLY_DRIVER21(filename_rd, aMed);
66 aMedMedRdDriver21->open();
67 aMedMedRdDriver21->read();
68 aMedMedRdDriver21->close();
72 //Creation incorrect Vtk Med Driver (file is not exists)
73 VTK_MED_DRIVER *aInvalidVtkMedDriver = new VTK_MED_DRIVER(fileNotExistsName,aMed);
75 //Trying write data in the not existing file
76 CPPUNIT_ASSERT_THROW(aInvalidVtkMedDriver->write(),MEDEXCEPTION);
78 //Creation correct Vtk Med Driver
79 VTK_MED_DRIVER *aVtkMedDriver = new VTK_MED_DRIVER(filename_wr ,aMed);
82 CPPUNIT_ASSERT(aVtkMedDriver);
88 aVtkMedDriver->write();
90 catch(MEDEXCEPTION &e)
92 CPPUNIT_FAIL(e.what());
96 CPPUNIT_FAIL("Unknown exception");
99 //Test copy constructor
100 VTK_MED_DRIVER *aVtkMedDriverCpy = new VTK_MED_DRIVER(*aVtkMedDriver);
101 #ifdef ENABLE_FORCED_FAILURES
102 CPPUNIT_ASSERT_EQUAL(*aVtkMedDriverCpy, *aVtkMedDriver);
105 //Test (operator ==) defined in GENDRIVER class in MEDMEM_GenDriver.hxx
106 #ifdef ENABLE_FORCED_FAILURES
107 CPPUNIT_ASSERT(*aVtkMedDriverCpy == *aVtkMedDriver);
110 //Test copy() function
111 VTK_MED_DRIVER *aVtkMedDriverCpy_1 = (VTK_MED_DRIVER*)aVtkMedDriver->copy();
112 #ifdef ENABLE_FORCED_FAILURES
113 CPPUNIT_ASSERT_EQUAL(*aVtkMedDriverCpy_1, *aVtkMedDriver);
116 //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx
117 ostringstream ostr1, ostr2;
118 ostr1<<*aVtkMedDriverCpy;
119 ostr2<<*aVtkMedDriverCpy_1;
120 CPPUNIT_ASSERT(ostr1.str() != "");
121 CPPUNIT_ASSERT(ostr1.str() == ostr2.str());
125 delete aMedMedRdDriver21;
126 #ifdef ENABLE_FORCED_FAILURES
127 delete aInvalidVtkMedDriver;
128 delete aVtkMedDriver;
129 delete aVtkMedDriverCpy;
130 delete aVtkMedDriverCpy_1;
131 //MEDEXCEPTION in the destructor (after trying close file)